Trait exmex::prelude::Express

source ·
pub trait Express<'a, T>: Clone
where T: Clone,
{ type OperatorFactory: MakeOperators<T>; type LiteralMatcher: MatchLiteral; // Required methods fn eval(&self, vars: &[T]) -> ExResult<T>; fn eval_relaxed(&self, vars: &[T]) -> ExResult<T>; fn unparse(&self) -> &str; fn var_names(&self) -> &[String]; fn to_deepex( self ) -> ExResult<DeepEx<'a, T, Self::OperatorFactory, Self::LiteralMatcher>> where Self: Sized, T: DataType, <T as FromStr>::Err: Debug; fn from_deepex( deepex: DeepEx<'a, T, Self::OperatorFactory, Self::LiteralMatcher> ) -> ExResult<Self> where Self: Sized, T: DataType, <T as FromStr>::Err: Debug; fn parse(text: &'a str) -> ExResult<Self> where Self: Sized; }
Expand description

Expressions implementing this trait can be parsed from stings, evaluated for specific variable values, and unparsed, i.e., transformed into a string representation.

Required Associated Types§

Required Methods§

source

fn eval(&self, vars: &[T]) -> ExResult<T>

Evaluates an expression with the given variable values and returns the computed result.

Arguments
  • vars - Values of the variables of the expression; the n-th value corresponds to the n-th variable in alphabetical order. Thereby, only the first occurrence of the variable in the string is relevant. If an expression has been created by partial derivation, the variables always coincide with those of the antiderivatives even in cases where variables are irrelevant such as (x)'=1.
Errors

If the number of variables in the parsed expression are different from the length of the variable slice, we return an ExError.

source

fn eval_relaxed(&self, vars: &[T]) -> ExResult<T>

Evaluates an expression with the given variable values and returns the computed result. If more variables are passed than necessary the unnecessary ones are ignored.

Arguments
  • vars - Values of the variables of the expression; the n-th value corresponds to the n-th variable in alphabetical order. Thereby, only the first occurrence of the variable in the string is relevant. If an expression has been created by partial derivation, the variables always coincide with those of the antiderivatives even in cases where variables are irrelevant such as (x)'=1.
Errors

If the number of variables in the parsed expression is larger than the length of the variable slice, we return an ExError.

source

fn unparse(&self) -> &str

Creates an expression string that corresponds to the FlatEx instance.

use exmex::prelude::*;
let flatex = FlatEx::<f64>::parse("--sin ( z) +  {another var} + 1 + 2")?;
assert_eq!(format!("{}", flatex), "--sin ( z) +  {another var} + 1 + 2");
source

fn var_names(&self) -> &[String]

Returns the variables of the expression

source

fn to_deepex( self ) -> ExResult<DeepEx<'a, T, Self::OperatorFactory, Self::LiteralMatcher>>
where Self: Sized, T: DataType, <T as FromStr>::Err: Debug,

Conversion to a deep expression necessary for computations with expressions

source

fn from_deepex( deepex: DeepEx<'a, T, Self::OperatorFactory, Self::LiteralMatcher> ) -> ExResult<Self>
where Self: Sized, T: DataType, <T as FromStr>::Err: Debug,

source

fn parse(text: &'a str) -> ExResult<Self>
where Self: Sized,

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'a, T, OF, LM> Express<'a, T> for DeepEx<'a, T, OF, LM>
where T: DataType, OF: MakeOperators<T>, LM: MatchLiteral, <T as FromStr>::Err: Debug,

source§

impl<'a, T, OF, LM> Express<'a, T> for FlatEx<T, OF, LM>
where T: DataType, OF: MakeOperators<T>, LM: MatchLiteral, <T as FromStr>::Err: Debug,