Prime Numbers
Prime Numbers Prime Numbers
9.5 Large-integer multiplication 505 and similarly for the Yj. It is evident that the (total of) 2m X,Y polynomials can be stored in two arrays that are (r, m)-transpositions of x, y arrays respectively. Next we multiply x(t)y(t) by performing the cyclic convolution Z =(X0,X1,...,Xm−1, 0,...,0) × (Y0,Y1,...,Ym−1, 0,...,0) , where each operand signal here has been zero-padded to total length 2m. The key point here is that Z canbeevaluatedbyasymbolic DFT, using what we know to be a primitive 2m-throotofunity,namelyz r/m . What this means is that the usual FFT butterfly operations now involve mere shuttling around of polynomials, because multiplications by powers of the primitive root just translate coefficient polynomials. In other words the polynomial arithmetic now proceeds along the lines of Theorem 9.2.12, in that multiplication by a power of the relevant root is equivalent to a kind of shift operation. At a key juncture of the usual DFT-based convolution method, namely the dyadic (elementwise) multiply step, the dyadic operations can be seen to be themselves length-r negacyclic convolutions. This is evident on the observation that each of the polynomials Xj,Yj hasdegree(r − 1) in the variable z = t m , and so z r = t D = −1. To complete the Z convolution, a final, inverse DFT, with root z −r/m , is to be used. The result of this zero-padded convolution is seen to be a product in the ring S: x(t)y(t) = 2m−2 j=0 Zj(t m )t j , (9.37) from which we extract the negacyclic elements of x ×− y as the coefficients of thepowersoft. Algorithm 9.5.25 (Nussbaumer convolution, cyclic and negacyclic). Assume length-(D =2 k ) signals x, y whose elements belong to a ring R, which ring also admits of cancellation-by-2. This algorithm returns either the cyclic (x×y) or negacyclic (x×− y) convolution. Inside the negacyclic function neg is a “small” negacyclic routine smallneg, for example a grammar-school or Karatsuba version, which is called below a certain length threshold. 1. [Initialize] r =2 ⌈k/2⌉ ; m = D/r; // Now m divides r. blen =16; // Tune this small-negacyclic breakover length to taste. 2. [Cyclic convolution function cyc, recursive] cyc(x, y) { By calling half-length cyclic and negacyclic convolutions, return the desired cyclic, via identity (9.36); } 3. [Negacyclic convolution function neg, recursive] neg(x, y) { if(len(x) ≤ blen) return smallneg(x, y);
506 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC 4. [Transposition step] Create a total of 2m arrays Xj,Yj each of length r; Zero-pad the X, Y collections so each collection has 2m polynomials; Using root g = z r/m , perform (symbolically) two length-2m DFTs to get the transforms ˆ X, ˆ Y ; 5. [Recursive dyadic operation] for(0 ≤ h
- 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 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 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
- Page 558 and 559: 550 REFERENCES [Bernstein 2004b] D.
- Page 560 and 561: 552 REFERENCES [Buchmann et al. 199
- Page 562 and 563: 554 REFERENCES [Crandall 1997b] R.
9.5 Large-integer multiplication 505<br />
and similarly for the Yj. It is evident that the (total of) 2m X,Y polynomials<br />
can be stored in two arrays that are (r, m)-transpositions of x, y arrays<br />
respectively. Next we multiply x(t)y(t) by performing the cyclic convolution<br />
Z =(X0,X1,...,Xm−1, 0,...,0) × (Y0,Y1,...,Ym−1, 0,...,0) ,<br />
where each operand signal here has been zero-padded to total length 2m. The<br />
key point here is that Z canbeevaluatedbyasymbolic DFT, using what we<br />
know to be a primitive 2m-throotofunity,namelyz r/m . What this means is<br />
that the usual FFT butterfly operations now involve mere shuttling around<br />
of polynomials, because multiplications by powers of the primitive root just<br />
translate coefficient polynomials. In other words the polynomial arithmetic<br />
now proceeds along the lines of Theorem 9.2.12, in that multiplication by a<br />
power of the relevant root is equivalent to a kind of shift operation.<br />
At a key juncture of the usual DFT-based convolution method, namely the<br />
dyadic (elementwise) multiply step, the dyadic operations can be seen to be<br />
themselves length-r negacyclic convolutions. This is evident on the observation<br />
that each of the polynomials Xj,Yj hasdegree(r − 1) in the variable z = t m ,<br />
and so z r = t D = −1. To complete the Z convolution, a final, inverse DFT,<br />
with root z −r/m , is to be used. The result of this zero-padded convolution is<br />
seen to be a product in the ring S:<br />
x(t)y(t) =<br />
2m−2 <br />
j=0<br />
Zj(t m )t j , (9.37)<br />
from which we extract the negacyclic elements of x ×− y as the coefficients of<br />
thepowersoft.<br />
Algorithm 9.5.25 (Nussbaumer convolution, cyclic and negacyclic).<br />
Assume length-(D =2 k ) signals x, y whose elements belong to a ring R, which<br />
ring also admits of cancellation-by-2. This algorithm returns either the cyclic<br />
(x×y) or negacyclic (x×− y) convolution. Inside the negacyclic function neg is a<br />
“small” negacyclic routine smallneg, for example a grammar-school or Karatsuba<br />
version, which is called below a certain length threshold.<br />
1. [Initialize]<br />
r =2 ⌈k/2⌉ ;<br />
m = D/r; // Now m divides r.<br />
blen =16; // Tune this small-negacyclic breakover length to taste.<br />
2. [Cyclic convolution function cyc, recursive]<br />
cyc(x, y) {<br />
By calling half-length cyclic and negacyclic convolutions, return the<br />
desired cyclic, via identity (9.36);<br />
}<br />
3. [Negacyclic convolution function neg, recursive]<br />
neg(x, y) {<br />
if(len(x) ≤ blen) return smallneg(x, y);