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

Theorem karatsuba 12624
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 9538. (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 9278 . . . . 5  |-  A  e.  CC
3 10nn0 9491 . . . . . . 7  |- ; 1 0  e.  NN0
43nn0cni 9278 . . . . . 6  |- ; 1 0  e.  CC
5 karatsuba.m . . . . . 6  |-  M  e. 
NN0
6 expcl 10666 . . . . . 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 8048 . . . 4  |-  ( A  x.  (; 1 0 ^ M
) )  e.  CC
9 karatsuba.b . . . . 5  |-  B  e. 
NN0
109nn0cni 9278 . . . 4  |-  B  e.  CC
11 karatsuba.c . . . . . 6  |-  C  e. 
NN0
1211nn0cni 9278 . . . . 5  |-  C  e.  CC
1312, 7mulcli 8048 . . . 4  |-  ( C  x.  (; 1 0 ^ M
) )  e.  CC
14 karatsuba.d . . . . 5  |-  D  e. 
NN0
1514nn0cni 9278 . . . 4  |-  D  e.  CC
168, 10, 13, 15muladdi 8452 . . 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 8048 . . . 4  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  ( C  x.  (; 1 0 ^ M
) ) )  e.  CC
1815, 10mulcli 8048 . . . 4  |-  ( D  x.  B )  e.  CC
198, 15mulcli 8048 . . . . 5  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  D
)  e.  CC
2013, 10mulcli 8048 . . . . 5  |-  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
)  e.  CC
2119, 20addcli 8047 . . . 4  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M ) )  x.  B ) )  e.  CC
2217, 18, 21add32i 8207 . . 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 8048 . . . . . 6  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  e.  CC
24 karatsuba.s . . . . . . 7  |-  S  e. 
NN0
2524nn0cni 9278 . . . . . 6  |-  S  e.  CC
2623, 25, 7adddiri 8054 . . . . 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 8190 . . . . . . . . 9  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  =  ( ( A  x.  C )  x.  (; 1 0 ^ M
) )
28 karatsuba.r . . . . . . . . . 10  |-  ( A  x.  C )  =  R
2928oveq1i 5935 . . . . . . . . 9  |-  ( ( A  x.  C )  x.  (; 1 0 ^ M
) )  =  ( R  x.  (; 1 0 ^ M
) )
3027, 29eqtri 2217 . . . . . . . 8  |-  ( ( A  x.  (; 1 0 ^ M
) )  x.  C
)  =  ( R  x.  (; 1 0 ^ M
) )
3130oveq1i 5935 . . . . . . 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 2217 . . . . . 6  |-  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  =  W
3433oveq1i 5935 . . . . 5  |-  ( ( ( ( A  x.  (; 1 0 ^ M ) )  x.  C )  +  S )  x.  (; 1 0 ^ M
) )  =  ( W  x.  (; 1 0 ^ M
) )
358, 12, 7mulassi 8052 . . . . . 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 8048 . . . . . . . . . . . 12  |-  ( A  x.  C )  e.  CC
3736, 18, 25add32i 8207 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  S )  +  ( D  x.  B ) )
3828oveq1i 5935 . . . . . . . . . . . 12  |-  ( ( A  x.  C )  +  S )  =  ( R  +  S
)
39 karatsuba.t . . . . . . . . . . . . 13  |-  ( B  x.  D )  =  T
4010, 15, 39mulcomli 8050 . . . . . . . . . . . 12  |-  ( D  x.  B )  =  T
4138, 40oveq12i 5937 . . . . . . . . . . 11  |-  ( ( ( A  x.  C
)  +  S )  +  ( D  x.  B ) )  =  ( ( R  +  S )  +  T
)
4237, 41eqtri 2217 . . . . . . . . . 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 8452 . . . . . . . . . 10  |-  ( ( A  +  B )  x.  ( C  +  D ) )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4542, 43, 443eqtr2i 2223 . . . . . . . . 9  |-  ( ( ( A  x.  C
)  +  ( D  x.  B ) )  +  S )  =  ( ( ( A  x.  C )  +  ( D  x.  B
) )  +  ( ( A  x.  D
)  +  ( C  x.  B ) ) )
4636, 18addcli 8047 . . . . . . . . . 10  |-  ( ( A  x.  C )  +  ( D  x.  B ) )  e.  CC
472, 15mulcli 8048 . . . . . . . . . . 11  |-  ( A  x.  D )  e.  CC
4812, 10mulcli 8048 . . . . . . . . . . 11  |-  ( C  x.  B )  e.  CC
4947, 48addcli 8047 . . . . . . . . . 10  |-  ( ( A  x.  D )  +  ( C  x.  B ) )  e.  CC
5046, 25, 49addcani 8225 . . . . . . . . 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 5935 . . . . . . 7  |-  ( S  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  D )  +  ( C  x.  B ) )  x.  (; 1 0 ^ M
) )
5347, 48, 7adddiri 8054 . . . . . . 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 8190 . . . . . . . 8  |-  ( ( A  x.  D )  x.  (; 1 0 ^ M
) )  =  ( ( A  x.  (; 1 0 ^ M ) )  x.  D )
5512, 10, 7mul32i 8190 . . . . . . . 8  |-  ( ( C  x.  B )  x.  (; 1 0 ^ M
) )  =  ( ( C  x.  (; 1 0 ^ M ) )  x.  B )
5654, 55oveq12i 5937 . . . . . . 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 2221 . . . . . 6  |-  ( S  x.  (; 1 0 ^ M
) )  =  ( ( ( A  x.  (; 1 0 ^ M ) )  x.  D )  +  ( ( C  x.  (; 1 0 ^ M
) )  x.  B
) )
5835, 57oveq12i 5937 . . . . 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 2226 . . . 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 5937 . . 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 2221 . 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 5937 . 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 2225 1  |-  ( X  x.  Y )  =  Z
Colors of variables: wff set class
Syntax hints:    = wceq 1364    e. wcel 2167  (class class class)co 5925   CCcc 7894   0cc0 7896   1c1 7897    + caddc 7899    x. cmul 7901   NN0cn0 9266  ;cdc 9474   ^cexp 10647
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 710  ax-5 1461  ax-7 1462  ax-gen 1463  ax-ie1 1507  ax-ie2 1508  ax-8 1518  ax-10 1519  ax-11 1520  ax-i12 1521  ax-bndl 1523  ax-4 1524  ax-17 1540  ax-i9 1544  ax-ial 1548  ax-i5r 1549  ax-13 2169  ax-14 2170  ax-ext 2178  ax-coll 4149  ax-sep 4152  ax-nul 4160  ax-pow 4208  ax-pr 4243  ax-un 4469  ax-setind 4574  ax-iinf 4625  ax-cnex 7987  ax-resscn 7988  ax-1cn 7989  ax-1re 7990  ax-icn 7991  ax-addcl 7992  ax-addrcl 7993  ax-mulcl 7994  ax-mulrcl 7995  ax-addcom 7996  ax-mulcom 7997  ax-addass 7998  ax-mulass 7999  ax-distr 8000  ax-i2m1 8001  ax-0lt1 8002  ax-1rid 8003  ax-0id 8004  ax-rnegex 8005  ax-precex 8006  ax-cnre 8007  ax-pre-ltirr 8008  ax-pre-ltwlin 8009  ax-pre-lttrn 8010  ax-pre-apti 8011  ax-pre-ltadd 8012  ax-pre-mulgt0 8013  ax-pre-mulext 8014
This theorem depends on definitions:  df-bi 117  df-dc 836  df-3or 981  df-3an 982  df-tru 1367  df-fal 1370  df-nf 1475  df-sb 1777  df-eu 2048  df-mo 2049  df-clab 2183  df-cleq 2189  df-clel 2192  df-nfc 2328  df-ne 2368  df-nel 2463  df-ral 2480  df-rex 2481  df-reu 2482  df-rmo 2483  df-rab 2484  df-v 2765  df-sbc 2990  df-csb 3085  df-dif 3159  df-un 3161  df-in 3163  df-ss 3170  df-nul 3452  df-if 3563  df-pw 3608  df-sn 3629  df-pr 3630  df-op 3632  df-uni 3841  df-int 3876  df-iun 3919  df-br 4035  df-opab 4096  df-mpt 4097  df-tr 4133  df-id 4329  df-po 4332  df-iso 4333  df-iord 4402  df-on 4404  df-ilim 4405  df-suc 4407  df-iom 4628  df-xp 4670  df-rel 4671  df-cnv 4672  df-co 4673  df-dm 4674  df-rn 4675  df-res 4676  df-ima 4677  df-iota 5220  df-fun 5261  df-fn 5262  df-f 5263  df-f1 5264  df-fo 5265  df-f1o 5266  df-fv 5267  df-riota 5880  df-ov 5928  df-oprab 5929  df-mpo 5930  df-1st 6207  df-2nd 6208  df-recs 6372  df-frec 6458  df-pnf 8080  df-mnf 8081  df-xr 8082  df-ltxr 8083  df-le 8084  df-sub 8216  df-neg 8217  df-reap 8619  df-ap 8626  df-div 8717  df-inn 9008  df-2 9066  df-3 9067  df-4 9068  df-5 9069  df-6 9070  df-7 9071  df-8 9072  df-9 9073  df-n0 9267  df-z 9344  df-dec 9475  df-uz 9619  df-seqfrec 10557  df-exp 10648
This theorem is referenced by: (None)
  Copyright terms: Public domain W3C validator