mirror of
https://github.com/pseXperiments/clookup.git
synced 2026-01-09 15:47:56 -05:00
Add conversion from eval form to coeff form
This commit is contained in:
@@ -1,39 +1,33 @@
|
||||
use std::fmt::Debug;
|
||||
use ff::Field;
|
||||
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// [coeff, deg(x_1), ..., deg(x_n)]
|
||||
#[derive(Debug, Clone)]
|
||||
struct Term<F: Field>(Vec<F>);
|
||||
|
||||
/// num_vars: number of variables
|
||||
/// coefficients: [[coeff, deg(x_1), ..., deg(x_n)], ...] respectively
|
||||
#[derive(Clone, Debug)]
|
||||
struct CoefficientForm<F: Field> {
|
||||
num_vars: u32,
|
||||
coefficients: Vec<Term<F>>,
|
||||
#[derive(Debug)]
|
||||
pub struct MultilinearPolynomial<F> {
|
||||
coeffs: Vec<F>,
|
||||
num_vars: usize,
|
||||
}
|
||||
|
||||
/// format: f(g(h(..)))
|
||||
/// outer: f
|
||||
/// inner: g(..)
|
||||
#[derive(Debug, Clone)]
|
||||
struct CompositionForm {
|
||||
}
|
||||
// #[derive(Debug, Clone)]
|
||||
// pub enum MultivariatePolynomial<F: Field> {
|
||||
// Coeff(CoefficientForm<F>),
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct FactoredForm<F: Field> {
|
||||
terms: Vec<Vec<Term<F>>>,
|
||||
}
|
||||
impl<F: Field> MultilinearPolynomial<F> {
|
||||
fn new(coeffs: Vec<F>, num_vars: usize) -> Self {
|
||||
MultilinearPolynomial { coeffs, num_vars }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MultivariatePolynomial<F: Field> {
|
||||
Coeff(CoefficientForm<F>),
|
||||
Comp(CompositionForm),
|
||||
Fac(FactoredForm<F>),
|
||||
}
|
||||
|
||||
impl<F: Field> MultivariatePolynomial<F> {
|
||||
fn interpolate(points: Vec<F>, k: u32) -> Self {
|
||||
todo!()
|
||||
fn eval_to_coeff(poly: &[F], num_vars: usize) -> MultilinearPolynomial<F> {
|
||||
let mut result = poly.to_vec();
|
||||
for i in (0..num_vars).rev() {
|
||||
let chunk_size = 2usize.pow((i + 1) as u32);
|
||||
for chunk_offset in (0..poly.len()).step_by(chunk_size) {
|
||||
for j in chunk_offset..(chunk_offset + chunk_size / 2) {
|
||||
result[j + chunk_size / 2] -= poly[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::new(result, num_vars)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user