Skip to content Skip to navigation

Connexions

You are here: Home » Content » Horner's Method for Evaluating and Deflating Polynomials

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Recently Viewed

This feature requires Javascript to be enabled.

Horner's Method for Evaluating and Deflating Polynomials

Module by: C. Sidney Burrus

Summary: Horner's method is a standard minimum arithmetic method for evaluating and deflating polynomials. It can also efficiently evaluate various order derivatives of a polynomial, therefore is often used as part of Newton's method. This note tries to develop the various techniques called Horner's method, nested evaluation, and synthetic division in a common framework using a recursive structure and difference equations. There is a similarity to Goertzel's algorithm for the DFT, Z-transform inversion by division, and Pade's and Prony's methods. This approach also allows a straight forward explanation of "stability" or numerical errors of the algorithms. Matlab implementations are given. This note came from the work of the "Polynomial Club" at Rice: Burrus, Fox, Sitton, and Treitel.

Polynomials

Polynomials are one of the oldest classes of mathematical functions with an important history in mathematics, science, engineering, and other quantitative fields [1]. Part of the polynomial's appeal comes from the fact that it may be numerically evaluated using a finite number of multiplications and additions. In the processes of factoring, evaluating, and deflating polynomials, Horner's methods are central and are the focus of this note.

Any Nth degree polynomial can be written in coefficient form as:

fNaz=a0+a1z+a2z2+...+aNzN fN a z a0 a1 z a2 z2 ... aN zN (1)

can be written in a nested form as:

fNaz=a0+za1+za2+...+za N - 1 +z a N +... fN a z a0 z a1 z a2 ... z a N - 1 z a N ... (2)

or nested in a different order as:

fNaz=z...zzzaN+a N - 1 +a N - 2 +...+a0 fN a z z ... z z z aN a N - 1 a N - 2 ... a0 (3)

and in a factored form as:

fz= a N d=1Dz- z d Q d f z a N d 1 D z z d Q d (4)

where QdQd is the multiplicity of the dthdth zero, DD is the number of distinct zeros, and d=1DQd=N d 1 D Qd N .

The polynomial can be written in a first order remainder form as:

fNaz=qN-1bzz-z0+R fN a z qN-1 b z z z0 R (5)

where

qN-1bz=b0+b1z+b2z2+...+b N - 1 zN-1 qN-1 b z b0 b1 z b2 z2 ... b N - 1 zN1 (6)

is the quotient polynomial obtained when fNaz fN a z is divided by z-z0zz0 and the remainder is a constant easily seen to be the value

R=fNaz0 R fN az0 (7)

If z0z0 is a zero of fNz fN z , then R=0R0 and q N - 1 z q N - 1 z contains the same zeros as fNz fN z except for the one at z0z0 . A more general formulation of (5) is:

fNaz=q N - M bzdMcz+Rz fN az q N - M bz dM cz R z (8)

