Kahan summation has error at most (2u + (n + 4)u^2) times the sum of absolute values full
This proof shows: correctness.
Setting. Binary floating-point arithmetic with precision p≥9, subnormal numbers, round to nearest with any tie rule, and no overflow. The unit roundoff is u=2−p, so u≤2−9. Every addition and subtraction satisfies fl(a±b)=(a±b)(1+ϵ) with ∣ϵ∣≤u; if the result underflows, the operation is exact. For a float x, ex is its exponent (2ex≤∣x∣<2ex+1 for normal x, and ex=emin for subnormal x and for 0).
The iteration. Let s0=c0=0 and, for i=1,…,n,
yi=fl(xi−ci−1),ti=fl(si−1+yi),ci=fl(fl(ti−si−1)−yi),si=ti. The algorithm returns s^=sn. Let A=∑i=1n∣xi∣ and s=∑i=1nxi.
Hypothesis (H). For every i, si−1=0 or esi−1≥eyi.
Theorem. Under (H) and nu≤1/10, ∣s^−s∣≤(2u+(n+4)u2)A.
Step 1 (the correction is exact). Fix i. If si−1=0, then ti=yi, fl(ti−0)=yi and ci=0=ti−(si−1+yi). Otherwise esi−1≥eyi, and the theorem on Fast2Sum applied to a=si−1, b=yi says that z=fl(ti−si−1)=ti−si−1 exactly and fl(yi−z)=yi−z exactly, with ∣yi−z∣≤21ulp(ti). Line L6 computes fl(z−yi)=−fl(yi−z), because rounding to nearest is symmetric. So in both cases
ci=ti−(si−1+yi)exactly,(1) and ∣ci∣≤21ulp(ti). If ti is normal, 21ulp(ti)≤u∣ti∣. If ti is subnormal or zero, the addition si−1+yi is exact, so ci=0. Hence
∣ci∣≤u∣si∣.(2) Step 2 (telescoping). Write yi=(xi−ci−1)(1+ϵi) with ∣ϵi∣≤u. By (1), si−ci=si−1+yi=si−1−ci−1+xi+ϵi(xi−ci−1). Let Di=si−ci−∑j≤ixj; then D0=0 and Di=Di−1+ϵi(xi−ci−1), so
s^−s=sn−j=1∑nxj=cn+i=1∑nϵi(xi−ci−1).(3) Step 3 (bounding the partial sums). Let S=max1≤i≤n∣si∣. The same identity at step i gives si=∑j≤ixj+ci+Di with ∣Di∣≤u∑j≤i∣xj∣+u∑j<i∣cj∣. By (2), ∣cj∣≤uS, so
∣si∣≤A+uS+uA+(i−1)u2S≤(1+u)A+wS,w=u+(n−1)u2. Taking the maximum over i, S(1−w)≤(1+u)A. Since nu≤1/10, w≤u(1+nu)≤1.1u<1/2, so S≤(1+u)A/(1−w).
Step 4 (the bound). From (3) and (2), with c0=0,
∣s^−s∣≤u∣sn∣+uA+ui=1∑n−1∣ci∣≤uA+uS+(n−1)u2S=uA+wS≤uA+1−w(1+u)wA. For 0≤w≤1/2, 1/(1−w)≤1+2w, so (1+u)w/(1−w)≤w+uw+2w2+2uw2. Write w=ua with a=1+(n−1)u≤1.1. Then uw=u2a≤1.1u2, 2w2=2u2a2≤2.42u2 and 2uw2≤2.42u3≤0.01u2, using u≤2−9. So
1−w(1+u)w≤u+(n−1)u2+3.53u2≤u+(n+3)u2, and ∣s^−s∣≤(2u+(n+3)u2)A≤(2u+(n+4)u2)A. □
Remarks. The proof uses round to nearest twice: in the Fast2Sum theorem and in the symmetry fl(−v)=−fl(v). Without (H), line L6 need not be exact: for si−1=2−60 and yi=1, ti=1, fl(ti−si−1)=1 and ci=0, while the true error is −2−60. The general bound (2u+O(nu2))A without (H) is proved by Knuth (TAOCP Volume 2, Section 4.2.2) and by Goldberg (Theorem 8), with a case analysis of the steps where the term is larger than the running sum.