../../.cargo/katex-header.html

Function winter_math::polynom::interpolate

source ·
pub fn interpolate<E>(xs: &[E], ys: &[E], remove_leading_zeros: bool) -> Vec<E>
where E: FieldElement,
Expand description

Returns a polynomial in coefficient form interpolated from a set of X and Y coordinates.

Uses Lagrange interpolation to build a polynomial from X and Y coordinates. If remove_leading_zeros = true, all leading coefficients which are ZEROs will be truncated; otherwise, the length of result will be equal to the number of X coordinates.

§Panics

Panics if number of X and Y coordinates is not the same.

§Example

let xs: Vec<BaseElement> = rand_vector(16);
let ys: Vec<BaseElement> = rand_vector(16);

let p = interpolate(&xs, &ys, false);
assert_eq!(ys, eval_many(&p, &xs));