Sunteți pe pagina 1din 4

An algorithm for polynomial operations1

By C. L. Hamblinf
POLYGEORGE is an interpretive program for the English Electric KDF9 computer, providing
facilities for calculations with polynomials in accordance with a new algorithm, which is econo-
mical, fast, and simple enough to be realized in hardware. The program and its algorithm are
described and some extensions are discussed.

Recent interest in the mechanization of operations in descending powers of b, and so on. The algorithm to

Downloaded from https://academic.oup.com/comjnl/article-abstract/10/2/168/336835 by guest on 10 November 2019


polynomial algebra has led to the production of pro- be described is for the operatorless representation of a
grams such as ALPAK, FORMAC, Formula ALGOL polynomial in this form. Let us, as a first example,
(with associated translator), GRAD Assistant and PM. consider a polynomial in a alone, with integer coeffi-
(See the survey in Comm. ACM, Vol. 9, No. 8, August cients; such as
1966; and Brown, Hyde and Tague, 1962-3, Williams,
1962, and Collins, 1966a.) These programs provide for 8a4 + 6a2 + 13a + 5.
the handling of polynomials in one or several variables If, for uniformity, we write a1 for a where it occurs
and for operations on them such as addition, sub- without another exponent, and write coefficients after
traction, multiplication, differentiation, substitution for
variables, and calculation of residues. The aim of these the powers of a instead of before, we get
programs has usually been simply to provide assistance a 4 .8 + a 2 . 6 + a 1 . 1 3 + 5 .
in the (laborious and error-prone) task of calculating
with algebraic expressions. More ambitious aims are There is now no difficulty in dropping operators: using
possible, however, since the economical mechanization a comma after each number to avoid having numbers
of certain systematic approaches to algebra, such as run together, we have
that provided by Tarski's decision method (Tarski, 1948;
Seidenberg, 1954; Collins, 19666), could open up an a4, 8, a2, 6, al, 13, 5.
entirely new field to the computer. The end of the polynomial is sensed by the occurrence
List-processing techniques have generally commended of a term which is a simple number. It follows that we
themselves in this field. They suffer from the inherent must always write such a constant term; if necessary,
disadvantage of relative slowness, mainly due to the that is, we must write a zero. The characteristic of a
continual manipulation of non-germane next-item complete polynomial is that the number of numbers in
addresses. On the other hand, to operate with detached it shall be one more than twice the number of letters:
coefficients—in effect, with matrices—is extremely ineffi- incomplete polynomials have a surplus of letters.
cient in the common case in which most of the elements This characteristic is, moreover, preserved if we
of a matrix are zero, and is suitable mainly for a theore- permit coefficients to be themselves polynomials. For
tically restricted range of problems in which numbers example, the polynomial
are rounded-off to fixed lengths. In the case of many
important applications the operations must be exact, a3(4b2 + 3) + 6a + 1
in the sense that no rounding-off of numbers occurs at becomes
all.
In the algorithm to be described, polynomials are a3, bl, 4, 3, al, 6, 1
represented as strings of symbols some of which are
letters and some numbers in a positional notation. where bl, 4, 3, represents the coefficient of a3. In
Discussion will at first be limited to the case in which general, we may define a polynomial in standard form
the numbers are integers. recursively as
(polynomial) = (number)
Internal representation of polynomials /(letter) (number) (polynomial)
Within the POLYGEORGE program, polynomials (polynomial)
are handled in a standard form, which is preserved by A formula in this form would become a late-operator
all operations. In the first place, assuming a particular Forward Polish formula (Hamblin, 1962) if each letter
ordering a, b, c, . . . of the variables that may occur in were preceded by three operators + x f. It is not
them, they are arranged as sums of terms in descending difficult to find algorithms for inserting operators in
powers of a, with coefficients as sums of terms in positions yielding other Polish or orthodox forms.
* The work described was carried out as part of a project supported by the Australian Research Grants Committee. The author
wishes to acknowledge the programming assistance of Mr. M. C. Newey.
t University of New South Wales, Kensington, N.S.W., Australia.
168
Polynomial operations
As polynomials are actually written in the present if found, check whether the number being calculated is
application there are the following further restrictions: a coefficient (rather than an addend); and, if so, cancel
the zero and the preceding number and letter from the
(1) the first polynomial on the right of the above output. To make possible the test for a numerical
definition—that is, the "coefficient polynomial"— coefficient it is necessary to count numbers and letters
must not be zero and must not contain the letter in the output in accordance with a subsidiary algorithm:
of which it is a coefficient, or any alphabetically this must allow for the fact that cancelling one term
earlier letter; may bring another number into coefficient position, but
(2) the second or "addend" polynomial must not does not raise any other question of difficulty.
contain any letter alphabetically earlier than the
letter in the term of which it is an addend, and

