In mathematics and computer science, Horner's method (or Horner's scheme) is an algorithm for polynomial evaluation. It is named after William George Horner, although it is much older, attributed by Horner to Joseph-Louis Lagrange, and was discovered hundreds of years earlier by Chinese and Persian mathematicians. After the introduction of computers, this algorithm became fundamental for computing efficiently with polynomials. The algorithm is based on Horner's rule, in which a polynomial is written in nested form: a0+a1x+a2x2+a3x3+⋯+anxn=a0+x(a1+x(a2+x(a3+⋯+x(an−1+xan)⋯))). This allows the evaluation of a polynomial of degree n with only n multiplications and n additions. This is optimal, as it is impossible to evaluate polynomials of degree n with fewer arithmetic operations when both x and the coefficients a0, ..., an are given as input. The name Horner's method (or Horner–Ruffini method) also refers to a method for approximating the roots of polynomials, described by Horner in 1819. It finds a root digit by digit, by repeatedly transforming the equation so that its roots are diminished by the part of the root already found; Horner's rule gives a convenient tabular scheme for each transformation, and each next digit is estimated by a step of the Newton–Raphson method. It was widely used until computers came into general use around 1970.
Polynomial evaluation and long division Given the polynomialp(x)=∑i=0naixi=a0+a1x+a2x2+a3x3+⋯+anxn,where a0,…,an are constant coefficients, the problem is to evaluate the polynomial at a specific value x0 of x. For this, a new sequence of constants is defined recursively as follows:
Then b0 is the value of p(x0). To see why this works, the polynomial can be written in the form p(x)=a0+x(a1+x(a2+x(a3+⋯+x(an−1+xan)⋯))) . Thus, by iteratively substituting the bi into the expression, p(x0)=a0+x0(a1+x0(a2+⋯+x0(an−1+bnx0)⋯))=a0+x0(a1+x0(a2+⋯+x0bn−1))⋮=a0+x0b1=b0. Similarly, it can be shown that:
This gives a convenient procedure for the polynomial division p(x)/(x−x0): the quotient has coefficients b1,…,bn, and the remainder is b0=p(x0). If x0 is a root of p(x), then b0=0 and x−x0 is a factor of p(x).
Examples Evaluate f(x)=2x3−6x2+2x−1 for x=3. We use synthetic division as follows:
3 2−62−16062025 The entries in the third row are the sum of those in the first two. Each entry in the second row is the product of the x-value (3 in this example) with the third-row entry immediately to the left. The entries in the first row are the coefficients of the polynomial to be evaluated. Then the remainder of f(x) on division by x−3 is 5. But by the polynomial remainder theorem, we know that the remainder is f(3). Thus, f(3)=5. In the notation of the previous section, a3=2,a2=−6,a1=2,a0=−1, and the entries in the third row are b3=2,b2=0,b1=2,b0=5. Synthetic division, which Ruffini published before Horner's paper, is thus the same computation as Horner's method, arranged as a table. By equation 2, the first three entries of the third row are the coefficients of the quotient of f(x) on division by x−3, namely 2x2+2, and the last entry, 5, is the remainder. This makes Horner's method useful for polynomial long division. Divide x3−6x2+11x−6 by x−2:
2 1−611−62−861−430 The quotient is x2−4x+3. Let f1(x)=4x4−6x3+3x−5 and f2(x)=2x−1. Since f2(x)=2(x−0.5), one can divide f1(x) by x−0.5 using Horner's method and then divide the quotient by 2:
0.5 4−603−52−2−114−4−22−4 The quotient on division by x−0.5 is 4x3−4x2−2x+2 and the remainder is −4. Dividing the quotient by 2 gives f1(x)f2(x)=2x3−2x2−x+1−42x−1.
Efficiency Evaluation using the monomial form of a degree n polynomial requires at most n additions and (n2+n)/2 multiplications, if powers are calculated by repeated multiplication and each monomial is evaluated individually. The cost can be reduced to n additions and 2n−1 multiplications by evaluating the powers of x by iteration. If numerical data are represented in terms of digits (or bits), then the naive algorithm also entails storing approximately 2n times the number of bits of x: the evaluated polynomial has approximate magnitude xn, and one must also store xn itself. By contrast, Horner's method requires only n additions and n multiplications, and its storage requirements are only n times the number of bits of x. Alternatively, Horner's method can be computed with n fused multiply–adds. Horner's method can also be extended to evaluate the first k derivatives of the polynomial with kn additions and multiplications. Horner's method is optimal, in the sense that any algorithm to evaluate an arbitrary polynomial must use at least as many operations. Alexander Ostrowski proved in 1954 that the number of additions required is minimal. Victor Pan proved in 1966 that the number of multiplications is minimal. These optimality results assume that the polynomial is evaluated in monomial form and that no preconditioning of the representation is allowed, which makes sense if the polynomial is evaluated only once. However, if preconditioning is allowed and the polynomial is to be evaluated many times, then faster algorithms are possible. They involve a transformation of the representation of the polynomial. In general, a degree-n polynomial can be evaluated using only ⌊n/2⌋+2 multiplications and n additions. Horner's method is also not optimal for the evaluation of matrix polynomials (where x is a matrix but the coefficients are scalars) when scalar multiplications and matrix multiplications are counted separately, as the former are cheaper than the latter.
Parallel evaluation
… excerpt ends here. Continue reading the full article.
