The error bound of Dot2 full
This proof shows: correctness.
Setting. A binary floating-point system with precision p, unit roundoff u=2−p, round to nearest (any tie rule), and the standard model fl(a∘b)=(a∘b)(1+δ) with ∣δ∣≤u. We assume that no overflow occurs, that no product xiyi underflows in the sense that TwoProduct is exact (for TwoProduct with an FMA it suffices that exi+eyi≥emin+p−1), and that nu<1. Write γk=ku/(1−ku), P=∑i∣xiyi∣ and xTy=∑ixiyi. Two facts are used.
- (EFT) TwoSum returns (s,q) with a+b=s+q exactly and ∣q∣≤u∣s∣; TwoProduct returns (h,r) with ab=h+r exactly and ∣r∣≤u∣h∣. The exactness is proved in the encyclopedia pages on TwoSum and TwoProduct; the bounds hold because the error of a rounding to nearest is at most half an ulp of the result, which is at most u times its magnitude (Muller et al., Section 2.3.2, ulp as defined there), and because a sum whose result is subnormal is exact.
- (Gamma) (1+u)(1+γk)≤1+γk+1, and if ∣δj∣≤u for j≤k then ∏j(1+δj)=1+θk with ∣θk∣≤γk, for ku<1 (Higham, Lemma 3.1 and Lemma 3.3).
Notation for the run. Let (p1,s1)=(h1,r1) be the output of L1, and for i≥2 let (hi,ri), (pi,qi) and si be the values computed in L3, L4 and L5 at step i. Put q1=0 and ei=qi+ri (exact, a real number), and let ti=fl(qi+ri) be its computed value for i≥2, with t1=r1=e1.
Lemma 1 (an exact identity). xTy=pn+∑i=1nei.
Proof. By (EFT), x1y1=p1+r1 and, for i≥2, xiyi=hi+ri and pi−1+hi=pi+qi. Adding, ∑i≤kxiyi=pk+∑i≤k(qi+ri) by induction on k. □
Lemma 2 (the small parts are small). ∑i=1n∣ei∣≤γnP.
Proof. Let Sk=∑i≤k∣hi∣. We show by induction that ∣pk∣≤(1+γk−1)Sk and ∑i=2k∣qi∣≤γk−1Sk. For k=1, p1=h1 and the sum is empty. For k≥2, pk=fl(pk−1+hk), so ∣pk∣≤(1+u)(∣pk−1∣+∣hk∣)≤(1+u)(1+γk−2)Sk≤(1+γk−1)Sk by (Gamma). Then ∣qk∣≤u∣pk∣≤u(1+γk−1)Sk=1−(k−1)uuSk, and
i=2∑k∣qi∣≤γk−2Sk−1+1−(k−1)uuSk≤(γk−2+1−(k−1)uu)Sk≤γk−1Sk, since γk−1−γk−2=(1−(k−1)u)(1−(k−2)u)u≥1−(k−1)uu. Next, ∣ri∣≤u∣hi∣ gives ∑i∣ri∣≤uSn, and ∣hi∣≤(1+u)∣xiyi∣ gives Sn≤(1+u)P. So ∑i∣ei∣≤(γn−1+u)(1+u)P. Finally (γn−1+u)(1+u)≤γn: the left side is γn−1+u(1−(n−1)u1+u), while γn−γn−1=1−(n−1)uu⋅1−nu1=1−(n−1)uu(1+1−nunu)≥1−(n−1)uu+u⋅nu≥1−(n−1)uu+u2. □
Lemma 3 (the sum of the small parts). ∣sn−∑iei∣≤γn∑i∣ei∣.
Proof. s1=e1, and for i≥2, ti=ei(1+δi) and si=(si−1+ti)(1+εi) with ∣δi∣,∣εi∣≤u. Unrolling, sn=e1∏j=2n(1+εj)+∑i=2nei(1+δi)∏j=in(1+εj). Each ei is multiplied by at most n factors (1+δ) (n−1 for i=1, n−i+2≤n for i≥2), so by (Gamma) sn=∑iei(1+θ(i)) with ∣θ(i)∣≤γn. □
Theorem. Under the assumptions of the setting, the result res of Dot2 satisfies
∣res−xTy∣≤u∣xTy∣+(1+u)γn2P. If xTy=0 and cond=2P/∣xTy∣ is the condition number of the dot product, the relative error is at most u+21(1+u)γn2cond.
Proof. Let E=∑iei, so xTy=pn+E by Lemma 1, and ∣sn−E∣≤γn2P by Lemmas 2 and 3. L6 computes res=(pn+sn)(1+δ) with ∣δ∣≤u. Then
res−xTy=δ(pn+sn)+(sn−E)=δxTy+(1+δ)(sn−E), so ∣res−xTy∣≤u∣xTy∣+(1+u)γn2P. Dividing by ∣xTy∣=2P/cond gives the relative form. ■
Remarks. Ogita, Rump and Oishi state the bound with γn2 in place of (1+u)γn2; the extra factor here, which changes the bound by a relative 2−53, comes from the cruder treatment of the last addition. The bound says that Dot2 behaves like a dot product computed with unit roundoff about u2 and then rounded to working precision: the first term is the final rounding, and the second is negligible unless cond≳1/(nu)2, roughly u−2/n2. With underflow, TwoProduct can lose the error term, and an additive term proportional to n times the underflow unit must be added (Ogita, Rump and Oishi treat this case); the tests show a case where the bound above fails without it.