author | blanchet |
Thu, 17 Jan 2013 18:43:59 +0100 | |
changeset 50952 | 3fd83a0cc4bd |
parent 50826 | 18ace05656cf |
child 50953 | c4c746bbf836 |
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 |
50952 | 14 |
-> string -> 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" |
50952 | 28 |
val MaSh_IsarN = "MaSh-Isar" |
29 |
val MaSh_ProverN = "MaSh-Prover" |
|
30 |
val MeSh_IsarN = "MeSh-Isar" |
|
31 |
val MeSh_ProverN = "MeSh-Prover" |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
32 |
val IsarN = "Isar" |
48241 | 33 |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
34 |
fun in_range (from, to) j = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
35 |
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
|
36 |
|
50952 | 37 |
fun evaluate_mash_suggestions ctxt params range prob_dir_name |
38 |
isar_sugg_file_name prover_sugg_file_name report_file_name = |
|
48235 | 39 |
let |
50448
0a740d127187
have MaSh evaluator keep all raw problem/solution files in a directory
blanchet
parents:
50442
diff
changeset
|
40 |
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
|
41 |
val _ = File.write report_path "" |
50589 | 42 |
fun print s = File.append report_path (s ^ "\n") |
48293 | 43 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} = |
50557 | 44 |
default_params ctxt [] |
48318 | 45 |
val prover = hd provers |
50412 | 46 |
val slack_max_facts = generous_max_facts (the max_facts) |
50952 | 47 |
val mash_isar_lines = Path.explode isar_sugg_file_name |> File.read_lines |
48 |
val mash_prover_lines = |
|
49 |
case Path.explode prover_sugg_file_name |> try File.read_lines of |
|
50 |
NONE => replicate (length mash_isar_lines) "" |
|
51 |
| SOME lines => lines |
|
52 |
val mash_lines = mash_isar_lines ~~ mash_prover_lines |
|
50557 | 53 |
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
|
54 |
val facts = all_facts ctxt true false Symtab.empty [] [] css |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50633
diff
changeset
|
55 |
val name_tabs = build_name_tables nickname_of_thm facts |
48289 | 56 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
50952 | 57 |
fun index_str (j, s) = s ^ "@" ^ string_of_int j |
58 |
val str_of_heading = enclose " " ": " |
|
59 |
fun str_of_result heading facts ({outcome, run_time, used_facts, ...} |
|
60 |
: prover_result) = |
|
48289 | 61 |
let val facts = facts |> map (fn ((name, _), _) => name ()) in |
50952 | 62 |
str_of_heading heading ^ |
48289 | 63 |
(if is_none outcome then |
64 |
"Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^ |
|
65 |
(used_facts |> map (with_index facts o fst) |
|
66 |
|> sort (int_ord o pairself fst) |
|
50952 | 67 |
|> map index_str |
48289 | 68 |
|> space_implode " ") ^ |
48293 | 69 |
(if length facts < the max_facts then |
48289 | 70 |
" (of " ^ string_of_int (length facts) ^ ")" |
71 |
else |
|
72 |
"") |
|
73 |
else |
|
74 |
"Failure: " ^ |
|
48293 | 75 |
(facts |> take (the max_facts) |> tag_list 1 |
50952 | 76 |
|> map index_str |
48289 | 77 |
|> space_implode " ")) |
78 |
end |
|
50952 | 79 |
fun solve_goal (j, (mash_isar_line, mash_prover_line)) = |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
80 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
81 |
let |
50952 | 82 |
val (name, mash_isar_suggs) = extract_suggestions mash_isar_line |
83 |
val (_, mash_prover_suggs) = extract_suggestions mash_prover_line |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
84 |
val th = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
85 |
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
|
86 |
SOME (_, th) => th |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
87 |
| NONE => error ("No fact called \"" ^ name ^ "\".") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
88 |
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
|
89 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
50754
74a6adcb96ac
also generate queries for goals with too many Isar dependencies
blanchet
parents:
50735
diff
changeset
|
90 |
val isar_deps = isar_dependencies_of name_tabs th |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
91 |
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
|
92 |
val mepo_facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
93 |
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
|
94 |
concl_t facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
95 |
|> weight_mepo_facts |
50952 | 96 |
fun mash_of suggs = |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
97 |
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
|
98 |
|>> weight_mash_facts |
50952 | 99 |
val (mash_isar_facts, mash_isar_unks) = mash_of mash_isar_suggs |
100 |
val (mash_prover_facts, mash_prover_unks) = mash_of mash_prover_suggs |
|
101 |
fun mess_of mash_facts mash_unks = |
|
50814 | 102 |
[(mepo_weight, (mepo_facts, [])), |
103 |
(mash_weight, (mash_facts, mash_unks))] |
|
50952 | 104 |
fun mesh_of [] _ = [] |
105 |
| mesh_of mash_facts mash_unks = |
|
106 |
mesh_facts (Thm.eq_thm_prop o pairself snd) slack_max_facts |
|
107 |
(mess_of mash_facts mash_unks) |
|
108 |
val mesh_isar_facts = mesh_of mash_isar_facts mash_isar_unks |
|
109 |
val mesh_prover_facts = mesh_of mash_prover_facts mash_prover_unks |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
110 |
val isar_facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
111 |
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
|
112 |
(* adapted from "mirabelle_sledgehammer.ML" *) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
113 |
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
|
114 |
let |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
115 |
val prob_prefix = |
50826 | 116 |
"goal_" ^ string_of_int j ^ "__" ^ encode_str name ^ "__" ^ |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
117 |
heading |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
118 |
in |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
119 |
Config.put dest_dir dir |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
120 |
#> Config.put problem_prefix (prob_prefix ^ "__") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
121 |
#> 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
|
122 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
123 |
| set_file_name _ NONE = I |
50591 | 124 |
fun prove heading get facts = |
50952 | 125 |
if null facts andalso heading <> IsarN then |
126 |
(str_of_heading heading ^ "Skipped", 0) |
|
127 |
else |
|
128 |
let |
|
129 |
fun nickify ((_, stature), th) = |
|
130 |
((K (encode_str (nickname_of_thm th)), stature), th) |
|
131 |
val facts = |
|
132 |
facts |
|
133 |
|> map (get #> nickify) |
|
134 |
|> maybe_instantiate_inducts ctxt hyp_ts concl_t |
|
135 |
|> take (the max_facts) |
|
136 |
val ctxt = ctxt |> set_file_name heading prob_dir_name |
|
137 |
val res as {outcome, ...} = |
|
138 |
run_prover_for_mash ctxt params prover facts goal |
|
139 |
val ok = if is_none outcome then 1 else 0 |
|
140 |
in (str_of_result heading facts res, ok) end |
|
50591 | 141 |
val ress = |
142 |
[fn () => prove MePoN fst mepo_facts, |
|
50952 | 143 |
fn () => prove MaSh_IsarN fst mash_isar_facts, |
144 |
fn () => prove MaSh_ProverN fst mash_prover_facts, |
|
145 |
fn () => prove MeSh_IsarN I mesh_isar_facts, |
|
146 |
fn () => prove MeSh_ProverN I mesh_prover_facts, |
|
50591 | 147 |
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
|
148 |
|> (* Par_List. *) map (fn f => f ()) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
149 |
in |
50591 | 150 |
"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
|
151 |
|> cat_lines |> print; |
50591 | 152 |
map snd ress |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
153 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
154 |
else |
50952 | 155 |
[0, 0, 0, 0, 0, 0] |
48241 | 156 |
fun total_of heading ok n = |
50591 | 157 |
" " ^ heading ^ ": " ^ string_of_int ok ^ " (" ^ |
158 |
Real.fmt (StringCvt.FIX (SOME 1)) |
|
159 |
(100.0 * Real.fromInt ok / Real.fromInt n) ^ "%)" |
|
50557 | 160 |
val inst_inducts = Config.get ctxt instantiate_inducts |
48245 | 161 |
val options = |
50767 | 162 |
["prover = " ^ prover, |
163 |
"max_facts = " ^ string_of_int (the max_facts), |
|
164 |
"slice" |> not slice ? prefix "dont_", |
|
165 |
"type_enc = " ^ the_default "smart" type_enc, |
|
166 |
"lam_trans = " ^ the_default "smart" lam_trans, |
|
167 |
"timeout = " ^ ATP_Util.string_from_time (the_default one_year timeout), |
|
48241 | 168 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
50587
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
169 |
val _ = print " * * *"; |
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
170 |
val _ = print ("Options: " ^ commas options); |
50952 | 171 |
val oks = Par_List.map solve_goal (tag_list 1 mash_lines) |
50620 | 172 |
val n = length oks |
50952 | 173 |
val [mepo_ok, mash_isar_ok, mash_prover_ok, mesh_isar_ok, mesh_prover_ok, |
174 |
isar_ok] = |
|
50591 | 175 |
map Integer.sum (map_transpose I oks) |
48241 | 176 |
in |
177 |
["Successes (of " ^ string_of_int n ^ " goals)", |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
178 |
total_of MePoN mepo_ok n, |
50952 | 179 |
total_of MaSh_IsarN mash_isar_ok n, |
180 |
total_of MaSh_ProverN mash_prover_ok n, |
|
181 |
total_of MeSh_IsarN mesh_isar_ok n, |
|
182 |
total_of MeSh_ProverN mesh_prover_ok n, |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
183 |
total_of IsarN isar_ok n] |
50437 | 184 |
|> cat_lines |> print |
48241 | 185 |
end |
48235 | 186 |
|
48234 | 187 |
end; |