Skip to content

Commit

Permalink
remove monomial tests till we get roots
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJepsen committed May 2, 2024
1 parent 25194d5 commit c0a4f5f
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{collections::HashSet, ops::Div};

use p3_field::Field;


// https://people.inf.ethz.ch/gander/papers/changing.pdf

/// A polynomial of degree N-1
Expand Down Expand Up @@ -38,8 +39,7 @@ pub struct Nodes<const N: usize, F: Field>([F; N]);
/// A polynomial in monomial basis
impl<const N: usize, F: Field> Polynomial<N, Monomial, F> {
// TODO check that the polynomial degree divides the field order
pub fn new(coefficients: [F; N]) -> Self { Self { coefficients, basis: Monomial } }

pub fn new(coefficients: [F; N]) -> Self { Self { coefficients, basis: Monomial }}
/// Convert a polynomial from monomial to Lagrange basis using the Barycentric form
pub fn to_lagrange(&self, nodes: Nodes<N, F>) -> Polynomial<N, Lagrange<N, F>, F> {
// check that nodes are distinct
Expand Down Expand Up @@ -105,6 +105,7 @@ impl<const N: usize, F: Field> Polynomial<N, Lagrange<N, F>, F> {
}

pub fn to_monomial(&self) -> Polynomial<N, Monomial, F> {
//
// This is the inverse of the conversion from monomial to Lagrange basis
// This uses something called the Vandermonde matrix which is defined as:
//
Expand All @@ -119,22 +120,22 @@ impl<const N: usize, F: Field> Polynomial<N, Lagrange<N, F>, F> {
// where x_i are the nodes of the Lagrange basis
//
// Then the monomial basis m is given V^T * l = m, where l is the Lagrange basis
// because we know the monomial basis we need to compute to monomial coefficients a_m = V^{-1} *
// a_l where a_l are the coefficients of the Lagrange basis
// because we know the monomial basis we need to compute to monomial coefficients a_m = V^{-1} * a_l
// where a_l are the coefficients of the Lagrange basis

// It also is the case that the the columns of the inverse matrix are the coefficients of the
// Lagrange polynomial basis TODO Finish this.
// It also is the case that the the columns of the inverse matrix are the coefficients of the Lagrange polynomial basis
// TODO Finish this.
// let nodes = self.basis.nodes;
// let mut evaluations = [F::zero(); N];

// // Evaluate the polynomial at N distinct points
// for i in 0..N {
// let x = F::primitive_root().exp_u64(i as u64);
// let x = F::primitive_root().exp_u64(i as u64);
// evaluations[i] = self.evaluate(x);
// }

// Polynomial::<N, Monomial, F>::new(evaluations)
todo!("Finish this after we get the roots of unity from other PR")
todo!("Finish this after we get the roots of unity from other PRs")
}

/// Evaluate the polynomial at field element x
Expand Down Expand Up @@ -216,19 +217,4 @@ mod test {
let lagrange = polynomial.to_lagrange(nodes);
println!("lagrange coefficients {:?}", lagrange.coefficients);
}
#[test]
fn lagrange_to_monomial() {
let a = PlutoField::new(1);
let b = PlutoField::new(2);
let c = PlutoField::new(3);
let polynomial =
Polynomial::<3, Lagrange<3, PlutoField>, PlutoField>::new([a, b, c], [a, b, c]);
let lagrange_eval = polynomial.evaluate(PlutoField::new(2));
println!("lagrange coefficients {:?}", polynomial.coefficients);

let monomial = polynomial.to_monomial();
println!("monomial coefficients {:?}", monomial.coefficients);
let monomial_eval = monomial.evaluate(PlutoField::new(2));
assert_eq!(lagrange_eval, monomial_eval);
}
}

0 comments on commit c0a4f5f

Please sign in to comment.