These are the human proofs of Reproducible floating-point summation, at full length.
K-fold summation is exact in every fold, hence order independent, with a bounded error full
This proof shows: correctness.
Setting. Binary floating point with precision p≥4 and round to nearest under any tie rule. x1,…,xn are finite floats, not all zero, with 2≤2n≤2p−1. Let m=maxi∣xi∣, c=⌈log2n⌉+1 and Mj=2aj with aj=⌈log2m⌉+c+(j−1)(c−p). Assume no overflow (M1≤2emax) and aK≥emin+1, so that every unit Mj2−p is at least the smallest subnormal 2emin−p+1 and Mj/2 is normal. (The implementation keeps this second condition by clamping, which is treated in Step 6.) We use two facts.
(F1) Sterbenz. If a,b are floats with b/2≤a≤2b, then a−b is a float.
(F2) If a,b are floats and s=fl(a+b), then a+b−s is a float. This holds with or without underflow.
Theorem. Let vi(1)=xi, and for j=1,…,K let qi(j)=fl(fl(Mj+vi(j))−Mj) and vi(j+1)=fl(vi(j)−qi(j)). Then:
qi(j)=s−Mj and vi(j+1)=vi(j)−qi(j) exactly, where s=fl(Mj+vi(j)).
For every order of i, line L9 computes Tj=∑iqi(j) exactly. So Tj depends only on the multiset {xi}. The same holds when the index set is partitioned, each part is summed separately, and the part sums are added in any order.
∑ixi−∑jTj≤nMK2−p<2nm(4n2−p)K.
Step 1 (input bound). We show ∣vi(j)∣≤Mj/(2n) for all j≤K. For j=1, m≤2⌈log2m⌉ and 2n≤2c, so 2nm≤M1. For j≥1, Step 3 below gives ∣vi(j+1)∣≤Mj2−p=Mj+12−c≤Mj+1/(2n). The argument is an induction on j, in which Steps 2 and 3 use only the bound for the current j.
Step 2 (exact extraction). Fix j and i, and write M=Mj, v=vi(j). Since ∣v∣≤M/(2n)≤M/2, we have M/2≤M+v≤3M/2. The numbers M/2 and 3M/2 are floats, because p≥2 and M/2 is normal. Rounding is monotone, so s=fl(M+v)∈[M/2,3M/2]. By (F1), s−M is a float, so q=s−M exactly. Then v−q=(M+v)−s, which is a float by (F2), so fl(v−q)=v−q. This proves part 1.
Step 3 (sizes and grid). Every float in [M/2,2M) is a multiple of ulp(M/2)=M2−p, and so is M. Hence q=s−M is an integer multiple of U=M2−p. The residual is the rounding error of M+v, so ∣v−q∣≤21ulp(s)≤21⋅2M2−p=U, because s<2M gives ulp(s)≤2U. So ∣q∣≤∣v∣+U≤M/(2n)+U.
Step 4 (exact accumulation). Let A be any subset of the indices. Then ∑i∈Aqi(j)≤n(M/(2n)+U)=M/2+nU≤M, since nU=nM2−p≤M/2 by 2n≤2p−1. The sum is an integer multiple of U of magnitude at most M=2pU. Every such number is a float: it is kU with ∣k∣≤2p, and U≥2emin−p+1. Every partial sum formed in L9, in any order and over any partition, is such a subset sum. So every addition in L9 is exact, and the final Tj equals ∑iqi(j). This proves part 2.
Step 5 (error). By part 1, xi=∑j=1Kqi(j)+vi(K+1) for each i. Summing over i, ∑ixi=∑jTj+E with E=∑ivi(K+1), and by Step 3, ∣E∣≤nMK2−p. For the explicit form, 2⌈log2m⌉<2m and 2c<4n give M1<8nm, and 2c−p<4n2−p. So MK<8nm(4n2−p)K−1, and nMK2−p<2nm(4n2−p)K. This proves part 3.
Step 6 (the clamped bottom level). The implementation never uses an exponent below emin+1. If aj would fall below it, it uses aj=emin+1 instead. A larger boundary keeps Step 1 true, since ∣v∣≤Mj−12−p≤2emin+1/(2n) whenever aj−1+c−p≤emin+1. With M=2emin+1 the unit is U=2emin−p+1, the smallest subnormal. After that level every residual is 0 or ±U. The final level uses M=0, so q=v exactly and v(K+1)=0. Its partial sums are multiples of U of magnitude at most nU≤2pU, so they are floats. Parts 1 and 2 hold for this level, and part 3 holds with E=0.
Corollary. The returned value fl(T1+fl(T2+⋯)) is computed from the Tj in a fixed order. So it is the same for every order and partition of the input. By the standard model, ∣R−∑jTj∣≤γK−1∑j∣Tj∣, and with part 3,