Metamath Proof Explorer


Theorem nn0mullong

Description: Standard algorithm (also known as "long multiplication" or "grade-school multiplication") to calculate the product of two nonnegative integers a and b by multiplying the multiplicand b by each digit of the multiplier a and then add up all the properly shifted results. Here, the binary representation of the multiplier a is used, i.e., the above mentioned "digits" are 0 or 1. This is a similar result as provided by smumul . (Contributed by AV, 7-Jun-2020)

Ref Expression
Assertion nn0mullong A 0 B 0 A B = k 0 ..^ # b A k digit 2 A 2 k B

Proof

Step Hyp Ref Expression
1 nn0sumshdig A 0 A = k 0 ..^ # b A k digit 2 A 2 k
2 1 adantr A 0 B 0 A = k 0 ..^ # b A k digit 2 A 2 k
3 2 oveq1d A 0 B 0 A B = k 0 ..^ # b A k digit 2 A 2 k B
4 fzofi 0 ..^ # b A Fin
5 4 a1i A 0 B 0 0 ..^ # b A Fin
6 nn0cn B 0 B
7 6 adantl A 0 B 0 B
8 2nn 2
9 8 a1i A 0 B 0 k 0 ..^ # b A 2
10 elfzoelz k 0 ..^ # b A k
11 10 adantl A 0 B 0 k 0 ..^ # b A k
12 nn0rp0 A 0 A 0 +∞
13 12 adantr A 0 B 0 A 0 +∞
14 13 adantr A 0 B 0 k 0 ..^ # b A A 0 +∞
15 digvalnn0 2 k A 0 +∞ k digit 2 A 0
16 9 11 14 15 syl3anc A 0 B 0 k 0 ..^ # b A k digit 2 A 0
17 16 nn0cnd A 0 B 0 k 0 ..^ # b A k digit 2 A
18 2nn0 2 0
19 18 a1i k 0 ..^ # b A 2 0
20 elfzonn0 k 0 ..^ # b A k 0
21 19 20 nn0expcld k 0 ..^ # b A 2 k 0
22 21 nn0cnd k 0 ..^ # b A 2 k
23 22 adantl A 0 B 0 k 0 ..^ # b A 2 k
24 17 23 mulcld A 0 B 0 k 0 ..^ # b A k digit 2 A 2 k
25 5 7 24 fsummulc1 A 0 B 0 k 0 ..^ # b A k digit 2 A 2 k B = k 0 ..^ # b A k digit 2 A 2 k B
26 3 25 eqtrd A 0 B 0 A B = k 0 ..^ # b A k digit 2 A 2 k B