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 495 (2) Perform length-D weighted convolution, with weight generator A a primitive (2D)-th root of unity, do carry adjust as necessary. (3) Create length-(D/2) “fold-over” signals, as x ′ = L(x) +iH(x) and similarly for a y ′ , employ a weighted convolution with generator A a primitive (4D)-th root of unity, do carry adjust. Method (1) could, of course, involve Algorithm 9.5.12, with perhaps a fast Fermat-mod of Section 9.2.3; but one could instead use a pureinteger Nussbaumer convolution discussed later. Method (2) is the negacyclic approach, in which the weighted convolution can be seen to be multiplication (mod Fn); that is, the mod operation is “free” (see Exercises). Method (3) is the right-angle convolution approach, which also gives the mod operation for free (see Exercises). Note that neither method (2) nor method (3) involves zero-padding, and that method (3) actually halves the signal lengths (at the expense of complex arithmetic). We focus on method (3), to state the following algorithm, which, as with Algorithm 9.5.12, is often implemented in a floatingpoint paradigm: Algorithm 9.5.17 (DWT multiplication modulo Fermat numbers). For a given Fermat number Fn =22n +1, and positive integers x, y ≡ −1(modFn), this algorithm returns (xy) modFn. We choose B,D such that Fn = BD +1, with the inputs x, y interpreted as length-D signals of base-B digits. We assume that there exists a primitive 4D-th root of unity, A, in the field. 1. [Initialize] E = D/2; // Halve the signal length and “fold-over” the signals. x = L(x)+iH(x); // Length-E signals. y = L(y)+iH(y); a = 1,A,A 2 ,...,A E−1 ; // Weight signal. 2. [Apply transforms] X = DWT(x, a); // Via an efficient length-E FFT algorithm. Y = DWT(y, a); 3. [Dyadic product] Z = X ∗ Y ; 4. [Inverse transform] z = DWT −1 (Z, a); 5. [Unfold signal] z =Re(z) ∪ Im(z); // Now z will have length D. 6. [Round digits] z = round(z); // Elementwise rounding to nearest integer. 7. [Adjust carry in base B] carry =0; for(0 ≤ n

496 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC } carry = ⌊v/B⌋; 8. [Final modular adjustment] Include possible carry > 0 as a high digit of z; z = z mod Fn; // Via another ’carry’ loop or via special-form mod methods. return z; Note that in the steps [Adjust carry in base B] and [Final modular adjustment] the logic depends on the digits of the reconstructed integer z being positive. We say this because there are efficient variants using balanceddigit representation, in which variants care must be taken to interpret negative digits (and negative carry) correctly. This algorithm was used in the discoveries of new factors of F13,F15,F16, and F18 [Brent et al. 2000] (see the Fermat factor tabulation in Section 1.3.2), and also to establish the composite character of F22, F24, and of various cofactors for other Fn [Crandall et al. 1995], [Crandall et al. 1999]. In more recent times, [Woltman 2000] has implemented the algorithm to forge highly efficient factoring software for Fermat numbers (see remarks following Algorithm 7.4.4). Another DWT variant has been used in the discovery of eight Mersenne primes 2 1398269 −1, 2 2976221 −1, 2 3021377 −1, 2 6972593 −1, 2 13466917 −1, 2 20996011 − 1, 2 24036583 −1, 2 25964951 −1 (see Table 1.2), the last of which being the largest known explicit prime as of the present writing. For these discoveries, a network of volunteer users ran extensive Lucas–Lehmer tests that involve vast numbers of squarings modulo p =2 q − 1. The algorithm variant in question has been called the irrational-base discrete weighted transform (IBDWT) [Crandall and Fagin 1994], [Crandall 1996a] for the reason that a special digit representation reminiscent of irrational-base expansion is used, which representation amounts to a discrete rendition of an attempt to expand in an irrational base. Let p =2 q − 1 and observe first that if an integer x be represented in base B =2 as q−1 x = xj2 j , j=0 equivalently, x is the length-q signal (xj); and similarly for an integer y, then the cyclic convolution x×y has, without carry, the digits of (xy) modp. Thus, in principle, the standard FFT multiply could be effected in this way, modulo Mersenne primes, without zero-padding. However, there are two problems with this approach. First, the arithmetic is merely bitwise, not exploiting typical machine advantages of word arithmetic. Second, one would have to invoke a length-q FFT. This can certainly be done (see Exercises), but power-of-two lengths are usually more efficient, definitely more prevalent. It turns out that both of the obstacles to a not-zero-padded Mersenne multiply-mod can be overcome, if only we could somehow represent integers x in the irrational base B =2 q/D ,with1

9.5 Large-integer multiplication 495<br />

(2) Perform length-D weighted convolution, with weight generator A a<br />

primitive (2D)-th root of unity, do carry adjust as necessary.<br />

(3) Create length-(D/2) “fold-over” signals, as x ′ = L(x) +iH(x) and<br />

similarly for a y ′ , employ a weighted convolution with generator A a<br />

primitive (4D)-th root of unity, do carry adjust.<br />

Method (1) could, of course, involve Algorithm 9.5.12, with perhaps a<br />

fast Fermat-mod of Section 9.2.3; but one could instead use a pureinteger<br />

Nussbaumer convolution discussed later. Method (2) is the negacyclic<br />

approach, in which the weighted convolution can be seen to be multiplication<br />

(mod Fn); that is, the mod operation is “free” (see Exercises). Method (3)<br />

is the right-angle convolution approach, which also gives the mod operation<br />

for free (see Exercises). Note that neither method (2) nor method (3) involves<br />

zero-padding, and that method (3) actually halves the signal lengths (at the<br />

expense of complex arithmetic). We focus on method (3), to state the following<br />

algorithm, which, as with Algorithm 9.5.12, is often implemented in a floatingpoint<br />

paradigm:<br />

Algorithm 9.5.17 (DWT multiplication modulo Fermat numbers). For a<br />

given Fermat number Fn =22n +1, and positive integers x, y ≡ −1(modFn),<br />

this algorithm returns (xy) modFn. We choose B,D such that Fn = BD +1,<br />

with the inputs x, y interpreted as length-D signals of base-B digits. We assume<br />

that there exists a primitive 4D-th root of unity, A, in the field.<br />

1. [Initialize]<br />

E = D/2; // Halve the signal length and “fold-over” the signals.<br />

x = L(x)+iH(x); // Length-E signals.<br />

y = L(y)+iH(y);<br />

a = 1,A,A 2 ,...,A E−1 ; // Weight signal.<br />

2. [Apply transforms]<br />

X = DWT(x, a); // Via an efficient length-E FFT algorithm.<br />

Y = DWT(y, a);<br />

3. [Dyadic product]<br />

Z = X ∗ Y ;<br />

4. [Inverse transform]<br />

z = DWT −1 (Z, a);<br />

5. [Unfold signal]<br />

z =Re(z) ∪ Im(z); // Now z will have length D.<br />

6. [Round digits]<br />

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

7. [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!