pub enum Expr {
Var(VarId),
Const(u64),
Not(Box<Expr>),
Scale(u64, Box<Expr>),
And(Vec<Expr>),
Or(Vec<Expr>),
Xor(Vec<Expr>),
Add(Vec<Expr>),
Mul(Vec<Expr>),
}Expand description
A Mixed Boolean-Arithmetic expression tree.
Variants§
Var(VarId)
A variable, referenced by its VarId.
Const(u64)
A constant value.
Not(Box<Expr>)
Bitwise complement (~e).
Scale(u64, Box<Expr>)
Multiplication of an expression by a constant coefficient.
And(Vec<Expr>)
Bitwise AND of all operands.
Or(Vec<Expr>)
Bitwise OR of all operands.
Xor(Vec<Expr>)
Bitwise XOR of all operands.
Add(Vec<Expr>)
Arithmetic sum of all operands.
Mul(Vec<Expr>)
Arithmetic product of all operands.
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn make_const(c: u64) -> Self
pub fn make_const(c: u64) -> Self
Builds a constant expression from c.
Sourcepub fn eval(&self, vars: &[u64], n: u8) -> u64
pub fn eval(&self, vars: &[u64], n: u8) -> u64
Evaluates the expression for the given variable values on n bits.
Sourcepub fn sem_equal(
&self,
other: &Expr,
n: u8,
samples: usize,
) -> Result<(), (Vec<u64>, u64, u64)>
pub fn sem_equal( &self, other: &Expr, n: u8, samples: usize, ) -> Result<(), (Vec<u64>, u64, u64)>
Checks, by random sampling on n bits, whether two expressions are
semantically equal. On a counterexample returns the sampled variable
values and the two differing evaluations.
Sourcepub fn truth_table(&self, t: usize, n: u8) -> Vec<u64>
pub fn truth_table(&self, t: usize, n: u8) -> Vec<u64>
The truth table of this expression over its first t variables on n
bits (one entry per assignment of the t variables to 0/1).
Sourcepub fn repr(&self, n: u8, hex: bool, latex: bool) -> String
pub fn repr(&self, n: u8, hex: bool, latex: bool) -> String
A string representation of this expression on n bits.
Sourcepub fn is_bitwise(&self) -> bool
pub fn is_bitwise(&self) -> bool
Whether this expression is purely bitwise (no arithmetic operators).
Sourcepub fn variables_in(&self, allowed_vars: &Vec<usize>) -> bool
pub fn variables_in(&self, allowed_vars: &Vec<usize>) -> bool
Whether every variable in this expression is contained in allowed_vars.
Trait Implementations§
impl Eq for Expr
Source§impl Ord for Expr
impl Ord for Expr
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Expr
impl PartialOrd for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnsafeUnpin for Expr
impl UnwindSafe for Expr
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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.