logru_arithmetic

Struct ArithmeticResolver

Source
pub struct ArithmeticResolver {
    pub(crate) exp_map: HashMap<Sym, Exp>,
    pub(crate) pred_map: HashMap<Sym, Pred>,
}
Expand description

A special resolver for integer arithmetic. It provides special predicates which evaluate integer expressions:

  • is(A,B) - A=B
  • isNeg(A,B) - A=-B
  • isLess(A,B) - A<B
  • isGreater(A,B) - A>B
  • isLessEq(A,B) - A≤B
  • isGreaterEq(A,B) - A≥B
  • isDivider(A,B) - A mod B = 0

For all of those predicates, at least one of the arguments must be fully instantiated and must resolve to an integer value.

If the other argument also resolves to an integer, the predicate matches as expected.

is/2 and isNeg/2 accept an unbound variable as the other argument. That variable will get bound to the result of the corresponding computation.

In other cases (e.g. expression containing an unbound variable), the predicate fails. A message explaining details may be printed to the tracing log.

Expressions are represented using an integer term, or one of the following compound terms, which each take two expressions as arguments:

  • add/2: addition
  • sub/2: subtraction
  • mul/2: multiplication
  • div/2: division
  • rem/2: remainder
  • pow/2: power

Notably, free variables are not allowed in those expressions.

Integer overflow errors will fail the predicates.

§Examples

  • Computing the result of an expression and binding it to X:
    is(X, add(2, 3)).
  • Comparing 4 to the result of the expression (predicate succeeds):
    is(4, mul(2, 2)).
  • Comparing 4 to the result of the expression (predicate fails):
    is(4, add(1, 2)).

Fields§

§exp_map: HashMap<Sym, Exp>§pred_map: HashMap<Sym, Pred>

Implementations§

Source§

impl ArithmeticResolver

Source

pub fn new<T: SymbolStorage>(symbols: &mut T) -> Self

Source

pub(crate) fn eval_exp( &self, solution: &SolutionState, exp: TermId, ) -> Option<i64>

Source

pub(crate) fn resolve_with_args( &mut self, context: &mut ResolveContext<'_>, left: TermId, right: TermId, op: impl Fn(i64, i64) -> bool, var_generator: fn(_: i64) -> VariableSolutions, ) -> Option<Resolved<<Self as Resolver>::Choice>>

Source

pub(crate) fn resolve_both_sides_with_args( &mut self, context: &mut ResolveContext<'_>, left: TermId, right: TermId, op: impl Fn(i64, i64) -> bool, var_generator: fn(_: i64) -> VariableSolutions, ) -> Option<Resolved<<Self as Resolver>::Choice>>

Source

pub(crate) fn resolve_is( &mut self, args: ArgRange, context: &mut ResolveContext<'_>, ) -> Option<Resolved<<Self as Resolver>::Choice>>

Source

pub(crate) fn resolve_neg( &mut self, args: ArgRange, context: &mut ResolveContext<'_>, ) -> Option<Resolved<<Self as Resolver>::Choice>>

Source

pub(crate) fn resolve_instantiated_op2( &mut self, args: ArgRange, context: &mut ResolveContext<'_>, op: fn(_: i64, _: i64) -> bool, ) -> Option<Resolved<<Self as Resolver>::Choice>>

Source

pub(crate) fn resolve_range( &mut self, args: ArgRange, context: &mut ResolveContext<'_>, ) -> Option<Resolved<<Self as Resolver>::Choice>>

Trait Implementations§

Source§

impl Clone for ArithmeticResolver

Source§

fn clone(&self) -> ArithmeticResolver

Returns a copy 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 Resolver for ArithmeticResolver

Source§

type Choice = (Var, DynIter<dyn Iterator<Item = i64>>)

Source§

fn resolve( &mut self, _goal_id: TermId, AppTerm: AppTerm, context: &mut ResolveContext<'_>, ) -> Option<Resolved<Self::Choice>>

Source§

fn resume( &mut self, choice: &mut Self::Choice, _goal_id: TermId, context: &mut ResolveContext<'_>, ) -> bool

Auto Trait Implementations§

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, dst: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<R> ResolverExt for R
where R: Resolver,

§

fn or_else<R>(self, other: R) -> OrElse<Self, R>
where R: Resolver, Self: Sized,

First try the current resolver, and if that fails, use the other one.
§

fn by_ref(&mut self) -> &mut Self

Use the resolver by reference, rather than by value.
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more