Proofs: Wallace tree multiplier
These are the human proofs of Wallace tree multiplier, at full length.
The Wallace tree computes the product in few levels full
This proof shows: correctness, termination.
Let and with bits . A configuration is a finite multiset of bits placed in columns ; its value is , where is the number of ones in column , and its height in column is the number of bits in column .
Lemma 1 (the adders keep the value). For bits ,
Proof. Both sides of the first identity are symmetric in and depend only on the number of ones among them: for the right side is . The second identity is the first with .
The full adder of the implementation computes and , and the second expression is : if it is , and if it is . So replacing three bits of column by a full adder's sum bit in column and carry bit in column changes by , and the same holds for a half adder.
Lemma 2 (invariant). After line L1 and after every level of lines L2 to L6, .
Proof. After line L1, column holds the bits with , so . A level replaces disjoint groups of bits by adder outputs, each replacement keeps by Lemma 1, and bits outside the groups stay where they are; so is unchanged.
Lemma 3 (termination). The loop of line L2 ends after finitely many levels.
Proof. A full adder replaces three bits by two, and a half adder two bits by two, so the total number of bits never grows. If the loop runs, some column holds bits, and line L5 applies full adders there, so the total number of bits falls by at least one. It starts at , so there are at most levels. Lemma 4 gives a much better bound.
Theorem (correctness). The algorithm returns .
Proof. When the loop ends every column holds at most two bits, so line L7 can place them in two rows and with by Lemma 2. Line L8 adds them exactly, for example by the Kogge-Stone adder. No bit is lost by the width : a bit in a column would have weight at least , and since all weights are nonnegative and , every such bit is 0.
Lemma 4 (levels). Let and . If every column has height at most , then after one level every column has height at most . Hence, if is the least index with , the loop runs at most times.
Proof. Consider column of height and column of height . Write with . In column the level leaves sum bits of full adders and, if , one more bit (a half adder's sum or a single bit); that is bits. From column it receives one carry for each full adder and one for a half adder, which is carries. Both counts are nondecreasing in and , so for the new height is at most
as the three cases give . Since , we have , and is an integer, so .
After line L1 column has bits. By induction, after levels every height is at most , so after levels every height is at most , and the loop has stopped.
Since , we have , so .
Corollary (depth). The AND gates of line L1 have depth 1. A full adder's outputs have depth at most 3 more than its inputs, and a half adder's at most 1 more, so after levels every bit has depth at most . A Kogge-Stone adder of width adds at most : one level for the generate and propagate signals, two gates for each of the prefix levels, and one XOR for the sum bits. So the depth is at most , which is for .