author | blanchet |
Fri, 28 Dec 2012 23:31:51 +0100 | |
changeset 50633 | 87961472b404 |
parent 50624 | 4d0997abce79 |
child 50735 | 6b232d76cbc9 |
permissions | -rw-r--r-- |
48285 | 1 |
(* Title: HOL/TPTP/mash_eval.ML |
48234 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
3 |
Copyright 2012 |
|
4 |
||
48285 | 5 |
Evaluate proof suggestions from MaSh (Machine-learning for Sledgehammer). |
48234 | 6 |
*) |
7 |
||
48285 | 8 |
signature MASH_EVAL = |
48234 | 9 |
sig |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
10 |
type params = Sledgehammer_Provers.params |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
11 |
|
50437 | 12 |
val evaluate_mash_suggestions : |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
13 |
Proof.context -> params -> int * int option -> string option -> string |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
14 |
-> string -> unit |
48234 | 15 |
end; |
16 |
||
48285 | 17 |
structure MaSh_Eval : MASH_EVAL = |
48234 | 18 |
struct |
48235 | 19 |
|
50557 | 20 |
open Sledgehammer_Util |
48315
82d6e46c673f
fixed order of accessibles + other tweaks to MaSh
blanchet
parents:
48313
diff
changeset
|
21 |
open Sledgehammer_Fact |
50557 | 22 |
open Sledgehammer_MePo |
48381 | 23 |
open Sledgehammer_MaSh |
50557 | 24 |
open Sledgehammer_Provers |
25 |
open Sledgehammer_Isar |
|
48240 | 26 |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
27 |
val MePoN = "MePo" |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
28 |
val MaShN = "MaSh" |
50459 | 29 |
val MeShN = "MeSh" |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
30 |
val IsarN = "Isar" |
48241 | 31 |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
32 |
fun in_range (from, to) j = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
33 |
j >= from andalso (to = NONE orelse j <= the to) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
34 |
|
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
35 |
fun evaluate_mash_suggestions ctxt params range prob_dir_name sugg_file_name |
50448
0a740d127187
have MaSh evaluator keep all raw problem/solution files in a directory
blanchet
parents:
50442
diff
changeset
|
36 |
report_file_name = |
48235 | 37 |
let |
50448
0a740d127187
have MaSh evaluator keep all raw problem/solution files in a directory
blanchet
parents:
50442
diff
changeset
|
38 |
val report_path = report_file_name |> Path.explode |
0a740d127187
have MaSh evaluator keep all raw problem/solution files in a directory
blanchet
parents:
50442
diff
changeset
|
39 |
val _ = File.write report_path "" |
50589 | 40 |
fun print s = File.append report_path (s ^ "\n") |
48293 | 41 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} = |
50557 | 42 |
default_params ctxt [] |
48318 | 43 |
val prover = hd provers |
50412 | 44 |
val slack_max_facts = generous_max_facts (the max_facts) |
50437 | 45 |
val sugg_path = sugg_file_name |> Path.explode |
46 |
val lines = sugg_path |> File.read_lines |
|
50557 | 47 |
val css = clasimpset_rule_table_of ctxt |
50442
4f6a4d32522c
don't blacklist "case" theorems -- this causes problems in MaSh later
blanchet
parents:
50440
diff
changeset
|
48 |
val facts = all_facts ctxt true false Symtab.empty [] [] css |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
49 |
val all_names = build_all_names nickname_of_thm facts |
48289 | 50 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
48235 | 51 |
fun index_string (j, s) = s ^ "@" ^ string_of_int j |
50436 | 52 |
fun str_of_res label facts ({outcome, run_time, used_facts, ...} |
50557 | 53 |
: prover_result) = |
48289 | 54 |
let val facts = facts |> map (fn ((name, _), _) => name ()) in |
55 |
" " ^ label ^ ": " ^ |
|
56 |
(if is_none outcome then |
|
57 |
"Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^ |
|
58 |
(used_facts |> map (with_index facts o fst) |
|
59 |
|> sort (int_ord o pairself fst) |
|
60 |
|> map index_string |
|
61 |
|> space_implode " ") ^ |
|
48293 | 62 |
(if length facts < the max_facts then |
48289 | 63 |
" (of " ^ string_of_int (length facts) ^ ")" |
64 |
else |
|
65 |
"") |
|
66 |
else |
|
67 |
"Failure: " ^ |
|
48293 | 68 |
(facts |> take (the max_facts) |> tag_list 1 |
48289 | 69 |
|> map index_string |
70 |
|> space_implode " ")) |
|
71 |
end |
|
48311 | 72 |
fun solve_goal (j, line) = |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
73 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
74 |
let |
50633 | 75 |
val (name, suggs) = extract_suggestions line |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
76 |
val th = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
77 |
case find_first (fn (_, th) => nickname_of_thm th = name) facts of |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
78 |
SOME (_, th) => th |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
79 |
| NONE => error ("No fact called \"" ^ name ^ "\".") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
80 |
val goal = goal_of_thm (Proof_Context.theory_of ctxt) th |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
81 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
82 |
val isar_deps = isar_dependencies_of all_names th |> these |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
83 |
val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
84 |
val mepo_facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
85 |
mepo_suggested_facts ctxt params prover slack_max_facts NONE hyp_ts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
86 |
concl_t facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
87 |
|> weight_mepo_facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
88 |
val (mash_facts, mash_unks) = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
89 |
find_mash_suggestions slack_max_facts suggs facts [] [] |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
90 |
|>> weight_mash_facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
91 |
val mess = [(0.5, (mepo_facts, [])), (0.5, (mash_facts, mash_unks))] |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
92 |
val mesh_facts = mesh_facts slack_max_facts mess |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
93 |
val isar_facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
94 |
find_suggested_facts (map (rpair 1.0) isar_deps) facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
95 |
(* adapted from "mirabelle_sledgehammer.ML" *) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
96 |
fun set_file_name heading (SOME dir) = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
97 |
let |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
98 |
val prob_prefix = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
99 |
"goal_" ^ string_of_int j ^ "__" ^ escape_meta name ^ "__" ^ |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
100 |
heading |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
101 |
in |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
102 |
Config.put dest_dir dir |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
103 |
#> Config.put problem_prefix (prob_prefix ^ "__") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
104 |
#> Config.put SMT_Config.debug_files (dir ^ "/" ^ prob_prefix) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
105 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
106 |
| set_file_name _ NONE = I |
50591 | 107 |
fun prove heading get facts = |
50555 | 108 |
let |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
109 |
fun nickify ((_, stature), th) = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
110 |
((K (escape_meta (nickname_of_thm th)), stature), th) |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
111 |
val facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
112 |
facts |
50562
0a7c7e121bd8
generate proper nicks also for instantiated induction rules
blanchet
parents:
50559
diff
changeset
|
113 |
|> map (get #> nickify) |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
114 |
|> maybe_instantiate_inducts ctxt hyp_ts concl_t |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
115 |
|> take (the max_facts) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
116 |
val ctxt = ctxt |> set_file_name heading prob_dir_name |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
117 |
val res as {outcome, ...} = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
118 |
run_prover_for_mash ctxt params prover facts goal |
50591 | 119 |
val ok = if is_none outcome then 1 else 0 |
120 |
in (str_of_res heading facts res, ok) end |
|
121 |
val ress = |
|
122 |
[fn () => prove MePoN fst mepo_facts, |
|
123 |
fn () => prove MaShN fst mash_facts, |
|
124 |
fn () => prove MeShN I mesh_facts, |
|
125 |
fn () => prove IsarN fst isar_facts] |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
126 |
|> (* Par_List. *) map (fn f => f ()) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
127 |
in |
50591 | 128 |
"Goal " ^ string_of_int j ^ ": " ^ name :: map fst ress |
50587
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
129 |
|> cat_lines |> print; |
50591 | 130 |
map snd ress |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
131 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
132 |
else |
50591 | 133 |
[0, 0, 0, 0] |
48241 | 134 |
fun total_of heading ok n = |
50591 | 135 |
" " ^ heading ^ ": " ^ string_of_int ok ^ " (" ^ |
136 |
Real.fmt (StringCvt.FIX (SOME 1)) |
|
137 |
(100.0 * Real.fromInt ok / Real.fromInt n) ^ "%)" |
|
50557 | 138 |
val inst_inducts = Config.get ctxt instantiate_inducts |
48245 | 139 |
val options = |
48318 | 140 |
[prover, string_of_int (the max_facts) ^ " facts", |
48241 | 141 |
"slice" |> not slice ? prefix "dont_", the_default "smart" type_enc, |
50557 | 142 |
the_default "smart" lam_trans, |
143 |
ATP_Util.string_from_time (timeout |> the_default one_year), |
|
48241 | 144 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
50587
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
145 |
val _ = print " * * *"; |
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
146 |
val _ = print ("Options: " ^ commas options); |
50591 | 147 |
val oks = Par_List.map solve_goal (tag_list 1 lines) |
50620 | 148 |
val n = length oks |
50591 | 149 |
val [mepo_ok, mash_ok, mesh_ok, isar_ok] = |
150 |
map Integer.sum (map_transpose I oks) |
|
48241 | 151 |
in |
152 |
["Successes (of " ^ string_of_int n ^ " goals)", |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
153 |
total_of MePoN mepo_ok n, |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
154 |
total_of MaShN mash_ok n, |
50459 | 155 |
total_of MeShN mesh_ok n, |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
156 |
total_of IsarN isar_ok n] |
50437 | 157 |
|> cat_lines |> print |
48241 | 158 |
end |
48235 | 159 |
|
48234 | 160 |
end; |