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

Theorem sadadd 12934
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 1386 and df-cad 1387.

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 12893 . . . . . 6  |-  (bits `  A )  C_  NN0
2 bitsss 12893 . . . . . 6  |-  (bits `  B )  C_  NN0
3 sadcl 12929 . . . . . 6  |-  ( ( (bits `  A )  C_ 
NN0  /\  (bits `  B
)  C_  NN0 )  -> 
( (bits `  A
) sadd  (bits `  B )
)  C_  NN0 )
41, 2, 3mp2an 654 . . . . 5  |-  ( (bits `  A ) sadd  (bits `  B ) )  C_  NN0
54sseli 3304 . . . 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 12893 . . . . 5  |-  (bits `  ( A  +  B
) )  C_  NN0
87sseli 3304 . . . 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 2404 . . . . . . . . 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 2404 . . . . . . . . 9  |-  `' (bits  |`  NN0 )  =  `' (bits  |`  NN0 )
12 simpll 731 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  A  e.  ZZ )
13 simplr 732 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  B  e.  ZZ )
14 simpr 448 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  NN0 )
15 1nn0 10193 . . . . . . . . . . 11  |-  1  e.  NN0
1615a1i 11 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  1  e.  NN0 )
1714, 16nn0addcld 10234 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  +  1 )  e.  NN0 )
1810, 11, 12, 13, 17sadaddlem 12933 . . . . . . . 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 10335 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( A  +  B )  e.  ZZ )
20 bitsmod 12903 . . . . . . . . 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 643 . . . . . . . 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 2436 . . . . . . 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 2471 . . . . . 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 3490 . . . . . 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 3490 . . . . . 6  |-  ( k  e.  ( (bits `  ( A  +  B
) )  i^i  (
0..^ ( k  +  1 ) ) )  <-> 
( k  e.  (bits `  ( A  +  B
) )  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) )
2623, 24, 253bitr3g 279 . . . . 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 10476 . . . . . . . . 9  |-  NN0  =  ( ZZ>= `  0 )
2814, 27syl6eleq 2494 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  (
ZZ>= `  0 ) )
29 eluzfz2 11021 . . . . . . . 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 10329 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ZZ )
32 fzval3 11135 . . . . . . . 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 2480 . . . . . 6  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ( 0..^ ( k  +  1 ) ) )
3534biantrud 494 . . . . 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 494 . . . . 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 277 . . . 4  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  e.  ( (bits `  A
) sadd  (bits `  B )
)  <->  k  e.  (bits `  ( A  +  B
) ) ) )
3837ex 424 . . 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 344 . 2  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  ( (bits `  A ) sadd  (bits `  B ) )  <-> 
k  e.  (bits `  ( A  +  B
) ) ) )
4039eqrdv 2402 1  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( (bits `  A
) sadd  (bits `  B )
)  =  (bits `  ( A  +  B
) ) )
Colors of variables: wff set class
Syntax hints:    -> wi 4    <-> wb 177    /\ wa 359  caddwcad 1385    = wceq 1649    e. wcel 1721    i^i cin 3279    C_ wss 3280   (/)c0 3588   ifcif 3699    e. cmpt 4226   `'ccnv 4836    |` cres 4839   ` cfv 5413  (class class class)co 6040    e. cmpt2 6042   1oc1o 6676   2oc2o 6677   0cc0 8946   1c1 8947    + caddc 8949    - cmin 9247   2c2 10005   NN0cn0 10177   ZZcz 10238   ZZ>=cuz 10444   ...cfz 10999  ..^cfzo 11090    mod cmo 11205    seq cseq 11278   ^cexp 11337  bitscbits 12886   sadd csad 12887
This theorem is referenced by:  bitsres  12940  smumullem  12959
This theorem was proved from axioms:  ax-1 5  ax-2 6  ax-3 7  ax-mp 8  ax-gen 1552  ax-5 1563  ax-17 1623  ax-9 1662  ax-8 1683  ax-13 1723  ax-14 1725  ax-6 1740  ax-7 1745  ax-11 1757  ax-12 1946  ax-ext 2385  ax-rep 4280  ax-sep 4290  ax-nul 4298  ax-pow 4337  ax-pr 4363  ax-un 4660  ax-inf2 7552  ax-cnex 9002  ax-resscn 9003  ax-1cn 9004  ax-icn 9005  ax-addcl 9006  ax-addrcl 9007  ax-mulcl 9008  ax-mulrcl 9009  ax-mulcom 9010  ax-addass 9011  ax-mulass 9012  ax-distr 9013  ax-i2m1 9014  ax-1ne0 9015  ax-1rid 9016  ax-rnegex 9017  ax-rrecex 9018  ax-cnre 9019  ax-pre-lttri 9020  ax-pre-lttrn 9021  ax-pre-ltadd 9022  ax-pre-mulgt0 9023  ax-pre-sup 9024
This theorem depends on definitions:  df-bi 178  df-or 360  df-an 361  df-3or 937  df-3an 938  df-xor 1311  df-tru 1325  df-had 1386  df-cad 1387  df-ex 1548  df-nf 1551  df-sb 1656  df-eu 2258  df-mo 2259  df-clab 2391  df-cleq 2397  df-clel 2400  df-nfc 2529  df-ne 2569  df-nel 2570  df-ral 2671  df-rex 2672  df-reu 2673  df-rmo 2674  df-rab 2675  df-v 2918  df-sbc 3122  df-csb 3212  df-dif 3283  df-un 3285  df-in 3287  df-ss 3294  df-pss 3296  df-nul 3589  df-if 3700  df-pw 3761  df-sn 3780  df-pr 3781  df-tp 3782  df-op 3783  df-uni 3976  df-int 4011  df-iun 4055  df-disj 4143  df-br 4173  df-opab 4227  df-mpt 4228  df-tr 4263  df-eprel 4454  df-id 4458  df-po 4463  df-so 4464  df-fr 4501  df-se 4502  df-we 4503  df-ord 4544  df-on 4545  df-lim 4546  df-suc 4547  df-om 4805  df-xp 4843  df-rel 4844  df-cnv 4845  df-co 4846  df-dm 4847  df-rn 4848  df-res 4849  df-ima 4850  df-iota 5377  df-fun 5415  df-fn 5416  df-f 5417  df-f1 5418  df-fo 5419  df-f1o 5420  df-fv 5421  df-isom 5422  df-ov 6043  df-oprab 6044  df-mpt2 6045  df-1st 6308  df-2nd 6309  df-riota 6508  df-recs 6592  df-rdg 6627  df-1o 6683  df-2o 6684  df-oadd 6687  df-er 6864  df-map 6979  df-pm 6980  df-en 7069  df-dom 7070  df-sdom 7071  df-fin 7072  df-sup 7404  df-oi 7435  df-card 7782  df-cda 8004  df-pnf 9078  df-mnf 9079  df-xr 9080  df-ltxr 9081  df-le 9082  df-sub 9249  df-neg 9250  df-div 9634  df-nn 9957  df-2 10014  df-3 10015  df-n0 10178  df-z 10239  df-uz 10445  df-rp 10569  df-fz 11000  df-fzo 11091  df-fl 11157  df-mod 11206  df-seq 11279  df-exp 11338  df-hash 11574  df-cj 11859  df-re 11860  df-im 11861  df-sqr 11995  df-abs 11996  df-clim 12237  df-sum 12435  df-dvds 12808  df-bits 12889  df-sad 12918
  Copyright terms: Public domain W3C validator