Prime Numbers
Prime Numbers Prime Numbers
9.6 Polynomial arithmetic 517 Note that in the calculations of w(t),z(t) the intent is that the product must be expanded, to render w, z as signals of coefficients. The operations to expand these products must be taken into account in any proper complexity estimate for this evaluation algorithm (see Exercise 9.75). Along such lines, note that an especially efficient way to implement Algorithm 9.6.7 is to preconstruct a polynomial remainder tree; that is, to exploit the fact that the polynomials in Step [Assemble half-polynomials] have been calculated from their own respective halves, and so on. To lend support to the reader who desires to try this general evaluation Algorithm 9.6.7, let us give an example of its workings. Consider the task of calculating the number 64! not by the usual, sequential multiplication of successive integers but by evaluating the polynomial x(t) =t(1 + t)(2 + t)(3 + t)(4 + t)(5 + t)(6 + t)(7 + t) at the 8 points = 5040t + 13068t 2 + 13132t 3 + 6769t 4 + 1960t 5 322t 6 +28t 7 + t 8 T =(1, 9, 17, 25, 33, 41, 49, 57) and then taking the product of the eight evaluations to get the factorial. Since the algorithm is fully recursive, tracing is nontrivial. However, if we assign b = 2, say, in Step [Set breakover] and print out the half-polynomials w, z and polynomial-mod results a, b right after these entities are established, then our output should look as follows. On the first pass of eval we obtain w(t) = 3825 − 4628t + 854t 2 − 52t 3 , z(t) = 3778929 − 350100t + 11990t 2 − 180t 3 + t 4 , a(t) =x(t) modw(t) = −14821569000 + 17447650500t − 2735641440t 2 + 109600260t 3 , b(t) =x(t) modz(t) = −791762564494440 + 63916714435140t − 1735304951520t 2 + 16010208900t 3 , and for each of a, b there will be further recursive passes of eval. If we keep tracing in this way, the subsequent passes reveal w(t) =9− 10t + t 2 , z(t) = 425 − 42t + t 2 , and, continuing in recursive order, a(t) =−64819440 + 64859760t, b(t) =−808538598000 + 49305458160t, w(t) = 1353 − 74t + t 2 , z(t) = 2793 − 106t + t 2 , a(t) =−46869100573680 + 1514239317360t, b(t) =−685006261415280 + 15148583316720t.
518 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC There are no more recursive levels (for our example choice b = 2) because the eval function will break over to some classical method such as an easy instance of Horner’s rule and evaluate these last a(t),b(t) values directly, each one at four t = ti values. The final returned entity from eval turns out to be the sequence (x(t0),...,x(t7)) = (40320, 518918400, 29654190720, 424097856000, 3100796899200, 15214711438080, 57274321104000, 178462987637760). Indeed, the product of these eight values is exactly 64!, as expected. One should note that in such a “product” operation—where evaluations are eventually all multiplied together—the last phase of the eval function need not return a union of two signals, but may instead return the product eval(a, u) ∗ eval(b, v). If that is the designer’s choice, then the step [Check breakover threshold ...] must also return the product of the indicated x(ti). Incidentally, polynomial coefficients do not necessarily grow large as the above example seems to suggest. For one thing, when working on such as a factoring problem, one will typically be reducing all coefficients modulo some N, at every level. And there is a clean way to handle the problem of evaluating x(t) ofdegreeDat some smaller number of points, say at t0,...,tn−1 with n
- 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 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 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.
- Page 564 and 565: 556 REFERENCES [Dudon 1987] J. Dudo
- Page 566 and 567: 558 REFERENCES [Goldwasser and Kili
- Page 568 and 569: 560 REFERENCES [Joe 1999] S. Joe. A
- Page 570 and 571: 562 REFERENCES [Lenstra 1981] H. Le
- Page 572 and 573: 564 REFERENCES [Montgomery 1987] P.
- Page 574 and 575: 566 REFERENCES [Oesterlé 1985] J.
9.6 Polynomial arithmetic 517<br />
Note that in the calculations of w(t),z(t) the intent is that the product must<br />
be expanded, to render w, z as signals of coefficients. The operations to expand<br />
these products must be taken into account in any proper complexity estimate<br />
for this evaluation algorithm (see Exercise 9.75). Along such lines, note that<br />
an especially efficient way to implement Algorithm 9.6.7 is to preconstruct a<br />
polynomial remainder tree; that is, to exploit the fact that the polynomials<br />
in Step [Assemble half-polynomials] have been calculated from their own<br />
respective halves, and so on.<br />
To lend support to the reader who desires to try this general evaluation<br />
Algorithm 9.6.7, let us give an example of its workings. Consider the task<br />
of calculating the number 64! not by the usual, sequential multiplication of<br />
successive integers but by evaluating the polynomial<br />
x(t) =t(1 + t)(2 + t)(3 + t)(4 + t)(5 + t)(6 + t)(7 + t)<br />
at the 8 points<br />
= 5040t + 13068t 2 + 13132t 3 + 6769t 4 + 1960t 5 322t 6 +28t 7 + t 8<br />
T =(1, 9, 17, 25, 33, 41, 49, 57)<br />
and then taking the product of the eight evaluations to get the factorial.<br />
Since the algorithm is fully recursive, tracing is nontrivial. However, if we<br />
assign b = 2, say, in Step [Set breakover] and print out the half-polynomials<br />
w, z and polynomial-mod results a, b right after these entities are established,<br />
then our output should look as follows. On the first pass of eval we obtain<br />
w(t) = 3825 − 4628t + 854t 2 − 52t 3 ,<br />
z(t) = 3778929 − 350100t + 11990t 2 − 180t 3 + t 4 ,<br />
a(t) =x(t) modw(t)<br />
= −14821569000 + 17447650500t − 2735641440t 2 + 109600260t 3 ,<br />
b(t) =x(t) modz(t)<br />
= −791762564494440 + 63916714435140t − 1735304951520t 2<br />
+ 16010208900t 3 ,<br />
and for each of a, b there will be further recursive passes of eval. If we keep<br />
tracing in this way, the subsequent passes reveal<br />
w(t) =9− 10t + t 2 ,<br />
z(t) = 425 − 42t + t 2 ,<br />
and, continuing in recursive order,<br />
a(t) =−64819440 + 64859760t,<br />
b(t) =−808538598000 + 49305458160t,<br />
w(t) = 1353 − 74t + t 2 ,<br />
z(t) = 2793 − 106t + t 2 ,<br />
a(t) =−46869100573680 + 1514239317360t,<br />
b(t) =−685006261415280 + 15148583316720t.