1 (* ========================================================================= *)
2 (* Load in Petros Papapanagiotou's Boyer-Moore code and try examples. *)
3 (* ========================================================================= *)
5 loads "Boyer_Moore/boyer-moore.ml";;
7 (* ------------------------------------------------------------------------- *)
8 (* Slight variant of Petros's eval.ml file. *)
9 (* ------------------------------------------------------------------------- *)
11 (* ========================================================================= *)
13 (* ------------------------------------------------------------------------- *)
14 (* Shortcuts for the various evaluation versions: *)
15 (* ------------------------------------------------------------------------- *)
17 let BM = BOYER_MOORE;; (* Pure re-implementation of R.Boulton's work. *)
18 let BME = BOYER_MOORE_EXT;; (* Extended with early termination heuristics and HOL Light features. *)
19 let BMG = BOYER_MOORE_GEN;; (* Further extended with M.Aderhold's generalization techniques. *)
21 let RBM = new_rewrite_rule o BOYER_MOORE;;
22 let RBME = new_rewrite_rule o BOYER_MOORE_EXT;;
23 let RBMG = new_rewrite_rule o BOYER_MOORE_GEN;;
25 (* ------------------------------------------------------------------------- *)
26 (* Add a theorem as a new function definition and rewrite rule. *)
27 (* Adding it as a rewrite rule should no longer be necessary after the *)
28 (* latest (July 2009) bugfixes but it doesn't do any harm either. *)
29 (* ------------------------------------------------------------------------- *)
31 let new_stuff x = (new_def x ; new_rewrite_rule x);;
33 (* ------------------------------------------------------------------------- *)
34 (* Test sets extracted from the proven theorems in HOL Light's arith.ml and *)
36 (* ------------------------------------------------------------------------- *)
38 loads "Boyer_Moore/testset/arith.ml";; (* Arithmetic test set *)
39 loads "Boyer_Moore/testset/list.ml";; (* List test set *)
41 (* ------------------------------------------------------------------------- *)
42 (* Reloads all the necessary definitions and rules for the evaluation of the *)
43 (* test sets above. *)
44 (* ------------------------------------------------------------------------- *)
49 system_rewrites := [];
58 new_rewrite_rule (ARITH_RULE `1=SUC(0)`);
64 new_rewrite_rule NOT_SUC;
65 new_rewrite_rule SUC_INJ;
82 new_rewrite_rule ALL2;
84 new_rewrite_rule MAP2;
88 new_stuff ITLIST2_DEF;
89 new_rewrite_rule ITLIST2;
93 new_rewrite_rule NOT_CONS_NIL;
94 new_rewrite_rule CONS_11 ;;
98 (* ------------------------------------------------------------------------- *)
99 (* Test functions. They use the Unix library to measure time. *)
100 (* Unfortunately this means that they do not load properly in Cygwin. *)
101 (* ------------------------------------------------------------------------- *)
108 (* ------------------------------------------------------------------------- *)
109 (* Reference of the remaining theory to be proven. Load a list of theorems *)
110 (* that you want the evaluation to run through. *)
111 (* eg. remaining_theory := !mytheory;; *)
112 (* Then use nexttm (see below) to evaluate one of the BOYER_MOORE_* *)
113 (* procedures over the list. *)
114 (* ------------------------------------------------------------------------- *)
116 let remaining_theory = ref ([]:term list);;
118 let currenttm = ref `p`;;
120 (* ------------------------------------------------------------------------- *)
121 (* Tries a theorem-proving procedure f on arg. *)
122 (* Returns a truth value of whether the procedure succeeded in finding a *)
123 (* proof and a pair of timestamps taken from the start and the end of the *)
125 (* ------------------------------------------------------------------------- *)
128 let t1=Unix.times () in
129 let resu = try (if (can dest_thm (f arg)) then true else false) with Failure _ -> false in
130 let t2=Unix.times () in (resu,(t1,t2));;
131 (* printf "User time: %f - system time: %f\n%!" (t2.tms_utime -. t1.tms_utime) (t2.tms_stime -. t1.tms_stime);; *)
134 (* ------------------------------------------------------------------------- *)
135 (* Uses bm_time to try a Boyer-Moore theorem-proving procedure f on tm. *)
136 (* Prints out all the evaluation information that is collected and returns *)
137 (* the list of generalizations made during the proof. *)
138 (* ------------------------------------------------------------------------- *)
141 let pfpt = (print_term tm ; print_newline() ; proof_printer false) in
142 let (resu,(t1,t2)) = bm_time f tm in
143 let pfpt = proof_printer pfpt in
144 printf "Proven: %b - Time: %f - Steps: %d - Inductions: %d - Gen terms: %d - Over gens: %d \\\\\n" resu
145 (t2.tms_utime -. t1.tms_utime) (fst !bm_steps) (snd !bm_steps) (length !my_gen_terms) (!counterexamples) ;
148 (* ------------------------------------------------------------------------- *)
149 (* Another version of bm_test but with a more compact printout. *)
150 (* Returns unit (). *)
151 (* ------------------------------------------------------------------------- *)
154 let pfpt = (print_term tm ; print_newline() ; proof_printer false) in
155 let (resu,(t1,t2)) = bm_time f tm in
156 let pfpt = proof_printer pfpt in
157 printf "& %b & %f & %d & %d & %d & %d \\\\\n" resu (t2.tms_utime -. t1.tms_utime) (fst !bm_steps) (snd !bm_steps) (length !my_gen_terms) (!counterexamples) ;
160 (* ------------------------------------------------------------------------- *)
161 (* Convenient function for evaluation. *)
162 (* Uses f to try and prove the next term in !remaining_theory by bm_test2 *)
163 (* ------------------------------------------------------------------------- *)
166 if (!remaining_theory = []) then failwith "No more"
167 else currenttm := hd !remaining_theory ; remaining_theory := tl !remaining_theory ;
168 bm_test2 f !currenttm;;
170 (* ------------------------------------------------------------------------- *)
171 (* Reruns evaluation on the same term that was last loaded with nexttm. *)
172 (* ------------------------------------------------------------------------- *)
174 let sametm f = bm_test2 f !currenttm;;
177 (* ========================================================================= *)
180 (* ------------------------------------------------------------------------- *)
181 (* Just one example. *)
182 (* ------------------------------------------------------------------------- *)
184 bm_test BME `m + n:num = n + m`;;
186 (* ------------------------------------------------------------------------- *)
187 (* Note that these don't all terminate, so need more delicacy really. *)
188 (* Should carefully reconstruct the cases in Petros's thesis, also maybe *)
189 (* using a timeout. *)
190 (* ------------------------------------------------------------------------- *)
193 do_list (bm_test BME) (!mytheory);;
195 do_list (bm_test BME) (!mytheory2);;