Algorithm Search⌘K

Proofs: Fast2Sum (Dekker)

These are the human proofs of Fast2Sum (Dekker), at full length.

Fast2Sum returns the exact error of a rounded addition full

This proof shows: correctness.

Setting. Binary floating-point arithmetic with precision p≥2p \ge 2, minimal exponent emin⁡e_{\min}, 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≠0x \ne 0 let exe_x be the integer with 2ex≤∣x∣<2ex+12^{e_x} \le |x| < 2^{e_x + 1} if xx is normal, and ex=emin⁡e_x = e_{\min} if xx is subnormal; let e0=emin⁡e_0 = e_{\min}. Write Ux=2ex−p+1U_x = 2^{e_x - p + 1}. Every float xx is an integer multiple of UxU_x, and every integer multiple kUkU of U=2e−p+1U = 2^{e - p + 1} with e≥emin⁡e \ge e_{\min} and ∣k∣≤2p|k| \le 2^{p} is a float (if ∣k∣<2p|k| < 2^{p} it has at most pp significant bits, and if ∣k∣=2p|k| = 2^{p} it is a power of two).

Theorem. Let aa and bb be floats with ea≥ebe_a \ge e_b, and let s=fl(a+b)s = \mathrm{fl}(a + b), z=fl(s−a)z = \mathrm{fl}(s - a), t=fl(b−z)t = \mathrm{fl}(b - z). Then z=s−az = s - a and t=b−zt = b - z exactly, so

s+t=a+b,∣t∣≤12ulp(s).s + t = a + b, \qquad |t| \le \tfrac12\mathrm{ulp}(s).

Proof. Let U=Ub=2eb−p+1U = U_b = 2^{e_b - p + 1}. Since ea≥ebe_a \ge e_b, UaU_a is a multiple of UU, so aa, bb and a+ba + b are integer multiples of UU.

Step 1 (the nearest float is closer than aa). The float aa is a candidate for the rounding of a+ba + b, so ∣s−(a+b)∣≤∣a−(a+b)∣=∣b∣|s - (a + b)| \le |a - (a + b)| = |b|. Hence

∣s−a∣≤∣s−(a+b)∣+∣b∣≤2∣b∣.(1)|s - a| \le |s - (a + b)| + |b| \le 2|b|. \tag{1}

Step 2 (a small sum is exact). If ∣a+b∣≤2eb+1|a + b| \le 2^{e_b + 1}, then a+b=kUa + b = kU with ∣k∣≤2p|k| \le 2^{p}, which is a float, so s=a+bs = a + b. Then s−a=bs - a = b is a float and z=bz = b; then b−z=0b - z = 0 and t=0t = 0. The claims hold. From now on assume ∣a+b∣>2eb+1|a + b| > 2^{e_b + 1}. Since 2eb+12^{e_b + 1} is a float and rounding is monotone, ∣s∣≥2eb+1|s| \ge 2^{e_b + 1}, so es≥eb+1e_s \ge e_b + 1 and ss is a multiple of 2U2U.

Step 3 (s−as - a is a float). Two cases.

  • If ea≥eb+1e_a \ge e_b + 1, then aa is also a multiple of 2U2U, so s−a=k⋅2Us - a = k \cdot 2U for an integer kk, and by (1), ∣s−a∣≤2∣b∣<2eb+2=2p⋅2U|s - a| \le 2|b| < 2^{e_b + 2} = 2^{p} \cdot 2U. So ∣k∣<2p|k| < 2^{p} and s−as - a is a float.
  • If ea=ebe_a = e_b, then aa and bb have the same sign: otherwise ∣a+b∣<max⁡(∣a∣,∣b∣)<2eb+1|a + b| < \max(|a|, |b|) < 2^{e_b + 1}, which Step 2 excluded. Let δ=s−(a+b)\delta = s - (a + b). It is a multiple of UU (both ss and a+ba + b are) and ∣δ∣≤12ulp(a+b)|\delta| \le \tfrac12 \mathrm{ulp}(a + b). As ∣a+b∣<2eb+2|a + b| < 2^{e_b + 2}, ulp(a+b)≤2U\mathrm{ulp}(a + b) \le 2U, so δ∈{−U,0,U}\delta \in \{-U, 0, U\}. Then s−a=b+δs - a = b + \delta is a multiple of UU with ∣b+δ∣≤∣b∣+U≤(2eb+1−U)+U=2eb+1=2pU|b + \delta| \le |b| + U \le (2^{e_b + 1} - U) + U = 2^{e_b + 1} = 2^{p} U, because ∣b∣≤2eb+1−U|b| \le 2^{e_b + 1} - U is the largest multiple of UU below 2eb+12^{e_b + 1}. So s−as - a is a float.

In both cases the exact difference s−as - a is a float, so its correct rounding is itself: z=s−az = s - a.

Step 4 (b−zb - z is a float). Now b−z=(a+b)−s=−δb - z = (a + b) - s = -\delta. It is a multiple of UU, and by Step 1, ∣δ∣≤∣b∣<2eb+1=2pU|\delta| \le |b| < 2^{e_b + 1} = 2^{p} U. So it is a float and t=b−z=(a+b)−st = b - z = (a + b) - s. Then s+t=a+bs + t = a + b.

Step 5 (the size of tt). ∣t∣=∣s−(a+b)∣≤12ulp(a+b)|t| = |s - (a + b)| \le \tfrac12\mathrm{ulp}(a + b) for rounding to nearest, with the ulp of Muller et al., Section 2.3.2. If ∣s∣≥∣a+b∣|s| \ge |a + b|, then ulp(a+b)≤ulp(s)\mathrm{ulp}(a + b) \le \mathrm{ulp}(s) because the ulp is nondecreasing in the magnitude. If ∣s∣<∣a+b∣|s| < |a + b|, then ss lies in the same binade as a+ba + 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∣≤12ulp(s)|t| \le \tfrac12\mathrm{ulp}(s). ■\blacksquare

Remarks. The hypothesis ea≥ebe_a \ge e_b holds in particular when ∣a∣≥∣b∣|a| \ge |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+ba + b overflows, s=±∞s = \pm\infty and zz and tt are infinite or NaN. Without the hypothesis the theorem fails; for a=2−60a = 2^{-60} and b=1b = 1, the algorithm returns s=1s = 1 and t=0t = 0.

Back to Fast2Sum (Dekker)