pub struct ArithCircuit<F: Field> { /* private fields */ }
Expand description
Arithmetic expressions that can be evaluated symbolically.
Arithmetic expressions are trees, where the leaves are either constants or variables, and the non-leaf nodes are arithmetic operations, such as addition, multiplication, etc. They are specific representations of multivariate polynomials.
We store a tree in a form of a simple circuit. This implementation isn’t optimized for performance, but rather for simplicity to allow easy conversion and preservation of the common subexpressions
Implementations§
Source§impl<F: Field> ArithCircuit<F>
impl<F: Field> ArithCircuit<F>
pub fn var(index: usize) -> Self
pub fn constant(value: F) -> Self
pub fn zero() -> Self
pub fn one() -> Self
pub fn pow(self, exp: u64) -> Self
Sourcepub fn steps(&self) -> &[ArithCircuitStep<F>]
pub fn steps(&self) -> &[ArithCircuitStep<F>]
Steps of the circuit.
Sourcepub fn binary_tower_level(&self) -> usizewhere
F: TowerField,
pub fn binary_tower_level(&self) -> usizewhere
F: TowerField,
The maximum tower level of the constant terms in the circuit.
Sourcepub fn leading_term(&self) -> Self
pub fn leading_term(&self) -> Self
Return a new arithmetic expression that contains only the terms of highest degree (useful for interpolation at Karatsuba infinity point).
pub fn evaluate(&self, query: &[F]) -> Result<F, Error>
pub fn convert_field<FTgt: Field + From<F>>(&self) -> ArithCircuit<FTgt>
pub fn try_convert_field<FTgt: Field + TryFrom<F>>( &self, ) -> Result<ArithCircuit<FTgt>, <FTgt as TryFrom<F>>::Error>
Sourcepub fn remap_vars(&self, indices: &[usize]) -> Result<Self, Error>
pub fn remap_vars(&self, indices: &[usize]) -> Result<Self, Error>
Creates a new expression with the variable indices remapped.
This recursively replaces the variable sub-expressions with an index i
with the variable
indices[i]
.
§Throws
Error::IncorrectArgumentLength
if indices has length less than the current number of variables
Sourcepub fn const_subst(self, var: usize, value: F) -> Self
pub fn const_subst(self, var: usize, value: F) -> Self
Substitute variable with index var
with a constant value
Sourcepub fn get_constant(&self) -> Option<F>
pub fn get_constant(&self) -> Option<F>
Returns Some(F)
if the expression is a constant.
Sourcepub fn linear_normal_form(&self) -> Result<LinearNormalForm<F>, Error>
pub fn linear_normal_form(&self) -> Result<LinearNormalForm<F>, Error>
Returns the normal form of an expression if it is linear.
§Throws
Error::NonLinearExpression
if the expression is not linear.
Sourcepub fn vars_usage(&self) -> Vec<bool>
pub fn vars_usage(&self) -> Vec<bool>
Returns a vector of booleans indicating which variables are used in the expression.
The vector is indexed by variable index, and the value at index i
is true
if and only
if the variable is used in the expression.
Sourcepub fn optimize_constants_in_place(&mut self)
pub fn optimize_constants_in_place(&mut self)
Fold constants in the circuit.
Sourcepub fn optimize_constants(self) -> Self
pub fn optimize_constants(self) -> Self
Same as optimize_constants_in_place
, but returns a new instance of the circuit.
Sourcepub fn optimize_in_place(&mut self)
pub fn optimize_in_place(&mut self)
Optimize the current instance of the circuit:
- Fold constants
- Extract common steps
- Remove unused steps
Trait Implementations§
Source§impl<F: Field> Add for ArithCircuit<F>
impl<F: Field> Add for ArithCircuit<F>
Source§impl<F: Field> AddAssign for ArithCircuit<F>
impl<F: Field> AddAssign for ArithCircuit<F>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl<F: Clone + Field> Clone for ArithCircuit<F>
impl<F: Clone + Field> Clone for ArithCircuit<F>
Source§fn clone(&self) -> ArithCircuit<F>
fn clone(&self) -> ArithCircuit<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F: Field + DeserializeBytes> DeserializeBytes for ArithCircuit<F>
impl<F: Field + DeserializeBytes> DeserializeBytes for ArithCircuit<F>
fn deserialize(
read_buf: impl Buf,
mode: SerializationMode,
) -> Result<Self, SerializationError>where
Self: Sized,
Source§impl<F: Field> Display for ArithCircuit<F>
impl<F: Field> Display for ArithCircuit<F>
Source§impl<F: Field> From<&ArithCircuit<F>> for ArithExpr<F>
impl<F: Field> From<&ArithCircuit<F>> for ArithExpr<F>
Source§fn from(circuit: &ArithCircuit<F>) -> Self
fn from(circuit: &ArithCircuit<F>) -> Self
Source§impl<F: Field> From<ArithCircuit<F>> for ArithExpr<F>
impl<F: Field> From<ArithCircuit<F>> for ArithExpr<F>
Source§fn from(circuit: ArithCircuit<F>) -> Self
fn from(circuit: ArithCircuit<F>) -> Self
Source§impl<F: Field> Mul for ArithCircuit<F>
impl<F: Field> Mul for ArithCircuit<F>
Source§impl<F: Field> MulAssign for ArithCircuit<F>
impl<F: Field> MulAssign for ArithCircuit<F>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl<F: Field> PartialEq for ArithCircuit<F>
impl<F: Field> PartialEq for ArithCircuit<F>
Source§impl<F: Field> Product for ArithCircuit<F>
impl<F: Field> Product for ArithCircuit<F>
Source§impl<F: Field + SerializeBytes> SerializeBytes for ArithCircuit<F>
impl<F: Field + SerializeBytes> SerializeBytes for ArithCircuit<F>
fn serialize( &self, write_buf: impl BufMut, mode: SerializationMode, ) -> Result<(), SerializationError>
Source§impl<F: Field> Sub for ArithCircuit<F>
impl<F: Field> Sub for ArithCircuit<F>
Source§impl<F: Field> SubAssign for ArithCircuit<F>
impl<F: Field> SubAssign for ArithCircuit<F>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moreSource§impl<F: Field> Sum for ArithCircuit<F>
impl<F: Field> Sum for ArithCircuit<F>
impl<F: Eq + Field> Eq for ArithCircuit<F>
Auto Trait Implementations§
impl<F> Freeze for ArithCircuit<F>
impl<F> RefUnwindSafe for ArithCircuit<F>
impl<F> Send for ArithCircuit<F>
impl<F> Sync for ArithCircuit<F>
impl<F> Unpin for ArithCircuit<F>
impl<F> UnwindSafe for ArithCircuit<F>
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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