pub enum Expression<V>where
V: Clone,{
Boolean(BooleanExpr<V>),
Natural(NaturalExpr<V>),
Integer(IntegerExpr<V>),
Float(FloatExpr<V>),
}Expand description
Expressions for the language internally used by PGs and CSs.
Expression<V> encodes the language in which V is the type of variables.
Note that not all expressions that can be formed are well-typed.
Variants§
Boolean(BooleanExpr<V>)
Expression of Boolean type.
Natural(NaturalExpr<V>)
Expression of Natural type (unsigned integers).
Integer(IntegerExpr<V>)
Expression of Integer type.
Float(FloatExpr<V>)
Expression of Float type.
Implementations§
Source§impl<V> Expression<V>where
V: Clone,
impl<V> Expression<V>where
V: Clone,
Sourcepub fn type(&self) -> Type
pub fn type(&self) -> Type
Computes the type of an expression.
Fails if the expression is badly typed, e.g., if variables in it have type incompatible with the expression.
Sourcepub fn eval<R: Rng>(&self, vars: &dyn Fn(&V) -> Val, rng: &mut R) -> Val
pub fn eval<R: Rng>(&self, vars: &dyn Fn(&V) -> Val, rng: &mut R) -> Val
Evaluates the expression with the given variable assignments and provided RNG.
Will assume the expression (with the variable assignment) is well-typed, and may panic if producing an unexpected type.
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Evals a constant expression. Returns an error if expression contains variables.
Sourcepub fn eval_constant(&self) -> Result<Val, TypeError>
pub fn eval_constant(&self) -> Result<Val, TypeError>
Evals a constant expression. Returns an error if expression contains variables.
Sourcepub fn from_var(var: V, type: Type) -> Self
pub fn from_var(var: V, type: Type) -> Self
Creates an [Expression] out of a variable and the type of such variable.
Sourcepub fn equal_to(self, rhs: Self) -> Result<BooleanExpr<V>, TypeError>
pub fn equal_to(self, rhs: Self) -> Result<BooleanExpr<V>, TypeError>
Creates an Expression that predicates the equality of self and rhs,
and returns error if comparison is not possible.
Equality of Boolean is represented as “if and only if”.
Equality of numerical types automatically casts the one of most-restrictive type to the less restrictive type of the other one:
for example, NaturalExpr can be cast to IntegerExpr or FloatExpr;
and [IntegerExpr] can be cast to [FloatExpr].
Sourcepub fn greater_than_or_equal_to(
self,
rhs: Self,
) -> Result<BooleanExpr<V>, TypeError>
pub fn greater_than_or_equal_to( self, rhs: Self, ) -> Result<BooleanExpr<V>, TypeError>
Creates a BooleanExpr that compares numerical expressions self and rhs,
and returns error if comparison is not possible.
Equality of numerical types automatically casts the one of most-restrictive type to the less restrictive type of the other one;
see Self::equal_to.
Sourcepub fn greater_than(self, rhs: Self) -> Result<BooleanExpr<V>, TypeError>
pub fn greater_than(self, rhs: Self) -> Result<BooleanExpr<V>, TypeError>
Creates a BooleanExpr that compares numerical expressions self and rhs,
and returns error if comparison is not possible.
Equality of numerical types automatically casts the one of most-restrictive type to the less restrictive type of the other one;
see Self::equal_to.
Sourcepub fn less_than(self, rhs: Self) -> Result<BooleanExpr<V>, TypeError>
pub fn less_than(self, rhs: Self) -> Result<BooleanExpr<V>, TypeError>
Creates a BooleanExpr that compares numerical expressions self and rhs,
and returns error if comparison is not possible.
Equality of numerical types automatically casts the one of most-restrictive type to the less restrictive type of the other one;
see Self::equal_to.
Sourcepub fn less_than_or_equal_to(
self,
rhs: Self,
) -> Result<BooleanExpr<V>, TypeError>
pub fn less_than_or_equal_to( self, rhs: Self, ) -> Result<BooleanExpr<V>, TypeError>
Creates a BooleanExpr that compares numerical expressions self and rhs,
and returns error if comparison is not possible.
Equality of numerical types automatically casts the one of most-restrictive type to the less restrictive type of the other one;
see Self::equal_to.
Sourcepub fn ite(self, then: Self, else: Self) -> Result<Self, TypeError>
pub fn ite(self, then: Self, else: Self) -> Result<Self, TypeError>
Creates a BooleanExpr that compares numerical expressions self and rhs,
and returns error if comparison is not possible.
Equality of numerical types automatically casts the one of most-restrictive type to the less restrictive type of the other one;
see Self::equal_to.
Trait Implementations§
Source§impl<V: Clone> Add for Expression<V>
impl<V: Clone> Add for Expression<V>
Source§impl<V: Clone> BitAnd for Expression<V>
impl<V: Clone> BitAnd for Expression<V>
Source§impl<V: Clone> BitOr for Expression<V>
impl<V: Clone> BitOr for Expression<V>
Source§impl<V> Clone for Expression<V>
impl<V> Clone for Expression<V>
Source§fn clone(&self) -> Expression<V>
fn clone(&self) -> Expression<V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<V> Debug for Expression<V>
impl<V> Debug for Expression<V>
Source§impl<V: Clone> Div for Expression<V>
impl<V: Clone> Div for Expression<V>
Source§impl<V: Clone> Mul for Expression<V>
impl<V: Clone> Mul for Expression<V>
Source§impl<V: Clone> Neg for Expression<V>
impl<V: Clone> Neg for Expression<V>
Source§impl<V: Clone> Not for Expression<V>
impl<V: Clone> Not for Expression<V>
Source§impl<V: Clone> Rem for Expression<V>
impl<V: Clone> Rem for Expression<V>
Source§impl<V> TryFrom<Expression<V>> for BooleanExpr<V>where
V: Clone,
impl<V> TryFrom<Expression<V>> for BooleanExpr<V>where
V: Clone,
Source§impl<V> TryFrom<Expression<V>> for IntegerExpr<V>where
V: Clone,
impl<V> TryFrom<Expression<V>> for IntegerExpr<V>where
V: Clone,
Auto Trait Implementations§
impl<V> Freeze for Expression<V>where
V: Freeze,
impl<V> RefUnwindSafe for Expression<V>where
V: RefUnwindSafe,
impl<V> Send for Expression<V>where
V: Send,
impl<V> Sync for Expression<V>where
V: Sync,
impl<V> Unpin for Expression<V>where
V: Unpin,
impl<V> UnsafeUnpin for Expression<V>where
V: UnsafeUnpin,
impl<V> UnwindSafe for Expression<V>where
V: 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,
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