symbolic mathematics engine in OCaml with differentiation, integration, simplification, and numerical methods
1open Leibniz
2
3let () =
4 print_endline "physics: kinetic energy\n";
5
6 let ke = Parser.parse "0.5 * m * v^2" in
7 print_endline ("KE = " ^ Expr.to_string ke);
8
9 let dke_dv = Diff.diff "v" ke in
10 print_endline ("dKE/dv = " ^ Expr.to_string dke_dv);
11
12 print_endline "\nphysics: circular motion\n";
13
14 let circumference = Parser.parse "2 * pi * r" in
15 print_endline ("C = " ^ Expr.to_string circumference);
16
17 let dc_dr = Diff.diff "r" circumference in
18 print_endline ("dC/dr = " ^ Expr.to_string dc_dr);
19
20 let r_val = 5.0 in
21 let c_val = Eval.eval [("r", r_val)] circumference in
22 Printf.printf "C(%.1f) = %.4f\n" r_val c_val