Learn / Math / Lagrange Interpolation
09. Lagrange Interpolation
Algebra for ZK · Lesson 10 of 18 · 3:33
The mechanism that turns a handful of points into a single polynomial — and the exact process a QAP uses to collapse an entire ZK circuit into one polynomial that represents it.

Every lesson so far started with a polynomial and worked outward from it — building, evaluating, combining. Today flips the problem around: given a handful of points, how do you find the one polynomial that passes through all of them? That question has a name, Lagrange interpolation, and it’s the exact mechanism that turns an entire ZK circuit into a single polynomial.

The problem

Take three points: (0,1)(0, 1), (1,2)(1, 2), and (2,5)(2, 5). What polynomial passes through all three? With exactly three points, exactly one polynomial of degree 22 fits.

(0, 1) (1, 2) (2, 5) exactly one degree-2 polynomial fits all three points
Fig. 1 — three points, and the one degree-2 polynomial that passes through all of them.

The trick: basis polynomials

The trick is to build one small helper polynomial per point — a Lagrange basis polynomial. Each one is engineered to equal 11 at its own point and 00 at every other point in the set.

A Lagrange basis polynomial

Li(x)=1 at its own point,Li(x)=0 at every other pointL_i(x) = 1 \text{ at its own point}, \quad L_i(x) = 0 \text{ at every other point}

Each basis polynomial only ever “turns on” for its own point — everywhere else, it contributes nothing.

Building one is mechanical: for every other point, multiply in a factor of (x−that point)(x - \text{that point}), then divide by whatever that same product evaluates to at your own point — which forces the result to land on exactly 11 there.

building each basis polynomial — points at x = 0, 1, 2 L₀(x) = (x−1)(x−2) / (0−1)(0−2) L₁(x) = (x−0)(x−2) / (1−0)(1−2) L₂(x) = (x−0)(x−1) / (2−0)(2−1)
Fig. 2 — the three basis polynomials for x = 0, 1, 2. Each numerator zeroes out at every point but its own.

Combining them

With all three basis polynomials built, combine them by scaling each one by its point’s yy-value and adding the results together.

The combined polynomial

P(x)=1⋅L0(x)+2⋅L1(x)+5⋅L2(x)P(x) = 1 \cdot L_0(x) + 2 \cdot L_1(x) + 5 \cdot L_2(x)

Checking this against the original points confirms it works — at each xx, exactly one basis polynomial is “on,” and it hands back exactly that point’s yy-value.

P(x) = 1·L₀ + 2·L₁ + 5·L₂ — checked at each point check x = 0 only L₀ turns on = 1 ✓ check x = 1 only L₁ turns on = 2 ✓ check x = 2 only L₂ turns on = 5 ✓ expanded out, this simplifies to P(x) = x² + 1
Fig. 3 — checking the combined polynomial at each of the three points. Only one basis polynomial ever turns on at a time.

Expanded out, all of that simplifies down to a single clean expression: P(x)=x2+1P(x) = x^2 + 1 — exactly the curve from Fig. 1.

The general formula

Nothing about this is specific to three points. The same construction works for any number of them:

Lagrange interpolation, in general

P(x)=∑iyi⋅Li(x)P(x) = \sum_i y_i \cdot L_i(x)

Sum each point’s yy-value times its own basis polynomial — that’s the entire formula, however many points there are.

Why this matters for ZK

Here’s the payoff. In a QAP — the structure behind Groth16 — every gate in a circuit becomes a point: the gate’s index paired with its value.

every circuit gate becomes a point (gate index, gate value) Lagrange interpolation → one polynomial for the whole circuit this is literally the Q in QAP — Quadratic Arithmetic Program
Fig. 4 — Lagrange interpolation turns every gate-as-a-point into one polynomial representing the whole circuit.

Lagrange interpolation takes that entire set of points and produces a single polynomial representing the whole circuit at once. This is literally what the Q in QAP stands for — Quadratic Arithmetic Program — the same idea this lesson just built from scratch, running at the scale of a real circuit.