From c0a4f5fe03406c223b45d1e321efca7b3a6b7616 Mon Sep 17 00:00:00 2001 From: Waylon Jepsen <57912727+0xJepsen@users.noreply.github.com> Date: Thu, 2 May 2024 16:52:52 -0700 Subject: [PATCH] remove monomial tests till we get roots --- src/polynomial.rs | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/polynomial.rs b/src/polynomial.rs index 03a9efe9..40d5e6a2 100644 --- a/src/polynomial.rs +++ b/src/polynomial.rs @@ -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 @@ -38,8 +39,7 @@ pub struct Nodes([F; N]); /// A polynomial in monomial basis impl Polynomial { // 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) -> Polynomial, F> { // check that nodes are distinct @@ -105,6 +105,7 @@ impl Polynomial, F> { } pub fn to_monomial(&self) -> Polynomial { + // // This is the inverse of the conversion from monomial to Lagrange basis // This uses something called the Vandermonde matrix which is defined as: // @@ -119,22 +120,22 @@ impl Polynomial, 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::::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 @@ -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); - } }