Lagrange Interpolation

lean4-prooflinear-algebravisualization
p(x)=irijixxjxixjp(x) = \sum_{i} r_i \prod_{j \neq i} \frac{x - x_j}{x_i - x_j}

Statement

Given nn distinct nodes x0,x1,,xn1x_0, x_1, \ldots, x_{n-1} in a field FF and prescribed values r0,,rn1Fr_0, \ldots, r_{n-1} \in F, there exists a unique polynomial pF[X]p \in F[X] of degree <n< n satisfying p(xi)=rip(x_i) = r_i for all ii.

The Lagrange basis polynomial for node xix_i is

i(x)=jixxjxixj\ell_i(x) = \prod_{j \neq i} \frac{x - x_j}{x_i - x_j}

and the interpolating polynomial is

p(x)=i=0n1rii(x).p(x) = \sum_{i=0}^{n-1} r_i \,\ell_i(x).

Visualization

Interpolate through three points (0,1)(0, 1), (1,2)(1, 2), (2,5)(2, 5):

iinode xix_ivalue rir_ibasis i(x)\ell_i(x)
001(x1)(x2)(01)(02)=12(x1)(x2)\frac{(x-1)(x-2)}{(0-1)(0-2)} = \tfrac{1}{2}(x-1)(x-2)
112(x0)(x2)(10)(12)=(x)(x2)\frac{(x-0)(x-2)}{(1-0)(1-2)} = -(x)(x-2)
225(x0)(x1)(20)(21)=12x(x1)\frac{(x-0)(x-1)}{(2-0)(2-1)} = \tfrac{1}{2}x(x-1)

Summing: p(x)=12(x1)(x2)2x(x2)+52x(x1)p(x) = \tfrac{1}{2}(x-1)(x-2) - 2x(x-2) + \tfrac{5}{2}x(x-1)

Expanding term-by-term and collecting:

p(x)=x2+1p(x) = x^2 + 1

Verification: p(0)=1p(0)=1, p(1)=2p(1)=2, p(2)=5p(2)=5. Degree =2<3=n= 2 < 3 = n. Unique.

Proof Sketch

  1. Existence. Form p=iriip = \sum_i r_i \ell_i. By construction i(xj)=δij\ell_i(x_j) = \delta_{ij}, so p(xi)=rip(x_i) = r_i. Each i\ell_i has degree n1n-1, so degp<n\deg p < n.
  2. Uniqueness. Suppose qq also satisfies the conditions and degq<n\deg q < n. Then pqp - q vanishes at all nn nodes and has degree <n< n, so a polynomial of degree <n< n with nn roots must be the zero polynomial.
  3. Linear map. The assignment rinterpolate(r)r \mapsto \text{interpolate}(r) is an FF-linear map; the Lagrange basis {i}\{\ell_i\} is a basis for the space of polynomials of degree <n< n.

Connections

Lagrange interpolation generalizes Vieta's FormulasVieta's Formulasx1+x2++xn=an1anx_1 + x_2 + \cdots + x_n = -\frac{a_{n-1}}{a_n}Relating the coefficients of a polynomial to the sums and products of its rootsRead more → (which read off coefficients from roots) and underpins Taylor's TheoremTaylor's Theoremf(x)=k=0nf(k)(x0)k!(xx0)k+Rn(x)f(x) = \sum_{k=0}^{n} \frac{f^{(k)}(x_0)}{k!}(x-x_0)^k + R_n(x)Approximate smooth functions by polynomials with explicit error boundsRead more → (the limit as nodes coalesce). The uniqueness argument is the same dimension count as Rank–Nullity TheoremRank–Nullity Theoremrank(f)+nullity(f)=dimV\operatorname{rank}(f) + \operatorname{nullity}(f) = \dim VThe dimensions of image and kernel of a linear map sum to the domain dimensionRead more →.

Lean4 Proof

-- Mathlib: Mathlib.LinearAlgebra.Lagrange
-- `Lagrange.interpolate s v r` is the unique polynomial of degree < #s
-- interpolating r at the nodes v.
-- We state the two key properties: correct values and degree bound.
open Lagrange in
theorem lagrange_eval_node (F : Type*) [Field F] {ι : Type*} [DecidableEq ι]
    (s : Finset ι) (v : ι  F) (r : ι  F)
    (hvs : Set.InjOn v s) (hi :  i  s, True) (i : ι) (his : i  s) :
    (interpolate s v r).eval (v i) = r i :=
  eval_interpolate_at_node r hvs his

open Lagrange in
theorem lagrange_degree_lt (F : Type*) [Field F] {ι : Type*} [DecidableEq ι]
    (s : Finset ι) (v : ι  F) (r : ι  F) (hvs : Set.InjOn v s) :
    (interpolate s v r).degree < s.card :=
  degree_interpolate_lt r hvs