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

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.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!