expr!() { /* proc-macro */ }Expand description
Build a symbolic expression using natural math syntax.
All identifiers are treated as existing Rust variables of type Ex
(or &Ex). They are automatically borrowed with &.
§Syntax
- Operators:
+,-,*,/,^(power) - Functions:
sin(x),cos(x),tan(x),asin(x),acos(x),atan(x),sinh(x),cosh(x),tanh(x),exp(x),ln(x),sqrt(x),abs(x) - Parentheses for grouping
- Integer literals
- Unary minus:
-x
§Constants
The following identifiers are recognized as mathematical constants:
pi,Pi,PI→ πE→ Euler’s number eI→ imaginary unit ioo,inf→ positive infinity
§Rationals
1/2, 3/4, etc. produce exact rational numbers (not Rust integer division).
§Multi-argument functions
log(x, base)→ logarithm of x with given basediff(f, x)→ formal derivative of f with respect to x (unevaluated)factorial(n)→ n!binomial(n, k)orC(n, k)→ binomial coefficient C(n,k)
§Examples
ⓘ
use symplex::prelude::*;
use symplex::expr;
let ctx = Context::new();
syms!(ctx; x, y);
let e = expr!(ctx, x^2 + 2*x + 1);
let f = expr!(ctx, sin(x)^2 + cos(x)^2);§Limitations
- Implicit multiplication (
2x) is not supported. Write2*x. - Only the listed built-in functions are recognised.