ILE Home Intuitionistic Logic Explorer < Previous   Next >
Nearby theorems
Mirrors  >  Home  >  ILE Home  >  Th. List  >  karatsuba Unicode version

Theorem karatsuba 12797
Description: The Karatsuba multiplication algorithm. If  X and  Y are decomposed into two groups of digits of length  M (only the lower group is known to be this size but the algorithm is most efficient when the partition is chosen near the middle of the digit string), then  X Y can be written in three groups of digits, where each group needs only one multiplication. Thus, we can halve both inputs with only three multiplications on the smaller operands, yielding an asymptotic improvement of n^(log2 3) instead of n^2 for the "naive" algorithm decmul1c 9575. (Contributed by Mario Carneiro, 16-Jul-2015.) (Revised by AV, 9-Sep-2021.)
Hypotheses
Ref Expression
karatsuba.a  |-  A  e. 
NN0
karatsuba.b  |-  B  e. 
NN0
karatsuba.c  |-  C  e. 
NN0
karatsuba.d  |-  D  e. 
NN0
karatsuba.s  |-  S  e. 
NN0
karatsuba.m  |-  M  e. 
NN0
karatsuba.r  |-  ( A  x.  C )  =  R
karatsuba.t  |-  ( B  x.  D )  =  T
karatsuba.e  |-  ( ( A  +  B )  x.  ( C  +  D ) )  =  ( ( R  +  S )  +  T
)
karatsuba.x  |-  ( ( A  x.  (; 1 0 ^ M
) )  +  B
)  =  X
karatsuba.y  |-  ( ( C  x.  (; 1 0 ^ M
) )  +  D
)  =  Y
karatsuba.w  |-  ( ( R  x.  (; 1 0 ^ M
) )  +  S
)  =  W
karatsuba.z  |-  ( ( W  x.  (; 1 0 ^ M
) )  +  T
)  =  Z
Assertion
Ref Expression
karatsuba  |-  ( X  x.  Y )  =  Z

