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
impl Expr
sourcepub fn display(
&self,
w: &mut Formatter<'_>,
parens: bool,
rule: bool
) -> Result<(), Error>
pub fn display( &self, w: &mut Formatter<'_>, parens: bool, rule: bool ) -> Result<(), Error>
Used to display format with additional options.
sourcepub fn needs_parens(&self, parent_op: &Symbol, left: bool) -> bool
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
impl Expr
sourcepub fn equivalences(&self, knowledge: &[Knowledge]) -> Vec<(Expr, usize)>
pub fn equivalences(&self, knowledge: &[Knowledge]) -> Vec<(Expr, usize)>
Returns available equivalences of the expression, using a knowledge base.
sourcepub fn contains_nan(&self) -> bool
pub fn contains_nan(&self) -> bool
Returns true
if expressions contains NaN (not a number).
sourcepub fn eval(&self, knowledge: &[Knowledge]) -> Result<Expr, Error>
pub fn eval(&self, knowledge: &[Knowledge]) -> Result<Expr, Error>
Evaluate an expression using a knowledge base.
This combines reductions and inlining of all symbols.
sourcepub fn reduce_all(&self, knowledge: &[Knowledge]) -> Expr
pub fn reduce_all(&self, knowledge: &[Knowledge]) -> Expr
Reduces an expression using a knowledge base, until it can not be reduces further.
sourcepub fn reduce_eval_all(&self, knowledge: &[Knowledge], eval: bool) -> Expr
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.
sourcepub fn reduce(&self, knowledge: &[Knowledge]) -> Result<(Expr, usize), Error>
pub fn reduce(&self, knowledge: &[Knowledge]) -> Result<(Expr, usize), Error>
Reduces expression one step using a knowledge base.
sourcepub fn reduce_eval(
&self,
knowledge: &[Knowledge],
eval: bool
) -> Result<(Expr, usize), Error>
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.
sourcepub fn inline_all(&self, knowledge: &[Knowledge]) -> Result<Expr, Error>
pub fn inline_all(&self, knowledge: &[Knowledge]) -> Result<Expr, Error>
Inlines all symbols using a knowledge base.
Ignores missing definitions in domain constraints.
sourcepub fn inline(
&self,
sym: &Symbol,
knowledge: &[Knowledge]
) -> Result<Expr, Error>
pub fn inline( &self, sym: &Symbol, knowledge: &[Knowledge] ) -> Result<Expr, Error>
Inline a symbol using a knowledge base.
sourcepub fn has_constraint(&self, arity_args: usize) -> bool
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.
sourcepub fn is_substitution(&self) -> bool
pub fn is_substitution(&self) -> bool
Returns true
if expression is substitution.
sourcepub fn has_non_constant_type_judgement(&self) -> bool
pub fn has_non_constant_type_judgement(&self) -> bool
Returns true
if expression has non-constant type judgement.
Trait Implementations§
source§impl<T0, T1, T2> Into<Expr> for (T0, T1, T2)where
T0: Into<Expr>,
T1: Into<Expr>,
T2: Into<Expr>,
impl<T0, T1, T2> Into<Expr> for (T0, T1, T2)where T0: Into<Expr>, T1: Into<Expr>, T2: Into<Expr>,
source§impl PartialEq for Expr
impl PartialEq for Expr
source§impl PartialOrd for Expr
impl PartialOrd for Expr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more