next up previous
Next: Experimentation Up: Asymptotically fast algorithms Previous: Asymptotically fast algorithms

The Karatsuba trick

Let f, g mathend000# be two univariate polynomials in x mathend000# with degrees p mathend000# and q mathend000# respectively. Let $ \mathbb {R}$ mathend000# be their ring of coefficients. Define

f (x)  =   apxp + ... + a1x + a0 (39)

and

g(x)  =   bqxq + ... + b1x + b0. (40)

COMPUTING THE PRODUCT f (x)g(x) mathend000# by the straightforward method requires

So the complexity of this computation is $ \cal {O}$(pq) mathend000# (in term of operations in $ \mathbb {R}$ mathend000#).

Thus the complexity of the computation of the product of two univariate polynomials of degree at most n mathend000# is $ \cal {O}$(n2) mathend000# (in term of operations in $ \mathbb {R}$ mathend000#).

COMPUTING THE SUM f (x) + g(x) mathend000# is $ \cal {O}$(n) mathend000# (in term of operations in $ \mathbb {R}$ mathend000#) if f mathend000# and g mathend000# have of degree at most n mathend000#.


ADDING IS OFTEN CHEAPER THAN MULTIPLYING. So adding polynomials is cheaper than multiplying them. For many rings $ \mathbb {R}$ mathend000# addition is also cheaper than multiplication. So when computing f (x)g(x) mathend000# let's try to save on the number of multiplications in $ \mathbb {R}$ mathend000#.


THE KARATSUBA'S TRICK. Assume f mathend000# and g mathend000# have degree (strictly) less than n = 2k mathend000# (where k mathend000# is an integer). The Karatsuba's trick computes the product f (x)g(x) mathend000# as follows.

(1) mathend000#
If n = 1 mathend000# then compute the element f g mathend000# of $ \mathbb {R}$ mathend000#.
(2) mathend000#
Define f = F1 xn/2 + F0 mathend000# and g = G1 xn/2 + G0 mathend000# where F1, F0, G1, G0 mathend000# have degree < n/2 mathend000#.
(3) mathend000#
Compute F0 G0 mathend000#, F1 G1 mathend000#, (F0 + F1)(G0 + G1) mathend000# recursively
(4) mathend000#
Return

F1G1 xn + $\displaystyle \left(\vphantom{ (F_0 + F_1)(G_0 + G_1) - F_0 \, G_0 - F_1 \, G_1 }\right.$(F0 + F1)(G0 + G1) - F0 G0 - F1 G1$\displaystyle \left.\vphantom{ (F_0 + F_1)(G_0 + G_1) - F_0 \, G_0 - F_1 \, G_1 }\right)$xn/2 + F0 G0. (41)


ITS COMPLEXITY. Let us count how many operations in $ \mathbb {R}$ mathend000# we perform with the Karatsuba's trick.

Hence we can apply the previous formula (for estimating T(n) mathend000#) with

$\displaystyle \left\{\vphantom{ \begin{array}{rcl} a & = & 3 \\  T(1) & = & 1 \\  S(n) & = & 4 \, n \end{array} }\right.$$\displaystyle \begin{array}{rcl} a & = & 3 \\  T(1) & = & 1 \\  S(n) & = & 4 \, n \end{array}$ (42)

We obtain

T(n) $\displaystyle \in$ $\displaystyle \cal {O}$(4 n nlog2(3)-1). (43)

that is

T(n) $\displaystyle \in$ $\displaystyle \cal {O}$(nlog2(3)). (44)

Observe that:

log2(3) $\displaystyle \leq$ 1, 59. (45)

Figure 5: Complexity of the Karatsuba algorithm.
\begin{figure}\htmlimage[no_transparent]
\centering
\includegraphics[scale=.5]{kara.ps}\end{figure}



Subsections
next up previous
Next: Experimentation Up: Asymptotically fast algorithms Previous: Asymptotically fast algorithms
Marc Moreno Maza
2007-01-10