Skip to main content

Expression

Enum Expression 

Source
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,

Source

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.

Source

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.

Source

pub fn is_constant(&self) -> bool

Evals a constant expression. Returns an error if expression contains variables.

Source

pub fn eval_constant(&self) -> Result<Val, TypeError>

Evals a constant expression. Returns an error if expression contains variables.

Source

pub fn from_var(var: V, type: Type) -> Self

Creates an [Expression] out of a variable and the type of such variable.

Source

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].

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<V: Clone> BitAnd for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<V: Clone> BitOr for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<V> Clone for Expression<V>
where V: Clone + Clone,

Source§

fn clone(&self) -> Expression<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V> Debug for Expression<V>
where V: Clone + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Clone> Div for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<V> From<Val> for Expression<V>
where V: Clone,

Source§

fn from(value: Val) -> Self

Converts to this type from the input type.
Source§

impl<V> From<bool> for Expression<V>
where V: Clone,

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl<V> From<f64> for Expression<V>
where V: Clone,

Source§

fn from(value: Float) -> Self

Converts to this type from the input type.
Source§

impl<V> From<i64> for Expression<V>
where V: Clone,

Source§

fn from(value: Integer) -> Self

Converts to this type from the input type.
Source§

impl<V> From<u64> for Expression<V>
where V: Clone,

Source§

fn from(value: Natural) -> Self

Converts to this type from the input type.
Source§

impl<V: Clone> Mul for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<V: Clone> Neg for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<V: Clone> Not for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<V: Clone> Rem for Expression<V>

Source§

type Output = Result<Expression<V>, TypeError>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl<V> TryFrom<Expression<V>> for BooleanExpr<V>
where V: Clone,

Source§

type Error = TypeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Expression<V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<V> TryFrom<Expression<V>> for FloatExpr<V>
where V: Clone,

Source§

type Error = TypeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Expression<V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<V> TryFrom<Expression<V>> for IntegerExpr<V>
where V: Clone,

Source§

type Error = TypeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Expression<V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<V> TryFrom<Expression<V>> for NaturalExpr<V>
where V: Clone,

Source§

type Error = TypeError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Expression<V>) -> Result<Self, Self::Error>

Performs the conversion.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.