Skip to main content

lagrange_coefficients

Function lagrange_coefficients 

Source
pub fn lagrange_coefficients<F: FieldNTT>(
    total: NonZeroU32,
    iter: impl IntoIterator<Item = u32>,
) -> Vec<(u32, F)>
Expand description

Compute Lagrange coefficients for interpolating a polynomial at 0 from evaluations at roots of unity.

Given a subset S of indices where we have evaluations, this computes the Lagrange coefficients needed to interpolate to 0. For each index j in S, the coefficient is L_j(0) where L_j is the Lagrange basis polynomial.

The key formula is: L_j(0) = P_Sbar(w^j) / (N * P_Sbar(0))

where P_Sbar is the (possibly scaled) vanishing polynomial over the complement (missing points), and N is the domain size. This follows from V_S(X) * V_Sbar(X) = X^N - 1, which gives V_S(0) = -1/V_Sbar(0). The scaling factor of P_Sbar cancels in the ratio.

Building P_Sbar as the vanishing polynomial over missing points is cheaper than building V_S when most points are present (the typical erasure-coding case), since |Sbar| << |S|.

§Arguments

  • total - The total number of points in the domain (rounded up to power of 2)
  • iter - Iterator of indices where we have evaluations (duplicates ignored, indices >= total ignored)

§Returns

A vector of (index, coefficient) pairs for each unique index in the input set.