pub enum Expression {
Show 41 variants
Bubble(Metadata, Box<Expression>, Box<Expression>),
Atomic(Metadata, Atom),
Abs(Metadata, Box<Expression>),
Sum(Metadata, Vec<Expression>),
Product(Metadata, Vec<Expression>),
Min(Metadata, Vec<Expression>),
Max(Metadata, Vec<Expression>),
Not(Metadata, Box<Expression>),
Or(Metadata, Vec<Expression>),
And(Metadata, Vec<Expression>),
Imply(Metadata, Box<Expression>, Box<Expression>),
Eq(Metadata, Box<Expression>, Box<Expression>),
Neq(Metadata, Box<Expression>, Box<Expression>),
Geq(Metadata, Box<Expression>, Box<Expression>),
Leq(Metadata, Box<Expression>, Box<Expression>),
Gt(Metadata, Box<Expression>, Box<Expression>),
Lt(Metadata, Box<Expression>, Box<Expression>),
SafeDiv(Metadata, Box<Expression>, Box<Expression>),
UnsafeDiv(Metadata, Box<Expression>, Box<Expression>),
SafeMod(Metadata, Box<Expression>, Box<Expression>),
UnsafeMod(Metadata, Box<Expression>, Box<Expression>),
Neg(Metadata, Box<Expression>),
UnsafePow(Metadata, Box<Expression>, Box<Expression>),
SafePow(Metadata, Box<Expression>, Box<Expression>),
AllDiff(Metadata, Vec<Expression>),
Minus(Metadata, Box<Expression>, Box<Expression>),
FlatAbsEq(Metadata, Atom, Atom),
FlatSumGeq(Metadata, Vec<Atom>, Atom),
FlatSumLeq(Metadata, Vec<Atom>, Atom),
FlatIneq(Metadata, Atom, Atom, Literal),
FlatWatchedLiteral(Metadata, Name, Literal),
FlatWeightedSumLeq(Metadata, Vec<Literal>, Vec<Atom>, Atom),
FlatWeightedSumGeq(Metadata, Vec<Literal>, Vec<Atom>, Atom),
FlatMinusEq(Metadata, Atom, Atom),
FlatProductEq(Metadata, Atom, Atom, Atom),
MinionDivEqUndefZero(Metadata, Atom, Atom, Atom),
MinionModuloEqUndefZero(Metadata, Atom, Atom, Atom),
MinionPow(Metadata, Atom, Atom, Atom),
MinionReify(Metadata, Box<Expression>, Atom),
MinionReifyImply(Metadata, Box<Expression>, Atom),
AuxDeclaration(Metadata, Name, Box<Expression>),
}
Expand description
Represents different types of expressions used to define rules and constraints in the model.
The Expression
enum includes operations, constants, and variable references
used to build rules and conditions for the model.
§Compatability
§Minion
AuxDeclaration
FlatAbsEq
FlatIneq
FlatMinusEq
FlatProductEq
FlatSumGeq
FlatSumLeq
FlatWatchedLiteral
MinionDivEqUndefZero
MinionModuloEqUndefZero
MinionReify
MinionReifyImply
§JsonInput
Abs
AllDiff
And
Eq
Geq
Gt
Imply
Leq
Lt
Max
Min
Minus
Neg
Neq
Not
Or
Product
Sum
UnsafeDiv
UnsafeMod
UnsafePow
§SAT
Variants§
Bubble(Metadata, Box<Expression>, Box<Expression>)
An expression representing “A is valid as long as B is true” Turns into a conjunction when it reaches a boolean context
Atomic(Metadata, Atom)
Abs(Metadata, Box<Expression>)
|x|
- absolute value of x
Supported by: JsonInput.
Sum(Metadata, Vec<Expression>)
Supported by: JsonInput.
Product(Metadata, Vec<Expression>)
Supported by: JsonInput.
Min(Metadata, Vec<Expression>)
Supported by: JsonInput.
Max(Metadata, Vec<Expression>)
Supported by: JsonInput.
Not(Metadata, Box<Expression>)
Supported by: JsonInput, SAT.
Or(Metadata, Vec<Expression>)
Supported by: JsonInput, SAT.
And(Metadata, Vec<Expression>)
Supported by: JsonInput, SAT.
Imply(Metadata, Box<Expression>, Box<Expression>)
Ensures that a->b
(material implication).
Supported by: JsonInput.
Eq(Metadata, Box<Expression>, Box<Expression>)
Supported by: JsonInput.
Neq(Metadata, Box<Expression>, Box<Expression>)
Supported by: JsonInput.
Geq(Metadata, Box<Expression>, Box<Expression>)
Supported by: JsonInput.
Leq(Metadata, Box<Expression>, Box<Expression>)
Supported by: JsonInput.
Gt(Metadata, Box<Expression>, Box<Expression>)
Supported by: JsonInput.
Lt(Metadata, Box<Expression>, Box<Expression>)
Supported by: JsonInput.
SafeDiv(Metadata, Box<Expression>, Box<Expression>)
Division after preventing division by zero, usually with a bubble
UnsafeDiv(Metadata, Box<Expression>, Box<Expression>)
Division with a possibly undefined value (division by 0) Supported by: JsonInput.
SafeMod(Metadata, Box<Expression>, Box<Expression>)
Modulo after preventing mod 0, usually with a bubble
UnsafeMod(Metadata, Box<Expression>, Box<Expression>)
Modulo with a possibly undefined value (mod 0) Supported by: JsonInput.
Neg(Metadata, Box<Expression>)
Negation: -x
Supported by: JsonInput.
UnsafePow(Metadata, Box<Expression>, Box<Expression>)
Unsafe powerx**y
(possibly undefined)
Defined when (X!=0 \/ Y!=0) /\ Y>=0 Supported by: JsonInput.
SafePow(Metadata, Box<Expression>, Box<Expression>)
UnsafePow
after preventing undefinedness
AllDiff(Metadata, Vec<Expression>)
Supported by: JsonInput.
Minus(Metadata, Box<Expression>, Box<Expression>)
Binary subtraction operator
This is a parser-level construct, and is immediately normalised to Sum([a,-b])
.
Supported by: JsonInput.
FlatAbsEq(Metadata, Atom, Atom)
Ensures that x=|y| i.e. x is the absolute value of y.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
FlatSumGeq(Metadata, Vec<Atom>, Atom)
Ensures that sum(vec) >= x.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
FlatSumLeq(Metadata, Vec<Atom>, Atom)
Ensures that sum(vec) <= x.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
FlatIneq(Metadata, Atom, Atom, Literal)
ineq(x,y,k)
ensures that x <= y + k.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
FlatWatchedLiteral(Metadata, Name, Literal)
w-literal(x,k)
ensures that x == k, where x is a variable and k a constant.
Low-level Minion constraint.
This is a low-level Minion constraint and you should probably use Eq instead. The main use of w-literal is to convert boolean variables to constraints so that they can be used inside watched-and and watched-or.
§See also
- Minion documentation
rules::minion::boolean_literal_to_wliteral
. Supported by: Minion.
FlatWeightedSumLeq(Metadata, Vec<Literal>, Vec<Atom>, Atom)
weightedsumleq(cs,xs,total)
ensures that cs.xs <= total, where cs.xs is the scalar dot
product of cs and xs.
Low-level Minion constraint.
Represents a weighted sum of the form ax + by + cz + ...
§See also
FlatWeightedSumGeq(Metadata, Vec<Literal>, Vec<Atom>, Atom)
weightedsumgeq(cs,xs,total)
ensures that cs.xs >= total, where cs.xs is the scalar dot
product of cs and xs.
Low-level Minion constraint.
Represents a weighted sum of the form ax + by + cz + ...
§See also
FlatMinusEq(Metadata, Atom, Atom)
Ensures that x =-y, where x and y are atoms.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
FlatProductEq(Metadata, Atom, Atom, Atom)
Ensures that x*y=z.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
MinionDivEqUndefZero(Metadata, Atom, Atom, Atom)
Ensures that floor(x/y)=z. Always true when y=0.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
MinionModuloEqUndefZero(Metadata, Atom, Atom, Atom)
Ensures that x%y=z. Always true when y=0.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
MinionPow(Metadata, Atom, Atom, Atom)
Ensures that x**y = z
.
Low-level Minion constraint.
This constraint is false when y<0
except for 1**y=1
and (-1)**y=z
(where z is 1 if y
is odd and z is -1 if y is even).
§See also
MinionReify(Metadata, Box<Expression>, Atom)
reify(constraint,r)
ensures that r=1 iff constraint
is satisfied, where r is a 0/1
variable.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
MinionReifyImply(Metadata, Box<Expression>, Atom)
reifyimply(constraint,r)
ensures that r->constraint
, where r is a 0/1 variable.
variable.
Low-level Minion constraint.
§See also
- Minion documentation Supported by: Minion.
AuxDeclaration(Metadata, Name, Box<Expression>)
Declaration of an auxiliary variable.
As with Savile Row, we semantically distinguish this from Eq
.
Supported by: Minion.
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn domain_of(&self, syms: &SymbolTable) -> Option<Domain>
pub fn domain_of(&self, syms: &SymbolTable) -> Option<Domain>
Returns the possible values of the expression, recursing to leaf expressions
pub fn get_meta(&self) -> Metadata
pub fn set_meta(&self, meta: Metadata)
Sourcepub fn is_safe(&self) -> bool
pub fn is_safe(&self) -> bool
Checks whether this expression is safe.
An expression is unsafe if can be undefined, or if any of its children can be undefined.
Unsafe expressions are (typically) prefixed with Unsafe in our AST, and can be made safe through the use of bubble rules.
pub fn return_type(&self) -> Option<ReturnType>
pub fn is_clean(&self) -> bool
pub fn set_clean(&mut self, bool_value: bool)
Sourcepub fn is_associative_commutative_operator(&self) -> bool
pub fn is_associative_commutative_operator(&self) -> bool
True if the expression is an associative and commutative operator
Sourcepub fn identical_atom_to(&self, other: &Expression) -> bool
pub fn identical_atom_to(&self, other: &Expression) -> bool
True iff self and other are both atomic and identical.
This method is useful to cheaply check equivalence. Assuming CSE is enabled, any unifiable
expressions will be rewritten to a common variable. This is much cheaper than checking the
entire subtrees of self
and other
.
Trait Implementations§
Source§impl Biplate<Atom> for Expression
impl Biplate<Atom> for Expression
Source§fn biplate(&self) -> (Tree<Atom>, Box<dyn Fn(Tree<Atom>) -> Expression>)
fn biplate(&self) -> (Tree<Atom>, Box<dyn Fn(Tree<Atom>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Biplate<Expression> for Atom
impl Biplate<Expression> for Atom
Source§fn biplate(&self) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> Atom>)
fn biplate(&self) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> Atom>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Biplate<Expression> for Expression
impl Biplate<Expression> for Expression
Source§fn biplate(
&self,
) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> Expression>)
fn biplate( &self, ) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Biplate<Literal> for Expression
impl Biplate<Literal> for Expression
Source§fn biplate(&self) -> (Tree<Literal>, Box<dyn Fn(Tree<Literal>) -> Expression>)
fn biplate(&self) -> (Tree<Literal>, Box<dyn Fn(Tree<Literal>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Biplate<Metadata> for Expression
impl Biplate<Metadata> for Expression
Source§fn biplate(&self) -> (Tree<Metadata>, Box<dyn Fn(Tree<Metadata>) -> Expression>)
fn biplate(&self) -> (Tree<Metadata>, Box<dyn Fn(Tree<Metadata>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Biplate<Name> for Expression
impl Biplate<Name> for Expression
Source§fn biplate(&self) -> (Tree<Name>, Box<dyn Fn(Tree<Name>) -> Expression>)
fn biplate(&self) -> (Tree<Name>, Box<dyn Fn(Tree<Name>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Biplate<Vec<Expression>> for Expression
impl Biplate<Vec<Expression>> for Expression
Source§fn biplate(
&self,
) -> (Tree<Vec<Expression>>, Box<dyn Fn(Tree<Vec<Expression>>) -> Expression>)
fn biplate( &self, ) -> (Tree<Vec<Expression>>, Box<dyn Fn(Tree<Vec<Expression>>) -> Expression>)
§fn with_children_bi(&self, children: VecDeque<To>) -> Self
fn with_children_bi(&self, children: VecDeque<To>) -> Self
§fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Uniplate::descend
] Read more§fn universe_bi(&self) -> VecDeque<To>
fn universe_bi(&self) -> VecDeque<To>
§fn children_bi(&self) -> VecDeque<To>
fn children_bi(&self) -> VecDeque<To>
§fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Expression
impl Display for Expression
Source§impl From<Atom> for Expression
impl From<Atom> for Expression
Source§impl From<bool> for Expression
impl From<bool> for Expression
Source§impl From<i32> for Expression
impl From<i32> for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl Serialize for Expression
impl Serialize for Expression
Source§impl<'a> TryFrom<&'a Expression> for &'a Atom
impl<'a> TryFrom<&'a Expression> for &'a Atom
Source§impl TryFrom<Expression> for Atom
impl TryFrom<Expression> for Atom
Source§impl Uniplate for Expression
impl Uniplate for Expression
Source§fn uniplate(
&self,
) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> Expression>)
fn uniplate( &self, ) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> Expression>)
Uniplate
. Read more§fn descend(&self, op: Arc<dyn Fn(Self) -> Self>) -> Self
fn descend(&self, op: Arc<dyn Fn(Self) -> Self>) -> Self
§fn universe(&self) -> VecDeque<Self>
fn universe(&self) -> VecDeque<Self>
§fn with_children(&self, children: VecDeque<Self>) -> Self
fn with_children(&self, children: VecDeque<Self>) -> Self
§fn transform(&self, f: Arc<dyn Fn(Self) -> Self>) -> Self
fn transform(&self, f: Arc<dyn Fn(Self) -> Self>) -> Self
§fn rewrite(&self, f: Arc<dyn Fn(Self) -> Option<Self>>) -> Self
fn rewrite(&self, f: Arc<dyn Fn(Self) -> Option<Self>>) -> Self
§fn cata<T>(&self, op: Arc<dyn Fn(Self, VecDeque<T>) -> T>) -> T
fn cata<T>(&self, op: Arc<dyn Fn(Self, VecDeque<T>) -> T>) -> T
impl Eq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§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