blanchet@38021
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer.ML
|
wenzelm@28477
|
2 |
Author: Fabian Immler, TU Muenchen
|
wenzelm@32996
|
3 |
Author: Makarius
|
blanchet@35969
|
4 |
Author: Jasmin Blanchette, TU Muenchen
|
wenzelm@28477
|
5 |
|
blanchet@38021
|
6 |
Sledgehammer's heart.
|
wenzelm@28477
|
7 |
*)
|
wenzelm@28477
|
8 |
|
blanchet@38021
|
9 |
signature SLEDGEHAMMER =
|
wenzelm@28477
|
10 |
sig
|
blanchet@38023
|
11 |
type failure = ATP_Systems.failure
|
blanchet@38988
|
12 |
type locality = Sledgehammer_Filter.locality
|
blanchet@38988
|
13 |
type relevance_override = Sledgehammer_Filter.relevance_override
|
blanchet@39004
|
14 |
type fol_formula = Sledgehammer_Translate.fol_formula
|
blanchet@38988
|
15 |
type minimize_command = Sledgehammer_Reconstruct.minimize_command
|
blanchet@39493
|
16 |
|
blanchet@35969
|
17 |
type params =
|
blanchet@38982
|
18 |
{blocking: bool,
|
blanchet@38982
|
19 |
debug: bool,
|
blanchet@35969
|
20 |
verbose: bool,
|
blanchet@36143
|
21 |
overlord: bool,
|
blanchet@35969
|
22 |
atps: string list,
|
blanchet@35969
|
23 |
full_types: bool,
|
blanchet@36235
|
24 |
explicit_apply: bool,
|
blanchet@38745
|
25 |
relevance_thresholds: real * real,
|
blanchet@38744
|
26 |
max_relevant: int option,
|
blanchet@35969
|
27 |
isar_proof: bool,
|
blanchet@36924
|
28 |
isar_shrink_factor: int,
|
blanchet@38985
|
29 |
timeout: Time.time,
|
blanchet@38985
|
30 |
expect: string}
|
blanchet@39493
|
31 |
|
blanchet@35867
|
32 |
type problem =
|
blanchet@39318
|
33 |
{state: Proof.state,
|
blanchet@38998
|
34 |
goal: thm,
|
blanchet@38998
|
35 |
subgoal: int,
|
blanchet@39366
|
36 |
axioms: (term * ((string * locality) * fol_formula) option) list,
|
blanchet@39366
|
37 |
only: bool}
|
blanchet@39493
|
38 |
|
blanchet@35867
|
39 |
type prover_result =
|
blanchet@36370
|
40 |
{outcome: failure option,
|
blanchet@35969
|
41 |
message: string,
|
blanchet@37926
|
42 |
pool: string Symtab.table,
|
blanchet@38752
|
43 |
used_thm_names: (string * locality) list,
|
blanchet@35969
|
44 |
atp_run_time_in_msecs: int,
|
blanchet@36369
|
45 |
output: string,
|
blanchet@39452
|
46 |
tstplike_proof: string,
|
blanchet@38818
|
47 |
axiom_names: (string * locality) list vector,
|
blanchet@38083
|
48 |
conjecture_shape: int list list}
|
blanchet@39493
|
49 |
|
blanchet@38100
|
50 |
type prover = params -> minimize_command -> problem -> prover_result
|
blanchet@35867
|
51 |
|
blanchet@38023
|
52 |
val dest_dir : string Config.T
|
blanchet@38023
|
53 |
val problem_prefix : string Config.T
|
blanchet@39003
|
54 |
val measure_run_time : bool Config.T
|
blanchet@35969
|
55 |
val kill_atps: unit -> unit
|
blanchet@35969
|
56 |
val running_atps: unit -> unit
|
wenzelm@29112
|
57 |
val messages: int option -> unit
|
blanchet@38023
|
58 |
val get_prover_fun : theory -> string -> prover
|
blanchet@38044
|
59 |
val run_sledgehammer :
|
blanchet@39318
|
60 |
params -> bool -> int -> relevance_override -> (string -> minimize_command)
|
blanchet@39318
|
61 |
-> Proof.state -> bool * Proof.state
|
blanchet@38023
|
62 |
val setup : theory -> theory
|
wenzelm@28477
|
63 |
end;
|
wenzelm@28477
|
64 |
|
blanchet@38021
|
65 |
structure Sledgehammer : SLEDGEHAMMER =
|
wenzelm@28477
|
66 |
struct
|
wenzelm@28477
|
67 |
|
blanchet@38028
|
68 |
open ATP_Problem
|
blanchet@39491
|
69 |
open ATP_Proof
|
blanchet@38028
|
70 |
open ATP_Systems
|
blanchet@37578
|
71 |
open Metis_Clauses
|
blanchet@38023
|
72 |
open Sledgehammer_Util
|
blanchet@38988
|
73 |
open Sledgehammer_Filter
|
blanchet@38282
|
74 |
open Sledgehammer_Translate
|
blanchet@38988
|
75 |
open Sledgehammer_Reconstruct
|
blanchet@37583
|
76 |
|
blanchet@38023
|
77 |
|
blanchet@37583
|
78 |
(** The Sledgehammer **)
|
blanchet@37583
|
79 |
|
blanchet@38102
|
80 |
(* Identifier to distinguish Sledgehammer from other tools using
|
blanchet@38102
|
81 |
"Async_Manager". *)
|
blanchet@37585
|
82 |
val das_Tool = "Sledgehammer"
|
blanchet@37585
|
83 |
|
blanchet@37585
|
84 |
fun kill_atps () = Async_Manager.kill_threads das_Tool "ATPs"
|
blanchet@37585
|
85 |
fun running_atps () = Async_Manager.running_threads das_Tool "ATPs"
|
blanchet@37585
|
86 |
val messages = Async_Manager.thread_messages das_Tool "ATP"
|
blanchet@35969
|
87 |
|
blanchet@36281
|
88 |
(** problems, results, provers, etc. **)
|
blanchet@35969
|
89 |
|
blanchet@35969
|
90 |
type params =
|
blanchet@38982
|
91 |
{blocking: bool,
|
blanchet@38982
|
92 |
debug: bool,
|
blanchet@35969
|
93 |
verbose: bool,
|
blanchet@36143
|
94 |
overlord: bool,
|
blanchet@35969
|
95 |
atps: string list,
|
blanchet@35969
|
96 |
full_types: bool,
|
blanchet@36235
|
97 |
explicit_apply: bool,
|
blanchet@38745
|
98 |
relevance_thresholds: real * real,
|
blanchet@38744
|
99 |
max_relevant: int option,
|
blanchet@35969
|
100 |
isar_proof: bool,
|
blanchet@36924
|
101 |
isar_shrink_factor: int,
|
blanchet@38985
|
102 |
timeout: Time.time,
|
blanchet@38985
|
103 |
expect: string}
|
blanchet@35867
|
104 |
|
blanchet@35867
|
105 |
type problem =
|
blanchet@39318
|
106 |
{state: Proof.state,
|
blanchet@38998
|
107 |
goal: thm,
|
blanchet@38998
|
108 |
subgoal: int,
|
blanchet@39366
|
109 |
axioms: (term * ((string * locality) * fol_formula) option) list,
|
blanchet@39366
|
110 |
only: bool}
|
blanchet@35867
|
111 |
|
blanchet@35867
|
112 |
type prover_result =
|
blanchet@36370
|
113 |
{outcome: failure option,
|
blanchet@35969
|
114 |
message: string,
|
blanchet@37926
|
115 |
pool: string Symtab.table,
|
blanchet@38752
|
116 |
used_thm_names: (string * locality) list,
|
blanchet@35969
|
117 |
atp_run_time_in_msecs: int,
|
blanchet@36369
|
118 |
output: string,
|
blanchet@39452
|
119 |
tstplike_proof: string,
|
blanchet@38818
|
120 |
axiom_names: (string * locality) list vector,
|
blanchet@38083
|
121 |
conjecture_shape: int list list}
|
blanchet@35867
|
122 |
|
blanchet@38100
|
123 |
type prover = params -> minimize_command -> problem -> prover_result
|
blanchet@35867
|
124 |
|
blanchet@38023
|
125 |
(* configuration attributes *)
|
blanchet@38023
|
126 |
|
blanchet@38991
|
127 |
val (dest_dir, dest_dir_setup) =
|
blanchet@39003
|
128 |
Attrib.config_string "sledgehammer_dest_dir" (K "")
|
blanchet@38991
|
129 |
(* Empty string means create files in Isabelle's temporary files directory. *)
|
blanchet@38023
|
130 |
|
blanchet@38023
|
131 |
val (problem_prefix, problem_prefix_setup) =
|
blanchet@39003
|
132 |
Attrib.config_string "sledgehammer_problem_prefix" (K "prob")
|
blanchet@38023
|
133 |
|
blanchet@39003
|
134 |
val (measure_run_time, measure_run_time_setup) =
|
blanchet@39003
|
135 |
Attrib.config_bool "sledgehammer_measure_run_time" (K false)
|
wenzelm@28484
|
136 |
|
blanchet@38023
|
137 |
fun with_path cleanup after f path =
|
blanchet@38023
|
138 |
Exn.capture f path
|
blanchet@38023
|
139 |
|> tap (fn _ => cleanup path)
|
blanchet@38023
|
140 |
|> Exn.release
|
blanchet@38023
|
141 |
|> tap (after path)
|
blanchet@38023
|
142 |
|
blanchet@38023
|
143 |
(* generic TPTP-based provers *)
|
blanchet@38023
|
144 |
|
blanchet@39492
|
145 |
(* Important messages are important but not so important that users want to see
|
blanchet@39492
|
146 |
them each time. *)
|
blanchet@39493
|
147 |
val important_message_keep_factor = 0.1
|
blanchet@39492
|
148 |
|
blanchet@39318
|
149 |
fun prover_fun auto atp_name
|
blanchet@38645
|
150 |
{exec, required_execs, arguments, has_incomplete_mode, proof_delims,
|
blanchet@38997
|
151 |
known_failures, default_max_relevant, explicit_forall,
|
blanchet@38997
|
152 |
use_conjecture_for_hypotheses}
|
blanchet@38455
|
153 |
({debug, verbose, overlord, full_types, explicit_apply,
|
blanchet@38998
|
154 |
max_relevant, isar_proof, isar_shrink_factor, timeout, ...} : params)
|
blanchet@39366
|
155 |
minimize_command ({state, goal, subgoal, axioms, only} : problem) =
|
blanchet@38023
|
156 |
let
|
blanchet@39318
|
157 |
val ctxt = Proof.context_of state
|
blanchet@38998
|
158 |
val (_, hyp_ts, concl_t) = strip_subgoal goal subgoal
|
blanchet@39366
|
159 |
val axioms = axioms |> not only
|
blanchet@39366
|
160 |
? take (the_default default_max_relevant max_relevant)
|
blanchet@38023
|
161 |
val the_dest_dir = if overlord then getenv "ISABELLE_HOME_USER"
|
blanchet@38998
|
162 |
else Config.get ctxt dest_dir
|
blanchet@38998
|
163 |
val the_problem_prefix = Config.get ctxt problem_prefix
|
blanchet@39003
|
164 |
val problem_file_name =
|
blanchet@39003
|
165 |
Path.basic ((if overlord then "prob_" ^ atp_name
|
blanchet@39003
|
166 |
else the_problem_prefix ^ serial_string ())
|
blanchet@39003
|
167 |
^ "_" ^ string_of_int subgoal)
|
blanchet@39003
|
168 |
val problem_path_name =
|
blanchet@39003
|
169 |
if the_dest_dir = "" then
|
blanchet@39003
|
170 |
File.tmp_path problem_file_name
|
blanchet@39003
|
171 |
else if File.exists (Path.explode the_dest_dir) then
|
blanchet@39003
|
172 |
Path.append (Path.explode the_dest_dir) problem_file_name
|
blanchet@39003
|
173 |
else
|
blanchet@39003
|
174 |
error ("No such directory: " ^ quote the_dest_dir ^ ".")
|
blanchet@39003
|
175 |
val measure_run_time = verbose orelse Config.get ctxt measure_run_time
|
blanchet@38092
|
176 |
val command = Path.explode (getenv (fst exec) ^ "/" ^ snd exec)
|
blanchet@38023
|
177 |
(* write out problem file and call prover *)
|
blanchet@38645
|
178 |
fun command_line complete timeout probfile =
|
blanchet@38023
|
179 |
let
|
blanchet@38023
|
180 |
val core = File.shell_path command ^ " " ^ arguments complete timeout ^
|
blanchet@38023
|
181 |
" " ^ File.shell_path probfile
|
blanchet@38023
|
182 |
in
|
blanchet@39010
|
183 |
(if measure_run_time then "TIMEFORMAT='%3R'; { time " ^ core ^ " ; }"
|
blanchet@38744
|
184 |
else "exec " ^ core) ^ " 2>&1"
|
blanchet@38023
|
185 |
end
|
blanchet@38023
|
186 |
fun split_time s =
|
blanchet@38023
|
187 |
let
|
blanchet@38023
|
188 |
val split = String.tokens (fn c => str c = "\n");
|
blanchet@38023
|
189 |
val (output, t) = s |> split |> split_last |> apfst cat_lines;
|
blanchet@38023
|
190 |
fun as_num f = f >> (fst o read_int);
|
blanchet@38023
|
191 |
val num = as_num (Scan.many1 Symbol.is_ascii_digit);
|
blanchet@38023
|
192 |
val digit = Scan.one Symbol.is_ascii_digit;
|
blanchet@38023
|
193 |
val num3 = as_num (digit ::: digit ::: (digit >> single));
|
blanchet@38023
|
194 |
val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b);
|
blanchet@38023
|
195 |
val as_time = the_default 0 o Scan.read Symbol.stopper time o explode;
|
blanchet@38023
|
196 |
in (output, as_time t) end;
|
blanchet@38023
|
197 |
fun run_on probfile =
|
blanchet@38092
|
198 |
case filter (curry (op =) "" o getenv o fst) (exec :: required_execs) of
|
blanchet@38032
|
199 |
(home_var, _) :: _ =>
|
blanchet@38023
|
200 |
error ("The environment variable " ^ quote home_var ^ " is not set.")
|
blanchet@38032
|
201 |
| [] =>
|
blanchet@38032
|
202 |
if File.exists command then
|
blanchet@38032
|
203 |
let
|
blanchet@39318
|
204 |
fun run complete timeout =
|
blanchet@38032
|
205 |
let
|
blanchet@38645
|
206 |
val command = command_line complete timeout probfile
|
blanchet@38032
|
207 |
val ((output, msecs), res_code) =
|
blanchet@38032
|
208 |
bash_output command
|
blanchet@38032
|
209 |
|>> (if overlord then
|
blanchet@38032
|
210 |
prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n")
|
blanchet@38032
|
211 |
else
|
blanchet@38032
|
212 |
I)
|
blanchet@38744
|
213 |
|>> (if measure_run_time then split_time else rpair 0)
|
blanchet@39452
|
214 |
val (tstplike_proof, outcome) =
|
blanchet@39452
|
215 |
extract_tstplike_proof_and_outcome complete res_code
|
blanchet@39452
|
216 |
proof_delims known_failures output
|
blanchet@39452
|
217 |
in (output, msecs, tstplike_proof, outcome) end
|
blanchet@38032
|
218 |
val readable_names = debug andalso overlord
|
blanchet@38282
|
219 |
val (problem, pool, conjecture_offset, axiom_names) =
|
blanchet@38282
|
220 |
prepare_problem ctxt readable_names explicit_forall full_types
|
blanchet@39005
|
221 |
explicit_apply hyp_ts concl_t axioms
|
blanchet@39452
|
222 |
val ss = tptp_strings_for_atp_problem use_conjecture_for_hypotheses
|
blanchet@39452
|
223 |
problem
|
blanchet@38631
|
224 |
val _ = File.write_list probfile ss
|
blanchet@38032
|
225 |
val conjecture_shape =
|
blanchet@38032
|
226 |
conjecture_offset + 1 upto conjecture_offset + length hyp_ts + 1
|
blanchet@38040
|
227 |
|> map single
|
blanchet@39318
|
228 |
val run_twice = has_incomplete_mode andalso not auto
|
blanchet@38645
|
229 |
val timer = Timer.startRealTimer ()
|
blanchet@38032
|
230 |
val result =
|
blanchet@39318
|
231 |
run false (if run_twice then
|
blanchet@39318
|
232 |
Time.fromMilliseconds
|
blanchet@38645
|
233 |
(2 * Time.toMilliseconds timeout div 3)
|
blanchet@39318
|
234 |
else
|
blanchet@39318
|
235 |
timeout)
|
blanchet@39318
|
236 |
|> run_twice
|
blanchet@38645
|
237 |
? (fn (_, msecs0, _, SOME _) =>
|
blanchet@39318
|
238 |
run true (Time.- (timeout, Timer.checkRealTimer timer))
|
blanchet@39452
|
239 |
|> (fn (output, msecs, tstplike_proof, outcome) =>
|
blanchet@39452
|
240 |
(output, msecs0 + msecs, tstplike_proof, outcome))
|
blanchet@38645
|
241 |
| result => result)
|
blanchet@38282
|
242 |
in ((pool, conjecture_shape, axiom_names), result) end
|
blanchet@38032
|
243 |
else
|
blanchet@38032
|
244 |
error ("Bad executable: " ^ Path.implode command ^ ".")
|
blanchet@38023
|
245 |
|
blanchet@38023
|
246 |
(* If the problem file has not been exported, remove it; otherwise, export
|
blanchet@38023
|
247 |
the proof file too. *)
|
blanchet@38023
|
248 |
fun cleanup probfile =
|
blanchet@38023
|
249 |
if the_dest_dir = "" then try File.rm probfile else NONE
|
blanchet@38023
|
250 |
fun export probfile (_, (output, _, _, _)) =
|
blanchet@38023
|
251 |
if the_dest_dir = "" then
|
blanchet@38023
|
252 |
()
|
blanchet@38023
|
253 |
else
|
blanchet@38023
|
254 |
File.write (Path.explode (Path.implode probfile ^ "_proof")) output
|
blanchet@38282
|
255 |
val ((pool, conjecture_shape, axiom_names),
|
blanchet@39452
|
256 |
(output, msecs, tstplike_proof, outcome)) =
|
blanchet@39003
|
257 |
with_path cleanup export run_on problem_path_name
|
blanchet@38282
|
258 |
val (conjecture_shape, axiom_names) =
|
blanchet@39493
|
259 |
repair_conjecture_shape_and_axiom_names output conjecture_shape
|
blanchet@39493
|
260 |
axiom_names
|
blanchet@39492
|
261 |
val important_message =
|
blanchet@39493
|
262 |
if random () <= important_message_keep_factor then
|
blanchet@39492
|
263 |
extract_important_message output
|
blanchet@39492
|
264 |
else
|
blanchet@39492
|
265 |
""
|
blanchet@39327
|
266 |
val banner = if auto then "Sledgehammer found a proof"
|
blanchet@39327
|
267 |
else "Try this command"
|
blanchet@38023
|
268 |
val (message, used_thm_names) =
|
blanchet@38023
|
269 |
case outcome of
|
blanchet@38023
|
270 |
NONE =>
|
blanchet@38023
|
271 |
proof_text isar_proof
|
blanchet@38023
|
272 |
(pool, debug, isar_shrink_factor, ctxt, conjecture_shape)
|
blanchet@39452
|
273 |
(banner, full_types, minimize_command, tstplike_proof, axiom_names,
|
blanchet@39452
|
274 |
goal, subgoal)
|
blanchet@38744
|
275 |
|>> (fn message =>
|
blanchet@38744
|
276 |
message ^ (if verbose then
|
blanchet@39371
|
277 |
"\nATP real CPU time: " ^ string_of_int msecs ^
|
blanchet@39371
|
278 |
" ms."
|
blanchet@38744
|
279 |
else
|
blanchet@39107
|
280 |
"") ^
|
blanchet@39107
|
281 |
(if important_message <> "" then
|
blanchet@39107
|
282 |
"\n\nImportant message from Dr. Geoff Sutcliffe:\n" ^
|
blanchet@39107
|
283 |
important_message
|
blanchet@39107
|
284 |
else
|
blanchet@39107
|
285 |
""))
|
blanchet@38597
|
286 |
| SOME failure => (string_for_failure failure, [])
|
blanchet@38023
|
287 |
in
|
blanchet@38023
|
288 |
{outcome = outcome, message = message, pool = pool,
|
blanchet@38023
|
289 |
used_thm_names = used_thm_names, atp_run_time_in_msecs = msecs,
|
blanchet@39452
|
290 |
output = output, tstplike_proof = tstplike_proof,
|
blanchet@39452
|
291 |
axiom_names = axiom_names, conjecture_shape = conjecture_shape}
|
blanchet@38023
|
292 |
end
|
blanchet@38023
|
293 |
|
blanchet@39318
|
294 |
fun get_prover_fun thy name = prover_fun false name (get_prover thy name)
|
blanchet@38023
|
295 |
|
blanchet@39453
|
296 |
fun run_prover (params as {blocking, debug, verbose, max_relevant, timeout,
|
blanchet@39453
|
297 |
expect, ...})
|
blanchet@39338
|
298 |
auto i n minimize_command (problem as {state, goal, axioms, ...})
|
blanchet@39110
|
299 |
(prover as {default_max_relevant, ...}, atp_name) =
|
blanchet@36379
|
300 |
let
|
blanchet@39318
|
301 |
val ctxt = Proof.context_of state
|
blanchet@37584
|
302 |
val birth_time = Time.now ()
|
blanchet@37584
|
303 |
val death_time = Time.+ (birth_time, timeout)
|
blanchet@39110
|
304 |
val max_relevant = the_default default_max_relevant max_relevant
|
blanchet@39110
|
305 |
val num_axioms = Int.min (length axioms, max_relevant)
|
blanchet@36379
|
306 |
val desc =
|
blanchet@39110
|
307 |
"ATP " ^ quote atp_name ^
|
blanchet@39110
|
308 |
(if verbose then
|
blanchet@39110
|
309 |
" with " ^ string_of_int num_axioms ^ " fact" ^ plural_s num_axioms
|
blanchet@39110
|
310 |
else
|
blanchet@39110
|
311 |
"") ^
|
blanchet@39110
|
312 |
" on " ^ (if n = 1 then "goal" else "subgoal " ^ string_of_int i) ^ ":" ^
|
blanchet@38985
|
313 |
(if blocking then
|
blanchet@38985
|
314 |
""
|
blanchet@38985
|
315 |
else
|
blanchet@38985
|
316 |
"\n" ^ Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i)))
|
blanchet@39318
|
317 |
fun go () =
|
blanchet@38982
|
318 |
let
|
blanchet@39453
|
319 |
fun really_go () =
|
blanchet@39318
|
320 |
prover_fun auto atp_name prover params (minimize_command atp_name)
|
blanchet@39318
|
321 |
problem
|
blanchet@38985
|
322 |
|> (fn {outcome, message, ...} =>
|
blanchet@38985
|
323 |
(if is_some outcome then "none" else "some", message))
|
blanchet@39453
|
324 |
val (outcome_code, message) =
|
blanchet@39453
|
325 |
if debug then
|
blanchet@39453
|
326 |
really_go ()
|
blanchet@39453
|
327 |
else
|
blanchet@39453
|
328 |
(really_go ()
|
blanchet@39453
|
329 |
handle ERROR message => ("unknown", "Error: " ^ message ^ "\n")
|
blanchet@39453
|
330 |
| exn => ("unknown", "Internal error:\n" ^
|
blanchet@39453
|
331 |
ML_Compiler.exn_message exn ^ "\n"))
|
blanchet@39318
|
332 |
val _ =
|
blanchet@39318
|
333 |
if expect = "" orelse outcome_code = expect then
|
blanchet@39318
|
334 |
()
|
blanchet@39318
|
335 |
else if blocking then
|
blanchet@39318
|
336 |
error ("Unexpected outcome: " ^ quote outcome_code ^ ".")
|
blanchet@39318
|
337 |
else
|
blanchet@39318
|
338 |
warning ("Unexpected outcome: " ^ quote outcome_code ^ ".");
|
blanchet@39318
|
339 |
in (outcome_code = "some", message) end
|
blanchet@39318
|
340 |
in
|
blanchet@39318
|
341 |
if auto then
|
blanchet@39318
|
342 |
let val (success, message) = TimeLimit.timeLimit timeout go () in
|
blanchet@39318
|
343 |
(success, state |> success ? Proof.goal_message (fn () =>
|
blanchet@39318
|
344 |
Pretty.chunks [Pretty.str "", Pretty.mark Markup.hilite
|
blanchet@39327
|
345 |
(Pretty.str message)]))
|
blanchet@38982
|
346 |
end
|
blanchet@39318
|
347 |
else if blocking then
|
blanchet@39318
|
348 |
let val (success, message) = TimeLimit.timeLimit timeout go () in
|
blanchet@39370
|
349 |
List.app priority
|
blanchet@39370
|
350 |
(Async_Manager.break_into_chunks [desc ^ "\n" ^ message]);
|
blanchet@39370
|
351 |
(success, state)
|
blanchet@39318
|
352 |
end
|
blanchet@39318
|
353 |
else
|
blanchet@39318
|
354 |
(Async_Manager.launch das_Tool birth_time death_time desc (snd o go);
|
blanchet@39318
|
355 |
(false, state))
|
blanchet@37584
|
356 |
end
|
wenzelm@28582
|
357 |
|
blanchet@39318
|
358 |
val auto_max_relevant_divisor = 2
|
blanchet@39318
|
359 |
|
blanchet@39373
|
360 |
fun run_sledgehammer (params as {blocking, atps, full_types,
|
blanchet@38998
|
361 |
relevance_thresholds, max_relevant, ...})
|
blanchet@39366
|
362 |
auto i (relevance_override as {only, ...}) minimize_command
|
blanchet@39366
|
363 |
state =
|
blanchet@39318
|
364 |
if null atps then
|
blanchet@39318
|
365 |
error "No ATP is set."
|
blanchet@39318
|
366 |
else case subgoal_count state of
|
blanchet@39318
|
367 |
0 => (priority "No subgoal!"; (false, state))
|
blanchet@39318
|
368 |
| n =>
|
blanchet@39318
|
369 |
let
|
blanchet@39364
|
370 |
val _ = Proof.assert_backward state
|
blanchet@39318
|
371 |
val thy = Proof.theory_of state
|
blanchet@39318
|
372 |
val _ = () |> not blocking ? kill_atps
|
blanchet@39318
|
373 |
val _ = if auto then () else priority "Sledgehammering..."
|
blanchet@39318
|
374 |
val provers = map (`(get_prover thy)) atps
|
blanchet@39318
|
375 |
fun go () =
|
blanchet@39318
|
376 |
let
|
blanchet@39318
|
377 |
val {context = ctxt, facts = chained_ths, goal} = Proof.goal state
|
blanchet@39318
|
378 |
val (_, hyp_ts, concl_t) = strip_subgoal goal i
|
blanchet@39318
|
379 |
val max_max_relevant =
|
blanchet@39318
|
380 |
case max_relevant of
|
blanchet@39318
|
381 |
SOME n => n
|
blanchet@39318
|
382 |
| NONE =>
|
blanchet@39318
|
383 |
0 |> fold (Integer.max o #default_max_relevant o fst) provers
|
blanchet@39318
|
384 |
|> auto ? (fn n => n div auto_max_relevant_divisor)
|
blanchet@39318
|
385 |
val axioms =
|
blanchet@39318
|
386 |
relevant_facts ctxt full_types relevance_thresholds
|
blanchet@39318
|
387 |
max_max_relevant relevance_override chained_ths
|
blanchet@39318
|
388 |
hyp_ts concl_t
|
blanchet@39318
|
389 |
val problem =
|
blanchet@39318
|
390 |
{state = state, goal = goal, subgoal = i,
|
blanchet@39366
|
391 |
axioms = map (prepare_axiom ctxt) axioms, only = only}
|
blanchet@39338
|
392 |
val run_prover = run_prover params auto i n minimize_command problem
|
blanchet@39318
|
393 |
in
|
blanchet@39318
|
394 |
if auto then
|
blanchet@39318
|
395 |
fold (fn prover => fn (true, state) => (true, state)
|
blanchet@39318
|
396 |
| (false, _) => run_prover prover)
|
blanchet@39318
|
397 |
provers (false, state)
|
blanchet@39318
|
398 |
else
|
blanchet@39318
|
399 |
(if blocking then Par_List.map else map) run_prover provers
|
blanchet@39318
|
400 |
|> exists fst |> rpair state
|
blanchet@39318
|
401 |
end
|
blanchet@39318
|
402 |
in if blocking then go () else Future.fork (tap go) |> K (false, state) end
|
blanchet@38044
|
403 |
|
blanchet@38023
|
404 |
val setup =
|
blanchet@38023
|
405 |
dest_dir_setup
|
blanchet@38023
|
406 |
#> problem_prefix_setup
|
blanchet@39003
|
407 |
#> measure_run_time_setup
|
blanchet@38023
|
408 |
|
wenzelm@28582
|
409 |
end;
|