1 (* port of univariate.cc
2 a univariate represents a function u:real->real.
3 its first derivative du:real->real
4 and its second derivative ddu;real->real.
6 For example, if the function is x |-> x,
7 its derivative is x |-> 1,
8 and second derivative is x |-> 0,
9 which is implemented as ux1.
11 We give a few other examples, sqrt, 1/x, atan.
15 module Univariate = struct
19 let eval uni x = function
24 let mk_univariate (u1,du1,ddu1) = { u = u1; du = du1; ddu = ddu1; };;
26 let raise_zero x = bounded_from_zero x or raise Unstable ;;
28 (* here are a couple of examples *)
44 let _ = raise_zero x in
45 one / (two * isqrt x)),
48 let _ = raise_zero x in
49 ineg (one / (four * x * isqrt x)))
57 let _ = raise_zero x in
61 let _ = raise_zero x in
62 ineg (one / ( x * x))),
65 let _ = raise_zero x in
80 let t = one + x * x in
81 ineg (two * x/ (t * t)))
92 ineg (one / isqrt (one - x * x))),
94 let t = one - x * x in
95 ineg (x / isqrt (t * t * t)))