author | blanchet |
Fri, 01 Aug 2014 14:43:57 +0200 | |
changeset 57734 | 18bb3e1ff6f6 |
parent 57557 | 242ce8d3d16b |
child 57735 | 056a55b44ec7 |
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.ML |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Muenchen |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
3 |
Author: Makarius |
35969 | 4 |
Author: Jasmin Blanchette, TU Muenchen |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
5 |
|
38021
e024504943d1
rename "ATP_Manager" ML module to "Sledgehammer";
blanchet
parents:
38020
diff
changeset
|
6 |
Sledgehammer's heart. |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
7 |
*) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
8 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
9 |
signature SLEDGEHAMMER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
sig |
51008 | 11 |
type fact = Sledgehammer_Fact.fact |
48292 | 12 |
type fact_override = Sledgehammer_Fact.fact_override |
55287 | 13 |
type minimize_command = Sledgehammer_Proof_Methods.minimize_command |
55201 | 14 |
type mode = Sledgehammer_Prover.mode |
15 |
type params = Sledgehammer_Prover.params |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
16 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
17 |
val someN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
18 |
val noneN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
19 |
val timeoutN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
20 |
val unknownN : string |
55212 | 21 |
|
51010 | 22 |
val string_of_factss : (string * fact list) list -> string |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54799
diff
changeset
|
23 |
val run_sledgehammer : params -> mode -> (string -> unit) option -> int -> fact_override -> |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54799
diff
changeset
|
24 |
((string * string list) list -> string -> minimize_command) -> Proof.state -> |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54799
diff
changeset
|
25 |
bool * (string * Proof.state) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
26 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
27 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
28 |
structure Sledgehammer : SLEDGEHAMMER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
29 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
30 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43064
diff
changeset
|
31 |
open ATP_Util |
55212 | 32 |
open ATP_Proof |
46320 | 33 |
open ATP_Problem_Generate |
38023 | 34 |
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:
47904
diff
changeset
|
35 |
open Sledgehammer_Fact |
55287 | 36 |
open Sledgehammer_Proof_Methods |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
37 |
open Sledgehammer_Isar_Proof |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
38 |
open Sledgehammer_Isar_Preplay |
55201 | 39 |
open Sledgehammer_Prover |
55212 | 40 |
open Sledgehammer_Prover_ATP |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55201
diff
changeset
|
41 |
open Sledgehammer_Prover_Minimize |
48381 | 42 |
open Sledgehammer_MaSh |
40072
27f2a45b0aab
more robust handling of "remote_" vs. non-"remote_" provers
blanchet
parents:
40071
diff
changeset
|
43 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
44 |
val someN = "some" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
45 |
val noneN = "none" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
46 |
val timeoutN = "timeout" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
47 |
val unknownN = "unknown" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
48 |
|
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
49 |
val ordered_outcome_codes = [someN, unknownN, timeoutN, noneN] |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
50 |
|
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
51 |
fun max_outcome_code codes = |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
52 |
NONE |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
53 |
|> fold (fn candidate => |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
54 |
fn accum as SOME _ => accum |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
55 |
| NONE => if member (op =) codes candidate then SOME candidate else NONE) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
56 |
ordered_outcome_codes |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
57 |
|> the_default unknownN |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
58 |
|
57053
46000c075d07
shorten Sledgehammer output, as suggested by Andrei Popescu
blanchet
parents:
57037
diff
changeset
|
59 |
fun prover_description verbose name num_facts = |
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
48299
diff
changeset
|
60 |
(quote name, |
57053
46000c075d07
shorten Sledgehammer output, as suggested by Andrei Popescu
blanchet
parents:
57037
diff
changeset
|
61 |
if verbose then " with " ^ string_of_int num_facts ^ " fact" ^ plural_s num_facts else "") |
41089 | 62 |
|
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
63 |
fun play_one_line_proof mode timeout used_facts state i (preferred, methss as (meth :: _) :: _) = |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
64 |
let |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
65 |
fun dont_know () = |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
66 |
(if exists (fn meths => member (op =) meths preferred) methss then preferred else meth, |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
67 |
Play_Timed_Out Time.zeroTime) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
68 |
in |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
69 |
if timeout = Time.zeroTime then |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
70 |
dont_know () |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
71 |
else |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
72 |
let |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
73 |
val _ = if mode = Minimize then Output.urgent_message "Preplaying proof..." else () |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
74 |
val facts = used_facts |> map (fst o fst) |> sort string_ord |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
75 |
|
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
76 |
val {context = ctxt, facts = chained, goal} = Proof.goal state |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
77 |
val (_, hyp_ts, concl_t) = strip_subgoal goal i ctxt |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
78 |
val goal_t = Logic.list_implies (map prop_of chained @ hyp_ts, concl_t) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
79 |
|
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
80 |
fun try_methss [] = dont_know () |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
81 |
| try_methss (meths :: methss) = |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
82 |
let val step = Prove ([], [], ("", 0), goal_t, [], ([], facts), meths, "") in |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
83 |
(case preplay_isar_step ctxt timeout [] step of |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
84 |
(res as (_, Played _)) :: _ => res |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
85 |
| _ => try_methss methss) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
86 |
end |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
87 |
in |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
88 |
try_methss methss |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
89 |
end |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
90 |
end |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
91 |
|
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
92 |
fun launch_prover (params as {debug, verbose, spy, blocking, max_facts, timeout, preplay_timeout, |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
93 |
expect, ...}) mode output_result minimize_command only learn |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54799
diff
changeset
|
94 |
{comment, state, goal, subgoal, subgoal_count, factss as (_, facts) :: _} name = |
41089 | 95 |
let |
96 |
val ctxt = Proof.context_of state |
|
53800 | 97 |
|
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54799
diff
changeset
|
98 |
val hard_timeout = time_mult 3.0 timeout |
54062 | 99 |
val _ = spying spy (fn () => (state, subgoal, name, "Launched")); |
41089 | 100 |
val birth_time = Time.now () |
42850
c8709be8a40f
distinguish between a soft timeout (30 s by defalt) and a hard timeout (60 s), to let minimization-based provers (such as CVC3, Yices, and occasionally the other provers) do their job
blanchet
parents:
42646
diff
changeset
|
101 |
val death_time = Time.+ (birth_time, hard_timeout) |
54126
6675cdc0d1ae
if slicing is disabled, pick the maximum number of facts, not the number of facts in the last slice
blanchet
parents:
54090
diff
changeset
|
102 |
val max_facts = max_facts |> the_default (default_max_facts_of_prover ctxt name) |
48293 | 103 |
val num_facts = length facts |> not only ? Integer.min max_facts |
53800 | 104 |
|
41089 | 105 |
val problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
106 |
{comment = comment, state = state, goal = goal, subgoal = subgoal, |
47904
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
107 |
subgoal_count = subgoal_count, |
53800 | 108 |
factss = factss |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
109 |
|> map (apsnd ((not (is_ho_atp ctxt name) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
110 |
? filter_out (fn ((_, (_, Induction)), _) => true | _ => false)) |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
111 |
#> take num_facts))} |
53800 | 112 |
|
51009
e8ff34a1fa9a
thread through fact triple component from which used facts come, for accurate index output
blanchet
parents:
51008
diff
changeset
|
113 |
fun print_used_facts used_facts used_from = |
e8ff34a1fa9a
thread through fact triple component from which used facts come, for accurate index output
blanchet
parents:
51008
diff
changeset
|
114 |
tag_list 1 used_from |
51005
ce4290c33d73
eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents:
51004
diff
changeset
|
115 |
|> map (fn (j, fact) => fact |> apsnd (K j)) |
48798 | 116 |
|> filter_used_facts false used_facts |
48394
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48384
diff
changeset
|
117 |
|> map (fn ((name, _), j) => name ^ "@" ^ string_of_int j) |
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48384
diff
changeset
|
118 |
|> commas |
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48384
diff
changeset
|
119 |
|> enclose ("Fact" ^ plural_s (length facts) ^ " in " ^ quote name ^ |
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48384
diff
changeset
|
120 |
" proof (of " ^ string_of_int (length facts) ^ "): ") "." |
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48384
diff
changeset
|
121 |
|> Output.urgent_message |
53800 | 122 |
|
54062 | 123 |
fun spying_str_of_res ({outcome = NONE, used_facts, used_from, ...} : prover_result) = |
124 |
let |
|
125 |
val num_used_facts = length used_facts |
|
54063 | 126 |
|
127 |
fun find_indices facts = |
|
128 |
tag_list 1 facts |
|
54062 | 129 |
|> map (fn (j, fact) => fact |> apsnd (K j)) |
130 |
|> filter_used_facts false used_facts |
|
54773 | 131 |
|> distinct (eq_fst (op =)) |
54062 | 132 |
|> map (prefix "@" o string_of_int o snd) |
54063 | 133 |
|
134 |
fun filter_info (fact_filter, facts) = |
|
135 |
let |
|
136 |
val indices = find_indices facts |
|
54773 | 137 |
(* "Int.max" is there for robustness -- it shouldn't be necessary *) |
138 |
val unknowns = replicate (Int.max (0, num_used_facts - length indices)) "?" |
|
139 |
in |
|
140 |
(commas (indices @ unknowns), fact_filter) |
|
141 |
end |
|
54063 | 142 |
|
143 |
val filter_infos = |
|
144 |
map filter_info (("actual", used_from) :: factss) |
|
145 |
|> AList.group (op =) |
|
146 |
|> map (fn (indices, fact_filters) => commas fact_filters ^ ": " ^ indices) |
|
54062 | 147 |
in |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
148 |
"Success: Found proof with " ^ string_of_int num_used_facts ^ " of " ^ |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
149 |
string_of_int num_facts ^ " fact" ^ plural_s num_facts ^ |
54063 | 150 |
(if num_used_facts = 0 then "" else ": " ^ commas filter_infos) |
53800 | 151 |
end |
152 |
| spying_str_of_res {outcome = SOME failure, ...} = |
|
54062 | 153 |
"Failure: " ^ string_of_atp_failure failure |
53800 | 154 |
|
41255
a80024d7b71b
added debugging option to find out how good the relevance filter was at identifying relevant facts
blanchet
parents:
41245
diff
changeset
|
155 |
fun really_go () = |
41263
4cac389c005f
renamed function to run prover with minimizer and changed signature to clarify its semantics and make it a drop in replacement for "get_prover"
blanchet
parents:
41262
diff
changeset
|
156 |
problem |
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:
51010
diff
changeset
|
157 |
|> get_minimizing_prover ctxt mode learn name params minimize_command |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
158 |
|> verbose ? tap (fn {outcome = NONE, used_facts as _ :: _, used_from, ...} => |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
159 |
print_used_facts used_facts used_from |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
160 |
| _ => ()) |
57056 | 161 |
|> spy ? tap (fn res => spying spy (fn () => (state, subgoal, name, spying_str_of_res res))) |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
162 |
|> (fn {outcome, used_facts, used_from, preferred_methss, message, message_tail, ...} => |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
163 |
(if outcome = SOME ATP_Proof.TimedOut then timeoutN |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
164 |
else if is_some outcome then noneN |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
165 |
else someN, |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
166 |
fn () => message (play_one_line_proof mode preplay_timeout |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
167 |
(filter_used_facts false used_facts used_from) state subgoal |
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57557
diff
changeset
|
168 |
preferred_methss) ^ message_tail)) |
53800 | 169 |
|
41089 | 170 |
fun go () = |
171 |
let |
|
172 |
val (outcome_code, message) = |
|
173 |
if debug then |
|
174 |
really_go () |
|
175 |
else |
|
176 |
(really_go () |
|
57056 | 177 |
handle |
178 |
ERROR msg => (unknownN, fn () => "Error: " ^ msg ^ "\n") |
|
179 |
| exn => |
|
180 |
if Exn.is_interrupt exn then reraise exn |
|
181 |
else (unknownN, fn () => "Internal error:\n" ^ Runtime.exn_message exn ^ "\n")) |
|
182 |
||
41089 | 183 |
val _ = |
41142
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
184 |
(* The "expect" argument is deliberately ignored if the prover is |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
185 |
missing so that the "Metis_Examples" can be processed on any |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
186 |
machine. *) |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
187 |
if expect = "" orelse outcome_code = expect orelse |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
188 |
not (is_prover_installed ctxt name) then |
41089 | 189 |
() |
190 |
else if blocking then |
|
191 |
error ("Unexpected outcome: " ^ quote outcome_code ^ ".") |
|
192 |
else |
|
193 |
warning ("Unexpected outcome: " ^ quote outcome_code ^ "."); |
|
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
194 |
in (outcome_code, message) end |
41089 | 195 |
in |
43021 | 196 |
if mode = Auto_Try then |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54799
diff
changeset
|
197 |
let val (outcome_code, message) = TimeLimit.timeLimit timeout go () in |
43006 | 198 |
(outcome_code, |
199 |
state |
|
200 |
|> outcome_code = someN |
|
201 |
? Proof.goal_message (fn () => |
|
52643
34c29356930e
more explicit Markup.information for messages produced by "auto" tools;
wenzelm
parents:
52555
diff
changeset
|
202 |
Pretty.mark Markup.information (Pretty.str (message ())))) |
41089 | 203 |
end |
204 |
else if blocking then |
|
43006 | 205 |
let |
206 |
val (outcome_code, message) = TimeLimit.timeLimit hard_timeout go () |
|
53048
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
207 |
val outcome = |
57056 | 208 |
if outcome_code = someN orelse mode = Normal then quote name ^ ": " ^ message () else "" |
53048
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
209 |
val _ = |
53052
a0db255af8c5
sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents:
53048
diff
changeset
|
210 |
if outcome <> "" andalso is_some output_result then |
53048
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
211 |
the output_result outcome |
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
52643
diff
changeset
|
212 |
else |
53048
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
213 |
outcome |
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
214 |
|> Async_Manager.break_into_chunks |
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
215 |
|> List.app Output.urgent_message |
0f76e620561f
more direct sledgehammer configuration via mode = Normal_Result and output_result;
wenzelm
parents:
52997
diff
changeset
|
216 |
in (outcome_code, state) end |
41089 | 217 |
else |
57053
46000c075d07
shorten Sledgehammer output, as suggested by Andrei Popescu
blanchet
parents:
57037
diff
changeset
|
218 |
(Async_Manager.thread SledgehammerN birth_time death_time |
46000c075d07
shorten Sledgehammer output, as suggested by Andrei Popescu
blanchet
parents:
57037
diff
changeset
|
219 |
(prover_description verbose name num_facts) |
55212 | 220 |
((fn (outcome_code, message) => (verbose orelse outcome_code = someN, message ())) o go); |
43006 | 221 |
(unknownN, state)) |
41089 | 222 |
end |
223 |
||
48293 | 224 |
val auto_try_max_facts_divisor = 2 (* FUDGE *) |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
225 |
|
51008 | 226 |
fun string_of_facts facts = |
57384 | 227 |
"Including " ^ string_of_int (length facts) ^ " relevant fact" ^ plural_s (length facts) ^ ": " ^ |
51008 | 228 |
(facts |> map (fst o fst) |> space_implode " ") ^ "." |
229 |
||
51010 | 230 |
fun string_of_factss factss = |
57464 | 231 |
if forall (null o snd) factss then |
232 |
"Found no relevant facts." |
|
233 |
else |
|
234 |
cat_lines (map (fn (filter, facts) => |
|
235 |
(if filter = "" then "" else quote filter ^ ": ") ^ string_of_facts facts) factss) |
|
51008 | 236 |
|
57368 | 237 |
fun run_sledgehammer (params as {verbose, spy, blocking, provers, max_facts, ...}) mode |
54799 | 238 |
output_result i (fact_override as {only, ...}) minimize_command state = |
40059
6ad9081665db
use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents:
39494
diff
changeset
|
239 |
if null provers then |
6ad9081665db
use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents:
39494
diff
changeset
|
240 |
error "No prover is set." |
55286 | 241 |
else |
242 |
(case subgoal_count state of |
|
243 |
0 => |
|
52908
3461985dcbc3
dockable window for Sledgehammer, based on asynchronous/parallel query operation;
wenzelm
parents:
52643
diff
changeset
|
244 |
((if blocking then error else Output.urgent_message) "No subgoal!"; (false, (noneN, state))) |
55286 | 245 |
| n => |
246 |
let |
|
247 |
val _ = Proof.assert_backward state |
|
248 |
val print = |
|
249 |
if mode = Normal andalso is_none output_result then Output.urgent_message else K () |
|
250 |
val ctxt = Proof.context_of state |
|
251 |
val {facts = chained, goal, ...} = Proof.goal state |
|
252 |
val (_, hyp_ts, concl_t) = strip_subgoal goal i ctxt |
|
253 |
val ho_atp = exists (is_ho_atp ctxt) provers |
|
254 |
val reserved = reserved_isar_keyword_table () |
|
255 |
val css = clasimpset_rule_table_of ctxt |
|
256 |
val all_facts = |
|
57262 | 257 |
nearly_all_facts ctxt ho_atp fact_override reserved css chained hyp_ts concl_t |
55286 | 258 |
val _ = () |> not blocking ? kill_provers |
259 |
val _ = |
|
260 |
(case find_first (not o is_prover_supported ctxt) provers of |
|
261 |
SOME name => error ("No such prover: " ^ name ^ ".") |
|
262 |
| NONE => ()) |
|
263 |
val _ = print "Sledgehammering..." |
|
57037 | 264 |
val _ = spying spy (fn () => (state, i, "***", "Starting " ^ str_of_mode mode ^ " mode")) |
54090
a28992e35032
run relevance filter only once for ATPs and SMT solvers, since it should now yield the same results anyway
blanchet
parents:
54063
diff
changeset
|
265 |
|
55286 | 266 |
val spying_str_of_factss = |
267 |
commas o map (fn (filter, facts) => filter ^ ": " ^ string_of_int (length facts)) |
|
53800 | 268 |
|
55286 | 269 |
fun get_factss provers = |
270 |
let |
|
271 |
val max_max_facts = |
|
272 |
(case max_facts of |
|
273 |
SOME n => n |
|
274 |
| NONE => |
|
275 |
0 |> fold (Integer.max o default_max_facts_of_prover ctxt) provers |
|
276 |
|> mode = Auto_Try ? (fn n => n div auto_try_max_facts_divisor)) |
|
277 |
val _ = spying spy (fn () => (state, i, "All", |
|
57557 | 278 |
"Filtering " ^ string_of_int (length all_facts) ^ " facts (MaSh algorithm: " ^ |
279 |
str_of_mash_algorithm (the_mash_algorithm ()) ^ ")")); |
|
55286 | 280 |
in |
281 |
all_facts |
|
282 |
|> relevant_facts ctxt params (hd provers) max_max_facts fact_override hyp_ts concl_t |
|
283 |
|> tap (fn factss => if verbose then print (string_of_factss factss) else ()) |
|
284 |
|> spy ? tap (fn factss => spying spy (fn () => |
|
285 |
(state, i, "All", "Selected facts: " ^ spying_str_of_factss factss))) |
|
286 |
end |
|
53800 | 287 |
|
55286 | 288 |
fun launch_provers state = |
289 |
let |
|
290 |
val factss = get_factss provers |
|
291 |
val problem = |
|
292 |
{comment = "", state = state, goal = goal, subgoal = i, subgoal_count = n, |
|
293 |
factss = factss} |
|
294 |
val learn = mash_learn_proof ctxt params (prop_of goal) all_facts |
|
295 |
val launch = launch_prover params mode output_result minimize_command only learn |
|
296 |
in |
|
297 |
if mode = Auto_Try then |
|
298 |
(unknownN, state) |
|
299 |
|> fold (fn prover => fn accum as (outcome_code, _) => |
|
57056 | 300 |
if outcome_code = someN then accum else launch problem prover) |
301 |
provers |
|
55286 | 302 |
else |
57387
2b6fe2a48352
reintroduced MaSh hints, this time as persistent creatures
blanchet
parents:
57384
diff
changeset
|
303 |
(learn chained; |
2b6fe2a48352
reintroduced MaSh hints, this time as persistent creatures
blanchet
parents:
57384
diff
changeset
|
304 |
provers |
2b6fe2a48352
reintroduced MaSh hints, this time as persistent creatures
blanchet
parents:
57384
diff
changeset
|
305 |
|> (if blocking then Par_List.map else map) (launch problem #> fst) |
2b6fe2a48352
reintroduced MaSh hints, this time as persistent creatures
blanchet
parents:
57384
diff
changeset
|
306 |
|> max_outcome_code |> rpair state) |
55286 | 307 |
end |
308 |
in |
|
309 |
(if blocking then launch_provers state |
|
310 |
else (Future.fork (tap (fn () => launch_provers state)); (unknownN, state))) |
|
311 |
handle TimeLimit.TimeOut => (print "Sledgehammer ran out of time."; (unknownN, state)) |
|
312 |
end |
|
313 |
|> `(fn (outcome_code, _) => outcome_code = someN)) |
|
38044 | 314 |
|
28582 | 315 |
end; |