author | blanchet |
Sun, 13 Jan 2013 21:42:38 +0100 | |
changeset 50866 | e12ebcb859a7 |
parent 50749 | 82dee320d340 |
child 50876 | e6317e8b11db |
permissions | -rw-r--r-- |
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_run.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 |
|
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
9 |
signature SLEDGEHAMMER_RUN = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
sig |
48292 | 11 |
type fact_override = Sledgehammer_Fact.fact_override |
49914 | 12 |
type minimize_command = Sledgehammer_Reconstruct.minimize_command |
43021 | 13 |
type mode = Sledgehammer_Provers.mode |
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
14 |
type params = Sledgehammer_Provers.params |
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
15 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
16 |
val someN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
17 |
val noneN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
18 |
val timeoutN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
19 |
val unknownN : string |
38044 | 20 |
val run_sledgehammer : |
48292 | 21 |
params -> mode -> int -> fact_override |
45520 | 22 |
-> ((string * string list) list -> string -> minimize_command) |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
23 |
-> Proof.state -> bool * (string * Proof.state) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
24 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
25 |
|
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
26 |
structure Sledgehammer_Run : SLEDGEHAMMER_RUN = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
27 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
28 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43064
diff
changeset
|
29 |
open ATP_Util |
46320 | 30 |
open ATP_Problem_Generate |
31 |
open ATP_Proof_Reconstruct |
|
38023 | 32 |
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
|
33 |
open Sledgehammer_Fact |
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
34 |
open Sledgehammer_Provers |
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
35 |
open Sledgehammer_Minimize |
48381 | 36 |
open Sledgehammer_MaSh |
40072
27f2a45b0aab
more robust handling of "remote_" vs. non-"remote_" provers
blanchet
parents:
40071
diff
changeset
|
37 |
|
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
38 |
val someN = "some" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
39 |
val noneN = "none" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
40 |
val timeoutN = "timeout" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
41 |
val unknownN = "unknown" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
42 |
|
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
43 |
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
|
44 |
|
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
45 |
fun max_outcome_code codes = |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
46 |
NONE |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
47 |
|> fold (fn candidate => |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
48 |
fn accum as SOME _ => accum |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
49 |
| NONE => if member (op =) codes candidate then SOME candidate |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
50 |
else NONE) |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
51 |
ordered_outcome_codes |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
52 |
|> the_default unknownN |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
53 |
|
41208
1b28c43a7074
make "debug" imply "blocking", since in blocking mode the exceptions flow through and are more instructive
blanchet
parents:
41180
diff
changeset
|
54 |
fun prover_description ctxt ({verbose, blocking, ...} : params) name num_facts i |
41089 | 55 |
n goal = |
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
48299
diff
changeset
|
56 |
(quote name, |
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
57 |
(if verbose then |
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
58 |
" with " ^ string_of_int num_facts ^ " fact" ^ plural_s num_facts |
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
59 |
else |
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
60 |
"") ^ |
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
61 |
" on " ^ (if n = 1 then "goal" else "subgoal " ^ string_of_int i) ^ |
45379
0147a4348ca1
try "smt" as a fallback for ATPs if "metis" fails/times out
blanchet
parents:
45370
diff
changeset
|
62 |
(if blocking then "." |
0147a4348ca1
try "smt" as a fallback for ATPs if "metis" fails/times out
blanchet
parents:
45370
diff
changeset
|
63 |
else "\n" ^ Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i)))) |
41089 | 64 |
|
48293 | 65 |
fun launch_prover (params as {debug, verbose, blocking, max_facts, slice, |
43059 | 66 |
timeout, expect, ...}) |
48407 | 67 |
mode minimize_command only learn |
68 |
{state, goal, subgoal, subgoal_count, facts} name = |
|
41089 | 69 |
let |
70 |
val ctxt = Proof.context_of state |
|
50749
82dee320d340
increased hard timeout -- minimization can take time
blanchet
parents:
50669
diff
changeset
|
71 |
val hard_timeout = time_mult 3.0 (timeout |> the_default one_day) |
41089 | 72 |
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
|
73 |
val death_time = Time.+ (birth_time, hard_timeout) |
48293 | 74 |
val max_facts = |
75 |
max_facts |> the_default (default_max_facts_for_prover ctxt slice name) |
|
76 |
val num_facts = length facts |> not only ? Integer.min max_facts |
|
43006 | 77 |
fun desc () = |
41089 | 78 |
prover_description ctxt params name num_facts subgoal subgoal_count goal |
79 |
val problem = |
|
47904
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
80 |
{state = state, goal = goal, subgoal = subgoal, |
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
81 |
subgoal_count = subgoal_count, |
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
82 |
facts = facts |
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
83 |
|> not (Sledgehammer_Provers.is_ho_atp ctxt name) |
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
84 |
? filter_out (curry (op =) Induction o snd o snd o fst |
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
85 |
o untranslated_fact) |
67663c968d70
distinguish between instantiated and uninstantiated inductions -- the latter are OK for first-order provers
blanchet
parents:
47531
diff
changeset
|
86 |
|> take num_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
|
87 |
fun print_used_facts used_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
|
88 |
tag_list 1 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
|
89 |
|> map (fn (j, fact) => fact |> untranslated_fact |> apsnd (K j)) |
48798 | 90 |
|> 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
|
91 |
|> 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
|
92 |
|> 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
|
93 |
|> 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
|
94 |
" 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
|
95 |
|> Output.urgent_message |
41255
a80024d7b71b
added debugging option to find out how good the relevance filter was at identifying relevant facts
blanchet
parents:
41245
diff
changeset
|
96 |
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
|
97 |
problem |
50668 | 98 |
|> get_minimizing_isar_prover ctxt mode learn name params minimize_command |
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
|
99 |
|> verbose ? tap (fn {outcome = NONE, used_facts as _ :: _, ...} => |
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48384
diff
changeset
|
100 |
print_used_facts used_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
|
101 |
| _ => ()) |
43261
a4aeb26a6362
make sure that the message tail (timing + TPTP important message) is preserved upon automatic minimization
blanchet
parents:
43233
diff
changeset
|
102 |
|> (fn {outcome, preplay, message, message_tail, ...} => |
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
103 |
(if outcome = SOME ATP_Proof.TimedOut then timeoutN |
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
104 |
else if is_some outcome then noneN |
50669
84c7cf36b2e0
use "Lazy" to simplify control flow a bit and guarantee single evaluation (at most)
blanchet
parents:
50668
diff
changeset
|
105 |
else someN, fn () => message (Lazy.force preplay) ^ message_tail)) |
41089 | 106 |
fun go () = |
107 |
let |
|
108 |
val (outcome_code, message) = |
|
109 |
if debug then |
|
110 |
really_go () |
|
111 |
else |
|
112 |
(really_go () |
|
43052
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
113 |
handle ERROR msg => (unknownN, fn () => "Error: " ^ msg ^ "\n") |
41089 | 114 |
| exn => |
115 |
if Exn.is_interrupt exn then |
|
116 |
reraise exn |
|
117 |
else |
|
43052
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
118 |
(unknownN, fn () => "Internal error:\n" ^ |
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
119 |
ML_Compiler.exn_message exn ^ "\n")) |
41089 | 120 |
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
|
121 |
(* 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
|
122 |
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
|
123 |
machine. *) |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
124 |
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
|
125 |
not (is_prover_installed ctxt name) then |
41089 | 126 |
() |
127 |
else if blocking then |
|
128 |
error ("Unexpected outcome: " ^ quote outcome_code ^ ".") |
|
129 |
else |
|
130 |
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
|
131 |
in (outcome_code, message) end |
41089 | 132 |
in |
43021 | 133 |
if mode = Auto_Try then |
50557 | 134 |
let val (outcome_code, message) = time_limit timeout go () in |
43006 | 135 |
(outcome_code, |
136 |
state |
|
137 |
|> outcome_code = someN |
|
138 |
? Proof.goal_message (fn () => |
|
139 |
[Pretty.str "", |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49914
diff
changeset
|
140 |
Pretty.mark Markup.intensify (Pretty.str (message ()))] |
43006 | 141 |
|> Pretty.chunks)) |
41089 | 142 |
end |
143 |
else if blocking then |
|
43006 | 144 |
let |
145 |
val (outcome_code, message) = TimeLimit.timeLimit hard_timeout go () |
|
146 |
in |
|
43058
5f8bac7a2945
minimize automatically even if Metis failed, if the external prover was really fast
blanchet
parents:
43052
diff
changeset
|
147 |
(if outcome_code = someN orelse mode = Normal then |
5f8bac7a2945
minimize automatically even if Metis failed, if the external prover was really fast
blanchet
parents:
43052
diff
changeset
|
148 |
quote name ^ ": " ^ message () |
5f8bac7a2945
minimize automatically even if Metis failed, if the external prover was really fast
blanchet
parents:
43052
diff
changeset
|
149 |
else |
5f8bac7a2945
minimize automatically even if Metis failed, if the external prover was really fast
blanchet
parents:
43052
diff
changeset
|
150 |
"") |
43005
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
151 |
|> Async_Manager.break_into_chunks |
c96f06bffd90
merge timeout messages from several ATPs into one message to avoid clutter
blanchet
parents:
43004
diff
changeset
|
152 |
|> List.app Output.urgent_message; |
43006 | 153 |
(outcome_code, state) |
41089 | 154 |
end |
155 |
else |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
48299
diff
changeset
|
156 |
(Async_Manager.launch SledgehammerN birth_time death_time (desc ()) |
43052
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
157 |
((fn (outcome_code, message) => |
43059 | 158 |
(verbose orelse outcome_code = someN, |
159 |
message ())) o go); |
|
43006 | 160 |
(unknownN, state)) |
41089 | 161 |
end |
162 |
||
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
163 |
fun class_of_smt_solver ctxt name = |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
164 |
ctxt |> select_smt_solver name |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
165 |
|> SMT_Config.solver_class_of |> SMT_Utils.string_of_class |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
166 |
|
48293 | 167 |
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
|
168 |
|
48293 | 169 |
fun run_sledgehammer (params as {debug, verbose, blocking, provers, max_facts, |
170 |
slice, ...}) |
|
48292 | 171 |
mode 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
|
172 |
if null provers then |
6ad9081665db
use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents:
39494
diff
changeset
|
173 |
error "No prover is set." |
39318 | 174 |
else case subgoal_count state of |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
175 |
0 => (Output.urgent_message "No subgoal!"; (false, (noneN, state))) |
39318 | 176 |
| n => |
177 |
let |
|
39364 | 178 |
val _ = Proof.assert_backward state |
43021 | 179 |
val print = if mode = Normal then Output.urgent_message else K () |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
180 |
val state = |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
181 |
state |> Proof.map_context (Config.put SMT_Config.verbose debug) |
40200 | 182 |
val ctxt = Proof.context_of state |
48396 | 183 |
val {facts = chained, goal, ...} = Proof.goal state |
43004
20e9caff1f86
fix soundness bug in Sledgehammer: distinguish params in goals from fixed variables in context
blanchet
parents:
42968
diff
changeset
|
184 |
val (_, hyp_ts, concl_t) = strip_subgoal ctxt goal i |
44625 | 185 |
val ho_atp = exists (Sledgehammer_Provers.is_ho_atp ctxt) provers |
48299 | 186 |
val reserved = reserved_isar_keyword_table () |
48396 | 187 |
val css = clasimpset_rule_table_of ctxt |
48407 | 188 |
val all_facts = |
48396 | 189 |
nearly_all_facts ctxt ho_atp fact_override reserved css chained hyp_ts |
190 |
concl_t |
|
44586 | 191 |
val _ = () |> not blocking ? kill_provers |
41727
ab3f6d76fb23
available_provers ~> supported_provers (for clarity)
blanchet
parents:
41432
diff
changeset
|
192 |
val _ = case find_first (not o is_prover_supported ctxt) provers of |
40941
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40723
diff
changeset
|
193 |
SOME name => error ("No such prover: " ^ name ^ ".") |
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40723
diff
changeset
|
194 |
| NONE => () |
41773 | 195 |
val _ = print "Sledgehammering..." |
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
196 |
val (smts, (ueq_atps, full_atps)) = |
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
197 |
provers |> List.partition (is_smt_prover ctxt) |
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
198 |
||> List.partition (is_unit_equational_atp ctxt) |
47531
7fe7c7419489
get rid of minor optimization that caused strange problems and was hard to debug (and apparently saved less than 100 ms on a 30 s run)
blanchet
parents:
47148
diff
changeset
|
199 |
fun launch_provers state get_facts translate provers = |
41256
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
200 |
let |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
201 |
val facts = get_facts () |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
202 |
val num_facts = length facts |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
203 |
val facts = facts ~~ (0 upto num_facts - 1) |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
204 |
|> map (translate num_facts) |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
205 |
val problem = |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
206 |
{state = state, goal = goal, subgoal = i, subgoal_count = n, |
47531
7fe7c7419489
get rid of minor optimization that caused strange problems and was hard to debug (and apparently saved less than 100 ms on a 30 s run)
blanchet
parents:
47148
diff
changeset
|
207 |
facts = facts} |
48407 | 208 |
fun learn prover = |
209 |
mash_learn_proof ctxt params prover (prop_of goal) all_facts |
|
210 |
val launch = launch_prover params mode minimize_command only learn |
|
41256
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
211 |
in |
43021 | 212 |
if mode = Auto_Try orelse mode = Try then |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
213 |
(unknownN, state) |
43021 | 214 |
|> fold (fn prover => fn accum as (outcome_code, _) => |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
215 |
if outcome_code = someN then accum |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
216 |
else launch problem prover) |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
217 |
provers |
41256
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
218 |
else |
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
219 |
provers |
46892 | 220 |
|> (if blocking then Par_List.map else map) |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
221 |
(launch problem #> fst) |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
222 |
|> max_outcome_code |> rpair state |
41256
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
223 |
end |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48250
diff
changeset
|
224 |
fun get_facts label is_appropriate_prop provers = |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
225 |
let |
48293 | 226 |
val max_max_facts = |
227 |
case max_facts of |
|
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
228 |
SOME n => n |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
229 |
| NONE => |
48293 | 230 |
0 |> fold (Integer.max o default_max_facts_for_prover ctxt slice) |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
231 |
provers |
48293 | 232 |
|> mode = Auto_Try ? (fn n => n div auto_try_max_facts_divisor) |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
233 |
in |
48407 | 234 |
all_facts |
43351
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
235 |
|> (case is_appropriate_prop of |
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
236 |
SOME is_app => filter (is_app o prop_of o snd) |
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
237 |
| NONE => I) |
48293 | 238 |
|> relevant_facts ctxt params (hd provers) max_max_facts fact_override |
239 |
hyp_ts concl_t |
|
48289 | 240 |
|> map (apfst (apfst (fn name => name ()))) |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
241 |
|> tap (fn 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
|
242 |
if verbose then |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
243 |
label ^ plural_s (length provers) ^ ": " ^ |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
244 |
(if null facts then |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
245 |
"Found no relevant facts." |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
246 |
else |
50866 | 247 |
"Including " ^ string_of_int (length facts) ^ |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
248 |
" relevant fact" ^ plural_s (length facts) ^ ":\n" ^ |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
249 |
(facts |> map (fst o fst) |> space_implode " ") ^ ".") |
41773 | 250 |
|
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
251 |
else |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
252 |
()) |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
253 |
end |
42952
96f62b77748f
tuning -- the "appropriate" terminology is inspired from TPTP
blanchet
parents:
42946
diff
changeset
|
254 |
fun launch_atps label is_appropriate_prop atps accum = |
42946 | 255 |
if null atps then |
41256
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
256 |
accum |
43351
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
257 |
else if is_some is_appropriate_prop andalso |
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
258 |
not (the is_appropriate_prop concl_t) then |
42946 | 259 |
(if verbose orelse length atps = length provers then |
260 |
"Goal outside the scope of " ^ |
|
261 |
space_implode " " (serial_commas "and" (map quote atps)) ^ "." |
|
262 |
|> Output.urgent_message |
|
263 |
else |
|
264 |
(); |
|
265 |
accum) |
|
41256
0e7d45cc005f
put the SMT weights back where they belong, so that they're also used by Mirabelle
blanchet
parents:
41255
diff
changeset
|
266 |
else |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48250
diff
changeset
|
267 |
launch_provers state (get_facts label is_appropriate_prop o K atps) |
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48250
diff
changeset
|
268 |
(K (Untranslated_Fact o fst)) atps |
41746
e590971528b2
run all provers in blocking mode, even if a proof was already found -- this behavior is less confusing to the user
blanchet
parents:
41743
diff
changeset
|
269 |
fun launch_smts accum = |
e590971528b2
run all provers in blocking mode, even if a proof was already found -- this behavior is less confusing to the user
blanchet
parents:
41743
diff
changeset
|
270 |
if null smts then |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
271 |
accum |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
272 |
else |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
273 |
let |
48288
255c6e1fd505
rationalize relevance filter, slowing moving code from Iter to MaSh
blanchet
parents:
48250
diff
changeset
|
274 |
val facts = get_facts "SMT solver" NONE smts |
42646
4781fcd53572
replaced some Unsynchronized.refs with Config.Ts
blanchet
parents:
42642
diff
changeset
|
275 |
val weight = SMT_Weighted_Fact oo weight_smt_fact ctxt |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
276 |
in |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
277 |
smts |> map (`(class_of_smt_solver ctxt)) |
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
278 |
|> AList.group (op =) |
47531
7fe7c7419489
get rid of minor optimization that caused strange problems and was hard to debug (and apparently saved less than 100 ms on a 30 s run)
blanchet
parents:
47148
diff
changeset
|
279 |
|> map (snd #> launch_provers state (K facts) weight #> fst) |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
280 |
|> max_outcome_code |> rpair state |
41242
8edeb1dbbc76
run the SMT relevance filter only once, then run the normalization/monomorphization code once _per class_ of SMT solvers
blanchet
parents:
41208
diff
changeset
|
281 |
end |
43351
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
282 |
val launch_full_atps = launch_atps "ATP" NONE full_atps |
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
283 |
val launch_ueq_atps = |
43351
b19d95b4d736
compute the set of base facts only once (instead of three times in parallel) -- this saves about .5 s of CPU time, albeit much less clock wall time
blanchet
parents:
43306
diff
changeset
|
284 |
launch_atps "Unit equational provers" (SOME is_unit_equality) ueq_atps |
41262
095ecb0c687f
factored out running a prover with (optionally) an implicit minimizer phrase
blanchet
parents:
41260
diff
changeset
|
285 |
fun launch_atps_and_smt_solvers () = |
43043
1406f6fc5dc3
normalize indices in chained facts to make sure that backtick facts (which often result in different names) are recognized + changed definition of urgent messages
blanchet
parents:
43037
diff
changeset
|
286 |
[launch_full_atps, launch_smts, launch_ueq_atps] |
46892 | 287 |
|> Par_List.map (fn f => ignore (f (unknownN, state))) |
41773 | 288 |
handle ERROR msg => (print ("Error: " ^ msg); error msg) |
43021 | 289 |
fun maybe f (accum as (outcome_code, _)) = |
290 |
accum |> (mode = Normal orelse outcome_code <> someN) ? f |
|
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
291 |
in |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
292 |
(unknownN, state) |
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
293 |
|> (if blocking then |
43021 | 294 |
launch_full_atps |
295 |
#> mode <> Auto_Try ? (maybe launch_ueq_atps #> maybe launch_smts) |
|
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
296 |
else |
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42850
diff
changeset
|
297 |
(fn p => Future.fork (tap launch_atps_and_smt_solvers) |> K p)) |
41773 | 298 |
handle TimeLimit.TimeOut => |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
299 |
(print "Sledgehammer ran out of time."; (unknownN, state)) |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
300 |
end |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43006
diff
changeset
|
301 |
|> `(fn (outcome_code, _) => outcome_code = someN) |
38044 | 302 |
|
28582 | 303 |
end; |