1 (* Title: HOL/TPTP/mash_eval.ML
2 Author: Jasmin Blanchette, TU Muenchen
5 Evaluate proof suggestions from MaSh (Machine-learning for Sledgehammer).
10 type params = Sledgehammer_Provers.params
12 val evaluate_mash_suggestions :
13 Proof.context -> params -> theory -> string -> unit
16 structure MaSh_Eval : MASH_EVAL =
19 open Sledgehammer_Fact
20 open Sledgehammer_Filter_MaSh
27 val max_facts_slack = 2
30 filter_out is_likely_tautology_or_too_meta
31 #> map (rpair () o Thm.get_name_hint) #> Symtab.make
33 fun evaluate_mash_suggestions ctxt params thy file_name =
35 val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} =
36 Sledgehammer_Isar.default_params ctxt []
37 val prover = hd provers
38 val slack_max_facts = max_facts_slack * the max_facts
39 val path = file_name |> Path.explode
40 val lines = path |> File.read_lines
41 val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt
42 val facts = all_facts_of thy css_table
43 val all_names = all_names (facts |> map snd)
44 val iter_ok = Unsynchronized.ref 0
45 val mash_ok = Unsynchronized.ref 0
46 val mesh_ok = Unsynchronized.ref 0
47 val isar_ok = Unsynchronized.ref 0
48 fun with_index facts s = (find_index (curry (op =) s) facts + 1, s)
49 fun index_string (j, s) = s ^ "@" ^ string_of_int j
50 fun str_of_res label facts {outcome, run_time, used_facts, ...} =
51 let val facts = facts |> map (fn ((name, _), _) => name ()) in
53 (if is_none outcome then
54 "Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^
55 (used_facts |> map (with_index facts o fst)
56 |> sort (int_ord o pairself fst)
58 |> space_implode " ") ^
59 (if length facts < the max_facts then
60 " (of " ^ string_of_int (length facts) ^ ")"
65 (facts |> take (the max_facts) |> tag_list 1
67 |> space_implode " "))
69 fun solve_goal (j, line) =
71 val (name, suggs) = extract_query line
73 case find_first (fn (_, th) => Thm.get_name_hint th = name) facts of
75 | NONE => error ("No fact called \"" ^ name ^ "\"")
76 val goal = goal_of_thm thy th
77 val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
78 val isar_deps = isabelle_dependencies_of all_names th
79 val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS)
80 val isar_facts = suggested_facts isar_deps facts
82 Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params
83 prover slack_max_facts NONE hyp_ts concl_t facts
84 val mash_facts = facts |> suggested_facts suggs
85 val mess = [(iter_facts, []), (mash_facts, [])]
86 val mesh_facts = mesh_facts slack_max_facts mess
87 fun prove ok heading facts =
91 |> Sledgehammer_Fact.maybe_instantiate_inducts ctxt hyp_ts concl_t
92 |> take (the max_facts)
93 val res as {outcome, ...} =
94 run_prover_for_mash ctxt params prover facts goal
95 val _ = if is_none outcome then ok := !ok + 1 else ()
96 in str_of_res heading facts res end
97 val iter_s = prove iter_ok iterN iter_facts
98 val mash_s = prove mash_ok mashN mash_facts
99 val mesh_s = prove mesh_ok meshN mesh_facts
100 val isar_s = prove isar_ok isarN isar_facts
102 ["Goal " ^ string_of_int j ^ ": " ^ name, iter_s, mash_s, mesh_s,
104 |> cat_lines |> tracing
106 fun total_of heading ok n =
107 " " ^ heading ^ ": " ^ string_of_int (!ok) ^ " (" ^
108 Real.fmt (StringCvt.FIX (SOME 1))
109 (100.0 * Real.fromInt (!ok) / Real.fromInt n) ^ "%)"
110 val inst_inducts = Config.get ctxt Sledgehammer_Fact.instantiate_inducts
112 [prover, string_of_int (the max_facts) ^ " facts",
113 "slice" |> not slice ? prefix "dont_", the_default "smart" type_enc,
114 the_default "smart" lam_trans, ATP_Util.string_from_time timeout,
115 "instantiate_inducts" |> not inst_inducts ? prefix "dont_"]
119 tracing ("Options: " ^ commas options);
120 List.app solve_goal (tag_list 1 lines);
121 ["Successes (of " ^ string_of_int n ^ " goals)",
122 total_of iterN iter_ok n,
123 total_of mashN mash_ok n,
124 total_of meshN mesh_ok n,
125 total_of isarN isar_ok n]
126 |> cat_lines |> tracing