Lagrange interpolation #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Main definitions #
- In everything that follows,
s : finset ι
is a finite set of indexes, withv : ι → F
an indexing of the field over some type. We call the image of v on s the interpolation nodes, though strictly unique nodes are only defined when v is injective on s. lagrange.basis_divisor x y
, withx y : F
. These are the normalised irreducible factors of the Lagrange basis polynomials. They evaluate to1
atx
and0
aty
whenx
andy
are distinct.lagrange.basis v i
withi : ι
: the Lagrange basis polynomial that evaluates to1
atv i
and0
atv j
fori ≠ j
.lagrange.interpolate v r
wherer : ι → F
is a function from the fintype to the field: the Lagrange interpolant that evaluates tor i
atx i
for alli : ι
. Ther i
are the values associated with the nodesx i
.lagrange.interpolate_at v f
, wherev : ι ↪ F
andι
is a fintype, andf : F → F
is a function from the field to itself: this is the Lagrange interpolant that evaluates tof (x i)
atx i
, and so approximates the functionf
. This is just a special case of the general interpolation, where the values are given by a known functionf
.
basis_divisor x y
is the unique linear or constant polynomial such that
when evaluated at x
it gives 1
and y
it gives 0
(where when x = y
it is identically 0
).
Such polynomials are the building blocks for the Lagrange interpolants.
Equations
- lagrange.basis_divisor x y = ⇑polynomial.C (x - y)⁻¹ * (polynomial.X - ⇑polynomial.C y)
Lagrange basis polynomials indexed by s : finset ι
, defined at nodes v i
for a
map v : ι → F
. For i, j ∈ s
, basis s v i
evaluates to 0 at v j
for i ≠ j
. When
v
is injective on s
, basis s v i
evaluates to 1 at v i
.
Equations
- lagrange.basis s v i = (s.erase i).prod (λ (j : ι), lagrange.basis_divisor (v i) (v j))
Lagrange interpolation: given a finset s : finset ι
, a nodal map v : ι → F
injective on
s
and a value function r : ι → F
, interpolate s v r
is the unique
polynomial of degree < s.card
that takes value r i
on v i
for all i
in s
.
Equations
- lagrange.interpolate s v = {to_fun := λ (r : ι → F), s.sum (λ (i : ι), ⇑polynomial.C (r i) * lagrange.basis s v i), map_add' := _, map_smul' := _}
This is the characteristic property of the interpolation: the interpolation is the
unique polynomial of degree < fintype.card ι
which takes the value of the r i
on the v i
.
Lagrange interpolation induces isomorphism between functions from s
and polynomials of degree less than fintype.card ι
.
Equations
- lagrange.fun_equiv_degree_lt hvs = {to_fun := λ (f : ↥(polynomial.degree_lt F s.card)) (i : ↥s), polynomial.eval (v ↑i) f.val, map_add' := _, map_smul' := _, inv_fun := λ (r : ↥s → F), ⟨⇑(lagrange.interpolate s v) (λ (x : ι), dite (x ∈ s) (λ (hx : x ∈ s), r ⟨x, hx⟩) (λ (hx : x ∉ s), 0)), _⟩, left_inv := _, right_inv := _}
nodal s v
is the unique monic polynomial whose roots are the nodes defined by v
and s
.
That is, the roots of nodal s v
are exactly the image of v
on s
,
with appropriate multiplicity.
We can use nodal
to define the barycentric forms of the evaluated interpolant.
Equations
- lagrange.nodal s v = s.prod (λ (i : ι), polynomial.X - ⇑polynomial.C (v i))
This defines the nodal weight for a given set of node indexes and node mapping function v
.
This is the first barycentric form of the Lagrange interpolant.
This is the second barycentric form of the Lagrange interpolant.