◄ WORLD V · SONNY 5DART 100 · a helldive at the net

LAGRANGE the one curve through your points

Given n points, there is exactly one polynomial of degree at most n−1 through them all — and Lagrange writes it down directly, as a blend of basis polynomials each worth 1 at its own point and 0 at the others. It is the engine behind Shamir’s secret sharing (dart 097), numerical integration, and every “connect the dots” smoothly.

THE TECHNIQUE basis polynomials that are 1 here, 0 there

For each point i build Lᵢ(x) = the product ∏(x−xⱼ)/(xᵢ−xⱼ) over the other points — it is 1 at xᵢ and 0 at every other node. The interpolant is Σ yᵢ Lᵢ(x): it hits each yᵢ because only that basis is alive there. Drag the points; the curve follows. live demo

HISTORY & CREDIT Waring had it first

“Lagrange’s formula, 1795” — Waring published it in 1779, and Euler in 1783; Lagrange was first third. cited

~1675 · Isaac Newton — divided differences give the same interpolating polynomial in a form better for adding points incrementally.
1779 · Edward Waring publishes the barycentric/Lagrange formula — 16 years before Lagrange.
1783 / 1795 · Euler and then Joseph-Louis Lagrange restate it; Lagrange’s clean presentation is what stuck to the name.
the caution · high-degree interpolation on evenly spaced points oscillates wildly at the ends (Runge’s phenomenon) — more points is not always better.

The exact same formula, over a finite field, is how Shamir’s shares (097) rebuild a secret. Waring 1779 / Lagrange 1795

RECOMMEND FOR I-13 multiply, divide, add

Evaluating the interpolant at a target is pure f64 arithmetic — and it reproduces the underlying polynomial exactly:

$ i13 run lag.i13 # points (0,1) (1,3) (2,7), evaluate at x=3 L0=1 L1=-3 L2=3 -> P(3) = 13 # = 3^2+3+1, the quadratic it sampled
Recommend: nothing newΣ yᵢ ∏(x−xⱼ)/(xᵢ−xⱼ) is multiply / divide / add, so it runs directly (verified P(3)=13). It is the exact engine behind Shamir (097).
Note: the one wall is Shamir’s, not Lagrange’s — “over a field” means exact modular integers (GF(p)), which f64 cannot hold, so the cryptographic version needs bignum; the real-number interpolation here is pure f64.