Skip to main content

Fast symbolic differentiation library - Rust-powered Python bindings

Project description

SymbAnaFis: Symbolic Analysis for Physics

A fast, focused Rust library for symbolic differentiation and analysis, designed for physics and engineering applications.

Features

  • Symbolic Differentiation: Compute derivatives of complex mathematical expressions.
  • Context-Aware Parsing: Support for fixed variables (constants) and custom functions.
  • Simplification: Comprehensive algebraic, trigonometric, hyperbolic, and logarithmic simplification rules.
  • Extensible: Easily add new functions and simplification rules.
  • Safe: Built with Rust's safety guarantees, with limits on recursion depth and node count.

Installation

Add this to your Cargo.toml:

[dependencies]
symb_anafis = "0.1.0"

Quick Start

use symb_anafis::{diff, simplify};

fn main() {
    // Differentiate sin(x) * x with respect to x
    let derivative = diff(
        "sin(x) * x".to_string(),
        "x".to_string(),
        None, // No fixed variables
        None  // No custom functions
    ).unwrap();

    println!("Derivative: {}", derivative);
    // Output: cos(x) * x + sin(x)

    // Simplify an expression
    let simplified = simplify(
        "x^2 + 2*x + 1".to_string(),
        None, // No fixed variables
        None  // No custom functions
    ).unwrap();

    println!("Simplified: {}", simplified);
    // Output: (x + 1)^2
}

Configuration

You can configure safety limits using environment variables:

  • SYMB_ANAFIS_MAX_DEPTH: Maximum AST depth (default: 100)
  • SYMB_ANAFIS_MAX_NODES: Maximum AST node count (default: 10000)
export SYMB_ANAFIS_MAX_DEPTH=200
export SYMB_ANAFIS_MAX_NODES=50000

Advanced Usage

Expression Simplification

You can simplify expressions without differentiation:

use symb_anafis::simplify;

fn main() {
    // Simplify a complex expression
    let result = simplify(
        "sin(x)^2 + cos(x)^2".to_string(),
        None, // No fixed variables
        None  // No custom functions
    ).unwrap();

    println!("Simplified: {}", result);
    // Output: 1
}

Multi-Character Symbols

For symbols with multiple characters (like "sigma", "alpha", etc.), pass them as fixed variables to ensure they're treated as single symbols:

use symb_anafis::simplify;

fn main() {
    // This treats "sigma" as one symbol
    let result = simplify(
        "(sigma^2)^2".to_string(),
        Some(&["sigma".to_string()]),
        None
    ).unwrap();
    println!("Simplified: {}", result);
    // Output: sigma^4
}

Fixed Variables and Custom Functions

You can define constants (like a, b) and custom functions (like f(x)) that are treated correctly during differentiation.

use symb_anafis::diff;

fn main() {
    // Differentiate a * f(x) with respect to x
    let result = diff(
        "a * f(x)".to_string(),
        "x".to_string(),
        Some(&["a".to_string()]),       // 'a' is a constant
        Some(&["f".to_string()])        // 'f' is a custom function
    ).unwrap();

    println!("Derivative: {}", result);
    // Output: a * ∂_f(x)/∂_x
}

Supported Functions

  • Trigonometric: sin, cos, tan, cot, sec, csc, asin, acos, atan, acot, asec, acsc
  • Hyperbolic: sinh, cosh, tanh, coth, sech, csch, asinh, acosh, atanh, acoth, asech, acsch
  • Exponential/Logarithmic: exp, ln, log, log10, log2
  • Roots: sqrt, cbrt
  • Absolute Value/Sign: abs, sign
  • Special: sinc, erf, erfc, gamma, digamma, trigamma, tetragamma, polygamma, beta, LambertW, besselj, bessely, besseli, besselk

Note: The polygamma(n, x) function provides derivatives for all polygamma functions. Functions with non-elementary derivatives use custom notation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

symb_anafis-0.2.3.tar.gz (132.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

symb_anafis-0.2.3-cp314-cp314-manylinux_2_34_x86_64.whl (540.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

File details

Details for the file symb_anafis-0.2.3.tar.gz.

File metadata

  • Download URL: symb_anafis-0.2.3.tar.gz
  • Upload date:
  • Size: 132.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for symb_anafis-0.2.3.tar.gz
Algorithm Hash digest
SHA256 d4a51e9d7e5c304ec6dc608e21de68bd016ada9c5029a15d4c715c4aa81b7e41
MD5 fe9a4ecd8858c2a91f882e8f532dd66c
BLAKE2b-256 e86041ff3627937dc45a165fa6fdddff955c1f02d84bf477c3dfd5672f3feab5

See more details on using hashes here.

File details

Details for the file symb_anafis-0.2.3-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for symb_anafis-0.2.3-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7631b7d4dd79e6e059244a82700f78c35241e3a17c1b75c694dc929e743a3ffa
MD5 ae509783d36c157dfc1aac7541cebedd
BLAKE2b-256 70aaafe657e21c4d05300548f5123ff8a3552047042f0d04faff5a9955a923b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page