pub enum Expr {
Show 23 variants
Var(String),
Const(f64),
Neg(Box<Expr>),
Add(Box<Expr>, Box<Expr>),
Sub(Box<Expr>, Box<Expr>),
Mul(Box<Expr>, Box<Expr>),
Div(Box<Expr>, Box<Expr>),
Pow(Box<Expr>, Box<Expr>),
Sin(Box<Expr>),
Cos(Box<Expr>),
Tan(Box<Expr>),
Ln(Box<Expr>),
Exp(Box<Expr>),
Sqrt(Box<Expr>),
Abs(Box<Expr>),
Floor(Box<Expr>),
Ceil(Box<Expr>),
Atan(Box<Expr>),
Atan2(Box<Expr>, Box<Expr>),
Sum {
body: Box<Expr>,
var: String,
from: Box<Expr>,
to: Box<Expr>,
},
Product {
body: Box<Expr>,
var: String,
from: Box<Expr>,
to: Box<Expr>,
},
Integral {
body: Box<Expr>,
var: String,
},
Derivative {
body: Box<Expr>,
var: String,
},
}Expand description
A symbolic mathematical expression.
Variants§
Var(String)
Named variable: x, y, t, etc.
Const(f64)
Numeric constant.
Neg(Box<Expr>)
Negation: -a.
Add(Box<Expr>, Box<Expr>)
Addition: a + b.
Sub(Box<Expr>, Box<Expr>)
Subtraction: a - b.
Mul(Box<Expr>, Box<Expr>)
Multiplication: a * b.
Div(Box<Expr>, Box<Expr>)
Division: a / b.
Pow(Box<Expr>, Box<Expr>)
Power: a^b.
Sin(Box<Expr>)
Sine.
Cos(Box<Expr>)
Cosine.
Tan(Box<Expr>)
Tangent.
Ln(Box<Expr>)
Natural logarithm.
Exp(Box<Expr>)
Exponential: e^a.
Sqrt(Box<Expr>)
Square root.
Abs(Box<Expr>)
Absolute value.
Floor(Box<Expr>)
Floor function.
Ceil(Box<Expr>)
Ceiling function.
Atan(Box<Expr>)
Arctangent.
Atan2(Box<Expr>, Box<Expr>)
Atan2(y, x).
Sum
Summation: Σ(body, var, from, to).
Product
Product: Π(body, var, from, to).
Integral
Integral: ∫(body, var).
Derivative
Derivative: d/dvar(body).
Implementations§
Source§impl Expr
impl Expr
pub fn var(name: &str) -> Self
pub fn c(val: f64) -> Self
pub fn zero() -> Self
pub fn one() -> Self
pub fn pi() -> Self
pub fn e() -> Self
pub fn add(self, other: Expr) -> Expr
pub fn sub(self, other: Expr) -> Expr
pub fn mul(self, other: Expr) -> Expr
pub fn div(self, other: Expr) -> Expr
pub fn pow(self, exp: Expr) -> Expr
pub fn neg(self) -> Expr
pub fn sin(self) -> Expr
pub fn cos(self) -> Expr
pub fn tan(self) -> Expr
pub fn ln(self) -> Expr
pub fn exp(self) -> Expr
pub fn sqrt(self) -> Expr
pub fn abs(self) -> Expr
Sourcepub fn eval(&self, vars: &HashMap<String, f64>) -> f64
pub fn eval(&self, vars: &HashMap<String, f64>) -> f64
Evaluate the expression with variable bindings.
Sourcepub fn contains_var(&self, var: &str) -> bool
pub fn contains_var(&self, var: &str) -> bool
Whether this expression contains the given variable.
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Whether this is a constant (no variables).
Sourcepub fn substitute(&self, var: &str, replacement: &Expr) -> Expr
pub fn substitute(&self, var: &str, replacement: &Expr) -> Expr
Substitute a variable with an expression.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Count the number of nodes in the expression tree.
Trait Implementations§
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnsafeUnpin for Expr
impl UnwindSafe for Expr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.