Prime Numbers
Prime Numbers Prime Numbers
9.5 Large-integer multiplication 499 rings and fields. The primary observation is that over a ring or field, the DFT defining relations (9.20) and (9.21) need no modification whatever, as long as we understand the requisite operations to occur (legally) in the algebraic domain at hand. In particular, a number-theoretical DFT of length D supports cyclic convolution of length D, via the celebrated convolution Theorem 9.5.11, whenever both D −1 and g, a primitive D-th root of unity, exist in the algebraic domain. With these constraints in mind, number-theoretical transforms have attained a solid niche, in regard to fast algorithms in the field of digital signal processing. Not just raw convolution, but other interesting applications of such transforms can be found in the literature. A typical example is the use of number-theoretical transforms for classical algebraic operations [Yagle 1995], while yet more applications are summarized in [Madisetti and Williams 1997]. Our first example will be the case that the relevant domain is Fp. For a prime p and some divisor d|p − 1 let the field be Fp and consider the relevant transform to be Xk = (p−1)/d−1 j=0 xjh −jk mod p, (9.33) where h is an element of multiplicative order (p − 1)/d in Fp. Note that the mod operation can in principle be taken either after individual summands, or for the whole sum, or in some combination of these, so that for convenience we simply append the symbols “mod p” to indicate that a transform element Xk is to be reduced to lie in the interval [0,p−1]. Now the inverse transform is (p−1)/d−1 xj = −d Xkh jk mod p, (9.34) k=0 whose prefactor is just ((p − 1)/d) −1 mod p ≡−d. These transforms can be used to provide increased precision for convolutions. The idea is to establish each convolution element (mod pr) for some convenient set of primes {pr}, whence the exact convolution can be reconstructed using the Chinese remainder theorem. Algorithm 9.5.20 (Integer convolution on a CRT prime set). Given two signals x, y each of length N =2 m having integer elements bounded by 0 ≤ xj,yj NM2 ; for(1 ≤ r ≤ q) { Find a primitive root gr of pr; hr = gar r mod pr; // hr is an N-th root of 1. } 2. [Loop over primes]
500 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC for(1 ≤ r ≤ q) { h = hr; p = pr; d = ar; // Preparing for DFTs. X (r) = DFT(x); // Via relation (9.33). Y (r) = DFT(y); 3. [Dyadic product] Z (r) = X (r) ∗ Y (r) ; 4. [Inverse transforms] z (r) = DWT −1 (Z (r) ); // Via relation (9.34). } 5. [Reconstruct elements] From the now known relations zj ≡ z (r) j (mod pr) find each (unambiguous) element zj in [0,NM2 ) via CRT reconstruction, using such as Algorithm 2.1.7 or 9.5.26; return z; What this algorithm does is allow us to invoke length-2 m FFTs for the DFT and its inverse, except that only integer arithmetic is to be used in the usual FFT butterflies (and of course the butterflies are continually reduced (mod pr) during the FFT calculations). This scheme has been used to good effect in [Montgomery 1992a] in various factorization implementations. Note that if the forward DFT (9.33) is performed with a decimation-in-frequency (DIF) algorithm, and the reverse DFT (9.34) with a DIT algorithm, there is no need to invoke the scramble function of Algorithm 9.5.5 in either of the FFT functions shown there. A second example of useful number-theoretical transforms has been called the discrete Galois transform (DGT) [Crandall 1996a], with relevant field F p 2 for p =2 q − 1 a Mersenne prime. The delightful fact about such fields is that the multiplicative group order is |F ∗ p 2| = p2 − 1=2 q+1 (2 q−1 − 1), so that in practice, one can find primitive roots of unity of orders N =2 k as long as k ≤ q + 1. We can thus define discrete transforms of such lengths, as Xk = N−1 j=0 xjh −jk mod p, (9.35) where now all arithmetic is presumed, due to the known structure of F p 2 for primes p ≡ 3 (mod 4), to involve complex (Gaussian) integers (mod p) with N =2 k , xj =Re(xj)+i Im(xj), h =Re(h)+i Im(h), the latter being an element of multiplicative order N in F p 2, with the transform element Xk itself being a Gaussian integer (mod p). Happily, there
- 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 498 and 499: 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 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
- Page 548 and 549: 9.8 Research problems 539 9.82. A c
- Page 550 and 551: 542 Appendix BOOK PSEUDOCODE Becaus
- Page 552 and 553: 544 Appendix BOOK PSEUDOCODE } ...;
- Page 554 and 555: 546 Appendix BOOK PSEUDOCODE Functi
- Page 556 and 557: 548 REFERENCES [Apostol 1986] T. Ap
500 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC<br />
for(1 ≤ r ≤ q) {<br />
h = hr; p = pr; d = ar; // Preparing for DFTs.<br />
X (r) = DFT(x); // Via relation (9.33).<br />
Y (r) = DFT(y);<br />
3. [Dyadic product]<br />
Z (r) = X (r) ∗ Y (r) ;<br />
4. [Inverse transforms]<br />
z (r) = DWT −1 (Z (r) ); // Via relation (9.34).<br />
}<br />
5. [Reconstruct elements]<br />
From the now known relations zj ≡ z (r)<br />
j (mod pr) find each (unambiguous)<br />
element zj in [0,NM2 ) via CRT reconstruction, using such as Algorithm<br />
2.1.7 or 9.5.26;<br />
return z;<br />
What this algorithm does is allow us to invoke length-2 m FFTs for the DFT<br />
and its inverse, except that only integer arithmetic is to be used in the usual<br />
FFT butterflies (and of course the butterflies are continually reduced (mod pr)<br />
during the FFT calculations). This scheme has been used to good effect in<br />
[Montgomery 1992a] in various factorization implementations. Note that if<br />
the forward DFT (9.33) is performed with a decimation-in-frequency (DIF)<br />
algorithm, and the reverse DFT (9.34) with a DIT algorithm, there is no<br />
need to invoke the scramble function of Algorithm 9.5.5 in either of the FFT<br />
functions shown there.<br />
A second example of useful number-theoretical transforms has been called<br />
the discrete Galois transform (DGT) [Crandall 1996a], with relevant field F p 2<br />
for p =2 q − 1 a Mersenne prime. The delightful fact about such fields is that<br />
the multiplicative group order is<br />
|F ∗ p 2| = p2 − 1=2 q+1 (2 q−1 − 1),<br />
so that in practice, one can find primitive roots of unity of orders N =2 k as<br />
long as k ≤ q + 1. We can thus define discrete transforms of such lengths, as<br />
Xk =<br />
N−1 <br />
j=0<br />
xjh −jk mod p, (9.35)<br />
where now all arithmetic is presumed, due to the known structure of F p 2 for<br />
primes p ≡ 3 (mod 4), to involve complex (Gaussian) integers (mod p) with<br />
N =2 k ,<br />
xj =Re(xj)+i Im(xj),<br />
h =Re(h)+i Im(h),<br />
the latter being an element of multiplicative order N in F p 2, with the<br />
transform element Xk itself being a Gaussian integer (mod p). Happily, there