Prime Numbers
Prime Numbers Prime Numbers
9.6 Polynomial arithmetic 511 Incidentally, if polynomial multiplication in rings is done via fast integer convolution (recall that acyclic convolution is sufficient, and so zero-padded cyclic will do), then one may obtain a different expression for the complexity bound. For the Nussbaumer Algorithm 9.5.25 one requires O(M(ln m)D ln D) bit operations, where M is the usual integer-multiplication complexity. It is interesting to compare these various estimates for polynomial multiplication (see Exercise 9.70). 9.6.2 Fast polynomial inversion and remaindering Let x(t) = D−1 j=0 xjt j be a polynomial. If x0 = 0,thereisaformalinversion 1/x(t) =1/x0 − (x1/x 2 0)t +(x 2 1/x 3 0 − x2/x 2 0)t 2 + ··· that admits of rapid evaluation, by way of a scheme we have already invoked for reciprocation, the celebrated Newton method. We describe the scheme in the case that x0 = 1, from which case generalizations are easily inferred. In what follows, the notation z(t) modt k is a polynomial remainder (which we cover later), but in this setting it is simple truncation: The result of the mod operation is a polynomial consisting of the terms of polynomial z(t) through order t k−1 inclusive. Let us define, then, a truncated reciprocal, R[x, N] =x(t) −1 mod t N+1 as the series of 1/x(t) through degree t N ,inclusive. Algorithm 9.6.2 (Fast polynomial inversion). Let x(t) be a polynomial with first coefficient x0 = 1. This algorithm returns the truncated reciprocal R[x, N] through a desired degree N. 1. [Initialize] g(t) =1; // Degree-zero polynomial. n =1; // Working degree precision. 2. [Newton loop] while(n N+1) n = N +1; h(t) =x(t) modt n ; // Simple truncation. h(t) =h(t)g(t) modt n ; g(t) =g(t)(2 − h(t)) mod t n ; // Newton iteration. } return g(t); One point that should be stressed right off is that in principle, an operation f(t)g(t) modt n is simple truncation of a product (the operands usually themselves being approximately of degree n). This means that within
512 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC multiplication loops, one need not handle terms of degree higher than indicated. In convolution-theory language, we are therefore doing “half-cyclic” convolutions, so when transform methods are used, there is also gain to be realized because of the truncation. As is typical of Newton methods, the dynamical precision degree n essentially doubles on each pass of the Newton loop. Let us give an example of the workings of the algorithm. Take x(t) =1+t + t 2 +4t 3 and call the algorithm to output R[x, 8]. Then the values of g(t) attheendof each pass of the Newton loop come out as 1 − t, 1 − t − 3t 3 , 1 − t − 3t 3 +7t 4 − 4t 5 +9t 6 − 33t 7 , 1 − t − 3t 3 +7t 4 − 4t 5 +9t 6 − 33t 7 +40t 8 , and indeed, this last output of g(t) multiplied by the original x(t) is 1+43t 9 − 92t 10 + 160t 11 , showing that the last output g(t) is correct through O(t 8 ). Polynomial remaindering (polynomial mod operation) can be performed in much the same way as some of our mod algorithms for integers used a “reciprocal.” However, it is not always possible to divide one polynomial by another and get a unique and legitimate remainder: This can depend on the ring of coefficients for the polynomials. However, if the divisor polynomial has its high coefficient invertible in the ring, then there is no problem with divide and remainder; see the discussion in Section 2.2.1. For simplicity, we shall restrict to the case that the divisor polynomial is monic, that is, the high coefficient is 1, since generalizing is straightforward. Assume that x(t),y(t) are polynomials and that y(t) is monic. Then there are unique polynomials q(t),r(t) such that x(t) =q(t)y(t)+r(t), and r =0ordeg(r) < deg(x). We shall write r(t) =x(t) mody(t), and view q(t) asthequotientandr(t) as the remainder. Incidentally, for some polynomial operations one demands that coefficients lie in a field, for example in the evaluation of polynomial gcd’s, but many polynomial operations do not require field coefficients. Before exhibiting a fast polynomial remaindering algorithm, we establish some nomenclature: Definition 9.6.3 (Polynomial operations). Let x(t) = D−1 j=0 xjt j be a polynomial. We define the reversal of x by degree d as the polynomial rev(x, d) = d j=0 xd−jt j ,
- 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 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 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.
- 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
512 Chapter 9 FAST ALGORITHMS FOR LARGE-INTEGER ARITHMETIC<br />
multiplication loops, one need not handle terms of degree higher than<br />
indicated. In convolution-theory language, we are therefore doing “half-cyclic”<br />
convolutions, so when transform methods are used, there is also gain to be<br />
realized because of the truncation.<br />
As is typical of Newton methods, the dynamical precision degree n<br />
essentially doubles on each pass of the Newton loop. Let us give an example<br />
of the workings of the algorithm. Take<br />
x(t) =1+t + t 2 +4t 3<br />
and call the algorithm to output R[x, 8]. Then the values of g(t) attheendof<br />
each pass of the Newton loop come out as<br />
1 − t,<br />
1 − t − 3t 3 ,<br />
1 − t − 3t 3 +7t 4 − 4t 5 +9t 6 − 33t 7 ,<br />
1 − t − 3t 3 +7t 4 − 4t 5 +9t 6 − 33t 7 +40t 8 ,<br />
and indeed, this last output of g(t) multiplied by the original x(t) is<br />
1+43t 9 − 92t 10 + 160t 11 , showing that the last output g(t) is correct through<br />
O(t 8 ).<br />
Polynomial remaindering (polynomial mod operation) can be performed<br />
in much the same way as some of our mod algorithms for integers used a<br />
“reciprocal.” However, it is not always possible to divide one polynomial by<br />
another and get a unique and legitimate remainder: This can depend on the<br />
ring of coefficients for the polynomials. However, if the divisor polynomial has<br />
its high coefficient invertible in the ring, then there is no problem with divide<br />
and remainder; see the discussion in Section 2.2.1. For simplicity, we shall<br />
restrict to the case that the divisor polynomial is monic, that is, the high<br />
coefficient is 1, since generalizing is straightforward. Assume that x(t),y(t)<br />
are polynomials and that y(t) is monic. Then there are unique polynomials<br />
q(t),r(t) such that<br />
x(t) =q(t)y(t)+r(t),<br />
and r =0ordeg(r) < deg(x). We shall write<br />
r(t) =x(t) mody(t),<br />
and view q(t) asthequotientandr(t) as the remainder. Incidentally, for some<br />
polynomial operations one demands that coefficients lie in a field, for example<br />
in the evaluation of polynomial gcd’s, but many polynomial operations do not<br />
require field coefficients. Before exhibiting a fast polynomial remaindering<br />
algorithm, we establish some nomenclature:<br />
Definition 9.6.3 (Polynomial operations). Let x(t) = D−1<br />
j=0 xjt j be a<br />
polynomial. We define the reversal of x by degree d as the polynomial<br />
rev(x, d) =<br />
d<br />
j=0<br />
xd−jt j ,