Booth's recoding and the sequential algorithm compute the signed product full
This proof shows: correctness, termination.
Let y be an n-bit two's complement integer with bits yn−1,…,y0 and y−1=0, so y=−yn−12n−1+∑i=0n−2yi2i. Let Di=yi−1−yi∈{−1,0,1}.
Termination. BOOTH runs exactly n steps and BOOTH-4 exactly ⌈n/2⌉ digits.
Lemma 1 (radix-2 recoding). ∑i=0n−1Di2i=y.
Proof. ∑i=0n−1yi−12i=∑i=0n−2yi2i+1, so the sum is ∑i=0n−2yi(2i+1−2i)−yn−12n−1=∑i=0n−2yi2i−yn−12n−1=y. □
Lemma 2 (radix-4 recoding). For even n and qj=y2j−1+y2j−2y2j+1, ∑j=0n/2−1qj4j=y, and qj∈{−2,…,2}.
Proof. qj4j=D2j22j+D2j+122j+1, since D2j+2D2j+1=y2j−1−y2j+2y2j−2y2j+1=qj. Summing over j gives Lemma 1. The bound is clear from y2j−1+y2j∈[0,2]. For odd n, sign extension by one bit keeps the value of y, and the claim applies to n+1 bits. □
So line L8 returns ∑jqjx4j=xy, which proves BOOTH-4.
The sequential algorithm. Read the 2n+1 bits of (A,Q,q−1) with A in two's complement of n+1 bits. Write val(A) for the signed value of A. Before step k+1 (0≤k≤n), let Q hold the bits yn−1,…,yk in its low n−k positions and the k low bits of a partial product in its top k positions, and q−1=yk−1. We prove the invariant
Pk:=val(A)⋅2k+(top k bits of Q)=xi=0∑k−1Di2i, and A never overflows.
Base. For k=0, A=0, Q=y, q−1=0=y−1, and both sides are 0.
Step. At step k+1, q0=yk and q−1=yk−1, so lines L3 and L4 add Dkx to A. By the invariant, ∣Pk∣≤∣x∣(2k−1), and the top k bits of Q form a number T∈[0,2k), so val(A)=(Pk−T)/2k satisfies −∣x∣−1<val(A)<∣x∣, that is −2n−1≤val(A)≤2n−1−1 since ∣x∣≤2n−1. With ∣Dkx∣≤2n−1, −2n≤val(A)+Dkx≤2n−1, which is the range of n+1 bits; so no overflow occurs. Line L5 is an arithmetic shift of A by one bit with the low bit of A moved into the top of Q; with A′=⌊(val(A)+Dkx)/2⌋ and b the bit moved, val(A)+Dkx=2A′+b. Then
Pk+1=A′2k+1+b2k+(top k bits)=(val(A)+Dkx)2k+(top k bits)=Pk+Dkx2k, which is the invariant for k+1. Line L5 also moves yk into q−1 and exposes yk+1 in q0.
End. After n steps, Pn=val(A)2n+Q=x∑i<nDi2i=xy by Lemma 1. Since ∣xy∣≤22n−2<22n−1, the low 2n bits of (A,Q), read in two's complement, are xy, which line L6 returns. ■