Lagrange Interpolation #
This file defines computable Lagrange interpolation
for univariate polynomials, i.e. CPolynomials.
basisDivisor xᵢ xⱼ is the unique linear or constant computable polynomial such that
when evaluated at xᵢ it gives 1 and xⱼ it gives 0 (where when xᵢ = xⱼ it is
identically 0). Such polynomials are the building blocks for the Lagrange interpolants.
Instances For
Helpers for deferred-trim folds #
The basis product and interpolate sum below combine raw arrays with the untrimmed
Raw.mulRaw/Raw.addRaw and trim once at the end, rather than paying a trim per factor
(as Finset.prod/Finset.sum over the canonical CPolynomial.Mul/.Add instances
would). Computability requires bypassing the noncomputable Finset.toList, so the folds
go through Quotient.liftOn on the underlying multiset with a permutation-invariance
proof routed through toPoly.
Computable Lagrange basis polynomials indexed by s : Finset ι, defined at nodes x i for a
map x : ι → F. For i, j ∈ s, basis s x i evaluates to 0 at x j for i ≠ j. When
x is injective on s, basis s x i evaluates to 1 at x i.
The product folds (s.erase i).val with the untrimmed Raw.mulRaw via Quotient.liftOn
and trims once at the end, rather than paying one Raw.mul trim per factor (as the
Finset.prod formulation would).
Instances For
Interpolation sum #
The interpolate sum is folded with the untrimmed Raw.addRaw, with each addend itself
formed by Raw.mulRaw (Raw.C (y i)) (basis s x i).val (also untrimmed). One trim runs
at the end of the entire fold.
Computable Lagrange interpolation: given a finset s : Finset ι, a nodal map x : ι → F
injective on s and a value function y : ι → F, interpolate s x y is the unique computable
polynomial of degree < #s that takes value y i on x i for all i in s.
Instances For
Produces the unique polynomial of degree at most n-1 that equals r[i] at ω^i for i = 0, 1, ..., n-1.
Uses Lagrange interpolation: p(X) = Σᵢ rᵢ · Lᵢ(X) where Lᵢ(X) = ∏_{j≠i} (X - ωʲ) / (ωⁱ - ωʲ).