1 (* ========================================================================== *)
2 (* FLYSPECK - BOOK FORMALIZATION *)
5 (* Copied from HOL Light jordan directory *)
6 (* Author: Thomas C. Hales *)
8 (* ========================================================================== *)
12 module Refinement = struct
14 (* ------------------------------------------------------------------ *)
15 (* This bundles an interactive session into a proof. *)
16 (* Later split off into general/prove_by_refinement *)
17 (* ------------------------------------------------------------------ *)
20 let labels_flag = ref false;; (* if true add labels to assumptions *)
23 let LABEL_ALL_TAC:tactic =
25 let rec mk_one_label i avoid =
26 let label = "Z-"^(string_of_int i) in
27 if not(mem label avoid) then label else mk_one_label (i+1) avoid in
28 mk_one_label 0 avoid in
29 let update_label i asl =
32 | a::b -> if (j=0) then (f a)::b else a::(f_at_i f (j-1) b) in
33 let avoid = map fst asl in
34 let current = el i avoid in
35 let new_label = mk_label avoid in
36 if (String.length current > 0) then asl else
37 f_at_i (fun (_,y) -> (new_label,y) ) i asl in
39 let (asl,w) = dest_goal gl in
41 (for i=0 to ((length asl)-1) do (aslp := update_label i !aslp) done;
42 (ALL_TAC (mk_goal(!aslp,w))));;
45 let enhance flag every tac =
46 if flag then (tac THEN every) THEN LABEL_ALL_TAC
49 let (e_enhance :bool ->tactic->tactic ->goalstack) =
50 fun flag every tac -> refine(by(VALID (enhance flag every tac)));;
55 let e = e_enhance true every;;
59 let typ = (type_vars_in_term t) in
60 can (find (fun ty -> (is_vartype ty) && ((dest_vartype ty).[0] = '?'))) typ;;
62 let enhanced_prove_by_refinement flag every (t,(tacl:tactic list)) =
63 if (length (frees t) > 0)
64 then failwith "prove_by_refinement: free vars" else
66 then failwith "prove_by_refinement: has stv" else
67 let gstate = mk_goalstate ([],t) in
68 let _,sgs,just = rev_itlist
69 (fun tac gs -> by (enhance flag every tac) gs)
71 let th = if sgs = [] then just null_inst []
72 else failwith "BY_REFINEMENT_PROOF: Unsolved goals" in
74 if t' = t then th else
75 try EQ_MP (ALPHA t' t) th
76 with Failure _ -> failwith "prove_by_refinement: generated wrong theorem";;
78 let prove_by_refinement = enhanced_prove_by_refinement false ALL_TAC;;