2 (* port of univariate.cc
3 a univariate represents a function u:real->real.
4 its first derivative du:real->real
5 and its second derivative ddu;real->real.
7 For example, if the function is x |-> x,
8 its derivative is x |-> 1,
9 and second derivative is x |-> 0,
10 which is implemented as ux1.
12 We give a few other examples, sqrt, 1/x, atan.
16 module Univariate = struct
20 let eval uni x = function
25 let mk_univariate (u1,du1,ddu1) = { u = u1; du = du1; ddu = ddu1; };;
27 let raise_zero x = bounded_from_zero x or raise Unstable ;;
29 (* here are a couple of examples *)
45 let _ = raise_zero x in
46 one / (two * isqrt x)),
49 let _ = raise_zero x in
50 ineg (one / ((two * isqrt x) * (two * x))))
58 let _ = raise_zero x in
62 let _ = raise_zero x in
63 ineg (one / ( x * x))),
66 let _ = raise_zero x in
81 let t = one / (one + x * x) in
82 (ineg two * x) * (t * t))
93 ineg (one / isqrt (one - x * x))),
95 let t = one - x * x in
96 ineg (x / isqrt (t * t * t)))