#math-parser #symbolic-math #variables #function #derivative #2d-3d #gradient

ruut-functions

A crate to parse math functions from string (1D,2D,3D,ND) and perform symbolic derivation, gradient, hessian

12 releases

0.2.1 Jul 18, 2024
0.2.0 Jul 18, 2024
0.1.2 Apr 30, 2024
0.0.61 Apr 23, 2023
0.0.5 Feb 19, 2023

#652 in Rust patterns

Download history 4/week @ 2024-07-22 46/week @ 2024-07-29 16/week @ 2024-09-16 8/week @ 2024-09-23 13/week @ 2024-09-30

643 downloads per month

MIT license

71KB
2K SLoC

Features

  • 1D, 2D, 3D, ND (with custom variables) functions
  • Set params and assign values (default is 0.0)
  • Compute derivatives of any orders, gradients, hessian
  • F1D can be numerically integrated
  • Supports the following functions:
    • Ln, Sin, Cos, Tan, Sec, Csc, ASin, ACos, ATan, Sinh, Cosh, Tanh, Coth, Sech, Csch, ASinh, ACosh, ATanh, Abs
  • Some kind of expression semplification

Examples

use ruut_functions::{f3d, F3D};

fn main() {
    let mut f = f3d!("x^3+y^2+yx^2+[eta]");
    f.set_par("eta", 6.9);
    assert_eq!(f.eval(0., 0., 0.), 6.9);
    assert_eq!(
        f.gradient(),
        vec![f3d!("2xy+3x^2"), f3d!("2y+x^2"), f3d!("0")]
    );
    assert_eq!(
        f.hessian(),
        vec![
            vec![f3d!("2y+6x"), f3d!("2x"), f3d!("0")],
            vec![f3d!("2x"), f3d!("2"), f3d!("0")],
            vec![f3d!("0"), f3d!("0"), f3d!("0")]
        ]
    )


    let f = f1d!("abs(x)+sin(x)");
    assert_eq!(f.eval(-2),2.90929742683)
}

lib.rs:

Crate for creating math functions from string and perform symbolic derivation

No runtime deps