38892
|
1 |
(* Title: HOL/Mirabelle/Tools/mirabelle_sledgehammer_filter.ML
|
|
2 |
Author: Jasmin Blanchette, TU Munich
|
|
3 |
*)
|
|
4 |
|
|
5 |
structure Mirabelle_Sledgehammer_Filter : MIRABELLE_ACTION =
|
|
6 |
struct
|
|
7 |
|
|
8 |
structure Prooftab =
|
|
9 |
Table(type key = int * int val ord = prod_ord int_ord int_ord);
|
|
10 |
|
|
11 |
val proof_table = Unsynchronized.ref Prooftab.empty
|
|
12 |
|
38894
|
13 |
val num_successes = Unsynchronized.ref 0
|
|
14 |
val num_failures = Unsynchronized.ref 0
|
|
15 |
val num_found_proofs = Unsynchronized.ref 0
|
|
16 |
val num_lost_proofs = Unsynchronized.ref 0
|
|
17 |
val num_found_facts = Unsynchronized.ref 0
|
|
18 |
val num_lost_facts = Unsynchronized.ref 0
|
|
19 |
|
|
20 |
fun init proof_file _ thy =
|
38892
|
21 |
let
|
|
22 |
fun do_line line =
|
|
23 |
case line |> space_explode ":" of
|
|
24 |
[line_num, col_num, proof] =>
|
|
25 |
SOME (pairself (the o Int.fromString) (line_num, col_num),
|
|
26 |
proof |> space_explode " " |> filter_out (curry (op =) ""))
|
|
27 |
| _ => NONE
|
38894
|
28 |
val proofs = File.read (Path.explode proof_file)
|
38892
|
29 |
val proof_tab =
|
|
30 |
proofs |> space_explode "\n"
|
|
31 |
|> map_filter do_line
|
|
32 |
|> AList.coalesce (op =)
|
|
33 |
|> Prooftab.make
|
|
34 |
in proof_table := proof_tab; thy end
|
|
35 |
|
38894
|
36 |
fun percentage a b = if b = 0 then "N/A" else string_of_int (a * 100 div b)
|
|
37 |
fun percentage_alt a b = percentage a (a + b)
|
|
38 |
|
|
39 |
fun done _ ({log, ...} : Mirabelle.done_args) =
|
|
40 |
if !num_successes + !num_failures > 0 then
|
|
41 |
(log ("Number of overall success: " ^ Int.toString (!num_successes));
|
|
42 |
log ("Number of overall failures: " ^ Int.toString (!num_failures));
|
|
43 |
log ("Overall success rate: " ^
|
|
44 |
percentage_alt (!num_successes) (!num_failures) ^ "%");
|
|
45 |
log ("Number of found proofs: " ^ Int.toString (!num_found_proofs));
|
|
46 |
log ("Number of lost proofs: " ^ Int.toString (!num_lost_proofs));
|
|
47 |
log ("Proof found rate: " ^
|
|
48 |
percentage_alt (!num_found_proofs) (!num_lost_proofs) ^ "%");
|
|
49 |
log ("Number of found facts: " ^ Int.toString (!num_found_facts));
|
|
50 |
log ("Number of lost facts: " ^ Int.toString (!num_lost_facts));
|
|
51 |
log ("Fact found rate: " ^
|
|
52 |
percentage_alt (!num_found_facts) (!num_lost_facts) ^ "%"))
|
|
53 |
else
|
|
54 |
()
|
38892
|
55 |
|
|
56 |
val default_max_relevant = 300
|
|
57 |
|
38894
|
58 |
fun action args _ ({pre, pos, log, ...} : Mirabelle.run_args) =
|
38892
|
59 |
case (Position.line_of pos, Position.column_of pos) of
|
|
60 |
(SOME line_num, SOME col_num) =>
|
|
61 |
(case Prooftab.lookup (!proof_table) (line_num, col_num) of
|
|
62 |
SOME proofs =>
|
|
63 |
let
|
|
64 |
val {context = ctxt, facts, goal} = Proof.goal pre
|
|
65 |
val thy = ProofContext.theory_of ctxt
|
|
66 |
val {relevance_thresholds, full_types, max_relevant, theory_relevant,
|
|
67 |
...} = Sledgehammer_Isar.default_params thy args
|
|
68 |
val subgoal = 1
|
|
69 |
val (_, hyp_ts, concl_t) = Sledgehammer_Util.strip_subgoal goal subgoal
|
|
70 |
val facts =
|
|
71 |
Sledgehammer_Fact_Filter.relevant_facts ctxt full_types
|
|
72 |
relevance_thresholds
|
|
73 |
(the_default default_max_relevant max_relevant)
|
|
74 |
(the_default false theory_relevant)
|
|
75 |
{add = [], del = [], only = false} facts hyp_ts concl_t
|
|
76 |
|> map (fst o fst)
|
38894
|
77 |
val (found_facts, lost_facts) =
|
38892
|
78 |
List.concat proofs |> sort_distinct string_ord
|
|
79 |
|> List.partition (member (op =) facts)
|
|
80 |
val found_proofs = filter (forall (member (op =) facts)) proofs
|
38894
|
81 |
val n = length found_proofs
|
38892
|
82 |
val _ =
|
38894
|
83 |
if n = 0 then
|
|
84 |
(num_failures := !num_failures + 1; log "Failure")
|
|
85 |
else
|
|
86 |
(num_successes := !num_successes + 1;
|
|
87 |
num_found_proofs := !num_found_proofs + n;
|
|
88 |
log ("Success (" ^ Int.toString n ^ " of " ^
|
|
89 |
Int.toString (length proofs) ^ " proofs)"))
|
|
90 |
val _ = num_lost_proofs := !num_lost_proofs + length proofs - n
|
|
91 |
val _ = num_found_facts := !num_found_facts + (length found_facts)
|
|
92 |
val _ = num_lost_facts := !num_lost_facts + (length lost_facts)
|
|
93 |
val _ = if null found_facts then ()
|
|
94 |
else log ("Found facts: " ^ commas found_facts)
|
|
95 |
val _ = if null lost_facts then ()
|
|
96 |
else log ("Lost facts: " ^ commas lost_facts)
|
38892
|
97 |
in () end
|
38894
|
98 |
| NONE => log "No known proof")
|
38892
|
99 |
| _ => ()
|
|
100 |
|
38894
|
101 |
val proof_fileK = "proof_file"
|
|
102 |
|
|
103 |
fun invoke args =
|
|
104 |
let
|
|
105 |
val (pf_args, other_args) =
|
|
106 |
args |> List.partition (curry (op =) proof_fileK o fst)
|
|
107 |
val proof_file = case pf_args of
|
|
108 |
[] => error "No \"proof_file\" specified"
|
|
109 |
| (_, s) :: _ => s
|
|
110 |
in Mirabelle.register (init proof_file, action other_args, done) end
|
38892
|
111 |
|
|
112 |
end;
|
38894
|
113 |
|
|
114 |
(* Workaround to keep the "mirabelle.pl" script happy *)
|
|
115 |
structure Mirabelle_Sledgehammer_filter = Mirabelle_Sledgehammer_Filter;
|