Downloaded from https://academic.oup.com/comjnl/article-abstract/10/2/168/336835 by guest on 10 November 2019


may contain this letter only to lower degree Multiplication
(the "degree" of any occurrence of any letter is,
of course, given by the number following it); It is convenient to think of polynomials as made up
and of simple terms, each consisting of (possibly) a product
of exponentiated letters and (in any case) just one
(3) any number which immediately follows a letter numerical coefficient: thus, for example, the polynomial
(i.e. any exponent) must be a positive integer.
a\3b3 + 8) + 3a26 + 9
Addition contains the four simple terms 3a4b3, 8a4, 3a2b and 9.
The representation of a polynomial under these rules In multiplying two polynomials we need, in one way
is unique, and is subject to a particularly simple and or another, to multiply every simple term of the first by
easily mechanizable addition algorithm.* First of all, every simple term of the second, and add up the results.
let us define precedence of polynomials as follows: There are, however, different ways in which the program
for doing this might be arranged.
(a) a polynomial commencing with a letter takes The simplest program seems to arise from breaking
precedence over one commencing with a number; down one multiplicand into its simple terms and multi-
(b) in the case of polynomials commencing with plying them successively into the other multiplicand,
different letters the one with alphabetically earlier accumulating the result using the addition algorithm
letter takes precedence; already described. The accumulated partial product
(c) in the case of polynomials commencing with the needs to be rewritten, however, with the possible excep-
same letter, one with higher value of following tion of some initial terms, each time something is added
number takes precedence over one with lower; to it; and this not only makes the method a slow one
and but involves relatively heavy demands on storage.
(d) in other cases, precedence is equal. The alternative is, at each stage, to collect together
all those products of simple terms which contribute to
Now in adding two polynomials they are first com- a given simple term in the answer. As the polynomials
pared for precedence. are arranged, this involves scanning the one forwards
(1) If one takes precedence a complete term is trans- as the other is scanned backwards. For example, in
ferred to output as the first complete term of the multiplying
sum. a\3b2 + 4) + ab + 9
(2) If precedence is equal and both commence with a
letter, the letter and following number must be by 9a4 + a\8b3 + 5b1) + 2a2b + 2b2 + 1
the same in both, and are transferred to output
as the next part of the sum; and the two coeffi- there are contributions to the simple term in a3b2
cient polynomials are now compared for prece- from the product of a3. 3b2 and 1, the product of a3.4
dence preparatory to being added, the operation and 2b2, the product of ab and 2a2b, and so on. If we
proceeding recursively. start by finding the simple term of highest precedence
in the answer, this may be written as first term of the
(3) Finally, if both are numbers, they are added and answer and remain unaltered by what follows; we then
the sum is transferred to output. The process proceed to the simple term of next highest precedence,
continues until both polynomials are exhausted; and so on.
the final operation will be the addition of the
final numbers of the two polynomials. This procedure will be helped if one of the two multi-
plicands is first written in a special reverse standard
The sum of two polynomials added in this way will form, so that both multiplicands may always be scanned
itself be a polynomial in standard form, with one quali- forwards. The form that recommends itself is less neat
fication: namely, that it may contain zero coefficients. than the standard form already described, and depends
To preserve strict standard form it is necessary, when on the sensing of letter-precedences and on a special
adding numbers under (3), to check for zero result and, symbol to indicate the end of the formula.
* Provisional patent
169
Polynomial operations
It may be derived as follows. If we first of all put in general, handled in a nesting-store during the running
zero powers of letters in the constant terms of any of the program.)
polynomials in which they are principal letters, we can Polynomials may be written into the program, or
write terms in ascending degrees instead of descending. read in by it, in a form which is an approximation to
Thus: ordinary notation. They are immediately converted to
the standard form described. They may be "stored"
4a3 + 3a + 2 by means of instructions "=A", "=B", etc. which, in
becomes 2a° + 3al + 4 effect, tag the polynomials with the names "A", "B",
etc. so that they may be recalled under these names as
written as aO,2, al, 3, a3, 4, # required. The operations provided are addition; sub-
' #" is the special end-symbol. traction; sign-change; multiplication; exact division
where

