Expand description
Symbolic Differentiation Library
A fast, focused Rust library for symbolic differentiation.
§Features
- Context-aware parsing with known symbols and custom functions
- Extensible simplification framework
- Support for built-in functions (sin, cos, ln, exp)
- Implicit function handling
- Partial derivative notation
- Type-safe expression building with operator overloading
- Builder pattern API for differentiation and simplification
§Usage Examples
§String-based API (original)
use symb_anafis::diff;
let result = diff("x^2", "x", &[], None).unwrap();
assert_eq!(result, "2*x");§Type-safe API (new)
use symb_anafis::{symb, Diff};
let x = symb("x");
let expr = x.pow(2.0) + x.sin();
let derivative = Diff::new().differentiate(&expr, &x).unwrap();
// derivative is: 2*x + cos(x)Modules§
- visitor
- Expression visitor pattern for AST traversal
Macros§
- rule
- Macro to define a simplification rule with minimal boilerplate
- rule_
arc - Macro to define a simplification rule that returns
Option<Arc<Expr>>directly. This avoids unnecessary wrapping when the result is already an Arc. - rule_
with_ helpers - Macro for rules with helpers that wrap result in Arc
- rule_
with_ helpers_ arc - Macro for rules with helpers that return
Option<Arc<Expr>>directly
Structs§
- Compiled
Evaluator - Compiled expression evaluator - thread-safe, reusable.
- Context
- Unified context for all
symb_anafisoperations. - Covariance
Matrix - Covariance matrix for uncertainty propagation
- Diff
- Builder for differentiation operations
- Dual
- Dual number for automatic differentiation
- Expr
- A symbolic mathematical expression.
- Simplify
- Builder for simplification operations
- Span
- Source location span for error reporting Represents a range of characters in the input string
- Symbol
- Symbol type and context for variable handling.
- User
Function - A user-defined function with optional body expression and partial derivatives.
Enums§
- CovEntry
- Covariance matrix entry - can be numeric or symbolic
- Diff
Error - Errors that can occur during parsing and differentiation
- Symbol
Error - Errors that can occur during symbol operations
Constants§
- DEFAULT_
MAX_ DEPTH - Default maximum AST depth. This limit prevents stack overflow from deeply nested expressions.
- DEFAULT_
MAX_ NODES - Default maximum AST node count. This limit prevents memory exhaustion from extremely large expressions.
Traits§
- ArcExpr
Ext - Symbol type and context for variable handling.
- Math
Scalar - A trait comprising all operations required for mathematical scalars
in the
SymbAnaFislibrary.
Functions§
- clear_
symbols - Symbol type and context for variable handling.
- diff
- Main API function for symbolic differentiation
- evaluate_
str - Evaluate a formula string with given variable values Performs partial evaluation - returns simplified expression string
- gradient
- Compute the gradient of an expression with respect to multiple variables Returns a vector of partial derivatives [∂f/∂x₁, ∂f/∂x₂, …]
- gradient_
str - Compute gradient from a formula string
- hessian
- Compute the Hessian matrix of an expression Returns a 2D vector of second partial derivatives H[i][j] = ∂²f/∂xᵢ∂xⱼ
- hessian_
str - Compute Hessian matrix from a formula string
- jacobian
- Compute the Jacobian matrix of a vector of expressions
Returns a 2D vector where
J[i][j]= ∂fᵢ/∂xⱼ - jacobian_
str - Compute Jacobian matrix from formula strings
- parse
- Parse a formula string into an expression AST
- relative_
uncertainty - Compute relative uncertainty expression:
σ_f/ |f| - remove_
symbol - Symbol type and context for variable handling.
- simplify
- Simplify a mathematical expression
- symb
- Symbol type and context for variable handling.
- symb_
get - Symbol type and context for variable handling.
- symb_
new - Symbol type and context for variable handling.
- symbol_
count - Symbol type and context for variable handling.
- symbol_
exists - Symbol type and context for variable handling.
- symbol_
names - Symbol type and context for variable handling.
- uncertainty_
propagation - Compute the uncertainty propagation expression