The array multiplier computes the product of its inputs full
This proof shows: correctness.
Let n≥1, a=∑i=0n−1ai2i and b=∑j=0n−1bj2j with all ai,bj∈{0,1}. Line L1 sets pp[j][i]=aibj, so ∑ipp[j][i]2i=abj. A full adder satisfies x+y+z=s+2c with s,c∈{0,1}, and we read s[n]=0 in line L5.
For j=0,…,n−1 let s(j) and c(j) be the vectors s and c after row j (after line L2 for j=0, after line L6 for j≥1), and define
Pj=k=0∑j−1pk2k,Vj=i=0∑n−1s(j)[i]2j+i+i=0∑n−1c(j)[i]2j+i+1. Lemma. For each j, (a) Pj+Vj=a⋅(bmod2j+1), and (b) c(j)[n−1]=0.
Proof. By induction on j.
Base, j=0. P0=0, s(0)=pp[0] and c(0)=0, so V0=ab0=a⋅(bmod2), and (b) holds.
Step, from j−1 to j, for 1≤j≤n−1. Assume (a) and (b) for j−1, and write s=s(j−1), c=c(j−1), s′=s(j), c′=c(j). Line L4 sets pj−1=s[0], so Pj=Pj−1+s[0]2j−1. Line L5 gives, for each i,
s′[i]+2c′[i]=pp[j][i]+s[i+1]+c[i]. Multiply by 2j+i and sum over i=0,…,n−1. The left side is Vj. On the right side, ∑ipp[j][i]2j+i=abj2j; ∑i=0n−1s[i+1]2j+i=∑i=1n−1s[i]2j−1+i because s[n]=0; and ∑ic[i]2j+i is the c part of Vj−1. So
Vj=abj2j+Vj−1−s[0]2j−1. Adding the formula for Pj gives Pj+Vj=Pj−1+Vj−1+abj2j=a⋅(bmod2j)+abj2j=a⋅(bmod2j+1), which is (a). For (b), the top cell i=n−1 adds pp[j][n−1]+s[n]+c[n−1]=pp[j][n−1]+0+0≤1 by the hypothesis (b), so its carry c′[n−1] is 0. □
Theorem. The bits p0,…,p2n−1 computed by ARRAY-MULTIPLY satisfy ∑k=02n−1pk2k=ab.
Proof. Apply the lemma with j=n−1, and write s=s(n−1), c=c(n−1). Since b<2n,
Pn−1+i=0∑n−1s[i]2n−1+i+i=0∑n−2c[i]2n+i=ab, where the term c[n−1] is dropped by (b). Line L7 sets pn−1=s[0], so the left side is Pn+2n(X+Y) with Pn=Pn−1+s[0]2n−1,
X=i=1∑n−1s[i]2i−1,Y=i=1∑n−1c[i−1]2i−1. Lines L8 to L11 are a ripple-carry adder for the (n−1)-bit numbers X and Y with carry-in 0: by induction on i, after the step i of line L10,
k=1∑ipn−1+k2k−1+carry⋅2i=k=1∑i(s[k]+c[k−1])2k−1, since the step adds (s[i]+c[i−1])2i−1 to the right side and replaces carry⋅2i−1 on the left by pn−1+i2i−1+carry′⋅2i, which has the same value by the full adder equation. After i=n−1 and line L11, ∑k=1npn−1+k2k−1=X+Y. Hence
k=0∑2n−1pk2k=Pn+2n(X+Y)=ab.■ Cell counts. By (b), the top cell of each row has at most one live input. In row 1, c(0)=0, so cells 0,…,n−2 have two live inputs (half adders) and cell n−1 has one (a wire). In rows j≥2, cell i≤n−2 has three live inputs, because c(j−1)[i] comes from an adder of row j−1; so these rows have n−1 full adders each. The final adder has a half adder at i=1 and full adders at i=2,…,n−1. This gives (n−1)(n−2)+(n−2)=n2−2n full adders and (n−1)+1=n half adders for n≥2.