author | blanchet |
Wed, 28 May 2014 17:42:36 +0200 | |
changeset 57108 | dc0b4f50e288 |
parent 55212 | 5832470d956e |
child 57125 | 2f620ef839ee |
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 |
55201 | 10 |
type params = Sledgehammer_Prover.params |
48251
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 |
55201 | 31 |
open Sledgehammer_Prover |
55212 | 32 |
open Sledgehammer_Prover_ATP |
55198 | 33 |
open Sledgehammer_Commands |
48240 | 34 |
|
53980
7e6a82c593f4
made SML/NJ happy (NB: toplevel ML environment is unmanaged);
wenzelm
parents:
53139
diff
changeset
|
35 |
val prefix = Library.prefix |
7e6a82c593f4
made SML/NJ happy (NB: toplevel ML environment is unmanaged);
wenzelm
parents:
53139
diff
changeset
|
36 |
|
51008 | 37 |
val MaSh_IsarN = MaShN ^ "-Isar" |
38 |
val MaSh_ProverN = MaShN ^ "-Prover" |
|
39 |
val MeSh_IsarN = MeShN ^ "-Isar" |
|
40 |
val MeSh_ProverN = MeShN ^ "-Prover" |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
41 |
val IsarN = "Isar" |
48241 | 42 |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
43 |
fun in_range (from, to) j = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
44 |
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
|
45 |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51135
diff
changeset
|
46 |
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
|
47 |
mepo_file_name mash_isar_file_name mash_prover_file_name |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
48 |
mesh_isar_file_name mesh_prover_file_name report_file_name = |
48235 | 49 |
let |
55205 | 50 |
val thy = Proof_Context.theory_of ctxt |
51028 | 51 |
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
|
52 |
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
|
53 |
val _ = File.write report_path "" |
50589 | 54 |
fun print s = File.append report_path (s ^ "\n") |
55205 | 55 |
val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} = default_params thy [] |
48318 | 56 |
val prover = hd provers |
57108
dc0b4f50e288
more generous max number of suggestions, for more safety
blanchet
parents:
55212
diff
changeset
|
57 |
val max_suggs = generous_max_suggestions (the max_facts) |
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
58 |
val lines_of = Path.explode #> try File.read_lines #> these |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
59 |
val file_names = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
60 |
[mepo_file_name, mash_isar_file_name, mash_prover_file_name, |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
61 |
mesh_isar_file_name, mesh_prover_file_name] |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
62 |
val lines as [mepo_lines, mash_isar_lines, mash_prover_lines, |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
63 |
mesh_isar_lines, mesh_prover_lines] = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
64 |
map lines_of file_names |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
65 |
val num_lines = fold (Integer.max o length) lines 0 |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
66 |
fun pad lines = lines @ replicate (num_lines - length lines) "" |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
67 |
val lines = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
68 |
pad mepo_lines ~~ pad mash_isar_lines ~~ pad mash_prover_lines ~~ |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
69 |
pad mesh_isar_lines ~~ pad mesh_prover_lines |
50557 | 70 |
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
|
71 |
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
|
72 |
val name_tabs = build_name_tables nickname_of_thm facts |
48289 | 73 |
fun with_index facts s = (find_index (curry (op =) s) facts + 1, s) |
50952 | 74 |
fun index_str (j, s) = s ^ "@" ^ string_of_int j |
50953 | 75 |
val str_of_method = enclose " " ": " |
76 |
fun str_of_result method facts ({outcome, run_time, used_facts, ...} |
|
50952 | 77 |
: 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
|
78 |
let val facts = facts |> map (fst o fst) in |
50953 | 79 |
str_of_method method ^ |
48289 | 80 |
(if is_none outcome then |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51199
diff
changeset
|
81 |
"Success (" ^ ATP_Util.string_of_time run_time ^ "): " ^ |
48289 | 82 |
(used_facts |> map (with_index facts o fst) |
83 |
|> sort (int_ord o pairself fst) |
|
50952 | 84 |
|> map index_str |
48289 | 85 |
|> space_implode " ") ^ |
48293 | 86 |
(if length facts < the max_facts then |
48289 | 87 |
" (of " ^ string_of_int (length facts) ^ ")" |
88 |
else |
|
89 |
"") |
|
90 |
else |
|
91 |
"Failure: " ^ |
|
48293 | 92 |
(facts |> take (the max_facts) |> tag_list 1 |
50952 | 93 |
|> map index_str |
48289 | 94 |
|> space_implode " ")) |
95 |
end |
|
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
99 |
let |
57108
dc0b4f50e288
more generous max number of suggestions, for more safety
blanchet
parents:
55212
diff
changeset
|
100 |
val get_suggs = extract_suggestions ##> take max_suggs |
50965 | 101 |
val (name1, mepo_suggs) = get_suggs mepo_line |
102 |
val (name2, mash_isar_suggs) = get_suggs mash_isar_line |
|
103 |
val (name3, mash_prover_suggs) = get_suggs mash_prover_line |
|
104 |
val (name4, mesh_isar_suggs) = get_suggs mesh_isar_line |
|
105 |
val (name5, mesh_prover_suggs) = get_suggs mesh_prover_line |
|
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
106 |
val [name] = |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
107 |
[name1, name2, name3, name4, name5] |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
108 |
|> filter (curry (op <>) "") |> distinct (op =) |
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
109 |
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
|
110 |
val th = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50620
diff
changeset
|
111 |
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
|
112 |
SOME (_, th) => th |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
113 |
| NONE => error ("No fact called \"" ^ name ^ "\".") |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
val isar_deps = isar_dependencies_of name_tabs th |
51135 | 117 |
val facts = |
51199
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
118 |
facts |
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
119 |
|> filter (fn (_, th') => |
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
120 |
if linearize then crude_thm_ord (th', th) = LESS |
e3447c380fe1
honor linearization option also in the evaluation driver
blanchet
parents:
51182
diff
changeset
|
121 |
else thm_less (th', th)) |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
122 |
(* adapted from "mirabelle_sledgehammer.ML" *) |
50953 | 123 |
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
|
124 |
let |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
125 |
val prob_prefix = |
50826 | 126 |
"goal_" ^ string_of_int j ^ "__" ^ encode_str name ^ "__" ^ |
50953 | 127 |
method |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
128 |
in |
55212 | 129 |
Config.put atp_dest_dir dir |
130 |
#> Config.put atp_problem_prefix (prob_prefix ^ "__") |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
131 |
#> 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
|
132 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
133 |
| set_file_name _ NONE = I |
53139 | 134 |
fun prove method suggs = |
50953 | 135 |
if not (member (op =) methods method) orelse |
136 |
(null facts andalso method <> IsarN) then |
|
137 |
(str_of_method method ^ "Skipped", 0) |
|
50952 | 138 |
else |
139 |
let |
|
140 |
fun nickify ((_, stature), th) = |
|
141 |
((K (encode_str (nickname_of_thm th)), stature), th) |
|
142 |
val facts = |
|
53139 | 143 |
suggs |
144 |
|> find_suggested_facts ctxt facts |
|
145 |
|> map (fact_of_raw_fact #> nickify) |
|
50952 | 146 |
|> maybe_instantiate_inducts ctxt hyp_ts concl_t |
147 |
|> 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
|
148 |
|> map fact_of_raw_fact |
50953 | 149 |
val ctxt = ctxt |> set_file_name method prob_dir_name |
50952 | 150 |
val res as {outcome, ...} = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
53980
diff
changeset
|
151 |
run_prover_for_mash ctxt params prover name facts goal |
50952 | 152 |
val ok = if is_none outcome then 1 else 0 |
50953 | 153 |
in (str_of_result method facts res, ok) end |
50591 | 154 |
val ress = |
53139 | 155 |
[fn () => prove MePoN mepo_suggs, |
156 |
fn () => prove MaSh_IsarN mash_isar_suggs, |
|
157 |
fn () => prove MaSh_ProverN mash_prover_suggs, |
|
158 |
fn () => prove MeSh_IsarN mesh_isar_suggs, |
|
159 |
fn () => prove MeSh_ProverN mesh_prover_suggs, |
|
160 |
fn () => prove IsarN isar_deps] |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
161 |
|> (* Par_List. *) map (fn f => f ()) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
162 |
in |
50591 | 163 |
"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
|
164 |
|> cat_lines |> print; |
50591 | 165 |
map snd ress |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
166 |
end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50557
diff
changeset
|
167 |
else |
51028 | 168 |
zeros |
50953 | 169 |
fun total_of method ok n = |
170 |
str_of_method method ^ string_of_int ok ^ " (" ^ |
|
50591 | 171 |
Real.fmt (StringCvt.FIX (SOME 1)) |
51028 | 172 |
(100.0 * Real.fromInt ok / Real.fromInt (Int.max (1, n))) ^ "%)" |
50557 | 173 |
val inst_inducts = Config.get ctxt instantiate_inducts |
48245 | 174 |
val options = |
50767 | 175 |
["prover = " ^ prover, |
176 |
"max_facts = " ^ string_of_int (the max_facts), |
|
177 |
"slice" |> not slice ? prefix "dont_", |
|
178 |
"type_enc = " ^ the_default "smart" type_enc, |
|
179 |
"lam_trans = " ^ the_default "smart" lam_trans, |
|
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54141
diff
changeset
|
180 |
"timeout = " ^ ATP_Util.string_of_time timeout, |
48241 | 181 |
"instantiate_inducts" |> not inst_inducts ? prefix "dont_"] |
50587
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
182 |
val _ = print " * * *"; |
bd6582be1562
synchronize access to shared reference and print proper total
blanchet
parents:
50563
diff
changeset
|
183 |
val _ = print ("Options: " ^ commas options); |
50964
2a990baa09af
use precomputed MaSh/MePo data whenever available
blanchet
parents:
50953
diff
changeset
|
184 |
val oks = Par_List.map solve_goal (tag_list 1 lines) |
50620 | 185 |
val n = length oks |
50952 | 186 |
val [mepo_ok, mash_isar_ok, mash_prover_ok, mesh_isar_ok, mesh_prover_ok, |
187 |
isar_ok] = |
|
51028 | 188 |
if n = 0 then zeros else map Integer.sum (map_transpose I oks) |
48241 | 189 |
in |
190 |
["Successes (of " ^ string_of_int n ^ " goals)", |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
191 |
total_of MePoN mepo_ok n, |
50952 | 192 |
total_of MaSh_IsarN mash_isar_ok n, |
193 |
total_of MaSh_ProverN mash_prover_ok n, |
|
194 |
total_of MeSh_IsarN mesh_isar_ok n, |
|
195 |
total_of MeSh_ProverN mesh_prover_ok n, |
|
48379
2b5ad61e2ccc
renamed "iter" fact filter to "MePo" (Meng--Paulson)
blanchet
parents:
48378
diff
changeset
|
196 |
total_of IsarN isar_ok n] |
50437 | 197 |
|> cat_lines |> print |
48241 | 198 |
end |
48235 | 199 |
|
48234 | 200 |
end; |