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

Theorem karatsuba 17026
Description: The Karatsuba multiplication algorithm. If ๐‘‹ and ๐‘Œ are decomposed into two groups of digits of length ๐‘€ (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 ๐‘‹๐‘Œ 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 12746. (Contributed by Mario Carneiro, 16-Jul-2015.) (Revised by AV, 9-Sep-2021.)
Hypotheses
Ref Expression
karatsuba.a ๐ด โˆˆ โ„•0
karatsuba.b ๐ต โˆˆ โ„•0
karatsuba.c ๐ถ โˆˆ โ„•0
karatsuba.d ๐ท โˆˆ โ„•0
karatsuba.s ๐‘† โˆˆ โ„•0
karatsuba.m ๐‘€ โˆˆ โ„•0
karatsuba.r (๐ด ยท ๐ถ) = ๐‘…
karatsuba.t (๐ต ยท ๐ท) = ๐‘‡
karatsuba.e ((๐ด + ๐ต) ยท (๐ถ + ๐ท)) = ((๐‘… + ๐‘†) + ๐‘‡)
karatsuba.x ((๐ด ยท (10โ†‘๐‘€)) + ๐ต) = ๐‘‹
karatsuba.y ((๐ถ ยท (10โ†‘๐‘€)) + ๐ท) = ๐‘Œ
karatsuba.w ((๐‘… ยท (10โ†‘๐‘€)) + ๐‘†) = ๐‘Š
karatsuba.z ((๐‘Š ยท (10โ†‘๐‘€)) + ๐‘‡) = ๐‘
Assertion
Ref Expression
karatsuba (๐‘‹ ยท ๐‘Œ) = ๐‘

Proof of Theorem karatsuba
StepHypRef Expression
1 karatsuba.a . . . . . 6 ๐ด โˆˆ โ„•0
21nn0cni 12488 . . . . 5 ๐ด โˆˆ โ„‚
3 10nn0 12699 . . . . . . 7 10 โˆˆ โ„•0
43nn0cni 12488 . . . . . 6 10 โˆˆ โ„‚
5 karatsuba.m . . . . . 6 ๐‘€ โˆˆ โ„•0
6 expcl 14050 . . . . . 6 ((10 โˆˆ โ„‚ โˆง ๐‘€ โˆˆ โ„•0) โ†’ (10โ†‘๐‘€) โˆˆ โ„‚)
74, 5, 6mp2an 689 . . . . 5 (10โ†‘๐‘€) โˆˆ โ„‚
82, 7mulcli 11225 . . . 4 (๐ด ยท (10โ†‘๐‘€)) โˆˆ โ„‚
9 karatsuba.b . . . . 5 ๐ต โˆˆ โ„•0
109nn0cni 12488 . . . 4 ๐ต โˆˆ โ„‚
11 karatsuba.c . . . . . 6 ๐ถ โˆˆ โ„•0
1211nn0cni 12488 . . . . 5 ๐ถ โˆˆ โ„‚
1312, 7mulcli 11225 . . . 4 (๐ถ ยท (10โ†‘๐‘€)) โˆˆ โ„‚
14 karatsuba.d . . . . 5 ๐ท โˆˆ โ„•0
1514nn0cni 12488 . . . 4 ๐ท โˆˆ โ„‚
168, 10, 13, 15muladdi 11669 . . 3 (((๐ด ยท (10โ†‘๐‘€)) + ๐ต) ยท ((๐ถ ยท (10โ†‘๐‘€)) + ๐ท)) = ((((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) + (๐ท ยท ๐ต)) + (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต)))
178, 13mulcli 11225 . . . 4 ((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) โˆˆ โ„‚
1815, 10mulcli 11225 . . . 4 (๐ท ยท ๐ต) โˆˆ โ„‚
198, 15mulcli 11225 . . . . 5 ((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) โˆˆ โ„‚
2013, 10mulcli 11225 . . . . 5 ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต) โˆˆ โ„‚
2119, 20addcli 11224 . . . 4 (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต)) โˆˆ โ„‚
2217, 18, 21add32i 11441 . . 3 ((((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) + (๐ท ยท ๐ต)) + (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต))) = ((((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) + (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต))) + (๐ท ยท ๐ต))
238, 12mulcli 11225 . . . . . 6 ((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) โˆˆ โ„‚
24 karatsuba.s . . . . . . 7 ๐‘† โˆˆ โ„•0
2524nn0cni 12488 . . . . . 6 ๐‘† โˆˆ โ„‚
2623, 25, 7adddiri 11231 . . . . 5 ((((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) + ๐‘†) ยท (10โ†‘๐‘€)) = ((((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) ยท (10โ†‘๐‘€)) + (๐‘† ยท (10โ†‘๐‘€)))
272, 7, 12mul32i 11414 . . . . . . . . 9 ((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) = ((๐ด ยท ๐ถ) ยท (10โ†‘๐‘€))
28 karatsuba.r . . . . . . . . . 10 (๐ด ยท ๐ถ) = ๐‘…
2928oveq1i 7415 . . . . . . . . 9 ((๐ด ยท ๐ถ) ยท (10โ†‘๐‘€)) = (๐‘… ยท (10โ†‘๐‘€))
3027, 29eqtri 2754 . . . . . . . 8 ((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) = (๐‘… ยท (10โ†‘๐‘€))
3130oveq1i 7415 . . . . . . 7 (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) + ๐‘†) = ((๐‘… ยท (10โ†‘๐‘€)) + ๐‘†)
32 karatsuba.w . . . . . . 7 ((๐‘… ยท (10โ†‘๐‘€)) + ๐‘†) = ๐‘Š
3331, 32eqtri 2754 . . . . . 6 (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) + ๐‘†) = ๐‘Š
3433oveq1i 7415 . . . . 5 ((((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) + ๐‘†) ยท (10โ†‘๐‘€)) = (๐‘Š ยท (10โ†‘๐‘€))
358, 12, 7mulassi 11229 . . . . . 6 (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) ยท (10โ†‘๐‘€)) = ((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€)))
362, 12mulcli 11225 . . . . . . . . . . . 12 (๐ด ยท ๐ถ) โˆˆ โ„‚
3736, 18, 25add32i 11441 . . . . . . . . . . 11 (((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ๐‘†) = (((๐ด ยท ๐ถ) + ๐‘†) + (๐ท ยท ๐ต))
3828oveq1i 7415 . . . . . . . . . . . 12 ((๐ด ยท ๐ถ) + ๐‘†) = (๐‘… + ๐‘†)
39 karatsuba.t . . . . . . . . . . . . 13 (๐ต ยท ๐ท) = ๐‘‡
4010, 15, 39mulcomli 11227 . . . . . . . . . . . 12 (๐ท ยท ๐ต) = ๐‘‡
4138, 40oveq12i 7417 . . . . . . . . . . 11 (((๐ด ยท ๐ถ) + ๐‘†) + (๐ท ยท ๐ต)) = ((๐‘… + ๐‘†) + ๐‘‡)
4237, 41eqtri 2754 . . . . . . . . . 10 (((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ๐‘†) = ((๐‘… + ๐‘†) + ๐‘‡)
43 karatsuba.e . . . . . . . . . 10 ((๐ด + ๐ต) ยท (๐ถ + ๐ท)) = ((๐‘… + ๐‘†) + ๐‘‡)
442, 10, 12, 15muladdi 11669 . . . . . . . . . 10 ((๐ด + ๐ต) ยท (๐ถ + ๐ท)) = (((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ((๐ด ยท ๐ท) + (๐ถ ยท ๐ต)))
4542, 43, 443eqtr2i 2760 . . . . . . . . 9 (((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ๐‘†) = (((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ((๐ด ยท ๐ท) + (๐ถ ยท ๐ต)))
4636, 18addcli 11224 . . . . . . . . . 10 ((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) โˆˆ โ„‚
472, 15mulcli 11225 . . . . . . . . . . 11 (๐ด ยท ๐ท) โˆˆ โ„‚
4812, 10mulcli 11225 . . . . . . . . . . 11 (๐ถ ยท ๐ต) โˆˆ โ„‚
4947, 48addcli 11224 . . . . . . . . . 10 ((๐ด ยท ๐ท) + (๐ถ ยท ๐ต)) โˆˆ โ„‚
5046, 25, 49addcani 11411 . . . . . . . . 9 ((((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ๐‘†) = (((๐ด ยท ๐ถ) + (๐ท ยท ๐ต)) + ((๐ด ยท ๐ท) + (๐ถ ยท ๐ต))) โ†” ๐‘† = ((๐ด ยท ๐ท) + (๐ถ ยท ๐ต)))
5145, 50mpbi 229 . . . . . . . 8 ๐‘† = ((๐ด ยท ๐ท) + (๐ถ ยท ๐ต))
5251oveq1i 7415 . . . . . . 7 (๐‘† ยท (10โ†‘๐‘€)) = (((๐ด ยท ๐ท) + (๐ถ ยท ๐ต)) ยท (10โ†‘๐‘€))
5347, 48, 7adddiri 11231 . . . . . . 7 (((๐ด ยท ๐ท) + (๐ถ ยท ๐ต)) ยท (10โ†‘๐‘€)) = (((๐ด ยท ๐ท) ยท (10โ†‘๐‘€)) + ((๐ถ ยท ๐ต) ยท (10โ†‘๐‘€)))
542, 15, 7mul32i 11414 . . . . . . . 8 ((๐ด ยท ๐ท) ยท (10โ†‘๐‘€)) = ((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท)
5512, 10, 7mul32i 11414 . . . . . . . 8 ((๐ถ ยท ๐ต) ยท (10โ†‘๐‘€)) = ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต)
5654, 55oveq12i 7417 . . . . . . 7 (((๐ด ยท ๐ท) ยท (10โ†‘๐‘€)) + ((๐ถ ยท ๐ต) ยท (10โ†‘๐‘€))) = (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต))
5752, 53, 563eqtri 2758 . . . . . 6 (๐‘† ยท (10โ†‘๐‘€)) = (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต))
5835, 57oveq12i 7417 . . . . 5 ((((๐ด ยท (10โ†‘๐‘€)) ยท ๐ถ) ยท (10โ†‘๐‘€)) + (๐‘† ยท (10โ†‘๐‘€))) = (((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) + (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต)))
5926, 34, 583eqtr3ri 2763 . . . 4 (((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) + (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต))) = (๐‘Š ยท (10โ†‘๐‘€))
6059, 40oveq12i 7417 . . 3 ((((๐ด ยท (10โ†‘๐‘€)) ยท (๐ถ ยท (10โ†‘๐‘€))) + (((๐ด ยท (10โ†‘๐‘€)) ยท ๐ท) + ((๐ถ ยท (10โ†‘๐‘€)) ยท ๐ต))) + (๐ท ยท ๐ต)) = ((๐‘Š ยท (10โ†‘๐‘€)) + ๐‘‡)
6116, 22, 603eqtri 2758 . 2 (((๐ด ยท (10โ†‘๐‘€)) + ๐ต) ยท ((๐ถ ยท (10โ†‘๐‘€)) + ๐ท)) = ((๐‘Š ยท (10โ†‘๐‘€)) + ๐‘‡)
62 karatsuba.x . . 3 ((๐ด ยท (10โ†‘๐‘€)) + ๐ต) = ๐‘‹
63 karatsuba.y . . 3 ((๐ถ ยท (10โ†‘๐‘€)) + ๐ท) = ๐‘Œ
6462, 63oveq12i 7417 . 2 (((๐ด ยท (10โ†‘๐‘€)) + ๐ต) ยท ((๐ถ ยท (10โ†‘๐‘€)) + ๐ท)) = (๐‘‹ ยท ๐‘Œ)
65 karatsuba.z . 2 ((๐‘Š ยท (10โ†‘๐‘€)) + ๐‘‡) = ๐‘
6661, 64, 653eqtr3i 2762 1 (๐‘‹ ยท ๐‘Œ) = ๐‘
Colors of variables: wff setvar class
Syntax hints:   = wceq 1533   โˆˆ wcel 2098  (class class class)co 7405  โ„‚cc 11110  0cc0 11112  1c1 11113   + caddc 11115   ยท cmul 11117  โ„•0cn0 12476  cdc 12681  โ†‘cexp 14032
This theorem was proved from axioms:  ax-mp 5  ax-1 6  ax-2 7  ax-3 8  ax-gen 1789  ax-4 1803  ax-5 1905  ax-6 1963  ax-7 2003  ax-8 2100  ax-9 2108  ax-10 2129  ax-11 2146  ax-12 2163  ax-ext 2697  ax-sep 5292  ax-nul 5299  ax-pow 5356  ax-pr 5420  ax-un 7722  ax-cnex 11168  ax-resscn 11169  ax-1cn 11170  ax-icn 11171  ax-addcl 11172  ax-addrcl 11173  ax-mulcl 11174  ax-mulrcl 11175  ax-mulcom 11176  ax-addass 11177  ax-mulass 11178  ax-distr 11179  ax-i2m1 11180  ax-1ne0 11181  ax-1rid 11182  ax-rnegex 11183  ax-rrecex 11184  ax-cnre 11185  ax-pre-lttri 11186  ax-pre-lttrn 11187  ax-pre-ltadd 11188  ax-pre-mulgt0 11189
This theorem depends on definitions:  df-bi 206  df-an 396  df-or 845  df-3or 1085  df-3an 1086  df-tru 1536  df-fal 1546  df-ex 1774  df-nf 1778  df-sb 2060  df-mo 2528  df-eu 2557  df-clab 2704  df-cleq 2718  df-clel 2804  df-nfc 2879  df-ne 2935  df-nel 3041  df-ral 3056  df-rex 3065  df-reu 3371  df-rab 3427  df-v 3470  df-sbc 3773  df-csb 3889  df-dif 3946  df-un 3948  df-in 3950  df-ss 3960  df-pss 3962  df-nul 4318  df-if 4524  df-pw 4599  df-sn 4624  df-pr 4626  df-op 4630  df-uni 4903  df-iun 4992  df-br 5142  df-opab 5204  df-mpt 5225  df-tr 5259  df-id 5567  df-eprel 5573  df-po 5581  df-so 5582  df-fr 5624  df-we 5626  df-xp 5675  df-rel 5676  df-cnv 5677  df-co 5678  df-dm 5679  df-rn 5680  df-res 5681  df-ima 5682  df-pred 6294  df-ord 6361  df-on 6362  df-lim 6363  df-suc 6364  df-iota 6489  df-fun 6539  df-fn 6540  df-f 6541  df-f1 6542  df-fo 6543  df-f1o 6544  df-fv 6545  df-riota 7361  df-ov 7408  df-oprab 7409  df-mpo 7410  df-om 7853  df-2nd 7975  df-frecs 8267  df-wrecs 8298  df-recs 8372  df-rdg 8411  df-er 8705  df-en 8942  df-dom 8943  df-sdom 8944  df-pnf 11254  df-mnf 11255  df-xr 11256  df-ltxr 11257  df-le 11258  df-sub 11450  df-neg 11451  df-nn 12217  df-2 12279  df-3 12280  df-4 12281  df-5 12282  df-6 12283  df-7 12284  df-8 12285  df-9 12286  df-n0 12477  df-z 12563  df-dec 12682  df-uz 12827  df-seq 13973  df-exp 14033
This theorem is referenced by:  dpmul4  32585
  Copyright terms: Public domain W3C validator