mirror of
https://github.com/pseXperiments/clookup.git
synced 2026-01-10 08:08:11 -05:00
Fix structure of polynomial
This commit is contained in:
@@ -1 +1,22 @@
|
||||
use ff::Field;
|
||||
use crate::utils::{ProtocolError, TWO, log};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Table<F: Field> {
|
||||
table: Vec<F>,
|
||||
/// Table size should be 2^k
|
||||
/// pow_vars = k
|
||||
exp_vars: u32
|
||||
}
|
||||
|
||||
impl<F: Field> TryFrom<Vec<F>> for Table<F> {
|
||||
type Error = ProtocolError;
|
||||
fn try_from(table: Vec<F>) -> Result<Self, Self::Error> {
|
||||
let exp_vars = log(table.len());
|
||||
if TWO.pow(exp_vars) != table.len() {
|
||||
Err(ProtocolError::SizeError)
|
||||
} else {
|
||||
Ok(Self { table, exp_vars })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,39 @@
|
||||
use std::fmt::Debug;
|
||||
use ff::Field;
|
||||
|
||||
// These are different form of multivariate polynomial
|
||||
pub mod coefficient;
|
||||
pub mod factored;
|
||||
pub mod composition;
|
||||
/// [coeff, deg(x_1), ..., deg(x_n)]
|
||||
#[derive(Debug, Clone)]
|
||||
struct Term<F: Field>(Vec<F>);
|
||||
|
||||
pub trait MultivariatePolynomial<F: Field>: Clone + Debug {
|
||||
fn interpolate(points: Vec<F>) -> Self;
|
||||
/// 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>>,
|
||||
}
|
||||
|
||||
/// format: f(g(h(..)))
|
||||
/// outer: f
|
||||
/// inner: g(..)
|
||||
#[derive(Debug, Clone)]
|
||||
struct CompositionForm {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct FactoredForm<F: Field> {
|
||||
terms: Vec<Vec<Term<F>>>,
|
||||
}
|
||||
|
||||
#[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!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
use ff::Field;
|
||||
|
||||
use crate::poly::Polynomial;
|
||||
use crate::utils::*;
|
||||
|
||||
use super::MultivariatePolynomial;
|
||||
|
||||
const TWO: usize = 2;
|
||||
|
||||
/// num_vars: number of variables
|
||||
/// coefficients: [[coeff, deg(x_1), ..., deg(x_n)], ...] respectively
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CoefficientForm<F: Field> {
|
||||
num_vars: u32,
|
||||
coefficients: Vec<F>,
|
||||
}
|
||||
|
||||
impl<F: Field> Polynomial<F> for CoefficientForm<F> {
|
||||
type Point = Vec<F>;
|
||||
|
||||
fn evaluate(&self, point: &Self::Point) -> F {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: Field> MultivariatePolynomial<F> for CoefficientForm<F> {
|
||||
fn interpolate(points: Vec<F>) -> Self {
|
||||
let num_vars = log(points.len());
|
||||
// TODO: interpolation can be done with 2^k values
|
||||
assert_eq!(TWO.pow(num_vars), points.len());
|
||||
|
||||
Self { num_vars, coefficients: () }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
pub const TWO: usize = 2;
|
||||
pub enum ProtocolError {
|
||||
SizeError,
|
||||
}
|
||||
|
||||
pub fn log(n: usize) -> u32 {
|
||||
let mut k = 0;
|
||||
let mut m = n;
|
||||
|
||||
Reference in New Issue
Block a user