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

Theorem karatsuba 13124
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 9772. (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 9507 . . . . 5  |-  A  e.  CC
3 10nn0 9725 . . . . . . 7  |- ; 1 0  e.  NN0
43nn0cni 9507 . . . . . 6  |- ; 1 0  e.  CC
5 karatsuba.m . . . . . 6  |-  M  e. 
NN0
6 expcl 10918 . . . . . 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 8278 . . . 4  |-  ( A  x.  (; 1 0 ^ M
) )  e.  CC
9 karatsuba.b . . . . 5  |-  B  e. 
NN0
109nn0cni 9507 . . . 4  |-  B  e.  CC
11 karatsuba.c . . . . . 6  |-  C  e. 
NN0
1211nn0cni 9507 . . . . 5  |-  C  e.  CC
1312, 7mulcli 8278 . . . 4  |-  ( C  x.  (; 1 0 ^ M
) )  e.  CC
14 karatsuba.d . . . . 5  |-  D  e. 
NN0
1514nn0cni 9507 . . . 4  |-  D  e.  CC
168, 10, 13, 15muladdi 8681 . . 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 8278 . . . 4  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  e.  CC
1815, 10mulcli 8278 . . . 4  |-  ( D  x.  B )  e.  CC
198, 15mulcli 8278 . . . . 5  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  e.  CC
2013, 10mulcli 8278 . . . . 5  |-  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
)  e.  CC
2119, 20addcli 8277 . . . 4  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M ) )  x.  B ) )  e.  CC
2217, 18, 21add32i 8436 . . 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 8278 . . . . . 6  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  e.  CC
24 karatsuba.s . . . . . . 7  |-  S  e. 
NN0
2524nn0cni 9507 . . . . . 6  |-  S  e.  CC
2623, 25, 7adddiri 8284 . . . . 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 8419 . . . . . . . . 9  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  =  ( ( A  x.  C )  x.  (; 1 0 ^ M
) )
28 karatsuba.r . . . . . . . . . 10  |-  ( A  x.  C )  =  R
2928oveq1i 6059 . . . . . . . . 9  |-  ( ( A  x.  C )  x.  (; 1 0 ^ M
) )  =  ( R  x.  (; 1 0 ^ M
) )
3027, 29eqtri 2253 . . . . . . . 8  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  =  ( R  x.  (; 1 0 ^ M
) )
3130oveq1i 6059 . . . . . . 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 2253 . . . . . 6  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  =  W
3433oveq1i 6059 . . . . 5  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  x.  (; 1 0 ^ M
) )  =  ( W  x.  (; 1 0 ^ M
) )
358, 12, 7mulassi 8282 . . . . . 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 8278 . . . . . . . . . . . 12  |-  ( A  x.  C )  e.  CC
3736, 18, 25add32i 8436 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  S )  +  ( D  x.  B ) )
3828oveq1i 6059 . . . . . . . . . . . 12  |-  ( ( A  x.  C )  +  S )  =  ( R  +  S
)
39 karatsuba.t . . . . . . . . . . . . 13  |-  ( B  x.  D )  =  T
4010, 15, 39mulcomli 8280 . . . . . . . . . . . 12  |-  ( D  x.  B )  =  T
4138, 40oveq12i 6061 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  S )  +  ( D  x.  B ) )  =  ( ( R  +  S )  +  T
)
4237, 41eqtri 2253 . . . . . . . . . 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 8681 . . . . . . . . . 10  |-  ( ( A  +  B )  x.  ( C  +  D ) )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4542, 43, 443eqtr2i 2259 . . . . . . . . 9  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4636, 18addcli 8277 . . . . . . . . . 10  |-  ( ( A  x.  C )  +  ( D  x.  B ) )  e.  CC
472, 15mulcli 8278 . . . . . . . . . . 11  |-  ( A  x.  D )  e.  CC
4812, 10mulcli 8278 . . . . . . . . . . 11  |-  ( C  x.  B )  e.  CC
4947, 48addcli 8277 . . . . . . . . . 10  |-  ( ( A  x.  D )  +  ( C  x.  B ) )  e.  CC
5046, 25, 49addcani 8454 . . . . . . . . 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 6059 . . . . . . 7  |-  ( S  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  D )  +  ( C  x.  B ) )  x.  (; 1 0 ^ M
) )
5347, 48, 7adddiri 8284 . . . . . . 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 8419 . . . . . . . 8  |-  ( ( A  x.  D )  x.  (; 1 0 ^ M
) )  =  ( ( A  x.  (; 1 0 ^ M ) )  x.  D )
5512, 10, 7mul32i 8419 . . . . . . . 8  |-  ( ( C  x.  B )  x.  (; 1 0 ^ M
) )  =  ( ( C  x.  (; 1 0 ^ M ) )  x.  B )
5654, 55oveq12i 6061 . . . . . . 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 2257 . . . . . 6  |-  ( S  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) )
5835, 57oveq12i 6061 . . . . 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 2262 . . . 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 6061 . . 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 2257 . 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 6061 . 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 2261 1  |-  ( X  x.  Y )  =  Z
Colors of variables: wff set class
Syntax hints:    = wceq 1398    e. wcel 2203  (class class class)co 6049   CCcc 8124   0cc0 8126   1c1 8127    + caddc 8129    x. cmul 8131   NN0cn0 9495  ;cdc 9708   ^cexp 10899
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 619  ax-in2 620  ax-io 717  ax-5 1496  ax-7 1497  ax-gen 1498  ax-ie1 1542  ax-ie2 1543  ax-8 1553  ax-10 1554  ax-11 1555  ax-i12 1556  ax-bndl 1558  ax-4 1559  ax-17 1575  ax-i9 1579  ax-ial 1583  ax-i5r 1584  ax-13 2205  ax-14 2206  ax-ext 2214  ax-coll 4224  ax-sep 4227  ax-nul 4235  ax-pow 4286  ax-pr 4321  ax-un 4553  ax-setind 4658  ax-iinf 4709  ax-cnex 8217  ax-resscn 8218  ax-1cn 8219  ax-1re 8220  ax-icn 8221  ax-addcl 8222  ax-addrcl 8223  ax-mulcl 8224  ax-mulrcl 8225  ax-addcom 8226  ax-mulcom 8227  ax-addass 8228  ax-mulass 8229  ax-distr 8230  ax-i2m1 8231  ax-0lt1 8232  ax-1rid 8233  ax-0id 8234  ax-rnegex 8235  ax-precex 8236  ax-cnre 8237  ax-pre-ltirr 8238  ax-pre-ltwlin 8239  ax-pre-lttrn 8240  ax-pre-apti 8241  ax-pre-ltadd 8242  ax-pre-mulgt0 8243  ax-pre-mulext 8244
This theorem depends on definitions:  df-bi 117  df-dc 843  df-3or 1006  df-3an 1007  df-tru 1401  df-fal 1404  df-nf 1510  df-sb 1812  df-eu 2083  df-mo 2084  df-clab 2219  df-cleq 2225  df-clel 2228  df-nfc 2373  df-ne 2413  df-nel 2508  df-ral 2525  df-rex 2526  df-reu 2527  df-rmo 2528  df-rab 2529  df-v 2814  df-sbc 3042  df-csb 3138  df-dif 3212  df-un 3214  df-in 3216  df-ss 3223  df-nul 3508  df-if 3620  df-pw 3670  df-sn 3694  df-pr 3695  df-op 3697  df-uni 3914  df-int 3949  df-iun 3992  df-br 4109  df-opab 4171  df-mpt 4172  df-tr 4208  df-id 4413  df-po 4416  df-iso 4417  df-iord 4486  df-on 4488  df-ilim 4489  df-suc 4491  df-iom 4712  df-xp 4754  df-rel 4755  df-cnv 4756  df-co 4757  df-dm 4758  df-rn 4759  df-res 4760  df-ima 4761  df-iota 5311  df-fun 5353  df-fn 5354  df-f 5355  df-f1 5356  df-fo 5357  df-f1o 5358  df-fv 5359  df-riota 6002  df-ov 6052  df-oprab 6053  df-mpo 6054  df-1st 6333  df-2nd 6334  df-recs 6535  df-frec 6621  df-pnf 8309  df-mnf 8310  df-xr 8311  df-ltxr 8312  df-le 8313  df-sub 8445  df-neg 8446  df-reap 8848  df-ap 8855  df-div 8946  df-inn 9237  df-2 9295  df-3 9296  df-4 9297  df-5 9298  df-6 9299  df-7 9300  df-8 9301  df-9 9302  df-n0 9496  df-z 9577  df-dec 9709  df-uz 9853  df-seqfrec 10809  df-exp 10900
This theorem is referenced by: (None)
  Copyright terms: Public domain W3C validator