pub struct Expression<F> {
pub mul_terms: Vec<(F, Witness, Witness)>,
pub linear_combinations: Vec<(F, Witness)>,
pub q_c: F,
}Expand description
An expression representing a quadratic polynomial.
This struct is primarily used to express arithmetic relations between variables. It includes multiplication terms, linear combinations, and a constant term.
§Addition polynomial
- Unlike standard plonk constraints with fixed wire assignments (wL, wR, wO), we allow arbitrary fan-in and fan-out. This means we need a more flexible representation and we need more than wL, wR, and wO.
- When looking at the quotient polynomial for the assert-zero opcode in standard plonk,
you can interpret the structure in two ways:
- Fan-in 2 and fan-out 1
- Fan-in 1 and fan-out 2
§Multiplication polynomial
- If we were allow the degree of the quotient polynomial to be arbitrary, then we will need a vector of wire values.
Fields§
§mul_terms: Vec<(F, Witness, Witness)>Collection of multiplication terms.
To avoid having to create intermediate variables pre-optimization We collect all of the multiplication terms in the assert-zero opcode A multiplication term is of the form q_M * wL * wR Hence this vector represents the following sum: q_M1 * wL1 * wR1 + q_M2 * wL2 * wR2 + .. +
linear_combinations: Vec<(F, Witness)>Collection of linear terms in the expression.
Each term follows the form: q_L * w, where q_L is a coefficient
and w is a witness.
q_c: FA constant term in the expression
Implementations§
Source§impl<F> Expression<F>
impl<F> Expression<F>
Sourcepub fn num_mul_terms(&self) -> usize
pub fn num_mul_terms(&self) -> usize
Returns the number of multiplication terms
Sourcepub fn push_addition_term(&mut self, coefficient: F, variable: Witness)
pub fn push_addition_term(&mut self, coefficient: F, variable: Witness)
Adds a new linear term to the Expression.
Sourcepub fn push_multiplication_term(
&mut self,
coefficient: F,
lhs: Witness,
rhs: Witness,
)
pub fn push_multiplication_term( &mut self, coefficient: F, lhs: Witness, rhs: Witness, )
Adds a new quadratic term to the Expression.
Sourcepub fn is_const(&self) -> bool
pub fn is_const(&self) -> bool
Returns true if the expression represents a constant polynomial.
Examples:
- f(x,y) = x + y would return false
- f(x,y) = xy would return false, the degree here is 2
- f(x,y) = 5 would return true, the degree is 0
Sourcepub fn to_const(&self) -> Option<&F>
pub fn to_const(&self) -> Option<&F>
Returns a FieldElement if the expression represents a constant polynomial.
Otherwise returns None.
Examples:
- f(x,y) = x would return
None - f(x,y) = x + 6 would return
None - f(x,y) = 2*y + 6 would return
None - f(x,y) = x + y would return
None - f(x,y) = 5 would return
FieldElement(5)
Sourcepub fn is_linear(&self) -> bool
pub fn is_linear(&self) -> bool
Returns true if highest degree term in the expression is one or less.
mul_termin an expression contains degree-2 termslinear_combinationscontains degree-1 terms
Hence, it is sufficient to check that there are no mul_terms
Examples:
- f(x,y) = x + y would return true
- f(x,y) = xy would return false, the degree here is 2
- f(x,y) = 0 would return true, the degree is 0
Sourcepub fn is_degree_one_univariate(&self) -> bool
pub fn is_degree_one_univariate(&self) -> bool
Returns true if the expression can be seen as a degree-1 univariate polynomial
mul_termsin an expression can be univariate, however unless the coefficient is zero, it is always degree-2.linear_combinationscontains the sum of degree-1 terms, these terms do not need to contain the same variable and so it can be multivariate. However, we have thus far only checked iflinear_combinationscontains one term, so this method will return false, if theExpressionhas not been simplified.
Hence, we check in the simplest case if an expression is a degree-1 univariate,
by checking if it contains no mul_terms and it contains one linear_combination term.
Examples:
- f(x,y) = x would return true
- f(x,y) = x + 6 would return true
- f(x,y) = 2*y + 6 would return true
- f(x,y) = x + y would return false
- f(x,y) = x + x should return true, but we return false *** (we do not simplify)
- f(x,y) = 5 would return false
Source§impl<F: AcirField> Expression<F>
impl<F: AcirField> Expression<F>
pub fn from_field(q_c: F) -> Self
pub fn zero() -> Self
pub fn is_zero(&self) -> bool
pub fn one() -> Self
pub fn is_one(&self) -> bool
Sourcepub fn to_witness(&self) -> Option<Witness>
pub fn to_witness(&self) -> Option<Witness>
Returns a Witness if the Expression can be represented as a degree-1
univariate polynomial. Otherwise returns None.
Note that Witness is only capable of expressing polynomials of the form
f(x) = x and not polynomials of the form f(x) = mx+c , so this method has
extra checks to ensure that m=1 and c=0
Source§impl Expression<FieldElement>
impl Expression<FieldElement>
Sourcepub fn from_str(src: &str) -> Result<Self, AcirParserErrorWithSource>
pub fn from_str(src: &str) -> Result<Self, AcirParserErrorWithSource>
Creates a Expression object from the given string.
pub fn from_str_impl(src: &str) -> Result<Self, AcirParserErrorWithSource>
Trait Implementations§
Source§impl<F: AcirField> Add<&Expression<F>> for &Expression<F>
impl<F: AcirField> Add<&Expression<F>> for &Expression<F>
Source§type Output = Expression<F>
type Output = Expression<F>
+ operator.Source§impl<F: AcirField> Add<&Expression<F>> for Witness
impl<F: AcirField> Add<&Expression<F>> for Witness
Source§type Output = Expression<F>
type Output = Expression<F>
+ operator.Source§impl<F: AcirField> Add<F> for Expression<F>
impl<F: AcirField> Add<F> for Expression<F>
Source§impl<F: Clone> Clone for Expression<F>
impl<F: Clone> Clone for Expression<F>
Source§fn clone(&self) -> Expression<F>
fn clone(&self) -> Expression<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Debug> Debug for Expression<F>
impl<F: Debug> Debug for Expression<F>
Source§impl<F: AcirField> Default for Expression<F>
impl<F: AcirField> Default for Expression<F>
Source§impl<'de, F> Deserialize<'de> for Expression<F>where
F: Deserialize<'de>,
impl<'de, F> Deserialize<'de> for Expression<F>where
F: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<F: AcirField> Display for Expression<F>
impl<F: AcirField> Display for Expression<F>
Source§impl<F: AcirField> From<F> for Expression<F>
impl<F: AcirField> From<F> for Expression<F>
Source§impl FromStr for Expression<FieldElement>
impl FromStr for Expression<FieldElement>
Source§impl<F: Hash> Hash for Expression<F>
impl<F: Hash> Hash for Expression<F>
Source§impl<F: AcirField> Mul<&Expression<F>> for &Expression<F>
impl<F: AcirField> Mul<&Expression<F>> for &Expression<F>
Source§impl<F: AcirField> Mul<F> for &Expression<F>
impl<F: AcirField> Mul<F> for &Expression<F>
Source§impl<F: AcirField> Neg for &Expression<F>
impl<F: AcirField> Neg for &Expression<F>
Source§impl<F: AcirField> Neg for Expression<F>
impl<F: AcirField> Neg for Expression<F>
Source§impl<F: PartialEq> PartialEq for Expression<F>
impl<F: PartialEq> PartialEq for Expression<F>
Source§impl<F> Serialize for Expression<F>where
F: Serialize,
impl<F> Serialize for Expression<F>where
F: Serialize,
Source§impl<F: AcirField> Sub<&Expression<F>> for &Expression<F>
impl<F: AcirField> Sub<&Expression<F>> for &Expression<F>
Source§type Output = Expression<F>
type Output = Expression<F>
- operator.Source§impl<F: AcirField> Sub<&Expression<F>> for Witness
impl<F: AcirField> Sub<&Expression<F>> for Witness
Source§type Output = Expression<F>
type Output = Expression<F>
- operator.Source§impl<F: AcirField> Sub<F> for Expression<F>
impl<F: AcirField> Sub<F> for Expression<F>
impl<F: Eq> Eq for Expression<F>
impl<F> StructuralPartialEq for Expression<F>
Auto Trait Implementations§
impl<F> Freeze for Expression<F>where
F: Freeze,
impl<F> RefUnwindSafe for Expression<F>where
F: RefUnwindSafe,
impl<F> Send for Expression<F>where
F: Send,
impl<F> Sync for Expression<F>where
F: Sync,
impl<F> Unpin for Expression<F>where
F: Unpin,
impl<F> UnwindSafe for Expression<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more