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

Theorem karatsuba 13412
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 10421. (Contributed by Mario Carneiro, 16-Jul-2015.)
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.  ( 10
^ M ) )  +  B )  =  X
karatsuba.y  |-  ( ( C  x.  ( 10
^ M ) )  +  D )  =  Y
karatsuba.w  |-  ( ( R  x.  ( 10
^ M ) )  +  S )  =  W
karatsuba.z  |-  ( ( W  x.  ( 10
^ 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 10225 . . . . 5  |-  A  e.  CC
3 10nn0 10238 . . . . . . 7  |-  10  e.  NN0
43nn0cni 10225 . . . . . 6  |-  10  e.  CC
5 karatsuba.m . . . . . 6  |-  M  e. 
NN0
6 expcl 11391 . . . . . 6  |-  ( ( 10  e.  CC  /\  M  e.  NN0 )  -> 
( 10 ^ M
)  e.  CC )
74, 5, 6mp2an 654 . . . . 5  |-  ( 10
^ M )  e.  CC
82, 7mulcli 9087 . . . 4  |-  ( A  x.  ( 10 ^ M ) )  e.  CC
9 karatsuba.b . . . . 5  |-  B  e. 
NN0
109nn0cni 10225 . . . 4  |-  B  e.  CC
11 karatsuba.c . . . . . 6  |-  C  e. 
NN0
1211nn0cni 10225 . . . . 5  |-  C  e.  CC
1312, 7mulcli 9087 . . . 4  |-  ( C  x.  ( 10 ^ M ) )  e.  CC
14 karatsuba.d . . . . 5  |-  D  e. 
NN0
1514nn0cni 10225 . . . 4  |-  D  e.  CC
168, 10, 13, 15muladdi 9476 . . 3  |-  ( ( ( A  x.  ( 10 ^ M ) )  +  B )  x.  ( ( C  x.  ( 10 ^ M ) )  +  D ) )  =  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  +  ( D  x.  B ) )  +  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) ) )
178, 13mulcli 9087 . . . 4  |-  ( ( A  x.  ( 10
^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  e.  CC
1815, 10mulcli 9087 . . . 4  |-  ( D  x.  B )  e.  CC
198, 15mulcli 9087 . . . . 5  |-  ( ( A  x.  ( 10
^ M ) )  x.  D )  e.  CC
2013, 10mulcli 9087 . . . . 5  |-  ( ( C  x.  ( 10
^ M ) )  x.  B )  e.  CC
2119, 20addcli 9086 . . . 4  |-  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) )  e.  CC
2217, 18, 21add32i 9276 . . 3  |-  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  +  ( D  x.  B ) )  +  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) ) )  =  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  +  ( ( ( A  x.  ( 10
^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) ) )  +  ( D  x.  B ) )
238, 12mulcli 9087 . . . . . 6  |-  ( ( A  x.  ( 10
^ M ) )  x.  C )  e.  CC
24 karatsuba.s . . . . . . 7  |-  S  e. 
NN0
2524nn0cni 10225 . . . . . 6  |-  S  e.  CC
2623, 25, 7adddiri 9093 . . . . 5  |-  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  +  S )  x.  ( 10 ^ M
) )  =  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  x.  ( 10 ^ M ) )  +  ( S  x.  ( 10 ^ M ) ) )
272, 7, 12mul32i 9254 . . . . . . . . 9  |-  ( ( A  x.  ( 10
^ M ) )  x.  C )  =  ( ( A  x.  C )  x.  ( 10 ^ M ) )
28 karatsuba.r . . . . . . . . . 10  |-  ( A  x.  C )  =  R
2928oveq1i 6083 . . . . . . . . 9  |-  ( ( A  x.  C )  x.  ( 10 ^ M ) )  =  ( R  x.  ( 10 ^ M ) )
3027, 29eqtri 2455 . . . . . . . 8  |-  ( ( A  x.  ( 10
^ M ) )  x.  C )  =  ( R  x.  ( 10 ^ M ) )
3130oveq1i 6083 . . . . . . 7  |-  ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  +  S )  =  ( ( R  x.  ( 10 ^ M ) )  +  S )
32 karatsuba.w . . . . . . 7  |-  ( ( R  x.  ( 10
^ M ) )  +  S )  =  W
3331, 32eqtri 2455 . . . . . 6  |-  ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  +  S )  =  W
3433oveq1i 6083 . . . . 5  |-  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  +  S )  x.  ( 10 ^ M
) )  =  ( W  x.  ( 10
^ M ) )
358, 12, 7mulassi 9091 . . . . . 6  |-  ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  x.  ( 10 ^ M
) )  =  ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )
362, 12mulcli 9087 . . . . . . . . . . . 12  |-  ( A  x.  C )  e.  CC
3736, 18, 25add32i 9276 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  S )  +  ( D  x.  B ) )
3828oveq1i 6083 . . . . . . . . . . . 12  |-  ( ( A  x.  C )  +  S )  =  ( R  +  S
)
39 karatsuba.t . . . . . . . . . . . . 13  |-  ( B  x.  D )  =  T
4010, 15, 39mulcomli 9089 . . . . . . . . . . . 12  |-  ( D  x.  B )  =  T
4138, 40oveq12i 6085 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  S )  +  ( D  x.  B ) )  =  ( ( R  +  S )  +  T
)
4237, 41eqtri 2455 . . . . . . . . . 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 9476 . . . . . . . . . 10  |-  ( ( A  +  B )  x.  ( C  +  D ) )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4542, 43, 443eqtr2i 2461 . . . . . . . . 9  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4636, 18addcli 9086 . . . . . . . . . 10  |-  ( ( A  x.  C )  +  ( D  x.  B ) )  e.  CC
472, 15mulcli 9087 . . . . . . . . . . 11  |-  ( A  x.  D )  e.  CC
4812, 10mulcli 9087 . . . . . . . . . . 11  |-  ( C  x.  B )  e.  CC
4947, 48addcli 9086 . . . . . . . . . 10  |-  ( ( A  x.  D )  +  ( C  x.  B ) )  e.  CC
5046, 25, 49addcani 9251 . . . . . . . . 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 200 . . . . . . . 8  |-  S  =  ( ( A  x.  D )  +  ( C  x.  B ) )
5251oveq1i 6083 . . . . . . 7  |-  ( S  x.  ( 10 ^ M ) )  =  ( ( ( A  x.  D )  +  ( C  x.  B
) )  x.  ( 10 ^ M ) )
5347, 48, 7adddiri 9093 . . . . . . 7  |-  ( ( ( A  x.  D
)  +  ( C  x.  B ) )  x.  ( 10 ^ M ) )  =  ( ( ( A  x.  D )  x.  ( 10 ^ M
) )  +  ( ( C  x.  B
)  x.  ( 10
^ M ) ) )
542, 15, 7mul32i 9254 . . . . . . . 8  |-  ( ( A  x.  D )  x.  ( 10 ^ M ) )  =  ( ( A  x.  ( 10 ^ M ) )  x.  D )
5512, 10, 7mul32i 9254 . . . . . . . 8  |-  ( ( C  x.  B )  x.  ( 10 ^ M ) )  =  ( ( C  x.  ( 10 ^ M ) )  x.  B )
5654, 55oveq12i 6085 . . . . . . 7  |-  ( ( ( A  x.  D
)  x.  ( 10
^ M ) )  +  ( ( C  x.  B )  x.  ( 10 ^ M
) ) )  =  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) )
5752, 53, 563eqtri 2459 . . . . . 6  |-  ( S  x.  ( 10 ^ M ) )  =  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) )
5835, 57oveq12i 6085 . . . . 5  |-  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  C )  x.  ( 10 ^ M ) )  +  ( S  x.  ( 10 ^ M ) ) )  =  ( ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  +  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) ) )
5926, 34, 583eqtr3ri 2464 . . . 4  |-  ( ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  +  ( ( ( A  x.  ( 10 ^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) ) )  =  ( W  x.  ( 10 ^ M ) )
6059, 40oveq12i 6085 . . 3  |-  ( ( ( ( A  x.  ( 10 ^ M ) )  x.  ( C  x.  ( 10 ^ M ) ) )  +  ( ( ( A  x.  ( 10
^ M ) )  x.  D )  +  ( ( C  x.  ( 10 ^ M ) )  x.  B ) ) )  +  ( D  x.  B ) )  =  ( ( W  x.  ( 10
^ M ) )  +  T )
6116, 22, 603eqtri 2459 . 2  |-  ( ( ( A  x.  ( 10 ^ M ) )  +  B )  x.  ( ( C  x.  ( 10 ^ M ) )  +  D ) )  =  ( ( W  x.  ( 10
^ M ) )  +  T )
62 karatsuba.x . . 3  |-  ( ( A  x.  ( 10
^ M ) )  +  B )  =  X
63 karatsuba.y . . 3  |-  ( ( C  x.  ( 10
^ M ) )  +  D )  =  Y
6462, 63oveq12i 6085 . 2  |-  ( ( ( A  x.  ( 10 ^ M ) )  +  B )  x.  ( ( C  x.  ( 10 ^ M ) )  +  D ) )  =  ( X  x.  Y )
65 karatsuba.z . 2  |-  ( ( W  x.  ( 10
^ M ) )  +  T )  =  Z
6661, 64, 653eqtr3i 2463 1  |-  ( X  x.  Y )  =  Z
Colors of variables: wff set class
Syntax hints:    = wceq 1652    e. wcel 1725  (class class class)co 6073   CCcc 8980    + caddc 8985    x. cmul 8987   10c10 10049   NN0cn0 10213   ^cexp 11374
This theorem was proved from axioms:  ax-1 5  ax-2 6  ax-3 7  ax-mp 8  ax-gen 1555  ax-5 1566  ax-17 1626  ax-9 1666  ax-8 1687  ax-13 1727  ax-14 1729  ax-6 1744  ax-7 1749  ax-11 1761  ax-12 1950  ax-ext 2416  ax-sep 4322  ax-nul 4330  ax-pow 4369  ax-pr 4395  ax-un 4693  ax-cnex 9038  ax-resscn 9039  ax-1cn 9040  ax-icn 9041  ax-addcl 9042  ax-addrcl 9043  ax-mulcl 9044  ax-mulrcl 9045  ax-mulcom 9046  ax-addass 9047  ax-mulass 9048  ax-distr 9049  ax-i2m1 9050  ax-1ne0 9051  ax-1rid 9052  ax-rnegex 9053  ax-rrecex 9054  ax-cnre 9055  ax-pre-lttri 9056  ax-pre-lttrn 9057  ax-pre-ltadd 9058  ax-pre-mulgt0 9059
This theorem depends on definitions:  df-bi 178  df-or 360  df-an 361  df-3or 937  df-3an 938  df-tru 1328  df-ex 1551  df-nf 1554  df-sb 1659  df-eu 2284  df-mo 2285  df-clab 2422  df-cleq 2428  df-clel 2431  df-nfc 2560  df-ne 2600  df-nel 2601  df-ral 2702  df-rex 2703  df-reu 2704  df-rab 2706  df-v 2950  df-sbc 3154  df-csb 3244  df-dif 3315  df-un 3317  df-in 3319  df-ss 3326  df-pss 3328  df-nul 3621  df-if 3732  df-pw 3793  df-sn 3812  df-pr 3813  df-tp 3814  df-op 3815  df-uni 4008  df-iun 4087  df-br 4205  df-opab 4259  df-mpt 4260  df-tr 4295  df-eprel 4486  df-id 4490  df-po 4495  df-so 4496  df-fr 4533  df-we 4535  df-ord 4576  df-on 4577  df-lim 4578  df-suc 4579  df-om 4838  df-xp 4876  df-rel 4877  df-cnv 4878  df-co 4879  df-dm 4880  df-rn 4881  df-res 4882  df-ima 4883  df-iota 5410  df-fun 5448  df-fn 5449  df-f 5450  df-f1 5451  df-fo 5452  df-f1o 5453  df-fv 5454  df-ov 6076  df-oprab 6077  df-mpt2 6078  df-2nd 6342  df-riota 6541  df-recs 6625  df-rdg 6660  df-er 6897  df-en 7102  df-dom 7103  df-sdom 7104  df-pnf 9114  df-mnf 9115  df-xr 9116  df-ltxr 9117  df-le 9118  df-sub 9285  df-neg 9286  df-nn 9993  df-2 10050  df-3 10051  df-4 10052  df-5 10053  df-6 10054  df-7 10055  df-8 10056  df-9 10057  df-10 10058  df-n0 10214  df-z 10275  df-uz 10481  df-seq 11316  df-exp 11375
  Copyright terms: Public domain W3C validator