make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
"max_relevant" is more reliable than "max_relevant_per_iter";
also made sure that the option is monotone -- larger values should lead to more axioms -- which wasn't always the case before;
SOS for Vampire makes a difference of about 3% (i.e. 3% more proofs are found)
1 (* Title: HOL/Tools/Sledgehammer/sledgehammer_fact_minimize.ML
2 Author: Philipp Meyer, TU Muenchen
3 Author: Jasmin Blanchette, TU Muenchen
5 Minimization of theorem list for Metis using automatic theorem provers.
8 signature SLEDGEHAMMER_FACT_MINIMIZE =
10 type params = Sledgehammer.params
12 val minimize_theorems :
13 params -> int -> int -> Proof.state -> ((string * bool) * thm list) list
14 -> ((string * bool) * thm list) list option * string
15 val run_minimize : params -> int -> Facts.ref list -> Proof.state -> unit
18 structure Sledgehammer_Fact_Minimize : SLEDGEHAMMER_FACT_MINIMIZE =
22 open Sledgehammer_Util
23 open Sledgehammer_Fact_Filter
24 open Sledgehammer_Proof_Reconstruct
27 (* wrapper for calling external prover *)
29 fun string_for_failure Unprovable = "Unprovable."
30 | string_for_failure TimedOut = "Timed out."
31 | string_for_failure _ = "Unknown error."
33 fun n_theorems names =
34 let val n = length names in
35 string_of_int n ^ " theorem" ^ plural_s n ^
37 ": " ^ (names |> map fst
38 |> sort_distinct string_ord |> space_implode " ")
43 fun test_theorems ({debug, verbose, overlord, atps, full_types, isar_proof,
44 isar_shrink_factor, ...} : params)
45 (prover : prover) explicit_apply timeout subgoal state
49 priority ("Testing " ^ n_theorems (map fst axioms) ^ "...")
51 {debug = debug, verbose = verbose, overlord = overlord, atps = atps,
52 full_types = full_types, explicit_apply = explicit_apply,
53 relevance_threshold = 1.1, relevance_decay = NONE, max_relevant = NONE,
54 theory_relevant = NONE, isar_proof = isar_proof,
55 isar_shrink_factor = isar_shrink_factor, timeout = timeout}
56 val axioms = maps (fn (n, ths) => map (pair n) ths) axioms
57 val {context = ctxt, facts, goal} = Proof.goal state
59 {subgoal = subgoal, goal = (ctxt, (facts, goal)),
60 relevance_override = {add = [], del = [], only = false},
62 val result as {outcome, used_thm_names, ...} = prover params (K "") problem
64 priority (case outcome of
66 if length used_thm_names = length axioms then
69 "Found proof with " ^ n_theorems used_thm_names ^ "."
70 | SOME failure => string_for_failure failure);
74 (* minimalization of thms *)
76 fun filter_used_facts used = filter (member (op =) used o fst)
78 fun sublinear_minimize _ [] p = p
79 | sublinear_minimize test (x :: xs) (seen, result) =
80 case test (xs @ seen) of
81 result as {outcome = NONE, proof, used_thm_names, ...} : prover_result =>
82 sublinear_minimize test (filter_used_facts used_thm_names xs)
83 (filter_used_facts used_thm_names seen, result)
84 | _ => sublinear_minimize test xs (x :: seen, result)
86 (* Give the ATP some slack. The ATP gets further slack because the Sledgehammer
87 preprocessing time is included in the estimate below but isn't part of the
89 val fudge_msecs = 1000
91 fun minimize_theorems {atps = [], ...} _ _ _ _ = error "No ATP is set."
92 | minimize_theorems (params as {debug, atps = atp :: _, full_types,
93 isar_proof, isar_shrink_factor, timeout, ...})
96 val thy = Proof.theory_of state
97 val prover = get_prover_fun thy atp
98 val msecs = Time.toMilliseconds timeout
99 val _ = priority ("Sledgehammer minimize: ATP " ^ quote atp ^ ".")
100 val {context = ctxt, goal, ...} = Proof.goal state
101 val (_, hyp_ts, concl_t) = strip_subgoal goal i
103 not (forall (Meson.is_fol_term thy)
104 (concl_t :: hyp_ts @ maps (map prop_of o snd) axioms))
105 fun do_test timeout =
106 test_theorems params prover explicit_apply timeout i state
107 val timer = Timer.startRealTimer ()
109 (case do_test timeout axioms of
110 result as {outcome = NONE, pool, used_thm_names,
111 conjecture_shape, ...} =>
113 val time = Timer.checkRealTimer timer
115 Int.min (msecs, Time.toMilliseconds time + fudge_msecs)
116 |> Time.fromMilliseconds
117 val (min_thms, {proof, axiom_names, ...}) =
118 sublinear_minimize (do_test new_timeout)
119 (filter_used_facts used_thm_names axioms) ([], result)
120 val n = length min_thms
121 val _ = priority (cat_lines
122 ["Minimized: " ^ string_of_int n ^ " theorem" ^ plural_s n] ^
123 (case length (filter (snd o fst) min_thms) of
125 | n => " (including " ^ Int.toString n ^ " chained)") ^ ".")
128 proof_text isar_proof
129 (pool, debug, isar_shrink_factor, ctxt, conjecture_shape)
130 (full_types, K "", proof, axiom_names, goal, i) |> fst)
132 | {outcome = SOME TimedOut, ...} =>
133 (NONE, "Timeout: You can increase the time limit using the \"timeout\" \
134 \option (e.g., \"timeout = " ^
135 string_of_int (10 + msecs div 1000) ^ " s\").")
136 | {outcome = SOME UnknownError, ...} =>
137 (* Failure sometimes mean timeout, unfortunately. *)
138 (NONE, "Failure: No proof was found with the current time limit. You \
139 \can increase the time limit using the \"timeout\" \
140 \option (e.g., \"timeout = " ^
141 string_of_int (10 + msecs div 1000) ^ " s\").")
142 | {message, ...} => (NONE, "ATP error: " ^ message))
143 handle ERROR msg => (NONE, "Error: " ^ msg)
146 fun run_minimize params i refs state =
148 val ctxt = Proof.context_of state
149 val reserved = reserved_isar_keyword_table ()
150 val chained_ths = #facts (Proof.goal state)
152 maps (map (fn (name, (_, th)) => (name (), [th]))
153 o name_thm_pairs_from_ref ctxt reserved chained_ths) refs
155 case subgoal_count state of
156 0 => priority "No subgoal!"
158 (kill_atps (); priority (#2 (minimize_theorems params i n state axioms)))