1 flyspeck_needs "../formal_lp/formal_interval/interval_m/verifier.hl";;
2 flyspeck_needs "../formal_lp/formal_interval/eval_interval.hl";;
10 (****************************)
11 (* Automatic conversion of formal interval functions into functions *)
13 let rec build_fun i_fun =
16 (try F_int_var (dest_small_numeral (rand tm))
18 let name = (fst o dest_var) tm in
19 F_int_var (int_of_string (String.sub name 1 (String.length name - 1))))
21 let f1, f2 = (dest_pair o rand o concl) th in
22 let int = mk_interval (float_of_float_tm f1, float_of_float_tm f2) in
24 | Int_pow (n, f) -> F_int_pow (n, build_fun f)
25 | Int_unary (op, f) ->
26 let f' = build_fun f in
27 if op = neg_op_real then F_int_neg f' else failwith ("Unsupported operator: "^string_of_term op)
28 | Int_binary (op, f1, f2) ->
29 let f1', f2' = build_fun f1, build_fun f2 in
30 if op = add_op_real then F_int_add (f1',f2')
31 else if op = sub_op_real then F_int_sub (f1',f2')
32 else if op = mul_op_real then F_int_mul (f1',f2')
33 else failwith ("Unsupported operator: "^string_of_term op)
34 | _ -> failwith "Unsupported function";;
37 let buildL pp lin_th =
38 let funs = map (fst o dest_interval_arith) ((striplist dest_conj o rand o concl) lin_th) in
39 let i_funs = map (eval_constants pp o build_interval_fun) funs in
40 let fs = map build_fun i_funs @ (replicate (F_int_const zero) (8 - length funs + 1)) in
41 let eval_fs = map eval_int_fun fs in
42 let f, df = hd eval_fs, tl eval_fs in
44 let vars = map2 (curry mk_interval) x z in
45 if i = 0 then f vars else (List.nth df (i - 1)) vars),
47 let vars = map (fun x -> mk_interval (x,x)) x in
48 mk_line (f vars, map (fun df -> df vars) df));;
50 let buildL0 pp poly_tm =
51 let lin_th = gen_lin_approx_poly_thm0 poly_tm in
54 let buildDD pp second_th =
55 let poly_tm = (lhand o rator o lhand o concl) second_th in
56 let n = (get_dim o fst o dest_abs) poly_tm in
58 let funs = (striplist dest_conj o rand o snd o dest_forall o rand o concl) second_th in
59 let i_funs = map (eval_constants pp o build_interval_fun o fst o dest_interval_arith) funs in
60 let fs0 = map build_fun i_funs in
61 let pad1 = replicate zero (8 - n) and
62 pad2 = replicate zero 8 in
63 let pad3 = replicate pad2 (8 - n) in
65 let i', j' = if j <= i then i, j else j, i in
66 let index = (i' - 1) * i' / 2 + (j' - 1) in
68 let eval_fs = map eval_int_fun fs0 in
70 let ints = map2 (curry mk_interval) x z in
71 let vals = map (fun f -> f ints) eval_fs in
72 map (fun i -> map (fun j -> get_el vals i j) ns @ pad1) ns @ pad3;;
75 let buildDD0 pp poly_tm =
76 let second_th = gen_second_bounded_poly_thm0 poly_tm in
77 buildDD pp second_th;;
82 let build_taylor pp lin_th second_th =
83 let f_df, lin = buildL pp lin_th and
84 dd = buildDD pp second_th in
85 Prim_a (make_primitiveA (f_df, lin, dd));;
87 let build_taylor0 pp poly_tm =
88 build_taylor pp (gen_lin_approx_poly_thm0 poly_tm) (gen_second_bounded_poly_thm0 poly_tm);;