blanchet@49263
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_filter_mash.ML
|
blanchet@49263
|
2 |
Author: Jasmin Blanchette, TU Muenchen
|
blanchet@49263
|
3 |
|
blanchet@49263
|
4 |
Sledgehammer's machine-learning-based relevance filter (MaSh).
|
blanchet@49263
|
5 |
*)
|
blanchet@49263
|
6 |
|
blanchet@49263
|
7 |
signature SLEDGEHAMMER_FILTER_MASH =
|
blanchet@49263
|
8 |
sig
|
blanchet@49266
|
9 |
type status = ATP_Problem_Generate.status
|
blanchet@49266
|
10 |
type stature = ATP_Problem_Generate.stature
|
blanchet@49311
|
11 |
type fact = Sledgehammer_Fact.fact
|
blanchet@49311
|
12 |
type fact_override = Sledgehammer_Fact.fact_override
|
blanchet@49266
|
13 |
type params = Sledgehammer_Provers.params
|
blanchet@49303
|
14 |
type relevance_fudge = Sledgehammer_Provers.relevance_fudge
|
blanchet@49266
|
15 |
type prover_result = Sledgehammer_Provers.prover_result
|
blanchet@49266
|
16 |
|
blanchet@49266
|
17 |
val fact_name_of : string -> string
|
blanchet@49311
|
18 |
val all_non_tautological_facts_of : theory -> fact list
|
blanchet@49266
|
19 |
val theory_ord : theory * theory -> order
|
blanchet@49266
|
20 |
val thm_ord : thm * thm -> order
|
blanchet@49266
|
21 |
val thms_by_thy : ('a * thm) list -> (string * thm list) list
|
blanchet@49266
|
22 |
val has_thy : theory -> thm -> bool
|
blanchet@49311
|
23 |
val parent_facts : (string * thm list) list -> theory -> string list
|
blanchet@49266
|
24 |
val features_of : theory -> status * thm -> string list
|
blanchet@49266
|
25 |
val isabelle_dependencies_of : string list -> thm -> string list
|
blanchet@49266
|
26 |
val goal_of_thm : theory -> thm -> thm
|
blanchet@49311
|
27 |
val run_prover : Proof.context -> params -> fact list -> thm -> prover_result
|
blanchet@49266
|
28 |
val generate_accessibility : theory -> bool -> string -> unit
|
blanchet@49266
|
29 |
val generate_features : theory -> bool -> string -> unit
|
blanchet@49266
|
30 |
val generate_isa_dependencies : theory -> bool -> string -> unit
|
blanchet@49266
|
31 |
val generate_atp_dependencies :
|
blanchet@49266
|
32 |
Proof.context -> params -> theory -> bool -> string -> unit
|
blanchet@49266
|
33 |
|
blanchet@49264
|
34 |
val reset : unit -> unit
|
blanchet@49303
|
35 |
val can_suggest_facts : unit -> bool
|
blanchet@49303
|
36 |
(* ### val suggest_facts : ... *)
|
blanchet@49264
|
37 |
val can_learn_thy : theory -> bool
|
blanchet@49264
|
38 |
val learn_thy : theory -> real -> unit
|
blanchet@49264
|
39 |
val learn_proof : theory -> term -> thm list -> unit
|
blanchet@49303
|
40 |
|
blanchet@49303
|
41 |
val relevant_facts :
|
blanchet@49307
|
42 |
Proof.context -> params -> string -> int -> fact_override -> term list
|
blanchet@49311
|
43 |
-> term -> fact list -> fact list
|
blanchet@49263
|
44 |
end;
|
blanchet@49263
|
45 |
|
blanchet@49263
|
46 |
structure Sledgehammer_Filter_MaSh : SLEDGEHAMMER_FILTER_MASH =
|
blanchet@49263
|
47 |
struct
|
blanchet@49264
|
48 |
|
blanchet@49266
|
49 |
open ATP_Util
|
blanchet@49266
|
50 |
open ATP_Problem_Generate
|
blanchet@49266
|
51 |
open Sledgehammer_Util
|
blanchet@49266
|
52 |
open Sledgehammer_Fact
|
blanchet@49266
|
53 |
open Sledgehammer_Filter_Iter
|
blanchet@49266
|
54 |
open Sledgehammer_Provers
|
blanchet@49266
|
55 |
|
blanchet@49266
|
56 |
|
blanchet@49266
|
57 |
(*** Low-level communication with MaSh ***)
|
blanchet@49266
|
58 |
|
blanchet@49264
|
59 |
fun mash_reset () =
|
blanchet@49264
|
60 |
tracing "MaSh RESET"
|
blanchet@49264
|
61 |
|
blanchet@49264
|
62 |
fun mash_add fact (access, feats, deps) =
|
blanchet@49264
|
63 |
tracing ("MaSh ADD " ^ fact ^ ": " ^ space_implode " " access ^ "; " ^
|
blanchet@49264
|
64 |
space_implode " " feats ^ "; " ^ space_implode " " deps)
|
blanchet@49264
|
65 |
|
blanchet@49264
|
66 |
fun mash_del fact =
|
blanchet@49264
|
67 |
tracing ("MaSh DEL " ^ fact)
|
blanchet@49264
|
68 |
|
blanchet@49264
|
69 |
fun mash_suggest fact (access, feats) =
|
blanchet@49264
|
70 |
tracing ("MaSh SUGGEST " ^ fact ^ ": " ^ space_implode " " access ^ "; " ^
|
blanchet@49264
|
71 |
space_implode " " feats)
|
blanchet@49264
|
72 |
|
blanchet@49266
|
73 |
|
blanchet@49266
|
74 |
(*** Isabelle helpers ***)
|
blanchet@49266
|
75 |
|
blanchet@49266
|
76 |
fun escape_meta_char c =
|
blanchet@49266
|
77 |
if Char.isAlphaNum c orelse c = #"_" orelse c = #"." orelse c = #"(" orelse
|
blanchet@49266
|
78 |
c = #")" orelse c = #"," then
|
blanchet@49266
|
79 |
String.str c
|
blanchet@49266
|
80 |
else
|
blanchet@49266
|
81 |
(* fixed width, in case more digits follow *)
|
blanchet@49266
|
82 |
"\\" ^ stringN_of_int 3 (Char.ord c)
|
blanchet@49266
|
83 |
|
blanchet@49266
|
84 |
val escape_meta = String.translate escape_meta_char
|
blanchet@49266
|
85 |
|
blanchet@49266
|
86 |
val thy_prefix = "y_"
|
blanchet@49266
|
87 |
|
blanchet@49266
|
88 |
val fact_name_of = escape_meta
|
blanchet@49266
|
89 |
val thy_name_of = prefix thy_prefix o escape_meta
|
blanchet@49266
|
90 |
val const_name_of = prefix const_prefix o escape_meta
|
blanchet@49266
|
91 |
val type_name_of = prefix type_const_prefix o escape_meta
|
blanchet@49266
|
92 |
val class_name_of = prefix class_prefix o escape_meta
|
blanchet@49266
|
93 |
|
blanchet@49266
|
94 |
val thy_name_of_thm = theory_of_thm #> Context.theory_name
|
blanchet@49266
|
95 |
|
blanchet@49266
|
96 |
local
|
blanchet@49266
|
97 |
|
blanchet@49266
|
98 |
fun has_bool @{typ bool} = true
|
blanchet@49266
|
99 |
| has_bool (Type (_, Ts)) = exists has_bool Ts
|
blanchet@49266
|
100 |
| has_bool _ = false
|
blanchet@49266
|
101 |
|
blanchet@49266
|
102 |
fun has_fun (Type (@{type_name fun}, _)) = true
|
blanchet@49266
|
103 |
| has_fun (Type (_, Ts)) = exists has_fun Ts
|
blanchet@49266
|
104 |
| has_fun _ = false
|
blanchet@49266
|
105 |
|
blanchet@49266
|
106 |
val is_conn = member (op =)
|
blanchet@49266
|
107 |
[@{const_name Trueprop}, @{const_name HOL.conj}, @{const_name HOL.disj},
|
blanchet@49266
|
108 |
@{const_name HOL.implies}, @{const_name Not},
|
blanchet@49266
|
109 |
@{const_name All}, @{const_name Ex}, @{const_name Ball}, @{const_name Bex},
|
blanchet@49266
|
110 |
@{const_name HOL.eq}]
|
blanchet@49266
|
111 |
|
blanchet@49266
|
112 |
val has_bool_arg_const =
|
blanchet@49266
|
113 |
exists_Const (fn (c, T) =>
|
blanchet@49266
|
114 |
not (is_conn c) andalso exists has_bool (binder_types T))
|
blanchet@49266
|
115 |
|
blanchet@49266
|
116 |
fun higher_inst_const thy (c, T) =
|
blanchet@49266
|
117 |
case binder_types T of
|
blanchet@49266
|
118 |
[] => false
|
blanchet@49266
|
119 |
| Ts => length (binder_types (Sign.the_const_type thy c)) <> length Ts
|
blanchet@49266
|
120 |
|
blanchet@49266
|
121 |
val binders = [@{const_name All}, @{const_name Ex}]
|
blanchet@49266
|
122 |
|
blanchet@49266
|
123 |
in
|
blanchet@49266
|
124 |
|
blanchet@49266
|
125 |
fun is_fo_term thy t =
|
blanchet@49266
|
126 |
let
|
blanchet@49266
|
127 |
val t =
|
blanchet@49266
|
128 |
t |> Envir.beta_eta_contract
|
blanchet@49266
|
129 |
|> transform_elim_prop
|
blanchet@49266
|
130 |
|> Object_Logic.atomize_term thy
|
blanchet@49266
|
131 |
in
|
blanchet@49266
|
132 |
Term.is_first_order binders t andalso
|
blanchet@49266
|
133 |
not (exists_subterm (fn Var (_, T) => has_bool T orelse has_fun T
|
blanchet@49266
|
134 |
| _ => false) t orelse
|
blanchet@49266
|
135 |
has_bool_arg_const t orelse exists_Const (higher_inst_const thy) t)
|
blanchet@49266
|
136 |
end
|
blanchet@49266
|
137 |
|
blanchet@49266
|
138 |
end
|
blanchet@49266
|
139 |
|
blanchet@49266
|
140 |
fun interesting_terms_types_and_classes term_max_depth type_max_depth t =
|
blanchet@49266
|
141 |
let
|
blanchet@49266
|
142 |
val bad_types = [@{type_name prop}, @{type_name bool}, @{type_name fun}]
|
blanchet@49266
|
143 |
val bad_consts = atp_widely_irrelevant_consts
|
blanchet@49266
|
144 |
fun do_add_type (Type (s, Ts)) =
|
blanchet@49266
|
145 |
(not (member (op =) bad_types s) ? insert (op =) (type_name_of s))
|
blanchet@49266
|
146 |
#> fold do_add_type Ts
|
blanchet@49266
|
147 |
| do_add_type (TFree (_, S)) = union (op =) (map class_name_of S)
|
blanchet@49266
|
148 |
| do_add_type (TVar (_, S)) = union (op =) (map class_name_of S)
|
blanchet@49266
|
149 |
fun add_type T = type_max_depth >= 0 ? do_add_type T
|
blanchet@49266
|
150 |
fun mk_app s args =
|
blanchet@49266
|
151 |
if member (op <>) args "" then s ^ "(" ^ space_implode "," args ^ ")"
|
blanchet@49266
|
152 |
else s
|
blanchet@49266
|
153 |
fun patternify ~1 _ = ""
|
blanchet@49266
|
154 |
| patternify depth t =
|
blanchet@49266
|
155 |
case strip_comb t of
|
blanchet@49266
|
156 |
(Const (s, _), args) =>
|
blanchet@49266
|
157 |
mk_app (const_name_of s) (map (patternify (depth - 1)) args)
|
blanchet@49266
|
158 |
| _ => ""
|
blanchet@49266
|
159 |
fun add_term_patterns ~1 _ = I
|
blanchet@49266
|
160 |
| add_term_patterns depth t =
|
blanchet@49266
|
161 |
insert (op =) (patternify depth t)
|
blanchet@49266
|
162 |
#> add_term_patterns (depth - 1) t
|
blanchet@49266
|
163 |
val add_term = add_term_patterns term_max_depth
|
blanchet@49266
|
164 |
fun add_patterns t =
|
blanchet@49266
|
165 |
let val (head, args) = strip_comb t in
|
blanchet@49266
|
166 |
(case head of
|
blanchet@49266
|
167 |
Const (s, T) =>
|
blanchet@49266
|
168 |
not (member (op =) bad_consts s) ? (add_term t #> add_type T)
|
blanchet@49266
|
169 |
| Free (_, T) => add_type T
|
blanchet@49266
|
170 |
| Var (_, T) => add_type T
|
blanchet@49266
|
171 |
| Abs (_, T, body) => add_type T #> add_patterns body
|
blanchet@49266
|
172 |
| _ => I)
|
blanchet@49266
|
173 |
#> fold add_patterns args
|
blanchet@49266
|
174 |
end
|
blanchet@49266
|
175 |
in [] |> add_patterns t |> sort string_ord end
|
blanchet@49266
|
176 |
|
blanchet@49266
|
177 |
fun is_likely_tautology th =
|
blanchet@49266
|
178 |
null (interesting_terms_types_and_classes 0 ~1 (prop_of th)) andalso
|
blanchet@49266
|
179 |
not (Thm.eq_thm_prop (@{thm ext}, th))
|
blanchet@49266
|
180 |
|
blanchet@49266
|
181 |
fun is_too_meta thy th =
|
blanchet@49266
|
182 |
fastype_of (Object_Logic.atomize_term thy (prop_of th)) <> @{typ bool}
|
blanchet@49266
|
183 |
|
blanchet@49266
|
184 |
fun all_non_tautological_facts_of thy =
|
blanchet@49266
|
185 |
all_facts_of thy
|
blanchet@49266
|
186 |
|> filter_out ((is_likely_tautology orf is_too_meta thy) o snd)
|
blanchet@49266
|
187 |
|
blanchet@49266
|
188 |
fun theory_ord p =
|
blanchet@49266
|
189 |
if Theory.eq_thy p then EQUAL
|
blanchet@49266
|
190 |
else if Theory.subthy p then LESS
|
blanchet@49266
|
191 |
else if Theory.subthy (swap p) then GREATER
|
blanchet@49266
|
192 |
else EQUAL
|
blanchet@49266
|
193 |
|
blanchet@49266
|
194 |
val thm_ord = theory_ord o pairself theory_of_thm
|
blanchet@49266
|
195 |
|
blanchet@49266
|
196 |
fun thms_by_thy ths =
|
blanchet@49266
|
197 |
ths |> map (snd #> `thy_name_of_thm)
|
blanchet@49266
|
198 |
|> AList.group (op =)
|
blanchet@49266
|
199 |
|> sort (int_ord o pairself (length o Theory.ancestors_of o theory_of_thm
|
blanchet@49266
|
200 |
o hd o snd))
|
blanchet@49266
|
201 |
|> map (apsnd (sort thm_ord))
|
blanchet@49266
|
202 |
|
blanchet@49266
|
203 |
fun has_thy thy th = (Context.theory_name thy = thy_name_of_thm th)
|
blanchet@49266
|
204 |
|
blanchet@49311
|
205 |
fun add_last_thms thy_ths thy =
|
blanchet@49311
|
206 |
case AList.lookup (op =) thy_ths (Context.theory_name thy) of
|
blanchet@49311
|
207 |
SOME (ths as _ :: _) => insert Thm.eq_thm (List.last ths)
|
blanchet@49311
|
208 |
| _ => add_parent_thms thy_ths thy
|
blanchet@49311
|
209 |
and add_parent_thms thy_ths thy =
|
blanchet@49311
|
210 |
fold (add_last_thms thy_ths) (Theory.parents_of thy)
|
blanchet@49311
|
211 |
|
blanchet@49311
|
212 |
fun parent_facts thy_ths thy =
|
blanchet@49311
|
213 |
add_parent_thms thy_ths thy []
|
blanchet@49266
|
214 |
|> map (fact_name_of o Thm.get_name_hint)
|
blanchet@49266
|
215 |
|
blanchet@49266
|
216 |
fun is_exists (s, _) = (s = @{const_name Ex} orelse s = @{const_name Ex1})
|
blanchet@49266
|
217 |
|
blanchet@49266
|
218 |
val max_depth = 1
|
blanchet@49266
|
219 |
|
blanchet@49266
|
220 |
(* TODO: Generate type classes for types? *)
|
blanchet@49266
|
221 |
fun features_of thy (status, th) =
|
blanchet@49266
|
222 |
let val t = Thm.prop_of th in
|
blanchet@49266
|
223 |
thy_name_of (thy_name_of_thm th) ::
|
blanchet@49266
|
224 |
interesting_terms_types_and_classes max_depth max_depth t
|
blanchet@49266
|
225 |
|> not (has_no_lambdas t) ? cons "lambdas"
|
blanchet@49266
|
226 |
|> exists_Const is_exists t ? cons "skolems"
|
blanchet@49266
|
227 |
|> not (is_fo_term thy t) ? cons "ho"
|
blanchet@49266
|
228 |
|> (case status of
|
blanchet@49266
|
229 |
General => I
|
blanchet@49266
|
230 |
| Induction => cons "induction"
|
blanchet@49266
|
231 |
| Intro => cons "intro"
|
blanchet@49266
|
232 |
| Inductive => cons "inductive"
|
blanchet@49266
|
233 |
| Elim => cons "elim"
|
blanchet@49266
|
234 |
| Simp => cons "simp"
|
blanchet@49266
|
235 |
| Def => cons "def")
|
blanchet@49266
|
236 |
end
|
blanchet@49266
|
237 |
|
blanchet@49266
|
238 |
fun isabelle_dependencies_of all_facts =
|
blanchet@49266
|
239 |
thms_in_proof (SOME all_facts)
|
blanchet@49266
|
240 |
#> map fact_name_of #> sort string_ord
|
blanchet@49266
|
241 |
|
blanchet@49266
|
242 |
val freezeT = Type.legacy_freeze_type
|
blanchet@49266
|
243 |
|
blanchet@49266
|
244 |
fun freeze (t $ u) = freeze t $ freeze u
|
blanchet@49266
|
245 |
| freeze (Abs (s, T, t)) = Abs (s, freezeT T, freeze t)
|
blanchet@49266
|
246 |
| freeze (Var ((s, _), T)) = Free (s, freezeT T)
|
blanchet@49266
|
247 |
| freeze (Const (s, T)) = Const (s, freezeT T)
|
blanchet@49266
|
248 |
| freeze (Free (s, T)) = Free (s, freezeT T)
|
blanchet@49266
|
249 |
| freeze t = t
|
blanchet@49266
|
250 |
|
blanchet@49266
|
251 |
fun goal_of_thm thy = prop_of #> freeze #> cterm_of thy #> Goal.init
|
blanchet@49266
|
252 |
|
blanchet@49266
|
253 |
fun run_prover ctxt (params as {provers, ...}) facts goal =
|
blanchet@49266
|
254 |
let
|
blanchet@49266
|
255 |
val problem =
|
blanchet@49266
|
256 |
{state = Proof.init ctxt, goal = goal, subgoal = 1, subgoal_count = 1,
|
blanchet@49304
|
257 |
facts = facts |> map (apfst (apfst (fn name => name ())))
|
blanchet@49304
|
258 |
|> map Sledgehammer_Provers.Untranslated_Fact}
|
blanchet@49266
|
259 |
val prover =
|
blanchet@49266
|
260 |
Sledgehammer_Minimize.get_minimizing_prover ctxt
|
blanchet@49266
|
261 |
Sledgehammer_Provers.Normal (hd provers)
|
blanchet@49266
|
262 |
in prover params (K (K (K ""))) problem end
|
blanchet@49266
|
263 |
|
blanchet@49266
|
264 |
fun generate_accessibility thy include_thy file_name =
|
blanchet@49266
|
265 |
let
|
blanchet@49266
|
266 |
val path = file_name |> Path.explode
|
blanchet@49266
|
267 |
val _ = File.write path ""
|
blanchet@49266
|
268 |
fun do_thm th prevs =
|
blanchet@49266
|
269 |
let
|
blanchet@49266
|
270 |
val s = th ^ ": " ^ space_implode " " prevs ^ "\n"
|
blanchet@49266
|
271 |
val _ = File.append path s
|
blanchet@49266
|
272 |
in [th] end
|
blanchet@49266
|
273 |
val thy_ths =
|
blanchet@49266
|
274 |
all_non_tautological_facts_of thy
|
blanchet@49266
|
275 |
|> not include_thy ? filter_out (has_thy thy o snd)
|
blanchet@49266
|
276 |
|> thms_by_thy
|
blanchet@49266
|
277 |
fun do_thy ths =
|
blanchet@49266
|
278 |
let
|
blanchet@49266
|
279 |
val thy = theory_of_thm (hd ths)
|
blanchet@49311
|
280 |
val parents = parent_facts thy_ths thy
|
blanchet@49266
|
281 |
val ths = ths |> map (fact_name_of o Thm.get_name_hint)
|
blanchet@49266
|
282 |
in fold do_thm ths parents; () end
|
blanchet@49266
|
283 |
in List.app (do_thy o snd) thy_ths end
|
blanchet@49266
|
284 |
|
blanchet@49266
|
285 |
fun generate_features thy include_thy file_name =
|
blanchet@49266
|
286 |
let
|
blanchet@49266
|
287 |
val path = file_name |> Path.explode
|
blanchet@49266
|
288 |
val _ = File.write path ""
|
blanchet@49266
|
289 |
val facts =
|
blanchet@49266
|
290 |
all_non_tautological_facts_of thy
|
blanchet@49266
|
291 |
|> not include_thy ? filter_out (has_thy thy o snd)
|
blanchet@49266
|
292 |
fun do_fact ((_, (_, status)), th) =
|
blanchet@49266
|
293 |
let
|
blanchet@49266
|
294 |
val name = Thm.get_name_hint th
|
blanchet@49266
|
295 |
val feats = features_of thy (status, th)
|
blanchet@49266
|
296 |
val s = fact_name_of name ^ ": " ^ space_implode " " feats ^ "\n"
|
blanchet@49266
|
297 |
in File.append path s end
|
blanchet@49266
|
298 |
in List.app do_fact facts end
|
blanchet@49266
|
299 |
|
blanchet@49266
|
300 |
fun generate_isa_dependencies thy include_thy file_name =
|
blanchet@49266
|
301 |
let
|
blanchet@49266
|
302 |
val path = file_name |> Path.explode
|
blanchet@49266
|
303 |
val _ = File.write path ""
|
blanchet@49266
|
304 |
val ths =
|
blanchet@49266
|
305 |
all_non_tautological_facts_of thy
|
blanchet@49266
|
306 |
|> not include_thy ? filter_out (has_thy thy o snd)
|
blanchet@49266
|
307 |
|> map snd
|
blanchet@49266
|
308 |
val all_names = ths |> map Thm.get_name_hint
|
blanchet@49266
|
309 |
fun do_thm th =
|
blanchet@49266
|
310 |
let
|
blanchet@49266
|
311 |
val name = Thm.get_name_hint th
|
blanchet@49266
|
312 |
val deps = isabelle_dependencies_of all_names th
|
blanchet@49266
|
313 |
val s = fact_name_of name ^ ": " ^ space_implode " " deps ^ "\n"
|
blanchet@49266
|
314 |
in File.append path s end
|
blanchet@49266
|
315 |
in List.app do_thm ths end
|
blanchet@49266
|
316 |
|
blanchet@49308
|
317 |
fun generate_atp_dependencies ctxt (params as {provers, max_facts, ...}) thy
|
blanchet@49266
|
318 |
include_thy file_name =
|
blanchet@49266
|
319 |
let
|
blanchet@49266
|
320 |
val path = file_name |> Path.explode
|
blanchet@49266
|
321 |
val _ = File.write path ""
|
blanchet@49266
|
322 |
val facts =
|
blanchet@49266
|
323 |
all_non_tautological_facts_of thy
|
blanchet@49266
|
324 |
|> not include_thy ? filter_out (has_thy thy o snd)
|
blanchet@49266
|
325 |
val ths = facts |> map snd
|
blanchet@49266
|
326 |
val all_names = ths |> map Thm.get_name_hint
|
blanchet@49266
|
327 |
fun is_dep dep (_, th) = fact_name_of (Thm.get_name_hint th) = dep
|
blanchet@49266
|
328 |
fun add_isa_dep facts dep accum =
|
blanchet@49266
|
329 |
if exists (is_dep dep) accum then
|
blanchet@49266
|
330 |
accum
|
blanchet@49266
|
331 |
else case find_first (is_dep dep) facts of
|
blanchet@49304
|
332 |
SOME ((name, status), th) => accum @ [((name, status), th)]
|
blanchet@49266
|
333 |
| NONE => accum (* shouldn't happen *)
|
blanchet@49266
|
334 |
fun fix_name ((_, stature), th) =
|
blanchet@49304
|
335 |
((fn () => th |> Thm.get_name_hint |> fact_name_of, stature), th)
|
blanchet@49266
|
336 |
fun do_thm th =
|
blanchet@49266
|
337 |
let
|
blanchet@49266
|
338 |
val name = Thm.get_name_hint th
|
blanchet@49266
|
339 |
val goal = goal_of_thm thy th
|
blanchet@49307
|
340 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
|
blanchet@49266
|
341 |
val deps =
|
blanchet@49266
|
342 |
case isabelle_dependencies_of all_names th of
|
blanchet@49266
|
343 |
[] => []
|
blanchet@49266
|
344 |
| isa_dep as [_] => isa_dep (* can hardly beat that *)
|
blanchet@49266
|
345 |
| isa_deps =>
|
blanchet@49266
|
346 |
let
|
blanchet@49266
|
347 |
val facts =
|
blanchet@49266
|
348 |
facts |> filter (fn (_, th') => thm_ord (th', th) = LESS)
|
blanchet@49266
|
349 |
val facts =
|
blanchet@49307
|
350 |
facts |> iterative_relevant_facts ctxt params (hd provers)
|
blanchet@49308
|
351 |
(the max_facts) NONE hyp_ts concl_t
|
blanchet@49266
|
352 |
|> fold (add_isa_dep facts) isa_deps
|
blanchet@49266
|
353 |
|> map fix_name
|
blanchet@49266
|
354 |
in
|
blanchet@49266
|
355 |
case run_prover ctxt params facts goal of
|
blanchet@49266
|
356 |
{outcome = NONE, used_facts, ...} =>
|
blanchet@49266
|
357 |
used_facts |> map fst |> sort string_ord
|
blanchet@49266
|
358 |
| _ => isa_deps
|
blanchet@49266
|
359 |
end
|
blanchet@49266
|
360 |
val s = fact_name_of name ^ ": " ^ space_implode " " deps ^ "\n"
|
blanchet@49266
|
361 |
in File.append path s end
|
blanchet@49266
|
362 |
in List.app do_thm ths end
|
blanchet@49266
|
363 |
|
blanchet@49266
|
364 |
|
blanchet@49266
|
365 |
(*** High-level communication with MaSh ***)
|
blanchet@49266
|
366 |
|
blanchet@49264
|
367 |
fun reset () =
|
blanchet@49264
|
368 |
()
|
blanchet@49264
|
369 |
|
blanchet@49303
|
370 |
fun can_suggest_facts () =
|
blanchet@49264
|
371 |
true
|
blanchet@49264
|
372 |
|
blanchet@49264
|
373 |
fun can_learn_thy thy =
|
blanchet@49264
|
374 |
true
|
blanchet@49264
|
375 |
|
blanchet@49264
|
376 |
fun learn_thy thy timeout =
|
blanchet@49264
|
377 |
()
|
blanchet@49264
|
378 |
|
blanchet@49307
|
379 |
fun learn_proof thy t ths =
|
blanchet@49264
|
380 |
()
|
blanchet@49264
|
381 |
|
blanchet@49308
|
382 |
fun relevant_facts ctxt params prover max_facts
|
blanchet@49308
|
383 |
({add, only, ...} : fact_override) hyp_ts concl_t facts =
|
blanchet@49303
|
384 |
if only then
|
blanchet@49304
|
385 |
facts
|
blanchet@49308
|
386 |
else if max_facts <= 0 then
|
blanchet@49303
|
387 |
[]
|
blanchet@49303
|
388 |
else
|
blanchet@49303
|
389 |
let
|
blanchet@49303
|
390 |
val add_ths = Attrib.eval_thms ctxt add
|
blanchet@49307
|
391 |
fun prepend_facts ths accepts =
|
blanchet@49303
|
392 |
((facts |> filter (member Thm.eq_thm_prop ths o snd)) @
|
blanchet@49307
|
393 |
(accepts |> filter_out (member Thm.eq_thm_prop ths o snd)))
|
blanchet@49308
|
394 |
|> take max_facts
|
blanchet@49303
|
395 |
in
|
blanchet@49308
|
396 |
facts
|
blanchet@49308
|
397 |
|> iterative_relevant_facts ctxt params prover max_facts NONE hyp_ts
|
blanchet@49308
|
398 |
concl_t
|
blanchet@49303
|
399 |
|> not (null add_ths) ? prepend_facts add_ths
|
blanchet@49303
|
400 |
end
|
blanchet@49303
|
401 |
|
blanchet@49263
|
402 |
end;
|