exprkit
A mathematical expression parser and evaluator library for Rust, inspired by the ExprTk C++ library.
Features
- Parse and evaluate mathematical expressions at runtime
- Variables, constants, and arrays
- User-defined functions
- Control flow (if/else, loops, switch)
- 100+ built-in mathematical functions
- String operations
- Vector/array operations with BLAS-like functions
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Basic Usage
use ;
Variables and Arrays
use ;
let mut symbol_table = new;
symbol_table.add_variable;
symbol_table.add_vector;
let mut expr = new;
expr.compile_with_symbol_table.unwrap;
assert_eq!; // 15 + 1 = 16
Control Flow
use ;
let mut symbol_table = new;
symbol_table.add_variable;
let mut expr = new;
expr.compile_with_symbol_table.unwrap;
assert_eq!;
User-Defined Functions
use ;
let mut symbol_table = new;
symbol_table.add_function;
symbol_table.add_variable;
let mut expr = new;
expr.compile_with_symbol_table.unwrap;
assert_eq!;
Built-in Functions
Mathematical Functions
sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, exp, log, log10, log2, sqrt, abs, ceil, floor, round, trunc, erf, erfc, pow, mod, min, max, clamp, hypot, atan2
Aggregation Functions
sum, avg, mul, min, max
Vector Functions
sum, avg, min, max, dot, axpy, axpby, axpyz, nrm2
Combinatorics
fib (Fibonacci), ncr (combinations), npr (permutations)
Statistical
erf, erfc, ncdf (normal CDF)
CLI Tool
The exprkit binary provides a command-line expression evaluator. Install with the cli feature:
Usage:
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
This library is inspired by ExprTk by Arash Partow.