pub trait Express<'a, T>: Clonewhere
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§
type OperatorFactory: MakeOperators<T>
type LiteralMatcher: MatchLiteral
Required Methods§
sourcefn eval(&self, vars: &[T]) -> ExResult<T>
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
.
sourcefn eval_relaxed(&self, vars: &[T]) -> ExResult<T>
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
.
sourcefn unparse(&self) -> &str
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");
sourcefn to_deepex(
self
) -> ExResult<DeepEx<'a, T, Self::OperatorFactory, Self::LiteralMatcher>>
fn to_deepex( self ) -> ExResult<DeepEx<'a, T, Self::OperatorFactory, Self::LiteralMatcher>>
Conversion to a deep expression necessary for computations with expressions