pub struct E(/* private fields */);Expand description
Symbolic expression wrapper.
Reference-counted (cheap to clone). All arithmetic operations auto-simplify.
Dereferences to Expr so all methods on Expr (e.g. Expr::diff,
Expr::eval, Expr::simplify) are available directly on E.
Implementations§
Methods from Deref<Target = Expr>§
Sourcepub fn diff(&self, var: impl AsVarName) -> E
pub fn diff(&self, var: impl AsVarName) -> E
Symbolically differentiate this expression with respect to a variable.
Applies the chain rule, product rule, and quotient rule automatically. The result is simplified.
Sourcepub fn eval(&self, vars: &HashMap<&str, f64>) -> Result<f64, String>
pub fn eval(&self, vars: &HashMap<&str, f64>) -> Result<f64, String>
Evaluate the expression numerically given variable bindings.
Returns Err if any symbol in the expression is not bound in vars.
Sourcepub fn subs(&self, var: impl AsVarName, replacement: &E) -> E
pub fn subs(&self, var: impl AsVarName, replacement: &E) -> E
Substitute all occurrences of the named variable with replacement.
var can be any [AsVarName] – a &str, a String, or an
E handle wrapping a Sym node. Returns a new expression
with the substitution applied throughout.
Sourcepub fn free_vars(&self) -> BTreeSet<String>
pub fn free_vars(&self) -> BTreeSet<String>
Collect all free (unbound) variable names in the expression.
Returns a sorted set of variable name strings.
Sourcepub fn diff_all(&self, vars: &[&str]) -> Vec<E>
pub fn diff_all(&self, vars: &[&str]) -> Vec<E>
Differentiate with respect to multiple variables, returning a vector.
Equivalent to calling Expr::diff for each variable in order.
Sourcepub fn to_latex(&self) -> String
pub fn to_latex(&self) -> String
Format the expression as LaTeX math notation.
Produces a string suitable for embedding in LaTeX documents, using
\frac, \sqrt, \sin, etc.
Sourcepub fn to_rust(&self, float_type: &str) -> String
pub fn to_rust(&self, float_type: &str) -> String
Generate Rust source code for this expression.
The float_type parameter (e.g. "f64") controls numeric literal
suffixes. Pass an empty string to omit type suffixes.
Sourcepub fn simplify(&self) -> E
pub fn simplify(&self) -> E
Apply algebraic simplification rules.
Performs constant folding, identity elimination (0+x=x, 1*x=x), like-term collection, power combination, fraction cancellation, and canonical ordering. Iterates until a fixed point is reached.
Sourcepub fn expand(&self) -> E
pub fn expand(&self) -> E
Expand products and integer powers over sums.
Distributes multiplication: (a + b) * c becomes a*c + b*c.
Integer powers up to 8 are expanded: (a + b)^3 becomes the full
multinomial expansion. The result is simplified afterwards.
Sourcepub fn collect(&self, var: impl AsVarName) -> E
pub fn collect(&self, var: impl AsVarName) -> E
Collect like terms containing var by structural match.
var can be any [AsVarName] – a &str, a String, or an
E handle wrapping a Sym node. Groups additive terms
that share var as a factor, summing their coefficients.
For example, a*x + b*x + c becomes (a + b)*x + c.