pub enum ACOperatorKind {
And,
Or,
Product,
Sum,
Min,
Max,
}Expand description
The possible kinds of associative-commutative (AC) operator.
AC operators take a single vector as input and are commonly used alongside comprehensions.
Min/Max are included here for the sole purpose of tagging a comprehension’s
skip_operator so that a symbolic guard
inside min([... | ...])/max([... | ...]) can be lowered correctly by the native
comprehension expander – unlike And/Or/Sum/Product, they have no universal identity
element (the “safe value to substitute for a guarded-out element” depends on the element’s own
domain), so identity is intentionally unreachable for them; callers that
might see a Min/Max operator must check for that first (see
expand_native.rs’s guard on the identity-dropping optimisation for the only current example).
They are deliberately not wired into TryFrom<&Expression> or the AC-comprehension merge/
via-solver machinery, which only ever handles the four true AC operators.
Variants§
Implementations§
Source§impl ACOperatorKind
impl ACOperatorKind
Sourcepub fn as_expression(&self, child_expr: Expression) -> Expression
pub fn as_expression(&self, child_expr: Expression) -> Expression
Creates a new Expression of this AC operator kind with the given child expression.
The child expression given should be of type matrix.
Sourcepub fn identity(&self) -> Literal
pub fn identity(&self) -> Literal
Returns the identity element of this operation.
§Example
use conjure_cp_core::ast::{ac_operators::ACOperatorKind,Literal};
let identity = ACOperatorKind::And.identity();
assert_eq!(identity,Literal::Bool(true));§Panics
Min/Max have no universal identity element – see the type-level doc comment. Callers
must not call this for those two variants.
Sourcepub fn make_skip_operation(
&self,
guard_expr: Expression,
tail_expr: Expression,
) -> Expression
pub fn make_skip_operation( &self, guard_expr: Expression, tail_expr: Expression, ) -> Expression
Given some guard and tail expressions, constructs the skipping operator for this operation.
The skipping operator is operator that takes some boolean guard expression b and some tail expression x. If b is true, then it evaluates to x, otherwise it evaluates to the identity element.
§Usage
This can be used to add guards to elements of AC operations. In the example model below, we only want to multiply y*z by 2 if multiplyByTwo is true:
find multiplyByTwo: bool
find x: int(1..5)
find y: int(1..5)
find z: int(1..5)
such that
x = product([y,z,[1,x;int(0..1)][toInt(b)]])[1,x;int(0..1)][toInt(b)] is the skipping operator for product.
This method constructs the skipping operator, substituting in the given expressions for b and x.
Sourcepub fn make_min_max_skip_operation(
&self,
guard_expr: Expression,
tail_expr: Expression,
skip_value: Literal,
) -> Expression
pub fn make_min_max_skip_operation( &self, guard_expr: Expression, tail_expr: Expression, skip_value: Literal, ) -> Expression
The min/max equivalent of make_skip_operation: self must
be Min or Max. Unlike the four true AC operators, min/max have no value that’s always
safe to substitute for a guarded-out element – callers must supply one themselves (skip_value),
since this method has no way to know it: by the time a per-branch skip operation is being
built, tail_expr is already the branch-specific (and so potentially far too narrow)
result, not the comprehension’s general return-expression domain the skip value should
come from. Any domain bound safe for every element being aggregated works (e.g. the
element’s declared domain’s max, for min, or min, for max) – including it can never
change a min/max computed over at least one included real element, since it is never more
extreme than any value the element could actually take.
Sourcepub fn return_type(&self) -> ReturnType
pub fn return_type(&self) -> ReturnType
Gives the return type of the operator, and the return types its elements should be.
Trait Implementations§
Source§impl Clone for ACOperatorKind
impl Clone for ACOperatorKind
Source§fn clone(&self) -> ACOperatorKind
fn clone(&self) -> ACOperatorKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ACOperatorKind
Source§impl Debug for ACOperatorKind
impl Debug for ACOperatorKind
Source§impl<'de> Deserialize<'de> for ACOperatorKind
impl<'de> Deserialize<'de> for ACOperatorKind
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ACOperatorKind, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ACOperatorKind, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for ACOperatorKind
Source§impl Hash for ACOperatorKind
impl Hash for ACOperatorKind
Source§impl PartialEq for ACOperatorKind
impl PartialEq for ACOperatorKind
Source§impl Serialize for ACOperatorKind
impl Serialize for ACOperatorKind
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ACOperatorKind
Source§impl TryFrom<&Expression> for ACOperatorKind
impl TryFrom<&Expression> for ACOperatorKind
Source§fn try_from(
expr: &Expression,
) -> Result<ACOperatorKind, <ACOperatorKind as TryFrom<&Expression>>::Error>
fn try_from( expr: &Expression, ) -> Result<ACOperatorKind, <ACOperatorKind as TryFrom<&Expression>>::Error>
Source§impl TryFrom<Box<Expression>> for ACOperatorKind
impl TryFrom<Box<Expression>> for ACOperatorKind
Source§fn try_from(
value: Box<Expression>,
) -> Result<ACOperatorKind, <ACOperatorKind as TryFrom<Box<Expression>>>::Error>
fn try_from( value: Box<Expression>, ) -> Result<ACOperatorKind, <ACOperatorKind as TryFrom<Box<Expression>>>::Error>
Source§impl TryFrom<Expression> for ACOperatorKind
impl TryFrom<Expression> for ACOperatorKind
Source§fn try_from(
value: Expression,
) -> Result<ACOperatorKind, <ACOperatorKind as TryFrom<Expression>>::Error>
fn try_from( value: Expression, ) -> Result<ACOperatorKind, <ACOperatorKind as TryFrom<Expression>>::Error>
Auto Trait Implementations§
impl Freeze for ACOperatorKind
impl RefUnwindSafe for ACOperatorKind
impl Send for ACOperatorKind
impl Sync for ACOperatorKind
impl Unpin for ACOperatorKind
impl UnsafeUnpin for ACOperatorKind
impl UnwindSafe for ACOperatorKind
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
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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> ⓘ
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 moreimpl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 1 byte
Size for each variant:
And: 0 bytesOr: 0 bytesProduct: 0 bytesSum: 0 bytesMin: 0 bytesMax: 0 bytes