AI Glossary / Mathematics and optimization / Intermediate
Horner's method
Definition
Horner's method evaluates a polynomial by rewriting it as nested multiplication and addition. Instead of computing each power of the input separately, it carries a running value through the coefficients from highest degree to lowest. For a dense degree-n polynomial, the basic evaluation uses n multiplications and n additions. It is an arithmetic technique, not a learning algorithm, though polynomial calculations occur throughout numerical computing and machine learning.
What it means
A polynomial combines coefficients with powers of a variable. For example, 2x cubed minus 3x squared plus 4x minus 5 is one polynomial, regardless of how its arithmetic is arranged. Horner's method changes that arrangement without changing the exact mathematical function.
The benefit is a simple repeated operation: multiply the accumulated value by x, then add the next coefficient. Coefficient order is therefore crucial. A missing power still needs a zero coefficient when using the standard dense recurrence, or the algorithm will evaluate a different polynomial.
How it works
For p(x)=a_n x^n + ... + a_1 x + a_0, initialize b=a_n. Then, for coefficients a_(n-1) down to a_0, replace b with xb+a_k. The final b is p(x).
The same recurrence is closely related to synthetic division by x-alpha: intermediate values give quotient coefficients and the last value is the remainder p(alpha). An extended form can evaluate derivatives. In floating-point arithmetic, the algebraic equivalence remains exact only at the mathematical level; rounding and conditioning still affect the computed result.
Three practical examples
- A numerical model can evaluate a polynomial approximation repeatedly without recomputing separate powers for every term.
- A calibration routine can use a compact coefficient representation and a consistent evaluation loop for its fitted polynomial.
- A root-finding implementation can use polynomial values and derivative evaluations as ingredients in a larger iterative method.
Think of it this way
Think of assembling a nested set of boxes: each new layer multiplies what is already inside and then adds one more item. The final contents equal a more spread-out arrangement, but the assembly steps are simpler. The analogy is limited because arithmetic order can affect floating-point rounding even when two algebraic expressions describe the same exact value.
Worked example
Consider the original polynomial p(x)=2x^3-3x^2+4x-5 at x=2. Its nested form is ((2x-3)x+4)x-5. Start with b=2. Multiply by 2 and add -3 to obtain 1. Multiply by 2 and add 4 to obtain 6. Multiply by 2 and add -5 to obtain 7. Thus p(2)=7.
Check directly: 2 times 8 minus 3 times 4 plus 4 times 2 minus 5 equals 16-12+8-5=7. The Horner trace used three multiplication stages and three additions. This operation count refers to the stated recurrence, not to a measured speedup on a particular processor.
The intermediate values also show synthetic division. Dividing p(x) by x-2 gives quotient 2x^2+x+6 and remainder 7, since (x-2)(2x^2+x+6)+7 expands back to 2x^3-3x^2+4x-5. A zero remainder would establish that 2 is a root in exact arithmetic; here it is not.
Now consider q(x)=3x^3+2x+1. Its coefficient sequence is 3,0,2,1, including zero for the missing squared term. At x=2, the running values are 3,6,14,29. Omitting the zero would instead evaluate 3x^2+2x+1 and return 17. The arithmetic loop cannot infer an omitted exponent from a short coefficient list.
For a numerical caution, (x-1)^2 equals x^2-2x+1. At x=1.0001, the exact value is 0.00000001. In the expanded or Horner arrangement, intermediate terms of roughly unit size must cancel to produce this small result. Finite-precision rounding can affect the final relative accuracy. The factored expression may behave differently. This is an exact-arithmetic illustration of cancellation, not a claim that a particular floating-point run returned an incorrect number.
Illustrative case study
Fictional case: a sensor-software team replaces a manually expanded calibration formula with a shared polynomial evaluator. A test fails because one coefficient file lists values from constant term to highest degree, while the evaluator expects the reverse order.
The team documents the convention, includes zeros for missing powers, and tests values against a reference calculation. It also checks the input range over which the calibration was fitted. Efficient evaluation does not make extrapolation outside that range trustworthy.
Common misconceptions and mistakes
Do not assume Horner's method finds polynomial roots by itself. It evaluates a polynomial and supports related division or derivative operations; root finding needs additional logic.
Do not confuse fewer arithmetic operations with guaranteed accurate answers for every polynomial and input. Cancellation and poor conditioning can limit relative accuracy, especially near roots. Nor is the standard dense recurrence always the best choice for every representation: a sparse polynomial, a factored form, or an orthogonal-polynomial expansion may support a more suitable specialized method.
Business use
Horner evaluation is useful when polynomial computations are frequent and a simple, predictable implementation is desirable. Its practical value comes from reducing unnecessary work while keeping coefficient handling explicit.
Specify coefficient order, numeric type, degree, and valid input range. Check edge cases such as x=0, constant polynomials, and missing powers. Compare against higher-precision or exact calculations where numerical accuracy matters. Benchmark within the actual application before claiming a runtime benefit, since compilers, vectorization, and surrounding work affect observed performance.
People also ask
Does Horner's method change the polynomial?
No. In exact arithmetic it evaluates the same polynomial through a nested form.
Why must zero coefficients be included?
They preserve the place of missing powers in the recurrence.
Is it always numerically exact?
No. Floating-point operations round, and an ill-conditioned evaluation can still have substantial relative error.
Check your understanding
What goes wrong if q(x)=3x^3+2x+1 is encoded as 3,2,1 for a dense descending-order Horner loop?
Answer: The missing zero shifts the powers, so the loop evaluates 3x^2+2x+1 instead of the intended cubic.
Related terms
- Conditioning
- Root finding
- Polynomial evaluation
- Synthetic division
- Floating-point arithmetic
- Numerical stability
- Cancellation
- Polynomial approximation
- Compensated Horner algorithm
Learn next
Evaluate the original cubic at x=-1 using Horner's method and direct substitution. Then use the intermediate values to write its quotient and remainder upon division by x+1. Explain why the remainder must equal the polynomial's value at -1.
More in Mathematics and optimization
- Absolute error loss - Absolute error loss measures a numerical prediction's error as the absolute difference between its predicted and reference values: L(y,y-hat)=|y-y-hat|.
- Active-set method - An active-set method is an optimization approach that works with a changing subset of constraints believed to be tight at the solution.
- Adjoint state method - The adjoint state method computes how a chosen objective changes when the parameters of a mathematical model change.
- Σ-algebra
- Algebraic connectivity - Algebraic connectivity is the second-smallest eigenvalue of a graph's Laplacian matrix.
- Algorithm IMED - Algorithm IMED, short for Indexed Minimum Empirical Divergence, is a method for choosing actions in a stochastic multi-armed bandit problem.
Sources
Primary mathematical reference: NIST Digital Library of Mathematical Functions, Horner's scheme and extended scheme: https://dlmf.nist.gov/1.11 . Original numerical-analysis research context: Langlois and Louvet, Faithful Polynomial Evaluation with Compensated Horner Algorithm: https://arxiv.org/abs/cs/0610122 . All polynomial traces are original calculations.
Previous: Horn - Schunck Next: Horseshoe distribution