Enum kimchi::circuits::expr::Operations
source · pub enum Operations<T> {
Atom(T),
Pow(Box<Self>, u64),
Add(Box<Self>, Box<Self>),
Mul(Box<Self>, Box<Self>),
Sub(Box<Self>, Box<Self>),
Double(Box<Self>),
Square(Box<Self>),
Cache(CacheId, Box<Self>),
IfFeature(FeatureFlag, Box<Self>, Box<Self>),
}
Variants§
Atom(T)
Pow(Box<Self>, u64)
Add(Box<Self>, Box<Self>)
Mul(Box<Self>, Box<Self>)
Sub(Box<Self>, Box<Self>)
Double(Box<Self>)
Square(Box<Self>)
Cache(CacheId, Box<Self>)
IfFeature(FeatureFlag, Box<Self>, Box<Self>)
Implementations§
source§impl<T: Literal> Operations<T>where
T::F: Field,
impl<T: Literal> Operations<T>where T::F: Field,
source§impl<F: Field, ChallengeTerm: Copy> Operations<ConstantExprInner<F, ChallengeTerm>>
impl<F: Field, ChallengeTerm: Copy> Operations<ConstantExprInner<F, ChallengeTerm>>
source§impl<T: Literal + PartialEq> Operations<T>where
T::F: Field,
impl<T: Literal + PartialEq> Operations<T>where T::F: Field,
pub fn apply_feature_flags(&self, features: &FeatureFlags) -> Self
source§impl<C, Column> Operations<ExprInner<C, Column>>
impl<C, Column> Operations<ExprInner<C, Column>>
sourcepub fn cell(col: Column, row: CurrOrNext) -> Expr<C, Column>
pub fn cell(col: Column, row: CurrOrNext) -> Expr<C, Column>
Convenience function for constructing cell variables.
pub fn double(self) -> Self
pub fn square(self) -> Self
sourcepub fn constant(c: C) -> Expr<C, Column>
pub fn constant(c: C) -> Expr<C, Column>
Convenience function for constructing constant expressions.
sourcepub fn degree(&self, d1_size: u64, zk_rows: u64) -> u64
pub fn degree(&self, d1_size: u64, zk_rows: u64) -> u64
Return the degree of the expression.
The degree of a cell is defined by the first argument d1_size
, a
constant being of degree zero. The degree of the expression is defined
recursively using the definition of the degree of a multivariate
polynomial. The function can be (and is) used to compute the domain
size, hence the name of the first argument d1_size
.
The second parameter zk_rows
is used to define the degree of the
constructor VanishesOnZeroKnowledgeAndPreviousRows
.
source§impl<'a, F: Field, Column: PartialEq + Copy, ChallengeTerm: AlphaChallengeTerm<'a>> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
impl<'a, F: Field, Column: PartialEq + Copy, ChallengeTerm: AlphaChallengeTerm<'a>> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
sourcepub fn literal(x: F) -> Self
pub fn literal(x: F) -> Self
Convenience function for constructing expressions from literal field elements.
sourcepub fn combine_constraints(
alphas: impl Iterator<Item = u32>,
cs: Vec<Self>
) -> Self
pub fn combine_constraints( alphas: impl Iterator<Item = u32>, cs: Vec<Self> ) -> Self
Combines multiple constraints [c0, ..., cn]
into a single constraint
alpha^alpha0 * c0 + alpha^{alpha0 + 1} * c1 + ... + alpha^{alpha0 + n} * cn
.
source§impl<F: FftField, Column: Copy, ChallengeTerm: Copy> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
impl<F: FftField, Column: Copy, ChallengeTerm: Copy> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
sourcepub fn to_polish(&self) -> Vec<PolishToken<F, Column, ChallengeTerm>>
pub fn to_polish(&self) -> Vec<PolishToken<F, Column, ChallengeTerm>>
Compile an expression to an RPN expression.
source§impl<F: FftField, Column: PartialEq + Copy, ChallengeTerm: Copy> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
impl<F: FftField, Column: PartialEq + Copy, ChallengeTerm: Copy> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
sourcepub fn evaluate<'a, Evaluations: ColumnEvaluations<F, Column = Column>, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>(
&self,
d: D<F>,
pt: F,
evals: &Evaluations,
env: &Environment
) -> Result<F, ExprError<Column>>
pub fn evaluate<'a, Evaluations: ColumnEvaluations<F, Column = Column>, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>( &self, d: D<F>, pt: F, evals: &Evaluations, env: &Environment ) -> Result<F, ExprError<Column>>
Evaluate an expression as a field element against an environment.
sourcepub fn evaluate_<Evaluations: ColumnEvaluations<F, Column = Column>>(
&self,
d: D<F>,
pt: F,
evals: &Evaluations,
c: &Constants<F>,
chals: &dyn Index<ChallengeTerm, Output = F>
) -> Result<F, ExprError<Column>>
pub fn evaluate_<Evaluations: ColumnEvaluations<F, Column = Column>>( &self, d: D<F>, pt: F, evals: &Evaluations, c: &Constants<F>, chals: &dyn Index<ChallengeTerm, Output = F> ) -> Result<F, ExprError<Column>>
Evaluate an expression as a field element against the constants.
sourcepub fn evaluate_constants<'a, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>(
&self,
env: &Environment
) -> Expr<F, Column>
pub fn evaluate_constants<'a, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>( &self, env: &Environment ) -> Expr<F, Column>
Evaluate the constant expressions in this expression down into field elements.
sourcepub fn evaluations<'a, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>(
&self,
env: &Environment
) -> Evaluations<F, D<F>>
pub fn evaluations<'a, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>( &self, env: &Environment ) -> Evaluations<F, D<F>>
Compute the polynomial corresponding to this expression, in evaluation form.
The routine will first replace the constants (verifier challenges and
constants like the matrix used by Poseidon
) in the expression with their
respective values using evaluate_constants
and will after evaluate the
monomials with the corresponding column values using the method
evaluations
.
source§impl<F: FftField, Column: Copy> Operations<ExprInner<F, Column>>
impl<F: FftField, Column: Copy> Operations<ExprInner<F, Column>>
sourcepub fn evaluate<Evaluations: ColumnEvaluations<F, Column = Column>>(
&self,
d: D<F>,
pt: F,
zk_rows: u64,
evals: &Evaluations
) -> Result<F, ExprError<Column>>
pub fn evaluate<Evaluations: ColumnEvaluations<F, Column = Column>>( &self, d: D<F>, pt: F, zk_rows: u64, evals: &Evaluations ) -> Result<F, ExprError<Column>>
Evaluate an expression into a field element.
sourcepub fn evaluations<'a, ChallengeTerm, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>(
&self,
env: &Environment
) -> Evaluations<F, D<F>>
pub fn evaluations<'a, ChallengeTerm, Challenge: Index<ChallengeTerm, Output = F>, Environment: ColumnEnvironment<'a, F, ChallengeTerm, Challenge, Column = Column>>( &self, env: &Environment ) -> Evaluations<F, D<F>>
Compute the polynomial corresponding to this expression, in evaluation form.
source§impl<F: Neg<Output = F> + Clone + One + Zero + PartialEq, Column: Ord + Copy + Hash> Operations<ExprInner<F, Column>>where
ExprInner<F, Column>: Literal,
<ExprInner<F, Column> as Literal>::F: Field,
impl<F: Neg<Output = F> + Clone + One + Zero + PartialEq, Column: Ord + Copy + Hash> Operations<ExprInner<F, Column>>where ExprInner<F, Column>: Literal, <ExprInner<F, Column> as Literal>::F: Field,
sourcepub fn linearize(
&self,
evaluated: HashSet<Column>
) -> Result<Linearization<Expr<F, Column>, Column>, ExprError<Column>>
pub fn linearize( &self, evaluated: HashSet<Column> ) -> Result<Linearization<Expr<F, Column>, Column>, ExprError<Column>>
There is an optimization in PLONK called “linearization” in which a certain polynomial is expressed as a linear combination of other polynomials in order to reduce the number of evaluations needed in the IOP (by relying on the homomorphic property of the polynomial commitments used.)
The function performs this “linearization”, which we now describe in some detail.
In mathematical language, an expression e: Expr<F>
is an element of the polynomial ring F[V]
, where V
is a set of variables.
Given a subset V_0
of V
(and letting V_1 = V \setminus V_0
), there is a map
factor_{V_0}: F[V] -> (F[V_1])[V_0]
. That is, polynomials with F
coefficients in the variables V = V_0 \cup V_1
are the same thing as polynomials with F[V_1]
coefficients in variables V_0
.
There is also a function
lin_or_err : (F[V_1])[V_0] -> Result<Vec<(V_0, F[V_1])>, &str>
which checks if the given input is in fact a degree 1 polynomial in the variables V_0
(i.e., a linear combination of V_0
elements with F[V_1]
coefficients)
returning this linear combination if so.
Given an expression e
and set of columns C_0
, letting
V_0 = { Variable { col: c, row: r } | c in C_0, r in { Curr, Next } }
,
this function computes lin_or_err(factor_{V_0}(e))
, although it does not
compute it in that way. Instead, it computes it by reducing the expression into
a sum of monomials with F
coefficients, and then factors the monomials.
source§impl<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>where
F: PrimeField,
ChallengeTerm: AlphaChallengeTerm<'a>,
impl<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>where F: PrimeField, ChallengeTerm: AlphaChallengeTerm<'a>,
Trait Implementations§
source§impl<T: Literal> Add<Operations<T>> for Operations<T>where
T::F: Field,
impl<T: Literal> Add<Operations<T>> for Operations<T>where T::F: Field,
source§impl<F: Zero + Clone, Column: Clone> AddAssign<Operations<ExprInner<F, Column>>> for Expr<F, Column>where
ExprInner<F, Column>: Literal,
<ExprInner<F, Column> as Literal>::F: Field,
impl<F: Zero + Clone, Column: Clone> AddAssign<Operations<ExprInner<F, Column>>> for Expr<F, Column>where ExprInner<F, Column>: Literal, <ExprInner<F, Column> as Literal>::F: Field,
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moresource§impl<T: Clone> Clone for Operations<T>
impl<T: Clone> Clone for Operations<T>
source§fn clone(&self) -> Operations<T>
fn clone(&self) -> Operations<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: Debug> Debug for Operations<T>
impl<T: Debug> Debug for Operations<T>
source§impl<T: FormattedOutput + Clone> FormattedOutput for Operations<T>
impl<T: FormattedOutput + Clone> FormattedOutput for Operations<T>
source§impl<F, Column, ChallengeTerm> From<Operations<ConstantExprInner<F, ChallengeTerm>>> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<F, Column, ChallengeTerm> From<Operations<ConstantExprInner<F, ChallengeTerm>>> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
source§fn from(x: ConstantExpr<F, ChallengeTerm>) -> Self
fn from(x: ConstantExpr<F, ChallengeTerm>) -> Self
source§impl<T> From<T> for Operations<T>
impl<T> From<T> for Operations<T>
source§impl<T: Hash> Hash for Operations<T>
impl<T: Hash> Hash for Operations<T>
source§impl<T: Literal + Clone> Literal for Operations<T>
impl<T: Literal + Clone> Literal for Operations<T>
type F = <T as Literal>::F
fn literal(x: Self::F) -> Self
fn to_literal(self) -> Result<Self::F, Self>
fn to_literal_ref(&self) -> Option<&Self::F>
source§fn as_literal(&self, constants: &Constants<Self::F>) -> Self
fn as_literal(&self, constants: &Constants<Self::F>) -> Self
source§impl<T: Literal + PartialEq> Mul<Operations<T>> for Operations<T>where
T::F: Field,
impl<T: Literal + PartialEq> Mul<Operations<T>> for Operations<T>where T::F: Field,
source§impl<F, Column> MulAssign<Operations<ExprInner<F, Column>>> for Expr<F, Column>where
F: Zero + One + PartialEq + Clone,
Column: PartialEq + Clone,
ExprInner<F, Column>: Literal,
<ExprInner<F, Column> as Literal>::F: Field,
impl<F, Column> MulAssign<Operations<ExprInner<F, Column>>> for Expr<F, Column>where F: Zero + One + PartialEq + Clone, Column: PartialEq + Clone, ExprInner<F, Column>: Literal, <ExprInner<F, Column> as Literal>::F: Field,
source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
*=
operation. Read moresource§impl<T: PartialEq> PartialEq<Operations<T>> for Operations<T>
impl<T: PartialEq> PartialEq<Operations<T>> for Operations<T>
source§fn eq(&self, other: &Operations<T>) -> bool
fn eq(&self, other: &Operations<T>) -> bool
self
and other
values to be equal, and is used
by ==
.