The carry-select adder computes the sum of its inputs full
This proof shows: correctness, termination.
Let n≥1, ai,bi,cin∈{0,1}, and block sizes k0,…,kt−1≥1 with ∑jkj=n. Block j covers the positions ℓj..uj with ℓ0=0, uj=ℓj+kj−1 and ℓj+1=uj+1. Write Aj=∑i=ℓjujai2i−ℓj and Bj likewise.
Termination. Every loop runs over a finite list of blocks or positions, once.
Ripple steps. For a block and a carry-in c∈{0,1}, the ripple of lines L2 and L4 sets cℓ=c, si=pi⊕ci and ci+1=gi∨(pi∧ci) for i=ℓ..u, with gi=ai∧bi and pi=ai⊕bi. The simplified first steps with a constant carry compute the same values: with c=0, s=p and cℓ+1=g; with c=1, s=p⊕1 and cℓ+1=g∨p.
Lemma 1. The ripple through block j with carry-in c returns bits sℓj,…,suj and a carry out C with ∑isi2i−ℓj+C2kj=Aj+Bj+c.
Proof. For each position, ai+bi+ci=si+2ci+1: if pi=1 then ai+bi=1 and gi=0, so both sides are 1+ci; if pi=0 then ai=bi=gi, si=ci and ci+1=gi, so both sides are 2gi+ci. Multiply by 2i−ℓj and sum over the block; the terms ci for ℓj<i≤uj cancel, which leaves the claim with C=cuj+1. □
Lemma 2 (monotone carries). In line L4, C0[j]≤C1[j].
Proof. By Lemma 1, Cc[j]=⌊(Aj+Bj+c)/2kj⌋, which does not decrease when c goes from 0 to 1. □
Lemma 3 (selection). If x∈{0,1}, then si0⊕(x∧(si0⊕si1))=six and C0[j]∨(C1[j]∧x)=Cx[j].
Proof. For x=0, the first expression is si0 and the second is C0[j]. For x=1, the first is si0⊕si0⊕si1=si1, and the second is C0[j]∨C1[j]=C1[j] by Lemma 2. □
Lemma 4. Let cj∗ be the true carry into block j, that is, c0∗=cin and cj+1∗=⌊(Aj+Bj+cj∗)/2kj⌋. Then the value x of line L6 at step j is cj∗, and the value C after line L8 at step j is cj+1∗.
Proof. By induction on j. Before the loop, C is the carry out of block 0 with carry-in cin, which is c1∗ by Lemma 1. At step j, line L6 sets x=C=cj∗ by the induction hypothesis, and line L8 sets C=Cx[j] by Lemma 3, which is ⌊(Aj+Bj+cj∗)/2kj⌋=cj+1∗ by Lemma 1. □
Theorem. CARRY-SELECT-ADD returns the n+1 bits of a+b+cin.
Proof. By Lemmas 1, 3 and 4, the bits that the algorithm writes for block j are the low kj bits of Aj+Bj+cj∗, so with Sj their value, Sj+cj+1∗2kj=Aj+Bj+cj∗. Multiply by 2ℓj and sum over j. Since ℓj+kj=ℓj+1, the carry terms telescope, and
j∑Sj2ℓj+ct∗2n=j∑(Aj+Bj)2ℓj+c0∗=a+b+cin. The returned carry is C=ct∗ by Lemma 4 (or by Lemma 1 when t=1), so the output represents a+b+cin. ■