MPE Home Metamath Proof Explorer < Previous   Next >
Nearby theorems
Mirrors  >  Home  >  MPE Home  >  Th. List  >  sadadd Structured version   Unicode version

Theorem sadadd 13659
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 1426 and df-cad 1427.

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.)

Assertion
Ref Expression
sadadd  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( (bits `  A
) sadd  (bits `  B )
)  =  (bits `  ( A  +  B
) ) )

Proof of Theorem sadadd
Dummy variables  k 
c  m  n are mutually distinct and distinct from all other variables.
StepHypRef Expression
1 bitsss 13618 . . . . . 6  |-  (bits `  A )  C_  NN0
2 bitsss 13618 . . . . . 6  |-  (bits `  B )  C_  NN0
3 sadcl 13654 . . . . . 6  |-  ( ( (bits `  A )  C_ 
NN0  /\  (bits `  B
)  C_  NN0 )  -> 
( (bits `  A
) sadd  (bits `  B )
)  C_  NN0 )
41, 2, 3mp2an 667 . . . . 5  |-  ( (bits `  A ) sadd  (bits `  B ) )  C_  NN0
54sseli 3349 . . . 4  |-  ( k  e.  ( (bits `  A ) sadd  (bits `  B
) )  ->  k  e.  NN0 )
65a1i 11 . . 3  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  ( (bits `  A ) sadd  (bits `  B ) )  ->  k  e.  NN0 ) )
7 bitsss 13618 . . . . 5  |-  (bits `  ( A  +  B
) )  C_  NN0
87sseli 3349 . . . 4  |-  ( k  e.  (bits `  ( A  +  B )
)  ->  k  e.  NN0 )
98a1i 11 . . 3  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  (bits `  ( A  +  B
) )  ->  k  e.  NN0 ) )
10 eqid 2441 . . . . . . . . 9  |-  seq 0
( ( c  e.  2o ,  m  e. 
NN0  |->  if (cadd ( m  e.  (bits `  A ) ,  m  e.  (bits `  B ) ,  (/)  e.  c ) ,  1o ,  (/) ) ) ,  ( n  e.  NN0  |->  if ( n  =  0 ,  (/) ,  ( n  - 
1 ) ) ) )  =  seq 0
( ( c  e.  2o ,  m  e. 
NN0  |->  if (cadd ( m  e.  (bits `  A ) ,  m  e.  (bits `  B ) ,  (/)  e.  c ) ,  1o ,  (/) ) ) ,  ( n  e.  NN0  |->  if ( n  =  0 ,  (/) ,  ( n  - 
1 ) ) ) )
11 eqid 2441 . . . . . . . . 9  |-  `' (bits  |`  NN0 )  =  `' (bits  |`  NN0 )
12 simpll 748 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  A  e.  ZZ )
13 simplr 749 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  B  e.  ZZ )
14 simpr 458 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  NN0 )
15 1nn0 10591 . . . . . . . . . . 11  |-  1  e.  NN0
1615a1i 11 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  1  e.  NN0 )
1714, 16nn0addcld 10636 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  +  1 )  e.  NN0 )
1810, 11, 12, 13, 17sadaddlem 13658 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( ( (bits `  A ) sadd  (bits `  B ) )  i^i  ( 0..^ ( k  +  1 ) ) )  =  (bits `  ( ( A  +  B )  mod  (
2 ^ ( k  +  1 ) ) ) ) )
1912, 13zaddcld 10747 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( A  +  B )  e.  ZZ )
20 bitsmod 13628 . . . . . . . . 9  |-  ( ( ( A  +  B
)  e.  ZZ  /\  ( k  +  1 )  e.  NN0 )  ->  (bits `  ( ( A  +  B )  mod  ( 2 ^ (
k  +  1 ) ) ) )  =  ( (bits `  ( A  +  B )
)  i^i  ( 0..^ ( k  +  1 ) ) ) )
2119, 17, 20syl2anc 656 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  (bits `  (
( A  +  B
)  mod  ( 2 ^ ( k  +  1 ) ) ) )  =  ( (bits `  ( A  +  B
) )  i^i  (
0..^ ( k  +  1 ) ) ) )
2218, 21eqtrd 2473 . . . . . . 7  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( ( (bits `  A ) sadd  (bits `  B ) )  i^i  ( 0..^ ( k  +  1 ) ) )  =  ( (bits `  ( A  +  B
) )  i^i  (
0..^ ( k  +  1 ) ) ) )
2322eleq2d 2508 . . . . . 6  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  e.  ( ( (bits `  A ) sadd  (bits `  B
) )  i^i  (
0..^ ( k  +  1 ) ) )  <-> 
k  e.  ( (bits `  ( A  +  B
) )  i^i  (
0..^ ( k  +  1 ) ) ) ) )
24 elin 3536 . . . . . 6  |-  ( k  e.  ( ( (bits `  A ) sadd  (bits `  B ) )  i^i  ( 0..^ ( k  +  1 ) ) )  <->  ( k  e.  ( (bits `  A
) sadd  (bits `  B )
)  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) )
25 elin 3536 . . . . . 6  |-  ( k  e.  ( (bits `  ( A  +  B
) )  i^i  (
0..^ ( k  +  1 ) ) )  <-> 
( k  e.  (bits `  ( A  +  B
) )  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) )
2623, 24, 253bitr3g 287 . . . . 5  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( ( k  e.  ( (bits `  A ) sadd  (bits `  B
) )  /\  k  e.  ( 0..^ ( k  +  1 ) ) )  <->  ( k  e.  (bits `  ( A  +  B ) )  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) ) )
27 nn0uz 10891 . . . . . . . . 9  |-  NN0  =  ( ZZ>= `  0 )
2814, 27syl6eleq 2531 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  (
ZZ>= `  0 ) )
29 eluzfz2 11455 . . . . . . . 8  |-  ( k  e.  ( ZZ>= `  0
)  ->  k  e.  ( 0 ... k
) )
3028, 29syl 16 . . . . . . 7  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ( 0 ... k ) )
3114nn0zd 10741 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ZZ )
32 fzval3 11601 . . . . . . . 8  |-  ( k  e.  ZZ  ->  (
0 ... k )  =  ( 0..^ ( k  +  1 ) ) )
3331, 32syl 16 . . . . . . 7  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( 0 ... k )  =  ( 0..^ ( k  +  1 ) ) )
3430, 33eleqtrd 2517 . . . . . 6  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ( 0..^ ( k  +  1 ) ) )
3534biantrud 504 . . . . 5  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  e.  ( (bits `  A
) sadd  (bits `  B )
)  <->  ( k  e.  ( (bits `  A
) sadd  (bits `  B )
)  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) ) )
3634biantrud 504 . . . . 5  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  e.  (bits `  ( A  +  B ) )  <->  ( k  e.  (bits `  ( A  +  B ) )  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) ) )
3726, 35, 363bitr4d 285 . . . 4  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  e.  ( (bits `  A
) sadd  (bits `  B )
)  <->  k  e.  (bits `  ( A  +  B
) ) ) )
3837ex 434 . . 3  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  NN0  ->  ( k  e.  ( (bits `  A ) sadd  (bits `  B ) )  <-> 
k  e.  (bits `  ( A  +  B
) ) ) ) )
396, 9, 38pm5.21ndd 354 . 2  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  ( (bits `  A ) sadd  (bits `  B ) )  <-> 
k  e.  (bits `  ( A  +  B
) ) ) )
4039eqrdv 2439 1  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( (bits `  A
) sadd  (bits `  B )
)  =  (bits `  ( A  +  B
) ) )
Colors of variables: wff setvar class
Syntax hints:    -> wi 4    <-> wb 184    /\ wa 369    = wceq 1364  caddwcad 1425    e. wcel 1761    i^i cin 3324    C_ wss 3325   (/)c0 3634   ifcif 3788    e. cmpt 4347   `'ccnv 4835    |` cres 4838   ` cfv 5415  (class class class)co 6090    e. cmpt2 6092   1oc1o 6909   2oc2o 6910   0cc0 9278   1c1 9279    + caddc 9281    - cmin 9591   2c2 10367   NN0cn0 10575   ZZcz 10642   ZZ>=cuz 10857   ...cfz 11433  ..^cfzo 11544    mod cmo 11704    seqcseq 11802   ^cexp 11861  bitscbits 13611   sadd csad 13612
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1596  ax-4 1607  ax-5 1675  ax-6 1713  ax-7 1733  ax-8 1763  ax-9 1765  ax-10 1780  ax-11 1785  ax-12 1797  ax-13 1948  ax-ext 2422  ax-rep 4400  ax-sep 4410  ax-nul 4418  ax-pow 4467  ax-pr 4528  ax-un 6371  ax-inf2 7843  ax-cnex 9334  ax-resscn 9335  ax-1cn 9336  ax-icn 9337  ax-addcl 9338  ax-addrcl 9339  ax-mulcl 9340  ax-mulrcl 9341  ax-mulcom 9342  ax-addass 9343  ax-mulass 9344  ax-distr 9345  ax-i2m1 9346  ax-1ne0 9347  ax-1rid 9348  ax-rnegex 9349  ax-rrecex 9350  ax-cnre 9351  ax-pre-lttri 9352  ax-pre-lttrn 9353  ax-pre-ltadd 9354  ax-pre-mulgt0 9355  ax-pre-sup 9356
This theorem depends on definitions:  df-bi 185  df-or 370  df-an 371  df-3or 961  df-3an 962  df-xor 1346  df-tru 1367  df-fal 1370  df-had 1426  df-cad 1427  df-ex 1592  df-nf 1595  df-sb 1706  df-eu 2261  df-mo 2262  df-clab 2428  df-cleq 2434  df-clel 2437  df-nfc 2566  df-ne 2606  df-nel 2607  df-ral 2718  df-rex 2719  df-reu 2720  df-rmo 2721  df-rab 2722  df-v 2972  df-sbc 3184  df-csb 3286  df-dif 3328  df-un 3330  df-in 3332  df-ss 3339  df-pss 3341  df-nul 3635  df-if 3789  df-pw 3859  df-sn 3875  df-pr 3877  df-tp 3879  df-op 3881  df-uni 4089  df-int 4126  df-iun 4170  df-disj 4260  df-br 4290  df-opab 4348  df-mpt 4349  df-tr 4383  df-eprel 4628  df-id 4632  df-po 4637  df-so 4638  df-fr 4675  df-se 4676  df-we 4677  df-ord 4718  df-on 4719  df-lim 4720  df-suc 4721  df-xp 4842  df-rel 4843  df-cnv 4844  df-co 4845  df-dm 4846  df-rn 4847  df-res 4848  df-ima 4849  df-iota 5378  df-fun 5417  df-fn 5418  df-f 5419  df-f1 5420  df-fo 5421  df-f1o 5422  df-fv 5423  df-isom 5424  df-riota 6049  df-ov 6093  df-oprab 6094  df-mpt2 6095  df-om 6476  df-1st 6576  df-2nd 6577  df-recs 6828  df-rdg 6862  df-1o 6916  df-2o 6917  df-oadd 6920  df-er 7097  df-map 7212  df-pm 7213  df-en 7307  df-dom 7308  df-sdom 7309  df-fin 7310  df-sup 7687  df-oi 7720  df-card 8105  df-cda 8333  df-pnf 9416  df-mnf 9417  df-xr 9418  df-ltxr 9419  df-le 9420  df-sub 9593  df-neg 9594  df-div 9990  df-nn 10319  df-2 10376  df-3 10377  df-n0 10576  df-z 10643  df-uz 10858  df-rp 10988  df-fz 11434  df-fzo 11545  df-fl 11638  df-mod 11705  df-seq 11803  df-exp 11862  df-hash 12100  df-cj 12584  df-re 12585  df-im 12586  df-sqr 12720  df-abs 12721  df-clim 12962  df-sum 13160  df-dvds 13532  df-bits 13614  df-sad 13643
This theorem is referenced by:  bitsres  13665  smumullem  13684
  Copyright terms: Public domain W3C validator