Prime Numbers

Prime Numbers Prime Numbers

thales.doa.fmph.uniba.sk
from thales.doa.fmph.uniba.sk More from this publisher
10.12.2012 Views

9.5 Large-integer multiplication 489 and the acyclic convolution of x, y is a signal u = x ×A y having 2D elements given by un = xiyj, i+j=n for n ∈{0,...,2D − 2}, together with the assignment u2D−1 = 0. Finally, the half-cyclic convolution of x, y is the length-D signal x ×H y consisting of the first D elements of the acyclic convolution u. These fundamental convolutions are closely related, as is seen in the following result. In such statements we interpret the sum of two signals c = a + b in elementwise fashion; that is, cn = an + bn for relevant indices n. Likewise, a scalar-signal product qa, withq a number and a a signal, is the signal (qan). We shall require the notion of the splitting of signals (of even length) into halves, so we denote by L(a),H(a), respectively, the lower-indexed and higher-indexed halves of a. That is, from c = a ∪ b the natural, left-right, concatenation of two signals of equal length, we shall have L(c) = a and H(c) =b. Theorem 9.5.10. Let signals x, y have the same length D. Then the various convolutions are related as follows (it is assumed that in the relevant domain to which signal elements belong, 2 −1 exists): Furthermore, x ×H y = 1 2 ((x × y)+(x ×− y)). x ×A y =(x ×H y) ∪ 1 2 ((x × y) − (x ×− y)). Finally, if the length D is even and xj,yj =0for j ≥ D/2, then L(x) ×A L(y) =x × y = x ×− y. These interrelations allow us to use certain algorithms more universally. For example, a pair of algorithms for cyclic and negacyclic can be used to extract both the half-cyclic or the acyclic, and so on. In the final statement of the theorem, we have introduced the notion of “zero padding,” which in practice amounts to appending D zeros to signals already of length D, sothat the signals’ acyclic convolution is identical to the cyclic (or the negacyclic) convolution of the two padded sequences. The connection between convolution and the DFT of the previous section is evident in the following celebrated theorem, wherein we refer to the dyadic operator ∗, under which a signal z = x ∗ y has elements zn = xnyn: Theorem 9.5.11 (Convolution theorem). Let signals x, y have the same length D. Then the cyclic convolution of x, y satisfies x × y = DFT −1 (DFT(x) ∗ DFT(y)),

490 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC whichistosay (x × y)n = 1 D−1 D k=0 XkYk g kn . Armed with this mighty theorem we can effect the cyclic convolution of two signals with three transforms (one of them being the inverse transform), or the cyclic convolution of a signal with itself with two transforms. As the known complexity of the DFT is O(D ln D) operations in the field, the dyadic product implicit in Theorem 9.5.11, being O(D), is asymptotically negligible. A direct and elegant application of FFTs for large-integer arithmetic is to perform the DFTs of Theorem 9.5.11 in order to effect multiplication via acyclic convolution. This essential idea—pioneered by Strassen in the 1960s and later optimized in [Schönhage and Strassen 1971] (see Section 9.5.6)—runs asfollows.Ifanintegerx is represented as a length-D signal consisting of the (base-B) digits, and the same for y, then the integer product xy is an acyclic convolution of length 2D. Though Theorem 9.5.11 pertains to the cyclic, not the acyclic, we nevertheless have Theorem 9.5.10, which allows us to use zeropadded signals and then perform the cyclic. This idea leads, in the case of complex field transforms, to the following scheme, which is normally applied using floating-point arithmetic, with DFT’s done via fast Fourier transform (FFT) techniques: Algorithm 9.5.12 (Basic FFT multiplication). Given two nonnegative integers x, y, each having at most D digits in some base B (Definition 9.1.1), this algorithm returns the base-B representation of the product xy. (The FFTs normally employed herein would be of the floating-point variety, so one must beware of roundoff error.) 1. [Initialize] Zero-pad both of x, y until each has length 2D, so that the cyclic convolution of the padded sequences will contain the acyclic convolution of the unpadded ones; 2. [Apply transforms] X = DFT(x); // Perform transforms via efficient FFT algorithm. Y = DFT(y); 3. [Dyadic product] Z = X ∗ Y ; 4. [Inverse transform] z = DFT −1 (Z); 5. [Round digits] z = round(z); // Elementwise rounding to nearest integer. 6. [Adjust carry in base B] carry =0; for(0 ≤ n

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

whichistosay<br />

(x × y)n = 1<br />

D−1 <br />

D<br />

k=0<br />

XkYk g kn .<br />

Armed with this mighty theorem we can effect the cyclic convolution of<br />

two signals with three transforms (one of them being the inverse transform),<br />

or the cyclic convolution of a signal with itself with two transforms. As the<br />

known complexity of the DFT is O(D ln D) operations in the field, the dyadic<br />

product implicit in Theorem 9.5.11, being O(D), is asymptotically negligible.<br />

A direct and elegant application of FFTs for large-integer arithmetic is<br />

to perform the DFTs of Theorem 9.5.11 in order to effect multiplication via<br />

acyclic convolution. This essential idea—pioneered by Strassen in the 1960s<br />

and later optimized in [Schönhage and Strassen 1971] (see Section 9.5.6)—runs<br />

asfollows.Ifanintegerx is represented as a length-D signal consisting of the<br />

(base-B) digits, and the same for y, then the integer product xy is an acyclic<br />

convolution of length 2D. Though Theorem 9.5.11 pertains to the cyclic, not<br />

the acyclic, we nevertheless have Theorem 9.5.10, which allows us to use zeropadded<br />

signals and then perform the cyclic. This idea leads, in the case of<br />

complex field transforms, to the following scheme, which is normally applied<br />

using floating-point arithmetic, with DFT’s done via fast Fourier transform<br />

(FFT) techniques:<br />

Algorithm 9.5.12 (Basic FFT multiplication). Given two nonnegative integers<br />

x, y, each having at most D digits in some base B (Definition 9.1.1), this<br />

algorithm returns the base-B representation of the product xy. (The FFTs normally<br />

employed herein would be of the floating-point variety, so one must beware<br />

of roundoff error.)<br />

1. [Initialize]<br />

Zero-pad both of x, y until each has length 2D, so that the cyclic<br />

convolution of the padded sequences will contain the acyclic convolution<br />

of the unpadded ones;<br />

2. [Apply transforms]<br />

X = DFT(x); // Perform transforms via efficient FFT algorithm.<br />

Y = DFT(y);<br />

3. [Dyadic product]<br />

Z = X ∗ Y ;<br />

4. [Inverse transform]<br />

z = DFT −1 (Z);<br />

5. [Round digits]<br />

z = round(z); // Elementwise rounding to nearest integer.<br />

6. [Adjust carry in base B]<br />

carry =0;<br />

for(0 ≤ n

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

Saved successfully!

Ooh no, something went wrong!