Struct exmex::prelude::FlatEx [−][src]
pub struct FlatEx<'a, T, OF = FloatOpsFactory<T>> where
T: Clone + Debug,
OF: MakeOperators<T>, { /* fields omitted */ }
Expand description
This is the core data type representing a flattened expression and the result of
parsing a string. We use flattened expressions to make efficient evaluation possible.
Simplified, a flat expression consists of a SmallVec
of nodes and a SmallVec
of operators that are applied
to the nodes in an order following operator priorities.
Creation of expressions is possible with the function parse
which is equivalent to
FlatEx::from_str
or with FlatEx::from_pattern
.
use exmex::prelude::*;
// create an expression by parsing a string
let expr = FlatEx::<f32>::from_str("sin(1+y)*x")?;
assert!((expr.eval(&[1.5, 2.0])? - (1.0 + 2.0 as f32).sin() * 1.5).abs() < 1e-6);
The argument &[1.5, 2.0]
in the call of eval
specifies the
variable values in the alphabetical order of the variable names.
In this example, we want to evaluate the expression for the varibale values x=2.0
and y=1.5
.
Trait Implementations
impl<'de: 'a, 'a, T: DataType + 'a, OF: MakeOperators<T>> Deserialize<'de> for FlatEx<'a, T, OF> where
<T as FromStr>::Err: Debug,
impl<'de: 'a, 'a, T: DataType + 'a, OF: MakeOperators<T>> Deserialize<'de> for FlatEx<'a, T, OF> where
<T as FromStr>::Err: Debug,
Deserialize this value from the given Serde deserializer. Read more
The expression is displayed as a string created by unparse
.
Parses a string into an expression that can be evaluated. Read more
Use custom number literals defined as regex to create an expression that can be evaluated. Read more
Use custom number literals defined as regex patterns to create an expression that can be evaluated. Read more
Evaluates an expression with the given variable values and returns the computed result. Read more
This method computes a new instance that is a partial derivative of
self
with default operators. Read more
Creates an expression string that corresponds to the FlatEx
instance. This is
not necessarily the input string. More precisely, Read more
impl<'a, T: PartialOrd, OF: PartialOrd> PartialOrd<FlatEx<'a, T, OF>> for FlatEx<'a, T, OF> where
T: Clone + Debug,
OF: MakeOperators<T>,
impl<'a, T: PartialOrd, OF: PartialOrd> PartialOrd<FlatEx<'a, T, OF>> for FlatEx<'a, T, OF> where
T: Clone + Debug,
OF: MakeOperators<T>,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<'a, T, OF> StructuralEq for FlatEx<'a, T, OF> where
T: Clone + Debug,
OF: MakeOperators<T>,
impl<'a, T, OF> StructuralPartialEq for FlatEx<'a, T, OF> where
T: Clone + Debug,
OF: MakeOperators<T>,
Auto Trait Implementations
impl<'a, T, OF> RefUnwindSafe for FlatEx<'a, T, OF> where
OF: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, OF> UnwindSafe for FlatEx<'a, T, OF> where
OF: UnwindSafe,
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more