# Crate math_engine

Expand description

Tools for parsing and manipulating mathematical expressions

Math-engine is a set of tools for manipulating mathematical expressions. These expressions may contain various operations and variables. The crate defines tools for building, evaluating, and operating on such expressions.

### Example

Math-engine allows you to build variable expressions and evaluate them within a context, i.e. a set of values for each variable.

``````let expr = Expression::parse("1.0 + 3.0 * (4.0 - x)").unwrap();
let ctx = Context:new().with_variable("x", 3.0);

let eval = expr.eval_with_context(&ctx).unwrap();

assert!(eval, 4.0);``````

Basic operators are implemented for allowing easy to use building:

``````let e1 = Expression::constant(3.0);
let e2 = Expression::variable("x");
let e = e1 + e2;

println!("{}", e);``````

Also, some useful operations are available for manipulating expressions, such as derivation and simplification by constant propagation:

``````let e1 = Expression("1.0 * y + 2.0 * x").unwrap();
let deriv = e1.derivate("x");
println!("{}", deriv);

let simp = deriv.constant_propagation().unwrap();
println!("{}", simp);``````