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

Theorem sadadd 13675
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 1421 and df-cad 1422.

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 13634 . . . . . 6  |-  (bits `  A )  C_  NN0
2 bitsss 13634 . . . . . 6  |-  (bits `  B )  C_  NN0
3 sadcl 13670 . . . . . 6  |-  ( ( (bits `  A )  C_ 
NN0  /\  (bits `  B
)  C_  NN0 )  -> 
( (bits `  A
) sadd  (bits `  B )
)  C_  NN0 )
41, 2, 3mp2an 672 . . . . 5  |-  ( (bits `  A ) sadd  (bits `  B ) )  C_  NN0
54sseli 3364 . . . 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 13634 . . . . 5  |-  (bits `  ( A  +  B
) )  C_  NN0
87sseli 3364 . . . 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 2443 . . . . . . . . 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 2443 . . . . . . . . 9  |-  `' (bits  |`  NN0 )  =  `' (bits  |`  NN0 )
12 simpll 753 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  A  e.  ZZ )
13 simplr 754 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  B  e.  ZZ )
14 simpr 461 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  NN0 )
15 1nn0 10607 . . . . . . . . . . 11  |-  1  e.  NN0
1615a1i 11 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  1  e.  NN0 )
1714, 16nn0addcld 10652 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  +  1 )  e.  NN0 )
1810, 11, 12, 13, 17sadaddlem 13674 . . . . . . . 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 10763 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( A  +  B )  e.  ZZ )
20 bitsmod 13644 . . . . . . . . 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 661 . . . . . . . 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 2475 . . . . . . 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 2510 . . . . . 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 3551 . . . . . 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 3551 . . . . . 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 10907 . . . . . . . . 9  |-  NN0  =  ( ZZ>= `  0 )
2814, 27syl6eleq 2533 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  (
ZZ>= `  0 ) )
29 eluzfz2 11471 . . . . . . . 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 10757 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ZZ )
32 fzval3 11617 . . . . . . . 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 2519 . . . . . 6  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ( 0..^ ( k  +  1 ) ) )
3534biantrud 507 . . . . 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 507 . . . . 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 2441 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 1369  caddwcad 1420    e. wcel 1756    i^i cin 3339    C_ wss 3340   (/)c0 3649   ifcif 3803    e. cmpt 4362   `'ccnv 4851    |` cres 4854   ` cfv 5430  (class class class)co 6103    e. cmpt2 6105   1oc1o 6925   2oc2o 6926   0cc0 9294   1c1 9295    + caddc 9297    - cmin 9607   2c2 10383   NN0cn0 10591   ZZcz 10658   ZZ>=cuz 10873   ...cfz 11449  ..^cfzo 11560    mod cmo 11720    seqcseq 11818   ^cexp 11877  bitscbits 13627   sadd csad 13628
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1591  ax-4 1602  ax-5 1670  ax-6 1708  ax-7 1728  ax-8 1758  ax-9 1760  ax-10 1775  ax-11 1780  ax-12 1792  ax-13 1943  ax-ext 2423  ax-rep 4415  ax-sep 4425  ax-nul 4433  ax-pow 4482  ax-pr 4543  ax-un 6384  ax-inf2 7859  ax-cnex 9350  ax-resscn 9351  ax-1cn 9352  ax-icn 9353  ax-addcl 9354  ax-addrcl 9355  ax-mulcl 9356  ax-mulrcl 9357  ax-mulcom 9358  ax-addass 9359  ax-mulass 9360  ax-distr 9361  ax-i2m1 9362  ax-1ne0 9363  ax-1rid 9364  ax-rnegex 9365  ax-rrecex 9366  ax-cnre 9367  ax-pre-lttri 9368  ax-pre-lttrn 9369  ax-pre-ltadd 9370  ax-pre-mulgt0 9371  ax-pre-sup 9372
This theorem depends on definitions:  df-bi 185  df-or 370  df-an 371  df-3or 966  df-3an 967  df-xor 1351  df-tru 1372  df-fal 1375  df-had 1421  df-cad 1422  df-ex 1587  df-nf 1590  df-sb 1701  df-eu 2257  df-mo 2258  df-clab 2430  df-cleq 2436  df-clel 2439  df-nfc 2577  df-ne 2620  df-nel 2621  df-ral 2732  df-rex 2733  df-reu 2734  df-rmo 2735  df-rab 2736  df-v 2986  df-sbc 3199  df-csb 3301  df-dif 3343  df-un 3345  df-in 3347  df-ss 3354  df-pss 3356  df-nul 3650  df-if 3804  df-pw 3874  df-sn 3890  df-pr 3892  df-tp 3894  df-op 3896  df-uni 4104  df-int 4141  df-iun 4185  df-disj 4275  df-br 4305  df-opab 4363  df-mpt 4364  df-tr 4398  df-eprel 4644  df-id 4648  df-po 4653  df-so 4654  df-fr 4691  df-se 4692  df-we 4693  df-ord 4734  df-on 4735  df-lim 4736  df-suc 4737  df-xp 4858  df-rel 4859  df-cnv 4860  df-co 4861  df-dm 4862  df-rn 4863  df-res 4864  df-ima 4865  df-iota 5393  df-fun 5432  df-fn 5433  df-f 5434  df-f1 5435  df-fo 5436  df-f1o 5437  df-fv 5438  df-isom 5439  df-riota 6064  df-ov 6106  df-oprab 6107  df-mpt2 6108  df-om 6489  df-1st 6589  df-2nd 6590  df-recs 6844  df-rdg 6878  df-1o 6932  df-2o 6933  df-oadd 6936  df-er 7113  df-map 7228  df-pm 7229  df-en 7323  df-dom 7324  df-sdom 7325  df-fin 7326  df-sup 7703  df-oi 7736  df-card 8121  df-cda 8349  df-pnf 9432  df-mnf 9433  df-xr 9434  df-ltxr 9435  df-le 9436  df-sub 9609  df-neg 9610  df-div 10006  df-nn 10335  df-2 10392  df-3 10393  df-n0 10592  df-z 10659  df-uz 10874  df-rp 11004  df-fz 11450  df-fzo 11561  df-fl 11654  df-mod 11721  df-seq 11819  df-exp 11878  df-hash 12116  df-cj 12600  df-re 12601  df-im 12602  df-sqr 12736  df-abs 12737  df-clim 12978  df-sum 13176  df-dvds 13548  df-bits 13630  df-sad 13659
This theorem is referenced by:  bitsres  13681  smumullem  13700
  Copyright terms: Public domain W3C validator