pub struct Expression { /* private fields */ }Expand description
A symbolic expression in postfix notation
Implementations§
Source§impl Expression
impl Expression
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parse a well-formed postfix expression (e.g., “32s1+s*”).
This validates stack discipline while parsing, so malformed or incomplete
postfix strings return None instead of constructing an expression that
will later panic during formatting.
Sourcepub fn complexity(&self) -> u32
pub fn complexity(&self) -> u32
Get the complexity score
Sourcepub fn contains_x(&self) -> bool
pub fn contains_x(&self) -> bool
Check if this expression contains the variable x
Sourcepub fn count_symbol(&self, sym: Symbol) -> u32
pub fn count_symbol(&self, sym: Symbol) -> u32
Count occurrences of a symbol in this expression.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check if this is a valid complete expression (stack depth = 1)
This method is part of the public API for external consumers who may want to validate expressions before processing them.
Sourcepub fn push_with_table(&mut self, sym: Symbol, table: &SymbolTable)
pub fn push_with_table(&mut self, sym: Symbol, table: &SymbolTable)
Append a symbol using a symbol table for weight lookup
This is the table-driven version that uses per-run configuration instead of global overrides.
Sourcepub fn pop_with_table(&mut self, table: &SymbolTable) -> Option<Symbol>
pub fn pop_with_table(&mut self, table: &SymbolTable) -> Option<Symbol>
Remove the last symbol using a symbol table for weight lookup
This is the table-driven version that uses per-run configuration instead of global overrides.
Sourcepub fn to_postfix(&self) -> String
pub fn to_postfix(&self) -> String
Get the postfix string representation
Sourcepub fn try_to_infix(&self) -> Result<String, EvalError>
pub fn try_to_infix(&self) -> Result<String, EvalError>
Convert to infix notation for display
Uses proper operator precedence and associativity rules:
- Precedence levels (higher = tighter binding):
- 100: Atoms (constants, x, function calls)
- 9: Power (right-associative)
- 7: Unary operators (negation, reciprocal)
- 6: Multiplication, division
- 5: Addition, subtraction
- Right-associative operators (power) bind right-to-left
- Left-associative operators bind left-to-right
Convert to infix notation, returning Err(EvalError::StackUnderflow) if
the expression is malformed (e.g. a binary operator with no operands).
Prefer this over to_infix when the expression may come
from untrusted or user-provided input.
pub fn to_infix(&self) -> String
Sourcepub fn to_infix_with_table(&self, table: &SymbolTable) -> String
pub fn to_infix_with_table(&self, table: &SymbolTable) -> String
Convert to infix notation using a symbol table for display names
This is the table-driven version that uses per-run configuration instead of global overrides for symbol display names.
Sourcepub fn to_infix_with_format(&self, format: OutputFormat) -> String
pub fn to_infix_with_format(&self, format: OutputFormat) -> String
Convert to infix notation with specified format
Sourcepub fn operator_count(&self) -> usize
pub fn operator_count(&self) -> usize
Count the number of operators (non-atoms) in the expression
Sourcepub fn tree_depth(&self) -> usize
pub fn tree_depth(&self) -> usize
Compute the maximum depth of the expression tree
pub fn to_infix_mathematica(&self) -> String
pub fn to_infix_sympy(&self) -> String
Trait Implementations§
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl Default for Expression
impl Default for Expression
Source§impl Display for Expression
impl Display for Expression
Source§impl Hash for Expression
impl Hash for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
impl Eq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnsafeUnpin for Expression
impl UnwindSafe for Expression
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more