author | blanchet |
Thu, 28 Aug 2014 16:58:27 +0200 | |
changeset 58085 | ee65e9cfe284 |
parent 58061 | 3d060f43accb |
child 58092 | 4ae52c60603a |
permissions | -rw-r--r-- |
55201 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_prover.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 |
|
41087
d7b5fd465198
split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents:
41066
diff
changeset
|
6 |
Generic prover abstraction for Sledgehammer. |
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 |
|
55201 | 9 |
signature SLEDGEHAMMER_PROVER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
sig |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53551
diff
changeset
|
11 |
type atp_failure = ATP_Proof.atp_failure |
46340 | 12 |
type stature = ATP_Problem_Generate.stature |
46320 | 13 |
type type_enc = ATP_Problem_Generate.type_enc |
51005
ce4290c33d73
eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents:
50927
diff
changeset
|
14 |
type fact = Sledgehammer_Fact.fact |
55287 | 15 |
type proof_method = Sledgehammer_Proof_Methods.proof_method |
16 |
type play_outcome = Sledgehammer_Proof_Methods.play_outcome |
|
39493
cb2208f2c07d
move SPASS's Flotter hack to "Sledgehammer_Reconstruct"
blanchet
parents:
39492
diff
changeset
|
17 |
|
58085 | 18 |
datatype mode = Auto_Try | Try | Normal | Minimize | MaSh |
43021 | 19 |
|
35969 | 20 |
type params = |
48321 | 21 |
{debug : bool, |
22 |
verbose : bool, |
|
23 |
overlord : bool, |
|
53800 | 24 |
spy : bool, |
48321 | 25 |
blocking : bool, |
26 |
provers : string list, |
|
27 |
type_enc : string option, |
|
28 |
strict : bool, |
|
29 |
lam_trans : string option, |
|
30 |
uncurried_aliases : bool option, |
|
31 |
learn : bool, |
|
32 |
fact_filter : string option, |
|
33 |
max_facts : int option, |
|
34 |
fact_thresholds : real * real, |
|
35 |
max_mono_iters : int option, |
|
36 |
max_new_mono_instances : int option, |
|
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51186
diff
changeset
|
37 |
isar_proofs : bool option, |
57783 | 38 |
compress : real option, |
57245 | 39 |
try0 : bool, |
55297
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
40 |
smt_proofs : bool option, |
48321 | 41 |
slice : bool, |
57721 | 42 |
minimize : bool, |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
43 |
timeout : Time.time, |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
44 |
preplay_timeout : Time.time, |
48321 | 45 |
expect : string} |
39493
cb2208f2c07d
move SPASS's Flotter hack to "Sledgehammer_Reconstruct"
blanchet
parents:
39492
diff
changeset
|
46 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
47 |
type prover_problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
48 |
{comment : string, |
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
49 |
state : Proof.state, |
48321 | 50 |
goal : thm, |
51 |
subgoal : int, |
|
52 |
subgoal_count : int, |
|
51010 | 53 |
factss : (string * fact list) list} |
39493
cb2208f2c07d
move SPASS's Flotter hack to "Sledgehammer_Reconstruct"
blanchet
parents:
39492
diff
changeset
|
54 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
55 |
type prover_result = |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53551
diff
changeset
|
56 |
{outcome : atp_failure option, |
51009
e8ff34a1fa9a
thread through fact triple component from which used facts come, for accurate index output
blanchet
parents:
51007
diff
changeset
|
57 |
used_facts : (string * stature) list, |
e8ff34a1fa9a
thread through fact triple component from which used facts come, for accurate index output
blanchet
parents:
51007
diff
changeset
|
58 |
used_from : fact list, |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57732
diff
changeset
|
59 |
preferred_methss : proof_method * proof_method list list, |
48321 | 60 |
run_time : Time.time, |
57750 | 61 |
message : (unit -> (string * stature) list * (proof_method * play_outcome)) -> string} |
39493
cb2208f2c07d
move SPASS's Flotter hack to "Sledgehammer_Reconstruct"
blanchet
parents:
39492
diff
changeset
|
62 |
|
57735
056a55b44ec7
eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents:
57734
diff
changeset
|
63 |
type prover = params -> prover_problem -> prover_result |
35867 | 64 |
|
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
48314
diff
changeset
|
65 |
val SledgehammerN : string |
57037 | 66 |
val str_of_mode : mode -> string |
55205 | 67 |
val overlord_file_location_of_prover : string -> string * string |
68 |
val proof_banner : mode -> string -> string |
|
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
69 |
val is_atp : theory -> string -> bool |
57742 | 70 |
val bunches_of_proof_methods : bool -> bool -> bool -> string -> proof_method list list |
48798 | 71 |
val is_fact_chained : (('a * stature) * 'b) -> bool |
57056 | 72 |
val filter_used_facts : bool -> (''a * stature) list -> ((''a * stature) * 'b) list -> |
48798 | 73 |
((''a * stature) * 'b) list |
55205 | 74 |
val repair_monomorph_context : int option -> int -> int option -> int -> Proof.context -> |
75 |
Proof.context |
|
55212 | 76 |
|
77 |
val supported_provers : Proof.context -> unit |
|
78 |
val kill_provers : unit -> unit |
|
79 |
val running_provers : unit -> unit |
|
80 |
val messages : int option -> unit |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
81 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
82 |
|
55201 | 83 |
structure Sledgehammer_Prover : SLEDGEHAMMER_PROVER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
84 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
85 |
|
57154 | 86 |
open ATP_Proof |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43063
diff
changeset
|
87 |
open ATP_Util |
57154 | 88 |
open ATP_Systems |
38028 | 89 |
open ATP_Problem |
46320 | 90 |
open ATP_Problem_Generate |
91 |
open ATP_Proof_Reconstruct |
|
45521 | 92 |
open Metis_Tactic |
51005
ce4290c33d73
eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents:
50927
diff
changeset
|
93 |
open Sledgehammer_Fact |
55287 | 94 |
open Sledgehammer_Proof_Methods |
54000
9cfff7f61d0d
added experimental configuration options to tune use of builtin symbols in SMT
blanchet
parents:
53989
diff
changeset
|
95 |
|
58085 | 96 |
(* Identifier that distinguishes Sledgehammer from other tools that could use "Async_Manager". *) |
48319
340187063d84
use async manager to manage MaSh learners to make sure they get killed cleanly
blanchet
parents:
48314
diff
changeset
|
97 |
val SledgehammerN = "Sledgehammer" |
37585 | 98 |
|
58085 | 99 |
datatype mode = Auto_Try | Try | Normal | Minimize | MaSh |
57037 | 100 |
|
101 |
fun str_of_mode Auto_Try = "Auto Try" |
|
102 |
| str_of_mode Try = "Try" |
|
103 |
| str_of_mode Normal = "Normal" |
|
58085 | 104 |
| str_of_mode Minimize = "Minimize" |
57037 | 105 |
| str_of_mode MaSh = "MaSh" |
106 |
||
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
107 |
val is_atp = member (op =) o supported_atps |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
108 |
|
35969 | 109 |
type params = |
48321 | 110 |
{debug : bool, |
111 |
verbose : bool, |
|
112 |
overlord : bool, |
|
53800 | 113 |
spy : bool, |
48321 | 114 |
blocking : bool, |
115 |
provers : string list, |
|
116 |
type_enc : string option, |
|
117 |
strict : bool, |
|
118 |
lam_trans : string option, |
|
119 |
uncurried_aliases : bool option, |
|
120 |
learn : bool, |
|
121 |
fact_filter : string option, |
|
122 |
max_facts : int option, |
|
123 |
fact_thresholds : real * real, |
|
124 |
max_mono_iters : int option, |
|
125 |
max_new_mono_instances : int option, |
|
51190
2654b3965c8d
made "isar_proofs" a 3-way option, to provide a way to totally disable isar_proofs if desired
blanchet
parents:
51186
diff
changeset
|
126 |
isar_proofs : bool option, |
57783 | 127 |
compress : real option, |
57245 | 128 |
try0 : bool, |
55297
1dfcd49f5dcb
renamed 'smt' option 'smt_proofs' to avoid clash with 'smt' prover
blanchet
parents:
55288
diff
changeset
|
129 |
smt_proofs : bool option, |
48321 | 130 |
slice : bool, |
57721 | 131 |
minimize : bool, |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
132 |
timeout : Time.time, |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
133 |
preplay_timeout : Time.time, |
48321 | 134 |
expect : string} |
35867 | 135 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
136 |
type prover_problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
137 |
{comment : string, |
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
138 |
state : Proof.state, |
48321 | 139 |
goal : thm, |
140 |
subgoal : int, |
|
141 |
subgoal_count : int, |
|
51010 | 142 |
factss : (string * fact list) list} |
35867 | 143 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
144 |
type prover_result = |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53551
diff
changeset
|
145 |
{outcome : atp_failure option, |
48321 | 146 |
used_facts : (string * stature) list, |
51009
e8ff34a1fa9a
thread through fact triple component from which used facts come, for accurate index output
blanchet
parents:
51007
diff
changeset
|
147 |
used_from : fact list, |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57732
diff
changeset
|
148 |
preferred_methss : proof_method * proof_method list list, |
48321 | 149 |
run_time : Time.time, |
57750 | 150 |
message : (unit -> (string * stature) list * (proof_method * play_outcome)) -> string} |
35867 | 151 |
|
57735
056a55b44ec7
eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents:
57734
diff
changeset
|
152 |
type prover = params -> prover_problem -> prover_result |
35867 | 153 |
|
55205 | 154 |
fun overlord_file_location_of_prover prover = (getenv "ISABELLE_HOME_USER", "prob_" ^ prover) |
41313
a96ac4d180b7
optionally supply constant weights to E -- turned off by default until properly parameterized
blanchet
parents:
41259
diff
changeset
|
155 |
|
43052
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
156 |
fun proof_banner mode name = |
55205 | 157 |
(case mode of |
43033 | 158 |
Auto_Try => "Auto Sledgehammer (" ^ quote name ^ ") found a proof" |
159 |
| Try => "Sledgehammer (" ^ quote name ^ ") found a proof" |
|
55205 | 160 |
| _ => "Try this") |
43033 | 161 |
|
57742 | 162 |
fun bunches_of_proof_methods try0 smt_proofs needs_full_types desperate_lam_trans = |
163 |
(if try0 then |
|
164 |
[[Simp_Method, Auto_Method, Blast_Method, Linarith_Method], |
|
165 |
[Meson_Method, Force_Method, Presburger_Method]] |
|
166 |
else |
|
167 |
[]) @ |
|
168 |
[[Metis_Method (if needs_full_types then SOME full_typesN else NONE, NONE)], |
|
169 |
(if needs_full_types then |
|
170 |
[Metis_Method (NONE, NONE), |
|
171 |
Metis_Method (SOME really_full_type_enc, NONE), |
|
172 |
Metis_Method (SOME full_typesN, SOME desperate_lam_trans), |
|
173 |
Metis_Method (SOME really_full_type_enc, SOME desperate_lam_trans)] |
|
174 |
else |
|
175 |
[Metis_Method (SOME full_typesN, NONE), |
|
176 |
Metis_Method (SOME no_typesN, SOME desperate_lam_trans), |
|
177 |
Metis_Method (SOME really_full_type_enc, SOME desperate_lam_trans)])] @ |
|
58061 | 178 |
(if smt_proofs then [[SMT_Method]] else []) |
43033 | 179 |
|
48798 | 180 |
fun is_fact_chained ((_, (sc, _)), _) = sc = Chained |
181 |
||
182 |
fun filter_used_facts keep_chained used = |
|
54773 | 183 |
filter ((member (op =) used o fst) orf (if keep_chained then is_fact_chained else K false)) |
43033 | 184 |
|
53480
247817dbb990
limit the number of instances of a single theorem
blanchet
parents:
53478
diff
changeset
|
185 |
val max_fact_instances = 10 (* FUDGE *) |
247817dbb990
limit the number of instances of a single theorem
blanchet
parents:
53478
diff
changeset
|
186 |
|
55205 | 187 |
fun repair_monomorph_context max_iters best_max_iters max_new_instances best_max_new_instances = |
52034
11b48e7a4e7e
correctly 'repair' the monomorphization context for SMT solvers from Sledgehammer
blanchet
parents:
52031
diff
changeset
|
188 |
Config.put Monomorph.max_rounds (max_iters |> the_default best_max_iters) |
11b48e7a4e7e
correctly 'repair' the monomorphization context for SMT solvers from Sledgehammer
blanchet
parents:
52031
diff
changeset
|
189 |
#> Config.put Monomorph.max_new_instances |
55205 | 190 |
(max_new_instances |> the_default best_max_new_instances) |
53480
247817dbb990
limit the number of instances of a single theorem
blanchet
parents:
53478
diff
changeset
|
191 |
#> Config.put Monomorph.max_thm_instances max_fact_instances |
52034
11b48e7a4e7e
correctly 'repair' the monomorphization context for SMT solvers from Sledgehammer
blanchet
parents:
52031
diff
changeset
|
192 |
|
55212 | 193 |
fun supported_provers ctxt = |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
194 |
let |
55212 | 195 |
val thy = Proof_Context.theory_of ctxt |
196 |
val (remote_provers, local_provers) = |
|
58061 | 197 |
sort_strings (supported_atps thy) @ sort_strings (SMT_Config.available_solvers_of ctxt) |
55212 | 198 |
|> List.partition (String.isPrefix remote_prefix) |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
199 |
in |
57056 | 200 |
Output.urgent_message ("Supported provers: " ^ commas (local_provers @ remote_provers) ^ ".") |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
201 |
end |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
202 |
|
55212 | 203 |
fun kill_provers () = Async_Manager.kill_threads SledgehammerN "prover" |
204 |
fun running_provers () = Async_Manager.running_threads SledgehammerN "prover" |
|
205 |
val messages = Async_Manager.thread_messages SledgehammerN "prover" |
|
206 |
||
28582 | 207 |
end; |