1 (* =========================================================== *)
2 (* OCaml linear approximation of functions *)
3 (* Author: Thomas C. Hales *)
5 (* =========================================================== *)
7 (* port of lineInterval.cc.
8 Only the top section has been translated. The rest should be
9 automatically generated from HOL Light specs.
11 This impements basic operations on the type line,
12 such as addition and scalar multiplication.
16 needs "verifier/interval_m/interval.ml";;
18 module Line_interval = struct
25 (* general utilities *)
28 let table f = map f iter8;;
30 let table2 f = map (fun i -> map (fun j-> f i j) iter8) iter8;;
32 let rth m x i = if (i >=0) && (i < m) then List.nth x i else
33 failwith (Printf.sprintf "index %d not in 0..%d" i (m-1));;
35 let mth x i = if (i >=0) && (i < 8) then List.nth x i else
36 failwith (Printf.sprintf "index %d not in 0..8" i );;
38 let mth2 a i j = mth (mth a i) j;;
40 let maxl xs = end_itlist max xs;;
42 let minl xs = end_itlist min xs;;
44 (* line interval proper *)
46 let partial line i = mth line.df i ;;
48 let mk_line(f1,df1) = { f = f1; df =df1};;
52 mk_line(z,replicate z 8);;
55 mk_line(one,replicate zero 8);;
60 fun a b -> mk_line ( a.f * b.f, map (fun i -> a.f * mth b.df i + b.f * mth a.df i) iter8);;
64 fun a b -> mk_line ( a.f * b, map (fun x -> x * b) a.df);;
67 let one = mk_interval(1.0,1.0) in
75 mk_line ( f, map (fun i -> ((mth b.df i) * a.f - (mth a.df i) * b.f)* r2) iter8);;
80 mk_line(b.f + a.f, map (fun i -> mth b.df i + mth a.df i) iter8);;
85 mk_line(b.f - a.f, map (fun i -> mth b.df i - mth a.df i) iter8);;
90 mk_line(ineg a.f, map ineg a.df);;
93 let one = mk_interval(1.0,1.0) in
94 let two = mk_interval(2.0,2.0) in
99 let rs = one / (two * f) in
100 mk_line(f, map (fun i -> mth a.df i * rs) iter8);;
102 let latan = (* arctan (a/b) *)
103 let one = mk_interval(1.0,1.0) in
109 let f = iatan (a.f/b.f) in
110 let rden = one/ (a.f * a.f + b.f * b.f) in
111 mk_line(f, map (fun i -> rden * (mth a.df i * b.f - mth b.df i * a.f)) iter8);;