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

The Karatsuba trick

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

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

and

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

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

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

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

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


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


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

(1)
If n = 1 then compute the element f g of $ \mathbb {R}$.
(2)
Define f = F1 xn/2 + F0 and g = G1 xn/2 + G0 where F1, F0, G1, G0 have degree < n/2.
(3)
Compute F0 G0, F1 G1, (F0 + F1)(G0 + G1) recursively
(4)
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. (47)


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

Hence we can apply the previous formula (for estimating T(n)) 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}$ (48)

We obtain

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

that is

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

Observe that:

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

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
2003-06-06