#math-parser #function #variables #integration #derivation #evaluation #string

ruut-functions

A math library that allows for parsing functions from string and perform integration, derivation and evaluation. Also supports functions with 2 and 3 variables

10 releases

new 0.1.2 Apr 30, 2024
0.1.1 Apr 19, 2024
0.0.61 Apr 23, 2023
0.0.5 Feb 19, 2023

#181 in Math

Download history 2/week @ 2024-02-26 127/week @ 2024-03-04 1/week @ 2024-03-11 28/week @ 2024-04-01 230/week @ 2024-04-15 18/week @ 2024-04-22

276 downloads per month

MIT license

88KB
2.5K SLoC

Functionalities

  • Parsing from string to function
  • support for 1/2/3 variable(s) functions
  • supports the following functions:
    • Ln, Sin, Cos, Tan, Sec, Csc, ASin, ACos, ATan, Sinh, Cosh, Tanh, Coth, Sech, Csch, ASinh, ACosh, ATanh, Abs
  • Ability to define parameters
  • Some kind of expression semplification

1D Functions

  • Derivative
  • Definite integral between a and b
  • Evaluate functions at x

2D Functions

  • Derivative
  • Hessian
  • Evaluate functions at (x,y)

3D Functions

  • Derivative
  • Hessian
  • Evaluate functions at (x,y,z)

Examples

Create a function with a macro and calculate gradient and hessian

use ruut_functions::{f3d, F3D}
use std::str::FromStr;

let func_3d = f3d!("ysin(x)+ln(z)cos(x)");

let gradient = func_3d.derivative();
println!("{}", gradient);
// { ycos(x)-ln(z)sin(x) , sin(x) , cos(x)/z }

let hessian = func_3d.hessian();
println!("{}", hessian);
// | -ysin(x)-ln(z)cos(z) | cos(x) |  -sin(x)/z  |
// |    cos(x)            |    0   |     0       |
// |    -sin(x)/z         |   0    | -cos(x)/z^2 |

Create a function with a context and use the parameter

use ruut_functions::{ctx::Ctx, F3D};

let ctx = Ctx::new(vec![("eta", 0.69)]);
let func_3d = F3D::build("x*eta", &ctx);

Dependencies