Skip to main content

E

Struct E 

Source
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§

Source§

impl E

Source

pub fn symbols(&self) -> HashSet<String>

Collect all symbol names referenced in this expression.

Source

pub fn substitute(&self, subs: &[(E, E)]) -> E

Substitute symbols in this expression. Each pair (from, to) replaces occurrences of from with to. Returns a new expression.

Methods from Deref<Target = Expr>§

Source

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.

Source

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.

Source

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.

Source

pub fn free_vars(&self) -> BTreeSet<String>

Collect all free (unbound) variable names in the expression.

Returns a sorted set of variable name strings.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Add<E> for f64

Source§

type Output = E

The resulting type after applying the + operator.
Source§

fn add(self, rhs: E) -> E

Performs the + operation. Read more
Source§

impl Add<E> for i64

Source§

type Output = E

The resulting type after applying the + operator.
Source§

fn add(self, rhs: E) -> E

Performs the + operation. Read more
Source§

impl Add<f64> for E

Source§

type Output = E

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> E

Performs the + operation. Read more
Source§

impl Add<i64> for E

Source§

type Output = E

The resulting type after applying the + operator.
Source§

fn add(self, rhs: i64) -> E

Performs the + operation. Read more
Source§

impl Add for E

Source§

type Output = E

The resulting type after applying the + operator.
Source§

fn add(self, rhs: E) -> E

Performs the + operation. Read more
Source§

impl AsRef<Expr> for E

Source§

fn as_ref(&self) -> &Expr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsVarName for &E

Source§

fn var_name(&self) -> &str

Return the variable name as a string slice.
Source§

fn var_expr(&self) -> E

Return an E representing this variable. Default: build a fresh Sym node from var_name().
Source§

impl AsVarName for E

Source§

fn var_name(&self) -> &str

Return the variable name as a string slice.
Source§

fn var_expr(&self) -> E

Return an E representing this variable. Default: build a fresh Sym node from var_name().
Source§

impl Clone for E

Source§

fn clone(&self) -> E

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for E

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for E

Source§

type Target = Expr

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Expr

Dereferences the value.
Source§

impl Display for E

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<E> for f64

Source§

type Output = E

The resulting type after applying the / operator.
Source§

fn div(self, rhs: E) -> E

Performs the / operation. Read more
Source§

impl Div<E> for i64

Source§

type Output = E

The resulting type after applying the / operator.
Source§

fn div(self, rhs: E) -> E

Performs the / operation. Read more
Source§

impl Div<E> for vect2sym

Source§

type Output = vect2sym

The resulting type after applying the / operator.
Source§

fn div(self, rhs: E) -> vect2sym

Performs the / operation. Read more
Source§

impl Div<f64> for E

Source§

type Output = E

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> E

Performs the / operation. Read more
Source§

impl Div<i64> for E

Source§

type Output = E

The resulting type after applying the / operator.
Source§

fn div(self, rhs: i64) -> E

Performs the / operation. Read more
Source§

impl Div for E

Source§

type Output = E

The resulting type after applying the / operator.
Source§

fn div(self, rhs: E) -> E

Performs the / operation. Read more
Source§

impl From<f64> for E

Source§

fn from(v: f64) -> E

Converts to this type from the input type.
Source§

impl From<i32> for E

Source§

fn from(v: i32) -> E

Converts to this type from the input type.
Source§

impl From<i64> for E

Source§

fn from(v: i64) -> E

Converts to this type from the input type.
Source§

impl FromStr for E

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<E, ParseError>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for E

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<E> for SymMat

Source§

type Output = SymMat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> SymMat

Performs the * operation. Read more
Source§

impl Mul<E> for SymVec

Source§

type Output = SymVec

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> SymVec

Performs the * operation. Read more
Source§

impl Mul<E> for f64

Source§

type Output = E

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> E

Performs the * operation. Read more
Source§

impl Mul<E> for i64

Source§

type Output = E

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> E

Performs the * operation. Read more
Source§

impl Mul<E> for vect2sym

Source§

type Output = vect2sym

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> vect2sym

Performs the * operation. Read more
Source§

impl Mul<E> for vect3sym

Source§

type Output = vect3sym

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> vect3sym

Performs the * operation. Read more
Source§

impl Mul<SymMat> for E

Source§

type Output = SymMat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SymMat) -> SymMat

Performs the * operation. Read more
Source§

impl Mul<SymVec> for E

Source§

type Output = SymVec

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SymVec) -> SymVec

Performs the * operation. Read more
Source§

impl Mul<f64> for E

Source§

type Output = E

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> E

Performs the * operation. Read more
Source§

impl Mul<i64> for E

Source§

type Output = E

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: i64) -> E

Performs the * operation. Read more
Source§

impl Mul<vect2sym> for E

Source§

type Output = vect2sym

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vect2sym) -> vect2sym

Performs the * operation. Read more
Source§

impl Mul<vect3sym> for E

Source§

type Output = vect3sym

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: vect3sym) -> vect3sym

Performs the * operation. Read more
Source§

impl Mul for E

Source§

type Output = E

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> E

Performs the * operation. Read more
Source§

impl Neg for E

Source§

type Output = E

The resulting type after applying the - operator.
Source§

fn neg(self) -> E

Performs the unary - operation. Read more
Source§

impl PartialEq for E

Source§

fn eq(&self, other: &E) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<E> for f64

Source§

type Output = E

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: E) -> E

Performs the - operation. Read more
Source§

impl Sub<E> for i64

Source§

type Output = E

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: E) -> E

Performs the - operation. Read more
Source§

impl Sub<f64> for E

Source§

type Output = E

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> E

Performs the - operation. Read more
Source§

impl Sub<i64> for E

Source§

type Output = E

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: i64) -> E

Performs the - operation. Read more
Source§

impl Sub for E

Source§

type Output = E

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: E) -> E

Performs the - operation. Read more
Source§

impl Eq for E

Source§

impl StructuralPartialEq for E

Auto Trait Implementations§

§

impl Freeze for E

§

impl RefUnwindSafe for E

§

impl !Send for E

§

impl !Sync for E

§

impl Unpin for E

§

impl UnsafeUnpin for E

§

impl UnwindSafe for E

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.