author | blanchet |
Fri, 16 May 2014 19:14:00 +0200 | |
changeset 56985 | 82c83978fbd9 |
parent 56081 | 72fad75baf7e |
child 57054 | fed0329ea8e2 |
permissions | -rw-r--r-- |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_prover_minimize.ML |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
diff
changeset
|
2 |
Author: Philipp Meyer, TU Muenchen |
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
diff
changeset
|
4 |
|
40977 | 5 |
Minimization of fact list for Metis using external provers. |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
diff
changeset
|
6 |
*) |
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
diff
changeset
|
7 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
8 |
signature SLEDGEHAMMER_PROVER_MINIMIZE = |
32525 | 9 |
sig |
46340 | 10 |
type stature = ATP_Problem_Generate.stature |
55287 | 11 |
type proof_method = Sledgehammer_Proof_Methods.proof_method |
12 |
type play_outcome = Sledgehammer_Proof_Methods.play_outcome |
|
55201 | 13 |
type mode = Sledgehammer_Prover.mode |
14 |
type params = Sledgehammer_Prover.params |
|
15 |
type prover = Sledgehammer_Prover.prover |
|
35867 | 16 |
|
55205 | 17 |
val is_prover_supported : Proof.context -> string -> bool |
18 |
val is_prover_installed : Proof.context -> string -> bool |
|
19 |
val default_max_facts_of_prover : Proof.context -> string -> int |
|
20 |
val get_prover : Proof.context -> mode -> string -> prover |
|
21 |
||
42646
4781fcd53572
replaced some Unsynchronized.refs with Config.Ts
blanchet
parents:
42579
diff
changeset
|
22 |
val binary_min_facts : int Config.T |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
23 |
val auto_minimize_min_facts : int Config.T |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
24 |
val auto_minimize_max_time : real Config.T |
54824 | 25 |
val minimize_facts : (thm list -> unit) -> string -> params -> bool -> int -> int -> |
55285 | 26 |
Proof.state -> thm -> (proof_method * play_outcome) Lazy.lazy option -> |
54824 | 27 |
((string * stature) * thm list) list -> |
28 |
((string * stature) * thm list) list option |
|
55285 | 29 |
* ((proof_method * play_outcome) Lazy.lazy * ((proof_method * play_outcome) -> string) |
30 |
* string) |
|
54503 | 31 |
val get_minimizing_prover : Proof.context -> mode -> (thm list -> unit) -> string -> prover |
55205 | 32 |
|
54503 | 33 |
val run_minimize : params -> (thm list -> unit) -> int -> (Facts.ref * Attrib.src list) list -> |
34 |
Proof.state -> unit |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
35865
diff
changeset
|
35 |
end; |
32525 | 36 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
37 |
structure Sledgehammer_Prover_Minimize : SLEDGEHAMMER_PROVER_MINIMIZE = |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
diff
changeset
|
38 |
struct |
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
diff
changeset
|
39 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43064
diff
changeset
|
40 |
open ATP_Util |
39496
a52a4e4399c1
got caught once again by SML's pattern maching (ctor vs. var)
blanchet
parents:
39491
diff
changeset
|
41 |
open ATP_Proof |
46320 | 42 |
open ATP_Problem_Generate |
55212 | 43 |
open ATP_Proof_Reconstruct |
51200
260cb10aac4b
minimize SMT proofs with E if Isar proofs are desired and Metis managed to preplay
blanchet
parents:
51191
diff
changeset
|
44 |
open ATP_Systems |
36142
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36063
diff
changeset
|
45 |
open Sledgehammer_Util |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
46 |
open Sledgehammer_Fact |
55287 | 47 |
open Sledgehammer_Proof_Methods |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
48 |
open Sledgehammer_Isar |
55201 | 49 |
open Sledgehammer_Prover |
55205 | 50 |
open Sledgehammer_Prover_ATP |
51 |
open Sledgehammer_Prover_SMT |
|
56081 | 52 |
open Sledgehammer_Prover_SMT2 |
55205 | 53 |
|
55452
29ec8680e61f
avoid changing the state's context -- this results in transfer problems later with SMT, and hence preplay tactic failures
blanchet
parents:
55308
diff
changeset
|
54 |
fun run_proof_method mode name (params as {debug, verbose, timeout, type_enc, lam_trans, ...}) |
55212 | 55 |
minimize_command |
56 |
({state, subgoal, subgoal_count, factss = (_, facts) :: _, ...} : prover_problem) = |
|
57 |
let |
|
55285 | 58 |
val meth = |
59 |
if name = metisN then Metis_Method (type_enc, lam_trans) |
|
56081 | 60 |
else if name = smtN then SMT2_Method |
55285 | 61 |
else raise Fail ("unknown proof_method: " ^ quote name) |
55212 | 62 |
val used_facts = facts |> map fst |
63 |
in |
|
56985
82c83978fbd9
correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents:
56081
diff
changeset
|
64 |
(case play_one_line_proof (if mode = Minimize then Normal else mode) debug verbose timeout |
82c83978fbd9
correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents:
56081
diff
changeset
|
65 |
facts state subgoal meth [meth] of |
55212 | 66 |
play as (_, Played time) => |
67 |
{outcome = NONE, used_facts = used_facts, used_from = facts, run_time = time, |
|
68 |
preplay = Lazy.value play, |
|
69 |
message = |
|
70 |
fn play => |
|
71 |
let |
|
56985
82c83978fbd9
correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents:
56081
diff
changeset
|
72 |
val ctxt = Proof.context_of state |
55285 | 73 |
val (_, override_params) = extract_proof_method params meth |
55212 | 74 |
val one_line_params = |
75 |
(play, proof_banner mode name, used_facts, minimize_command override_params name, |
|
76 |
subgoal, subgoal_count) |
|
77 |
val num_chained = length (#facts (Proof.goal state)) |
|
78 |
in |
|
56985
82c83978fbd9
correctly add extra facts to lemmas (cf. conjecture and hypotheses) in Z3 Isar proofs
blanchet
parents:
56081
diff
changeset
|
79 |
one_line_proof_text ctxt num_chained one_line_params |
55212 | 80 |
end, |
81 |
message_tail = ""} |
|
82 |
| play => |
|
83 |
let |
|
84 |
val failure = (case play of (_, Play_Failed) => GaveUp | _ => TimedOut) |
|
85 |
in |
|
86 |
{outcome = SOME failure, used_facts = [], used_from = [], |
|
87 |
run_time = Time.zeroTime, preplay = Lazy.value play, |
|
88 |
message = fn _ => string_of_atp_failure failure, message_tail = ""} |
|
89 |
end) |
|
90 |
end |
|
91 |
||
55205 | 92 |
fun is_prover_supported ctxt = |
93 |
let val thy = Proof_Context.theory_of ctxt in |
|
56081 | 94 |
is_proof_method orf is_atp thy orf is_smt_prover ctxt orf is_smt2_prover ctxt |
55205 | 95 |
end |
96 |
||
97 |
fun is_prover_installed ctxt = |
|
56081 | 98 |
is_proof_method orf is_smt_prover ctxt orf is_smt2_prover ctxt orf |
99 |
is_atp_installed (Proof_Context.theory_of ctxt) |
|
55205 | 100 |
|
55285 | 101 |
val proof_method_default_max_facts = 20 |
55205 | 102 |
|
103 |
fun default_max_facts_of_prover ctxt name = |
|
104 |
let val thy = Proof_Context.theory_of ctxt in |
|
55285 | 105 |
if is_proof_method name then |
106 |
proof_method_default_max_facts |
|
55205 | 107 |
else if is_atp thy name then |
108 |
fold (Integer.max o fst o #1 o fst o snd) (#best_slices (get_atp thy name ()) ctxt) 0 |
|
56081 | 109 |
else if is_smt_prover ctxt name then |
55205 | 110 |
SMT_Solver.default_max_relevant ctxt name |
56081 | 111 |
else if is_smt2_prover ctxt name then |
112 |
SMT2_Solver.default_max_relevant ctxt name |
|
113 |
else |
|
114 |
error ("No such prover: " ^ name ^ ".") |
|
55205 | 115 |
end |
116 |
||
117 |
fun get_prover ctxt mode name = |
|
118 |
let val thy = Proof_Context.theory_of ctxt in |
|
55285 | 119 |
if is_proof_method name then run_proof_method mode name |
55205 | 120 |
else if is_atp thy name then run_atp mode name |
121 |
else if is_smt_prover ctxt name then run_smt_solver mode name |
|
56081 | 122 |
else if is_smt2_prover ctxt name then run_smt2_solver mode name |
55205 | 123 |
else error ("No such prover: " ^ name ^ ".") |
124 |
end |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
35865
diff
changeset
|
125 |
|
36370
a4f601daa175
centralized ATP-specific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset
|
126 |
(* wrapper for calling external prover *) |
31236 | 127 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
128 |
fun n_facts names = |
38698
d19c3a7ce38b
clean handling of whether a fact is chained or not;
blanchet
parents:
38696
diff
changeset
|
129 |
let val n = length names in |
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
130 |
string_of_int n ^ " fact" ^ plural_s n ^ |
38092
81a003f7de0d
speed up the minimizer by using the time taken for the first iteration as a timeout for the following iterations, and fix a subtle bug in "string_for_failure"
blanchet
parents:
38084
diff
changeset
|
131 |
(if n > 0 then |
48085
ff5e900d7b1a
avoid dumping definitions several times in LEO-II proofs
blanchet
parents:
47531
diff
changeset
|
132 |
": " ^ (names |> map fst |> sort string_ord |> space_implode " ") |
38092
81a003f7de0d
speed up the minimizer by using the time taken for the first iteration as a timeout for the following iterations, and fix a subtle bug in "string_for_failure"
blanchet
parents:
38084
diff
changeset
|
133 |
else |
81a003f7de0d
speed up the minimizer by using the time taken for the first iteration as a timeout for the following iterations, and fix a subtle bug in "string_for_failure"
blanchet
parents:
38084
diff
changeset
|
134 |
"") |
81a003f7de0d
speed up the minimizer by using the time taken for the first iteration as a timeout for the following iterations, and fix a subtle bug in "string_for_failure"
blanchet
parents:
38084
diff
changeset
|
135 |
end |
81a003f7de0d
speed up the minimizer by using the time taken for the first iteration as a timeout for the following iterations, and fix a subtle bug in "string_for_failure"
blanchet
parents:
38084
diff
changeset
|
136 |
|
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
137 |
fun print silent f = if silent then () else Output.urgent_message (f ()) |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
138 |
|
54824 | 139 |
fun test_facts ({debug, verbose, overlord, spy, provers, max_mono_iters, max_new_mono_instances, |
55297
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
140 |
type_enc, strict, lam_trans, uncurried_aliases, isar_proofs, compress_isar, try0_isar, |
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
141 |
smt_proofs, preplay_timeout, ...} : params) |
54824 | 142 |
silent (prover : prover) timeout i n state goal facts = |
31236 | 143 |
let |
41277
1369c27c6966
reduce the minimizer slack and add verbose information
blanchet
parents:
41267
diff
changeset
|
144 |
val _ = |
1369c27c6966
reduce the minimizer slack and add verbose information
blanchet
parents:
41267
diff
changeset
|
145 |
print silent (fn () => |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
146 |
"Testing " ^ n_facts (map fst facts) ^ |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
147 |
(if verbose then " (timeout: " ^ string_of_time timeout ^ ")" else "") ^ "...") |
51005
ce4290c33d73
eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents:
50669
diff
changeset
|
148 |
val facts = facts |> maps (fn (n, ths) => map (pair n) ths) |
38100
e458a0dd3dc1
use "explicit_apply" in the minimizer whenever it might make a difference to prevent freak failures;
blanchet
parents:
38094
diff
changeset
|
149 |
val params = |
53800 | 150 |
{debug = debug, verbose = verbose, overlord = overlord, spy = spy, blocking = true, |
151 |
provers = provers, type_enc = type_enc, strict = strict, lam_trans = lam_trans, |
|
152 |
uncurried_aliases = uncurried_aliases, learn = false, fact_filter = NONE, |
|
153 |
max_facts = SOME (length facts), fact_thresholds = (1.01, 1.01), |
|
154 |
max_mono_iters = max_mono_iters, max_new_mono_instances = max_new_mono_instances, |
|
55297
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
155 |
isar_proofs = isar_proofs, compress_isar = compress_isar, try0_isar = try0_isar, |
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
156 |
smt_proofs = smt_proofs, slice = false, minimize = SOME false, timeout = timeout, |
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
157 |
preplay_timeout = preplay_timeout, expect = ""} |
40065 | 158 |
val problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54130
diff
changeset
|
159 |
{comment = "", state = state, goal = goal, subgoal = i, subgoal_count = n, |
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54130
diff
changeset
|
160 |
factss = [("", facts)]} |
45370
bab52dafa63a
use "Time.time" rather than milliseconds internally
blanchet
parents:
45369
diff
changeset
|
161 |
val result as {outcome, used_facts, run_time, ...} = |
45520 | 162 |
prover params (K (K (K ""))) problem |
36223
217ca1273786
make Sledgehammer's minimizer also minimize Isar proofs
blanchet
parents:
36143
diff
changeset
|
163 |
in |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
164 |
print silent (fn () => |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
165 |
(case outcome of |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
166 |
SOME failure => string_of_atp_failure failure |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
167 |
| NONE => |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
168 |
"Found proof" ^ |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
169 |
(if length used_facts = length facts then "" else " with " ^ n_facts used_facts) ^ |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
170 |
" (" ^ string_of_time run_time ^ ").")); |
38092
81a003f7de0d
speed up the minimizer by using the time taken for the first iteration as a timeout for the following iterations, and fix a subtle bug in "string_for_failure"
blanchet
parents:
38084
diff
changeset
|
171 |
result |
36223
217ca1273786
make Sledgehammer's minimizer also minimize Isar proofs
blanchet
parents:
36143
diff
changeset
|
172 |
end |
31236 | 173 |
|
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40200
diff
changeset
|
174 |
(* minimalization of facts *) |
31236 | 175 |
|
45372 | 176 |
(* Give the external prover some slack. The ATP gets further slack because the |
177 |
Sledgehammer preprocessing time is included in the estimate below but isn't |
|
178 |
part of the timeout. *) |
|
179 |
val slack_msecs = 200 |
|
180 |
||
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
181 |
fun new_timeout timeout run_time = |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
182 |
Int.min (Time.toMilliseconds timeout, Time.toMilliseconds run_time + slack_msecs) |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
183 |
|> Time.fromMilliseconds |
45372 | 184 |
|
45367 | 185 |
(* The linear algorithm usually outperforms the binary algorithm when over 60% |
186 |
of the facts are actually needed. The binary algorithm is much more |
|
187 |
appropriate for provers that cannot return the list of used facts and hence |
|
188 |
returns all facts as used. Since we cannot know in advance how many facts are |
|
189 |
actually needed, we heuristically set the threshold to 10 facts. *) |
|
42646
4781fcd53572
replaced some Unsynchronized.refs with Config.Ts
blanchet
parents:
42579
diff
changeset
|
190 |
val binary_min_facts = |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
191 |
Attrib.setup_config_int @{binding sledgehammer_minimize_binary_min_facts} (K 20) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
192 |
val auto_minimize_min_facts = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
193 |
Attrib.setup_config_int @{binding sledgehammer_auto_minimize_min_facts} |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
194 |
(fn generic => Config.get_generic generic binary_min_facts) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
195 |
val auto_minimize_max_time = |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
196 |
Attrib.setup_config_real @{binding sledgehammer_auto_minimize_max_time} (K 5.0) |
40977 | 197 |
|
45368 | 198 |
fun linear_minimize test timeout result xs = |
199 |
let |
|
200 |
fun min _ [] p = p |
|
201 |
| min timeout (x :: xs) (seen, result) = |
|
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
202 |
(case test timeout (xs @ seen) of |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
203 |
result as {outcome = NONE, used_facts, run_time, ...} : prover_result => |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
204 |
min (new_timeout timeout run_time) (filter_used_facts true used_facts xs) |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
205 |
(filter_used_facts false used_facts seen, result) |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
206 |
| _ => min timeout xs (x :: seen, result)) |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
207 |
in |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
208 |
min timeout xs ([], result) |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
209 |
end |
38015 | 210 |
|
45368 | 211 |
fun binary_minimize test timeout result xs = |
40977 | 212 |
let |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
213 |
fun min depth (result as {run_time, ...} : prover_result) sup (xs as _ :: _ :: _) = |
41743 | 214 |
let |
45367 | 215 |
val (l0, r0) = chop (length xs div 2) xs |
41743 | 216 |
(* |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
217 |
val _ = warning (replicate_string depth " " ^ "{ " ^ "sup: " ^ n_facts (map fst sup)) |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
218 |
val _ = warning (replicate_string depth " " ^ " " ^ "xs: " ^ n_facts (map fst xs)) |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
219 |
val _ = warning (replicate_string depth " " ^ " " ^ "l0: " ^ n_facts (map fst l0)) |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
220 |
val _ = warning (replicate_string depth " " ^ " " ^ "r0: " ^ n_facts (map fst r0)) |
41743 | 221 |
*) |
45367 | 222 |
val depth = depth + 1 |
45372 | 223 |
val timeout = new_timeout timeout run_time |
41743 | 224 |
in |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
225 |
(case test timeout (sup @ l0) of |
45372 | 226 |
result as {outcome = NONE, used_facts, ...} => |
48798 | 227 |
min depth result (filter_used_facts true used_facts sup) |
228 |
(filter_used_facts true used_facts l0) |
|
45367 | 229 |
| _ => |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
230 |
(case test timeout (sup @ r0) of |
45367 | 231 |
result as {outcome = NONE, used_facts, ...} => |
48798 | 232 |
min depth result (filter_used_facts true used_facts sup) |
233 |
(filter_used_facts true used_facts r0) |
|
45367 | 234 |
| _ => |
235 |
let |
|
236 |
val (sup_r0, (l, result)) = min depth result (sup @ r0) l0 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
237 |
val (sup, r0) = (sup, r0) |> pairself (filter_used_facts true (map fst sup_r0)) |
45367 | 238 |
val (sup_l, (r, result)) = min depth result (sup @ l) r0 |
48798 | 239 |
val sup = sup |> filter_used_facts true (map fst sup_l) |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
240 |
in (sup, (l @ r, result)) end)) |
40977 | 241 |
end |
41743 | 242 |
(* |
243 |
|> tap (fn _ => warning (replicate_string depth " " ^ "}")) |
|
244 |
*) |
|
45367 | 245 |
| min _ result sup xs = (sup, (xs, result)) |
246 |
in |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
247 |
(case snd (min 0 result [] xs) of |
45372 | 248 |
([x], result as {run_time, ...}) => |
249 |
(case test (new_timeout timeout run_time) [] of |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
250 |
result as {outcome = NONE, ...} => ([], result) |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
251 |
| _ => ([x], result)) |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
252 |
| p => p) |
45367 | 253 |
end |
40977 | 254 |
|
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
255 |
fun minimize_facts do_learn prover_name (params as {learn, timeout, ...}) silent i n state goal |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
256 |
preplay0 facts = |
31236 | 257 |
let |
40941
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40553
diff
changeset
|
258 |
val ctxt = Proof.context_of state |
54815 | 259 |
val prover = get_prover ctxt (if silent then Auto_Minimize else Minimize) prover_name |
54130
b4e6cd4cab92
thread the goal through instead of relying on unreliable (possibly fake) state
blanchet
parents:
54127
diff
changeset
|
260 |
fun test timeout = test_facts params silent prover timeout i n state goal |
48796
0f94b8b69e79
consider removing chained facts last, so that they're more likely to be kept
blanchet
parents:
48399
diff
changeset
|
261 |
val (chained, non_chained) = List.partition is_fact_chained facts |
48799 | 262 |
(* Push chained facts to the back, so that they are less likely to be |
263 |
kicked out by the linear minimization algorithm. *) |
|
48796
0f94b8b69e79
consider removing chained facts last, so that they're more likely to be kept
blanchet
parents:
48399
diff
changeset
|
264 |
val facts = non_chained @ chained |
31236 | 265 |
in |
54815 | 266 |
(print silent (fn () => "Sledgehammer minimizer: " ^ quote prover_name ^ "."); |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
267 |
(case test timeout facts of |
45371 | 268 |
result as {outcome = NONE, used_facts, run_time, ...} => |
38015 | 269 |
let |
48798 | 270 |
val facts = filter_used_facts true used_facts facts |
45372 | 271 |
val min = |
54815 | 272 |
if length facts >= Config.get ctxt binary_min_facts then binary_minimize |
273 |
else linear_minimize |
|
45368 | 274 |
val (min_facts, {preplay, message, message_tail, ...}) = |
45371 | 275 |
min test (new_timeout timeout run_time) result facts |
48321 | 276 |
in |
277 |
print silent (fn () => cat_lines |
|
278 |
["Minimized to " ^ n_facts (map fst min_facts)] ^ |
|
48796
0f94b8b69e79
consider removing chained facts last, so that they're more likely to be kept
blanchet
parents:
48399
diff
changeset
|
279 |
(case min_facts |> filter is_fact_chained |> length of |
48321 | 280 |
0 => "" |
281 |
| n => "\n(including " ^ string_of_int n ^ " chained)") ^ "."); |
|
54503 | 282 |
(if learn then do_learn (maps snd min_facts) else ()); |
51187
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51130
diff
changeset
|
283 |
(SOME min_facts, |
54815 | 284 |
(if is_some preplay0 andalso length min_facts = length facts then the preplay0 |
285 |
else preplay, |
|
51187
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51130
diff
changeset
|
286 |
message, message_tail)) |
48321 | 287 |
end |
43052
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
288 |
| {outcome = SOME TimedOut, preplay, ...} => |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
289 |
(NONE, (preplay, fn _ => |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
290 |
"Timeout: You can increase the time limit using the \"timeout\" option (e.g., \ |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
291 |
\timeout = " ^ string_of_int (10 + Time.toMilliseconds timeout div 1000) ^ "\").", "")) |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
292 |
| {preplay, message, ...} => (NONE, (preplay, prefix "Prover error: " o message, "")))) |
55285 | 293 |
handle ERROR msg => |
294 |
(NONE, (Lazy.value (Metis_Method (NONE, NONE), Play_Failed), fn _ => "Error: " ^ msg, "")) |
|
31236 | 295 |
end |
296 |
||
55285 | 297 |
fun adjust_proof_method_params override_params |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
298 |
({debug, verbose, overlord, spy, blocking, provers, type_enc, strict, lam_trans, |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
299 |
uncurried_aliases, learn, fact_filter, max_facts, fact_thresholds, max_mono_iters, |
55297
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
300 |
max_new_mono_instances, isar_proofs, compress_isar, try0_isar, smt_proofs, slice, minimize, |
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
301 |
timeout, preplay_timeout, expect} : params) = |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
302 |
let |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
303 |
fun lookup_override name default_value = |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
304 |
(case AList.lookup (op =) override_params name of |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
305 |
SOME [s] => SOME s |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
306 |
| _ => default_value) |
55285 | 307 |
(* Only those options that proof_methods are interested in are considered here. *) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
308 |
val type_enc = lookup_override "type_enc" type_enc |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
309 |
val lam_trans = lookup_override "lam_trans" lam_trans |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
310 |
in |
53800 | 311 |
{debug = debug, verbose = verbose, overlord = overlord, spy = spy, blocking = blocking, |
312 |
provers = provers, type_enc = type_enc, strict = strict, lam_trans = lam_trans, |
|
313 |
uncurried_aliases = uncurried_aliases, learn = learn, fact_filter = fact_filter, |
|
314 |
max_facts = max_facts, fact_thresholds = fact_thresholds, max_mono_iters = max_mono_iters, |
|
49918
cf441f4a358b
renamed Isar-proof related options + changed semantics of Isar shrinking
blanchet
parents:
49914
diff
changeset
|
315 |
max_new_mono_instances = max_new_mono_instances, isar_proofs = isar_proofs, |
55297
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
316 |
compress_isar = compress_isar, try0_isar = try0_isar, smt_proofs = smt_proofs, slice = slice, |
55288
1a4358d14ce2
added 'smt' option to control generation of 'by smt' proofs
blanchet
parents:
55287
diff
changeset
|
317 |
minimize = minimize, timeout = timeout, preplay_timeout = preplay_timeout, expect = expect} |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
318 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
319 |
|
55205 | 320 |
fun maybe_minimize ctxt mode do_learn name (params as {verbose, isar_proofs, minimize, ...}) |
321 |
({state, goal, subgoal, subgoal_count, ...} : prover_problem) |
|
322 |
(result as {outcome, used_facts, used_from, run_time, preplay, message, message_tail} : |
|
323 |
prover_result) = |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
324 |
if is_some outcome orelse null used_facts then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
325 |
result |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
326 |
else |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
327 |
let |
55205 | 328 |
val thy = Proof_Context.theory_of ctxt |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
329 |
val num_facts = length used_facts |
55205 | 330 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
331 |
val ((perhaps_minimize, (minimize_name, params)), preplay) = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
332 |
if mode = Normal then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
333 |
if num_facts >= Config.get ctxt auto_minimize_min_facts then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
334 |
((true, (name, params)), preplay) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
335 |
else |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
336 |
let |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
337 |
fun can_min_fast_enough time = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
338 |
0.001 |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
339 |
* Real.fromInt ((num_facts + 1) * Time.toMilliseconds time) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
340 |
<= Config.get ctxt auto_minimize_max_time |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
341 |
fun prover_fast_enough () = can_min_fast_enough run_time |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
342 |
in |
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
343 |
(case Lazy.force preplay of |
55285 | 344 |
(meth as Metis_Method _, Played timeout) => |
51191
89e9e945a005
auto-minimizer should respect "isar_proofs = true"
blanchet
parents:
51190
diff
changeset
|
345 |
if isar_proofs = SOME true then |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
346 |
(* Cheat: Assume the selected ATP is as fast as "metis" for the goal it proved |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
347 |
itself. *) |
55205 | 348 |
(can_min_fast_enough timeout, (isar_supported_prover_of thy name, params)) |
51191
89e9e945a005
auto-minimizer should respect "isar_proofs = true"
blanchet
parents:
51190
diff
changeset
|
349 |
else if can_min_fast_enough timeout then |
55285 | 350 |
(true, extract_proof_method params meth |
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
351 |
||> (fn override_params => |
55285 | 352 |
adjust_proof_method_params override_params params)) |
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
353 |
else |
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
354 |
(prover_fast_enough (), (name, params)) |
56081 | 355 |
| (SMT2_Method, Played timeout) => |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
356 |
(* Cheat: Assume the original prover is as fast as "smt" for the goal it proved |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
357 |
itself. *) |
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
358 |
(can_min_fast_enough timeout, (name, params)) |
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
359 |
| _ => (prover_fast_enough (), (name, params)), |
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51187
diff
changeset
|
360 |
preplay) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
361 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
362 |
else |
54127
1e6db1c9f14c
verbose minimization when learning from ATP proofs
blanchet
parents:
54119
diff
changeset
|
363 |
((false, (name, params)), preplay) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
364 |
val minimize = minimize |> the_default perhaps_minimize |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
365 |
val (used_facts, (preplay, message, _)) = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
366 |
if minimize then |
48392
ca998fa08cd9
added "learn_from_atp" command to MaSh, for patient users
blanchet
parents:
48384
diff
changeset
|
367 |
minimize_facts do_learn minimize_name params |
54824 | 368 |
(not verbose orelse (mode <> Normal andalso mode <> MaSh)) subgoal subgoal_count state |
369 |
goal (SOME preplay) (filter_used_facts true used_facts (map (apsnd single) used_from)) |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
370 |
|>> Option.map (map fst) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
371 |
else |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
372 |
(SOME used_facts, (preplay, message, "")) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
373 |
in |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
374 |
(case used_facts of |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
375 |
SOME used_facts => |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
376 |
{outcome = NONE, used_facts = used_facts, used_from = used_from, run_time = run_time, |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
377 |
preplay = preplay, message = message, message_tail = message_tail} |
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
378 |
| NONE => result) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
379 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
380 |
|
51187
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51130
diff
changeset
|
381 |
fun get_minimizing_prover ctxt mode do_learn name params minimize_command |
c344cf148e8f
avoid using "smt" for minimization -- better use the prover itself, since then Sledgehammer gets to try metis again and gives the opportunity to output an Isar proof -- and show Isar proof as fallback for SMT proofs
blanchet
parents:
51130
diff
changeset
|
382 |
problem = |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
383 |
get_prover ctxt mode name params minimize_command problem |
48384
83dc102041e6
learn on explicit "min" command but do the learning in a thread, since it may take a couple of seconds
blanchet
parents:
48321
diff
changeset
|
384 |
|> maybe_minimize ctxt mode do_learn name params problem |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
48085
diff
changeset
|
385 |
|
48321 | 386 |
fun run_minimize (params as {provers, ...}) do_learn i refs state = |
38045 | 387 |
let |
388 |
val ctxt = Proof.context_of state |
|
54130
b4e6cd4cab92
thread the goal through instead of relying on unreliable (possibly fake) state
blanchet
parents:
54127
diff
changeset
|
389 |
val {goal, facts = chained_ths, ...} = Proof.goal state |
38696
4c6b65d6a135
quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents:
38617
diff
changeset
|
390 |
val reserved = reserved_isar_keyword_table () |
48396 | 391 |
val css = clasimpset_rule_table_of ctxt |
54130
b4e6cd4cab92
thread the goal through instead of relying on unreliable (possibly fake) state
blanchet
parents:
54127
diff
changeset
|
392 |
val facts = refs |> maps (map (apsnd single) o fact_of_ref ctxt reserved chained_ths css) |
38045 | 393 |
in |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
394 |
(case subgoal_count state of |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
40114
diff
changeset
|
395 |
0 => Output.urgent_message "No subgoal!" |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
396 |
| n => (case provers of |
41265
a393d6d8e198
let each prover minimizes its own stuff (rather than taking the first prover of the list to minimize every prover's stuff)
blanchet
parents:
41259
diff
changeset
|
397 |
[] => error "No prover is set." |
a393d6d8e198
let each prover minimizes its own stuff (rather than taking the first prover of the list to minimize every prover's stuff)
blanchet
parents:
41259
diff
changeset
|
398 |
| prover :: _ => |
a393d6d8e198
let each prover minimizes its own stuff (rather than taking the first prover of the list to minimize every prover's stuff)
blanchet
parents:
41259
diff
changeset
|
399 |
(kill_provers (); |
54130
b4e6cd4cab92
thread the goal through instead of relying on unreliable (possibly fake) state
blanchet
parents:
54127
diff
changeset
|
400 |
minimize_facts do_learn prover params false i n state goal NONE facts |
43261
a4aeb26a6362
make sure that the message tail (timing + TPTP important message) is preserved upon automatic minimization
blanchet
parents:
43259
diff
changeset
|
401 |
|> (fn (_, (preplay, message, message_tail)) => |
50669
84c7cf36b2e0
use "Lazy" to simplify control flow a bit and guarantee single evaluation (at most)
blanchet
parents:
50668
diff
changeset
|
402 |
message (Lazy.force preplay) ^ message_tail |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
403 |
|> Output.urgent_message)))) |
38045 | 404 |
end |
405 |
||
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
35865
diff
changeset
|
406 |
end; |