Downloaded from https://academic.oup.com/comjnl/article-abstract/10/2/168/336835 by guest on 10 November 2019


(with failure if not possible); a "residue" operation
Coefficients may be polynomials instead of mere which guarantees non-failure by multiplying the dividend
numbers, and arranged in the same form, an end of a by a suitable power of the leading coefficient of the
coefficient being sensed by the occurrence of an alpha- divisor; integral exponentiation; partial differentiation
betically earlier letter. Thus: with respect to any variable; substitution of poly-
nomials for one or more variables in a given polynomial;
4a3 + a(5b2 + 7) + 2 discrimination on whether a given polynomial is a pure
becomes aO, 2, al, bO, 7, 62, 5, al, 4, # . number, whether it is determinably zero, non-zero,
positive, etc.; and various more trivial operations such
One further elaboration is desirable. Since the first as determination of degree in a given variable or selection
term of any polynomial is always a zero-degree one, the of a coefficient. The operation of substitution may be
zero is in fact redundant except as a place marker; and used to substitute pure numbers (integers) for all the
since we frequently want, in scanning through, to know variables in a polynomial and hence to calculate a "value"
the degree of polynomial, the zero may be replaced by a of it. As a subsidiary operation, provision is made for
copy of the largest of the exponents of the relevant calculating a value more directly, using the normal
letter. The above example now becomes floating arithmetic of the machine, given values of the
ai, 2, al, b2, 1, b2, 5, a.3, 4, #. variables (not necessarily integral) in standard Usercode
floating representations.
Here the underlining, which is put in only for the sake
of illustration, indicates numbers which have been
inserted in place of zero exponents and which give the Polynomial multiplication and division times
degrees of the polynomials concerned. In the following table multiplication times are for
In multiplying, one multiplicand is first rewritten in two polynomials in the same variables and of the same
this form by a preliminary program. The main multi- total degree, all terms being present and having small
plication program is a complicated one in detail, and positive integer coefficients c, 1 < c < 7. (The size of
need not be further described here, but follows closely coefficients does not affect times so long as accumulated
the principles outlined. products do not exceed word-length.) Division times
are for re-division of the calculated product by one of
Machine representation of polynomials the factors. The column giving the number of terms in
the factor-polynomials permits more meaningful com-
In the current use of this polynomial algorithm in a parison of figures for different numbers of variables.
program for the English Electric KDF9 machine a
variable and its exponent each occupy 24 bits of a
NUMBER OF TOTAL NUMBER OF MULTIPLICATION RE-DIVISION
48-bit machine word, and each number other than an VARIABLES DEGREE TERMS TIME TIME
exponent is represented in binary in one or more machine (EACH (EACH (EACH (SEC ± 1 SEC) (SEC ± 1 SEC)
words, with the least-significant first. To facilitate FACTOR) FACTOR) FACTOR)
numerical multiplication only 39 bits of each 48-bit
word store significant bits of the number; and the last 1 20 21 2 6
word of each number also has a sign-bit and a "last 40 41 5 40
word" marker bit. 60 61 10 125
80 81 17 —
Operations available in POLYGEORGE 5 21 2 2
The POLYGEORGE program permits the writing of 10 66 15 26
programs for polynomial manipulations in an inter- 15 136 59 131
pretive language which in some ways resembles the
Usercode of the KDF9 machine, and are carried out as 2 21 3 2
if polynomials were being handled in a push-down 3 56 18 21
store. (In fact, it is polynomial addresses that are, in 4 126 94 118
170
Polynomial operations
Possible extensions the general case of rational coefficients by letting all
The limitation of coefficients to integer values is coefficients be quotients of integers, preserving unique-
unimportant for many purposes, since the case of ness, if desired, by cancelling common factors from
arbitrary rational values may often be dealt with by numerator and denominator. A generalization of a
multiplying a polynomial through by the lowest common similar kind would deal with the "field" of quotients of
denominator of its coefficients, leaving roots and other polynomials, rather than with the "ring" of polynomials.
relevant properties unchanged. That this would some- The operation of finding the common factor of two
times lead to rather large integer coefficients is not a polynomials is, however, a relatively time-consuming
reflection on the method itself so much as on the class one, and in many cases it would be wasteful to attempt
of problem that is being dealt with, since it is only in to secure uniqueness of representation by this means.
simple contexts that truncation or rounding-off can be Certain generalizations of another kind—namely, to

Downloaded from https://academic.oup.com/comjnl/article-abstract/10/2/168/336835 by guest on 10 November 2019


guaranteed not to lead to intolerable error. the use of complex numbers and vectors—are relatively
Certain generalizations which at first seem to offer straightforward and may be introduced as applications
useful facilities turn out, on examination, to involve demand.
theoretical problems. One of these, for example, is the The wealth of applications awaiting these develop-
introduction of non-integral powers; this immediately ments justifies some attention to methods of securing
destroys the uniqueness of any system of representation, the highest possible speed of operation. The provision
since it is not an elementary matter to decide whether, of some special hardware should not be ruled out. In
for example, a given polynomial has a square root. this connection the algorithm described might prove
It would be a relatively simple matter to accommodate especially suitable as a basis.

References
BROWN, W. S., HYDE, J. P., and TAGUE, B. A. (1962-3). "The ALPAK system for non-numerical algebra on a digital computer",
B.S.T.J., Vol. 42, pp. 2081-2119; Vol. 43, pp. 785-804; Vol. 53, pp. 1547-1562.
COLLINS, G. E. (1966C). "PM, A System for Polynomial Manipulation", Comm. ACM, Vol. 9, No. 8.
COLLINS, G. E. (19666). "Subresultants and Reduced Polynomial Remainder Sequences", IBM Research Paper No. RC-1595.
HAMBLIN, C. L. (1962). "Translation to and from Polish notation", The Computer Journal, Vol. 5, pp. 210-13.
SEIDENBERG, A. (1954). "A New Decision Method for Elementary Algebra", Ann. Math., Vol. 60, pp. 365-74.
TARSKI, A. (1948). A Decision Method for Elementary Algebra and Geometry, Rand Corporation; 2nd edn., Berkeley and Los
Angeles, 1951.
WILLIAMS, LELAND H. (1962). "Algebra of Polynomials in Several Variables for a Digital Computer", /. ACM, Vol. 9, pp. 29-40.

Automata Theory, edited by E. R. Caianiello, 1966; 342 pages. long as you are prepared to ignore a finite subset of the
(New York: Academic Press Inc., 112s.) domain), are here extended to logics by Michael Arbib.
This volume consists of some thirty papers presented at a Problems of formal linguistics, also inseparable from auto-
NATO Summer School in 1964 at Ravello. Although it is mata theory, are the subject of authoritative contributions by
hardly, as its title might suggest, that systematic survey of a Schiitzenberger and others from the Institut Blaise Pascal; it
broad field which we are still lacking, it undoubtedly contains is perhaps a pity these were left untranslated. In a long and
much that is worth the attention of the computer scientist, interesting paper, Bohm and Gross introduce their descrip-
whatever his line of country. Buchi and Rabin, for instance, tion language CUCH, being an amalgam of CUrry com-
provide clear expositions of finite automata theory, mainly binatory logic and CHurch lambda-calculus. CUCH is a
from the abstract algebraic standpoint. McCulloch and powerful language of wide potential application, as is also
Harth speculate on the latest brain models based on "a more the system of Generalized Normal Algorithms described by
realistic neuron". A few admirable pages by Martin Davis Caracciolo di Forino.
clarify in simple terms what recursive function theory is Something has gone very wrong with pages 119 to 121 in
about and how it concerns automata. At the other end of Caracciolo's otherwise lucid paper; at this price should the
the road, some of the more bizarre propositions of that theory, reader have to work quite so hard to restore the original text ?
such as that any program may be indefinitely accelerated (as M. BELL

171

S-ar putea să vă placă și