Article · Wikipedia archive · Last revised May 31, 2026

Knuth–Eve algorithm

In computer science, the Knuth–Eve algorithm is an algorithm for polynomial evaluation. It preprocesses the coefficients of the polynomial to reduce the number of multiplications required at runtime.

Last revised
May 31, 2026
Read time
≈ 7 min
Length
1,563 w
Citations
29
Source

In computer science, the Knuth–Eve algorithm is an algorithm for polynomial evaluation. It preprocesses the coefficients of the polynomial to reduce the number of multiplications required at runtime.

Ideas used in the algorithm were originally proposed by Donald Knuth in 1962. His procedure opportunistically exploits structure in the polynomial being evaluated.1 In 1964, James Eve determined for which polynomials this structure exists, and gave a simple method of "preconditioning" polynomials (explained below) to endow them with that structure.2note 1

Algorithm

Preliminaries

Consider an arbitrary polynomial p R [ x ] {\displaystyle p\in \mathbb {R} [x]} of degree n {\displaystyle n} . Assume that n 3 {\displaystyle n\geq 3} . Define m {\displaystyle m} such that: if n {\displaystyle n} is odd then n = 2 m + 1 {\displaystyle n=2m+1} , and if n {\displaystyle n} is even then n = 2 m + 2 {\displaystyle n=2m+2} .2

Unless otherwise stated, all variables in this article represent either real numbers or univariate polynomials with real coefficients.12 All operations in this article are done over R {\displaystyle \mathbb {R} } .2

Again, the goal is to create an algorithm that returns p ( x ) {\displaystyle p(x)} given any x {\displaystyle x} . The algorithm is allowed to depend on the polynomial p {\displaystyle p} itself, since its coefficients are known in advance.1

Overview

Key idea

Using polynomial long division, we can write

p ( x ) = q ( x ) ( x 2 α ) + ( β x + γ ) , {\displaystyle p(x)=q(x)\cdot (x^{2}-\alpha )+(\beta x+\gamma ),}

where x 2 α {\displaystyle x^{2}-\alpha } is the divisor. Picking a value for α {\displaystyle \alpha } fixes both the quotient q {\displaystyle q} and the coefficients in the remainder β {\displaystyle \beta } and γ {\displaystyle \gamma } . The key idea is to cleverly choose α {\displaystyle \alpha } such that β = 0 {\displaystyle \beta =0} , so that

p ( x ) = q ( x ) ( x 2 α ) + γ . {\displaystyle p(x)=q(x)\cdot (x^{2}-\alpha )+\gamma .}

4 This way, no operations are needed to compute the remainder polynomial, since it's just a constant. We apply this procedure recursively to q {\displaystyle q} , expressing

p ( x ) = ( ( q ( x ) ( x 2 α m ) + γ m ) ) ( x 2 α 1 ) + γ 1 . {\displaystyle p(x)=\left(\left(q(x)\cdot (x^{2}-\alpha _{m})+\gamma _{m}\right)\cdots \right)\cdot (x^{2}-\alpha _{1})+\gamma _{1}.}

After m {\displaystyle m} recursive calls, the quotient q {\displaystyle q} is either a linear or a quadratic polynomial. In this base case, the polynomial can be evaluated with (say) Horner's method.145

"Preconditioning"

For arbitrary p {\displaystyle p} , it may not be possible to force β = 0 {\displaystyle \beta =0} at every step of the recursion.1 Consider the polynomials p e {\displaystyle p^{e}} and p o {\displaystyle p^{o}} with coefficients taken from the even and odd terms of p {\displaystyle p} respectively, so that

p ( x ) = p e ( x 2 ) + x p o ( x 2 ) . {\displaystyle p(x)=p^{e}(x^{2})+x\cdot p^{o}(x^{2}).}

If every root of p o {\displaystyle p^{o}} is real, then it is possible to write p {\displaystyle p} in the form given above. Each α i {\displaystyle \alpha _{i}} is a different root of p o {\displaystyle p^{o}} , counting multiple roots as distinct.4 Furthermore, if at least n 1 {\displaystyle n-1} roots of p {\displaystyle p} lie in one half of the complex plane, then every root of p o {\displaystyle p^{o}} is real.2

Ultimately, it may be necessary to "precondition" p {\displaystyle p} by shifting it — by setting p ( x ) p ( x + t ) {\displaystyle p(x)\gets p(x+t)} for some t {\displaystyle t} — to endow it with the structure that most of its roots lie in one half of the complex plane. At runtime, this shift has to be "undone" by first setting x x t {\displaystyle x\gets x-t} .2

Preprocessing step

