shockwave-plus/shockwave_plus/src/polynomial/ml_poly.rs
shockwave_plus/src/polynomial/ml_poly.rsRaw
1use tensor_pcs::EqPoly;
2
3use crate::FieldExt;
4
5#[derive(Clone, Debug)]
6pub struct MlPoly<F> {
7 pub evals: Vec<F>,
8 pub num_vars: usize,
9}
10
11impl<F: FieldExt> MlPoly<F> {
12 pub fn new(evals: Vec<F>) -> Self {
13 assert!(evals.len().is_power_of_two());
14 let num_vars = (evals.len() as f64).log2() as usize;
15 Self { evals, num_vars }
16 }
17
18 fn dot_prod(x: &[F], y: &[F]) -> F {
19 assert_eq!(x.len(), y.len());
20 let mut result = F::ZERO;
21 for i in 0..x.len() {
22 result += x[i] * y[i];
23 }
24 result
25 }
26
27 // Evaluate the multilinear extension of the polynomial `a`, at point `t`.
28 // `a` is in evaluation form.
29 pub fn eval(&self, t: &[F]) -> F {
30 let n = self.evals.len();
31 debug_assert_eq!((n as f64).log2() as usize, t.len());
32 // Evaluate the multilinear extension of the polynomial `a`,
33 // over the boolean hypercube
34
35 let eq_evals = EqPoly::new(t.to_vec()).evals();
36
37 Self::dot_prod(&self.evals, &eq_evals)
38 }
39}