(* ========================================================================== *) (* Formal verification of nonlinear inequalities in HOL Light *) (* *) (* Copyright (c) 2012 Alexey Solovyev *) (* *) (* This file is distributed under the terms of the MIT licence *) (* ========================================================================== *) (* -------------------------------------------------------------------------- *) (* Miscellaneous functions *) (* -------------------------------------------------------------------------- *) #load "unix.cma";; module Misc_functions = struct exception Error of string * term list * thm list;; let error msg tms ths = raise (Error (msg, tms, ths));; let error_msg msg = raise (Error (msg, [], []));; let error_fmt str fmt = let msg = sprintf str fmt in error_msg msg;; (* A little faster version of PROVE_HYP *) let MY_PROVE_HYP hyp th = EQ_MP (DEDUCT_ANTISYM_RULE hyp th) hyp;; (* A faster version of BETA_RULE *) let MY_BETA_RULE th = let rec beta tm = let op, arg = dest_comb tm in if is_comb op then let op_th = AP_THM (beta op) arg in let beta_th = BETA_CONV (rand (concl op_th)) in TRANS op_th beta_th else BETA_CONV tm in EQ_MP (beta (concl th)) th;; (* Converts a list with two elements into a pair *) let pair_of_list = function | [a; b] -> a, b | _ -> failwith "pair_of_list: list does not contain exactly two element";; (* Applies f to arg n times and returns the total execution time *) let test n f arg = let start = Unix.gettimeofday() in let result = f arg in for i = 1 to n - 1 do let _ = f arg in () done; result, Unix.gettimeofday() -. start;; (* Do not use when msg is not a fixed string *) let assert_msg (cond, msg) = if cond then () else failwith msg;; (* Generates a power function for the given binary operation *) let gen_pow op id = let ( * ) = op in let rec pow n x = if n <= 0 then id else if n = 1 then x else if n land 1 = 1 then x * pow (n - 1) x else let t = pow (n lsr 1) x in t * t in pow;; let rec shape_list n list = if length list <= n then [list] else let l1, l2 = chop_list n list in l1 :: shape_list n l2;; (* map2 which works for lists of any size (no requirement |l1| = |l2|) *) let rec my_map2 f l1 l2 = match l1 with | [] -> [] | (h1::t1) -> (match l2 with | [] -> [] | (h2::t2) -> (f h1 h2) :: my_map2 f t1 t2);; end;;