Dekker's TwoProduct returns the exact error of a rounded product full
This proof shows: correctness.
Setting. Radix 2, precision p≥4, round to nearest with a symmetric tie rule, s=⌈p/2⌉, and normal floats a, b with ea+eb≥emin+p−1. No operation overflows. We use one fact.
- (F1) If U≥2emin−p+1 is a power of two and k is an integer with ∣k∣≤2p, then kU is a float (when it does not overflow).
Theorem. Lines L1 to L7 return x=fl(ab) and y=ab−x exactly.
Proof. Multiplying a or b by a power of two, or negating it, scales every intermediate value by the same factor, as long as no unit drops below the subnormal spacing; Step 6 checks that. So assume 1≤a,b<2 and write q=21−p, so a and b are multiples of q.
Step 1: the parts. By the theorem on Veltkamp splitting with split point s, a=ah+al with ah=ka2sq, ∣ka∣≤2p−s, ∣ah∣≤2, and al=maq with ∣ma∣≤2s−1; the same holds for b.
Step 2: the products of parts are exact. ahbh=kakb22sq2 with ∣kakb∣≤22p−2s≤2p because 2s≥p. ahbl=kamb2sq2 with ∣kamb∣≤2p−1, and likewise albh. albl=mambq2 with ∣mamb∣≤22s−2≤2p−1 because 2s≤p+1. By (F1) all four are floats, so the inner multiplications in lines L4 to L7 are exact. In size, ∣ahbl∣,∣albh∣≤2sq and ∣albl∣≤22s−2q2=22s−1−pq≤q.
Step 3: the rounding error of x. ab∈[1,4), so ulp(x)≤2q and ∣ab−x∣≤q. Also x is a multiple of q.
Step 4: lines L4, L5 and L6 are exact. Since ab=ahbh+ahbl+albh+albl,
ahbh−x=(ab−x)−ahbl−albh−albl.
- ahbh is a multiple of 22s+1−pq, and 2s+1−p≥1, so ahbh−x is a multiple of q. Its size is at most q+2⋅2sq+q=(2s+1+2)q. Since s+1≤p−1 for p≥4, 2s+1+2≤2p and by (F1) t1=ahbh−x exactly.
- Let q′=2s+1−pq=2sq2; q is a multiple of q′, and so are ahbl and albh. The exact value t1+ahbl=(ab−x)−albh−albl is a multiple of q′ of size at most (2s+2)q=(2s+2)2p−s−1q′. That integer factor is 2p−1+2p−s≤2p, so t2=t1+ahbl exactly.
- The exact value t2+albh=(ab−x)−albl is a multiple of q′ of size at most 2q=2p−sq′, so t3=t2+albh exactly.
Step 5: line L7 is exact. t3+albl=ab−x is a multiple of q2 (both terms are) with ∣ab−x∣≤q=2p−1q2. By (F1) it is a float, so y=ab−x exactly.
Step 6: the exponent condition. Before scaling, the finest unit used is q2 times 2ea+eb, that is 2ea+eb+2−2p. (F1) requires it to be at least 2emin−p+1, which is ea+eb≥emin+p−1. The coarser units q′ and q then satisfy (F1) too, and the splits operate on normal a and b. □
The FMA variant. With x any faithful rounding of ab (in particular round to nearest with any tie rule), ∣ab−x∣<ulp(x)≤2q=2pq2, and ab−x is a multiple of q2, so under the same exponent condition it is a float by (F1). The FMA computes fl(ab−x) with one rounding, and the rounding of a float is that float, so fma(a,b,−x)=ab−x. This needs no split and so no condition on overflow of Ca, only that ab does not overflow.