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.

Implementations

Executes calculations that can trivially be executed, e.g., two numbers that need to be multiplied anyway.

Parses into an expression without compilation. Allow slightly faster direct evaluation of strings.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

The expression is displayed as a string created by unparse.

Formats the value using the given formatter. Read more

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. Read more

This function frees some memory. After calling partial memory might be re-allocated. Read more

Returns the number of variables of the expression

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.