pub enum SymExpr {
Primary(Primary),
Add(Vec<SymExpr>),
Mul(Vec<SymExpr>),
Exp(Box<SymExpr>, Box<SymExpr>),
}Expand description
A mathematical expression with information about its terms and factors.
This type should be distinguished from the cas_parser::parser::ast::Expr type, which is
produced by cas_parser. The main difference is that this type flattens out the tree
structure. For example, the expression x + (y + z) would be represented internally as a
single SymExpr::Add node with three children, x, y, and z.
For more information about this type, see the module-level documentation.
Variants§
Primary(Primary)
A single term or factor.
Add(Vec<SymExpr>)
Multiple terms added together.
Mul(Vec<SymExpr>)
Multiple factors multiplied together.
Exp(Box<SymExpr>, Box<SymExpr>)
An expression raised to a power.
Implementations§
Source§impl SymExpr
impl SymExpr
Sourcepub fn cmp_precedence(&self, other: &Self) -> Ordering
pub fn cmp_precedence(&self, other: &Self) -> Ordering
Returns true if the given expression has lower precedence than this expression.
This is used to determine if parentheses are needed around the given expression when printing.
Sourcepub fn as_integer(&self) -> Option<&Integer>
pub fn as_integer(&self) -> Option<&Integer>
If the expression is a Primary::Integer, returns a reference to the contained integer.
Sourcepub fn into_integer(self) -> Option<Integer>
pub fn into_integer(self) -> Option<Integer>
If the expression is a Primary::Integer, returns the contained integer.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if the expression is a Primary::Integer.
Sourcepub fn is_integer_recip(&self) -> bool
pub fn is_integer_recip(&self) -> bool
Returns true if the expression is a Primary::Integer raised to the power of -1.
Sourcepub fn as_integer_recip(&self) -> Option<&Integer>
pub fn as_integer_recip(&self) -> Option<&Integer>
If the expression is a Primary::Integer raised to the power of -1, returns a reference to
the contained integer (the denominator of the fraction).
Sourcepub fn into_integer_recip(self) -> Option<Integer>
pub fn into_integer_recip(self) -> Option<Integer>
If the expression is a Primary::Integer raised to the power of -1, returns the contained
integer (the denominator of the fraction).
Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
Returns true if the expression is a Primary::Float.
Sourcepub fn as_symbol(&self) -> Option<&str>
pub fn as_symbol(&self) -> Option<&str>
If the expression is a Primary::Symbol, returns a reference to the contained symbol.
Sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
Returns the square root of this expression. No simplification is done.
Sourcepub fn post_order_iter(&self) -> ExprIter<'_>
pub fn post_order_iter(&self) -> ExprIter<'_>
Returns an iterator that traverses the tree of expressions in left-to-right post-order (i.e. depth-first).
Trait Implementations§
Source§impl Add for SymExpr
Adds two SymExprs together. No simplification is done, except for the case where the
operands are a mix of Primary and / or SymExpr::Add, in which case both are combined in
one list of terms (flattening).
impl Add for SymExpr
Adds two SymExprs together. No simplification is done, except for the case where the
operands are a mix of Primary and / or SymExpr::Add, in which case both are combined in
one list of terms (flattening).
Source§impl AddAssign for SymExpr
impl AddAssign for SymExpr
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Hash for SymExpr
impl Hash for SymExpr
We also manage to hash SymExpr::Add and SymExpr::Mul in O(n) time by using a
commutative hashing function, unaffected by the order of the elements.
Source§impl Mul for SymExpr
Multiplies two SymExprs together. No simplification is done, except for the case where the
operands are a mix of Primary and / or SymExpr::Mul, in which case both are combined in
one list of factors (flattening).
impl Mul for SymExpr
Multiplies two SymExprs together. No simplification is done, except for the case where the
operands are a mix of Primary and / or SymExpr::Mul, in which case both are combined in
one list of factors (flattening).
Source§impl MulAssign for SymExpr
impl MulAssign for SymExpr
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl Neg for SymExpr
Multiplies this expression by -1. No simplification is done, except for the case where the
expression is a numeric Primary, in which case the number is negated.
impl Neg for SymExpr
Multiplies this expression by -1. No simplification is done, except for the case where the
expression is a numeric Primary, in which case the number is negated.
Source§impl PartialEq for SymExpr
Checks if two expressions are strictly equal.
impl PartialEq for SymExpr
Checks if two expressions are strictly equal.
Two expressions are strictly equal if:
- They are the same type of expression (i.e. both
SymExpr::Primary, bothSymExpr::Add, etc.). - If both are
SymExpr::Primary, both expressions must have strictly equal values. - If both are
SymExpr::AddorSymExpr::Mul, both expressions must have strictly equal terms / factors, in any order. - If both are
SymExpr::Exp, both expressions must have strictly equal base and exponent.
For more information about strict equality, see the module-level documentation.