Skip to content

Commit

Permalink
MVPoly: make the expression generic over the challenge term
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Oct 14, 2024
1 parent 808f4be commit a35fa79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
7 changes: 2 additions & 5 deletions mvpoly/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::collections::HashMap;

use ark_ff::PrimeField;
use kimchi::circuits::{
berkeley_columns::BerkeleyChallengeTerm,
expr::{ConstantExpr, Expr},
};
use kimchi::circuits::expr::{ConstantExpr, Expr};
use rand::RngCore;

pub mod monomials;
Expand Down Expand Up @@ -73,7 +70,7 @@ pub trait MVPoly<F: PrimeField, const N: usize, const D: usize>:
/// "the expression framework".
/// In the near future, the "expression framework" should be moved also into
/// this library.
fn from_expr<Column: Into<usize>>(expr: Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>) -> Self;
fn from_expr<Column: Into<usize>, ChallengeTerm: Clone>(expr: Expr<ConstantExpr<F, ChallengeTerm>, Column>) -> Self;

/// Returns true if the polynomial is homogeneous (of degree `D`).
/// As a reminder, a polynomial is homogeneous if all its monomials have the
Expand Down
9 changes: 3 additions & 6 deletions mvpoly/src/monomials.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use ark_ff::{One, PrimeField, Zero};
use kimchi::circuits::{
berkeley_columns::BerkeleyChallengeTerm,
expr::{ConstantExpr, Expr},
};
use kimchi::circuits::expr::{ConstantExpr, Expr};
use num_integer::binomial;
use rand::RngCore;
use std::{
Expand Down Expand Up @@ -432,8 +429,8 @@ impl<const N: usize, const D: usize, F: PrimeField> MVPoly<F, N, D> for Sparse<F

// FIXME: use a better implementation, this is a temporary (working but not
// efficient) solution
fn from_expr<Column: Into<usize>>(
expr: Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>,
fn from_expr<Column: Into<usize>, ChallengeTerm: Clone>(
expr: Expr<ConstantExpr<F, ChallengeTerm>, Column>,
) -> Self {
prime::Dense::from_expr(expr).into()
}
Expand Down
36 changes: 10 additions & 26 deletions mvpoly/src/prime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ use std::{

use ark_ff::{One, PrimeField, Zero};
use kimchi::circuits::{
berkeley_columns::BerkeleyChallengeTerm,
expr::{ConstantExpr, ConstantExprInner, ConstantTerm, Expr, ExprInner, Operations, Variable},
gate::CurrOrNext,
};
Expand Down Expand Up @@ -328,8 +327,8 @@ impl<F: PrimeField, const N: usize, const D: usize> MVPoly<F, N, D> for Dense<F,
})
}

fn from_expr<Column: Into<usize>>(
expr: Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>,
fn from_expr<Column: Into<usize>, ChallengeTerm: Clone>(
expr: Expr<ConstantExpr<F, ChallengeTerm>, Column>,
) -> Self {
use kimchi::circuits::expr::Operations::*;

Expand Down Expand Up @@ -805,28 +804,13 @@ impl<F: PrimeField, const N: usize, const D: usize> From<F> for Dense<F, N, D> {
}
}

impl<F: PrimeField, const N: usize, const D: usize>
From<ConstantExprInner<F, BerkeleyChallengeTerm>> for Dense<F, N, D>
impl<F: PrimeField, const N: usize, const D: usize, ChallengeTerm>
From<ConstantExprInner<F, ChallengeTerm>> for Dense<F, N, D>
{
fn from(expr: ConstantExprInner<F, BerkeleyChallengeTerm>) -> Self {
fn from(expr: ConstantExprInner<F, ChallengeTerm>) -> Self {
match expr {
// The unimplemented methods might be implemented in the future if
// we move to the challenge into the type of the constant
// terms/expressions
// Unrolling for visibility
ConstantExprInner::Challenge(BerkeleyChallengeTerm::Alpha) => {
unimplemented!("The challenge alpha is not supposed to be used in this context")
}
ConstantExprInner::Challenge(BerkeleyChallengeTerm::Beta) => {
unimplemented!("The challenge beta is not supposed to be used in this context")
}
ConstantExprInner::Challenge(BerkeleyChallengeTerm::Gamma) => {
unimplemented!("The challenge gamma is not supposed to be used in this context")
}
ConstantExprInner::Challenge(BerkeleyChallengeTerm::JointCombiner) => {
unimplemented!(
"The challenge joint combiner is not supposed to be used in this context"
)
ConstantExprInner::Challenge(_) => {
unimplemented!("Challenges are not supposed to be used in this context for now")
}
ConstantExprInner::Constant(ConstantTerm::EndoCoefficient) => {
unimplemented!(
Expand All @@ -844,10 +828,10 @@ impl<F: PrimeField, const N: usize, const D: usize>
}
}

impl<F: PrimeField, const N: usize, const D: usize>
From<Operations<ConstantExprInner<F, BerkeleyChallengeTerm>>> for Dense<F, N, D>
impl<F: PrimeField, const N: usize, const D: usize, ChallengeTerm: Clone>
From<Operations<ConstantExprInner<F, ChallengeTerm>>> for Dense<F, N, D>
{
fn from(op: Operations<ConstantExprInner<F, BerkeleyChallengeTerm>>) -> Self {
fn from(op: Operations<ConstantExprInner<F, ChallengeTerm>>) -> Self {
use kimchi::circuits::expr::Operations::*;
match op {
Atom(op_const) => Self::from(op_const),
Expand Down

0 comments on commit a35fa79

Please sign in to comment.