pub type Expr<C, Column> = Operations<ExprInner<C, Column>>;
Expand description
An multi-variate polynomial over the base ring C
with
variables
Cell(v)
forv : Variable
- VanishesOnZeroKnowledgeAndPreviousRows
- UnnormalizedLagrangeBasis(i) for
i : i32
This represents a PLONK “custom constraint”, which enforces that the corresponding combination of the polynomials corresponding to the above variables should vanish on the PLONK domain.
Implementations§
source§impl<C, Column> Expr<C, Column>
impl<C, Column> Expr<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>> Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<'a, F: Field, Column: PartialEq + Copy, ChallengeTerm: AlphaChallengeTerm<'a>> Expr<ConstantExpr<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> Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<F: FftField, Column: Copy, ChallengeTerm: Copy> Expr<ConstantExpr<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> Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<F: FftField, Column: PartialEq + Copy, ChallengeTerm: Copy> Expr<ConstantExpr<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> Expr<F, Column>
impl<F: FftField, Column: Copy> Expr<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> Expr<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> Expr<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> Expr<ConstantExpr<F, ChallengeTerm>, Column>where
F: PrimeField,
ChallengeTerm: AlphaChallengeTerm<'a>,
impl<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> Expr<ConstantExpr<F, ChallengeTerm>, Column>where F: PrimeField, ChallengeTerm: AlphaChallengeTerm<'a>,
Trait Implementations§
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<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> Display for Expr<ConstantExpr<F, ChallengeTerm>, Column>where
F: PrimeField,
ChallengeTerm: AlphaChallengeTerm<'a>,
impl<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> Display for Expr<ConstantExpr<F, ChallengeTerm>, Column>where F: PrimeField, ChallengeTerm: AlphaChallengeTerm<'a>,
source§impl<F> ExprOps<F, BerkeleyChallengeTerm> for Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>where
F: PrimeField,
Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>: Display,
impl<F> ExprOps<F, BerkeleyChallengeTerm> for Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>where F: PrimeField, Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column>: Display,
source§fn two_to_limb() -> Self
fn two_to_limb() -> Self
source§fn two_to_2limb() -> Self
fn two_to_2limb() -> Self
source§fn two_to_3limb() -> Self
fn two_to_3limb() -> Self
fn witness(row: CurrOrNext, col: usize, _: Option<&ArgumentData<F>>) -> Self
source§fn constant(
expr: ConstantExpr<F, BerkeleyChallengeTerm>,
_: Option<&ArgumentData<F>>
) -> Self
fn constant( expr: ConstantExpr<F, BerkeleyChallengeTerm>, _: Option<&ArgumentData<F>> ) -> Self
source§impl<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> FormattedOutput for Expr<ConstantExpr<F, ChallengeTerm>, Column>where
F: PrimeField,
ChallengeTerm: AlphaChallengeTerm<'a>,
impl<'a, F, Column: FormattedOutput + Debug + Clone, ChallengeTerm> FormattedOutput for Expr<ConstantExpr<F, ChallengeTerm>, Column>where F: PrimeField, ChallengeTerm: AlphaChallengeTerm<'a>,
source§fn ocaml(
&self,
cache: &mut HashMap<CacheId, Expr<ConstantExpr<F, ChallengeTerm>, Column>>
) -> String
fn ocaml( &self, cache: &mut HashMap<CacheId, Expr<ConstantExpr<F, ChallengeTerm>, Column>> ) -> String
Converts the expression in OCaml code
Recursively print the expression,
except for the cached expression that are stored in the cache
.
source§fn text(
&self,
cache: &mut HashMap<CacheId, Expr<ConstantExpr<F, ChallengeTerm>, Column>>
) -> String
fn text( &self, cache: &mut HashMap<CacheId, Expr<ConstantExpr<F, ChallengeTerm>, Column>> ) -> String
Recursively print the expression,
except for the cached expression that are stored in the cache
.
fn is_alpha(&self) -> bool
fn latex( &self, cache: &mut HashMap<CacheId, Expr<ConstantExpr<F, ChallengeTerm>, Column>> ) -> String
source§impl<'a, F, Column, ChallengeTerm: AlphaChallengeTerm<'a>> From<ChallengeTerm> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<'a, F, Column, ChallengeTerm: AlphaChallengeTerm<'a>> From<ChallengeTerm> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
source§impl<'a, F, Column, ChallengeTerm: AlphaChallengeTerm<'a>> From<ConstantTerm<F>> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<'a, F, Column, ChallengeTerm: AlphaChallengeTerm<'a>> From<ConstantTerm<F>> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
source§fn from(x: ConstantTerm<F>) -> Self
fn from(x: ConstantTerm<F>) -> Self
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<'a, F: Field, Column, ChallengeTerm: AlphaChallengeTerm<'a>> From<u64> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<'a, F: Field, Column, ChallengeTerm: AlphaChallengeTerm<'a>> From<u64> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
source§impl<'a, F: Field, Column: PartialEq + Copy, ChallengeTerm: AlphaChallengeTerm<'a>> Mul<F> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
impl<'a, F: Field, Column: PartialEq + Copy, ChallengeTerm: AlphaChallengeTerm<'a>> Mul<F> for Expr<ConstantExpr<F, ChallengeTerm>, Column>
§type Output = Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
type Output = Operations<ExprInner<Operations<ConstantExprInner<F, ChallengeTerm>>, Column>>
*
operator.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 more