Lagrange Interpolation
One particularly useful property of polynomials is that a polynomial of degree is completely determined on evaluation points, which implies that we can uniquely derive a polynomial of degree from a set :
Polynomials therefore have the property that pairs of points are enough to determine the set of pairs .
If the coefficients of the polynomial we want to find have a notion of multiplicative inverse, it is always possible to find such a polynomial using a method called Lagrange Interpolation, which works as follows.

The set of polynomials is called the Lagrange basis. Each of the polynomials has degree and take values if and . Using the Kronecker delta this can be written as .
Notice that the numerator has m roots at the nodes while the denominator scales the resulting polynomial so that .
The naive implemetation of Lagrange Interpolation can be found below:
def lagrange_polynomial(evals):
Qx = QQ[x]
m = len(evals)
P = Qx(0)
for j in range(0, m):
l_j = Qx(1)
for i in range(0, m):
if i == j:
continue
l_j = l_j * Qx(x - evals[i][0]) / (evals[j][0] - evals[i][0])
P = P + l_j * evals[j][1]
return P
Sage example:
Qx = QQ[x]
Qx.lagrange_polynomial([(0, 4), (-2, 1), (2, 3)])
Last updated