Carry-save addition preserves the sum full
This proof shows: correctness, termination.
Fix a base β≥2 and n≥1. A digit vector d=(d0,…,dn−1) stands for ⟨d⟩=∑i=0n−1diβi; the digits of c below are allowed to be any nonnegative integers in this formula.
Termination. CSA runs one pass over n positions. CARRY-SAVE-SUM runs m−2 calls of CSA and one addition. The tree form strictly decreases the number of operands at each level while there are more than 2, since a group of three becomes two.
Lemma 1 (one step). Let x,y,z have digits in [0,β) and ⟨x⟩+⟨y⟩+⟨z⟩<βn. Then CSA returns s and c with ⟨s⟩+⟨c⟩=⟨x⟩+⟨y⟩+⟨z⟩, all si∈[0,β), c0=0, and ci≤2, with ci≤1 when β=2.
Proof. At position i, line L1 forms ti=xi+yi+zi with 0≤ti≤3(β−1), and line L2 writes ti=si+βqi with si=timodβ∈[0,β) and qi=⌊ti/β⌋. Since 3(β−1)<3β, qi≤2; for β=2, ti≤3 gives qi≤1. Line L2 stores ci+1=qi for i<n−1 and line L3 sets c0=0. Then
i=0∑n−1tiβi=i=0∑n−1siβi+i=0∑n−2qiβi+1+qn−1βn=⟨s⟩+⟨c⟩+qn−1βn. The left side is ⟨x⟩+⟨y⟩+⟨z⟩<βn, and the right side is at least qn−1βn, so qn−1=0, and the identity is the claim. □
Lemma 2 (the outputs are valid inputs). The digits of c lie in [0,β).
Proof. For β=2, ci≤1<2. For β≥3, ci≤2<β. □
Theorem (many operands). Let x1,…,xm, m≥2, have digits in [0,β) and ∑j⟨xj⟩<βn. Then CARRY-SAVE-SUM returns ∑j⟨xj⟩.
Proof. We show by induction on j≥2 that after the step for j (line L5 for j=2, line L6 for j≥3), the vectors S and C have digits in [0,β) and ⟨S⟩+⟨C⟩=∑k=1j⟨xk⟩. For j=2 this is the input. For the step to j, the three inputs S, C and xj have digits in [0,β) by the induction hypothesis, and their values add up to ∑k≤j⟨xk⟩≤∑k≤m⟨xk⟩<βn. Lemma 1 gives the sum identity and Lemma 2 the digit bounds. After j=m, line L7 adds S and C by an ordinary addition, which returns ⟨S⟩+⟨C⟩=∑k=1m⟨xk⟩; it fits in n digits since this is less than βn. ■
The tree form. Each level applies Lemma 1 to disjoint groups of three operands and keeps the others. By Lemmas 1 and 2, the multiset of operands after the level has digits in [0,β) and the same total, which is below βn, so the hypothesis of Lemma 1 holds for every group of the next level. When at most two operands remain, the final addition returns the total. ■