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

Theorem sadadd 12658
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 1370 and df-cad 1371.

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 12617 . . . . . 6  |-  (bits `  A )  C_  NN0
2 bitsss 12617 . . . . . 6  |-  (bits `  B )  C_  NN0
3 sadcl 12653 . . . . . 6  |-  ( ( (bits `  A )  C_ 
NN0  /\  (bits `  B
)  C_  NN0 )  -> 
( (bits `  A
) sadd  (bits `  B )
)  C_  NN0 )
41, 2, 3mp2an 653 . . . . 5  |-  ( (bits `  A ) sadd  (bits `  B ) )  C_  NN0
54sseli 3176 . . . 4  |-  ( k  e.  ( (bits `  A ) sadd  (bits `  B
) )  ->  k  e.  NN0 )
65a1i 10 . . 3  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  ( (bits `  A ) sadd  (bits `  B ) )  ->  k  e.  NN0 ) )
7 bitsss 12617 . . . . 5  |-  (bits `  ( A  +  B
) )  C_  NN0
87sseli 3176 . . . 4  |-  ( k  e.  (bits `  ( A  +  B )
)  ->  k  e.  NN0 )
98a1i 10 . . 3  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  (bits `  ( A  +  B
) )  ->  k  e.  NN0 ) )
10 eqid 2283 . . . . . . . . 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 2283 . . . . . . . . 9  |-  `' (bits  |`  NN0 )  =  `' (bits  |`  NN0 )
12 simpll 730 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  A  e.  ZZ )
13 simplr 731 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  B  e.  ZZ )
14 simpr 447 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  NN0 )
15 1nn0 9981 . . . . . . . . . . 11  |-  1  e.  NN0
1615a1i 10 . . . . . . . . . 10  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  1  e.  NN0 )
1714, 16nn0addcld 10022 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  +  1 )  e.  NN0 )
1810, 11, 12, 13, 17sadaddlem 12657 . . . . . . . 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 10121 . . . . . . . . 9  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( A  +  B )  e.  ZZ )
20 bitsmod 12627 . . . . . . . . 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 642 . . . . . . . 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 2315 . . . . . . 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 2350 . . . . . 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 3358 . . . . . 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 3358 . . . . . 6  |-  ( k  e.  ( (bits `  ( A  +  B
) )  i^i  (
0..^ ( k  +  1 ) ) )  <-> 
( k  e.  (bits `  ( A  +  B
) )  /\  k  e.  ( 0..^ ( k  +  1 ) ) ) )
2623, 24, 253bitr3g 278 . . . . 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 10262 . . . . . . . . 9  |-  NN0  =  ( ZZ>= `  0 )
2814, 27syl6eleq 2373 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  (
ZZ>= `  0 ) )
29 eluzfz2 10804 . . . . . . . 8  |-  ( k  e.  ( ZZ>= `  0
)  ->  k  e.  ( 0 ... k
) )
3028, 29syl 15 . . . . . . 7  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ( 0 ... k ) )
3114nn0zd 10115 . . . . . . . 8  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ZZ )
32 fzval3 10911 . . . . . . . 8  |-  ( k  e.  ZZ  ->  (
0 ... k )  =  ( 0..^ ( k  +  1 ) ) )
3331, 32syl 15 . . . . . . 7  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( 0 ... k )  =  ( 0..^ ( k  +  1 ) ) )
3430, 33eleqtrd 2359 . . . . . 6  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  k  e.  ( 0..^ ( k  +  1 ) ) )
3534biantrud 493 . . . . 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 493 . . . . 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 276 . . . 4  |-  ( ( ( A  e.  ZZ  /\  B  e.  ZZ )  /\  k  e.  NN0 )  ->  ( k  e.  ( (bits `  A
) sadd  (bits `  B )
)  <->  k  e.  (bits `  ( A  +  B
) ) ) )
3837ex 423 . . 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 343 . 2  |-  ( ( A  e.  ZZ  /\  B  e.  ZZ )  ->  ( k  e.  ( (bits `  A ) sadd  (bits `  B ) )  <-> 
k  e.  (bits `  ( A  +  B
) ) ) )
4039eqrdv 2281 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 176    /\ wa 358  caddwcad 1369    = wceq 1623    e. wcel 1684    i^i cin 3151    C_ wss 3152   (/)c0 3455   ifcif 3565    e. cmpt 4077   `'ccnv 4688    |` cres 4691   ` cfv 5255  (class class class)co 5858    e. cmpt2 5860   1oc1o 6472   2oc2o 6473   0cc0 8737   1c1 8738    + caddc 8740    - cmin 9037   2c2 9795   NN0cn0 9965   ZZcz 10024   ZZ>=cuz 10230   ...cfz 10782  ..^cfzo 10870    mod cmo 10973    seq cseq 11046   ^cexp 11104  bitscbits 12610   sadd csad 12611
This theorem is referenced by:  bitsres  12664  smumullem  12683
This theorem was proved from axioms:  ax-1 5  ax-2 6  ax-3 7  ax-mp 8  ax-gen 1533  ax-5 1544  ax-17 1603  ax-9 1635  ax-8 1643  ax-13 1686  ax-14 1688  ax-6 1703  ax-7 1708  ax-11 1715  ax-12 1866  ax-ext 2264  ax-rep 4131  ax-sep 4141  ax-nul 4149  ax-pow 4188  ax-pr 4214  ax-un 4512  ax-inf2 7342  ax-cnex 8793  ax-resscn 8794  ax-1cn 8795  ax-icn 8796  ax-addcl 8797  ax-addrcl 8798  ax-mulcl 8799  ax-mulrcl 8800  ax-mulcom 8801  ax-addass 8802  ax-mulass 8803  ax-distr 8804  ax-i2m1 8805  ax-1ne0 8806  ax-1rid 8807  ax-rnegex 8808  ax-rrecex 8809  ax-cnre 8810  ax-pre-lttri 8811  ax-pre-lttrn 8812  ax-pre-ltadd 8813  ax-pre-mulgt0 8814  ax-pre-sup 8815
This theorem depends on definitions:  df-bi 177  df-or 359  df-an 360  df-3or 935  df-3an 936  df-xor 1296  df-tru 1310  df-had 1370  df-cad 1371  df-ex 1529  df-nf 1532  df-sb 1630  df-eu 2147  df-mo 2148  df-clab 2270  df-cleq 2276  df-clel 2279  df-nfc 2408  df-ne 2448  df-nel 2449  df-ral 2548  df-rex 2549  df-reu 2550  df-rmo 2551  df-rab 2552  df-v 2790  df-sbc 2992  df-csb 3082  df-dif 3155  df-un 3157  df-in 3159  df-ss 3166  df-pss 3168  df-nul 3456  df-if 3566  df-pw 3627  df-sn 3646  df-pr 3647  df-tp 3648  df-op 3649  df-uni 3828  df-int 3863  df-iun 3907  df-disj 3994  df-br 4024  df-opab 4078  df-mpt 4079  df-tr 4114  df-eprel 4305  df-id 4309  df-po 4314  df-so 4315  df-fr 4352  df-se 4353  df-we 4354  df-ord 4395  df-on 4396  df-lim 4397  df-suc 4398  df-om 4657  df-xp 4695  df-rel 4696  df-cnv 4697  df-co 4698  df-dm 4699  df-rn 4700  df-res 4701  df-ima 4702  df-iota 5219  df-fun 5257  df-fn 5258  df-f 5259  df-f1 5260  df-fo 5261  df-f1o 5262  df-fv 5263  df-isom 5264  df-ov 5861  df-oprab 5862  df-mpt2 5863  df-1st 6122  df-2nd 6123  df-riota 6304  df-recs 6388  df-rdg 6423  df-1o 6479  df-2o 6480  df-oadd 6483  df-er 6660  df-map 6774  df-pm 6775  df-en 6864  df-dom 6865  df-sdom 6866  df-fin 6867  df-sup 7194  df-oi 7225  df-card 7572  df-cda 7794  df-pnf 8869  df-mnf 8870  df-xr 8871  df-ltxr 8872  df-le 8873  df-sub 9039  df-neg 9040  df-div 9424  df-nn 9747  df-2 9804  df-3 9805  df-n0 9966  df-z 10025  df-uz 10231  df-rp 10355  df-fz 10783  df-fzo 10871  df-fl 10925  df-mod 10974  df-seq 11047  df-exp 11105  df-hash 11338  df-cj 11584  df-re 11585  df-im 11586  df-sqr 11720  df-abs 11721  df-clim 11962  df-sum 12159  df-dvds 12532  df-bits 12613  df-sad 12642
  Copyright terms: Public domain W3C validator