Prime Numbers
Prime Numbers Prime Numbers
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
- Page 448 and 449: 8.8 Research problems 439 the Leveq
- Page 450 and 451: 8.8 Research problems 441 for every
- Page 452 and 453: Chapter 9 FAST ALGORITHMS FOR LARGE
- Page 454 and 455: 9.1 Tour of “grammar-school” me
- Page 456 and 457: 9.2 Enhancements to modular arithme
- Page 458 and 459: 9.2 Enhancements to modular arithme
- Page 460 and 461: 9.2 Enhancements to modular arithme
- Page 462 and 463: 9.2 Enhancements to modular arithme
- Page 464 and 465: 9.2 Enhancements to modular arithme
- Page 466 and 467: 9.3 Exponentiation 457 Algorithm 9.
- Page 468 and 469: 9.3 Exponentiation 459 But there is
- Page 470 and 471: 9.3 Exponentiation 461 the benefit
- Page 472 and 473: 9.4 Enhancements for gcd and invers
- Page 474 and 475: 9.4 Enhancements for gcd and invers
- Page 476 and 477: 9.4 Enhancements for gcd and invers
- Page 478 and 479: 9.4 Enhancements for gcd and invers
- Page 480 and 481: 9.4 Enhancements for gcd and invers
- Page 482 and 483: 9.5 Large-integer multiplication 47
- Page 484 and 485: 9.5 Large-integer multiplication 47
- Page 486 and 487: 9.5 Large-integer multiplication 47
- Page 488 and 489: 9.5 Large-integer multiplication 47
- Page 490 and 491: 9.5 Large-integer multiplication 48
- Page 492 and 493: 9.5 Large-integer multiplication 48
- Page 494 and 495: 9.5 Large-integer multiplication 48
- Page 496 and 497: 9.5 Large-integer multiplication 48
- Page 500 and 501: 9.5 Large-integer multiplication 49
- Page 502 and 503: 9.5 Large-integer multiplication 49
- Page 504 and 505: 9.5 Large-integer multiplication 49
- Page 506 and 507: 9.5 Large-integer multiplication 49
- Page 508 and 509: 9.5 Large-integer multiplication 49
- Page 510 and 511: 9.5 Large-integer multiplication 50
- Page 512 and 513: 9.5 Large-integer multiplication 50
- Page 514 and 515: 9.5 Large-integer multiplication 50
- Page 516 and 517: 9.5 Large-integer multiplication 50
- Page 518 and 519: 9.6 Polynomial arithmetic 509 can i
- Page 520 and 521: 9.6 Polynomial arithmetic 511 Incid
- Page 522 and 523: 9.6 Polynomial arithmetic 513 where
- Page 524 and 525: 9.6 Polynomial arithmetic 515 such
- Page 526 and 527: 9.6 Polynomial arithmetic 517 Note
- Page 528 and 529: 9.7 Exercises 519 (3) Write out com
- Page 530 and 531: 9.7 Exercises 521 where “do” si
- Page 532 and 533: 9.7 Exercises 523 9.23. How general
- Page 534 and 535: 9.7 Exercises 525 two (and thus, me
- Page 536 and 537: 9.7 Exercises 527 0 2 +3 2 +0 2 is
- Page 538 and 539: 9.7 Exercises 529 9.49. In the FFT
- Page 540 and 541: 9.7 Exercises 531 adjustment step.
- Page 542 and 543: 9.7 Exercises 533 9.69. Implement A
- Page 544 and 545: 9.8 Research problems 535 less than
- Page 546 and 547: 9.8 Research problems 537 1.66), na
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