Pairwise summation satisfies the gamma of ceil(log2 n) error bound full
This proof shows: correctness.
Setting. A floating-point system with unit roundoff u in which every addition satisfies the standard model fl(a+b)=(a+b)(1+δ), ∣δ∣≤u. This holds for round to nearest with u=21β1−p and for directed rounding with u=β1−p, as long as the result does not overflow; an addition that underflows is exact, so it satisfies the model with δ=0. Write γh=hu/(1−hu) for hu<1.
Lemma 1 (Higham, Lemma 3.1). If ∣δj∣≤u and ρj=±1 for j=1,…,h, and hu<1, then ∏j=1h(1+δj)ρj=1+θh with ∣θh∣≤γh. Only the case ρj=1 is needed here, and for it the proof is short: ∣∏(1+δj)−1∣≤(1+u)h−1, and (1+u)h≤1/(1−u)h≤1/(1−hu), the last step by Bernoulli's inequality (1−u)h≥1−hu. So (1+u)h−1≤hu/(1−hu)=γh.
The tree. A run of PAIRWISE-SUM on x1,…,xn, n≥1, defines a binary tree: a call with n≤b terms is a chain in which the terms are added one by one, and a call with n>b terms is a node whose two children are the calls on the two halves. Every addition (line L4 or line L9) is an internal node with two inputs. For a term xi, let hi be the number of additions on the path from xi to the root, and let h=maxihi.
Lemma 2 (the computed value). If no addition overflows and hu<1, the value returned by any call on a range R is ∑i∈Rxi∏j∈Pi(1+δj), where Pi is the set of additions on the path from xi to the root of that call, and ∣δj∣≤u.
Proof. By induction on the size of the call. A single term is returned unchanged, and the product over the empty path is 1. For a chain in lines L3 and L4, after the step that adds xk the value is fl(s+xk)=(s+xk)(1+δ); by induction s has the stated form for the earlier terms, and multiplying by 1+δ adds the new addition to the path of every earlier term and of xk. For line L9, fl(s1+s2)=(s1+s2)(1+δ), and s1 and s2 have the stated form by induction on the two halves; the addition of line L9 is on the path of every term of the range. □
Theorem. Under the same assumptions, s^=∑i=1nxi(1+θi) with ∣θi∣≤γhi≤γh, hence
∣s^−s∣≤γhi=1∑n∣xi∣. Proof. Apply Lemma 2 to the top-level call and Lemma 1 to each product, which has hi≤h factors; γ is increasing in h. Then ∣s^−s∣=∣∑xiθi∣≤∑∣xi∣∣θi∣≤γh∑∣xi∣. □
Lemma 3 (the depth for b=1). With b=1, h=d(n) where d(1)=0 and d(n)=1+d(⌈n/2⌉) for n≥2, and d(n)=⌈log2n⌉.
Proof. A call on n≥2 terms makes one addition and two calls on ⌊n/2⌋ and ⌈n/2⌉ terms. The largest path goes through the larger half, because d is nondecreasing (by induction: if m≤n then ⌈m/2⌉≤⌈n/2⌉). So h=1+d(⌈n/2⌉). For the closed form, let k=⌈log2n⌉≥1 for n≥2, so 2k−1<n≤2k. Then 2k−2<n/2≤2k−1, and since 2k−1 is an integer, ⌈n/2⌉≤2k−1; also ⌈n/2⌉≥n/2>2k−2. Hence ⌈log2⌈n/2⌉⌉=k−1, and by induction d(n)=1+(k−1)=k. □
Lemma 4 (the depth with blocks). With block size b≥1, h≤(b−1)+⌈log2⌈n/b⌉⌉ for n≥1.
Proof. After k halvings the largest range has ⌈n/2k⌉ terms (the ceiling of a ceiling of halves is the ceiling of n/2k). Recursion stops on a path once the range has at most b terms, which happens after at most K halvings, the least k with ⌈n/2k⌉≤b, that is 2k≥n/b, that is 2k≥⌈n/b⌉; so K=⌈log2⌈n/b⌉⌉. Each halving contributes one addition (line L9) to the path, and the leaf chain contributes at most b−1 additions. □
Bottom-up variant. Level ℓ of the bottom-up method has ⌈n/2ℓ⌉ values, each the sum of a contiguous group of at most 2ℓ terms, and each level adds at most one addition to the path of every term. After ⌈log2n⌉ levels one value is left, so the same theorem holds with h=⌈log2n⌉.
Cost. Every addition merges two values into one, and the algorithm starts with n values and ends with one, so it makes exactly n−1 additions.