Multipoint Evaluation of a Polynomial
Description
Given a polynomial f(x) and n points x1,x2,…,xn, compute
f(x1),f(x2),…,f(xn)
Solution
Consider using divide and conquer to halve the size of the problem.
Split the given points into two parts:
X0X1={x1,x2,…,x⌊2n⌋}={x⌊2n⌋+1,x⌊2n⌋+2,…,xn}
Construct the polynomial
g0(x)=xi∈X0∏(x−xi)
Then ∀x∈X0:g0(x)=0.
Consider expressing f(x) in the form g0(x)Q(x)+f0(x), namely:
f0(x)≡f(x)(modg0(x))
Then ∀x∈X0:f(x)=g0(x)Q(x)+f0(x)=f0(x); the same holds for X1.
The problem size has now been halved, so it can be solved with divide and conquer plus polynomial modulo.
The time complexity is
T(n)=2T(2n)+O(nlogn)=O(nlog2n)
Fast polynomial interpolation
Description
Given a set of n+1 points
X={(x0,y0),(x1,y1),…,(xn,yn)}
find an n-degree polynomial f(x) satisfying ∀(x,y)∈X:f(x)=y.
Solution
Consider the Lagrange interpolation formula
f(x)=i=1∑nj=i∏xi−xjx−xjyi
Let M(x)=∏i=1n(x−xi). By l'Hôpital's rule,
j=i∏(xi−xj)=x→xilimx−xi∏j=1n(x−xj)=M′(xi)
Therefore, the polynomial can be written as
f(x)=i=1∑nM′(xi)yij=i∏(x−xj)
We first use divide and conquer to compute the coefficient representation of M(x), then use multipoint evaluation to compute every M′(xi) in O(nlog2n) time.
Let vi=M′(xi)yi. We now compute f(x). For n=1, we have f(x)=v1,M(x)=x−x1. Otherwise, let
f0(x)M0(x)f1(x)M1(x)=i=1∑⌊2n⌋vij=i∧j≤⌊2n⌋∏(x−xj)=i=1∏⌊2n⌋(x−xi)=i=⌊2n⌋+1∑nvij=i∧⌊2n⌋<j≤n∏(x−xj)=i=⌊2n⌋+1∏n(x−xi)
Then f(x)=f0(x)M1(x)+f1(x)M0(x),M(x)=M0(x)M1(x), so divide and conquer can be used. The complexity of this part is also O(nlog2n).