Range reduction, tables and polynomial degree
Part 2 · Approximating the reduced interval
What we covered in Part 1
Part 1 used , with and , to write . We approximate on a fixed interval, then multiply by . For normal binary floating-point outputs, that last operation changes the exponent.
Even on , a low-degree polynomial has approximation error. Here we examine two ways to reduce it: use several polynomials on shorter intervals, or increase the degree of each polynomial.
Posts in this series
- Computing exp2 — Motivation, base conversion, range reduction, and the choice of polynomial.
- Range reduction, tables and polynomial degree (this post) — Why subdivision and higher degree improve the fit, and how they change storage and arithmetic.
- Remez, coefficient search, accuracy testing and hardware cost — Fit coefficients for finite-precision arithmetic, test accuracy, and compare hardware experiments.
- Generating RTL and searching implementation choices — Identify circuit choices, generate RTL and improve the implementation through measured experiments.
Why use several quadratics after range reduction?
On , increases from one to two. A quadratic can follow much of that curve, but its second derivative is constant:
The exponential’s second derivative increases with :
It doubles across the interval. Choosing to match this curvature near zero makes the quadratic bend too little near one; matching near one makes it bend too much near zero. Changing or cannot resolve that mismatch because neither affects the second derivative.
Splitting the interval gives each quadratic its own coefficients. The first can have a smaller second derivative and the last a larger one. Within each shorter piece, the exponential’s curvature also varies less.
The figures use coefficients that minimize the maximum relative error, . Part 3 explains how Remez finds them. Here we use real-valued coefficients to examine the effect of subdivision first.
The maximum relative error falls from with one quadratic to with two and with four. Halving the interval width reduces the error by about eight in these fits.
Selecting the polynomial
A coefficient table stores one set of for each interval. Every input selects one row and evaluates one quadratic, however many rows the table has.
For equal intervals, define
The figures above use the global coordinate . For evaluation, selects the row and rescales its interval to ; derivatives with respect to therefore have a different scale from the plotted derivatives with respect to . Row contains a polynomial approximating
For example, with eight intervals and , we get and . We evaluate row 5’s polynomial halfway through its interval to estimate . The coefficients already account for the interval’s location, so there is no extra multiplication by an interval-dependent exponential.
We evaluate the selected quadratic as
This form uses two multiply-adds. Increasing the number of rows gives us more coefficient sets without increasing the number of operations for one input.
What does a cubic add?
Its second derivative can increase linearly within an interval. A quadratic has to use one constant second derivative there.
One cubic reaches a maximum relative error of ; two reach . Each cubic needs four coefficients and three multiply-adds:
Comparing two implementations
For an illustrative approximation target of relative error, both of these real-valued fits qualify:
| Design | Maximum relative fit error | Coefficient values | Multiply-add stages |
|---|---|---|---|
| Eight quadratics | 24 | 2 | |
| Two cubics | 8 | 3 |
The cubic table has fewer rows and fewer coefficients in total, while its pipeline needs another multiply-add to sustain one result per cycle.
The operand widths matter too. With fractional bits for , eight rows use the leading three bits as an address and leave bits for . Two rows use one address bit and leave residual bits. Keeping the remaining bits makes the cubic’s multiplier input two bits wider. Coefficient widths can differ as well: a polynomial spanning a wider interval describes a larger output change, even though its local coordinate still runs from zero to one.
Conclusions
For the rest of the series, we favor the shorter arithmetic pipeline and develop piecewise quadratics. We can improve the fit by increasing table resolution while keeping two multiply-adds per input. We still need to choose the number of rows and the bit widths. Part 3 fits coefficients for those finite formats and their rounding operations, then compares the accuracy and circuit area of designs meeting our two-ULP limit.