-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample_08.ml
60 lines (51 loc) · 1.93 KB
/
example_08.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
open Owl_symbolic
open Op
open Infix
let make_expr0 () =
(* construct *)
let x = variable "x_0" in
let y =
exp ((sin x ** float 2.) + (cos x ** float 2.))
+ (float 10. * (x ** float 2.))
+ exp (pi () * complex 0. 1.)
in
let expr = SymGraph.make_graph [| y |] "sym_graph" in
(* to LaTeX string *)
LaTeX_Engine.of_symbolic expr |> print_endline;
expr
let make_expr1 () =
(* construct *)
let alpha = variable "\\alpha" in
let beta = variable "\\beta" in
let theta = variable "\\theta" in
let y = sqrt (alpha + atan (int 6)) - tanh (abs (beta / theta)) in
let expr = SymGraph.make_graph [| y |] "sym_graph" in
LaTeX_Engine.of_symbolic expr |> print_endline;
expr
let make_expr2 () =
(* construct *)
let x = variable "x_i" in
let y = (int 6 / int 4 * x) + (int 2 * x) in
let expr1 = SymGraph.make_graph [| y |] "sym_graph" in
(* initial simplification *)
let expr2 = Owl_symbolic_cas_canonical.canonical_form expr1 in
(* print to html for debugging *)
(* let s = Owl_symbolic_graph.to_dot expr in
let _ = Owl_io.write_file "example_08.dot" s in
Sys.command "dot -Tpdf example_08.dot -o example_08.pdf" |> ignore; *)
LaTeX_Engine.of_symbolic expr2 |> print_endline;
let z = equal_to expr1.sym_nodes.(0) expr2.sym_nodes.(0) in
SymGraph.make_graph [| z |] "sym_graph"
let make_expr3 () =
let x = variable "x_i" in
let y = (int 2 * x) + (int 9 / int 6 * x) in
(* TODO: this doesn't work: (int 2 * x) + (x * (int 9 / int 6)) *)
let expr1 = SymGraph.make_graph [| y |] "sym_graph" in
let expr2 = Owl_symbolic_cas_canonical.canonical_form expr1 in
LaTeX_Engine.of_symbolic expr2 |> print_endline;
LaTeX_Engine.of_symbolic expr2 |> print_endline;
let z = equal_to expr1.sym_nodes.(0) expr2.sym_nodes.(0) in
SymGraph.make_graph [| z |] "sym_graph"
let _ =
let exprs = [ make_expr0 (); make_expr1 (); make_expr2 (); make_expr3 () ] in
LaTeX_Engine.html ~dot:true ~exprs "example_08.html"