There are four polynomial problems that are often posed:

  1. Factor: Given the coefficients akak , find the roots or zeros zrzr . Matlab command: roots()
  2. Unfactor: Given the zeros zrzr , find the coefficients akak . Matlab command: poly()
  3. Evaluate: Given the coefficients or zeros and z0z0 , find the value of the polynomial at z=z0 z z0 , fz0 f z0 (or the value of the derivative of the polynomial at z=z0 z z0 , fz0 f z0 . Matlab command: polyval()
  4. Deflate: Given a polynomial and one of its roots, find the polynomial containing the other roots.

Horner's methods are important for evaluation and deflation, therefore, for factoring. For many high degree polynomial factoring schemes, it is important to use stable evaluation and deflation and to deflate in an order that maximizes the conditioning of the quotient. Unfactoring is simply the multiplying of the factors to obtain the polynomial but, because of round-off error, the order of multiplication is important. As an alternative, the FFT/DFT can be used to unfactor and evaluate. Of the four, only factoring is nonlinear and it is the most difficult. In many strategies, factoring uses the other three. For implementation of any of the four, the number of arithmetic operations required will determine the speed of execution and stability and conditioning will affect the error characteristics.

Evaluate the Polynomial and Its Derivatives

From the structure of the nested forms in (2) and (3), one can formulate a recursive relation which is also a linear first order difference equation:

x k+1 =zxk+a N-1-k , x0=an x k1 z xk a N-1-k , x0 an (9)

for k= 0,1,..., N-1 k 0,1,..., N-1 with the value of the polynomial at z given by fNaz=xn fN a z xn [3,4,5]. Here the xkxk are the values of the successively evaluated bracketed epressions in (2). Matlab code to evaluate fNaz0 fN a z0 with coefficients aa is given by:

Figure 1: Program 1. Forward Evaluation of Polynomial

   m = length(a);     % poly degree plus one: N+1
   f = a(1);          % initial condition
   for k = 2:m        % iterative Horner's algorithm
     f=z*f + a(k);    % recursive evaluation of f(z)
   end

Remember that Matlab stores polynomial coefficients in the reverse order of the notation used by many writers and the reverse of that shown in (1) and starts indexing with 1 rather than 0.

This formulation is very efficient if implemented with the "multiplicity-accumulate" single-cycle instruction of several DSP chips and some microprocessors.

The nested forms of (2) and (3), the remainder form of (5), and the recursive from of (9) are all versions of Horner's method [2,5,6] or synthetic division. There are also similarities to the Goertzel algoirthm to evaluate the DFT, the Padé or Prony method and inversion of z-transforms by division. Indeed, all of these methods convert an evaluation into a recursion and then into a difference equation which has considerable literature [7]. While in some cases it is possible to reduce the number of multiplications used by Horner in polynomial evaluation, it is generally a small gain and accompanied by an increase in the number of additions and the complexity of the algorithm. If preprocessing of the polynomial coefficients is not used, Horner gives a minimum arithmetic evaluation [3,5].

If we differentiate (5), we get:

fNaz=qN-1bz+ qN-1 bzz-z0 fN az qN-1 bz qN-1 bz z z0 (10)

which, if evaluated at z=z0zz0 , gives:

fN az0=qN-1bz0 fN az0 qN-1 bz0 (11)

which can be evaluated by a minor variation of (9). Thus Horner's method can evaluate an Nth degree polynomial with N multiplications and additions or evaluate it and its derivative with 2N multiplications and additions or avaluate it and its derivative with 2N multiplications and additions. Note = qN-1 az qN-1 az is not the derivative, but is the value of the derivative at z0z0 . The simple Matlab code for this is:

Figure 2: Program 2. Forward Evaluation of Polynomial and Its Derivative


m = length(a);          % N+1
f = a(1); fp = 0;       % initial conditions
for i = 2:m             % iterative Horner's algorithms
    fp = z * fp + f;    % recursive evaluation of f'(z)
    f = z * f + a(i);   % recursive evaluation of f(z)
end

This can be made much faster by using the filter() function in Matlab as:

Figure 3: Program 3. Forward Evaluation of Polynomial and Its Derivative by Filters

N = length(a) - 1;
b = filter(1,[1 -z], a);       % Horner by filter: f(z)
f = b(N+1);
c = filter(1,[1 -z], b(1:N));  % Horner by filter: f'(z)
fp = c(N);

From (11) and (6), we see that the value of the derivative of the Nth degree polynomial fNaz fN az is the value of the N-1thN1th degree polynomial qN-1bz qN-1 bz with coefficients bkbk as solutions to the difference equation

b k+1 =zbk+a N-1-k b k1 z bk a N-1-k (12)

which has the same form as (9) but saving the intermediate values of bkbk . This means that the solution to the difference equation (12) with the NN input values of akak gives N-1N1 output values of bkbk followed by the remainder R1R1 which is the value of fNaz fN az .

A similar argument shows that solving (12) with an input of bkbk will give N-2N2 output values of ckck followed by R2R2 which is the value of the derivative of fNaz fN az . Using the ckck as an input will give N-3N3 values of dkdk and R3R3 which is the second derivative. This can be continued NN times to evaluate the function and all of its N-1N1 derivatives (see Fig 1). These values of RkRk allow the original polynomial to be written as:

fNaz=R1+R2z-z0+R3z-z02+...+R N+1z-z0N fN a z R1 R2 zz0 R3 zz0 2 ... R N1 zz0 N (13)

which is a power series expansion [5] around z=z0 z z0 with the coefficients RkRk being defined in terms of derivatives evaluated at z=z0 z z0 .

The following program evaluates the function and its first and second derivatives in a very compact single loop solution of the basic first order difference equation without saving the coefficients bkbk or ckck .

Figure 4: Program 4. Forward Evaluation of Polynomial and Two Derivatives

m = length(a);              % poly degree + 1
f = 0; fp = 0; fpp = 0;     % initial values
for i = 1:m-2               % Horner's algorithm
    f = z*f + a(i);         % recursive evaluation of f(z)
    fp = z*fp + f;          % recursive evaluation of f'(z)
    fpp = z*fpp + fp;       % recursive evaluation of f''(z)
end
f = z*f + a(m-1);
fp = z*fp + f;
f = z*f + a(m);             % Finish evaluations
fpp = 2*fpp;

Higher order derivatives can be evaluated by a simple extension of this idea.

Describing the algorithm as a flow-graph illustrates the recursion as a feedback path with the feedback parameter being zz and shows the structure of evaluating derivatives.

Figure 5: Flow Graph for Horner's Algorithm
flowgraph1.png

Polynomial Deflation

If z0z0 is a zero of the polynomial fNaz fN a z , then R=0R0 and (5) becomes

fNaz=qN-1bzz-z0 fN az qN-1 bz z z0 (14)

with qN-1qN-1 being the N-1N1 degree polynomial (6) having the same zeros at fNfN except for the one at z=z0 z z0 . In other words, Horner's method can also be used to deflate a polynomial with a known zero. A Matlab program that will deflate fNaz fN az is given by:

Figure 6: Program 5. Forward Deflation of Polynomial

m = length(a);               % order = one: N+1
b = zeros(1, m-1);
b(1) = a(1);                 % initial conditions
for k = 1:m-2                % iterative Horner's algorithm 
  b(k+1) = z*b(k) + a(k+1);  % recursive deflation of f(z)
end

or using the more efficient Matlab "filter" command:

Figure 7: Program 6. Forward Deflation of Polynomial using Filter

N = length(a) - 1;
b = filter(1,[1 -z, a);   % Deflation by filter
b = b(1:N);

Because multiplication of two polynomials is the same operation as the convolution of their coefficients, one can get the same results by multiplying the discrete Fourier transform (DFT)'s of the polynomial coefficients and taking the inverse DFT of the product. This gives an alternative to Horner's algorithm for deflating polynomials and is the technique used in the Lindsey-Fox polynomial factoring scheme [8, 2]. The use of the FFT for deflation or unfactoring of polynomials has very different error characteristics from Horner's method and is often superior. A Matlab program that deflates a polynomial with coefficients akak by a divisor with coefficients dkdk to give a quotient with coefficients qkqk using the FFT is:

Figure 8: Program 7. Deflation of Polynomial usng the FFT

m = length(a); md = length(d);
q = ifft(ifft(a)./fft([d,zeros(1,(m-md))]));

A more general formulaiton of the deflation problem is of the form:

fNaz=qN-MbzdMcz+Rz fN az qN-M bz dM cz R z (15)
If the factors of dMz dM z are all roots of fNz fN z , then q N-Mq NM contains the others when Rz=0 R z 0 . This allows the easy deflation by quadratic factors or other factors that are already known.

Stability

Horner's method is implemented by the recursive equation (9) or (12) which, in this form, is seen to be a linear first order constant coefficient difference equation. There is considerable literature on the stability of linear differential and difference equations [7], and an equation of this form is known to be stable [9] for |z|<1 z 1 and unstable for |z|>1 z 1 .

To reduce error accumulation when |z|>1 z 1 we nest (1) and (2) in still a different way:

fNaz=zNz-1...z-1z-1z-1a0+a1+...+aN-1+aN fN a z zN z-1 ... z-1 z-1 z-1 a0 a1 ... a N1 aN (16)
to give an alternate recursive relationship to (9) which is the following difference equation:
x k+1 =z-1xk+a k-1 , x0=a0 x k1 z-1 xk a k1 , x0 a0 (17)
for k= 0,1,..., N-1 k 0,1,..., N-1 with the value of the polynomial at zz given by fNaz=zNxN fN a z zN xN . This equation is stable [7,9] for |z|>1 z 1 .

Again, remembering the Matlab index convention, the program for this form of Horner's algorithm is:

Figure 9: Program 8. Backward Evaluation of Polynomial which is stable for |z|>1

m = length(a);        % N+1
f = a(m);             % initial condition
for k = 1:m-1         % iterative Horner's method 
  f = f/z + a(m-k);   % recursive evaluation of f(z)
end
f = (z^(m-1))*f;      % remove the factor of z^{-m+1}

The same can be done for deflation.

This algorithm is equivalent to reversing the order ("flipping") the polynomial coefficients and applying (9) which will give zeros that are the reciprocal of those of the original polynomial [6,2]. Using the standard Matlab commands, this can be done by:

Figure 10: Program 9. Backward Evaluation of Polynomial by using Reversed Order Coefficients

m = length(a);
f = (z^(m-1))*polyval(a(m:-1:1),1/z);

It is easy to see that stability is very important when evaluating or deflating high degee polynomials by considering the effects if the degree is as high as one million [2]. Using this difference equation formulation of Horner's methods allows a more general deflation using a quadratic or higher degree divisor polynomial based on (8) and (15) to be easily analysed for stability.

Conclusions

We have seen that polynomial evaluation and deflation can be done by Horner's approach which is the conversion of the problem into a linear difference equation. Indeed, evaluation and first order deflation are accomplished by the same algorithm and the stability is easily controlled. Horner's methods are used in several basic Newton type factoring programs such as "broots". The alternative use of the DFT (FFT) for deflation should always be considered.

Having forwards and backwards algorithms allows one to always use a stable evaluation or deflation scheme [10,11,5,12,6,2,9]. If the magnitude of zz where the polynomial is being evaluated (or where the polynomial is being deflated) is less than one, use (9), if it is greater than one, use (17).

References

  1. V. Y. Pan. Solving a polynomial equation: some history and recent progress. SIAM Review, 39(2):187–220, June 1997.
  2. Gary A. Sitton, C. Sidney Burrus, James W. Fox, and Sven Treitel. Factoring very high degree polynomials. IEEE Signal Processing Magazine, 20(6):27–42, November 2003.
  3. Donald E. Knuth. The Art of Computer Programming, Vol. 2, Seminumerical Algo­rithms. Addison-Wesley, Reading, MA, third edition, 1997.
  4. E. J. Barbeau. Polynomials. Springer-Verlag, New York, 1989.
  5. N. J. Higham. Accuracy and Stability of Numerical Algorithms. SIAM, 1996. Chap­ter 5 on polynomials.
  6. W. H. Press, B. P.Flannery, S. A. Teukolsky, and W. T. Vetterling. Numerical Recipes in Fortran: The Art of Scientific Computing. Cambridge University Press, Cambridge, second edition, 1992.
  7. Saber N. Elaydi.An Introduction to Dierence Equations. Springer-Verlag, New York, second edition, 1999. First edition in 1996.
  8. J. P. Lindsey and James W. Fox. A method of factoring long z-transform polynomials. Computational Methods in Geosciences, SIAM, 78–90, 1992. Reprinted in Seismic Source Signature Estimation and Measurement, edited by Osman Osman and Enders Robinson, Society of Exploration Geophysicists, Geophysics Reprint Series no. 18, 712–724, 1996.
  9. James W. Fox. Improving the accuracy of polynomial evaluation, deflation, and root finding. draft manuscript, January 14 2002.
  10. Daniela Calvetti and Lothar Reichel. On the evaluation of polynomial coefficients. Numerical Algorithms, 33:153–161, 2003.
  11. J. H. Wilkinson.Rounding Errors in Algebraic Processes. Prentice-Hall, Englewood Cliffs, NJ, 1963. Now published by Dover, 1994.
  12. Forman S. Acton. Numerical Methods that Work. The Mathematical Association of America, Washington, DC, 1990.

Comments, questions, feedback, criticisms?

Send feedback