symbolic mathematics engine in OCaml with differentiation, integration, simplification, and numerical methods
  • OCaml 98.9%
  • Makefile 0.9%
  • Dune 0.2%
Find a file
2026-01-19 03:37:26 +00:00
bench initial 2026-01-19 03:37:26 +00:00
bin initial 2026-01-19 03:37:26 +00:00
examples initial 2026-01-19 03:37:26 +00:00
lib initial 2026-01-19 03:37:26 +00:00
test initial 2026-01-19 03:37:26 +00:00
.gitignore initial commit 2026-01-19 01:43:05 +00:00
dune-project initial commit 2026-01-19 01:43:05 +00:00
leibniz.opam initial commit 2026-01-19 01:43:05 +00:00
Makefile initial 2026-01-19 03:37:26 +00:00
README.md initial 2026-01-19 03:37:26 +00:00
test_expr_output.ml initial commit 2026-01-19 01:43:05 +00:00

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