author | blanchet |
Fri, 11 Jan 2013 16:30:56 +0100 | |
changeset 50826 | 18ace05656cf |
parent 50825 | aed1d7242050 |
child 50952 | 3fd83a0cc4bd |
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) |
50814 | 45 |
val lines = Path.explode sugg_file_name |> File.read_lines |
50557 | 46 |
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
|
47 |
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
|
48 |
val name_tabs = build_name_tables nickname_of_thm facts |
48289 | 49 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
48235 | 50 |
fun index_string (j, s) = s ^ "@" ^ string_of_int j |
50436 | 51 |
fun str_of_res label facts ({outcome, run_time, used_facts, ...} |
50557 | 52 |
: prover_result) = |
48289 | 53 |
let val facts = facts |> map (fn ((name, _), _) => name ()) in |
54 |
" " ^ label ^ ": " ^ |
|
55 |
(if is_none outcome then |
|
56 |
"Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^ |
|
57 |
(used_facts |> map (with_index facts o fst) |
|
58 |
|> sort (int_ord o pairself fst) |
|
59 |
|> map index_string |
|
60 |
|> space_implode " ") ^ |
|
48293 | 61 |
(if length facts < the max_facts then |
48289 | 62 |
" (of " ^ string_of_int (length facts) ^ ")" |
63 |
else |
|
64 |
"") |
|
65 |
else |
|
66 |
"Failure: " ^ |
|
48293 | 67 |
(facts |> take (the max_facts) |> tag_list 1 |
48289 | 68 |
|> map index_string |
69 |
|> space_implode " ")) |
|
70 |
end |
|
48311 | 71 |
fun solve_goal (j, line) = |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
72 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
73 |
let |
50633 | 74 |
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
|
75 |
val th = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
76 |
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
|
77 |
SOME (_, th) => th |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
78 |
| NONE => error ("No fact called \"" ^ name ^ "\".") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
val mepo_facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
84 |
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
|
85 |
concl_t facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
86 |
|> weight_mepo_facts |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
87 |
val (mash_facts, mash_unks) = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
88 |
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
|
89 |
|>> weight_mash_facts |
50814 | 90 |
val mess = |
91 |
[(mepo_weight, (mepo_facts, [])), |
|
92 |
(mash_weight, (mash_facts, mash_unks))] |
|
93 |
val mesh_facts = |
|
50825
aed1d7242050
always compare theorem using the same, weaker function
blanchet
parents:
50814
diff
changeset
|
94 |
mesh_facts (Thm.eq_thm_prop o pairself snd) slack_max_facts mess |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
95 |
val isar_facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
96 |
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
|
97 |
(* adapted from "mirabelle_sledgehammer.ML" *) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
98 |
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
|
99 |
let |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
100 |
val prob_prefix = |
50826 | 101 |
"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
|
102 |
heading |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
103 |
in |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
104 |
Config.put dest_dir dir |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
105 |
#> Config.put problem_prefix (prob_prefix ^ "__") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
106 |
#> 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
|
107 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
108 |
| set_file_name _ NONE = I |
50591 | 109 |
fun prove heading get facts = |
50555 | 110 |
let |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
111 |
fun nickify ((_, stature), th) = |
50826 | 112 |
((K (encode_str (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
|
113 |
val facts = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
114 |
facts |
50562
0a7c7e121bd8
generate proper nicks also for instantiated induction rules
blanchet
parents:
50559
diff
changeset
|
115 |
|> map (get #> nickify) |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
116 |
|> 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
|
117 |
|> take (the max_facts) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
118 |
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
|
119 |
val res as {outcome, ...} = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
120 |
run_prover_for_mash ctxt params prover facts goal |
50591 | 121 |
val ok = if is_none outcome then 1 else 0 |
122 |
in (str_of_res heading facts res, ok) end |
|
123 |
val ress = |
|
124 |
[fn () => prove MePoN fst mepo_facts, |
|
125 |
fn () => prove MaShN fst mash_facts, |
|
126 |
fn () => prove MeShN I mesh_facts, |
|
127 |
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
|
128 |
|> (* Par_List. *) map (fn f => f ()) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
129 |
in |
50591 | 130 |
"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
|
131 |
|> cat_lines |> print; |
50591 | 132 |
map snd ress |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
133 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
134 |
else |
50591 | 135 |
[0, 0, 0, 0] |
48241 | 136 |
fun total_of heading ok n = |
50591 | 137 |
" " ^ heading ^ ": " ^ string_of_int ok ^ " (" ^ |
138 |
Real.fmt (StringCvt.FIX (SOME 1)) |
|
139 |
(100.0 * Real.fromInt ok / Real.fromInt n) ^ "%)" |
|
50557 | 140 |
val inst_inducts = Config.get ctxt instantiate_inducts |
48245 | 141 |
val options = |
50767 | 142 |
["prover = " ^ prover, |
143 |
"max_facts = " ^ string_of_int (the max_facts), |
|
144 |
"slice" |> not slice ? prefix "dont_", |
|
145 |
"type_enc = " ^ the_default "smart" type_enc, |
|
146 |
"lam_trans = " ^ the_default "smart" lam_trans, |
|
147 |
"timeout = " ^ ATP_Util.string_from_time (the_default one_year timeout), |
|
48241 | 148 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
50587
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
149 |
val _ = print " * * *"; |
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
150 |
val _ = print ("Options: " ^ commas options); |
50591 | 151 |
val oks = Par_List.map solve_goal (tag_list 1 lines) |
50620 | 152 |
val n = length oks |
50591 | 153 |
val [mepo_ok, mash_ok, mesh_ok, isar_ok] = |
154 |
map Integer.sum (map_transpose I oks) |
|
48241 | 155 |
in |
156 |
["Successes (of " ^ string_of_int n ^ " goals)", |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
157 |
total_of MePoN mepo_ok n, |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
158 |
total_of MaShN mash_ok n, |
50459 | 159 |
total_of MeShN mesh_ok n, |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
160 |
total_of IsarN isar_ok n] |
50437 | 161 |
|> cat_lines |> print |
48241 | 162 |
end |
48235 | 163 |
|
48234 | 164 |
end; |