author | blanchet |
Wed, 15 Dec 2010 19:41:24 +0100 | |
changeset 41180 | a99bc6f3664b |
parent 41171 | 043f8dc3b51f |
child 41208 | 1b28c43a7074 |
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 |
38988 | 11 |
type relevance_override = Sledgehammer_Filter.relevance_override |
40068 | 12 |
type minimize_command = Sledgehammer_ATP_Reconstruct.minimize_command |
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
13 |
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
|
14 |
|
38044 | 15 |
val run_sledgehammer : |
39318 | 16 |
params -> bool -> int -> relevance_override -> (string -> minimize_command) |
17 |
-> Proof.state -> bool * Proof.state |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
18 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
19 |
|
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
20 |
structure Sledgehammer_Run : SLEDGEHAMMER_RUN = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
21 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
22 |
|
38023 | 23 |
open Sledgehammer_Util |
38988 | 24 |
open Sledgehammer_Filter |
40068 | 25 |
open Sledgehammer_ATP_Translate |
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
26 |
open Sledgehammer_Provers |
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
27 |
open Sledgehammer_Minimize |
40072
27f2a45b0aab
more robust handling of "remote_" vs. non-"remote_" provers
blanchet
parents:
40071
diff
changeset
|
28 |
|
41089 | 29 |
fun prover_description ctxt ({blocking, verbose, ...} : params) name num_facts i |
30 |
n goal = |
|
31 |
quote name ^ |
|
32 |
(if verbose then |
|
33 |
" with " ^ string_of_int num_facts ^ " fact" ^ plural_s num_facts |
|
34 |
else |
|
35 |
"") ^ |
|
36 |
" on " ^ (if n = 1 then "goal" else "subgoal " ^ string_of_int i) ^ ":" ^ |
|
37 |
(if blocking then |
|
38 |
"" |
|
39 |
else |
|
40 |
"\n" ^ Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i))) |
|
41 |
||
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
42 |
val implicit_minimization_threshold = 50 |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
43 |
|
41089 | 44 |
fun run_prover (params as {blocking, debug, max_relevant, timeout, expect, ...}) |
45 |
auto minimize_command only |
|
46 |
{state, goal, subgoal, subgoal_count, facts} name = |
|
47 |
let |
|
48 |
val ctxt = Proof.context_of state |
|
49 |
val birth_time = Time.now () |
|
50 |
val death_time = Time.+ (birth_time, timeout) |
|
51 |
val max_relevant = |
|
52 |
the_default (default_max_relevant_for_prover ctxt name) max_relevant |
|
53 |
val num_facts = length facts |> not only ? Integer.min max_relevant |
|
54 |
val desc = |
|
55 |
prover_description ctxt params name num_facts subgoal subgoal_count goal |
|
56 |
val prover = get_prover ctxt auto name |
|
57 |
val problem = |
|
58 |
{state = state, goal = goal, subgoal = subgoal, |
|
59 |
subgoal_count = subgoal_count, facts = take num_facts facts} |
|
60 |
fun go () = |
|
61 |
let |
|
62 |
fun really_go () = |
|
63 |
prover params (minimize_command name) problem |
|
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
64 |
|> (fn {outcome, used_facts, message, ...} => |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
65 |
if is_some outcome then |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
66 |
("none", message) |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
67 |
else |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
68 |
("some", |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
69 |
if length used_facts >= implicit_minimization_threshold then |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
70 |
minimize_facts params true subgoal subgoal_count state |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
71 |
(filter_used_facts used_facts |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
72 |
(map (apsnd single o untranslated_fact) facts)) |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
73 |
|> snd |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
74 |
else |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
75 |
message)) |
41089 | 76 |
val (outcome_code, message) = |
77 |
if debug then |
|
78 |
really_go () |
|
79 |
else |
|
80 |
(really_go () |
|
81 |
handle ERROR message => ("unknown", "Error: " ^ message ^ "\n") |
|
82 |
| exn => |
|
83 |
if Exn.is_interrupt exn then |
|
84 |
reraise exn |
|
85 |
else |
|
86 |
("unknown", "Internal error:\n" ^ |
|
87 |
ML_Compiler.exn_message exn ^ "\n")) |
|
88 |
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
|
89 |
(* 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
|
90 |
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
|
91 |
machine. *) |
43e2b051339c
weaken the "expect" flag so that it doesn't trigger errors if a prover is not installed
blanchet
parents:
41138
diff
changeset
|
92 |
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
|
93 |
not (is_prover_installed ctxt name) then |
41089 | 94 |
() |
95 |
else if blocking then |
|
96 |
error ("Unexpected outcome: " ^ quote outcome_code ^ ".") |
|
97 |
else |
|
98 |
warning ("Unexpected outcome: " ^ quote outcome_code ^ "."); |
|
99 |
in (outcome_code = "some", message) end |
|
100 |
in |
|
101 |
if auto then |
|
102 |
let val (success, message) = TimeLimit.timeLimit timeout go () in |
|
103 |
(success, state |> success ? Proof.goal_message (fn () => |
|
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
104 |
Pretty.chunks [Pretty.str "", |
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
105 |
Pretty.mark Markup.hilite (Pretty.str message)])) |
41089 | 106 |
end |
107 |
else if blocking then |
|
108 |
let val (success, message) = TimeLimit.timeLimit timeout go () in |
|
109 |
List.app Output.urgent_message |
|
110 |
(Async_Manager.break_into_chunks [desc ^ "\n" ^ message]); |
|
111 |
(success, state) |
|
112 |
end |
|
113 |
else |
|
114 |
(Async_Manager.launch das_Tool birth_time death_time desc (snd o go); |
|
115 |
(false, state)) |
|
116 |
end |
|
117 |
||
40698 | 118 |
(* FUDGE *) |
119 |
val auto_max_relevant_divisor = 2 |
|
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
120 |
|
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41091
diff
changeset
|
121 |
fun run_sledgehammer (params as {blocking, debug, provers, type_sys, |
40069 | 122 |
relevance_thresholds, max_relevant, ...}) |
39366
f58fbb959826
handle relevance filter corner cases more gracefully;
blanchet
parents:
39364
diff
changeset
|
123 |
auto i (relevance_override as {only, ...}) minimize_command |
f58fbb959826
handle relevance filter corner cases more gracefully;
blanchet
parents:
39364
diff
changeset
|
124 |
state = |
40059
6ad9081665db
use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents:
39494
diff
changeset
|
125 |
if null provers then |
6ad9081665db
use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents:
39494
diff
changeset
|
126 |
error "No prover is set." |
39318 | 127 |
else case subgoal_count state of |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
40114
diff
changeset
|
128 |
0 => (Output.urgent_message "No subgoal!"; (false, state)) |
39318 | 129 |
| n => |
130 |
let |
|
39364 | 131 |
val _ = Proof.assert_backward state |
40200 | 132 |
val ctxt = Proof.context_of state |
133 |
val {facts = chained_ths, goal, ...} = Proof.goal state |
|
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
134 |
val (_, hyp_ts, concl_t) = strip_subgoal goal i |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41091
diff
changeset
|
135 |
val no_dangerous_types = types_dangerous_types type_sys |
40059
6ad9081665db
use consistent terminology in Sledgehammer: "prover = ATP or SMT solver or ..."
blanchet
parents:
39494
diff
changeset
|
136 |
val _ = () |> not blocking ? kill_provers |
40941
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40723
diff
changeset
|
137 |
val _ = case find_first (not o is_prover_available ctxt) provers of |
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40723
diff
changeset
|
138 |
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
|
139 |
| NONE => () |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
40114
diff
changeset
|
140 |
val _ = if auto then () else Output.urgent_message "Sledgehammering..." |
40941
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40723
diff
changeset
|
141 |
val (smts, atps) = provers |> List.partition (is_smt_prover ctxt) |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41091
diff
changeset
|
142 |
fun run_provers label no_dangerous_types relevance_fudge maybe_translate |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41091
diff
changeset
|
143 |
provers (res as (success, state)) = |
40065 | 144 |
if success orelse null provers then |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
145 |
res |
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
146 |
else |
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
147 |
let |
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
148 |
val max_max_relevant = |
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
149 |
case max_relevant of |
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
150 |
SOME n => n |
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
151 |
| NONE => |
40941
a3e6f8634a11
replace "smt" prover with specific SMT solvers, e.g. "z3" -- whatever the SMT module gives us
blanchet
parents:
40723
diff
changeset
|
152 |
0 |> fold (Integer.max o default_max_relevant_for_prover ctxt) |
40065 | 153 |
provers |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
154 |
|> auto ? (fn n => n div auto_max_relevant_divisor) |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40341
diff
changeset
|
155 |
val is_built_in_const = |
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40341
diff
changeset
|
156 |
is_built_in_const_for_prover ctxt (hd provers) |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40202
diff
changeset
|
157 |
val facts = |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41091
diff
changeset
|
158 |
relevant_facts ctxt no_dangerous_types relevance_thresholds |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40341
diff
changeset
|
159 |
max_max_relevant is_built_in_const relevance_fudge |
40071
658a37c80b53
generalized the relevance filter so that it takes the list of "irrelevant constants" as argument (since the ATP and SMT preprocessing are different)
blanchet
parents:
40070
diff
changeset
|
160 |
relevance_override chained_ths hyp_ts concl_t |
40114 | 161 |
|> map maybe_translate |
40062 | 162 |
val problem = |
40065 | 163 |
{state = state, goal = goal, subgoal = i, subgoal_count = n, |
40983 | 164 |
facts = facts} |
165 |
val run_prover = run_prover params auto minimize_command only |
|
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
166 |
in |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
167 |
if debug then |
40370 | 168 |
Output.urgent_message (label ^ plural_s (length provers) ^ ": " ^ |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
169 |
(if null facts then |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
170 |
"Found no relevant facts." |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
171 |
else |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
172 |
"Including (up to) " ^ string_of_int (length facts) ^ |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
173 |
" relevant fact" ^ plural_s (length facts) ^ ":\n" ^ |
41091
0afdf5cde874
implicitly call the minimizer for SMT solvers that don't return an unsat core
blanchet
parents:
41090
diff
changeset
|
174 |
(facts |> map (fst o fst o untranslated_fact) |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
175 |
|> space_implode " ") ^ ".")) |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
176 |
else |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
177 |
(); |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
178 |
if auto then |
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
179 |
fold (fn prover => fn (true, state) => (true, state) |
40064
db8413d82c3b
got rid of duplicate functionality ("run_smt_solver_somehow");
blanchet
parents:
40063
diff
changeset
|
180 |
| (false, _) => run_prover problem prover) |
40065 | 181 |
provers (false, state) |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
182 |
else |
41171 | 183 |
provers |
184 |
|> (if blocking andalso length provers > 1 then Par_List.map |
|
185 |
else map) |
|
186 |
(run_prover problem) |
|
187 |
|> exists fst |> rpair state |
|
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
188 |
end |
40071
658a37c80b53
generalized the relevance filter so that it takes the list of "irrelevant constants" as argument (since the ATP and SMT preprocessing are different)
blanchet
parents:
40070
diff
changeset
|
189 |
val run_atps = |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41091
diff
changeset
|
190 |
run_provers "ATP" no_dangerous_types atp_relevance_fudge |
41090 | 191 |
(ATP_Translated_Fact o translate_atp_fact ctxt) atps |
40071
658a37c80b53
generalized the relevance filter so that it takes the list of "irrelevant constants" as argument (since the ATP and SMT preprocessing are different)
blanchet
parents:
40070
diff
changeset
|
192 |
val run_smts = |
41090 | 193 |
run_provers "SMT solver" true smt_relevance_fudge Untranslated_Fact smts |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
194 |
fun run_atps_and_smt_solvers () = |
40065 | 195 |
[run_atps, run_smts] |> Par_List.map (fn f => f (false, state) |> K ()) |
41180
a99bc6f3664b
make sure errors generated in a thread don't vanish in cyberspace (e.g., when invoking Sledgehammer with unknown facts)
blanchet
parents:
41171
diff
changeset
|
196 |
handle ERROR msg => (Output.urgent_message ("Error: " ^ msg); error msg) |
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
197 |
in |
40065 | 198 |
(false, state) |
199 |
|> (if blocking then run_atps #> not auto ? run_smts |
|
200 |
else (fn p => Future.fork (tap run_atps_and_smt_solvers) |> K p)) |
|
40060
5ef6747aa619
first step in adding support for an SMT backend to Sledgehammer
blanchet
parents:
40059
diff
changeset
|
201 |
end |
38044 | 202 |
|
28582 | 203 |
end; |