Metamath Proof Explorer


Theorem sadadd

Description: For sequences that correspond to valid integers, the adder sequence function produces the sequence for the sum. This is effectively a proof of the correctness of the ripple carry adder, implemented with logic gates corresponding to df-had and df-cad .

It is interesting to consider in what sense the sadd function can be said to be "adding" things outside the range of the bits function, that is, when adding sequences that are not eventually constant and so do not denote any integer. The correct interpretation is that the sequences are representations of 2-adic integers, which have a natural ring structure. (Contributed by Mario Carneiro, 9-Sep-2016)

Ref Expression
Assertion sadadd ABbitsAsaddbitsB=bitsA+B

Proof

Step Hyp Ref Expression
1 bitsss bitsA0
2 bitsss bitsB0
3 sadcl bitsA0bitsB0bitsAsaddbitsB0
4 1 2 3 mp2an bitsAsaddbitsB0
5 4 sseli kbitsAsaddbitsBk0
6 5 a1i ABkbitsAsaddbitsBk0
7 bitsss bitsA+B0
8 7 sseli kbitsA+Bk0
9 8 a1i ABkbitsA+Bk0
10 eqid seq0c2𝑜,m0ifcaddmbitsAmbitsBc1𝑜n0ifn=0n1=seq0c2𝑜,m0ifcaddmbitsAmbitsBc1𝑜n0ifn=0n1
11 eqid bits0-1=bits0-1
12 simpll ABk0A
13 simplr ABk0B
14 simpr ABk0k0
15 1nn0 10
16 15 a1i ABk010
17 14 16 nn0addcld ABk0k+10
18 10 11 12 13 17 sadaddlem ABk0bitsAsaddbitsB0..^k+1=bitsA+Bmod2k+1
19 12 13 zaddcld ABk0A+B
20 bitsmod A+Bk+10bitsA+Bmod2k+1=bitsA+B0..^k+1
21 19 17 20 syl2anc ABk0bitsA+Bmod2k+1=bitsA+B0..^k+1
22 18 21 eqtrd ABk0bitsAsaddbitsB0..^k+1=bitsA+B0..^k+1
23 22 eleq2d ABk0kbitsAsaddbitsB0..^k+1kbitsA+B0..^k+1
24 elin kbitsAsaddbitsB0..^k+1kbitsAsaddbitsBk0..^k+1
25 elin kbitsA+B0..^k+1kbitsA+Bk0..^k+1
26 23 24 25 3bitr3g ABk0kbitsAsaddbitsBk0..^k+1kbitsA+Bk0..^k+1
27 nn0uz 0=0
28 14 27 eleqtrdi ABk0k0
29 eluzfz2 k0k0k
30 28 29 syl ABk0k0k
31 14 nn0zd ABk0k
32 fzval3 k0k=0..^k+1
33 31 32 syl ABk00k=0..^k+1
34 30 33 eleqtrd ABk0k0..^k+1
35 34 biantrud ABk0kbitsAsaddbitsBkbitsAsaddbitsBk0..^k+1
36 34 biantrud ABk0kbitsA+BkbitsA+Bk0..^k+1
37 26 35 36 3bitr4d ABk0kbitsAsaddbitsBkbitsA+B
38 37 ex ABk0kbitsAsaddbitsBkbitsA+B
39 6 9 38 pm5.21ndd ABkbitsAsaddbitsBkbitsA+B
40 39 eqrdv ABbitsAsaddbitsB=bitsA+B