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 |
|
|
13 |
fun init id thy =
|
|
14 |
let
|
|
15 |
fun do_line line =
|
|
16 |
case line |> space_explode ":" of
|
|
17 |
[line_num, col_num, proof] =>
|
|
18 |
SOME (pairself (the o Int.fromString) (line_num, col_num),
|
|
19 |
proof |> space_explode " " |> filter_out (curry (op =) ""))
|
|
20 |
| _ => NONE
|
|
21 |
val proofs = File.read (Path.explode "$HOME/Judgement/AllProofs/NS_Shared.txt")
|
|
22 |
val proof_tab =
|
|
23 |
proofs |> space_explode "\n"
|
|
24 |
|> map_filter do_line
|
|
25 |
|> AList.coalesce (op =)
|
|
26 |
|> Prooftab.make
|
|
27 |
in proof_table := proof_tab; thy end
|
|
28 |
|
|
29 |
fun done id (args : Mirabelle.done_args) = ()
|
|
30 |
|
|
31 |
val default_max_relevant = 300
|
|
32 |
|
|
33 |
fun action args id ({pre, pos, ...} : Mirabelle.run_args) =
|
|
34 |
case (Position.line_of pos, Position.column_of pos) of
|
|
35 |
(SOME line_num, SOME col_num) =>
|
|
36 |
(case Prooftab.lookup (!proof_table) (line_num, col_num) of
|
|
37 |
SOME proofs =>
|
|
38 |
let
|
|
39 |
val {context = ctxt, facts, goal} = Proof.goal pre
|
|
40 |
val thy = ProofContext.theory_of ctxt
|
|
41 |
val {relevance_thresholds, full_types, max_relevant, theory_relevant,
|
|
42 |
...} = Sledgehammer_Isar.default_params thy args
|
|
43 |
val subgoal = 1
|
|
44 |
val (_, hyp_ts, concl_t) = Sledgehammer_Util.strip_subgoal goal subgoal
|
|
45 |
val facts =
|
|
46 |
Sledgehammer_Fact_Filter.relevant_facts ctxt full_types
|
|
47 |
relevance_thresholds
|
|
48 |
(the_default default_max_relevant max_relevant)
|
|
49 |
(the_default false theory_relevant)
|
|
50 |
{add = [], del = [], only = false} facts hyp_ts concl_t
|
|
51 |
|> map (fst o fst)
|
|
52 |
val (found_facts, missing_facts) =
|
|
53 |
List.concat proofs |> sort_distinct string_ord
|
|
54 |
|> List.partition (member (op =) facts)
|
|
55 |
val found_proofs = filter (forall (member (op =) facts)) proofs
|
|
56 |
val _ =
|
|
57 |
case length found_proofs of
|
|
58 |
0 => writeln "Failure"
|
|
59 |
| n => writeln ("Success (" ^ Int.toString n ^ " of " ^
|
|
60 |
Int.toString (length proofs) ^ " proofs)")
|
|
61 |
val _ = writeln ("Found facts: " ^ commas found_facts)
|
|
62 |
val _ = writeln ("Missing facts: " ^ commas missing_facts)
|
|
63 |
in () end
|
|
64 |
| NONE => ())
|
|
65 |
| _ => ()
|
|
66 |
|
|
67 |
fun invoke args = Mirabelle.register (init, action args, done)
|
|
68 |
|
|
69 |
end;
|