@@ -2,6 +2,7 @@ use std::{collections::HashSet, ops::Div};
2
2
3
3
use p3_field:: Field ;
4
4
5
+
5
6
// https://people.inf.ethz.ch/gander/papers/changing.pdf
6
7
7
8
/// A polynomial of degree N-1
@@ -38,8 +39,7 @@ pub struct Nodes<const N: usize, F: Field>([F; N]);
38
39
/// A polynomial in monomial basis
39
40
impl < const N : usize , F : Field > Polynomial < N , Monomial , F > {
40
41
// 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 } }
43
43
/// Convert a polynomial from monomial to Lagrange basis using the Barycentric form
44
44
pub fn to_lagrange ( & self , nodes : Nodes < N , F > ) -> Polynomial < N , Lagrange < N , F > , F > {
45
45
// check that nodes are distinct
@@ -105,6 +105,7 @@ impl<const N: usize, F: Field> Polynomial<N, Lagrange<N, F>, F> {
105
105
}
106
106
107
107
pub fn to_monomial ( & self ) -> Polynomial < N , Monomial , F > {
108
+ //
108
109
// This is the inverse of the conversion from monomial to Lagrange basis
109
110
// This uses something called the Vandermonde matrix which is defined as:
110
111
//
@@ -119,22 +120,22 @@ impl<const N: usize, F: Field> Polynomial<N, Lagrange<N, F>, F> {
119
120
// where x_i are the nodes of the Lagrange basis
120
121
//
121
122
// 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
124
125
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.
127
128
// let nodes = self.basis.nodes;
128
129
// let mut evaluations = [F::zero(); N];
129
130
130
131
// // Evaluate the polynomial at N distinct points
131
132
// 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);
133
134
// evaluations[i] = self.evaluate(x);
134
135
// }
135
136
136
137
// 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 " )
138
139
}
139
140
140
141
/// Evaluate the polynomial at field element x
@@ -216,19 +217,4 @@ mod test {
216
217
let lagrange = polynomial. to_lagrange ( nodes) ;
217
218
println ! ( "lagrange coefficients {:?}" , lagrange. coefficients) ;
218
219
}
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
- }
234
220
}
0 commit comments