10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

474 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC<br />

and we obtain xy, which is originally a size-W 2 multiply, for the price of only<br />

three size-W multiplies (and some final carry adjustments, to achieve base-W<br />

representation of the final result). This is in principle an advantage, because<br />

if grammar-school multiply is invoked throughout, a size-W 2 multiply should<br />

be four, not three times as expensive as a size-W one. It can be shown that if<br />

one applies the Karatsuba relation to t, u, v themselves, and so on recursively,<br />

the asymptotic complexity for a size-N multiply is<br />

<br />

ln 3/ ln<br />

O (ln N)<br />

2<br />

bit operations, a theoretical improvement over grammar-school methods.<br />

We say “theoretical improvement” because computer implementations will<br />

harbor so-called overhead, and the time to arrange memory and recombine<br />

subproducts and so on might rule out the Karatsuba method as a viable<br />

alternative. Still, it is often the case in practice that the Karatsuba approach<br />

does, in fact, outperform the grammar-school approach over a machine- and<br />

implementation-dependent range of operands.<br />

But a related method, the Toom–Cook method, reaches the theoretical<br />

boundary of O ln 1+ɛ N bit operations for the multiplicative part of size-N<br />

multiplication—that is, ignoring all the additions inherent in the method.<br />

However, there are several reasons why the method is not the final word<br />

in the art of large-integer multiply. First, for large N the number of<br />

additions is considerable. Second, the complexity estimate presupposes that<br />

multiplications by constants (such as 1/2, which is a binary shift, and so on)<br />

are inexpensive. Certainly multiplications by small constants are so, but the<br />

Toom–Cook coefficients grow radically as N increases. Still, the method is<br />

of theoretical interest and does have its practical applications, such as fast<br />

multiplication on machines whose fundamental word multiply is especially<br />

sluggish with respect to addition. The Toom–Cook method hinges on the idea<br />

that given two polynomials<br />

x(t) =x0 + x1t + ...+ xD−1t D−1 , (9.18)<br />

y(t) =y0 + y1t + ...+ yD−1t D−1 , (9.19)<br />

the polynomial product z(t) =x(t)y(t) is completely determined by its values<br />

at 2D −1 separate t values, for example by the sequence of evaluations (z(j)),<br />

j ∈ [1 − D, D − 1]:<br />

Algorithm 9.5.1 (Symbolic Toom–Cook multiplication). Given D, thisalgorithm<br />

generates the (symbolic)Toom–Cook scheme for multiplication of (Ddigit)-by-(D-digit)<br />

integers.<br />

1. [Initialize]<br />

Form two symbolic polynomials x(t),y(t) each of degree (D − 1), asin<br />

equation (9.18);<br />

2. [Evaluation]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!