blanchet@49300
|
1 |
(* Title: HOL/TPTP/mash_eval.ML
|
blanchet@49249
|
2 |
Author: Jasmin Blanchette, TU Muenchen
|
blanchet@49249
|
3 |
Copyright 2012
|
blanchet@49249
|
4 |
|
blanchet@49300
|
5 |
Evaluate proof suggestions from MaSh (Machine-learning for Sledgehammer).
|
blanchet@49249
|
6 |
*)
|
blanchet@49249
|
7 |
|
blanchet@49300
|
8 |
signature MASH_EVAL =
|
blanchet@49249
|
9 |
sig
|
blanchet@49266
|
10 |
type params = Sledgehammer_Provers.params
|
blanchet@49266
|
11 |
|
blanchet@49300
|
12 |
val evaluate_mash_suggestions :
|
blanchet@49266
|
13 |
Proof.context -> params -> theory -> string -> unit
|
blanchet@49249
|
14 |
end;
|
blanchet@49249
|
15 |
|
blanchet@49300
|
16 |
structure MaSh_Eval : MASH_EVAL =
|
blanchet@49249
|
17 |
struct
|
blanchet@49250
|
18 |
|
blanchet@49330
|
19 |
open Sledgehammer_Fact
|
blanchet@49266
|
20 |
open Sledgehammer_Filter_MaSh
|
blanchet@49255
|
21 |
|
blanchet@49330
|
22 |
val isarN = "Isar"
|
blanchet@49300
|
23 |
val iterN = "Iter"
|
blanchet@49256
|
24 |
val mashN = "MaSh"
|
blanchet@49313
|
25 |
val meshN = "Mesh"
|
blanchet@49256
|
26 |
|
blanchet@49308
|
27 |
val max_facts_slack = 2
|
blanchet@49250
|
28 |
|
blanchet@49333
|
29 |
fun all_names ctxt prover =
|
blanchet@49333
|
30 |
filter_out (is_likely_tautology ctxt prover orf is_too_meta)
|
blanchet@49331
|
31 |
#> map (rpair () o Thm.get_name_hint) #> Symtab.make
|
blanchet@49331
|
32 |
|
blanchet@49300
|
33 |
fun evaluate_mash_suggestions ctxt params thy file_name =
|
blanchet@49250
|
34 |
let
|
blanchet@49308
|
35 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} =
|
blanchet@49254
|
36 |
Sledgehammer_Isar.default_params ctxt []
|
blanchet@49333
|
37 |
val prover = hd provers
|
blanchet@49328
|
38 |
val slack_max_facts = max_facts_slack * the max_facts
|
blanchet@49250
|
39 |
val path = file_name |> Path.explode
|
blanchet@49250
|
40 |
val lines = path |> File.read_lines
|
blanchet@49314
|
41 |
val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt
|
blanchet@49330
|
42 |
val facts = all_facts_of thy css_table
|
blanchet@49333
|
43 |
val all_names = all_names ctxt prover (facts |> map snd)
|
blanchet@49266
|
44 |
val iter_ok = Unsynchronized.ref 0
|
blanchet@49256
|
45 |
val mash_ok = Unsynchronized.ref 0
|
blanchet@49313
|
46 |
val mesh_ok = Unsynchronized.ref 0
|
blanchet@49315
|
47 |
val isar_ok = Unsynchronized.ref 0
|
blanchet@49304
|
48 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s)
|
blanchet@49250
|
49 |
fun index_string (j, s) = s ^ "@" ^ string_of_int j
|
blanchet@49255
|
50 |
fun str_of_res label facts {outcome, run_time, used_facts, ...} =
|
blanchet@49304
|
51 |
let val facts = facts |> map (fn ((name, _), _) => name ()) in
|
blanchet@49304
|
52 |
" " ^ label ^ ": " ^
|
blanchet@49304
|
53 |
(if is_none outcome then
|
blanchet@49304
|
54 |
"Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^
|
blanchet@49304
|
55 |
(used_facts |> map (with_index facts o fst)
|
blanchet@49304
|
56 |
|> sort (int_ord o pairself fst)
|
blanchet@49304
|
57 |
|> map index_string
|
blanchet@49304
|
58 |
|> space_implode " ") ^
|
blanchet@49308
|
59 |
(if length facts < the max_facts then
|
blanchet@49304
|
60 |
" (of " ^ string_of_int (length facts) ^ ")"
|
blanchet@49304
|
61 |
else
|
blanchet@49304
|
62 |
"")
|
blanchet@49304
|
63 |
else
|
blanchet@49304
|
64 |
"Failure: " ^
|
blanchet@49308
|
65 |
(facts |> take (the max_facts) |> tag_list 1
|
blanchet@49304
|
66 |
|> map index_string
|
blanchet@49304
|
67 |
|> space_implode " "))
|
blanchet@49304
|
68 |
end
|
blanchet@49326
|
69 |
fun solve_goal (j, line) =
|
blanchet@49250
|
70 |
let
|
blanchet@49326
|
71 |
val (name, suggs) = extract_query line
|
blanchet@49250
|
72 |
val th =
|
blanchet@49250
|
73 |
case find_first (fn (_, th) => Thm.get_name_hint th = name) facts of
|
blanchet@49250
|
74 |
SOME (_, th) => th
|
blanchet@49250
|
75 |
| NONE => error ("No fact called \"" ^ name ^ "\"")
|
blanchet@49265
|
76 |
val goal = goal_of_thm thy th
|
blanchet@49260
|
77 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
|
blanchet@49328
|
78 |
val isar_deps = isabelle_dependencies_of all_names th
|
blanchet@49250
|
79 |
val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS)
|
blanchet@49328
|
80 |
val isar_facts = suggested_facts isar_deps facts
|
blanchet@49266
|
81 |
val iter_facts =
|
blanchet@49307
|
82 |
Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params
|
blanchet@49333
|
83 |
prover slack_max_facts NONE hyp_ts concl_t facts
|
blanchet@49335
|
84 |
val mash_facts = facts |> suggested_facts suggs
|
blanchet@49335
|
85 |
val mess = [(iter_facts, []), (mash_facts, [])]
|
blanchet@49328
|
86 |
val mesh_facts = mesh_facts slack_max_facts mess
|
blanchet@49328
|
87 |
fun prove ok heading facts =
|
blanchet@49328
|
88 |
let
|
blanchet@49328
|
89 |
val facts =
|
blanchet@49333
|
90 |
facts
|
blanchet@49333
|
91 |
|> Sledgehammer_Fact.maybe_instantiate_inducts ctxt hyp_ts concl_t
|
blanchet@49333
|
92 |
|> take (the max_facts)
|
blanchet@49336
|
93 |
val res as {outcome, ...} =
|
blanchet@49336
|
94 |
run_prover_for_mash ctxt params prover facts goal
|
blanchet@49328
|
95 |
val _ = if is_none outcome then ok := !ok + 1 else ()
|
blanchet@49328
|
96 |
in str_of_res heading facts res end
|
blanchet@49328
|
97 |
val iter_s = prove iter_ok iterN iter_facts
|
blanchet@49328
|
98 |
val mash_s = prove mash_ok mashN mash_facts
|
blanchet@49328
|
99 |
val mesh_s = prove mesh_ok meshN mesh_facts
|
blanchet@49328
|
100 |
val isar_s = prove isar_ok isarN isar_facts
|
blanchet@49250
|
101 |
in
|
blanchet@49315
|
102 |
["Goal " ^ string_of_int j ^ ": " ^ name, iter_s, mash_s, mesh_s,
|
blanchet@49315
|
103 |
isar_s]
|
blanchet@49256
|
104 |
|> cat_lines |> tracing
|
blanchet@49250
|
105 |
end
|
blanchet@49256
|
106 |
fun total_of heading ok n =
|
blanchet@49256
|
107 |
" " ^ heading ^ ": " ^ string_of_int (!ok) ^ " (" ^
|
blanchet@49256
|
108 |
Real.fmt (StringCvt.FIX (SOME 1))
|
blanchet@49256
|
109 |
(100.0 * Real.fromInt (!ok) / Real.fromInt n) ^ "%)"
|
blanchet@49265
|
110 |
val inst_inducts = Config.get ctxt Sledgehammer_Fact.instantiate_inducts
|
blanchet@49260
|
111 |
val options =
|
blanchet@49333
|
112 |
[prover, string_of_int (the max_facts) ^ " facts",
|
blanchet@49256
|
113 |
"slice" |> not slice ? prefix "dont_", the_default "smart" type_enc,
|
blanchet@49256
|
114 |
the_default "smart" lam_trans, ATP_Util.string_from_time timeout,
|
blanchet@49256
|
115 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"]
|
blanchet@49256
|
116 |
val n = length lines
|
blanchet@49256
|
117 |
in
|
blanchet@49256
|
118 |
tracing " * * *";
|
blanchet@49260
|
119 |
tracing ("Options: " ^ commas options);
|
blanchet@49326
|
120 |
List.app solve_goal (tag_list 1 lines);
|
blanchet@49256
|
121 |
["Successes (of " ^ string_of_int n ^ " goals)",
|
blanchet@49266
|
122 |
total_of iterN iter_ok n,
|
blanchet@49256
|
123 |
total_of mashN mash_ok n,
|
blanchet@49313
|
124 |
total_of meshN mesh_ok n,
|
blanchet@49315
|
125 |
total_of isarN isar_ok n]
|
blanchet@49256
|
126 |
|> cat_lines |> tracing
|
blanchet@49256
|
127 |
end
|
blanchet@49250
|
128 |
|
blanchet@49249
|
129 |
end;
|