Expand description
Math expression parser, compiler, and CSE engine.
Parses string expressions (e.g. "sin(x)*cos(y)") into an AST (Node),
applies constant folding (Node::pre_eval),
common-subexpression elimination (Node::cse),
and compiles to closures (Node::compile / Node::compile_multi)
for fast repeated evaluation over N-dimensional grids.
Variable names are resolved through the VarMap trait.
Macros§
- define_
ext_ f0 - Define a custom-constants enum implementing
ExtF0andFromStr. - define_
ext_ f1 - Define custom single-argument functions implementing
ExtF1andFromStr. - define_
ext_ f2 - Define custom two-argument functions implementing
ExtF2andFromStr.
Structs§
- Arith
Index Set - A type around
IndexSetproviding BigUint-like arithmetic. - Arith
Range From - An infinite iterator over
ArithIndexSetvalues starting from a given value. - Arith
Range Iter - A range of
ArithIndexSetvalues that can be iterated over. - Compiled
Expr Multi - Multi-level compiled expression with invariant groups and main expression.
- Index
SetIter - An iterator over the slot indices contained in an
IndexSet. - Invariant
Group - A group of dimension-invariant sub-expressions at a given nesting level.
Enums§
- Arith
Index SetTry From Error - Error type for
TryFromconversions involvingArithIndexSet. - Error
- Structured error type for expression parsing.
- F0
- Constants (PI, E).
- F1
- Single-argument math functions.
- F2
- Two-argument math functions (atan2, pow).
- Index
Set - A compact bitset for tracking slot indices in CSE.
- Lexer
Error Kind - Lexical analysis error details.
- Lexer
Token - Token produced by the lexer and consumed by the Pratt parser.
- NoExtF
- Zero-variant placeholder type for when no external functions/constants are used.
- Node
- AST node representing a mathematical expression.
- Parse
Error Kind - Parsing error details.
Traits§
- Cond
MulAdd - Fused multiply-add that respects the
fmafeature flag. - ExtF0
- Trait for custom constants.
- ExtF1
- Trait for custom single-argument functions.
- ExtF2
- Trait for custom two-argument functions.
- VarMap
- Trait for resolving variable names in expressions. Implementors define variable aliases and the indexed-variable naming scheme.
Functions§
- f0_list
- Return a comma-separated list of available constant names.
- f1_list
- Return a comma-separated list of available single-argument function names.
- f2_list
- Return a comma-separated list of available two-argument function names.
- parse
- Parse an expression string into a
NodeAST. - parse_
with_ ext - Parse an expression string into a
NodeAST, with support for custom extension functions. - validate
- Validate an expression string without producing a compiled result.
- validate_
with_ ext - Validate an expression string without producing a compiled result, with support for custom extension functions.
Type Aliases§
- Compiled
Expr - A compiled expression closure:
(vars, cse_cache) -> result.