The Kogge-Stone adder computes the sum full
This proof shows: correctness, termination.
Let a=∑i<nai2i and b=∑i<nbi2i with bits ai,bi, and let c0∈{0,1}. The carries of the addition are defined by the recurrence
ci+1=gi∨(pi∧ci),gi=ai∧bi,pi=ai⊕bi, and the full adder identity ai+bi+ci=(pi⊕ci)+2ci+1 gives, by induction on i (as on the page of the ripple-carry adder), a+b+c0=∑i<n(pi⊕ci)2i+cn2n. So it suffices to show that the network computes c1,…,cn.
Block signals. For 0≤k≤i<n define the block function Fi:k(x), the carry out of position i when the carry into position k is x: Fk:k(x)=gk∨(pk∧x) and Fi:k(x)=gi∨(pi∧Fi−1:k(x)). Every such function has the form F(x)=G∨(P∧x) for bits G,P, since compositions of maps of this form keep the form:
G1∨(P1∧(G2∨(P2∧x)))=(G1∨(P1∧G2))∨((P1∧P2)∧x). Write (Gi:k,Pi:k) for the pair of Fi:k. The identity shows that, for k≤j<i,
(Gi:k,Pi:k)=(Gi:j+1,Pi:j+1)∘(Gj:k,Pj:k),(G,P)∘(G′,P′)=(G∨(P∧G′),P∧P′), because Fi:k=Fi:j+1∘Fj:k as functions. Composition of functions is associative, so ∘ is associative on the pairs that arise.
Folding the carry in. Line L2 replaces g0 by g0′=g0∨(p0∧c0)=c1. With g0′ in place of g0, the block function of 0..i satisfies Fi:0′(0)=Fi:0(c0)=ci+1, and its G part is Gi:0′=Fi:0′(0)=ci+1. From now on g0 means g0′.
Lemma. For t=0,1,…,L with L=⌈log2n⌉, after t iterations of the loop of line L4 (so d=2t), position i holds (G[i],P[i])=(Gi:k,Pi:k) with k=max(0,i−2t+1).
Proof. By induction on t. For t=0, line L3 sets (G[i],P[i])=(gi,pi)=(Gi:i,Pi:i), and max(0,i)=i.
Assume the claim after t iterations, with d=2t, and consider line L5, which uses the values of iteration t for all positions. For i<d, position i is not updated, and max(0,i−2d+1)=0=max(0,i−d+1), so the claim holds. For i≥d, position i holds the block i−d+1..i, since i−d+1≥1>0, and position i−d holds the block k′..i−d with k′=max(0,i−2d+1). These two blocks are adjacent, so their combination is the pair of the block k′..i, as claimed, with 2d=2t+1. □
Theorem. KOGGE-STONE-ADD terminates and returns the n+1 bits of a+b+c0.
Proof. The variable d doubles in each iteration, so the loop stops after L=⌈log2n⌉ iterations, with 2L≥n. By the lemma with t=L, every position i≤n−1<2L holds the pair of the block 0..i, so G[i]=Gi:0′=ci+1. Line L7 therefore sets the true carries c0,…,cn, and line L8 computes si=pi⊕ci. By the identity at the start, ∑i<nsi2i+cn2n=a+b+c0. ■
Only G is needed for short blocks. If i<2d, the block held by position i after the update starts at 0, and only its G part is used later (by line L7, or by position i+d′ for larger d′, which needs only G from a block that starts at 0, since the combination (G,P)∘(G′,P′) uses P′ only in the P part of the result). So the implementation computes the P part only for i≥2d.