1 (* Title: HOL/TPTP/mash_export.ML
2 Author: Jasmin Blanchette, TU Muenchen
5 Export Isabelle theory information for MaSh (Machine-learning for Sledgehammer).
8 signature MASH_EXPORT =
10 type params = Sledgehammer_Provers.params
12 val generate_commands : theory -> string -> unit
13 val generate_iter_suggestions :
14 Proof.context -> params -> theory -> int -> string -> unit
17 structure MaSh_Export : MASH_EXPORT =
20 open Sledgehammer_Filter_MaSh
22 fun generate_commands thy file_name =
24 val path = file_name |> Path.explode
25 val _ = File.write path ""
26 val facts = all_non_tautological_facts_of thy
27 val (new_facts, old_facts) =
28 facts |> List.partition (has_thy thy o snd)
29 |>> sort (thm_ord o pairself snd)
30 val ths = facts |> map snd
31 val all_names = ths |> map Thm.get_name_hint
32 fun do_fact ((_, (_, status)), th) prevs =
34 val name = Thm.get_name_hint th
35 val feats = features_of thy (status, th)
36 val deps = isabelle_dependencies_of all_names th
37 val kind = Thm.legacy_get_kind th
38 val name = fact_name_of name
40 name ^ ": " ^ space_implode " " prevs ^ "; " ^ space_implode " " feats
41 val query = if kind <> "" then "? " ^ core ^ "\n" else ""
42 val update = "! " ^ core ^ "; " ^ space_implode " " deps ^ "\n"
43 val _ = File.append path (query ^ update)
45 val thy_ths = old_facts |> thms_by_thy
46 val parents = parent_thms thy_ths thy
47 in fold do_fact new_facts parents; () end
49 fun generate_iter_suggestions ctxt (params as {provers, ...}) thy max_relevant
52 val path = file_name |> Path.explode
53 val _ = File.write path ""
54 val facts = all_non_tautological_facts_of thy
55 val (new_facts, old_facts) =
56 facts |> List.partition (has_thy thy o snd)
57 |>> sort (thm_ord o pairself snd)
58 fun do_fact (fact as (_, th)) old_facts =
60 val name = Thm.get_name_hint th
61 val goal = goal_of_thm thy th
62 val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
63 val kind = Thm.legacy_get_kind th
69 |> Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params
70 (hd provers) max_relevant NONE hyp_ts concl_t
71 |> map (fn ((name, _), _) => fact_name_of (name ()))
73 val s = fact_name_of name ^ ": " ^ space_implode " " suggs ^ "\n"
74 in File.append path s end
77 in fact :: old_facts end
78 in fold do_fact new_facts old_facts; () end