The following algorithm is run once for a given polynomial p {\displaystyle p} .14 At this point, the values of x {\displaystyle x} that p {\displaystyle p} will be evaluated on are not known.1

  • Let r 1 , , r n C {\displaystyle r_{1},\cdots ,r_{n}\in \mathbb {C} } be the complex roots of p {\displaystyle p} , sorted in descending order by real part
  • Choose any t Re ( r 2 ) {\displaystyle t\geq {\text{Re}}(r_{2})}
  • Set p p ( x + t ) {\displaystyle p\gets p(x+t)}

  • Let p e {\displaystyle p^{e}} and p o {\displaystyle p^{o}} be the polynomials such that p ( x ) = p e ( x 2 ) + x p o ( x 2 ) {\displaystyle p(x)=p^{e}(x^{2})+x\cdot p^{o}(x^{2})}
  • Let α 1 , α m R {\displaystyle \alpha _{1},\cdots \alpha _{m}\in \mathbb {R} } be the roots of p o {\displaystyle p^{o}} . All of its roots will be real.

  • Initialize q p {\displaystyle q\gets p}
  • For i 1 , , m {\displaystyle i\gets 1,\cdots ,m} :
    • Divide q {\displaystyle q} by x 2 α i {\displaystyle x^{2}-\alpha _{i}} to get quotient q R [ x ] {\displaystyle q^{\prime }\in \mathbb {R} [x]} and remainder γ i R {\displaystyle \gamma _{i}\in \mathbb {R} } . The remainder will be a constant polynomial — a number.
    • Set q q {\displaystyle q\gets q^{\prime }}

  • Output: The derived values t {\displaystyle t} , α 1 , , α m {\displaystyle \alpha _{1},\cdots ,\alpha _{m}} , and γ 1 , , γ m {\displaystyle \gamma _{1},\cdots ,\gamma _{m}} ; as well as the base-case polynomial q {\displaystyle q}

Better choice of t

While any t Re ( r 2 ) {\displaystyle t\geq {\text{Re}}(r_{2})} can work, it is possible to remove one addition during evaluation if t {\displaystyle t} is also chosen such that two roots of p ( x + t ) {\displaystyle p(x+t)} are symmetric about the origin. In that case, α 1 {\displaystyle \alpha _{1}} can be chosen such that the shifted polynomial has a factor of x 2 α 1 {\displaystyle x^{2}-\alpha _{1}} , so γ 1 = 0 {\displaystyle \gamma _{1}=0} . It is always possible to find such a t {\displaystyle t} .2

One possible algorithm for choosing t {\displaystyle t} is:

  • If r 1 R {\displaystyle r_{1}\in \mathbb {R} } :
    • If r 2 R {\displaystyle r_{2}\in \mathbb {R} } : t = 1 2 ( r 1 + r 2 ) {\textstyle t={\tfrac {1}{2}}(r_{1}+r_{2})}
    • Else: t = Re ( r 2 ) {\displaystyle t={\text{Re}}(r_{2})}
  • Else: t = Re ( r 1 ) {\displaystyle t={\text{Re}}(r_{1})}

Evaluation step

The following algorithm evaluates p {\displaystyle p} at some, now known, point x {\displaystyle x} .1245

  • Set x x t {\displaystyle x\gets x-t}
  • Let s = x 2 {\displaystyle s=x^{2}} . Compute this once so it can be reused.

  • Compute y q ( x ) {\displaystyle y\gets q(x)} using Horner's method
  • For i m , , 2 , 1 {\displaystyle i\gets m,\cdots ,2,1} :
    • Let y y ( s α i ) + γ i {\displaystyle y\gets y\cdot (s-\alpha _{i})+\gamma _{i}}
  • Output: y {\displaystyle y}

Assuming t {\displaystyle t} is chosen optimally, γ 1 = 0 {\displaystyle \gamma _{1}=0} . So, the final iteration of the loop can instead run

y y ( s α i ) , {\displaystyle y\gets y\cdot (s-\alpha _{i}),}

saving an addition.2

Analysis

In total, evaluation using the Knuth–Eve algorithm for a polynomial of degree n {\displaystyle n} requires n {\displaystyle n} additions and n / 2 + 2 {\displaystyle \lfloor n/2\rfloor +2} multiplications, assuming t {\displaystyle t} is chosen optimally.2

No algorithm to evaluate a given polynomial of degree n {\displaystyle n} can use fewer than n {\displaystyle n} additions or fewer than n / 2 {\displaystyle \lceil n/2\rceil } multiplications during evaluation. This result assumes only addition and multiplication are allowed during both preprocessing and evaluation.6

The Knuth–Eve algorithm is not well-conditioned.7

Footnotes

Footnotes

  1. Article published under the name J. Eve, which is associated with the name James Eve by the ACM Digital Library.3
References

References

  1. Knuth, Donald (December 1962). "Evaluation of polynomials by computer". Communications of the ACM. 5 (12): 595–599. doi:10.1145/355580.369074. Retrieved 25 July 2025.
  2. Eve, James (December 1964). "The evaluation of polynomials". Numerische Mathematik. 6 (1): 17–21. doi:10.1007/BF01386049. Retrieved 25 July 2025.
  3. "James Eve (Newcastle University)". Author DO Series. ACM Digital Library. doi:10.1145/contrib-81100250587/abs (inactive 31 July 2025). Retrieved 2025-07-30.{{cite web}}: CS1 maint: DOI inactive as of July 2025 (link)
  4. Overill, Richard (12 June 1997). "Data parallel evaluation of univariate polynomials by the Knuth-Eve algorithm". Parallel Computing. 23 (13): 2115–2127. doi:10.1016/S0167-8191(97)00096-3. Retrieved 25 July 2025.
  5. Muller, Jean-Michel (17 November 2016). Elementary functions: Algorithms and implementation. Boston, MA: Birkhäuser Boston. pp. 82–84. doi:10.1007/978-1-4899-7983-4_5. ISBN 978-1-4899-7983-4. Retrieved 25 July 2025.
  6. Erickson, Jeff (10 March 2003). "Evaluating polynomials" (PDF). CS 497: Concrete Models of Computation. University of Illinois Urbana-Champaign. Retrieved 25 July 2025.
  7. Mesztenyi, Charles (January 1967). "Stable evaluation of polynomials". Journal of Research of the National Bureau of Standards, Section B. 71B (1): 11–17. doi:10.6028/jres.071B.003. Retrieved 25 July 2025.