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
29 fun evaluate_mash_suggestions ctxt params thy file_name =
31 val {provers, max_facts, slice, type_enc, lam_trans, timeout, ...} =
32 Sledgehammer_Isar.default_params ctxt []
33 val prover_name = hd provers
34 val slack_max_facts = max_facts_slack * the max_facts
35 val path = file_name |> Path.explode
36 val lines = path |> File.read_lines
37 val css_table = Sledgehammer_Fact.clasimpset_rule_table_of ctxt
38 val facts = all_facts_of thy css_table
41 |> filter_out (is_likely_tautology orf is_too_meta)
42 |> map Thm.get_name_hint
43 val iter_ok = Unsynchronized.ref 0
44 val mash_ok = Unsynchronized.ref 0
45 val mesh_ok = Unsynchronized.ref 0
46 val isar_ok = Unsynchronized.ref 0
47 fun with_index facts s = (find_index (curry (op =) s) facts + 1, s)
48 fun index_string (j, s) = s ^ "@" ^ string_of_int j
49 fun str_of_res label facts {outcome, run_time, used_facts, ...} =
50 let val facts = facts |> map (fn ((name, _), _) => name ()) in
52 (if is_none outcome then
53 "Success (" ^ ATP_Util.string_from_time run_time ^ "): " ^
54 (used_facts |> map (with_index facts o fst)
55 |> sort (int_ord o pairself fst)
57 |> space_implode " ") ^
58 (if length facts < the max_facts then
59 " (of " ^ string_of_int (length facts) ^ ")"
64 (facts |> take (the max_facts) |> tag_list 1
66 |> space_implode " "))
68 fun solve_goal (j, line) =
70 val (name, suggs) = extract_query line
72 case find_first (fn (_, th) => Thm.get_name_hint th = name) facts of
74 | NONE => error ("No fact called \"" ^ name ^ "\"")
75 val goal = goal_of_thm thy th
76 val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal 1
77 val isar_deps = isabelle_dependencies_of all_names th
78 val facts = facts |> filter (fn (_, th') => thm_ord (th', th) = LESS)
79 val isar_facts = suggested_facts isar_deps facts
81 Sledgehammer_Filter_Iter.iterative_relevant_facts ctxt params
82 prover_name slack_max_facts NONE hyp_ts concl_t facts
83 val mash_facts = suggested_facts suggs facts
84 val mess = [(iter_facts, SOME (length iter_facts)), (mash_facts, NONE)]
85 val mesh_facts = mesh_facts slack_max_facts mess
86 fun prove ok heading facts =
89 facts |> Sledgehammer_Fact.maybe_instantiate_inducts ctxt hyp_ts concl_t
90 |> take (the max_facts)
91 val res as {outcome, ...} = run_prover ctxt params facts goal
92 val _ = if is_none outcome then ok := !ok + 1 else ()
93 in str_of_res heading facts res end
94 val iter_s = prove iter_ok iterN iter_facts
95 val mash_s = prove mash_ok mashN mash_facts
96 val mesh_s = prove mesh_ok meshN mesh_facts
97 val isar_s = prove isar_ok isarN isar_facts
99 ["Goal " ^ string_of_int j ^ ": " ^ name, iter_s, mash_s, mesh_s,
101 |> cat_lines |> tracing
103 fun total_of heading ok n =
104 " " ^ heading ^ ": " ^ string_of_int (!ok) ^ " (" ^
105 Real.fmt (StringCvt.FIX (SOME 1))
106 (100.0 * Real.fromInt (!ok) / Real.fromInt n) ^ "%)"
107 val inst_inducts = Config.get ctxt Sledgehammer_Fact.instantiate_inducts
109 [prover_name, string_of_int (the max_facts) ^ " facts",
110 "slice" |> not slice ? prefix "dont_", the_default "smart" type_enc,
111 the_default "smart" lam_trans, ATP_Util.string_from_time timeout,
112 "instantiate_inducts" |> not inst_inducts ? prefix "dont_"]
116 tracing ("Options: " ^ commas options);
117 List.app solve_goal (tag_list 1 lines);
118 ["Successes (of " ^ string_of_int n ^ " goals)",
119 total_of iterN iter_ok n,
120 total_of mashN mash_ok n,
121 total_of meshN mesh_ok n,
122 total_of isarN isar_ok n]
123 |> cat_lines |> tracing