symbolic mathematics engine in OCaml with differentiation, integration, simplification, and numerical methods
17

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 98.0%
Makefile 0.8%
Dune 0.2%
Other 1.0%
2 1 0

Clone this repository

https://git.vm.fail/vm.fail/leibniz https://git.vm.fail/did:plc:p55djzh3ge452wdkbxcpphon
ssh://git@knot.vm.fail:2222/vm.fail/leibniz ssh://git@knot.vm.fail:2222/did:plc:p55djzh3ge452wdkbxcpphon

For self-hosted knots, clone URLs may differ based on your setup.


README.md

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