author | blanchet |
Sat, 08 Dec 2012 00:48:50 +0100 | |
changeset 50437 | 9762fe72936e |
parent 50436 | 5291606b21e2 |
child 50439 | 330d4ad89e92 |
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 : |
13 |
Proof.context -> params -> string -> 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 |
48381 | 20 |
open Sledgehammer_MaSh |
48240 | 21 |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
22 |
val MePoN = "MePo" |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
23 |
val MaShN = "MaSh" |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
24 |
val MeshN = "Mesh" |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
25 |
val IsarN = "Isar" |
48241 | 26 |
|
48438
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
blanchet
parents:
48406
diff
changeset
|
27 |
val all_names = map (rpair () o nickname_of) #> Symtab.make |
48316
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents:
48315
diff
changeset
|
28 |
|
50437 | 29 |
fun evaluate_mash_suggestions ctxt params sugg_file_name out_file_name = |
48235 | 30 |
let |
50437 | 31 |
val out_path = out_file_name |> Path.explode |
32 |
val _ = File.write out_path "" |
|
33 |
fun print s = (tracing s; File.append out_path (s ^ "\n")) |
|
48293 | 34 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} = |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48236
diff
changeset
|
35 |
Sledgehammer_Isar.default_params ctxt [] |
48318 | 36 |
val prover = hd provers |
50412 | 37 |
val slack_max_facts = generous_max_facts (the max_facts) |
50437 | 38 |
val sugg_path = sugg_file_name |> Path.explode |
39 |
val lines = sugg_path |> File.read_lines |
|
48530
d443166f9520
repaired accessibility chains generated by MaSh exporter + tuned one function out
blanchet
parents:
48438
diff
changeset
|
40 |
val css = Sledgehammer_Fact.clasimpset_rule_table_of ctxt |
50358 | 41 |
val facts = all_facts ctxt false Symtab.empty [] [] css |
48324 | 42 |
val all_names = all_names (facts |> map snd) |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
43 |
val mepo_ok = Unsynchronized.ref 0 |
48241 | 44 |
val mash_ok = Unsynchronized.ref 0 |
48298 | 45 |
val mesh_ok = Unsynchronized.ref 0 |
48300 | 46 |
val isar_ok = Unsynchronized.ref 0 |
48289 | 47 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
48235 | 48 |
fun index_string (j, s) = s ^ "@" ^ string_of_int j |
50436 | 49 |
fun str_of_res label facts ({outcome, run_time, used_facts, ...} |
50 |
: Sledgehammer_Provers.prover_result) = |
|
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 = |
48378 | 73 |
case find_first (fn (_, th) => nickname_of th = name) facts of |
48235 | 74 |
SOME (_, th) => th |
48530
d443166f9520
repaired accessibility chains generated by MaSh exporter + tuned one function out
blanchet
parents:
48438
diff
changeset
|
75 |
| NONE => error ("No fact called \"" ^ name ^ "\".") |
50358 | 76 |
val goal = goal_of_thm (Proof_Context.theory_of ctxt) th |
48245 | 77 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1 |
48404 | 78 |
val isar_deps = isar_dependencies_of all_names th |> these |
48235 | 79 |
val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS) |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
80 |
val mepo_facts = |
48406 | 81 |
Sledgehammer_MePo.mepo_suggested_facts ctxt params prover |
48381 | 82 |
slack_max_facts NONE hyp_ts concl_t facts |
48406 | 83 |
|> Sledgehammer_MePo.weight_mepo_facts |
50412 | 84 |
val mash_facts = |
85 |
find_mash_suggestions slack_max_facts suggs facts [] [] |
|
86 |
|> weight_mash_facts |
|
50383
4274b25ff4e7
take proximity into account for MaSh + fix a debilitating bug in feature generation
blanchet
parents:
50358
diff
changeset
|
87 |
val mess = [(0.5, (mepo_facts, [])), (0.5, (mash_facts, []))] |
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
88 |
val mesh_facts = mesh_facts slack_max_facts mess |
50412 | 89 |
val isar_facts = find_suggested_facts (map (rpair 1.0) isar_deps) facts |
48406 | 90 |
fun prove ok heading get facts = |
48313
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
91 |
let |
0faafdffa662
mesh facts by taking into consideration whether a fact is known to MeSh
blanchet
parents:
48312
diff
changeset
|
92 |
val facts = |
48406 | 93 |
facts |> map get |
94 |
|> Sledgehammer_Fact.maybe_instantiate_inducts ctxt hyp_ts |
|
95 |
concl_t |
|
96 |
|> take (the max_facts) |
|
48321 | 97 |
val res as {outcome, ...} = |
98 |
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
|
99 |
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
|
100 |
in str_of_res heading facts res end |
50436 | 101 |
val [mepo_s, mash_s, mesh_s, isar_s] = |
102 |
[fn () => prove mepo_ok MePoN fst mepo_facts, |
|
103 |
fn () => prove mash_ok MaShN fst mash_facts, |
|
104 |
fn () => prove mesh_ok MeshN I mesh_facts, |
|
105 |
fn () => prove isar_ok IsarN fst isar_facts] |
|
106 |
|> Par_List.map (fn f => f ()) |
|
48235 | 107 |
in |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
108 |
["Goal " ^ string_of_int j ^ ": " ^ name, mepo_s, mash_s, mesh_s, |
48300 | 109 |
isar_s] |
50437 | 110 |
|> cat_lines |> print |
48235 | 111 |
end |
48241 | 112 |
fun total_of heading ok n = |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
113 |
" " ^ heading ^ ": " ^ string_of_int (!ok) ^ " (" ^ |
48241 | 114 |
Real.fmt (StringCvt.FIX (SOME 1)) |
115 |
(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
|
116 |
val inst_inducts = Config.get ctxt Sledgehammer_Fact.instantiate_inducts |
48245 | 117 |
val options = |
48318 | 118 |
[prover, string_of_int (the max_facts) ^ " facts", |
48241 | 119 |
"slice" |> not slice ? prefix "dont_", the_default "smart" type_enc, |
120 |
the_default "smart" lam_trans, ATP_Util.string_from_time timeout, |
|
121 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
|
122 |
val n = length lines |
|
123 |
in |
|
50437 | 124 |
print " * * *"; |
125 |
print ("Options: " ^ commas options); |
|
48311 | 126 |
List.app solve_goal (tag_list 1 lines); |
48241 | 127 |
["Successes (of " ^ string_of_int n ^ " goals)", |
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
128 |
total_of MePoN mepo_ok n, |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
129 |
total_of MaShN mash_ok n, |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
130 |
total_of MeshN mesh_ok n, |
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
131 |
total_of IsarN isar_ok n] |
50437 | 132 |
|> cat_lines |> print |
48241 | 133 |
end |
48235 | 134 |
|
48234 | 135 |
end; |