pub struct ClassicalExpr { /* private fields */ }Expand description
A typed, side-effect-free runtime classical expression.
The expression node kind is exposed through ClassicalExpr::kind for
inspection and tooling. Prefer the typed constructors on this type when
building expressions; they centralize type checks and keep the AST valid.
Implementations§
Source§impl ClassicalExpr
impl ClassicalExpr
Sourcepub fn var(var: ClassicalVar) -> Self
pub fn var(var: ClassicalVar) -> Self
Creates an expression that reads the current runtime value of var.
Sourcepub fn value(value: ClassicalValue) -> Self
pub fn value(value: ClassicalValue) -> Self
Creates an expression that reads an immutable runtime classical value.
Sourcepub fn bool_literal(value: bool) -> Self
pub fn bool_literal(value: bool) -> Self
Creates a boolean literal expression.
Sourcepub fn bit_literal(value: bool) -> Self
pub fn bit_literal(value: bool) -> Self
Creates a bit literal expression.
Sourcepub fn uint_literal(width: u32, value: u128) -> Result<Self, CircuitError>
pub fn uint_literal(width: u32, value: u128) -> Result<Self, CircuitError>
Creates an unsigned integer literal with a non-zero width.
Literal construction currently supports constants up to 128 bits wide.
Sourcepub fn bit_vec_literal(width: u32, value: u128) -> Result<Self, CircuitError>
pub fn bit_vec_literal(width: u32, value: u128) -> Result<Self, CircuitError>
Creates a bit-vector literal with a non-zero width.
Literal construction currently supports constants up to 128 bits wide.
Sourcepub fn ty(&self) -> ClassicalType
pub fn ty(&self) -> ClassicalType
Returns this expression’s static type.
Sourcepub fn kind(&self) -> &ClassicalExprKind
pub fn kind(&self) -> &ClassicalExprKind
Returns the expression node kind.
This exposes the classical expression AST for inspection. Prefer the
typed constructors on ClassicalExpr when building expressions so
expression invariants remain centralized.
Sourcepub fn remap_classical_ids(
&self,
var_map: &HashMap<ClassicalVar, ClassicalVar>,
value_map: &HashMap<ClassicalValue, ClassicalValue>,
) -> Result<Self, CircuitError>
pub fn remap_classical_ids( &self, var_map: &HashMap<ClassicalVar, ClassicalVar>, value_map: &HashMap<ClassicalValue, ClassicalValue>, ) -> Result<Self, CircuitError>
Returns a copy of this expression with circuit-local classical handles remapped.
Every ClassicalVar and ClassicalValue referenced by this
expression must have an entry in the corresponding map. Literal and
structural nodes keep their static type and shape.
Sourcepub fn vars(&self) -> BTreeSet<ClassicalVar>
pub fn vars(&self) -> BTreeSet<ClassicalVar>
Returns all runtime classical variables read by this expression.
Sourcepub fn values(&self) -> BTreeSet<ClassicalValue>
pub fn values(&self) -> BTreeSet<ClassicalValue>
Returns all immutable runtime classical values read by this expression.
Sourcepub fn collect_vars(&self, out: &mut BTreeSet<ClassicalVar>)
pub fn collect_vars(&self, out: &mut BTreeSet<ClassicalVar>)
Adds every runtime classical variable read by this expression to out.
Sourcepub fn collect_values(&self, out: &mut BTreeSet<ClassicalValue>)
pub fn collect_values(&self, out: &mut BTreeSet<ClassicalValue>)
Adds every immutable runtime classical value read by this expression to out.
Sourcepub fn try_not(expr: impl Into<Self>) -> Result<Self, CircuitError>
pub fn try_not(expr: impl Into<Self>) -> Result<Self, CircuitError>
Creates a not expression for Bool or Bit values.
Sourcepub fn try_and(
lhs: impl Into<Self>,
rhs: impl Into<Self>,
) -> Result<Self, CircuitError>
pub fn try_and( lhs: impl Into<Self>, rhs: impl Into<Self>, ) -> Result<Self, CircuitError>
Creates an and expression for matching Bool or matching Bit values.
Sourcepub fn try_or(
lhs: impl Into<Self>,
rhs: impl Into<Self>,
) -> Result<Self, CircuitError>
pub fn try_or( lhs: impl Into<Self>, rhs: impl Into<Self>, ) -> Result<Self, CircuitError>
Creates an or expression for matching Bool or matching Bit values.
Sourcepub fn try_xor(
lhs: impl Into<Self>,
rhs: impl Into<Self>,
) -> Result<Self, CircuitError>
pub fn try_xor( lhs: impl Into<Self>, rhs: impl Into<Self>, ) -> Result<Self, CircuitError>
Creates an xor expression for matching Bool or matching Bit values.
Sourcepub fn eq(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
pub fn eq(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
Creates an equality comparison. Operands must have the same type.
Sourcepub fn ne(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
pub fn ne(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
Creates an inequality comparison. Operands must have the same type.
Sourcepub fn lt(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
pub fn lt(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
Creates an unsigned less-than comparison.
Sourcepub fn le(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
pub fn le(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
Creates an unsigned less-than-or-equal comparison.
Sourcepub fn gt(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
pub fn gt(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
Creates an unsigned greater-than comparison.
Sourcepub fn ge(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
pub fn ge(lhs: Self, rhs: Self) -> Result<Self, CircuitError>
Creates an unsigned greater-than-or-equal comparison.
Sourcepub fn bit_to_bool(expr: Self) -> Result<Self, CircuitError>
pub fn bit_to_bool(expr: Self) -> Result<Self, CircuitError>
Explicitly casts a Bit expression to Bool.
Sourcepub fn bit_vec_to_uint(expr: Self) -> Result<Self, CircuitError>
pub fn bit_vec_to_uint(expr: Self) -> Result<Self, CircuitError>
Explicitly casts a BitVec expression to a little-endian UInt.
Sourcepub fn to_bool(self) -> Result<Self, CircuitError>
pub fn to_bool(self) -> Result<Self, CircuitError>
Converts this Bit expression to Bool.
Sourcepub fn to_uint(self) -> Result<Self, CircuitError>
pub fn to_uint(self) -> Result<Self, CircuitError>
Converts this BitVec expression to a little-endian UInt.
Sourcepub fn select(
condition: Self,
then_expr: Self,
else_expr: Self,
) -> Result<Self, CircuitError>
pub fn select( condition: Self, then_expr: Self, else_expr: Self, ) -> Result<Self, CircuitError>
Creates an expression that chooses between two same-typed values.
Sourcepub fn extract_bit(value: Self, index: u32) -> Result<Self, CircuitError>
pub fn extract_bit(value: Self, index: u32) -> Result<Self, CircuitError>
Extracts a single bit from a BitVec or UInt.
Index 0 is the least-significant bit.
Sourcepub fn extract_bits(
value: Self,
offset: u32,
width: u32,
) -> Result<Self, CircuitError>
pub fn extract_bits( value: Self, offset: u32, width: u32, ) -> Result<Self, CircuitError>
Extracts a bit range from a BitVec or UInt.
offset is little-endian: offset 0 starts at the least-significant bit.
Sourcepub fn concat(
parts: impl IntoIterator<Item = Self>,
) -> Result<Self, CircuitError>
pub fn concat( parts: impl IntoIterator<Item = Self>, ) -> Result<Self, CircuitError>
Concatenates bit-vector values into a larger bit-vector.
The first part occupies the least-significant output bits.
Sourcepub fn is_bool_true(&self) -> bool
pub fn is_bool_true(&self) -> bool
Returns true when this expression is the boolean literal true.
Sourcepub fn is_bool_false(&self) -> bool
pub fn is_bool_false(&self) -> bool
Returns true when this expression is the boolean literal false.
Sourcepub fn is_bit_true(&self) -> bool
pub fn is_bit_true(&self) -> bool
Returns true when this expression is the bit literal true (1).
Sourcepub fn is_bit_false(&self) -> bool
pub fn is_bit_false(&self) -> bool
Returns true when this expression is the bit literal false (0).
Sourcepub fn simplified(&self) -> Self
pub fn simplified(&self) -> Self
Returns a structurally simplified copy of this expression.
Simplification eliminates literal-driven redundancies and algebraic identities without evaluating runtime variable or value reads. It is idempotent: applying it twice yields the same expression.
See simplify for the full rule set.
Sourcepub fn pack_bits(
bits: impl IntoIterator<Item = Self>,
) -> Result<Self, CircuitError>
pub fn pack_bits( bits: impl IntoIterator<Item = Self>, ) -> Result<Self, CircuitError>
Packs single-bit expressions into a BitVec.
The first bit becomes output index 0, the least-significant bit.
Trait Implementations§
Source§impl<Rhs> BitAnd<Rhs> for ClassicalExprwhere
Rhs: Into<ClassicalExpr>,
impl<Rhs> BitAnd<Rhs> for ClassicalExprwhere
Rhs: Into<ClassicalExpr>,
Source§impl<Rhs> BitOr<Rhs> for ClassicalExprwhere
Rhs: Into<ClassicalExpr>,
impl<Rhs> BitOr<Rhs> for ClassicalExprwhere
Rhs: Into<ClassicalExpr>,
Source§impl<Rhs> BitXor<Rhs> for ClassicalExprwhere
Rhs: Into<ClassicalExpr>,
impl<Rhs> BitXor<Rhs> for ClassicalExprwhere
Rhs: Into<ClassicalExpr>,
Source§impl Clone for ClassicalExpr
impl Clone for ClassicalExpr
Source§impl Debug for ClassicalExpr
impl Debug for ClassicalExpr
impl Eq for ClassicalExpr
Source§impl From<ClassicalValue> for ClassicalExpr
impl From<ClassicalValue> for ClassicalExpr
Source§fn from(value: ClassicalValue) -> Self
fn from(value: ClassicalValue) -> Self
Source§impl From<ClassicalVar> for ClassicalExpr
impl From<ClassicalVar> for ClassicalExpr
Source§fn from(var: ClassicalVar) -> Self
fn from(var: ClassicalVar) -> Self
Source§impl Hash for ClassicalExpr
impl Hash for ClassicalExpr
Source§impl Not for ClassicalExpr
impl Not for ClassicalExpr
Source§impl PartialEq for ClassicalExpr
impl PartialEq for ClassicalExpr
impl StructuralPartialEq for ClassicalExpr
Auto Trait Implementations§
impl Freeze for ClassicalExpr
impl RefUnwindSafe for ClassicalExpr
impl Send for ClassicalExpr
impl Sync for ClassicalExpr
impl Unpin for ClassicalExpr
impl UnsafeUnpin for ClassicalExpr
impl UnwindSafe for ClassicalExpr
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> CallHasher for T
impl<T> CallHasher for T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<T, U> Imply<T> for U
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.