Skip to content

Commit c0a4f5f

Browse files
committed
remove monomial tests till we get roots
1 parent 25194d5 commit c0a4f5f

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

src/polynomial.rs

+9-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{collections::HashSet, ops::Div};
22

33
use p3_field::Field;
44

5+
56
// https://people.inf.ethz.ch/gander/papers/changing.pdf
67

78
/// A polynomial of degree N-1
@@ -38,8 +39,7 @@ pub struct Nodes<const N: usize, F: Field>([F; N]);
3839
/// A polynomial in monomial basis
3940
impl<const N: usize, F: Field> Polynomial<N, Monomial, F> {
4041
// TODO check that the polynomial degree divides the field order
41-
pub fn new(coefficients: [F; N]) -> Self { Self { coefficients, basis: Monomial } }
42-
42+
pub fn new(coefficients: [F; N]) -> Self { Self { coefficients, basis: Monomial }}
4343
/// Convert a polynomial from monomial to Lagrange basis using the Barycentric form
4444
pub fn to_lagrange(&self, nodes: Nodes<N, F>) -> Polynomial<N, Lagrange<N, F>, F> {
4545
// check that nodes are distinct
@@ -105,6 +105,7 @@ impl<const N: usize, F: Field> Polynomial<N, Lagrange<N, F>, F> {
105105
}
106106

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

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

130131
// // Evaluate the polynomial at N distinct points
131132
// for i in 0..N {
132-
// let x = F::primitive_root().exp_u64(i as u64);
133+
// let x = F::primitive_root().exp_u64(i as u64);
133134
// evaluations[i] = self.evaluate(x);
134135
// }
135136

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

140141
/// Evaluate the polynomial at field element x
@@ -216,19 +217,4 @@ mod test {
216217
let lagrange = polynomial.to_lagrange(nodes);
217218
println!("lagrange coefficients {:?}", lagrange.coefficients);
218219
}
219-
#[test]
220-
fn lagrange_to_monomial() {
221-
let a = PlutoField::new(1);
222-
let b = PlutoField::new(2);
223-
let c = PlutoField::new(3);
224-
let polynomial =
225-
Polynomial::<3, Lagrange<3, PlutoField>, PlutoField>::new([a, b, c], [a, b, c]);
226-
let lagrange_eval = polynomial.evaluate(PlutoField::new(2));
227-
println!("lagrange coefficients {:?}", polynomial.coefficients);
228-
229-
let monomial = polynomial.to_monomial();
230-
println!("monomial coefficients {:?}", monomial.coefficients);
231-
let monomial_eval = monomial.evaluate(PlutoField::new(2));
232-
assert_eq!(lagrange_eval, monomial_eval);
233-
}
234220
}

0 commit comments

Comments
 (0)