Enum poi::Expr

source ·
pub enum Expr {
    Sym(Symbol),
    Ret(Value),
    EOp(Op, Box<Expr>, Box<Expr>),
    Tup(Vec<Expr>),
    List(Vec<Expr>),
}
Expand description

Function expression.

Variants§

§

Sym(Symbol)

A symbol that is used together with symbolic knowledge.

§

Ret(Value)

Some function that returns a value, ignoring the argument.

This can also be used to store values, since zero arguments is a value.

§

EOp(Op, Box<Expr>, Box<Expr>)

A binary operation on functions.

§

Tup(Vec<Expr>)

A tuple for more than one argument.

§

List(Vec<Expr>)

A list.

Implementations§

source§

impl Expr

source

pub fn display( &self, w: &mut Formatter<'_>, parens: bool, rule: bool ) -> Result<(), Error>

Used to display format with additional options.

source

pub fn needs_parens(&self, parent_op: &Symbol, left: bool) -> bool

Returns true if the expression needs parentheses, given parent operation and side.

source§

impl Expr

source

pub fn arity(&self) -> Option<usize>

Returns the arity of an expression.

Unfinished: This function requires analysis and unit testing.

source§

impl Expr

source

pub fn equivalences(&self, knowledge: &[Knowledge]) -> Vec<(Expr, usize)>

Returns available equivalences of the expression, using a knowledge base.

source

pub fn contains_nan(&self) -> bool

Returns true if expressions contains NaN (not a number).

source

pub fn eval(&self, knowledge: &[Knowledge]) -> Result<Expr, Error>

Evaluate an expression using a knowledge base.

This combines reductions and inlining of all symbols.

source

pub fn reduce_all(&self, knowledge: &[Knowledge]) -> Expr

Reduces an expression using a knowledge base, until it can not be reduces further.

source

pub fn reduce_eval_all(&self, knowledge: &[Knowledge], eval: bool) -> Expr

Reduces an expression using a knowledge base, until it can not be reduces further.

source

pub fn reduce(&self, knowledge: &[Knowledge]) -> Result<(Expr, usize), Error>

Reduces expression one step using a knowledge base.

source

pub fn reduce_eval( &self, knowledge: &[Knowledge], eval: bool ) -> Result<(Expr, usize), Error>

Reduces expression one step using a knowledge base.

When eval is set to true, the EqvEval variants are reduced.

source

pub fn inline_all(&self, knowledge: &[Knowledge]) -> Result<Expr, Error>

Inlines all symbols using a knowledge base.

Ignores missing definitions in domain constraints.

source

pub fn inline( &self, sym: &Symbol, knowledge: &[Knowledge] ) -> Result<Expr, Error>

Inline a symbol using a knowledge base.

source

pub fn has_constraint(&self, arity_args: usize) -> bool

Returns true if a function has any constraints, false if there are none constraints.

This is used in the following rules in the standard library, using no_constr:

  • ∀(f:!{}) => \true
  • f:!{}([x..]) => f{(: vec)}(x)
  • f:!{}(a)(a) <=> f{eq}(a)(a)

For example, to detect whether it is safe to insert a new constraint. This check is important because a constraint refers to one or more arguments. By introducing a new constraint that refers incorrectly to its argument, it leads to unsoundness.

A function has none constraints if it is applied enough times to cover existing constraints. This means the total arity of constraints is less or equal than the total arity of arguments.

To avoid unsoundness under uncertain edge cases, this function should return true. This is because the no_constr check fails to pattern match, which is safe, since inactive rules do not introduce unsoundness.

Unfinished: This function requires analysis and unit testing.

source

pub fn is_substitution(&self) -> bool

Returns true if expression is substitution.

source

pub fn has_non_constant_type_judgement(&self) -> bool

Returns true if expression has non-constant type judgement.

Trait Implementations§

source§

impl Add for Expr

§

type Output = Expr

The resulting type after applying the + operator.
source§

fn add(self, other: Expr) -> Expr

Performs the + operation. Read more
source§

impl Clone for Expr

source§

fn clone(&self) -> Expr

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 Debug for Expr

source§

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

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

impl Display for Expr

source§

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

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

impl Into<Expr> for &'static str

source§

fn into(self) -> Expr

Converts this type into the (usually inferred) input type.
source§

impl<T, U> Into<Expr> for (T, U)where T: Into<Expr>, U: Into<Expr>,

source§

fn into(self) -> Expr

Converts this type into the (usually inferred) input type.
source§

impl<T0, T1, T2> Into<Expr> for (T0, T1, T2)where T0: Into<Expr>, T1: Into<Expr>, T2: Into<Expr>,

source§

fn into(self) -> Expr

Converts this type into the (usually inferred) input type.
source§

impl Into<Expr> for Symbol

source§

fn into(self) -> Expr

Converts this type into the (usually inferred) input type.
source§

impl Into<Expr> for bool

source§

fn into(self) -> Expr

Converts this type into the (usually inferred) input type.
source§

impl Into<Expr> for f64

source§

fn into(self) -> Expr

Converts this type into the (usually inferred) input type.
source§

impl Mul for Expr

§

type Output = Expr

The resulting type after applying the * operator.
source§

fn mul(self, other: Expr) -> Expr

Performs the * operation. Read more
source§

impl PartialEq for Expr

source§

fn eq(&self, other: &Expr) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Expr

source§

fn partial_cmp(&self, other: &Expr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub for Expr

§

type Output = Expr

The resulting type after applying the - operator.
source§

fn sub(self, other: Expr) -> Expr

Performs the - operation. Read more
source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.