Math 2.0

Numerical analysis Basic notions and error analysis Theorem

Kahan summation algorithm

Builds on Floating-point arithmeticMachine epsilonRound-off errorBackward error analysis

Statement

Let x1,…,xnx_1, \ldots, x_n be numbers in a binary floating-point system with rounding to nearest and unit roundoff uu (see machine epsilon). Assume that no overflow or underflow occurs. The Kahan summation algorithm computes s^\hat s as follows, in floating-point operations: start with s=0s = 0 and c=0c = 0; for i=1,…,ni = 1, \ldots, n set y=xi−cy = x_i - c, t=s+yt = s + y, c=(t−s)−yc = (t - s) - y, s=ts = t; finally s^=s\hat s = s. Then s^=∑i=1n(1+μi)xiwith∣μi∣≤2u+O(nu2),\hat s = \sum_{i=1}^{n} (1 + \mu_i) x_i \quad\text{with}\quad \abs{\mu_i} \le 2u + O(n u^2), and hence ∣s^−∑i=1nxi∣≤(2u+O(nu2))∑i=1n∣xi∣.\Bigl| \hat s - \sum_{i=1}^{n} x_i \Bigr| \le \bigl( 2u + O(n u^2) \bigr) \sum_{i=1}^{n} \abs{x_i}.

Remarks

The variable cc holds the low-order part lost when yy is added to the large running sum ss. The difference t−st - s recovers what was actually added, and subtracting yy gives minus the round-off error of the addition. This correction is fed back into the next term. The proof tracks the rounding errors of the four operations through the loop; the key point is that, in binary arithmetic, cc captures the rounding error of s+ys + y almost exactly. For comparison, plain recursive summation only gives the bound (n−1)u1−(n−1)u∑∣xi∣\frac{(n-1)u}{1 - (n-1)u} \sum \abs{x_i}, which grows linearly in nn. The result is a backward error bound: s^\hat s is the exact sum of the slightly perturbed terms (1+μi)xi(1 + \mu_i) x_i. The relative error ∣s^−s∣/∣s∣\abs{\hat s - s}/\abs{s} can still be large when ∑∣xi∣≫∣∑xi∣\sum \abs{x_i} \gg \abs{\sum x_i}, that is, when the sum is ill-conditioned. Optimizing compilers that treat floating-point addition as associative can simplify cc to 00 and destroy the method.

Going deeper

For a student

The bound should be compared with the bound γn−1∑∣xi∣\gamma_{n-1} \sum \abs{x_i}, γk=ku/(1−ku)\gamma_k = ku/(1 - ku), for recursive summation and γ⌈log⁡2n⌉∑∣xi∣\gamma_{\lceil \log_2 n \rceil} \sum \abs{x_i} for pairwise summation. Compensated summation costs four floating-point operations per term instead of one, but removes the dependence on nn from the leading term. It is the simplest example of an error-free transformation: the pair (t,−c)(t, -c) represents s+ys + y exactly or nearly exactly. The same idea underlies compensated algorithms for dot products and polynomial evaluation.

Reading path

To understand this page from the ground up, read these 5 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Backward error analysis concept
  2. Floating-point arithmetic concept
  3. Machine epsilon concept
  4. Round-off error concept
  5. Kahan summation algorithm statement

Further reading

  1. Web https://en.wikipedia.org/wiki/Kahan_summation_algorithm
About this page
Tag4JAEKN22Y5
URIm2://4JAEKN22Y5
Kindstatement, theorem
WritingW0 stub
MSC65G50, 65B10
StatusThis copy of the site has no build data. Run m2 status 4JAEKN22Y5.
AboutRound-off error
UsesFloating-point arithmetic, Machine epsilon, Round-off error, Backward error analysis
Same as

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.