Algorithm Search⌘K

Proofs: TwoProduct (Dekker)

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

Dekker's TwoProduct returns the exact error of a rounded product full

This proof shows: correctness.

Setting. Radix 2, precision p≥4p \ge 4, round to nearest with a symmetric tie rule, s=⌈p/2⌉s = \lceil p/2 \rceil, and normal floats aa, bb with ea+eb≥emin⁡+p−1e_a + e_b \ge e_{\min} + p - 1. No operation overflows. We use one fact.

  • (F1) If U≥2emin⁡−p+1U \ge 2^{e_{\min} - p + 1} is a power of two and kk is an integer with ∣k∣≤2p|k| \le 2^p, then kUkU is a float (when it does not overflow).

Theorem. Lines L1 to L7 return x=fl(ab)x = \mathrm{fl}(ab) and y=ab−xy = ab - x exactly.

Proof. Multiplying aa or bb 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<21 \le a, b < 2 and write q=21−pq = 2^{1-p}, so aa and bb are multiples of qq.

Step 1: the parts. By the theorem on Veltkamp splitting with split point ss, a=ah+ala = a_h + a_l with ah=ka2sqa_h = k_a 2^s q, ∣ka∣≤2p−s|k_a| \le 2^{p-s}, ∣ah∣≤2|a_h| \le 2, and al=maqa_l = m_a q with ∣ma∣≤2s−1|m_a| \le 2^{s-1}; the same holds for bb.

Step 2: the products of parts are exact. ahbh=kakb 22sq2a_h b_h = k_a k_b\, 2^{2s} q^2 with ∣kakb∣≤22p−2s≤2p|k_a k_b| \le 2^{2p - 2s} \le 2^p because 2s≥p2s \ge p. ahbl=kamb 2sq2a_h b_l = k_a m_b\, 2^s q^2 with ∣kamb∣≤2p−1|k_a m_b| \le 2^{p-1}, and likewise albha_l b_h. albl=mamb q2a_l b_l = m_a m_b\, q^2 with ∣mamb∣≤22s−2≤2p−1|m_a m_b| \le 2^{2s - 2} \le 2^{p-1} because 2s≤p+12s \le p + 1. By (F1) all four are floats, so the inner multiplications in lines L4 to L7 are exact. In size, ∣ahbl∣,∣albh∣≤2sq|a_h b_l|, |a_l b_h| \le 2^s q and ∣albl∣≤22s−2q2=22s−1−pq≤q|a_l b_l| \le 2^{2s-2} q^2 = 2^{2s - 1 - p} q \le q.

Step 3: the rounding error of xx. ab∈[1,4)ab \in [1, 4), so ulp(x)≤2q\mathrm{ulp}(x) \le 2q and ∣ab−x∣≤q|ab - x| \le q. Also xx is a multiple of qq.

Step 4: lines L4, L5 and L6 are exact. Since ab=ahbh+ahbl+albh+alblab = a_h b_h + a_h b_l + a_l b_h + a_l b_l,

ahbh−x=(ab−x)−ahbl−albh−albl.a_h b_h - x = (ab - x) - a_h b_l - a_l b_h - a_l b_l.
  • ahbha_h b_h is a multiple of 22s+1−pq2^{2s+1-p} q, and 2s+1−p≥12s + 1 - p \ge 1, so ahbh−xa_h b_h - x is a multiple of qq. Its size is at most q+2⋅2sq+q=(2s+1+2)qq + 2 \cdot 2^s q + q = (2^{s+1} + 2) q. Since s+1≤p−1s + 1 \le p - 1 for p≥4p \ge 4, 2s+1+2≤2p2^{s+1} + 2 \le 2^p and by (F1) t1=ahbh−xt_1 = a_h b_h - x exactly.
  • Let q′=2s+1−pq=2sq2q' = 2^{s+1-p} q = 2^s q^2; qq is a multiple of q′q', and so are ahbla_h b_l and albha_l b_h. The exact value t1+ahbl=(ab−x)−albh−alblt_1 + a_h b_l = (ab - x) - a_l b_h - a_l b_l is a multiple of q′q' of size at most (2s+2)q=(2s+2)2p−s−1q′(2^s + 2)q = (2^s + 2) 2^{p-s-1} q'. That integer factor is 2p−1+2p−s≤2p2^{p-1} + 2^{p-s} \le 2^p, so t2=t1+ahblt_2 = t_1 + a_h b_l exactly.
  • The exact value t2+albh=(ab−x)−alblt_2 + a_l b_h = (ab - x) - a_l b_l is a multiple of q′q' of size at most 2q=2p−sq′2q = 2^{p-s} q', so t3=t2+albht_3 = t_2 + a_l b_h exactly.

Step 5: line L7 is exact. t3+albl=ab−xt_3 + a_l b_l = ab - x is a multiple of q2q^2 (both terms are) with ∣ab−x∣≤q=2p−1q2|ab - x| \le q = 2^{p-1} q^2. By (F1) it is a float, so y=ab−xy = ab - x exactly.

Step 6: the exponent condition. Before scaling, the finest unit used is q2q^2 times 2ea+eb2^{e_a + e_b}, that is 2ea+eb+2−2p2^{e_a + e_b + 2 - 2p}. (F1) requires it to be at least 2emin⁡−p+12^{e_{\min} - p + 1}, which is ea+eb≥emin⁡+p−1e_a + e_b \ge e_{\min} + p - 1. The coarser units q′q' and qq then satisfy (F1) too, and the splits operate on normal aa and bb. □\square

The FMA variant. With xx any faithful rounding of abab (in particular round to nearest with any tie rule), ∣ab−x∣<ulp(x)≤2q=2pq2|ab - x| < \mathrm{ulp}(x) \le 2q = 2^p q^2, and ab−xab - x is a multiple of q2q^2, so under the same exponent condition it is a float by (F1). The FMA computes fl(ab−x)\mathrm{fl}(ab - x) with one rounding, and the rounding of a float is that float, so fma(a,b,−x)=ab−x\mathrm{fma}(a, b, -x) = ab - x. This needs no split and so no condition on overflow of CaCa, only that abab does not overflow.

Back to TwoProduct (Dekker)