The carry-lookahead adder computes the sum of its inputs full
This proof shows: correctness, termination.
Let n≥1, r≥2, and let ai,bi,c0∈{0,1}. Define the true carries by c0∗=c0 and ci+1∗=gi∨(pi∧ci∗) with gi=ai∧bi and pi=ai⊕bi (line L1). Then ai+bi+ci∗=(ai⊕bi⊕ci∗)+2ci+1∗ for each i: if pi=1 the left side is 1+ci∗, and if pi=0 it is 2gi+ci∗. Multiplying by 2i and summing gives
a+b+c0=i=0∑n−1(pi⊕ci∗)2i+cn∗2n, so it suffices to show that leaf i receives the carry-in ci∗ and that line L10 gives cn∗.
Termination. Each pass of the loop L3 to L6 replaces a level of t≥1 nodes by ⌈t/r⌉ nodes. If t≥2 this is less than t, and if t=1 the pass makes one group, and the loop stops. So the loop runs h=max(1,⌈logrn⌉) times. The downward pass visits each of the finitely many nodes once.
Notation. Each node v covers an interval of positions [ℓv,uv]: a leaf i covers [i,i], and a group covers the union of the intervals of its children, which are consecutive and listed from low to high, because line L4 cuts each level into runs of consecutive nodes and the leaves are in order.
Lemma 1 (unrolling). Let (x0,y0),…,(xm−1,ym−1) and bits d0,…,dm satisfy dj+1=xj∨(yj∧dj) for 0≤j<m. Then for each k with 1≤k≤m,
dk=xk−1∨yk−1xk−2∨⋯∨yk−1⋯y1x0∨yk−1⋯y0d0. Proof. By induction on k. For k=1 it is the hypothesis. If it holds for k, then dk+1=xk∨ykdk; substituting the formula for dk and distributing yk over the OR gives the formula for k+1. □
Lemma 2 (upward invariant). For each node v that has signals (Gv,Pv) (a leaf, or a group built in line L5), cuv+1∗=Gv∨(Pv∧cℓv∗).
Proof. By induction on the level. For a leaf i, (Gv,Pv)=(gi,pi) and the claim is the definition of ci+1∗. For a group with one child, the signals are the child's and the interval is the same. For a group v with children w0,…,wm−1, m≥2, set xj=Gwj, yj=Pwj and dj=cℓwj∗ for j<m, and dm=cuv+1∗. Since the intervals are consecutive, uwj+1=ℓwj+1, so the induction hypothesis for the children says dj+1=xj∨yjdj. Lemma 1 with k=m gives dm=Gv∨Pvd0 where Gv and Pv are exactly the formulas of line L5, and d0=cℓv∗. □
Lemma 3 (downward invariant). Each node v receives the carry-in cℓv∗.
Proof. By induction from the root down. The root covers [0,n−1] and receives c0=c0∗ in line L7. Let v be a group with carry-in cℓv∗ and children w0,…,wm−1, and define xj,yj,dj as in the proof of Lemma 2, where now each child has signals by Lemma 2 (children of any group are leaves or groups built in line L5, since only the root skips line L5). Child w0 receives cℓv∗=d0, and ℓw0=ℓv. For 1≤k<m, line L9 gives child wk the value of the formula of Lemma 1 with d0=cℓv∗, which equals dk=cℓwk∗. □
Theorem. CLA-ADD returns the sum bits and the carry out of a+b+c0.
Proof. By Lemma 3, leaf i receives ci∗, so line L11 sets si=pi⊕ci∗. Line L10 applies the formula of Lemma 1 with k=m to the root's children and d0=c0; by Lemma 2 for the children it equals dm=cu+1∗ with u=n−1, so it is cn∗. By the identity at the start, the outputs represent a+b+c0. ■