(* ========================================================================== *) (* Formal verification of nonlinear inequalities in HOL Light *) (* *) (* Copyright (c) 2012 Alexey Solovyev *) (* *) (* This file is distributed under the terms of the MIT licence *) (* ========================================================================== *) (* -------------------------------------------------------------------------- *) (* Auxiliary formal verification functions *) (* -------------------------------------------------------------------------- *) needs "Formal_ineqs/arith/eval_interval.hl";; needs "Formal_ineqs/arith/more_float.hl";; needs "Formal_ineqs/taylor/m_taylor.hl";; needs "Formal_ineqs/informal/informal_verifier.hl";; needs "Formal_ineqs/verifier_options.hl";; needs "Formal_ineqs/misc/misc_vars.hl";; module M_verifier_build = struct open Interval_arith;; open Taylor_interval;; open Multivariate_taylor;; open More_float;; open Eval_interval;; open M_taylor;; open Misc_vars;; open Verifier_options;; type verification_funs = { (* p_lin -> p_second -> domain_th -> taylor_th *) taylor : int -> int -> thm -> thm; (* pp -> lo -> hi -> interval_th *) f : int -> term -> term -> thm; (* i -> pp -> lo -> hi -> interval_th *) df : int -> int -> term -> term -> thm; (* i -> j -> pp -> lo -> hi -> interval_th *) ddf : int -> int -> int -> term -> term -> thm; (* lo -> hi -> diff2_th *) diff2_f : term -> term -> thm; };; (**********************************) (* mk_verification_functions *) let mk_verification_functions_poly pp0 poly_tm = let x_tm, body_tm = dest_abs poly_tm in let new_f = poly_tm in let n = get_dim x_tm in let _ = !info_print_level <= 1 || (report0 (sprintf "Computing partial derivatives (%d)..." n); true) in let partials = map (fun i -> let _ = !info_print_level <= 1 || (report0 (sprintf " %d" i); true) in gen_partial_poly i new_f) (1--n) in let get_partial i eq_th = let partial_i = gen_partial_poly i (rand (concl eq_th)) in let pi = (rator o lhand o concl) partial_i in REWRITE_RULE[GSYM partial2] (TRANS (AP_TERM pi eq_th) partial_i) in let partials2 = map (fun j -> let th = List.nth partials (j - 1) in map (fun i -> let _ = !info_print_level <= 1 || (report0 (sprintf " %d,%d" j i); true) in get_partial i th) (1--j)) (1--n) in let _ = !info_print_level <= 1 || (report0 " done\n"; true) in let diff_th = gen_diff_poly new_f in let lin_th = gen_lin_approx_poly_thm new_f diff_th partials in let diff2_th = gen_diff2c_domain_poly new_f in let second_th = gen_second_bounded_poly_thm new_f partials2 in let replace_numeral i th = let num_eq = (REWRITE_RULE[Arith_num.NUM_THM] o Arith_nat.NUMERAL_TO_NUM_CONV) (mk_small_numeral i) in GEN_REWRITE_RULE (LAND_CONV o RATOR_CONV o DEPTH_CONV) [num_eq] th in let eval0 = mk_eval_function pp0 new_f in let eval1 = map (fun i -> let d_th = List.nth partials (i - 1) in let eq_th = replace_numeral i d_th in mk_eval_function_eq pp0 eq_th) (1--n) in let eval2 = map (fun i -> map (fun j -> let d2_th = List.nth (List.nth partials2 (i - 1)) (j - 1) in let eq_th' = replace_numeral i d2_th in let eq_th = replace_numeral j eq_th' in mk_eval_function_eq pp0 eq_th) (1--i)) (1--n) in let diff2_f = eval_diff2_poly diff2_th in let eval_f = eval_m_taylor pp0 diff2_th lin_th second_th in {taylor = eval_f; f = eval0; df = (fun i -> List.nth eval1 (i - 1)); ddf = (fun i j -> List.nth (List.nth eval2 (j - 1)) (i - 1)); diff2_f = diff2_f; }, Informal_verifier.mk_verification_functions_poly pp0 new_f partials partials2;; end;;