Knuth–Eve algorithm

From testwiki
Jump to navigation Jump to search

Template:Short description

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.[2]Template:Refn

Algorithm

Preliminaries

Consider an arbitrary polynomial p∈ℝ[x] of degree n. Assume that n≥3. Define m such that: if n is odd then n=2m+1, and if n is even then n=2m+2.[2]

Unless otherwise stated, all variables in this article represent either real numbers or univariate polynomials with real coefficients.[1][2] All operations in this article are done over ℝ.[2]

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

Overview

Key idea

Using polynomial long division, we can write

p(x)=q(x)⋅(x2−α)+(βx+γ),

where x2−α is the divisor. Picking a value for α fixes both the quotient q and the coefficients in the remainder β and γ. The key idea is to cleverly choose α such that β=0, so that

p(x)=q(x)⋅(x2−α)+γ.

[3] This way, no operations are needed to compute the remainder polynomial, since it's just a constant. We apply this procedure recursively to q, expressing

p(x)=((q(x)⋅(x2−αm)+γm)⋯)⋅(x2−α1)+γ1.

After m recursive calls, the quotient q is either a linear or a quadratic polynomial. In this base case, the polynomial can be evaluated with (say) Horner's method.[1][3][4]

"Preconditioning"

For arbitrary p, it may not be possible to force β=0 at every step of the recursion.[1] Consider the polynomials pe and po with coefficients taken from the even and odd terms of p respectively, so that

p(x)=pe(x2)+x⋅po(x2).

If every root of po is real, then it is possible to write p in the form given above. Each αi is a different root of po, counting multiple roots as distinct.[3] Furthermore, if at least n−1 roots of p lie in one half of the complex plane, then every root of po is real.[2]

Ultimately, it may be necessary to "precondition" p by shifting it Template:-- by setting p(x)←p(x+t) for some t Template:-- 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.[2]

Preprocessing step

The following algorithm is run once for a given polynomial p.[1][3] At this point, the values of x that p will be evaluated on are not known.[1]

Template:Framebox

  • Let r1,⋯,rn∈ℂ be the complex roots of p, sorted in descending order by real part
  • Choose any t≥Re(r2)
  • Set p←p(x+t)

  • Let pe and po be the polynomials such that p(x)=pe(x2)+x⋅po(x2)
  • Let α1,⋯αm∈ℝ be the roots of po. All of its roots will be real.

  • Initialize q←p
  • For i←1,⋯,m:
    • Divide q by x2−αi to get quotient q′∈ℝ[x] and remainder γi∈ℝ. The remainder will be a constant polynomial Template:-- a number.
    • Set q←q′

  • Output: The derived values t, α1,⋯,αm, and γ1,⋯,γm; as well as the base-case polynomial q

Template:Frame-footer

Better choice of t

While any t≥Re(r2) can work, it is possible to remove one addition during evaluation if t is also chosen such that two roots of p(x+t) are symmetric about the origin. In that case, α1 can be chosen such that the shifted polynomial has a factor of x2−α1, so γ1=0. It is always possible to find such a t.[2]

One possible algorithm for choosing t is:Template:Citation needed

Template:Framebox

  • If r1∈ℝ:
    • If r2∈ℝ: t=12(r1+r2)
    • Else: t=Re(r2)
  • Else: t=Re(r1)

Template:Frame-footer

Evaluation step

The following algorithm evaluates p at some, now known, point x.[1][2][3][4]

Template:Framebox

  • Set x←x−t
  • Let s=x2. Compute this once so it can be reused.

  • Compute y←q(x) using Horner's method
  • For i←m,⋯,2,1:
    • Let y←y⋅(s−αi)+γi
  • Output: y

Template:Frame-footer

Assuming t is chosen optimally, γ1=0. So, the final iteration of the loop can instead run

y←y⋅(s−αi),

saving an addition.[2]

Analysis

In total, evaluation using the Knuth–Eve algorithm for a polynomial of degree n requires n additions and ⌊n/2⌋+2 multiplications, assuming t is chosen optimally.[2]

No algorithm to evaluate a given polynomial of degree n can use fewer than n additions or fewer than ⌈n/2⌉ multiplications during evaluation. This result assumes only addition and multiplication are allowed during both preprocessing and evaluation.[5]Template:Better source needed

The Knuth–Eve algorithm is not well-conditioned.[6]

Footnotes

Template:Reflist

References