Crate symb_anafis

Crate symb_anafis 

Source
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§

CompiledEvaluator
Compiled expression evaluator - thread-safe, reusable.
Context
Unified context for all symb_anafis operations.
CovarianceMatrix
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.
UserFunction
A user-defined function with optional body expression and partial derivatives.

Enums§

CovEntry
Covariance matrix entry - can be numeric or symbolic
DiffError
Errors that can occur during parsing and differentiation
SymbolError
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§

ArcExprExt
Symbol type and context for variable handling.
MathScalar
A trait comprising all operations required for mathematical scalars in the SymbAnaFis library.

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

Type Aliases§

BodyFn
Thread-safe symbolic body function for user-defined functions. Takes argument expressions (as Arc<Expr>) and returns the function body as an expression.
PartialFn
Thread-safe partial derivative function. Takes argument expressions (as Arc<Expr>) and returns the partial derivative expression.