author | desharna |
Tue, 01 Dec 2020 15:29:54 +0100 | |
changeset 72798 | e732c98b02e6 |
parent 72518 | 4be6ae020fc4 |
child 73939 | 9231ea46e041 |
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 |
provers : string list, |
26 |
type_enc : string option, |
|
27 |
strict : bool, |
|
28 |
lam_trans : string option, |
|
29 |
uncurried_aliases : bool option, |
|
30 |
learn : bool, |
|
31 |
fact_filter : string option, |
|
32 |
max_facts : int option, |
|
33 |
fact_thresholds : real * real, |
|
34 |
max_mono_iters : int option, |
|
35 |
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
|
36 |
isar_proofs : bool option, |
57783 | 37 |
compress : real option, |
57245 | 38 |
try0 : bool, |
71931
0c8a9c028304
simplified 'smt_proofs' option to be a binary option (instead of ternary), now that SMT proofs are accepted in the AFP (done with Martin Desharnais)
blanchet
parents:
63692
diff
changeset
|
39 |
smt_proofs : bool, |
48321 | 40 |
slice : bool, |
57721 | 41 |
minimize : bool, |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
42 |
timeout : Time.time, |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
43 |
preplay_timeout : Time.time, |
48321 | 44 |
expect : string} |
39493
cb2208f2c07d
move SPASS's Flotter hack to "Sledgehammer_Reconstruct"
blanchet
parents:
39492
diff
changeset
|
45 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
46 |
type prover_problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
47 |
{comment : string, |
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
48 |
state : Proof.state, |
48321 | 49 |
goal : thm, |
50 |
subgoal : int, |
|
51 |
subgoal_count : int, |
|
62735 | 52 |
factss : (string * fact list) list, |
53 |
found_proof : unit -> unit} |
|
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 |
72518
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
70 |
val bunches_of_proof_methods : Proof.context -> bool -> bool -> bool -> string -> |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
71 |
proof_method list list |
48798 | 72 |
val is_fact_chained : (('a * stature) * 'b) -> bool |
57056 | 73 |
val filter_used_facts : bool -> (''a * stature) list -> ((''a * stature) * 'b) list -> |
48798 | 74 |
((''a * stature) * 'b) list |
55205 | 75 |
val repair_monomorph_context : int option -> int -> int option -> int -> Proof.context -> |
76 |
Proof.context |
|
55212 | 77 |
val supported_provers : Proof.context -> unit |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
78 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
79 |
|
55201 | 80 |
structure Sledgehammer_Prover : SLEDGEHAMMER_PROVER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
81 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
82 |
|
57154 | 83 |
open ATP_Proof |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43063
diff
changeset
|
84 |
open ATP_Util |
38028 | 85 |
open ATP_Problem |
46320 | 86 |
open ATP_Problem_Generate |
87 |
open ATP_Proof_Reconstruct |
|
45521 | 88 |
open Metis_Tactic |
51005
ce4290c33d73
eliminated needless speed optimization -- and simplified code quite a bit
blanchet
parents:
50927
diff
changeset
|
89 |
open Sledgehammer_Fact |
55287 | 90 |
open Sledgehammer_Proof_Methods |
72400 | 91 |
open Sledgehammer_ATP_Systems |
54000
9cfff7f61d0d
added experimental configuration options to tune use of builtin symbols in SMT
blanchet
parents:
53989
diff
changeset
|
92 |
|
58085 | 93 |
(* 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
|
94 |
val SledgehammerN = "Sledgehammer" |
37585 | 95 |
|
58085 | 96 |
datatype mode = Auto_Try | Try | Normal | Minimize | MaSh |
57037 | 97 |
|
98 |
fun str_of_mode Auto_Try = "Auto Try" |
|
99 |
| str_of_mode Try = "Try" |
|
100 |
| str_of_mode Normal = "Normal" |
|
58085 | 101 |
| str_of_mode Minimize = "Minimize" |
57037 | 102 |
| str_of_mode MaSh = "MaSh" |
103 |
||
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
104 |
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
|
105 |
|
35969 | 106 |
type params = |
48321 | 107 |
{debug : bool, |
108 |
verbose : bool, |
|
109 |
overlord : bool, |
|
53800 | 110 |
spy : bool, |
48321 | 111 |
provers : string list, |
112 |
type_enc : string option, |
|
113 |
strict : bool, |
|
114 |
lam_trans : string option, |
|
115 |
uncurried_aliases : bool option, |
|
116 |
learn : bool, |
|
117 |
fact_filter : string option, |
|
118 |
max_facts : int option, |
|
119 |
fact_thresholds : real * real, |
|
120 |
max_mono_iters : int option, |
|
121 |
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
|
122 |
isar_proofs : bool option, |
57783 | 123 |
compress : real option, |
57245 | 124 |
try0 : bool, |
71931
0c8a9c028304
simplified 'smt_proofs' option to be a binary option (instead of ternary), now that SMT proofs are accepted in the AFP (done with Martin Desharnais)
blanchet
parents:
63692
diff
changeset
|
125 |
smt_proofs : bool, |
48321 | 126 |
slice : bool, |
57721 | 127 |
minimize : bool, |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
128 |
timeout : Time.time, |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54815
diff
changeset
|
129 |
preplay_timeout : Time.time, |
48321 | 130 |
expect : string} |
35867 | 131 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
132 |
type prover_problem = |
54141
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
133 |
{comment : string, |
f57f8e7a879f
generate a comment storing the goal nickname in "learn_prover"
blanchet
parents:
54126
diff
changeset
|
134 |
state : Proof.state, |
48321 | 135 |
goal : thm, |
136 |
subgoal : int, |
|
137 |
subgoal_count : int, |
|
62735 | 138 |
factss : (string * fact list) list, |
139 |
found_proof : unit -> unit} |
|
35867 | 140 |
|
40061
71cc5aac8b76
generalization of the Sledgehammer minimizer, to make it possible to handle SMT solvers as well
blanchet
parents:
40060
diff
changeset
|
141 |
type prover_result = |
53586
bd5fa6425993
prefixed types and some functions with "atp_" for disambiguation
blanchet
parents:
53551
diff
changeset
|
142 |
{outcome : atp_failure option, |
48321 | 143 |
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
|
144 |
used_from : fact list, |
57734
18bb3e1ff6f6
rationalized preplaying by eliminating (now superfluous) laziness
blanchet
parents:
57732
diff
changeset
|
145 |
preferred_methss : proof_method * proof_method list list, |
48321 | 146 |
run_time : Time.time, |
57750 | 147 |
message : (unit -> (string * stature) list * (proof_method * play_outcome)) -> string} |
35867 | 148 |
|
57735
056a55b44ec7
eliminated Sledgehammer's "min" subcommand (and lots of complications in the code)
blanchet
parents:
57734
diff
changeset
|
149 |
type prover = params -> prover_problem -> prover_result |
35867 | 150 |
|
55205 | 151 |
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
|
152 |
|
43052
8d6a4978cc65
automatically minimize with Metis when this can be done within a few seconds
blanchet
parents:
43051
diff
changeset
|
153 |
fun proof_banner mode name = |
55205 | 154 |
(case mode of |
43033 | 155 |
Auto_Try => "Auto Sledgehammer (" ^ quote name ^ ") found a proof" |
156 |
| Try => "Sledgehammer (" ^ quote name ^ ") found a proof" |
|
55205 | 157 |
| _ => "Try this") |
43033 | 158 |
|
72518
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
159 |
fun bunches_of_proof_methods ctxt try0 smt_proofs needs_full_types desperate_lam_trans = |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
160 |
let |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
161 |
val try0_methodss = |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
162 |
if try0 then |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
163 |
[[Simp_Method, Auto_Method, Blast_Method, Linarith_Method, Meson_Method, |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
164 |
Metis_Method (NONE, NONE), Fastforce_Method, Force_Method, Presburger_Method]] |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
165 |
else |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
166 |
[] |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
167 |
|
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
168 |
val metis_methods = |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
169 |
(if try0 then [] else [Metis_Method (NONE, NONE)]) @ |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
170 |
Metis_Method (SOME full_typesN, NONE) :: |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
171 |
Metis_Method (SOME really_full_type_enc, SOME desperate_lam_trans) :: |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
172 |
(if needs_full_types then |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
173 |
[Metis_Method (SOME really_full_type_enc, NONE), |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
174 |
Metis_Method (SOME full_typesN, SOME desperate_lam_trans)] |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
175 |
else |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
176 |
[Metis_Method (SOME no_typesN, SOME desperate_lam_trans)]) |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
177 |
|
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
178 |
val smt_methodss = |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
179 |
if smt_proofs then |
72798
e732c98b02e6
tuned proof preplay to explicitly refer to Z3 backend
desharna
parents:
72518
diff
changeset
|
180 |
[SMT_Method SMT_Z3 :: |
72518
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
181 |
map (fn strategy => SMT_Method (SMT_Verit strategy)) |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
182 |
(Verit_Proof.all_veriT_stgies (Context.Proof ctxt))] |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
183 |
else |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
184 |
[] |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
185 |
in |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
186 |
try0_methodss @ [metis_methods] @ smt_methodss |
4be6ae020fc4
Added smt (verit) to Sledgehammer's proof preplay.
desharna
parents:
72400
diff
changeset
|
187 |
end |
43033 | 188 |
|
48798 | 189 |
fun is_fact_chained ((_, (sc, _)), _) = sc = Chained |
190 |
||
191 |
fun filter_used_facts keep_chained used = |
|
58654
3e1cad27fc2f
special treatment of extensionality in minimizer
blanchet
parents:
58498
diff
changeset
|
192 |
filter ((member (eq_fst (op =)) used o fst) orf |
3e1cad27fc2f
special treatment of extensionality in minimizer
blanchet
parents:
58498
diff
changeset
|
193 |
(if keep_chained then is_fact_chained else K false)) |
43033 | 194 |
|
53480
247817dbb990
limit the number of instances of a single theorem
blanchet
parents:
53478
diff
changeset
|
195 |
val max_fact_instances = 10 (* FUDGE *) |
247817dbb990
limit the number of instances of a single theorem
blanchet
parents:
53478
diff
changeset
|
196 |
|
55205 | 197 |
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
|
198 |
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
|
199 |
#> Config.put Monomorph.max_new_instances |
55205 | 200 |
(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
|
201 |
#> 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
|
202 |
|
55212 | 203 |
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
|
204 |
let |
55212 | 205 |
val thy = Proof_Context.theory_of ctxt |
206 |
val (remote_provers, local_provers) = |
|
58061 | 207 |
sort_strings (supported_atps thy) @ sort_strings (SMT_Config.available_solvers_of ctxt) |
55212 | 208 |
|> 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
|
209 |
in |
63692 | 210 |
writeln ("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
|
211 |
end |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43044
diff
changeset
|
212 |
|
28582 | 213 |
end; |