author | blanchet |
Mon, 19 May 2014 23:43:53 +0200 | |
changeset 57005 | 33f3d2ea803d |
parent 55212 | 5832470d956e |
child 57055 | df3a26987a8d |
permissions | -rw-r--r-- |
48234 | 1 |
(* Title: HOL/TPTP/mash_export.ML |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
3 |
Copyright 2012 |
|
4 |
||
5 |
Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer). |
|
6 |
*) |
|
7 |
||
8 |
signature MASH_EXPORT = |
|
9 |
sig |
|
55201 | 10 |
type params = Sledgehammer_Prover.params |
48235 | 11 |
|
55212 | 12 |
val generate_accessibility : Proof.context -> theory list -> bool -> string -> unit |
13 |
val generate_features : Proof.context -> theory list -> string -> unit |
|
14 |
val generate_isar_dependencies : Proof.context -> int * int option -> theory list -> bool -> |
|
15 |
string -> unit |
|
16 |
val generate_prover_dependencies : Proof.context -> params -> int * int option -> theory list -> |
|
17 |
bool -> string -> unit |
|
18 |
val generate_isar_commands : Proof.context -> string -> (int * int option) * int -> theory list -> |
|
19 |
bool -> int -> string -> unit |
|
20 |
val generate_prover_commands : Proof.context -> params -> (int * int option) * int -> |
|
21 |
theory list -> bool -> int -> string -> unit |
|
22 |
val generate_mepo_suggestions : Proof.context -> params -> (int * int option) * int -> |
|
23 |
theory list -> bool -> int -> string -> unit |
|
50814 | 24 |
val generate_mesh_suggestions : int -> string -> string -> string -> unit |
48234 | 25 |
end; |
26 |
||
27 |
structure MaSh_Export : MASH_EXPORT = |
|
28 |
struct |
|
29 |
||
50485
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50484
diff
changeset
|
30 |
open Sledgehammer_Fact |
55212 | 31 |
open Sledgehammer_Prover_ATP |
48381 | 32 |
open Sledgehammer_MePo |
33 |
open Sledgehammer_MaSh |
|
48245 | 34 |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
35 |
fun in_range (from, to) j = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
36 |
j >= from andalso (to = NONE orelse j <= the to) |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
37 |
|
50349 | 38 |
fun has_thm_thy th thy = |
48316
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents:
48315
diff
changeset
|
39 |
Context.theory_name thy = Context.theory_name (theory_of_thm th) |
252f45c04042
drastic overhaul of MaSh data structures + fixed a few performance issues
blanchet
parents:
48315
diff
changeset
|
40 |
|
50349 | 41 |
fun has_thys thys th = exists (has_thm_thy th) thys |
42 |
||
43 |
fun all_facts ctxt = |
|
48531 | 44 |
let val css = Sledgehammer_Fact.clasimpset_rule_table_of ctxt in |
50442
4f6a4d32522c
don't blacklist "case" theorems -- this causes problems in MaSh later
blanchet
parents:
50434
diff
changeset
|
45 |
Sledgehammer_Fact.all_facts ctxt true false Symtab.empty [] [] css |
51135 | 46 |
|> sort (crude_thm_ord o pairself snd) |
48531 | 47 |
end |
48 |
||
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
49 |
fun filter_accessible_from th = filter (fn (_, th') => thm_less (th', th)) |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
50 |
|
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
51 |
fun generate_accessibility ctxt thys linearize file_name = |
48304 | 52 |
let |
53 |
val path = file_name |> Path.explode |
|
54 |
val _ = File.write path "" |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
55 |
fun do_fact (parents, fact) prevs = |
48304 | 56 |
let |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
57 |
val parents = if linearize then prevs else parents |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
58 |
val s = encode_str fact ^ ": " ^ encode_strs parents ^ "\n" |
48304 | 59 |
val _ = File.append path s |
60 |
in [fact] end |
|
50611
99af6b652b3a
linearize eval driver, to work around horrible bug in previous implementation
blanchet
parents:
50582
diff
changeset
|
61 |
val facts = |
50349 | 62 |
all_facts ctxt |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
63 |
|> filter_out (has_thys thys o snd) |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
64 |
|> attach_parents_to_facts [] |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
65 |
|> map (apsnd (nickname_of_thm o snd)) |
50611
99af6b652b3a
linearize eval driver, to work around horrible bug in previous implementation
blanchet
parents:
50582
diff
changeset
|
66 |
in fold do_fact facts []; () end |
48304 | 67 |
|
55212 | 68 |
fun generate_features ctxt thys file_name = |
48304 | 69 |
let |
70 |
val path = file_name |> Path.explode |
|
71 |
val _ = File.write path "" |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
72 |
val facts = all_facts ctxt |> filter_out (has_thys thys o snd) |
48385 | 73 |
fun do_fact ((_, stature), th) = |
48304 | 74 |
let |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50611
diff
changeset
|
75 |
val name = nickname_of_thm th |
48318 | 76 |
val feats = |
54695 | 77 |
features_of ctxt (theory_of_thm th) 0 Symtab.empty stature false [prop_of th] |> map fst |
57005
33f3d2ea803d
store all MaSh data on the Isabelle side, in preparation for replacing 'mash.py' with ML solution
blanchet
parents:
55212
diff
changeset
|
78 |
val s = encode_str name ^ ": " ^ encode_unweighted_features (sort_wrt hd feats) ^ "\n" |
48304 | 79 |
in File.append path s end |
80 |
in List.app do_fact facts end |
|
81 |
||
51034 | 82 |
val prover_marker = "$a" |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
83 |
val isar_marker = "$i" |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
84 |
val omitted_marker = "$o" |
51034 | 85 |
val unprovable_marker = "$u" (* axiom or definition or characteristic theorem *) |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
86 |
val prover_failed_marker = "$x" |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
87 |
|
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
88 |
fun smart_dependencies_of ctxt params_opt facts name_tabs th isar_deps_opt = |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
89 |
let |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
90 |
val (marker, deps) = |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
91 |
case params_opt of |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
92 |
SOME (params as {provers = prover :: _, ...}) => |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
93 |
prover_dependencies_of ctxt params prover 0 facts name_tabs th |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
94 |
|>> (fn true => prover_marker | false => prover_failed_marker) |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
95 |
| NONE => |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
96 |
let |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
97 |
val deps = |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
98 |
case isar_deps_opt of |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
99 |
SOME deps => deps |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
100 |
| NONE => isar_dependencies_of name_tabs th |
51034 | 101 |
in (if null deps then unprovable_marker else isar_marker, deps) end |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
102 |
in |
51177 | 103 |
case trim_dependencies deps of |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
104 |
SOME deps => (marker, deps) |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
105 |
| NONE => (omitted_marker, []) |
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
106 |
end |
50411 | 107 |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
108 |
fun generate_isar_or_prover_dependencies ctxt params_opt range thys linearize |
50484
8ec31bdb9d36
adopt the neutral "prover" terminology for MaSh rather than the ambiguous/wrong ATP terminology (which sometimes excludes SMT solvers)
blanchet
parents:
50442
diff
changeset
|
109 |
file_name = |
48304 | 110 |
let |
111 |
val path = file_name |> Path.explode |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
112 |
val facts = all_facts ctxt |> filter_out (has_thys thys o snd) |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50624
diff
changeset
|
113 |
val name_tabs = build_name_tables nickname_of_thm facts |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
114 |
fun do_fact (j, (_, th)) = |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
115 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
116 |
let |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50611
diff
changeset
|
117 |
val name = nickname_of_thm th |
50561 | 118 |
val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
119 |
val access_facts = |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
120 |
if linearize then take (j - 1) facts |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
121 |
else facts |> filter_accessible_from th |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
122 |
val (marker, deps) = |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
123 |
smart_dependencies_of ctxt params_opt access_facts name_tabs th NONE |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
124 |
in encode_str name ^ ": " ^ marker ^ " " ^ encode_strs deps ^ "\n" end |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
125 |
else |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
126 |
"" |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
127 |
val lines = Par_List.map do_fact (tag_list 1 facts) |
50519 | 128 |
in File.write_list path lines end |
48304 | 129 |
|
50411 | 130 |
fun generate_isar_dependencies ctxt = |
54118 | 131 |
generate_isar_or_prover_dependencies ctxt NONE |
50411 | 132 |
|
50484
8ec31bdb9d36
adopt the neutral "prover" terminology for MaSh rather than the ambiguous/wrong ATP terminology (which sometimes excludes SMT solvers)
blanchet
parents:
50442
diff
changeset
|
133 |
fun generate_prover_dependencies ctxt params = |
8ec31bdb9d36
adopt the neutral "prover" terminology for MaSh rather than the ambiguous/wrong ATP terminology (which sometimes excludes SMT solvers)
blanchet
parents:
50442
diff
changeset
|
134 |
generate_isar_or_prover_dependencies ctxt (SOME params) |
50411 | 135 |
|
50954 | 136 |
fun is_bad_query ctxt ho_atp step j th isar_deps = |
137 |
j mod step <> 0 orelse |
|
50859
c0f38015a632
don't generate queries with empty dependency list
blanchet
parents:
50829
diff
changeset
|
138 |
Thm.legacy_get_kind th = "" orelse |
51020 | 139 |
null isar_deps orelse |
50523
0799339fea0f
get rid of some junk facts in the MaSh evaluation driver
blanchet
parents:
50519
diff
changeset
|
140 |
is_blacklisted_or_something ctxt ho_atp (Thm.get_name_hint th) |
50515
c4a27ab89c9b
shared bad MaSh query detection between MePo and MaSh, so that the generated files mirror each other
blanchet
parents:
50511
diff
changeset
|
141 |
|
50954 | 142 |
fun generate_isar_or_prover_commands ctxt prover params_opt (range, step) thys |
53120 | 143 |
linearize max_suggs file_name = |
48234 | 144 |
let |
55212 | 145 |
val ho_atp = is_ho_atp ctxt prover |
48234 | 146 |
val path = file_name |> Path.explode |
50349 | 147 |
val facts = all_facts ctxt |
50485
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50484
diff
changeset
|
148 |
val (new_facts, old_facts) = facts |> List.partition (has_thys thys o snd) |
53127 | 149 |
val num_old_facts = length old_facts |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50624
diff
changeset
|
150 |
val name_tabs = build_name_tables nickname_of_thm facts |
53127 | 151 |
fun do_fact (j, |
152 |
(((name, (parents, ((_, stature), th))), prevs), const_tab)) = |
|
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
153 |
if in_range range j then |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
154 |
let |
50561 | 155 |
val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
53127 | 156 |
val isar_deps = isar_dependencies_of name_tabs th |
157 |
val do_query = not (is_bad_query ctxt ho_atp step j th isar_deps) |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
158 |
val access_facts = |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
159 |
(if linearize then take (j - 1) new_facts |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
160 |
else new_facts |> filter_accessible_from th) @ old_facts |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
161 |
val (marker, deps) = |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
162 |
smart_dependencies_of ctxt params_opt access_facts name_tabs th |
51033
177db6811f11
added markers in proofs identifying origin of proofs, in eval driver
blanchet
parents:
51020
diff
changeset
|
163 |
(SOME isar_deps) |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
164 |
val parents = if linearize then prevs else parents |
53140
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
165 |
fun extra_features_of (((_, stature), th), weight) = |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
166 |
[prop_of th] |
54695 | 167 |
|> features_of ctxt (theory_of_thm th) (num_old_facts + j) const_tab stature false |
53141
d27e99a6a679
take chained and proximate facts into consideration when computing MaSh features
blanchet
parents:
53140
diff
changeset
|
168 |
|> map (apsnd (fn r => weight * extra_feature_factor * r)) |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
169 |
val query = |
53127 | 170 |
if do_query then |
53140
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
171 |
let |
54695 | 172 |
val goal_feats = |
173 |
features_of ctxt (theory_of_thm th) (num_old_facts + j) const_tab stature true |
|
174 |
[prop_of th] |
|
175 |
|> sort_wrt (hd o fst) |
|
53141
d27e99a6a679
take chained and proximate facts into consideration when computing MaSh features
blanchet
parents:
53140
diff
changeset
|
176 |
val query_feats = |
53140
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
177 |
new_facts |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
178 |
|> drop (j - num_extra_feature_facts) |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
179 |
|> take num_extra_feature_facts |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
180 |
|> rev |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
181 |
|> weight_facts_steeply |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
182 |
|> map extra_features_of |
53159 | 183 |
|> rpair goal_feats |-> fold (union (eq_fst (op =))) |
53140
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
184 |
in |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
185 |
"? " ^ string_of_int max_suggs ^ " # " ^ |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
186 |
encode_str name ^ ": " ^ encode_strs parents ^ "; " ^ |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
187 |
encode_features query_feats ^ "\n" |
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
188 |
end |
53127 | 189 |
else |
190 |
"" |
|
54695 | 191 |
val nongoal_feats = |
192 |
features_of ctxt (theory_of_thm th) (num_old_facts + j) const_tab stature false |
|
193 |
[prop_of th] |
|
194 |
|> map fst |> sort_wrt hd |
|
50754
74a6adcb96ac
also generate queries for goals with too many Isar dependencies
blanchet
parents:
50735
diff
changeset
|
195 |
val update = |
53121
5f727525b1ac
only generate feature weights for queries -- they're not used elsewhere
blanchet
parents:
53120
diff
changeset
|
196 |
"! " ^ encode_str name ^ ": " ^ encode_strs parents ^ "; " ^ |
57005
33f3d2ea803d
store all MaSh data on the Isabelle side, in preparation for replacing 'mash.py' with ML solution
blanchet
parents:
55212
diff
changeset
|
197 |
encode_unweighted_features nongoal_feats ^ "; " ^ marker ^ " " ^ encode_strs deps ^ "\n" |
50559
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
198 |
in query ^ update end |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
199 |
else |
89c0d2f13cca
MaSh exporter can now export subsets of the facts, as consecutive ranges
blanchet
parents:
50523
diff
changeset
|
200 |
"" |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
201 |
val new_facts = |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
202 |
new_facts |> attach_parents_to_facts old_facts |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
203 |
|> map (`(nickname_of_thm o snd o snd)) |
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
204 |
val hd_prevs = |
50624
4d0997abce79
improved thm order hack, in case the default names are overridden
blanchet
parents:
50611
diff
changeset
|
205 |
map (nickname_of_thm o snd) (the_list (try List.last old_facts)) |
53127 | 206 |
val prevss = hd_prevs :: map (single o fst) new_facts |> split_last |> fst |
207 |
val hd_const_tabs = |
|
208 |
fold (add_const_counts o prop_of o snd) old_facts Symtab.empty |
|
209 |
val (const_tabs, _) = |
|
210 |
fold_map (`I oo add_const_counts o prop_of o snd o snd o snd) new_facts |
|
211 |
hd_const_tabs |
|
212 |
val lines = |
|
213 |
Par_List.map do_fact (tag_list 1 (new_facts ~~ prevss ~~ const_tabs)) |
|
50519 | 214 |
in File.write_list path lines end |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
215 |
|
50411 | 216 |
fun generate_isar_commands ctxt prover = |
50954 | 217 |
generate_isar_or_prover_commands ctxt prover NONE |
50411 | 218 |
|
50484
8ec31bdb9d36
adopt the neutral "prover" terminology for MaSh rather than the ambiguous/wrong ATP terminology (which sometimes excludes SMT solvers)
blanchet
parents:
50442
diff
changeset
|
219 |
fun generate_prover_commands ctxt (params as {provers = prover :: _, ...}) = |
8ec31bdb9d36
adopt the neutral "prover" terminology for MaSh rather than the ambiguous/wrong ATP terminology (which sometimes excludes SMT solvers)
blanchet
parents:
50442
diff
changeset
|
220 |
generate_isar_or_prover_commands ctxt prover (SOME params) |
50411 | 221 |
|
50906 | 222 |
fun generate_mepo_suggestions ctxt (params as {provers = prover :: _, ...}) |
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
223 |
(range, step) thys linearize max_suggs file_name = |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
224 |
let |
55212 | 225 |
val ho_atp = is_ho_atp ctxt prover |
48239
0016290f904c
generate Meng--Paulson facts for evaluation purposes
blanchet
parents:
48235
diff
changeset
|
226 |
val path = file_name |> Path.explode |
50349 | 227 |
val facts = all_facts ctxt |
50485
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50484
diff
changeset
|
228 |
val (new_facts, old_facts) = facts |> List.partition (has_thys thys o snd) |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50624
diff
changeset
|
229 |
val name_tabs = build_name_tables nickname_of_thm facts |
50814 | 230 |
fun do_fact (j, ((_, th), old_facts)) = |
50906 | 231 |
if in_range range j then |
232 |
let |
|
233 |
val name = nickname_of_thm th |
|
234 |
val _ = tracing ("Fact " ^ string_of_int j ^ ": " ^ name) |
|
235 |
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
|
236 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal goal 1 ctxt |
50906 | 237 |
val isar_deps = isar_dependencies_of name_tabs th |
238 |
in |
|
50954 | 239 |
if is_bad_query ctxt ho_atp step j th isar_deps then |
50906 | 240 |
"" |
241 |
else |
|
242 |
let |
|
243 |
val suggs = |
|
244 |
old_facts |
|
51182
962190eab40d
provide two modes for MaSh driver: linearized or real visibility
blanchet
parents:
51177
diff
changeset
|
245 |
|> linearize ? filter_accessible_from th |
54143
18def1c73c79
make sure add: doesn't add duplicates, and works for [no_atp] facts
blanchet
parents:
54118
diff
changeset
|
246 |
|> Sledgehammer_Fact.drop_duplicate_facts |
54095 | 247 |
|> Sledgehammer_MePo.mepo_suggested_facts ctxt params max_suggs NONE hyp_ts concl_t |
50906 | 248 |
|> map (nickname_of_thm o snd) |
249 |
in encode_str name ^ ": " ^ encode_strs suggs ^ "\n" end |
|
250 |
end |
|
251 |
else |
|
252 |
"" |
|
50519 | 253 |
fun accum x (yss as ys :: _) = (x :: ys) :: yss |
254 |
val old_factss = tl (fold accum new_facts [old_facts]) |
|
50814 | 255 |
val lines = Par_List.map do_fact (tag_list 1 (new_facts ~~ rev old_factss)) |
50519 | 256 |
in File.write_list path lines end |
48234 | 257 |
|
50814 | 258 |
fun generate_mesh_suggestions max_suggs mash_file_name mepo_file_name |
259 |
mesh_file_name = |
|
260 |
let |
|
261 |
val mesh_path = Path.explode mesh_file_name |
|
262 |
val _ = File.write mesh_path "" |
|
263 |
fun do_fact (mash_line, mepo_line) = |
|
264 |
let |
|
50829 | 265 |
val (name, mash_suggs) = |
50814 | 266 |
extract_suggestions mash_line |
53140
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
267 |
||> weight_facts_steeply |
50829 | 268 |
val (name', mepo_suggs) = |
50814 | 269 |
extract_suggestions mepo_line |
53140
a1235e90da5f
pour extra features from proximate facts into goal, in exporter
blanchet
parents:
53127
diff
changeset
|
270 |
||> weight_facts_steeply |
50829 | 271 |
val _ = if name = name' then () else error "Input files out of sync." |
50814 | 272 |
val mess = |
273 |
[(mepo_weight, (mepo_suggs, [])), |
|
274 |
(mash_weight, (mash_suggs, []))] |
|
275 |
val mesh_suggs = mesh_facts (op =) max_suggs mess |
|
50829 | 276 |
val mesh_line = encode_str name ^ ": " ^ encode_strs mesh_suggs ^ "\n" |
50814 | 277 |
in File.append mesh_path mesh_line end |
278 |
val mash_lines = Path.explode mash_file_name |> File.read_lines |
|
279 |
val mepo_lines = Path.explode mepo_file_name |> File.read_lines |
|
50907 | 280 |
in |
281 |
if length mash_lines = length mepo_lines then |
|
282 |
List.app do_fact (mash_lines ~~ mepo_lines) |
|
283 |
else |
|
284 |
warning "Skipped: MaSh file missing or out of sync with MePo file." |
|
285 |
end |
|
50814 | 286 |
|
48234 | 287 |
end; |