Algorithm Search⌘K

Proofs: Neumaier summation

These are the human proofs of Neumaier summation, at full length.

Neumaier summation is as accurate as summation in twice the working precision full

This proof shows: correctness.

Setting. Binary floating-point arithmetic with round to nearest (any tie rule), subnormal numbers and no overflow; u=2−pu = 2^{-p}. Every addition and subtraction satisfies fl(a±b)=(a±b)(1+δ)\mathrm{fl}(a \pm b) = (a \pm b)(1 + \delta) with ∣δ∣≤u|\delta| \le u, and is exact if its result is subnormal. γk=ku/(1−ku)\gamma_k = ku/(1 - ku) for ku<1ku < 1, with γ0=0\gamma_0 = 0; γk\gamma_k is increasing in kk.

The iteration. Let t0=0t_0 = 0 and, for i=1,…,ni = 1, \ldots, n, ti=fl(ti−1+xi)t_i = \mathrm{fl}(t_{i-1} + x_i) and qi=fl(fl(a−ti)+b)q_i = \mathrm{fl}(\mathrm{fl}(a - t_i) + b), where (a,b)=(ti−1,xi)(a, b) = (t_{i-1}, x_i) if ∣ti−1∣≥∣xi∣|t_{i-1}| \ge |x_i| and (a,b)=(xi,ti−1)(a, b) = (x_i, t_{i-1}) otherwise. Let c0=0c_0 = 0, ci=fl(ci−1+qi)c_i = \mathrm{fl}(c_{i-1} + q_i), and s^=fl(tn+cn)\hat s = \mathrm{fl}(t_n + c_n). Let A=∑i=1n∣xi∣A = \sum_{i=1}^n |x_i|, s=∑i=1nxis = \sum_{i=1}^n x_i, and assume (n−1)u<1(n - 1)u < 1.

Theorem. qi=ti−1+xi−tiq_i = t_{i-1} + x_i - t_i exactly for every ii, s=tn+∑i=1nqis = t_n + \sum_{i=1}^n q_i, and

∣s^−s∣≤u∣s∣+(1+u)γn−2γn−1A.|\hat s - s| \le u|s| + (1 + u)\gamma_{n-2}\gamma_{n-1} A.

If moreover n(n−2)u≤1n(n - 2)u \le 1, then ∣s^−s∣≤u∣s∣+γn−12A|\hat s - s| \le u|s| + \gamma_{n-1}^2 A.

Step 1 (exact errors). If ∣a∣≥∣b∣|a| \ge |b| then ea≥ebe_a \ge e_b, so by the theorem on Fast2Sum, fl(a−ti)=a−ti\mathrm{fl}(a - t_i) = a - t_i and the error b−(ti−a)b - (t_i - a) is a float; here the algorithm computes fl((a−ti)+b)\mathrm{fl}((a - t_i) + b), which is that same float, so qi=a+b−ti=ti−1+xi−tiq_i = a + b - t_i = t_{i-1} + x_i - t_i. Summing over ii telescopes: ∑iqi=∑ixi+t0−tn=s−tn\sum_i q_i = \sum_i x_i + t_0 - t_n = s - t_n.

Step 2 (size of the errors). qiq_i is the rounding error of ti=fl(ti−1+xi)t_i = \mathrm{fl}(t_{i-1} + x_i), so ∣qi∣≤u∣ti∣|q_i| \le u|t_i| (if tit_i is normal, ∣qi∣≤12ulp(ti)≤u∣ti∣|q_i| \le \tfrac12\mathrm{ulp}(t_i) \le u|t_i|; if tit_i is subnormal, the addition is exact and qi=0q_i = 0). Also q1=0q_1 = 0, since t0=0t_0 = 0 makes the first addition exact. The tit_i are the partial sums of a plain loop, and by the standard analysis of recursive summation (Higham, Section 4.2, from Lemma 3.1), ti=∑j≤ixj(1+θj(i))t_i = \sum_{j \le i} x_j (1 + \theta^{(i)}_j) with ∣θj(i)∣≤γi−1|\theta^{(i)}_j| \le \gamma_{i-1}, so ∣ti∣≤(1+γi−1)∑j≤i∣xj∣≤(1+γn−1)A|t_i| \le (1 + \gamma_{i-1})\sum_{j \le i}|x_j| \le (1 + \gamma_{n-1})A. Hence

Q:=∑i=1n∣qi∣=∑i=2n∣qi∣≤(n−1)u(1+γn−1)A=γn−1A,Q := \sum_{i=1}^n |q_i| = \sum_{i=2}^n |q_i| \le (n - 1)u(1 + \gamma_{n-1})A = \gamma_{n-1}A,

because (n−1)u(1+γn−1)=(n−1)u/(1−(n−1)u)=γn−1(n - 1)u(1 + \gamma_{n-1}) = (n - 1)u/(1 - (n - 1)u) = \gamma_{n-1}.

Step 3 (summing the errors). Since q1=0q_1 = 0, c1=0c_1 = 0 and c2=q2c_2 = q_2 exactly, and cnc_n is a plain loop over the n−1n - 1 terms q2,…,qnq_2, \ldots, q_n, which makes n−2n - 2 rounded additions. By the same analysis, ∣cn−∑iqi∣≤γn−2Q≤γn−2γn−1A|c_n - \sum_i q_i| \le \gamma_{n-2} Q \le \gamma_{n-2}\gamma_{n-1}A. (For n≤2n \le 2 this error is 00.)

Step 4 (the final addition). Let E=cn−∑iqiE = c_n - \sum_i q_i. Then tn+cn=s+Et_n + c_n = s + E by Step 1, and s^=(s+E)(1+δ)\hat s = (s + E)(1 + \delta) with ∣δ∣≤u|\delta| \le u. So

∣s^−s∣=∣δs+(1+δ)E∣≤u∣s∣+(1+u)∣E∣≤u∣s∣+(1+u)γn−2γn−1A.|\hat s - s| = |\delta s + (1 + \delta)E| \le u|s| + (1 + u)|E| \le u|s| + (1 + u)\gamma_{n-2}\gamma_{n-1}A.

Step 5 (the simpler form). It suffices that (1+u)γn−2≤γn−1(1 + u)\gamma_{n-2} \le \gamma_{n-1} for n≥3n \ge 3 (for n≤2n \le 2 the left side is 00). Multiplying out with the positive denominators, this is (n−2)(1+u)(1−(n−1)u)≤(n−1)(1−(n−2)u)(n - 2)(1 + u)(1 - (n - 1)u) \le (n - 1)(1 - (n - 2)u). The left side is at most (n−2)(1+u)=n−2+(n−2)u(n - 2)(1 + u) = n - 2 + (n - 2)u, and the inequality n−2+(n−2)u≤n−1−(n−1)(n−2)un - 2 + (n - 2)u \le n - 1 - (n - 1)(n - 2)u is equivalent to n(n−2)u≤1n(n - 2)u \le 1. □\square

Remark. The theorem needs no assumption on the order or the signs of the terms. It says that s^\hat s is the rounding of a value within γn−12A\gamma_{n-1}^2 A (to first order, n2u2An^2 u^2 A) of ss, which is what a plain loop in a format with unit roundoff u2u^2 would guarantee, up to the constant.

Back to Neumaier summation