Toom-Cook: Sai Krishna Yedugani
Toom-Cook: Sai Krishna Yedugani
Contents
1 Abstract 2
2 Introduction 2
2.1 Where did the method come from ? . . . . . . . . . . . . . . . 2
2.2 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Multiplication Algorithms . . . . . . . . . . . . . . . . . . . . 3
2.4 Divide And Conquer . . . . . . . . . . . . . . . . . . . . . . . 3
3 History 4
5 Aplications 9
6 Conclusion 9
7 References 9
1
1 Abstract
In the present scientific computation like cryptography and many ap-
plications multiplication of two polynomials is very big concern. There are
only few algorithms that advance efficiency through this large integer mul-
tiplication. Toom cook-3, Toom-cook-4 way and Karatsuba area the well
known techniques that help in improving the efficiency in cryptosystems. In
this paper we work on the classical Toom-k way of dealing with the multi-
plication of large integers.
2 Introduction
Dealing with complex multiplications with our mind is completely out
of bound. We use calculators or some computer applications to do calcula-
tions. With these applications we can work on upto 8 digits and the result
we get is about 15 digits, and is accurate. Whereas, for the digits more
than this rounding off is done. There comes the issue when one needs to
work on large integers i.e more than 8 digits and getting the perfect result.
For these complex computations scientist have devised some special routines,
and this led to the invention of some algorithms. Few of these popular al-
gorithms are Toom-Cook and Karatsuba Algorithm and Schonhage-Strassen
algorithm(SSA).
The Toom-Cook algorithm follows the divide and conquer method for
multiplying large integers. Just like Karatsuba it splits the given integer
into n limbs of some fixed size. The division is then applied recursively with
Toom-3 algorithm. This goes on until we are able to apply another algorithm
on it for the last stage of recursion, or until the desired multiplier is reached.
The method works on the principles of polynomial multiplication. The
input numbers are divided into limbs of a given size, and each in the form
of polynomial, and the limb size is used as radix. Instead of multiplying the
obtained polynomials directly, they are evaluated at a set of points, and the
values multiplied together at those points. Based on the products obtained
at those points the product polynomial is obtained. The final result is then
obtained by substituting the radix.
2
based on the Karatsuba method by splitting each number to be multiplied
into multiple parts. Toom -3 way reduces number of multiplications greatly
depending on the number of splits done.
3
Karatsuba and Toom-Cook. In multi-Processor machines that have shared
memory systems, the sub-problems are executed on those processors thereby
increasing the performance of the divide and conquer algorithm.
3 History
Toom Cook algorithm is developed by Andrei Toom in 1963 and is
later improved and published by Stephen Cook in his Phd thesis. Toom
Cook Algorithm is also referred as Toom 3 which is the collective name for
all Toom Cook based algorithms. Toom Cook is the faster generalisation of
the Karatsuba method. Unllike Karatsuba it deals with 3 parts rather than
2 parts which makes it even more complex.
B = b2 = 108
Then we will seperate x and y into base B digits x,y.: These 2 equations are
multiplied to form w(t)=x(t)*y(t).
W (t) = w4 ∗ t4 + w3 ∗ t3 + w2 ∗ t2 + w1 ∗ t + w0
The final w(t) is calculated through the value of t, although the final step is
going to be the addition.
X(t) and Y(t) are calculated and multiplied by choosing some set of
points, forming w(t).
4
Let the following points be (0,1,2,-1,inf)
t=0 x0 * y0,
t=1 (x2+x1+x0) * (y2+y1+y0)
t=-1 (x2-x1+x0) * (y2-y1+y0)
O(N 1.465 )
O(N 1.585 )
4.1 Algorithm
1.
Input : T wointegersAandBaregivenwhere0 < A, B, < X n
2.
3.
HereA = x0 + x1t + x2t2 , B = y0 + y1t + y2t2 heret = X k
4. t=(0,1,2,-1,inf)
5
8.
t = 2(4 ∗ x2 + 2 ∗ x1 + x0) ∗ (4 ∗ y 2 + 2 ∗ y1 + y0)
C(t) = c4 ∗ t4 + c3 ∗ t3 + c2 ∗ t2 + c1t1 + c0
4.2 Complexity
Complexity is very essential to measure how long an algorithm is taking to
run.. Complexity of a problem is defined using big O notation . These are
further derivate into best case average and the worst cases. This helps to
choose the best algorithm that suits our problem. The classical addition and
multiplication method which e learned in our schools takes O(n2) for the
multiplication, which is of no use when dealing with the large integers. The
main task is to run our algorithm as fast as possible for efficient results.
Toom 3 splits the operand into n/2 parts
For ex: These 2 equations are multiplied to form w(t)=x(t)*y(t)
W (t) = w4 ∗ t4 + w3 ∗ t3 + w2 ∗ t2 + w1 ∗ t + w0
The running time for the above equation takes T(n)=9T(n/3), T(c)=1
Where 9 is the total number of multiplications, this is of no use
The implemented algorithm takes 5 multiplication for 3 splits. Z0 = x0
y0 Z1 = (x0 + x1 + x2) (x0 + y1 + y2) Z2 = (x0 + 2 x1 + 4 x2) (y0 + 2
y1 + 4 y2) Z3 = (x0 x1 + x2) (y0 y1 + y2) Z4 =(x0 2 x1 + 4 x2) (y0 2
y1 + 4 y2)
Therefor we see that the for k-way split requires 2( k) - 1 multiplications.
Toom-3 running time is significally
O(N 1.465 )
O(N 1.585 )
6
4.3 Implementation Of Toom-3 way Method
Toom-Cook is still one of the best techniques for multiplying big inte-
gers. Toom Cook-3 way is an improved method by a factor of 9/5 compared
to Karatsuba methods where the number of multiplications have been re-
duced to 5 from 9. Toom Cook covers various cases under Toom Cook k
where k equals to 3.
The implementation is shown in below example
Lets consider 2 numbers for the operation 831275469 by 897512436.
We can apply Toom-3 way on these numbers. Both the numbers are split
into 3 limbs each of length 3 digits written into polynomials
.
then we substitute the values of x for set of equations
Lets the set of points to be substituted be -2,-1,0,1,2
Now lets start with 0.
p(0)q(0) = r(0).
Therefore,
e = 204484.
Now,
p(1)q(1) = r(1).
7
p(-1)q(-1) = r(-1).
.
a-b+c-d+e= 841525 ——equation 2
Now,
p(2)q(2) = r(2).
16a-8b+4c-2d+e=1027116 ——-equation 4
The equations we got by those points are
e = 204484
a+ b+ c+ d+e= 2905875
a-b+ c- d+e= 841525
16a+8b+4c+2d+e = 21923464
16a-8b+4c-2d+e= 1027116
By solving the above equation we get
a=382828
c=-1286387
b=1397304
d=-365129
e=204484
The Fianl product is obtained by adding the numbers by shifting
382828
—-1397304
——–1286387
————365129
—————-204484
——————————————-
38296772326152333484 —— This is the final product obtained.
8
5 Aplications
There are various areas where this algorithm application is done, which
involves multiplication of large integers.
6 Conclusion
The Speed with which the operations are done not only depends on the
type and the size of the numbers but also on the type of the multiplication
algorithm. In this paper we analyzed how the operations have been done on
the polynomials by performing Toom -3 way algorithm. Toom -3 way reduced
the number of multiplication from 9 to 5, thereby reducing the complexity
of the problem in solving it less time. In classical method it takes around
On2 multiplications whereas through toom-cook the running time would be
On1.465 .
7 References
1.Bodrato, M., Zanoni, A.: Integer and Polynomial Multiplication: Towards
Optimal Toom-Cook Matrices. Proceedings of the ISSAC 2007 Conference.
ACM press, New York (2007)