Lagrange interpolation: turning points into a polynomial
1. What is a polynomial?
A polynomial is an expression built from a variable , using only addition, multiplication, and non-negative integer exponents:
The degree is the highest power of . The example above is degree 2 (quadratic) because is the highest term. Some more examples:
- - degree 3 (cubic)
- - degree 1 (linear)
- - degree 0 (constant)
Why does have no on the last term? Because is really , and for any value of . Every polynomial has an implicit on its constant term - we just don't write it.
The general form of a degree- polynomial:
where are constants called coefficients.
2. The setup: points on a graph
You have three data points - expressed as inputs and outputs of some unknown function:
How many polynomials pass through these points? Through a single point, infinitely many curves fit - constants, lines, parabolas, cubics. Add a second point and you rule out some of them, but many still work. A result in algebra called the unisolvence theorem tells us that points pin down exactly one polynomial of degree at most :
- 1 point - exactly one degree-0 polynomial (a constant)
- 2 points - exactly one degree-1 polynomial (a line)
- 3 points - exactly one degree-2 polynomial (a parabola)
For our three points, that unique parabola is . No lower-degree polynomial (a line, a constant) can pass through all three - this is the lowest-degree polynomial that fits.
Finding that polynomial is called interpolation. One way to do it: set up a system of equations. Plug each point into :
Subtract the first equation from the second: . Subtract the second from the third: . Subtract those two results: , so . Back-substitute: , . The answer is .
It works, but it's slow and repetitive - three equations for three points, and it only gets worse as you add more. Joseph-Louis Lagrange found a much more elegant way.
This matters because ZK proof systems encode computation as polynomials - a prover's data becomes evaluations of a polynomial, and Lagrange interpolation is how that happens. But for now, let's focus purely on the math.
3. Lagrange's approach: basis polynomials
We still have the same three points: , , . In section 2 we found the polynomial by setting up equations and solving for coefficients. Lagrange's approach reaches the same answer with a completely different method.
The goal: three basis polynomials
Our three x-values are . Lagrange's idea: build three basis polynomials, one for each x-value. Each one equals 1 at its own x-value and 0 at the other two. We'll call them , , .
- should equal 1 at , and zero at and .
How do we build it? The expression equals zero when . The expression equals zero when . Multiply them together:
Anything times zero is zero, so this product is zero at both and - exactly where we need zeros. But what does it give at ?
We got 2, but we need 1. So we divide the whole thing by 2:
Verify: , , . Exactly what we need.
If you expand , you get - a polynomial just like in section 1. But the factored form is the point: it makes the zeros and the normalization obvious.
- should equal 1 at , and zero at and .
Same recipe. We need zeros at and , so use factors . Evaluate at : . Divide by :
- should equal 1 at , and zero at and .
Factors . Evaluate at : . Divide by 2:
Each polynomial equals 1 at one x-value and 0 at the others:
Why 1 matters
The number 1 is a neutral multiplier: . Since , we can multiply by any y-value and deliver it exactly:
And since is 0 at the other x-values, those stay zero:
So gives us exactly 2 at and contributes nothing at the other points. Where does the 2 come from? It's the y-value of our first data point: .
Combining them
Do the same for each data point. Multiply each by the y-value of that point and add them up. The y-values come from our data points: , , .
Check at each point:
All three data points are hit. Each delivers its y-value to the right place and contributes nothing elsewhere.
In general, for points the -th basis polynomial is:
The symbol means "multiply all these together" - like a for loop that multiplies instead of adding. In pseudocode:
function basis(i, x, points):
result = 1
for j = 1 to n:
if j != i:
result = result * (x - points[j].x) / (points[i].x - points[j].x)
return result
The loop skips and multiplies one fraction per remaining point. The numerator creates a zero at ; the denominator normalizes to 1 at .
4. The interpolating polynomial
Section 3 built the result for three specific points. The general formula for any set of points:
The symbol means "add all these together" - like a for loop that adds. In pseudocode:
function interpolate(x, points):
result = 0
for i = 1 to n:
result = result + points[i].y * basis(i, x, points)
return result
The loop goes through each data point, computes its basis polynomial at , multiplies by the y-value, and adds it to the total.
This is Lagrange interpolation. Given any set of points, this formula produces the unique polynomial that passes through all of them. No guessing, no solving equations. You just plug in your points and get the polynomial directly. Every point contributes exactly its y-value at the right place and nothing elsewhere.
Result: From three basis polynomials , , and three data points , , , we combined them into a weighted sum:
This is the unique polynomial that passes through all three points. Each basis polynomial carried one y-value to the right place. The weighted sum produced one new polynomial out of three building blocks.
One property to keep in mind: change any single data point and the entire polynomial changes. Every point influences every part of the result. This sensitivity is what makes polynomials useful for encoding computation - any error in the input propagates through the entire polynomial.
5. Why ZK cares
In a ZK proof, the prover encodes their computation as evaluations of a polynomial. The computation produces some set of values at specific points - Lagrange interpolation is how those values become a polynomial.
The verifier never sees the full polynomial. They see a commitment (a locked-down version of it) and check a few evaluations. The fact that there's exactly one polynomial through any set of points is what makes this work - if the prover's polynomial passes through the right values, it must be the right polynomial.
Further resources
- Lagrange Interpolation Calculator - plug in your own points and see the polynomial step by step
- Polynomial interpolation - Wikipedia