Proof of Theorem karatsuba
StepHypRef Expression
1 karatsuba.a . . . . . 6  |-  A  e. 
NN0
21nn0cni 9314 . . . . 5  |-  A  e.  CC
3 10nn0 9528 . . . . . . 7  |- ; 1 0  e.  NN0
43nn0cni 9314 . . . . . 6  |- ; 1 0  e.  CC
5 karatsuba.m . . . . . 6  |-  M  e. 
NN0
6 expcl 10709 . . . . . 6  |-  ( (; 1
0  e.  CC  /\  M  e.  NN0 )  -> 
(; 1 0 ^ M
)  e.  CC )
74, 5, 6mp2an 426 . . . . 5  |-  (; 1 0 ^ M
)  e.  CC
82, 7mulcli 8084 . . . 4  |-  ( A  x.  (; 1 0 ^ M
) )  e.  CC
9 karatsuba.b . . . . 5  |-  B  e. 
NN0
109nn0cni 9314 . . . 4  |-  B  e.  CC
11 karatsuba.c . . . . . 6  |-  C  e. 
NN0
1211nn0cni 9314 . . . . 5  |-  C  e.  CC
1312, 7mulcli 8084 . . . 4  |-  ( C  x.  (; 1 0 ^ M
) )  e.  CC
14 karatsuba.d . . . . 5  |-  D  e. 
NN0
1514nn0cni 9314 . . . 4  |-  D  e.  CC
168, 10, 13, 15muladdi 8488 . . 3  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  +  B )  x.  ( ( C  x.  (; 1 0 ^ M ) )  +  D ) )  =  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  +  ( D  x.  B
) )  +  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) ) )
178, 13mulcli 8084 . . . 4  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  e.  CC
1815, 10mulcli 8084 . . . 4  |-  ( D  x.  B )  e.  CC
198, 15mulcli 8084 . . . . 5  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  e.  CC
2013, 10mulcli 8084 . . . . 5  |-  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
)  e.  CC
2119, 20addcli 8083 . . . 4  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M ) )  x.  B ) )  e.  CC
2217, 18, 21add32i 8243 . . 3  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  +  ( D  x.  B
) )  +  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) ) )  =  ( ( ( ( A  x.  (; 1 0 ^ M
) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  +  ( ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) ) )  +  ( D  x.  B
) )
238, 12mulcli 8084 . . . . . 6  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  e.  CC
24 karatsuba.s . . . . . . 7  |-  S  e. 
NN0
2524nn0cni 9314 . . . . . 6  |-  S  e.  CC
2623, 25, 7adddiri 8090 . . . . 5  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  x.  (; 1 0 ^ M
) )  =  ( ( ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  x.  (; 1 0 ^ M
) )  +  ( S  x.  (; 1 0 ^ M
) ) )
272, 7, 12mul32i 8226 . . . . . . . . 9  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  =  ( ( A  x.  C )  x.  (; 1 0 ^ M
) )
28 karatsuba.r . . . . . . . . . 10  |-  ( A  x.  C )  =  R
2928oveq1i 5961 . . . . . . . . 9  |-  ( ( A  x.  C )  x.  (; 1 0 ^ M
) )  =  ( R  x.  (; 1 0 ^ M
) )
3027, 29eqtri 2227 . . . . . . . 8  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  =  ( R  x.  (; 1 0 ^ M
) )
3130oveq1i 5961 . . . . . . 7  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  =  ( ( R  x.  (; 1 0 ^ M ) )  +  S )
32 karatsuba.w . . . . . . 7  |-  ( ( R  x.  (; 1 0 ^ M
) )  +  S
)  =  W
3331, 32eqtri 2227 . . . . . 6  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  =  W
3433oveq1i 5961 . . . . 5  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  x.  (; 1 0 ^ M
) )  =  ( W  x.  (; 1 0 ^ M
) )
358, 12, 7mulassi 8088 . . . . . 6  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  x.  (; 1 0 ^ M
) )  =  ( ( A  x.  (; 1 0 ^ M ) )  x.  ( C  x.  (; 1 0 ^ M ) ) )
362, 12mulcli 8084 . . . . . . . . . . . 12  |-  ( A  x.  C )  e.  CC
3736, 18, 25add32i 8243 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  S )  +  ( D  x.  B ) )
3828oveq1i 5961 . . . . . . . . . . . 12  |-  ( ( A  x.  C )  +  S )  =  ( R  +  S
)
39 karatsuba.t . . . . . . . . . . . . 13  |-  ( B  x.  D )  =  T
4010, 15, 39mulcomli 8086 . . . . . . . . . . . 12  |-  ( D  x.  B )  =  T
4138, 40oveq12i 5963 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  S )  +  ( D  x.  B ) )  =  ( ( R  +  S )  +  T
)
4237, 41eqtri 2227 . . . . . . . . . 10  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( R  +  S )  +  T
)
43 karatsuba.e . . . . . . . . . 10  |-  ( ( A  +  B )  x.  ( C  +  D ) )  =  ( ( R  +  S )  +  T
)
442, 10, 12, 15muladdi 8488 . . . . . . . . . 10  |-  ( ( A  +  B )  x.  ( C  +  D ) )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4542, 43, 443eqtr2i 2233 . . . . . . . . 9  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4636, 18addcli 8083 . . . . . . . . . 10  |-  ( ( A  x.  C )  +  ( D  x.  B ) )  e.  CC
472, 15mulcli 8084 . . . . . . . . . . 11  |-  ( A  x.  D )  e.  CC
4812, 10mulcli 8084 . . . . . . . . . . 11  |-  ( C  x.  B )  e.  CC
4947, 48addcli 8083 . . . . . . . . . 10  |-  ( ( A  x.  D )  +  ( C  x.  B ) )  e.  CC
5046, 25, 49addcani 8261 . . . . . . . . 9  |-  ( ( ( ( A  x.  C )  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  ( D  x.  B ) )  +  ( ( A  x.  D )  +  ( C  x.  B ) ) )  <->  S  =  ( ( A  x.  D )  +  ( C  x.  B ) ) )
5145, 50mpbi 145 . . . . . . . 8  |-  S  =  ( ( A  x.  D )  +  ( C  x.  B ) )
5251oveq1i 5961 . . . . . . 7  |-  ( S  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  D )  +  ( C  x.  B ) )  x.  (; 1 0 ^ M
) )
5347, 48, 7adddiri 8090 . . . . . . 7  |-  ( ( ( A  x.  D
)  +  ( C  x.  B ) )  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  D )  x.  (; 1 0 ^ M ) )  +  ( ( C  x.  B )  x.  (; 1 0 ^ M
) ) )
542, 15, 7mul32i 8226 . . . . . . . 8  |-  ( ( A  x.  D )  x.  (; 1 0 ^ M
) )  =  ( ( A  x.  (; 1 0 ^ M ) )  x.  D )
5512, 10, 7mul32i 8226 . . . . . . . 8  |-  ( ( C  x.  B )  x.  (; 1 0 ^ M
) )  =  ( ( C  x.  (; 1 0 ^ M ) )  x.  B )
5654, 55oveq12i 5963 . . . . . . 7  |-  ( ( ( A  x.  D
)  x.  (; 1 0 ^ M
) )  +  ( ( C  x.  B
)  x.  (; 1 0 ^ M
) ) )  =  ( ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) )
5752, 53, 563eqtri 2231 . . . . . 6  |-  ( S  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) )
5835, 57oveq12i 5963 . . . . 5  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  x.  (; 1 0 ^ M
) )  +  ( S  x.  (; 1 0 ^ M
) ) )  =  ( ( ( A  x.  (; 1 0 ^ M
) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  +  ( ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) ) )
5926, 34, 583eqtr3ri 2236 . . . 4  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  ( C  x.  (; 1 0 ^ M ) ) )  +  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) ) )  =  ( W  x.  (; 1 0 ^ M ) )
6059, 40oveq12i 5963 . . 3  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  +  ( ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) ) )  +  ( D  x.  B
) )  =  ( ( W  x.  (; 1 0 ^ M ) )  +  T )
6116, 22, 603eqtri 2231 . 2  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  +  B )  x.  ( ( C  x.  (; 1 0 ^ M ) )  +  D ) )  =  ( ( W  x.  (; 1 0 ^ M
) )  +  T
)
62 karatsuba.x . . 3  |-  ( ( A  x.  (; 1 0 ^ M
) )  +  B
)  =  X
63 karatsuba.y . . 3  |-  ( ( C  x.  (; 1 0 ^ M
) )  +  D
)  =  Y
6462, 63oveq12i 5963 . 2  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  +  B )  x.  ( ( C  x.  (; 1 0 ^ M ) )  +  D ) )  =  ( X  x.  Y )
65 karatsuba.z . 2  |-  ( ( W  x.  (; 1 0 ^ M
) )  +  T
)  =  Z
6661, 64, 653eqtr3i 2235 1  |-  ( X  x.  Y )  =  Z
Colors of variables: wff set class
Syntax hints:    = wceq 1373    e. wcel 2177  (class class class)co 5951   CCcc 7930   0cc0 7932   1c1 7933    + caddc 7935    x. cmul 7937   NN0cn0 9302  ;cdc 9511   ^cexp 10690
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-ia1 106  ax-ia2 107  ax-ia3 108  ax-in1 615  ax-in2 616  ax-io 711  ax-5 1471  ax-7 1472  ax-gen 1473  ax-ie1 1517  ax-ie2 1518  ax-8 1528  ax-10 1529  ax-11 1530  ax-i12 1531  ax-bndl 1533  ax-4 1534  ax-17 1550  ax-i9 1554  ax-ial 1558  ax-i5r 1559  ax-13 2179  ax-14 2180  ax-ext 2188  ax-coll 4163  ax-sep 4166  ax-nul 4174  ax-pow 4222  ax-pr 4257  ax-un 4484  ax-setind 4589  ax-iinf 4640  ax-cnex 8023  ax-resscn 8024  ax-1cn 8025  ax-1re 8026  ax-icn 8027  ax-addcl 8028  ax-addrcl 8029  ax-mulcl 8030  ax-mulrcl 8031  ax-addcom 8032  ax-mulcom 8033  ax-addass 8034  ax-mulass 8035  ax-distr 8036  ax-i2m1 8037  ax-0lt1 8038  ax-1rid 8039  ax-0id 8040  ax-rnegex 8041  ax-precex 8042  ax-cnre 8043  ax-pre-ltirr 8044  ax-pre-ltwlin 8045  ax-pre-lttrn 8046  ax-pre-apti 8047  ax-pre-ltadd 8048  ax-pre-mulgt0 8049  ax-pre-mulext 8050
This theorem depends on definitions:  df-bi 117  df-dc 837  df-3or 982  df-3an 983  df-tru 1376  df-fal 1379  df-nf 1485  df-sb 1787  df-eu 2058  df-mo 2059  df-clab 2193  df-cleq 2199  df-clel 2202  df-nfc 2338  df-ne 2378  df-nel 2473  df-ral 2490  df-rex 2491  df-reu 2492  df-rmo 2493  df-rab 2494  df-v 2775  df-sbc 3000  df-csb 3095  df-dif 3169  df-un 3171  df-in 3173  df-ss 3180  df-nul 3462  df-if 3573  df-pw 3619  df-sn 3640  df-pr 3641  df-op 3643  df-uni 3853  df-int 3888  df-iun 3931  df-br 4048  df-opab 4110  df-mpt 4111  df-tr 4147  df-id 4344  df-po 4347  df-iso 4348  df-iord 4417  df-on 4419  df-ilim 4420  df-suc 4422  df-iom 4643  df-xp 4685  df-rel 4686  df-cnv 4687  df-co 4688  df-dm 4689  df-rn 4690  df-res 4691  df-ima 4692  df-iota 5237  df-fun 5278  df-fn 5279  df-f 5280  df-f1 5281  df-fo 5282  df-f1o 5283  df-fv 5284  df-riota 5906  df-ov 5954  df-oprab 5955  df-mpo 5956  df-1st 6233  df-2nd 6234  df-recs 6398  df-frec 6484  df-pnf 8116  df-mnf 8117  df-xr 8118  df-ltxr 8119  df-le 8120  df-sub 8252  df-neg 8253  df-reap 8655  df-ap 8662  df-div 8753  df-inn 9044  df-2 9102  df-3 9103  df-4 9104  df-5 9105  df-6 9106  df-7 9107  df-8 9108  df-9 9109  df-n0 9303  df-z 9380  df-dec 9512  df-uz 9656  df-seqfrec 10600  df-exp 10691
This theorem is referenced by: (None)
  Copyright terms: Public domain W3C validator