Fast2Sum returns the exact error of a rounded addition full
This proof shows: correctness.
Setting. Binary floating-point arithmetic with precision p≥2, minimal exponent emin, subnormal numbers, and an unbounded maximal exponent (that is, no overflow occurs). Every operation is rounded to nearest, with any rule for breaking ties. For a float x=0 let ex be the integer with 2ex≤∣x∣<2ex+1 if x is normal, and ex=emin if x is subnormal; let e0=emin. Write Ux=2ex−p+1. Every float x is an integer multiple of Ux, and every integer multiple kU of U=2e−p+1 with e≥emin and ∣k∣≤2p is a float (if ∣k∣<2p it has at most p significant bits, and if ∣k∣=2p it is a power of two).
Theorem. Let a and b be floats with ea≥eb, and let s=fl(a+b), z=fl(s−a), t=fl(b−z). Then z=s−a and t=b−z exactly, so
s+t=a+b,∣t∣≤21ulp(s). Proof. Let U=Ub=2eb−p+1. Since ea≥eb, Ua is a multiple of U, so a, b and a+b are integer multiples of U.
Step 1 (the nearest float is closer than a). The float a is a candidate for the rounding of a+b, so ∣s−(a+b)∣≤∣a−(a+b)∣=∣b∣. Hence
∣s−a∣≤∣s−(a+b)∣+∣b∣≤2∣b∣.(1) Step 2 (a small sum is exact). If ∣a+b∣≤2eb+1, then a+b=kU with ∣k∣≤2p, which is a float, so s=a+b. Then s−a=b is a float and z=b; then b−z=0 and t=0. The claims hold. From now on assume ∣a+b∣>2eb+1. Since 2eb+1 is a float and rounding is monotone, ∣s∣≥2eb+1, so es≥eb+1 and s is a multiple of 2U.
Step 3 (s−a is a float). Two cases.
- If ea≥eb+1, then a is also a multiple of 2U, so s−a=k⋅2U for an integer k, and by (1), ∣s−a∣≤2∣b∣<2eb+2=2p⋅2U. So ∣k∣<2p and s−a is a float.
- If ea=eb, then a and b have the same sign: otherwise ∣a+b∣<max(∣a∣,∣b∣)<2eb+1, which Step 2 excluded. Let δ=s−(a+b). It is a multiple of U (both s and a+b are) and ∣δ∣≤21ulp(a+b). As ∣a+b∣<2eb+2, ulp(a+b)≤2U, so δ∈{−U,0,U}. Then s−a=b+δ is a multiple of U with ∣b+δ∣≤∣b∣+U≤(2eb+1−U)+U=2eb+1=2pU, because ∣b∣≤2eb+1−U is the largest multiple of U below 2eb+1. So s−a is a float.
In both cases the exact difference s−a is a float, so its correct rounding is itself: z=s−a.
Step 4 (b−z is a float). Now b−z=(a+b)−s=−δ. It is a multiple of U, and by Step 1, ∣δ∣≤∣b∣<2eb+1=2pU. So it is a float and t=b−z=(a+b)−s. Then s+t=a+b.
Step 5 (the size of t). ∣t∣=∣s−(a+b)∣≤21ulp(a+b) for rounding to nearest, with the ulp of Muller et al., Section 2.3.2. If ∣s∣≥∣a+b∣, then ulp(a+b)≤ulp(s) because the ulp is nondecreasing in the magnitude. If ∣s∣<∣a+b∣, then s lies in the same binade as a+b, since the power of two at the bottom of that binade is a float between them, so the two ulps are equal. In both cases ∣t∣≤21ulp(s). ■
Remarks. The hypothesis ea≥eb holds in particular when ∣a∣≥∣b∣. Underflow does not break the theorem: the proof uses only the spacing of floats, which is uniform in the subnormal range. Overflow does: if a+b overflows, s=±∞ and z and t are infinite or NaN. Without the hypothesis the theorem fails; for a=2−60 and b=1, the algorithm returns s=1 and t=0.