Algorithm Search⌘K

Proofs: Dadda multiplier

These are the human proofs of Dadda multiplier, at full length.

The Dadda reduction is always possible and computes the product full

This proof shows: correctness, termination.

Write a column state as heights h0,…,h2n−1h_0, \ldots, h_{2n-1} and the value of the state as ∑bitsbit⋅2column\sum_{\text{bits}} \text{bit} \cdot 2^{\text{column}}. Let d1=2d_1 = 2, dj+1=⌊3dj/2⌋d_{j+1} = \lfloor 3 d_j / 2 \rfloor and dtd_t the largest term below nn; for n≤2n \le 2 there are no stages.

Termination. There are tt stages, each a single pass over 2n2n columns with at most hkh_k cells per column, and one final addition.

Lemma 1 (value). Each stage keeps the value. A full adder on bits x,y,zx, y, z of column kk outputs s=x⊕y⊕zs = x \oplus y \oplus z in column kk and c=maj⁡(x,y,z)c = \operatorname{maj}(x, y, z) in column k+1k + 1, and x+y+z=s+2cx + y + z = s + 2c, so the value changes by (s+2c−x−y−z)2k=0(s + 2c - x - y - z) 2^k = 0. The same holds for a half adder with x+y=s+2cx + y = s + 2c. Bits that pass are unchanged. □\square

Lemma 2 (heights before a stage). Before the stage with target d=djd = d_j, every column has height at most DD, where D=nD = n if j=tj = t and D=dj+1D = d_{j+1} otherwise. In both cases D≤⌊3d/2⌋D \le \lfloor 3d/2 \rfloor.

Proof. Initially hk=min⁡(k+1,2n−1−k)≤nh_k = \min(k + 1, 2n - 1 - k) \le n. Since dt<n≤dt+1=⌊3dt/2⌋d_t < n \le d_{t+1} = \lfloor 3 d_t / 2 \rfloor by the choice of tt, the claim holds for the first stage. A stage with target dd leaves every column with height at most dd (Lemma 3 shows that the stage can be built; then each column has hk+ck−2Fk−Hk=dh_k + c_k - 2F_k - H_k = d bits when ek>0e_k > 0 and hk+ck≤dh_k + c_k \le d bits otherwise), which is the bound DD of the next stage, and dj+1=⌊3dj/2⌋d_{j+1} = \lfloor 3 d_j / 2 \rfloor. □\square

Lemma 3 (enough bits). In a stage with target dd and previous bound D≤⌊3d/2⌋D \le \lfloor 3d/2 \rfloor, let ckc_k be the number of carries into column kk, ek=hk+ck−de_k = h_k + c_k - d, Fk=⌊ek/2⌋F_k = \lfloor e_k/2 \rfloor and Hk=ek mod 2H_k = e_k \bmod 2 when ek>0e_k > 0, and Fk=Hk=0F_k = H_k = 0 otherwise. Then ck≤D−dc_k \le D - d and 3Fk+2Hk≤hk3F_k + 2H_k \le h_k for every kk.

Proof. By induction on kk. For k=0k = 0, c0=0c_0 = 0. Assume ck≤D−dc_k \le D - d. If ek≤0e_k \le 0 there are no adders and ck+1=0c_{k+1} = 0. Otherwise ck+1=Fk+Hk=⌈ek/2⌉c_{k+1} = F_k + H_k = \lceil e_k / 2 \rceil, and ek≤D+(D−d)−d=2(D−d)e_k \le D + (D - d) - d = 2(D - d), so ck+1≤D−dc_{k+1} \le D - d. For the bits: if eke_k is even, 3Fk+2Hk=3ek/23F_k + 2H_k = 3e_k/2, and 3ek/2≤hk3e_k / 2 \le h_k is equivalent to hk+3ck≤3dh_k + 3c_k \le 3d. If eke_k is odd, 3Fk+2Hk=(3ek+1)/23F_k + 2H_k = (3e_k + 1)/2, and the condition is hk+3ck≤3d−1h_k + 3c_k \le 3d - 1. Now hk+3ck≤D+3(D−d)=4D−3d≤3dh_k + 3c_k \le D + 3(D - d) = 4D - 3d \le 3d since D≤3d/2D \le 3d/2. Equality throughout needs hk=Dh_k = D, ck=D−dc_k = D - d and D=3d/2D = 3d/2; then ek=2D−2de_k = 2D - 2d is even. So when eke_k is odd the inequality is strict, hk+3ck≤3d−1h_k + 3c_k \le 3d - 1. □\square

No carry leaves the top. Column 2n−12n - 1 starts empty and, as long as it has height 0, Lemma 3 gives 3F+2H≤03F + 2H \le 0, so it has no adders and sends no carry to column 2n2n. Its height after a stage is at most dd. If it ever had bits with adders, the value would still be ab<22nab < 2^{2n} by Lemma 1; a bit of column 2n2n would make the value at least 22n2^{2n}, so column 2n2n is always empty.

Theorem. DADDA-MULTIPLY returns the 2n2n bits of abab.

Proof. Initially the value is ∑i,j(ai∧bj)2i+j=ab\sum_{i,j} (a_i \wedge b_j) 2^{i+j} = ab (line L1). By Lemma 3 every stage can be built, by Lemma 1 it keeps the value, and by Lemma 2 after the last stage, with d=d1=2d = d_1 = 2, every column has at most two bits. Reading the bits of each column as two rows r1r_1 and r2r_2 (a missing bit is 0), r1+r2=abr_1 + r_2 = ab, and line L8 returns abab, which is less than 22n2^{2n} and fits in the 2n2n output bits. ■\blacksquare

Delay. An AND gate has delay 1. The adders of a stage take only bits present before the stage, so if all of those arrive by time ss, all bits after the stage arrive by time s+1s + 1. By induction the two rows arrive by time t+1t + 1. ■\blacksquare

Back to Dadda multiplier