author | blanchet |
Wed, 18 Jul 2012 08:44:05 +0200 | |
changeset 48333 | 2250197977dc |
parent 48324 | 3ee5b5589402 |
child 48378 | 9e96486d53ad |
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 |
|
48285 | 12 |
val evaluate_mash_suggestions : |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
13 |
Proof.context -> params -> theory -> string -> unit |
48234 | 14 |
end; |
15 |
||
48285 | 16 |
structure MaSh_Eval : MASH_EVAL = |
48234 | 17 |
struct |
48235 | 18 |
|
48315
82d6e46c673f
fixed order of accessibles + other tweaks to MaSh
blanchet
parents:
48313
diff
changeset
|
19 |
open Sledgehammer_Fact |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
20 |
open Sledgehammer_Filter_MaSh |
48240 | 21 |
|
48315
82d6e46c673f
fixed order of accessibles + other tweaks to MaSh
blanchet
parents:
48313
diff
changeset
|
22 |
val isarN = "Isar" |
48285 | 23 |
val iterN = "Iter" |
48241 | 24 |
val mashN = "MaSh" |
48298 | 25 |
val meshN = "Mesh" |
48241 | 26 |
|
48293 | 27 |
val max_facts_slack = 2 |
48235 | 28 |
|
48324 | 29 |
val all_names = |
48333 | 30 |
filter_out is_likely_tautology_or_too_meta |
48316
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents:
48315
diff
changeset
|
31 |
#> map (rpair () o Thm.get_name_hint) #> Symtab.make |
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents:
48315
diff
changeset
|
32 |
|
48285 | 33 |
fun evaluate_mash_suggestions ctxt params thy file_name = |
48235 | 34 |
let |
48293 | 35 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} = |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48236
diff
changeset
|
36 |
Sledgehammer_Isar.default_params ctxt [] |
48318 | 37 |
val prover = hd provers |
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
38 |
val slack_max_facts = max_facts_slack * the max_facts |
48235 | 39 |
val path = file_name |> Path.explode |
40 |
val lines = path |> File.read_lines |
|
48299 | 41 |
val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt |
48315
82d6e46c673f
fixed order of accessibles + other tweaks to MaSh
blanchet
parents:
48313
diff
changeset
|
42 |
val facts = all_facts_of thy css_table |
48324 | 43 |
val all_names = all_names (facts |> map snd) |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
44 |
val iter_ok = Unsynchronized.ref 0 |
48241 | 45 |
val mash_ok = Unsynchronized.ref 0 |
48298 | 46 |
val mesh_ok = Unsynchronized.ref 0 |
48300 | 47 |
val isar_ok = Unsynchronized.ref 0 |
48289 | 48 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
48235 | 49 |
fun index_string (j, s) = s ^ "@" ^ string_of_int j |
48240 | 50 |
fun str_of_res label facts {outcome, run_time, used_facts, ...} = |
48289 | 51 |
let val facts = facts |> map (fn ((name, _), _) => name ()) in |
52 |
" " ^ label ^ ": " ^ |
|
53 |
(if is_none outcome then |
|
54 |
"Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^ |
|
55 |
(used_facts |> map (with_index facts o fst) |
|
56 |
|> sort (int_ord o pairself fst) |
|
57 |
|> map index_string |
|
58 |
|> space_implode " ") ^ |
|
48293 | 59 |
(if length facts < the max_facts then |
48289 | 60 |
" (of " ^ string_of_int (length facts) ^ ")" |
61 |
else |
|
62 |
"") |
|
63 |
else |
|
64 |
"Failure: " ^ |
|
48293 | 65 |
(facts |> take (the max_facts) |> tag_list 1 |
48289 | 66 |
|> map index_string |
67 |
|> space_implode " ")) |
|
68 |
end |
|
48311 | 69 |
fun solve_goal (j, line) = |
48235 | 70 |
let |
48311 | 71 |
val (name, suggs) = extract_query line |
48235 | 72 |
val th = |
73 |
case find_first (fn (_, th) => Thm.get_name_hint th = name) facts of |
|
74 |
SOME (_, th) => th |
|
75 |
| NONE => error ("No fact called \"" ^ name ^ "\"") |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48245
diff
changeset
|
76 |
val goal = goal_of_thm thy th |
48245 | 77 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
78 |
val isar_deps = isabelle_dependencies_of all_names th |
48235 | 79 |
val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS) |
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
80 |
val isar_facts = suggested_facts isar_deps facts |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
81 |
val iter_facts = |
48292 | 82 |
Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params |
48318 | 83 |
prover slack_max_facts NONE hyp_ts concl_t facts |
48320
891a24a48155
improved meshing of MaSh and Meng--Paulson if some MaSh suggestions are cut-off (the common case)
blanchet
parents:
48318
diff
changeset
|
84 |
val mash_facts = facts |> suggested_facts suggs |
891a24a48155
improved meshing of MaSh and Meng--Paulson if some MaSh suggestions are cut-off (the common case)
blanchet
parents:
48318
diff
changeset
|
85 |
val mess = [(iter_facts, []), (mash_facts, [])] |
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
86 |
val mesh_facts = mesh_facts slack_max_facts mess |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
87 |
fun prove ok heading facts = |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
88 |
let |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
89 |
val facts = |
48318 | 90 |
facts |
91 |
|> Sledgehammer_Fact.maybe_instantiate_inducts ctxt hyp_ts concl_t |
|
92 |
|> take (the max_facts) |
|
48321 | 93 |
val res as {outcome, ...} = |
94 |
run_prover_for_mash ctxt params prover facts goal |
|
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
95 |
val _ = if is_none outcome then ok := !ok + 1 else () |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
96 |
in str_of_res heading facts res end |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
97 |
val iter_s = prove iter_ok iterN iter_facts |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
98 |
val mash_s = prove mash_ok mashN mash_facts |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
99 |
val mesh_s = prove mesh_ok meshN mesh_facts |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
100 |
val isar_s = prove isar_ok isarN isar_facts |
48235 | 101 |
in |
48300 | 102 |
["Goal " ^ string_of_int j ^ ": " ^ name, iter_s, mash_s, mesh_s, |
103 |
isar_s] |
|
48241 | 104 |
|> cat_lines |> tracing |
48235 | 105 |
end |
48241 | 106 |
fun total_of heading ok n = |
107 |
" " ^ heading ^ ": " ^ string_of_int (!ok) ^ " (" ^ |
|
108 |
Real.fmt (StringCvt.FIX (SOME 1)) |
|
109 |
(100.0 * Real.fromInt (!ok) / Real.fromInt n) ^ "%)" |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48245
diff
changeset
|
110 |
val inst_inducts = Config.get ctxt Sledgehammer_Fact.instantiate_inducts |
48245 | 111 |
val options = |
48318 | 112 |
[prover, string_of_int (the max_facts) ^ " facts", |
48241 | 113 |
"slice" |> not slice ? prefix "dont_", the_default "smart" type_enc, |
114 |
the_default "smart" lam_trans, ATP_Util.string_from_time timeout, |
|
115 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
|
116 |
val n = length lines |
|
117 |
in |
|
118 |
tracing " * * *"; |
|
48245 | 119 |
tracing ("Options: " ^ commas options); |
48311 | 120 |
List.app solve_goal (tag_list 1 lines); |
48241 | 121 |
["Successes (of " ^ string_of_int n ^ " goals)", |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
122 |
total_of iterN iter_ok n, |
48241 | 123 |
total_of mashN mash_ok n, |
48298 | 124 |
total_of meshN mesh_ok n, |
48300 | 125 |
total_of isarN isar_ok n] |
48241 | 126 |
|> cat_lines |> tracing |
127 |
end |
|
48235 | 128 |
|
48234 | 129 |
end; |