pub struct SymbolicExpressionSimplifier { /* private fields */ }Expand description
A multi-pass symbolic expression simplifier with rewriting rules and canonical forms.
Implementations§
Source§impl SymbolicExpressionSimplifier
impl SymbolicExpressionSimplifier
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new simplifier with the default configuration and built-in rules.
Sourcepub fn with_config(config: SesSimplifierConfig) -> Self
pub fn with_config(config: SesSimplifierConfig) -> Self
Create a new simplifier with a custom configuration.
Sourcepub fn add_rule(&mut self, rule: SesRewriteRule)
pub fn add_rule(&mut self, rule: SesRewriteRule)
Add a custom rewrite rule.
Sourcepub fn simplify(&mut self, expr: &SesExpr) -> SesExpr
pub fn simplify(&mut self, expr: &SesExpr) -> SesExpr
Simplify expr using multi-pass rewriting until fixpoint or max_passes.
Sourcepub fn evaluate(
&mut self,
expr: &SesExpr,
vars: &HashMap<String, f64>,
) -> Result<f64, SesError>
pub fn evaluate( &mut self, expr: &SesExpr, vars: &HashMap<String, f64>, ) -> Result<f64, SesError>
Evaluate expr numerically given variable bindings.
Sourcepub fn differentiate(&mut self, expr: &SesExpr, var: &str) -> SesExpr
pub fn differentiate(&mut self, expr: &SesExpr, var: &str) -> SesExpr
Compute the symbolic derivative of expr with respect to var.
Sourcepub fn substitute(
&self,
expr: &SesExpr,
var: &str,
replacement: &SesExpr,
) -> SesExpr
pub fn substitute( &self, expr: &SesExpr, var: &str, replacement: &SesExpr, ) -> SesExpr
Substitute all occurrences of var in expr with replacement.
Sourcepub fn contains_var(&self, expr: &SesExpr, var: &str) -> bool
pub fn contains_var(&self, expr: &SesExpr, var: &str) -> bool
Returns true if expr contains the variable var.
Sourcepub fn collect_vars(&self, expr: &SesExpr) -> HashSet<String>
pub fn collect_vars(&self, expr: &SesExpr) -> HashSet<String>
Collect all distinct variable names appearing in expr.
Sourcepub fn to_string(&self, expr: &SesExpr) -> String
pub fn to_string(&self, expr: &SesExpr) -> String
Convert expr to infix string notation with minimal parentheses.
Sourcepub fn parse(s: &str) -> Result<SesExpr, SesError>
pub fn parse(s: &str) -> Result<SesExpr, SesError>
Parse an infix expression string into a SesExpr.
Supports: numbers, identifiers (variables), +, -, *, /, ^,
unary -, and function calls sin, cos, exp, ln, sqrt, abs.
Parentheses and |...| for absolute value are also supported.
Sourcepub fn simplifier_stats(&self) -> SesSimplifierStats
pub fn simplifier_stats(&self) -> SesSimplifierStats
Return current simplifier statistics.
Sourcepub fn history(&self) -> &VecDeque<SesSimplificationStep>
pub fn history(&self) -> &VecDeque<SesSimplificationStep>
Return a reference to the simplification history.
Sourcepub fn clear_history(&mut self)
pub fn clear_history(&mut self)
Clear the simplification history.
Sourcepub fn config(&self) -> &SesSimplifierConfig
pub fn config(&self) -> &SesSimplifierConfig
Return a reference to the current configuration.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Return number of registered rules.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SymbolicExpressionSimplifier
impl !UnwindSafe for SymbolicExpressionSimplifier
impl Freeze for SymbolicExpressionSimplifier
impl Send for SymbolicExpressionSimplifier
impl Sync for SymbolicExpressionSimplifier
impl Unpin for SymbolicExpressionSimplifier
impl UnsafeUnpin for SymbolicExpressionSimplifier
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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