Skip to content

Review: Accuracy and Stability of Numerical Algorithms

Citation

  • Higham, N. J. (2002). Accuracy and Stability of Numerical Algorithms, second edition. Society for Industrial and Applied Mathematics. DOI 10.1137/1.9780898718027. Bibliography key higham2002accuracy.

Chapters covered

This review covers the parts of chapters 2, 3 and 4 that Hifuku uses to bound rounding error. Page numbers are the book's own.

Unit roundoff (§2.1)

Theorem 2.2 (p. 38) states that every real number \( x \) in the range of the floating-point system rounds to the nearest representable number with a small relative error:

\[\mathrm{fl}(x) = x(1 + \delta), \qquad |\delta| < u.\]

The unit roundoff \( u \) is half the machine epsilon. IEEE single precision has \( u = 2^{-24} \approx 5.96 \times 10^{-8} \), and double precision has \( u = 2^{-53} \approx 1.11 \times 10^{-16} \) (p. 39). The relative distance between neighboring numbers changes by a factor of the base across a power of the base, which the book calls wobbling precision. The bound \( u \) holds across that range.

The standard model of arithmetic (§2.2)

Rounding error analysis rests on one assumption about each basic operation (p. 40):

\[\mathrm{fl}(x \mathbin{\mathrm{op}} y) = (x \mathbin{\mathrm{op}} y)(1 + \delta), \qquad |\delta| \le u, \qquad \mathrm{op} = +, -, \times, / \tag{2.4}\]

The book assumes that (2.4) also holds for the square root. A modified form, which the book says can also be used, divides instead (p. 40):

\[\mathrm{fl}(x \mathbin{\mathrm{op}} y) = \frac{x \mathbin{\mathrm{op}} y}{1 + \delta}, \qquad |\delta| \le u. \tag{2.5}\]

The two forms have different \( \delta \) for the same operation. IEEE arithmetic in its default mode, round to nearest, satisfies (2.4) (p. 41). The form (2.5) rests on Theorem 2.3 (p. 39), which states \( \mathrm{fl}(x) = x/(1 + \delta) \), \( |\delta| \le u \), for every real \( x \) in the range of the floating-point numbers. Every analysis in the book is done under (2.4), sometimes with (2.5).

Accumulated rounding: the γ notation (§3.1, §3.4)

A computed result usually carries many factors of the form \( 1 + \delta \). Lemma 3.1 (p. 63) combines them. If \( |\delta_i| \le u \), each \( \rho_i = \pm 1 \), and \( nu < 1 \), then

\[\prod_{i=1}^{n} (1 + \delta_i)^{\rho_i} = 1 + \theta_n, \qquad |\theta_n| \le \frac{nu}{1 - nu} =: \gamma_n.\]

Lemma 3.3 (p. 67) gives the rules for combining these terms. The rule this project uses is \( \gamma_k + \gamma_j + \gamma_k \gamma_j \le \gamma_{k+j} \), together with \( (1 + \theta_k)(1 + \theta_j) = 1 + \theta_{k+j} \).

Section 3.1 also notes (p. 64) that the product of two numbers with a \( t \)-digit significand has at most \( 2t \) digits. So a product of two single-precision numbers is exact in double precision, because \( 2 \times 24 \le 53 \).

Inner products and sums (§3.1, §4.2)

For an inner product evaluated in any order, the forward error satisfies (p. 63)

\[|x^\top y - \mathrm{fl}(x^\top y)| \le \gamma_n \sum_{i=1}^{n} |x_i y_i|. \tag{3.5}\]

Chapter 4 treats summation as a general algorithm (Algorithm 4.1, p. 81). The algorithm repeatedly removes two numbers from a set and puts back their sum. Recursive, pairwise and insertion summation are all special cases, so a bound for Algorithm 4.1 covers any order of addition. The total error is the sum of the local errors of the \( n - 1 \) additions, which gives

\[|E_n| \le u \sum_{i=1}^{n-1} |\hat T_i| \tag{4.3}\]

over the computed partial sums \( \hat T_i \), and the weaker a priori bound

\[|E_n| \le (n - 1)u \sum_{i=1}^{n} |x_i| + O(u^2). \tag{4.4}\]

The backward form is exact rather than first order. No summand takes part in more than \( n - 1 \) additions, so the computed sum is the exact sum of the terms \( x_i(1 + \epsilon_i) \) with \( |\epsilon_i| \le \gamma_{n-1} \) (p. 82). For nonnegative terms, this gives a relative error of at most \( \gamma_{n-1} \).

Compensated summation (§4.3)

Compensated summation adds a correction for the rounding error of each partial sum (Algorithm 4.2, p. 84). In Kahan's form, which feeds each correction back into the next term, the computed sum is \( \sum_i (1 + \mu_i)x_i \) with \( |\mu_i| \le 2u + O((n - i + 1)u^2) \) (p. 85). In the form studied by Kielbasinski and by Neumaier, the corrections are accumulated separately and added at the end. For that form, \( |\mu_i| \le 2.1u \) whenever \( n^2 u \le 0.1 \) (4.10). Python 3.12 and later sum floats by compensated summation that accumulates the corrections separately.

Running error analysis (§3.3)

An a priori bound does not use the rounding errors that actually occur. A running error bound does (p. 65). From (2.5), every operation satisfies

\[|x \mathbin{\mathrm{op}} y - \mathrm{fl}(x \mathbin{\mathrm{op}} y)| \le u\,|\mathrm{fl}(x \mathbin{\mathrm{op}} y)|,\]

and the right side uses a value that the computation already holds. Algorithm 3.2 (p. 66) computes an inner product and its error bound together. Rounding in the bound itself is negligible for \( nu \ll 1 \). The book adds (p. 65) that the constant terms in an a priori bound usually overestimate the actual error by orders of magnitude.

Relevance to Hifuku

The device and the host both compute the out-of-plane residual \( z \) of a tree. They use the same float32 branch lengths and the same formula, at different precisions. The device adds each run of merged edges in float32, reads the anchors' split lengths rounded to float32, and does the rest in float64. The host does all of it in float64, and adds its split-length sums with Python's compensated sum. A survey record stores which precision each engine used, and a test that compares the two residuals takes its tolerance from those precisions.

Each step of that tolerance uses one result from this book:

  • Theorem 2.2 bounds the float32 rounding of an anchor's split length.
  • The backward form of the summation analysis bounds a float32 run sum of \( r \) nonnegative edges by \( \gamma_{r-1} \) in single precision, and the device's float64 sums of \( A \), \( B \) and \( C \) likewise in double precision.
  • The exact product of two single-precision numbers in double precision means a squared run length adds no rounding on the device.
  • Bound (4.10) covers the host's compensated sums.
  • Model (2.4) covers the product, the square root and the division that form the cosine \( B / \sqrt{AC} \), and Lemma 3.1 combines their factors.
  • Running error analysis bounds the float64 closed form that maps the three squared distances to \( z^2 \).

The steps, and the exact identity that carries a change in the squared distances into \( z^2 \), are checked in higham2002accuracy-kuhner1994-residual-rounding.py. Because such a bound can exceed the actual error by orders of magnitude, a test on it detects a disagreement that rounding cannot explain. It does not detect a drift smaller than the bound.