Algorithm Search⌘K

Proofs: Carry-skip adder

These are the human proofs of Carry-skip adder, at full length.

The carry-skip adder computes the sum of its inputs full

This proof shows: correctness, termination.

Let n≥1n \ge 1, ai,bi,cin∈{0,1}a_i, b_i, c_{\text{in}} \in \{0, 1\}, and block sizes k0,…,kt−1≥1k_0, \ldots, k_{t-1} \ge 1 with sum nn. Block jj covers positions ℓj..uj\ell_j .. u_j, consecutive and in order. Write gi=ai∧big_i = a_i \wedge b_i and pi=ai⊕bip_i = a_i \oplus b_i.

Termination. The loops of lines L4 and L6 run over finite lists of blocks and positions, and the AND trees of line L2 halve the number of signals at each level.

The reference values. Define the ripple carries c0∗=cinc^{\ast}_0 = c_{\text{in}} and ci+1∗=gi∨(pi∧ci∗)c^{\ast}_{i+1} = g_i \vee (p_i \wedge c^{\ast}_i). For each position, ai+bi+ci∗=(pi⊕ci∗)+2ci+1∗a_i + b_i + c^{\ast}_i = (p_i \oplus c^{\ast}_i) + 2c^{\ast}_{i+1}: if pi=1p_i = 1, then gi=0g_i = 0 and both sides are 1+ci∗1 + c^{\ast}_i; if pi=0p_i = 0, then ai=bi=gia_i = b_i = g_i and both sides are 2gi+ci∗2g_i + c^{\ast}_i. Multiplying by 2i2^i and summing over ii, the carries telescope:

a+b+cin=∑i=0n−1(pi⊕ci∗) 2i+cn∗ 2n.a + b + c_{\text{in}} = \sum_{i=0}^{n-1} (p_i \oplus c^{\ast}_i)\, 2^i + c^{\ast}_n\, 2^n .

So it suffices to show that the algorithm sets si=pi⊕ci∗s_i = p_i \oplus c^{\ast}_i and returns cn∗c^{\ast}_n.

Lemma 1 (a propagating block). If pi=1p_i = 1 for every ii in block jj, then cuj+1∗=cℓj∗c^{\ast}_{u_j + 1} = c^{\ast}_{\ell_j}.

Proof. For each such ii, gi=ai∧bi=0g_i = a_i \wedge b_i = 0 because ai≠bia_i \ne b_i, so ci+1∗=0∨(1∧ci∗)=ci∗c^{\ast}_{i+1} = 0 \vee (1 \wedge c^{\ast}_i) = c^{\ast}_i. Apply this kjk_j times. □\square

Lemma 2 (the invariant). At the start of iteration jj of the loop of line L4, c=cℓj∗c = c^{\ast}_{\ell_j}. During the iteration, line L6 sets si=pi⊕ci∗s_i = p_i \oplus c^{\ast}_i for each position ii of block jj, and at its end c=cuj+1∗c = c^{\ast}_{u_j + 1}.

Proof. By induction on jj. For j=0j = 0, line L3 sets c=cin=c0∗c = c_{\text{in}} = c^{\ast}_0. Assume c=cℓj∗c = c^{\ast}_{\ell_j} at the start of iteration jj. Line L5 sets x=cℓj∗x = c^{\ast}_{\ell_j}. Line L6 processes positions ℓj,…,uj\ell_j, \ldots, u_j in order; by induction on the position, when it reaches ii the value cc is ci∗c^{\ast}_i, so it sets si=pi⊕ci∗s_i = p_i \oplus c^{\ast}_i and then c=gi∨(pi∧ci∗)=ci+1∗c = g_i \vee (p_i \wedge c^{\ast}_i) = c^{\ast}_{i+1}. After the block, c=cuj+1∗c = c^{\ast}_{u_j + 1}. If j=0j = 0, line L7 does nothing. If j≥1j \ge 1, line L2 gives Pj=⋀i=ℓjujpiP_j = \bigwedge_{i = \ell_j}^{u_j} p_i, and line L7 sets c←(Pj∧x)∨(¬Pj∧c)c \leftarrow (P_j \wedge x) \vee (\neg P_j \wedge c):

  • if Pj=0P_j = 0, the new value is c=cuj+1∗c = c^{\ast}_{u_j + 1};
  • if Pj=1P_j = 1, the new value is x=cℓj∗x = c^{\ast}_{\ell_j}, which equals cuj+1∗c^{\ast}_{u_j + 1} by Lemma 1.

So c=cuj+1∗=cℓj+1∗c = c^{\ast}_{u_j + 1} = c^{\ast}_{\ell_{j+1}} at the end of the iteration. □\square

Theorem. CARRY-SKIP-ADD returns the bits of a+b+cina + b + c_{\text{in}}.

Proof. By Lemma 2, every si=pi⊕ci∗s_i = p_i \oplus c^{\ast}_i, and after the last block c=cut−1+1∗=cn∗c = c^{\ast}_{u_{t-1} + 1} = c^{\ast}_n. By the identity above, these n+1n + 1 bits represent a+b+cina + b + c_{\text{in}}. ■\blacksquare

Back to Carry-skip adder