symbolic mathematics engine in OCaml with differentiation, integration, simplification, and numerical methods
- OCaml 98.9%
- Makefile 0.9%
- Dune 0.2%
| bench | ||
| bin | ||
| examples | ||
| lib | ||
| test | ||
| .gitignore | ||
| dune-project | ||
| leibniz.opam | ||
| Makefile | ||
| README.md | ||
| test_expr_output.ml | ||
leibniz
symbolic mathematics engine in OCaml with differentiation, integration, simplification, and numerical methods
usage
open Leibniz
let f = Parser.parse "x^3 * sin(x)"
let df = Diff.diff "x" f
let () = print_endline (Expr.to_string df)
let ddf = Diff.diff "x" df
let () = print_endline (Expr.to_string ddf)
let value = Eval.eval [("x", 2.0)] df
let () = print_endline (string_of_float value)
implicit multiplication
let expr = Parser.parse "2x + 3sin(x)"
symbolic integration
match Integrate.integrate "x" (Parser.parse "x^2") with
| Some antideriv -> print_endline (Expr.to_string antideriv)
| None -> print_endline "no closed form"
taylor series
let series = Series.maclaurin "x" (Parser.parse "sin(x)") 5
multivariate calc
let f = Parser.parse "x^2 + y^2"
let grad = Multivariate.gradient ["x"; "y"] f
numerical methods
let root = Numerical.newton_raphson
(Parser.parse "x^2 - 4") "x" 1.0 0.0001 100
pattern matching / rewriting
open Substitute
let pattern = POp("Add", [PVar "a"; PVar "a"])
let template = POp("Mul", [PConst 2.0; PVar "a"])
let expr = Parser.parse "x + x"
match rewrite pattern template expr with
| Some result -> print_endline (Expr.to_string result)
| None -> ()
testing
make test
examples
make examples
benchmarks
make bench