author | wenzelm |
Tue, 03 Sep 2013 01:12:40 +0200 | |
changeset 53374 | a14d2a854c02 |
parent 53139 | 07a6e11f1631 |
child 53980 | 7e6a82c593f4 |
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 |
|
51015 | 12 |
val MePoN : string |
50953 | 13 |
val MaSh_IsarN : string |
14 |
val MaSh_ProverN : string |
|
15 |
val MeSh_IsarN : string |
|
16 |
val MeSh_ProverN : string |
|
17 |
val IsarN : string |
|
50437 | 18 |
val evaluate_mash_suggestions : |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51135
diff
changeset
|
19 |
Proof.context -> params -> int * int option -> bool -> string list |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51135
diff
changeset
|
20 |
-> string option -> string -> string -> string -> string -> string -> string |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51135
diff
changeset
|
21 |
-> unit |
48234 | 22 |
end; |
23 |
||
48285 | 24 |
structure MaSh_Eval : MASH_EVAL = |
48234 | 25 |
struct |
48235 | 26 |
|
50557 | 27 |
open Sledgehammer_Util |
48315
82d6e46c673f
fixed order of accessibles + other tweaks to MaSh
blanchet
parents:
48313
diff
changeset
|
28 |
open Sledgehammer_Fact |
50557 | 29 |
open Sledgehammer_MePo |
48381 | 30 |
open Sledgehammer_MaSh |
50557 | 31 |
open Sledgehammer_Provers |
32 |
open Sledgehammer_Isar |
|
48240 | 33 |
|
51008 | 34 |
val MaSh_IsarN = MaShN ^ "-Isar" |
35 |
val MaSh_ProverN = MaShN ^ "-Prover" |
|
36 |
val MeSh_IsarN = MeShN ^ "-Isar" |
|
37 |
val MeSh_ProverN = MeShN ^ "-Prover" |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
38 |
val IsarN = "Isar" |
48241 | 39 |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
40 |
fun in_range (from, to) j = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
41 |
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
|
42 |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51135
diff
changeset
|
43 |
fun evaluate_mash_suggestions ctxt params range linearize methods prob_dir_name |
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
44 |
mepo_file_name mash_isar_file_name mash_prover_file_name |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
45 |
mesh_isar_file_name mesh_prover_file_name report_file_name = |
48235 | 46 |
let |
51028 | 47 |
val zeros = [0, 0, 0, 0, 0, 0] |
50448
0a740d127187
have MaSh evaluator keep all raw problem/solution files in a directory
blanchet
parents:
50442
diff
changeset
|
48 |
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
|
49 |
val _ = File.write report_path "" |
50589 | 50 |
fun print s = File.append report_path (s ^ "\n") |
48293 | 51 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} = |
50557 | 52 |
default_params ctxt [] |
48318 | 53 |
val prover = hd provers |
50412 | 54 |
val slack_max_facts = generous_max_facts (the max_facts) |
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
55 |
val lines_of = Path.explode #> try File.read_lines #> these |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
56 |
val file_names = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
57 |
[mepo_file_name, mash_isar_file_name, mash_prover_file_name, |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
58 |
mesh_isar_file_name, mesh_prover_file_name] |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
59 |
val lines as [mepo_lines, mash_isar_lines, mash_prover_lines, |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
60 |
mesh_isar_lines, mesh_prover_lines] = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
61 |
map lines_of file_names |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
62 |
val num_lines = fold (Integer.max o length) lines 0 |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
63 |
fun pad lines = lines @ replicate (num_lines - length lines) "" |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
64 |
val lines = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
65 |
pad mepo_lines ~~ pad mash_isar_lines ~~ pad mash_prover_lines ~~ |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
66 |
pad mesh_isar_lines ~~ pad mesh_prover_lines |
50557 | 67 |
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
|
68 |
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
|
69 |
val name_tabs = build_name_tables nickname_of_thm facts |
48289 | 70 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
50952 | 71 |
fun index_str (j, s) = s ^ "@" ^ string_of_int j |
50953 | 72 |
val str_of_method = enclose " " ": " |
73 |
fun str_of_result method facts ({outcome, run_time, used_facts, ...} |
|
50952 | 74 |
: prover_result) = |
51004
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50967
diff
changeset
|
75 |
let val facts = facts |> map (fst o fst) in |
50953 | 76 |
str_of_method method ^ |
48289 | 77 |
(if is_none outcome then |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51199
diff
changeset
|
78 |
"Success (" ^ ATP_Util.string_of_time run_time ^ "): " ^ |
48289 | 79 |
(used_facts |> map (with_index facts o fst) |
80 |
|> sort (int_ord o pairself fst) |
|
50952 | 81 |
|> map index_str |
48289 | 82 |
|> space_implode " ") ^ |
48293 | 83 |
(if length facts < the max_facts then |
48289 | 84 |
" (of " ^ string_of_int (length facts) ^ ")" |
85 |
else |
|
86 |
"") |
|
87 |
else |
|
88 |
"Failure: " ^ |
|
48293 | 89 |
(facts |> take (the max_facts) |> tag_list 1 |
50952 | 90 |
|> map index_str |
48289 | 91 |
|> space_implode " ")) |
92 |
end |
|
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
93 |
fun solve_goal (j, ((((mepo_line, mash_isar_line), mash_prover_line), |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
94 |
mesh_isar_line), mesh_prover_line)) = |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
95 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
96 |
let |
50965 | 97 |
val get_suggs = extract_suggestions ##> take slack_max_facts |
98 |
val (name1, mepo_suggs) = get_suggs mepo_line |
|
99 |
val (name2, mash_isar_suggs) = get_suggs mash_isar_line |
|
100 |
val (name3, mash_prover_suggs) = get_suggs mash_prover_line |
|
101 |
val (name4, mesh_isar_suggs) = get_suggs mesh_isar_line |
|
102 |
val (name5, mesh_prover_suggs) = get_suggs mesh_prover_line |
|
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
103 |
val [name] = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
104 |
[name1, name2, name3, name4, name5] |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
105 |
|> filter (curry (op <>) "") |> distinct (op =) |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
106 |
handle General.Match => error "Input files out of sync." |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
107 |
val th = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
108 |
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
|
109 |
SOME (_, th) => th |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
110 |
| NONE => error ("No fact called \"" ^ name ^ "\".") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
111 |
val goal = goal_of_thm (Proof_Context.theory_of ctxt) th |
52196
2281f33e8da6
redid rac7830871177 to avoid duplicate fixed variable (e.g. lemma "P (a::nat)" proof - have "!!a::int. Q a" sledgehammer [e])
blanchet
parents:
52125
diff
changeset
|
112 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal goal 1 ctxt |
50754
74a6adcb96ac
also generate queries for goals with too many Isar dependencies
blanchet
parents:
50735
diff
changeset
|
113 |
val isar_deps = isar_dependencies_of name_tabs th |
51135 | 114 |
val facts = |
51199
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
115 |
facts |
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
116 |
|> filter (fn (_, th') => |
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
117 |
if linearize then crude_thm_ord (th', th) = LESS |
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
118 |
else thm_less (th', th)) |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
119 |
(* adapted from "mirabelle_sledgehammer.ML" *) |
50953 | 120 |
fun set_file_name method (SOME dir) = |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
121 |
let |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
122 |
val prob_prefix = |
50826 | 123 |
"goal_" ^ string_of_int j ^ "__" ^ encode_str name ^ "__" ^ |
50953 | 124 |
method |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
125 |
in |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
126 |
Config.put dest_dir dir |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
127 |
#> Config.put problem_prefix (prob_prefix ^ "__") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
128 |
#> 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
|
129 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
130 |
| set_file_name _ NONE = I |
53139 | 131 |
fun prove method suggs = |
50953 | 132 |
if not (member (op =) methods method) orelse |
133 |
(null facts andalso method <> IsarN) then |
|
134 |
(str_of_method method ^ "Skipped", 0) |
|
50952 | 135 |
else |
136 |
let |
|
137 |
fun nickify ((_, stature), th) = |
|
138 |
((K (encode_str (nickname_of_thm th)), stature), th) |
|
139 |
val facts = |
|
53139 | 140 |
suggs |
141 |
|> find_suggested_facts ctxt facts |
|
142 |
|> map (fact_of_raw_fact #> nickify) |
|
50952 | 143 |
|> maybe_instantiate_inducts ctxt hyp_ts concl_t |
144 |
|> take (the max_facts) |
|
51004
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50967
diff
changeset
|
145 |
|> map fact_of_raw_fact |
50953 | 146 |
val ctxt = ctxt |> set_file_name method prob_dir_name |
50952 | 147 |
val res as {outcome, ...} = |
148 |
run_prover_for_mash ctxt params prover facts goal |
|
149 |
val ok = if is_none outcome then 1 else 0 |
|
50953 | 150 |
in (str_of_result method facts res, ok) end |
50591 | 151 |
val ress = |
53139 | 152 |
[fn () => prove MePoN mepo_suggs, |
153 |
fn () => prove MaSh_IsarN mash_isar_suggs, |
|
154 |
fn () => prove MaSh_ProverN mash_prover_suggs, |
|
155 |
fn () => prove MeSh_IsarN mesh_isar_suggs, |
|
156 |
fn () => prove MeSh_ProverN mesh_prover_suggs, |
|
157 |
fn () => prove IsarN isar_deps] |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
158 |
|> (* Par_List. *) map (fn f => f ()) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
159 |
in |
50591 | 160 |
"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
|
161 |
|> cat_lines |> print; |
50591 | 162 |
map snd ress |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
163 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
164 |
else |
51028 | 165 |
zeros |
50953 | 166 |
fun total_of method ok n = |
167 |
str_of_method method ^ string_of_int ok ^ " (" ^ |
|
50591 | 168 |
Real.fmt (StringCvt.FIX (SOME 1)) |
51028 | 169 |
(100.0 * Real.fromInt ok / Real.fromInt (Int.max (1, n))) ^ "%)" |
50557 | 170 |
val inst_inducts = Config.get ctxt instantiate_inducts |
48245 | 171 |
val options = |
50767 | 172 |
["prover = " ^ prover, |
173 |
"max_facts = " ^ string_of_int (the max_facts), |
|
174 |
"slice" |> not slice ? prefix "dont_", |
|
175 |
"type_enc = " ^ the_default "smart" type_enc, |
|
176 |
"lam_trans = " ^ the_default "smart" lam_trans, |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51199
diff
changeset
|
177 |
"timeout = " ^ ATP_Util.string_of_time (the_default one_year timeout), |
48241 | 178 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
50587
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
179 |
val _ = print " * * *"; |
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
180 |
val _ = print ("Options: " ^ commas options); |
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
181 |
val oks = Par_List.map solve_goal (tag_list 1 lines) |
50620 | 182 |
val n = length oks |
50952 | 183 |
val [mepo_ok, mash_isar_ok, mash_prover_ok, mesh_isar_ok, mesh_prover_ok, |
184 |
isar_ok] = |
|
51028 | 185 |
if n = 0 then zeros else map Integer.sum (map_transpose I oks) |
48241 | 186 |
in |
187 |
["Successes (of " ^ string_of_int n ^ " goals)", |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
188 |
total_of MePoN mepo_ok n, |
50952 | 189 |
total_of MaSh_IsarN mash_isar_ok n, |
190 |
total_of MaSh_ProverN mash_prover_ok n, |
|
191 |
total_of MeSh_IsarN mesh_isar_ok n, |
|
192 |
total_of MeSh_ProverN mesh_prover_ok n, |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
193 |
total_of IsarN isar_ok n] |
50437 | 194 |
|> cat_lines |> print |
48241 | 195 |
end |
48235 | 196 |
|
48234 | 197 |
end; |