Fast symbolic differentiation library - Rust-powered Python bindings
Project description
SymbAnaFis
High-performance symbolic mathematics written in Rust with Python bindings.
🚀 18-21x faster parsing and 4-43x faster simplification than SymPy
Installation
# Python
pip install symb-anafis
# Rust
cargo add symb_anafis
Quick Start
Python
import symb_anafis
# Differentiate
result = symb_anafis.diff("x^3 + sin(x)", "x")
# → "3*x^2 + cos(x)"
# Simplify
result = symb_anafis.simplify("sin(x)^2 + cos(x)^2")
# → "1"
# With constants
result = symb_anafis.diff("a*x^2", "x", fixed_vars=["a"])
# → "2*a*x"
Rust
use symb_anafis::{diff, simplify, symb};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// String API
let result = diff("sin(x) * x", "x", None, None)?;
println!("{result}"); // cos(x)*x + sin(x)
// Type-safe API (Symbol is Copy - no clone needed!)
let x = symb("x");
let expr = x.pow(2.0) + x.sin(); // x² + sin(x)
println!("{}", expr.to_latex()); // x^{2} + \sin(x)
Ok(())
}
Features
| Feature | Description |
|---|---|
| Fast Differentiation | Product, chain, quotient rules for all standard functions |
| Powerful Simplification | Trig identities, constant folding, algebraic factoring |
| Vector Calculus | Gradient, Hessian, Jacobian computation |
| Uncertainty Propagation | Full covariance matrix support |
| Beautiful Output | LaTeX (to_latex()) and Unicode (to_unicode()) export |
| Parallel Evaluation | Batch evaluation via Rayon (optional parallel feature) |
| 50+ Built-in Functions | Trig, hyperbolic, Bessel, gamma, polygamma, zeta, error functions |
Core API
Differentiation
// String API
diff("a * x^2", "x", Some(&["a"]), None)?; // 2*a*x
// Builder API for fine-grained control
Diff::new()
.domain_safe(true)
.max_depth(200)
.diff_str("sqrt(x^2)", "x")?; // abs(x)/x with domain_safe
Simplification
simplify("x^2 + 2*x + 1", None, None)?; // (x+1)^2
// Trigonometric identities
simplify("sin(x)^2 + cos(x)^2", None, None)?; // 1
Evaluation
use symb_anafis::evaluate_str;
// Full evaluation
evaluate_str("x*y + 1", &[("x", 3.0), ("y", 2.0)])?; // "7"
// Partial evaluation (y stays symbolic)
evaluate_str("x*y + 1", &[("x", 3.0)])?; // "3*y + 1"
Vector Calculus
use symb_anafis::{gradient_str, hessian_str, jacobian_str};
gradient_str("x^2 + y^2", &["x", "y"])?; // ["2*x", "2*y"]
hessian_str("x^2*y", &["x", "y"])?; // [["2*y", "2*x"], ["2*x", "0"]]
Uncertainty Propagation
use symb_anafis::{symb, uncertainty_propagation};
let x = symb("x");
let y = symb("y");
let expr = x + y;
let sigma = uncertainty_propagation(&expr, &["x", "y"], None)?;
// → sqrt(sigma_x^2 + sigma_y^2)
Examples
Physics: RC Circuit
# V(t) = V₀ · e^(-t/RC)
current = symb_anafis.diff(
"V0 * exp(-t / (R * C))",
"t",
fixed_vars=["V0", "R", "C"]
)
Statistics: Normal PDF Derivative
pdf = "exp(-(x - mu)^2 / (2 * sigma^2)) / sqrt(2 * pi * sigma^2)"
derivative = symb_anafis.diff(pdf, "x", fixed_vars=["mu", "sigma"])
Custom Functions
use symb_anafis::{Diff, Expr};
let diff = Diff::new()
.custom_derivative("f", |inner, _var, inner_prime| {
// d/dx[f(u)] = 2u · u' (chain rule automatic!)
Expr::number(2.0) * inner.clone() * inner_prime.clone()
});
diff.diff_str("f(x^2)", "x")?; // 4*x^3
Built-in Functions
| Category | Functions |
|---|---|
| Trig | sin, cos, tan, cot, sec, csc + inverses |
| Hyperbolic | sinh, cosh, tanh, coth, sech, csch + inverses |
| Exp/Log | exp, ln, log, log10, log2 |
| Roots | sqrt, cbrt |
| Special | gamma, digamma, trigamma, polygamma, beta, erf, erfc |
| Bessel | besselj, bessely, besseli, besselk |
| Other | zeta, LambertW, abs, sign, sinc |
Expression Syntax
x + y # Addition
x - y # Subtraction
x * y # Multiplication (also: 2x, xy)
x / y # Division
x^2 # Power
sin(x) # Function call
pi, e # Built-in constants
Performance
Benchmarked against SymPy 1.14.0 (Python bindings):
| Operation | Speedup |
|---|---|
| Parsing | 17-21x faster |
| Simplification | 4-43x faster |
See benches/BENCHMARK_COMPARISON.md for detailed comparisons with SymPy and Symbolica.
Configuration
Configure safety limits and domain-safe mode using the builder pattern:
use symb_anafis::{Diff, Simplify};
// Differentiation with limits
Diff::new()
.max_depth(200) // AST depth limit
.max_nodes(50000) // Node count limit
.domain_safe(true) // Domain-safe simplification
.diff_str("sqrt(x^2)", "x")?; // → abs(x)/x
// Simplification with limits
Simplify::new()
.domain_safe(true)
.simplify_str("sqrt(x^2)")?; // → abs(x)
Domain-safe mode prevents unsafe simplifications:
sqrt(x^2)→abs(x)(instead of justx)
Documentation
- API Reference - Complete function documentation
- Benchmark Comparison - Performance vs SymPy/Symbolica
- docs.rs - Rust API documentation
Building from Source
# Clone
git clone https://github.com/CokieMiner/SymbAnaFis.git
cd SymbAnaFis
# Python bindings
pip install maturin
maturin develop --release
# Rust
cargo build --release
cargo test --release
License
MIT License - see LICENSE
Citation
@software{symb_anafis,
author = {Pedro Martins},
title = {SymbAnaFis: Fast Symbolic Differentiation Library},
url = {https://github.com/CokieMiner/SymbAnaFis},
year = {2025}
}
Built with ❤️ in Rust 🚀
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file symb_anafis-0.3.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 627.5 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cac8e5b574a277799d4146560c1aef483319f738eede6a2724ec7a1595689f0b
|
|
| MD5 |
5210a72f04cbcdfe2aaf611f92fe6d8f
|
|
| BLAKE2b-256 |
c9837ae0c38cf466542b88295cc24e39cc41bfa5f23d97d42f8c440e0b73e7e2
|
File details
Details for the file symb_anafis-0.3.0-cp314-cp314-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp314-cp314-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 814.8 kB
- Tags: CPython 3.14, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3570c44ecad762b7b2afe1051566cd358b6d276bc90885e7be7ba3ac3f1daed
|
|
| MD5 |
5ee64c6798cf552b6ab201118f6c5b64
|
|
| BLAKE2b-256 |
2c2d5f0b8fdf826f9c6bd942e4da1c015280a2aaf0938c4c947048541ddcddd7
|
File details
Details for the file symb_anafis-0.3.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 721.9 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a04a3e099a0dfc54c2ccdd5f9c5a58af73373bd1fc647f75ea598f6725c20531
|
|
| MD5 |
5e0106193613029b9245a75b02d54637
|
|
| BLAKE2b-256 |
0ac810d687f65eb95c8db2f0d5d47fb05fa59ac7a6b83783719db6a38d47fc0a
|
File details
Details for the file symb_anafis-0.3.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 630.6 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30f25aa592dcc6ede8156379397384143dd57465eadab818adf5ce069fcfa96a
|
|
| MD5 |
19c513807f30f4c0821697033852e394
|
|
| BLAKE2b-256 |
9c08f0f2a75767dce699419c8acbac3004a9ad3b4dd8aea02fd8fbd8aa1ed095
|
File details
Details for the file symb_anafis-0.3.0-cp313-cp313-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp313-cp313-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 819.7 kB
- Tags: CPython 3.13, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40c4c29cf20215a340700ae2766f718ccfe39d2c9082b65d747c3397c93fbb4f
|
|
| MD5 |
371b9166181040800cc1947d97e0ab1d
|
|
| BLAKE2b-256 |
1edf5a6589784bc1bb0932fb6fc208cd01d129d6d3a59a1030d2bdf0b53720fb
|
File details
Details for the file symb_anafis-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 723.2 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e40ed206f59994e8deacf26778fd01d5fb0070718df73f448fd4af8ad3b3989e
|
|
| MD5 |
0bbdfb2e637ec98113a4285f6c4201df
|
|
| BLAKE2b-256 |
b11361bc7a0c7d6ee2b8c902183a0a1e385f03df79a39810cf0e4e3702b96260
|
File details
Details for the file symb_anafis-0.3.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 631.0 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e90194964b289d0d40bf7fabae78dbbd43a3b9126767d6cd80dac251266add7c
|
|
| MD5 |
0d1cad0e8268c3a1bc136d6a79921473
|
|
| BLAKE2b-256 |
2fb488616f4b26daeb7fa2ff16c9e2cbf124e125a487bf699d2a8e7b199a5ef9
|
File details
Details for the file symb_anafis-0.3.0-cp312-cp312-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp312-cp312-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 819.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c11edd80e28671845cacb82e1fbc95da4fc1769bcf946396ed4d1b2caa92e24e
|
|
| MD5 |
5b23f84f6df23807bc7be64b288a29ca
|
|
| BLAKE2b-256 |
51d11937f051d25c833c0745083568fbee2116667e2dd84eb2154a4ffbc62956
|
File details
Details for the file symb_anafis-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 723.2 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae4b4826555ed8c6f86f512c22650c69d2875fb9108057df9e51ad8980384090
|
|
| MD5 |
4ecd4a347b12a03baf407cc5f0e5a8ad
|
|
| BLAKE2b-256 |
0ed057d874de36e0a83039f4425184247c0088b35d5fe215b5b76878219d4969
|
File details
Details for the file symb_anafis-0.3.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 629.6 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f03db255238db396219bf8d87b1e3e55c9f495d94ced98374fee7e9faf410f6a
|
|
| MD5 |
edf2892395f628f0b07f728906e4a351
|
|
| BLAKE2b-256 |
19ac961e52694047f7964c8a6b2863baefff17e1157a0335d7208fbfb6da268d
|
File details
Details for the file symb_anafis-0.3.0-cp311-cp311-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp311-cp311-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 818.0 kB
- Tags: CPython 3.11, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b6c5dcbd9514e497d116593f2f13d213150a7b9637509ed073ac70eb236cec2
|
|
| MD5 |
6776e5becf8327ec84b186701900e1f8
|
|
| BLAKE2b-256 |
f3c04bfa59cbd2886db1102c43477f321707dbba2c3dba639b3fb99fcbefa6fc
|
File details
Details for the file symb_anafis-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 725.6 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0677536fcc5e09381bbf7303253e18505480c87dee793f2021f675873cbae344
|
|
| MD5 |
fbebed93a640074df2251970ef668e6a
|
|
| BLAKE2b-256 |
cd4cb8b0f5e060d22fb9da5da2377d5a1aac75fe762aeb00b08a7752e3dc539b
|
File details
Details for the file symb_anafis-0.3.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 629.7 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
480021d595fca3d3f8de2eaf7ce8063a4a01df2758cbb777bf368674da5ca8bb
|
|
| MD5 |
b63b188f28e051aad076a4ce174840ef
|
|
| BLAKE2b-256 |
1bd80faa5e85b216d896908808d68d54a216c3c184e2d01d3041a0d7c8b11e9b
|
File details
Details for the file symb_anafis-0.3.0-cp310-cp310-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp310-cp310-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 816.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3995411e76551b9c81a8b16d4d80aa3b506ab8d8fd561e9db5c37680acb51615
|
|
| MD5 |
7057c346ce64212bcd1bbca2de7c7f9c
|
|
| BLAKE2b-256 |
bd01cd914787a8a30a7d1791b46e6804bbf48a1d03af61994b17d1c3bf646dce
|
File details
Details for the file symb_anafis-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: symb_anafis-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 725.7 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9d77016e9f08a2493c18359460aa4ecc3156da0490de23b07f0188ad0384f66
|
|
| MD5 |
929d5e326586f76cd955113784fb5f2c
|
|
| BLAKE2b-256 |
a53a11093b020332b916448b318ad9111034c7009b3ead280614d574760b2518
|