Skip to main content

expr

Macro expr 

Source
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 e
  • I → imaginary unit i
  • oo, 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 base
  • diff(f, x) → formal derivative of f with respect to x (unevaluated)
  • factorial(n) → n!
  • binomial(n, k) or C(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!(x^2 + 2*x + 1);
let f = expr!(sin(x)^2 + cos(x)^2);

§Limitations

  • Implicit multiplication (2x) is not supported. Write 2*x.
  • Only the listed built-in functions are recognised.