Abstract
In the present paper, we investigate the approximation of a function by a polynomial with floating-point coefficients; we are looking for the best approximation in the $L^2$ sense. Finding a best polynomial $L^2$-approximation with real coefficients is an easy exercise about orthogonal projections. However, truncating the coefficients to floating-point numbers, which is needed for further computations, makes the approximation way worse. Hence, we study the problem of computing best approximations under the constraint that coefficients are floating-point numbers. We show that the corresponding problem is NP-hard, by reduction to the CVP problem. We investigate the practical behaviour of exact and approximate algorithms for this problem. The conclusion is that it is possible in a short amount of time to obtain a relative or absolute best $L^2$-approximation. The main applications are for large dimension, as a preliminary step of finding $L^\infty$-approximations and for functions with large variations, for which relative best approximation is by far more interesting than absolute.
Introduction
In computer arithmetic and software library development, mathematical functions such as $\sin(x)$ or $\exp(x)$ are typically evaluated using polynomial approximations. While the theoretical best polynomial—minimizing either the average squared error ($L^2$ norm) or the maximum error ($L^\infty$ norm)—is well-understood, a practical challenge arises: the coefficients of these polynomials must be stored as floating-point numbers (machine numbers).
Simply rounding the coefficients of a minimax or $L^2$ projection to the nearest machine numbers often results in a significant loss of accuracy. This paper addresses the Floating-Point $L^2$-Approximation problem, seeking the optimal polynomial whose coefficients are constrained to a specific floating-point format from the outset.
Problem Formulation and Complexity
The authors demonstrate that minimizing the $L^2$ distance between a target function $f$ and a polynomial with floating-point coefficients can be mapped to a geometric problem in lattice theory. Specifically, the task is equivalent to finding a vector in a discrete lattice that is closest to a target point representing the ideal real-valued coefficients.
NP-Hardness
The paper proves that this problem is NP-hard through a reduction to the Closest Vector Problem (CVP). In general, as the degree of the polynomial increases, the search space grows such that finding an exact solution becomes computationally prohibitive. However, for the degrees typically used in function approximation (often $n < 50$), the problem remains tractable using modern lattice reduction techniques.
Algorithmic Solutions
To solve the constrained $L^2$ problem, the authors employ several lattice-based algorithms:
- LLL (Lenstra-Lenstra-Lovász) Reduction: This algorithm is used as a preprocessing step to transform the lattice basis into a more orthogonal form, which significantly simplifies the search for the closest vector.
- Babai’s Nearest Plane Algorithm: This provides an efficient, though approximate, solution by greedily selecting the nearest lattice point.
- Kannan’s Method: For cases where an exact best approximation is required, Kannan's algorithm searches within a bounded ellipsoid to find the absolute closest lattice vector.
Additionally, the authors propose heuristics to determine the optimal bit-precision for each coefficient, ensuring the search space is effectively constrained without omitting the optimal solution.
Experimental Evaluation
The proposed methods were tested on standard mathematical functions commonly used in library development:
- Example 1: $x \mapsto \sin(\pi\sqrt{x})/(\pi\sqrt{x})$ on the interval $[0, 1]$.
- Example 2: The $\arctan$ function on the interval $[-1, 1]$.
Key Results
- Performance: Even for high-degree polynomials, the algorithms executed in under one second on a 2GHz Pentium M processor.
- Accuracy Gains: In the sine-based example, the lattice-based $L^2$ approach yielded an absolute error 100 times smaller than the standard approach of rounding a minimax polynomial. For a degree-8 polynomial, the improvement in $L^2$ error reached a factor of 10,000 compared to naive rounding.
- Relative Error: The method successfully handles relative error minimization, which is vital for functions with wide dynamic ranges. In the $\arctan$ test, relative error was improved by a factor of 5.
Discussion and Future Work
A significant insight of this research is the utility of $L^2$ approximations as a "warm start" for $L^\infty$ (minimax) optimization. While $L^\infty$ is the standard for function libraries due to its guaranteed error bounds, it lacks the helpful geometric structure of $L^2$ Hilbert spaces. By first finding a near-optimal $L^2$ approximation, developers can identify a small set of candidate polynomials to test for $L^\infty$ optimality.
Future work includes addressing numerical stability issues in LLL implementations and extending the methodology to multivariate functions. The authors also suggest that the $L^2$ lattice search can be used to generate a list of candidate vectors to find the absolute best $L^\infty$ floating-point approximation more efficiently than existing exhaustive search methods.
Summary updated