pub fn compute(points: &[F::E], values: &[F::E], field: &F) -> NewtonPolynomial<F>
    {
        assert_eq!(points.len(), values.len());

        // compute Newton coefficients
        
        let mut store: Vec<(usize, usize, F::E)> = 
            values.iter().enumerate()
            .map(|(index, value)| (index, index, value.clone()))
            .collect();

        for j in 1..store.len() {
            for i in (j..store.len()).rev() {
                let index_lower = store[i - 1].0;
                let index_upper = store[i].1;

                let point_lower = &points[index_lower];
                let point_upper = &points[index_upper];
                let point_diff = field.sub(point_upper, point_lower);
                let point_diff_inverse = field.inv(point_diff);

                let coef_lower = store[i - 1].2.clone();
                let coef_upper = store[i].2.clone();
                let coef_diff = field.sub(coef_upper, coef_lower);

                let fraction = field.mul(coef_diff, point_diff_inverse);

                store[i] = (index_lower, index_upper, fraction);
            }
        }

        let coefficients = store.into_iter().map(|(_, _, v)| v).collect();
        
        NewtonPolynomial {
            points: points.to_vec(),
            coefficients: coefficients,
        }
    }
/// General case for Newton interpolation in field Zp.
///
/// Given enough `points` (x) and `values` (p(x)), find the coefficients for `p`.
General case for Newton interpolation in field Zp.
General case for Newton interpolation in field Zp .
pub fn compute(points: &[F::E], values: &[F::E], field: &F) -> NewtonPolynomial<F>
    {
        assert_eq!(points.len(), values.len());
        // compute Newton coefficients
        let mut store: Vec<(usize, usize, F::E)> = 
            values.iter().enumerate()
            .map(|(index, value)| (index, index, value.clone()))
            .collect();
        for j in 1..store.len() {
            for i in (j..store.len()).rev() {
                let index_lower = store[i - 1].0;
                let index_upper = store[i].1;
                let point_lower = &points[index_lower];
                let point_upper = &points[index_upper];
                let point_diff = field.sub(point_upper, point_lower);
                let point_diff_inverse = field.inv(point_diff);
                let coef_lower = store[i - 1].2.clone();
                let coef_upper = store[i].2.clone();
                let coef_diff = field.sub(coef_upper, coef_lower);
                let fraction = field.mul(coef_diff, point_diff_inverse);
                store[i] = (index_lower, index_upper, fraction);
            }
        }
        let coefficients = store.into_iter().map(|(_, _, v)| v).collect();
        NewtonPolynomial {
            points: points.to_vec(),
            coefficients: coefficients,
        }
    }
pub fn compute ( points : & [ F :: E ] , values : & [ F :: E ] , field : & F ) -> NewtonPolynomial < F > { assert_eq ! ( points len ( ) values len ( ) ) ; // compute Newton coefficients let mut store : Vec < ( usize , usize , F :: E ) > = values . iter ( ) . enumerate ( ) . map ( | ( index , value ) | ( index , index , value . clone ( ) ) ) . collect ( ) ; for j in 1 .. store . len ( ) { for i in ( j .. store . len ( ) ) . rev ( ) { let index_lower = store [ i - 1 ] . 0 ; let index_upper = store [ i ] . 1 ; let point_lower = & points [ index_lower ] ; let point_upper = & points [ index_upper ] ; let point_diff = field . sub ( point_upper , point_lower ) ; let point_diff_inverse = field . inv ( point_diff ) ; let coef_lower = store [ i - 1 ] . 2 . clone ( ) ; let coef_upper = store [ i ] . 2 . clone ( ) ; let coef_diff = field . sub ( coef_upper , coef_lower ) ; let fraction = field . mul ( coef_diff , point_diff_inverse ) ; store [ i ] = ( index_lower , index_upper , fraction ) ; } } let coefficients = store . into_iter ( ) . map ( | ( _ , _ , v ) | v ) . collect ( ) ; NewtonPolynomial { points : points . to_vec ( ) , coefficients : coefficients , } }
General case for Newton interpolation in field Zp.
General case for Newton interpolation in field Zp .
points
&[F::E]
values
&[F::E]
field
&F