Polynomial Evaluation
   HOME

TheInfoList



OR:

In
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
and
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, polynomial evaluation refers to computation of the value of a
polynomial In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An exa ...
when its indeterminates are substituted for some values. In other words, evaluating the polynomial P(x_1, x_2) = 2x_1x_2 + x_1^3 + 4 at x_1=2, x_2=3 consists of computing P(2,3)= 2\cdot 2\cdot 3 + 2^3+4=24. See also For evaluating the
univariate polynomial In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An example ...
a_nx^n+a_x^+\cdots +a_0, the most naive method would use n multiplications to compute a_n x^n, use n-1 multiplications to compute a_ x^ and so on for a total of \tfrac multiplications and n additions. Using better methods, such as
Horner's rule In mathematics and computer science, Horner's method (or Horner's scheme) is an algorithm for polynomial evaluation. Although named after William George Horner, this method is much older, as it has been attributed to Joseph-Louis Lagrange by Horn ...
, this can be reduced to n multiplications and n additions. If some preprocessing is allowed, even more savings are possible.


Background

This problem arises frequently in practice. In
computational geometry Computational geometry is a branch of computer science devoted to the study of algorithms which can be stated in terms of geometry. Some purely geometrical problems arise out of the study of computational geometric algorithms, and such problems ar ...
, polynomials are used to compute function approximations using
Taylor polynomials In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor seri ...
. In
cryptography Cryptography, or cryptology (from grc, , translit=kryptós "hidden, secret"; and ''graphein'', "to write", or ''-logia'', "study", respectively), is the practice and study of techniques for secure communication in the presence of adver ...
and
hash table In computing, a hash table, also known as hash map, is a data structure that implements an associative array or dictionary. It is an abstract data type that maps keys to values. A hash table uses a hash function to compute an ''index'', als ...
s, polynomials are used to compute
k-independent hashing In computer science, a family of hash functions is said to be ''k''-independent, ''k''-wise independent or ''k''-universal if selecting a function at random from the family guarantees that the hash codes of any designated ''k'' keys are independe ...
. In the former case, polynomials are evaluated using
floating-point arithmetic In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
, which is not exact. Thus different schemes for the evaluation will, in general, give slightly different answers. In the latter case, the polynomials are usually evaluated in a
finite field In mathematics, a finite field or Galois field (so-named in honor of Évariste Galois) is a field that contains a finite number of elements. As with any field, a finite field is a set on which the operations of multiplication, addition, subtr ...
, in which case the answers are always exact.


General methods


Horner's rule

Horner's method evaluates a polynomial using repeated bracketing: \begin a_0 &+ a_1x + a_2x^2 + a_3x^3 + \cdots + a_nx^n \\ &= a_0 + x \bigg(a_1 + x \Big(a_2 + x \big(a_3 + \cdots + x(a_ + x\,a_n) \cdots \big) \Big) \bigg). \end This method reduces the number of multiplications and additions to just n Horner's method is so common that a computer instruction "
multiply–accumulate operation In computing, especially digital signal processing, the multiply–accumulate (MAC) or multiply-add (MAD) operation is a common step that computes the product of two numbers and adds that product to an accumulator. The hardware unit that perform ...
" has been added to many computer processors, which allow doing the addition and multiplication operations in one combined step.


Multivariate

If the polynomial is multivariate, Horner's rule can be applied recursively over some ordering of the variables. E.g. :P(x, y) = 4 + x + 2 x y + 2 x^2 y + x^2 y^2 can be written as :\begin P(x, y) &= 4 + x (1 + y(2) + x (y(2 + y))) \quad\text\\ P(x, y) &= 4 + x + y(x(2 + x(2)) + y(x^2)). \end An efficient version of this approach was described by Carnicer and Gasca.


Evaluation with preprocessing

Arbitrary polynomials can be evaluated with fewer operations than Horner's rule requires if we first "preprocess" the coefficients a_n, \dots, a_0. An example was first given by Motzkin who noted that :P(x)=x^4 + a_3 x^3 + a_2 x^2 + a_1 x + a_0 can be written as :y = (x+\beta_0)x+\beta_1,\quad P(x)=(y+x+\beta_2)y+\beta_3, where the values \beta_0, \dots, \beta_3 are computed in advance based on a_0, \dots, a_3. Motzkin's method uses just 3 multiplications compared to Horner's 4. The values for each \beta_i can be easily computed by expanding P(x) and equating the coefficients: :\begin \beta_0&=\tfrac12(a_3-1),\quad &z&=a_2-\beta_0(\beta_0+1),\quad &\beta_1&=a_1-\beta_0 z,\\ \beta_2&=z-2\beta_1, \quad &\beta_3&=a_0-\beta_1(\beta_1+\beta_2).\end


Example

To compute the
Taylor expansion In mathematics, the Taylor series or Taylor expansion of a function is an infinite sum of terms that are expressed in terms of the function's derivatives at a single point. For most common functions, the function and the sum of its Taylor serie ...
\exp(x) \approx 1+x+x^2/2+x^3/6+x^4/24, we can upscale by a factor 24, apply the above steps, and scale back down. That gives us the three multiplication computation :y = (x+1.5)x+11.625,\quad P(x)=(y+x-15)y/24+2.63477. Improving over the equivalent Horner form (that is P(x) = 1 + x (1 + x (1/2 + x(1/6 + x/24)))) by 1 multiplication.


Multipoint evaluation

Evaluate of a n-degree polynomial P(x) in multiple points x_1, \dots, x_m can be done with mn multiplications by using
Horner's method In mathematics and computer science, Horner's method (or Horner's scheme) is an algorithm for polynomial evaluation. Although named after William George Horner, this method is much older, as it has been attributed to Joseph-Louis Lagrange by Hor ...
m times. Using above preprocessing approach, this can be reduced that by a factor of two, that is, to mn/2 multiplications. However, it is possible to do better. It is possible to reduce the time requirement to just O\big((n + m) \log^2(n + m)\big). The idea is to define two polynomials that are zero in respectively the first and second half of the points: m_0(x)=(x-x_1)\cdots(x-x_) and m_1(x)=(x-x_)\cdots(x-x_). We then compute R_0 = P \bmod m_0 and R_1 = P \bmod m_1 using
Polynomial remainder theorem In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An exam ...
, which can be done in O(n\log n) time using
Fast Fourier Transform A fast Fourier transform (FFT) is an algorithm that computes the discrete Fourier transform (DFT) of a sequence, or its inverse (IDFT). Fourier analysis converts a signal from its original domain (often time or space) to a representation in th ...
. Since P(x) = Q(x)m_0(x) + R_0(x) and P(x) = Q(x)m_1(x) + R_1(x) by construction, we have :\begin R_0(x_i) &= P(x_i) \quad\text i \le n/2 \quad\text\\ R_1(x_i) &= P(x_i) \quad\text i > n/2. \end This gives us a
Divide-and-conquer algorithm In computer science, divide and conquer is an algorithm design paradigm. A divide-and-conquer algorithm recursively breaks down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved dire ...
with T(n) = 2T(n/2) + n\log n, which implies T(n)=O(n(\log n)^2). In the case where the points in which we wish to evaluate the polynomials have some structure, simpler methods exists. For example, Knuth section 4.6.4 gives a method for tabulating polynomial values of the type :P(x_0 + h), P(x_0 + 2h), \dots.


Dynamic evaluation

In the case where x_1, \dots, x_m are not known in advance, Kedlaya and Umans gave a data structure for evaluating polynomials over a
finite field In mathematics, a finite field or Galois field (so-named in honor of Évariste Galois) is a field that contains a finite number of elements. As with any field, a finite field is a set on which the operations of multiplication, addition, subtr ...
of size F_q in time (\log n)^(\log_2 q)^ per evaluation after some initial preprocessing. This was shown by Larsen to be essentially optimal. The idea is to transform P(x) of degree n into a
multivariate polynomial In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An exampl ...
f(x_1, x_2, \dots, x_m), such that P(x) = f(x, x^d, x^, \dots, x^) and the individual degrees of f is at most d. Since this is over \bmod q, the largest value f can take (over \mathbb Z) is M = d^m (q-1)^. Using the
Chinese remainder theorem In mathematics, the Chinese remainder theorem states that if one knows the remainders of the Euclidean division of an integer ''n'' by several integers, then one can determine uniquely the remainder of the division of ''n'' by the product of thes ...
, it suffices to evaluate f modulo different primes p_1, \dots, p_\ell with a product at least M. Each prime can be taken to be roughly \log M = O(dm\log q), and the number of primes needed, \ell, is roughly the same. Doing this process recursively, we can get the primes as small as \log\log q. That means we can compute and store f on all the possible values in T = (\log\log q)^m time and space. If we take d = \log q, we get m = \tfrac, so the time/space requirement is just n^\frac. Kedlaya and Umans further show how to combine this preprocessing with fast (FFT) multipoint evaluation. This allows optimal algorithms for many important algebraic problems, such as polynomial
modular composition Broadly speaking, modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a s ...
.


Specific polynomials

While general polynomials require \Omega(n) operations to evaluate, some polynomials can be computed much faster. For example, the polynomial P(x)=x^2+2x+1 can be computed using just one multiplication and one addition since P(x)=(x+1)^2


Evaluation of powers

A particularly interesting type of polynomial is powers like x^n. Such polynomials can always be computed in O(\log n) operations. Suppose, for example, that we need to compute x^; we could simply start with x and multiply by x to get x^2. We can then multiply that by itself to get x^4 and so on to get x^8 and x^ in just four multiplications. Other powers like x^5 can similarly be computed efficiently by first computing x^4 by 2 multiplications and then multiplying by x. The most efficient way to compute a given power x^n is provided by addition-chain exponentiation. However, this requires designing a specific algorithm for each exponent, and the computation needed for designing these algorithms are difficult (
NP-complete In computational complexity theory, a problem is NP-complete when: # it is a problem for which the correctness of each solution can be verified quickly (namely, in polynomial time) and a brute-force search algorithm can find a solution by tryi ...
), so exponentiation by squaring is generally preferred for effective computations.


Polynomial families

Often polynomials show up in a different form than the well known a_n x^n + \dots + a_1 x + a_0. For polynomials in
Chebyshev form The Chebyshev polynomials are two sequences of polynomials related to the cosine and sine functions, notated as T_n(x) and U_n(x). They can be defined in several equivalent ways, one of which starts with trigonometric functions: The Chebyshe ...
we can use
Clenshaw algorithm In numerical analysis, the Clenshaw algorithm, also called Clenshaw summation, is a recursive method to evaluate a linear combination of Chebyshev polynomials. Note that this paper is written in terms of the ''Shifted'' Chebyshev polynomials of th ...
. For polynomials in Bézier form we can use
De Casteljau's algorithm In the mathematical field of numerical analysis, De Casteljau's algorithm is a recursive method to evaluate polynomials in Bernstein form or Bézier curves, named after its inventor Paul de Casteljau. De Casteljau's algorithm can also be used to ...
, and for B-splines there is
De Boor's algorithm In the mathematical subfield of numerical analysis de Boor's algorithmC. de Boor 971 "Subroutine package for calculating with B-splines", Techn.Rep. LA-4728-MS, Los Alamos Sci.Lab, Los Alamos NM; p. 109, 121. is a polynomial-time and numerically sta ...
.


Hard polynomials

The fact that some polynomials can be computed significantly faster than "general polynomials" suggests the question: Can we give an example of a simple polynomial that cannot be computed in time much smaller than its degree?
Volker Strassen Volker Strassen (born April 29, 1936) is a German mathematician, a professor emeritus in the department of mathematics and statistics at the University of Konstanz. For important contributions to the analysis of algorithms he has received many aw ...
has shown that the polynomial :P(x)=\sum_^n 2^x^k cannot be evaluated by with less than \tfrac12 n - 2 multiplications and n - 4 additions. At least this bound holds if only operations of those types are allowed, giving rise to a so-called "polynomial chain of length ". The polynomial given by Strassen has very large coefficients, but by probabilistic methods, one can show there must exist even polynomials with coefficients just 0's and 1's such that the evaluation requires at least \Omega(n/\log n) multiplications. For other simple polynomials, the complexity is unknown. The polynomial (x+1)(x+2)\cdots(x+n) is conjectured to not be computable in time (\log n)^ for any c. This is supported by the fact, that if it can be computed fast then
Integer factorization In number theory, integer factorization is the decomposition of a composite number into a product of smaller integers. If these factors are further restricted to prime numbers, the process is called prime factorization. When the numbers are suf ...
can be computed in polynomial time, breaking the
RSA cryptosystem RSA (Rivest–Shamir–Adleman) is a public-key cryptosystem that is widely used for secure data transmission. It is also one of the oldest. The acronym "RSA" comes from the surnames of Ron Rivest, Adi Shamir and Leonard Adleman, who publicly ...
.


Matrix polynomials

Sometimes the computational cost of scalar multiplications (like ax) is less than the computational cost of "non scalar" multiplications (like x^2). The typical example of this is matrices. If M is an m\times m matrix, a scalar multiplication aM takes about m^2 arithmetic operations, while computing M^2 takes about m^3 (or m^ using
fast matrix multiplication In theoretical computer science, the computational complexity of matrix multiplication dictates how quickly the operation of matrix multiplication can be performed. Matrix multiplication algorithms are a central subroutine in theoretical and num ...
). Matrix polynomials are important for example for computing the Matrix Exponential. Paterson and Stockmeyer showed how to compute a degree n polynomial using only O(\sqrt n) non scalar multiplications and O(n) scalar multiplications. Thus a
matrix polynomial In mathematics, a matrix polynomial is a polynomial with square matrices as variables. Given an ordinary, scalar-valued polynomial : P(x) = \sum_^n =a_0 + a_1 x+ a_2 x^2 + \cdots + a_n x^n, this polynomial evaluated at a matrix ''A'' is :P(A) = ...
of degree can be evaluated in O(m^\sqrt + m^2n) time. If m=n this is less than O(n^3); that is, faster than a single matrix multiplication with the standard algorithm. This method works as follows: For a polynomial :P(M)=a_ M^ + \dots + a_M + a_0 I, let be the least integer not smaller than \sqrt. The powers M, M^2, \dots, M^k are computed with k matrix multiplications, and M^, M^, \dots, M^ are then computed by repeated multiplication by M^k. Now, :\beginP(M) = &\,(a_0 I + a_1 M + \dots + a_M^) \\+&\,(a_k I + a_ M + \dots + a_M^)M^k \\+&\,\dots \\+&\,(a_ I + a_ M + \dots + a_M^)M^, \end, where a_i=0 for . This requires just k more non-scalar multiplications. We can write this succinctly using the
Kronecker product In mathematics, the Kronecker product, sometimes denoted by ⊗, is an operation on two matrices of arbitrary size resulting in a block matrix. It is a generalization of the outer product (which is denoted by the same symbol) from vectors to ...
: :P(M) = \beginI\\M\\\vdots\\M^\end^T \left(\begin a_0 & a_1 & a_2 & \dots\\ a_k & a_ & \ddots \\ a_ & \ddots \\ \vdots\end\otimes I\right) \beginI\\M^k\\M^\\\vdots\end .


See also

*
Estrin's scheme In numerical analysis, Estrin's scheme (after Gerald Estrin), also known as Estrin's method, is an algorithm for numerical evaluation of polynomials. Horner's method for evaluation of polynomials is one of the most commonly used algorithms for thi ...
to facilitate parallelization on modern computer architectures *
Arithmetic circuit complexity In computational complexity theory, ''arithmetic circuits'' are the standard model for computing polynomials. Informally, an arithmetic circuit takes as inputs either variables or numbers, and is allowed to either add or multiply two expressions it ...
theory studies the
computational complexity In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations) ...
of evaluating different polynomials.


References

{{reflist Polynomials