19.07.2014 Views

Contents - Student subdomain for University of Bath

Contents - Student subdomain for University of Bath

Contents - Student subdomain for University of Bath

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.1. WHAT ARE POLYNOMIALS? 33<br />

MULTIPLY-POLY by O(m 2 n) ((m(m + 3)/2 − 1)n to be exact). 4 There are multiplication<br />

algorithms which are more efficient than this one: roughly speaking,<br />

we ought to sort the terms <strong>of</strong> the product so that they appear in decreasing<br />

order, and the use <strong>of</strong> ADD-POLY corresponds to an insertion sort. We know that<br />

the number <strong>of</strong> coefficient multiplications in such a ‘classical’ method is mn, so<br />

this emphasises that the extra cost is a function <strong>of</strong> the exponent operations<br />

(essentially, comparison) and list manipulation. Of course, the use <strong>of</strong> a better<br />

sorting method (such as “quicksort” or “mergesort”) <strong>of</strong>fers a more efficient multiplication<br />

algorithm, say O(mn log m) [Joh74]. But most systems have tended<br />

to use an algorithm similar to the procedure given above: [MP08]shows the<br />

substantial improvements that can be made using a better algorithm.<br />

Maple’s representation, and methods, are rather different. The terms in a<br />

Maple sum might appear to be unordered, so we might ask what prevents 2x 2<br />

from appearing at one point, and −2x 2 at another. Maple uses a hash-based<br />

representation [CGGG83], so that insertion in the hash table takes amortised 5<br />

constant time, and the multiplication is O(mn).<br />

In a dense representation, we can use radically different, and more efficient,<br />

methods based on Karatsuba’s method [KO63, and section B.3], which takes<br />

time O ( max(m, n) min(m, n) 0.57...) , or the Fast Fourier Trans<strong>for</strong>m [AHU74,<br />

chapter 8], where the running time is O(n log n).<br />

There is a technical, but occasionally important, difficulty with this procedure,<br />

reported in [ABD88]. We explain this difficulty in order to illustrate<br />

the problems which can arise in the translation <strong>of</strong> mathematical <strong>for</strong>mulae into<br />

computer algebra systems. In MULTIPLY-POLY, we add a 0 b 1 to a 1 b. The order<br />

in which these two objects are calculated is actually important. Why, since this<br />

can affect neither the results nor the time taken? The order can dramatically<br />

affect the maximum memory space used during the calculations. If a and b are<br />

dense <strong>of</strong> degree n, the order which first calculates a 0 b 1 should store all these<br />

intermediate results be<strong>for</strong>e the recursion finishes. There<strong>for</strong>e the memory space<br />

needed is O(n 2 ) words, <strong>for</strong> there are n results <strong>of</strong> length between 1 and n. The<br />

other order, a 1 b calculated be<strong>for</strong>e a 0 b 1 , is clearly more efficient, <strong>for</strong> the space<br />

used at any moment does not exceed O(n). This is not a purely theoretical remark:<br />

[ABD88] were able to factorise x 1155 − 1 with REDUCE in 2 megabytes<br />

<strong>of</strong> memory 6 , but they could not remultiply the factors without running out <strong>of</strong><br />

memory, which appears absurd.<br />

Division is fairly straight-<strong>for</strong>ward: to divide f by g, we keep subtracting<br />

appropriate (meaning c i = (lc(f)/lc(g))x degf−degg ) multiples <strong>of</strong> g from f until<br />

the degree <strong>of</strong> f is less than the degree <strong>of</strong> g. If the remaining term (the remainder)<br />

is zero, then g divides f, and the quotient can be computed by summing the<br />

4 It is worth noting the asymmetry in the computing time <strong>of</strong> what is fundamentally a<br />

symmetric operation. Hence we ought to choose A as the one with the fewer terms. If this<br />

involves counting the number <strong>of</strong> terms, many implementors ‘cheat’ and take A as the one <strong>of</strong><br />

lower degree, hoping <strong>for</strong> a similar effect.<br />

5 Occasionally the hash table may need to grow, so an individual insertion may be expensive,<br />

but the average time is constant.<br />

6 A large machine <strong>for</strong> the time!

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

Saved successfully!

Ooh no, something went wrong!