blanchet@41087
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_provers.ML
|
wenzelm@28477
|
2 |
Author: Fabian Immler, TU Muenchen
|
wenzelm@32996
|
3 |
Author: Makarius
|
blanchet@35969
|
4 |
Author: Jasmin Blanchette, TU Muenchen
|
wenzelm@28477
|
5 |
|
blanchet@41087
|
6 |
Generic prover abstraction for Sledgehammer.
|
wenzelm@28477
|
7 |
*)
|
wenzelm@28477
|
8 |
|
blanchet@41087
|
9 |
signature SLEDGEHAMMER_PROVERS =
|
wenzelm@28477
|
10 |
sig
|
blanchet@40181
|
11 |
type failure = ATP_Proof.failure
|
blanchet@46340
|
12 |
type stature = ATP_Problem_Generate.stature
|
blanchet@46320
|
13 |
type type_enc = ATP_Problem_Generate.type_enc
|
blanchet@51005
|
14 |
type fact = Sledgehammer_Fact.fact
|
blanchet@49914
|
15 |
type reconstructor = Sledgehammer_Reconstruct.reconstructor
|
blanchet@49914
|
16 |
type play = Sledgehammer_Reconstruct.play
|
blanchet@49914
|
17 |
type minimize_command = Sledgehammer_Reconstruct.minimize_command
|
blanchet@39493
|
18 |
|
blanchet@48392
|
19 |
datatype mode = Auto_Try | Try | Normal | MaSh | Auto_Minimize | Minimize
|
blanchet@43021
|
20 |
|
blanchet@35969
|
21 |
type params =
|
blanchet@48321
|
22 |
{debug : bool,
|
blanchet@48321
|
23 |
verbose : bool,
|
blanchet@48321
|
24 |
overlord : bool,
|
blanchet@48321
|
25 |
blocking : bool,
|
blanchet@48321
|
26 |
provers : string list,
|
blanchet@48321
|
27 |
type_enc : string option,
|
blanchet@48321
|
28 |
strict : bool,
|
blanchet@48321
|
29 |
lam_trans : string option,
|
blanchet@48321
|
30 |
uncurried_aliases : bool option,
|
blanchet@48321
|
31 |
learn : bool,
|
blanchet@48321
|
32 |
fact_filter : string option,
|
blanchet@48321
|
33 |
max_facts : int option,
|
blanchet@48321
|
34 |
fact_thresholds : real * real,
|
blanchet@48321
|
35 |
max_mono_iters : int option,
|
blanchet@48321
|
36 |
max_new_mono_instances : int option,
|
blanchet@49918
|
37 |
isar_proofs : bool,
|
blanchet@50020
|
38 |
isar_shrink : real,
|
blanchet@48321
|
39 |
slice : bool,
|
blanchet@48321
|
40 |
minimize : bool option,
|
blanchet@50557
|
41 |
timeout : Time.time option,
|
blanchet@50557
|
42 |
preplay_timeout : Time.time option,
|
blanchet@48321
|
43 |
expect : string}
|
blanchet@39493
|
44 |
|
blanchet@48288
|
45 |
type relevance_fudge =
|
blanchet@48288
|
46 |
{local_const_multiplier : real,
|
blanchet@48288
|
47 |
worse_irrel_freq : real,
|
blanchet@48288
|
48 |
higher_order_irrel_weight : real,
|
blanchet@48288
|
49 |
abs_rel_weight : real,
|
blanchet@48288
|
50 |
abs_irrel_weight : real,
|
blanchet@48288
|
51 |
skolem_irrel_weight : real,
|
blanchet@48288
|
52 |
theory_const_rel_weight : real,
|
blanchet@48288
|
53 |
theory_const_irrel_weight : real,
|
blanchet@48288
|
54 |
chained_const_irrel_weight : real,
|
blanchet@48288
|
55 |
intro_bonus : real,
|
blanchet@48288
|
56 |
elim_bonus : real,
|
blanchet@48288
|
57 |
simp_bonus : real,
|
blanchet@48288
|
58 |
local_bonus : real,
|
blanchet@48288
|
59 |
assum_bonus : real,
|
blanchet@48288
|
60 |
chained_bonus : real,
|
blanchet@48288
|
61 |
max_imperfect : real,
|
blanchet@48288
|
62 |
max_imperfect_exp : real,
|
blanchet@48288
|
63 |
threshold_divisor : real,
|
blanchet@48288
|
64 |
ridiculous_threshold : real}
|
blanchet@48288
|
65 |
|
blanchet@40061
|
66 |
type prover_problem =
|
blanchet@48321
|
67 |
{state : Proof.state,
|
blanchet@48321
|
68 |
goal : thm,
|
blanchet@48321
|
69 |
subgoal : int,
|
blanchet@48321
|
70 |
subgoal_count : int,
|
blanchet@51010
|
71 |
factss : (string * fact list) list}
|
blanchet@39493
|
72 |
|
blanchet@40061
|
73 |
type prover_result =
|
blanchet@48321
|
74 |
{outcome : failure option,
|
blanchet@51009
|
75 |
used_facts : (string * stature) list,
|
blanchet@51009
|
76 |
used_from : fact list,
|
blanchet@48321
|
77 |
run_time : Time.time,
|
blanchet@50669
|
78 |
preplay : play Lazy.lazy,
|
blanchet@48321
|
79 |
message : play -> string,
|
blanchet@48321
|
80 |
message_tail : string}
|
blanchet@39493
|
81 |
|
blanchet@43051
|
82 |
type prover =
|
blanchet@45520
|
83 |
params -> ((string * string list) list -> string -> minimize_command)
|
blanchet@45520
|
84 |
-> prover_problem -> prover_result
|
blanchet@35867
|
85 |
|
blanchet@43092
|
86 |
val dest_dir : string Config.T
|
blanchet@43092
|
87 |
val problem_prefix : string Config.T
|
blanchet@48143
|
88 |
val completish : bool Config.T
|
blanchet@44592
|
89 |
val atp_full_names : bool Config.T
|
blanchet@42646
|
90 |
val smt_triggers : bool Config.T
|
blanchet@42646
|
91 |
val smt_weights : bool Config.T
|
blanchet@42646
|
92 |
val smt_weight_min_facts : int Config.T
|
blanchet@42646
|
93 |
val smt_min_weight : int Config.T
|
blanchet@42646
|
94 |
val smt_max_weight : int Config.T
|
blanchet@42646
|
95 |
val smt_max_weight_index : int Config.T
|
blanchet@41256
|
96 |
val smt_weight_curve : (int -> int) Unsynchronized.ref
|
blanchet@42646
|
97 |
val smt_max_slices : int Config.T
|
blanchet@42646
|
98 |
val smt_slice_fact_frac : real Config.T
|
blanchet@42646
|
99 |
val smt_slice_time_frac : real Config.T
|
blanchet@42646
|
100 |
val smt_slice_min_secs : int Config.T
|
blanchet@48319
|
101 |
val SledgehammerN : string
|
blanchet@45519
|
102 |
val plain_metis : reconstructor
|
blanchet@41242
|
103 |
val select_smt_solver : string -> Proof.context -> Proof.context
|
blanchet@45520
|
104 |
val extract_reconstructor :
|
blanchet@45561
|
105 |
params -> reconstructor -> string * (string * string list) list
|
blanchet@45379
|
106 |
val is_reconstructor : string -> bool
|
blanchet@43050
|
107 |
val is_atp : theory -> string -> bool
|
blanchet@41087
|
108 |
val is_smt_prover : Proof.context -> string -> bool
|
blanchet@47962
|
109 |
val is_ho_atp: Proof.context -> string -> bool
|
blanchet@42944
|
110 |
val is_unit_equational_atp : Proof.context -> string -> bool
|
blanchet@41727
|
111 |
val is_prover_supported : Proof.context -> string -> bool
|
blanchet@40072
|
112 |
val is_prover_installed : Proof.context -> string -> bool
|
blanchet@48293
|
113 |
val default_max_facts_for_prover : Proof.context -> bool -> string -> int
|
blanchet@42944
|
114 |
val is_unit_equality : term -> bool
|
blanchet@42952
|
115 |
val is_appropriate_prop_for_prover : Proof.context -> string -> term -> bool
|
blanchet@40369
|
116 |
val is_built_in_const_for_prover :
|
blanchet@41336
|
117 |
Proof.context -> string -> string * typ -> term list -> bool * term list
|
blanchet@41087
|
118 |
val atp_relevance_fudge : relevance_fudge
|
blanchet@41087
|
119 |
val smt_relevance_fudge : relevance_fudge
|
blanchet@40941
|
120 |
val relevance_fudge_for_prover : Proof.context -> string -> relevance_fudge
|
blanchet@41256
|
121 |
val weight_smt_fact :
|
blanchet@46340
|
122 |
Proof.context -> int -> ((string * stature) * thm) * int
|
blanchet@46340
|
123 |
-> (string * stature) * (int option * thm)
|
blanchet@41727
|
124 |
val supported_provers : Proof.context -> unit
|
blanchet@40059
|
125 |
val kill_provers : unit -> unit
|
blanchet@40059
|
126 |
val running_provers : unit -> unit
|
blanchet@40059
|
127 |
val messages : int option -> unit
|
blanchet@48798
|
128 |
val is_fact_chained : (('a * stature) * 'b) -> bool
|
blanchet@48798
|
129 |
val filter_used_facts :
|
blanchet@48798
|
130 |
bool -> (''a * stature) list -> ((''a * stature) * 'b) list ->
|
blanchet@48798
|
131 |
((''a * stature) * 'b) list
|
blanchet@43021
|
132 |
val get_prover : Proof.context -> mode -> string -> prover
|
wenzelm@28477
|
133 |
end;
|
wenzelm@28477
|
134 |
|
blanchet@41087
|
135 |
structure Sledgehammer_Provers : SLEDGEHAMMER_PROVERS =
|
wenzelm@28477
|
136 |
struct
|
wenzelm@28477
|
137 |
|
blanchet@43085
|
138 |
open ATP_Util
|
blanchet@38028
|
139 |
open ATP_Problem
|
blanchet@39491
|
140 |
open ATP_Proof
|
blanchet@38028
|
141 |
open ATP_Systems
|
blanchet@46320
|
142 |
open ATP_Problem_Generate
|
blanchet@46320
|
143 |
open ATP_Proof_Reconstruct
|
blanchet@45521
|
144 |
open Metis_Tactic
|
blanchet@38023
|
145 |
open Sledgehammer_Util
|
blanchet@51005
|
146 |
open Sledgehammer_Fact
|
blanchet@49881
|
147 |
open Sledgehammer_Reconstruct
|
blanchet@48288
|
148 |
|
blanchet@37583
|
149 |
|
blanchet@37583
|
150 |
(** The Sledgehammer **)
|
blanchet@37583
|
151 |
|
blanchet@48392
|
152 |
datatype mode = Auto_Try | Try | Normal | MaSh | Auto_Minimize | Minimize
|
blanchet@43021
|
153 |
|
blanchet@45376
|
154 |
(* Identifier that distinguishes Sledgehammer from other tools that could use
|
blanchet@38102
|
155 |
"Async_Manager". *)
|
blanchet@48319
|
156 |
val SledgehammerN = "Sledgehammer"
|
blanchet@37585
|
157 |
|
blanchet@45520
|
158 |
val reconstructor_names = [metisN, smtN]
|
blanchet@46365
|
159 |
val plain_metis = Metis (hd partial_type_encs, combsN)
|
blanchet@45561
|
160 |
val is_reconstructor = member (op =) reconstructor_names
|
blanchet@43228
|
161 |
|
blanchet@43050
|
162 |
val is_atp = member (op =) o supported_atps
|
blanchet@43050
|
163 |
|
blanchet@43233
|
164 |
val select_smt_solver = Context.proof_map o SMT_Config.select_solver
|
blanchet@41242
|
165 |
|
blanchet@45376
|
166 |
fun is_smt_prover ctxt = member (op =) (SMT_Solver.available_solvers_of ctxt)
|
blanchet@40062
|
167 |
|
blanchet@44597
|
168 |
fun is_atp_for_format is_format ctxt name =
|
blanchet@42944
|
169 |
let val thy = Proof_Context.theory_of ctxt in
|
blanchet@42944
|
170 |
case try (get_atp thy) name of
|
blanchet@47606
|
171 |
SOME config =>
|
blanchet@48716
|
172 |
exists (fn (_, ((_, format, _, _, _), _)) => is_format format)
|
blanchet@47606
|
173 |
(#best_slices (config ()) ctxt)
|
blanchet@42944
|
174 |
| NONE => false
|
blanchet@42944
|
175 |
end
|
blanchet@42944
|
176 |
|
blanchet@44597
|
177 |
val is_unit_equational_atp = is_atp_for_format (curry (op =) CNF_UEQ)
|
blanchet@45303
|
178 |
val is_ho_atp = is_atp_for_format is_format_higher_order
|
blanchet@44597
|
179 |
|
blanchet@45376
|
180 |
fun is_prover_supported ctxt =
|
wenzelm@42361
|
181 |
let val thy = Proof_Context.theory_of ctxt in
|
blanchet@45379
|
182 |
is_reconstructor orf is_atp thy orf is_smt_prover ctxt
|
blanchet@40941
|
183 |
end
|
blanchet@40072
|
184 |
|
boehmes@41432
|
185 |
fun is_prover_installed ctxt =
|
blanchet@45379
|
186 |
is_reconstructor orf is_smt_prover ctxt orf
|
blanchet@43050
|
187 |
is_atp_installed (Proof_Context.theory_of ctxt)
|
blanchet@40941
|
188 |
|
blanchet@45706
|
189 |
fun get_slices slice slices =
|
blanchet@45706
|
190 |
(0 upto length slices - 1) ~~ slices |> not slice ? (List.last #> single)
|
blanchet@42443
|
191 |
|
blanchet@48293
|
192 |
val reconstructor_default_max_facts = 20
|
blanchet@43050
|
193 |
|
blanchet@48293
|
194 |
fun default_max_facts_for_prover ctxt slice name =
|
wenzelm@42361
|
195 |
let val thy = Proof_Context.theory_of ctxt in
|
blanchet@45379
|
196 |
if is_reconstructor name then
|
blanchet@48293
|
197 |
reconstructor_default_max_facts
|
blanchet@43050
|
198 |
else if is_atp thy name then
|
blanchet@48716
|
199 |
fold (Integer.max o #1 o fst o snd o snd)
|
blanchet@47606
|
200 |
(get_slices slice (#best_slices (get_atp thy name ()) ctxt)) 0
|
blanchet@43050
|
201 |
else (* is_smt_prover ctxt name *)
|
blanchet@43050
|
202 |
SMT_Solver.default_max_relevant ctxt name
|
blanchet@40941
|
203 |
end
|
blanchet@40063
|
204 |
|
blanchet@42956
|
205 |
fun is_if (@{const_name If}, _) = true
|
blanchet@42956
|
206 |
| is_if _ = false
|
blanchet@42956
|
207 |
|
blanchet@42956
|
208 |
(* Beware of "if and only if" (which is translated as such) and "If" (which is
|
blanchet@42956
|
209 |
translated to conditional equations). *)
|
blanchet@42956
|
210 |
fun is_good_unit_equality T t u =
|
blanchet@42956
|
211 |
T <> @{typ bool} andalso not (exists (exists_Const is_if) [t, u])
|
blanchet@42956
|
212 |
|
blanchet@42944
|
213 |
fun is_unit_equality (@{const Trueprop} $ t) = is_unit_equality t
|
blanchet@42944
|
214 |
| is_unit_equality (Const (@{const_name all}, _) $ Abs (_, _, t)) =
|
blanchet@42944
|
215 |
is_unit_equality t
|
blanchet@42944
|
216 |
| is_unit_equality (Const (@{const_name All}, _) $ Abs (_, _, t)) =
|
blanchet@42944
|
217 |
is_unit_equality t
|
blanchet@42956
|
218 |
| is_unit_equality (Const (@{const_name "=="}, Type (_, [T, _])) $ t $ u) =
|
blanchet@42956
|
219 |
is_good_unit_equality T t u
|
blanchet@42956
|
220 |
| is_unit_equality (Const (@{const_name HOL.eq}, Type (_ , [T, _])) $ t $ u) =
|
blanchet@42956
|
221 |
is_good_unit_equality T t u
|
blanchet@42944
|
222 |
| is_unit_equality _ = false
|
blanchet@42944
|
223 |
|
blanchet@42952
|
224 |
fun is_appropriate_prop_for_prover ctxt name =
|
blanchet@42944
|
225 |
if is_unit_equational_atp ctxt name then is_unit_equality else K true
|
blanchet@42944
|
226 |
|
blanchet@41242
|
227 |
fun is_built_in_const_for_prover ctxt name =
|
blanchet@41242
|
228 |
if is_smt_prover ctxt name then
|
blanchet@41336
|
229 |
let val ctxt = ctxt |> select_smt_solver name in
|
blanchet@41336
|
230 |
fn x => fn ts =>
|
blanchet@41336
|
231 |
if SMT_Builtin.is_builtin_num_ext ctxt (list_comb (Const x, ts)) then
|
blanchet@41336
|
232 |
(true, [])
|
blanchet@41336
|
233 |
else if SMT_Builtin.is_builtin_fun_ext ctxt x ts then
|
blanchet@41336
|
234 |
(true, ts)
|
blanchet@41336
|
235 |
else
|
blanchet@41336
|
236 |
(false, ts)
|
blanchet@41336
|
237 |
end
|
blanchet@41242
|
238 |
else
|
blanchet@41336
|
239 |
fn (s, _) => fn ts => (member (op =) atp_irrelevant_consts s, ts)
|
blanchet@40071
|
240 |
|
blanchet@40070
|
241 |
(* FUDGE *)
|
blanchet@40070
|
242 |
val atp_relevance_fudge =
|
blanchet@42738
|
243 |
{local_const_multiplier = 1.5,
|
blanchet@41159
|
244 |
worse_irrel_freq = 100.0,
|
blanchet@40070
|
245 |
higher_order_irrel_weight = 1.05,
|
blanchet@40070
|
246 |
abs_rel_weight = 0.5,
|
blanchet@40070
|
247 |
abs_irrel_weight = 2.0,
|
blanchet@47934
|
248 |
skolem_irrel_weight = 0.05,
|
blanchet@40070
|
249 |
theory_const_rel_weight = 0.5,
|
blanchet@40070
|
250 |
theory_const_irrel_weight = 0.25,
|
blanchet@42735
|
251 |
chained_const_irrel_weight = 0.25,
|
blanchet@40070
|
252 |
intro_bonus = 0.15,
|
blanchet@40070
|
253 |
elim_bonus = 0.15,
|
blanchet@40070
|
254 |
simp_bonus = 0.15,
|
blanchet@40070
|
255 |
local_bonus = 0.55,
|
blanchet@40070
|
256 |
assum_bonus = 1.05,
|
blanchet@40070
|
257 |
chained_bonus = 1.5,
|
blanchet@40070
|
258 |
max_imperfect = 11.5,
|
blanchet@40070
|
259 |
max_imperfect_exp = 1.0,
|
blanchet@40070
|
260 |
threshold_divisor = 2.0,
|
blanchet@41093
|
261 |
ridiculous_threshold = 0.01}
|
blanchet@40070
|
262 |
|
blanchet@40071
|
263 |
(* FUDGE (FIXME) *)
|
blanchet@40070
|
264 |
val smt_relevance_fudge =
|
blanchet@42738
|
265 |
{local_const_multiplier = #local_const_multiplier atp_relevance_fudge,
|
blanchet@41159
|
266 |
worse_irrel_freq = #worse_irrel_freq atp_relevance_fudge,
|
blanchet@40071
|
267 |
higher_order_irrel_weight = #higher_order_irrel_weight atp_relevance_fudge,
|
blanchet@40071
|
268 |
abs_rel_weight = #abs_rel_weight atp_relevance_fudge,
|
blanchet@40071
|
269 |
abs_irrel_weight = #abs_irrel_weight atp_relevance_fudge,
|
blanchet@40071
|
270 |
skolem_irrel_weight = #skolem_irrel_weight atp_relevance_fudge,
|
blanchet@40071
|
271 |
theory_const_rel_weight = #theory_const_rel_weight atp_relevance_fudge,
|
blanchet@40071
|
272 |
theory_const_irrel_weight = #theory_const_irrel_weight atp_relevance_fudge,
|
blanchet@42735
|
273 |
chained_const_irrel_weight = #chained_const_irrel_weight atp_relevance_fudge,
|
blanchet@40071
|
274 |
intro_bonus = #intro_bonus atp_relevance_fudge,
|
blanchet@40071
|
275 |
elim_bonus = #elim_bonus atp_relevance_fudge,
|
blanchet@40071
|
276 |
simp_bonus = #simp_bonus atp_relevance_fudge,
|
blanchet@40071
|
277 |
local_bonus = #local_bonus atp_relevance_fudge,
|
blanchet@40071
|
278 |
assum_bonus = #assum_bonus atp_relevance_fudge,
|
blanchet@40071
|
279 |
chained_bonus = #chained_bonus atp_relevance_fudge,
|
blanchet@40071
|
280 |
max_imperfect = #max_imperfect atp_relevance_fudge,
|
blanchet@40071
|
281 |
max_imperfect_exp = #max_imperfect_exp atp_relevance_fudge,
|
blanchet@40071
|
282 |
threshold_divisor = #threshold_divisor atp_relevance_fudge,
|
blanchet@40071
|
283 |
ridiculous_threshold = #ridiculous_threshold atp_relevance_fudge}
|
blanchet@40070
|
284 |
|
blanchet@40941
|
285 |
fun relevance_fudge_for_prover ctxt name =
|
blanchet@40941
|
286 |
if is_smt_prover ctxt name then smt_relevance_fudge else atp_relevance_fudge
|
blanchet@40070
|
287 |
|
blanchet@41727
|
288 |
fun supported_provers ctxt =
|
blanchet@40060
|
289 |
let
|
wenzelm@42361
|
290 |
val thy = Proof_Context.theory_of ctxt
|
blanchet@40060
|
291 |
val (remote_provers, local_provers) =
|
blanchet@45520
|
292 |
reconstructor_names @
|
blanchet@41727
|
293 |
sort_strings (supported_atps thy) @
|
blanchet@41727
|
294 |
sort_strings (SMT_Solver.available_solvers_of ctxt)
|
blanchet@40060
|
295 |
|> List.partition (String.isPrefix remote_prefix)
|
blanchet@40060
|
296 |
in
|
blanchet@41727
|
297 |
Output.urgent_message ("Supported provers: " ^
|
blanchet@40205
|
298 |
commas (local_provers @ remote_provers) ^ ".")
|
blanchet@40060
|
299 |
end
|
blanchet@35969
|
300 |
|
blanchet@48319
|
301 |
fun kill_provers () = Async_Manager.kill_threads SledgehammerN "prover"
|
blanchet@48319
|
302 |
fun running_provers () = Async_Manager.running_threads SledgehammerN "prover"
|
blanchet@48319
|
303 |
val messages = Async_Manager.thread_messages SledgehammerN "prover"
|
blanchet@40059
|
304 |
|
blanchet@48288
|
305 |
|
blanchet@40059
|
306 |
(** problems, results, ATPs, etc. **)
|
blanchet@35969
|
307 |
|
blanchet@35969
|
308 |
type params =
|
blanchet@48321
|
309 |
{debug : bool,
|
blanchet@48321
|
310 |
verbose : bool,
|
blanchet@48321
|
311 |
overlord : bool,
|
blanchet@48321
|
312 |
blocking : bool,
|
blanchet@48321
|
313 |
provers : string list,
|
blanchet@48321
|
314 |
type_enc : string option,
|
blanchet@48321
|
315 |
strict : bool,
|
blanchet@48321
|
316 |
lam_trans : string option,
|
blanchet@48321
|
317 |
uncurried_aliases : bool option,
|
blanchet@48321
|
318 |
learn : bool,
|
blanchet@48321
|
319 |
fact_filter : string option,
|
blanchet@48321
|
320 |
max_facts : int option,
|
blanchet@48321
|
321 |
fact_thresholds : real * real,
|
blanchet@48321
|
322 |
max_mono_iters : int option,
|
blanchet@48321
|
323 |
max_new_mono_instances : int option,
|
blanchet@49918
|
324 |
isar_proofs : bool,
|
blanchet@50020
|
325 |
isar_shrink : real,
|
blanchet@48321
|
326 |
slice : bool,
|
blanchet@48321
|
327 |
minimize : bool option,
|
blanchet@50557
|
328 |
timeout : Time.time option,
|
blanchet@50557
|
329 |
preplay_timeout : Time.time option,
|
blanchet@48321
|
330 |
expect : string}
|
blanchet@35867
|
331 |
|
blanchet@48288
|
332 |
type relevance_fudge =
|
blanchet@48288
|
333 |
{local_const_multiplier : real,
|
blanchet@48288
|
334 |
worse_irrel_freq : real,
|
blanchet@48288
|
335 |
higher_order_irrel_weight : real,
|
blanchet@48288
|
336 |
abs_rel_weight : real,
|
blanchet@48288
|
337 |
abs_irrel_weight : real,
|
blanchet@48288
|
338 |
skolem_irrel_weight : real,
|
blanchet@48288
|
339 |
theory_const_rel_weight : real,
|
blanchet@48288
|
340 |
theory_const_irrel_weight : real,
|
blanchet@48288
|
341 |
chained_const_irrel_weight : real,
|
blanchet@48288
|
342 |
intro_bonus : real,
|
blanchet@48288
|
343 |
elim_bonus : real,
|
blanchet@48288
|
344 |
simp_bonus : real,
|
blanchet@48288
|
345 |
local_bonus : real,
|
blanchet@48288
|
346 |
assum_bonus : real,
|
blanchet@48288
|
347 |
chained_bonus : real,
|
blanchet@48288
|
348 |
max_imperfect : real,
|
blanchet@48288
|
349 |
max_imperfect_exp : real,
|
blanchet@48288
|
350 |
threshold_divisor : real,
|
blanchet@48288
|
351 |
ridiculous_threshold : real}
|
blanchet@48288
|
352 |
|
blanchet@40061
|
353 |
type prover_problem =
|
blanchet@48321
|
354 |
{state : Proof.state,
|
blanchet@48321
|
355 |
goal : thm,
|
blanchet@48321
|
356 |
subgoal : int,
|
blanchet@48321
|
357 |
subgoal_count : int,
|
blanchet@51010
|
358 |
factss : (string * fact list) list}
|
blanchet@35867
|
359 |
|
blanchet@40061
|
360 |
type prover_result =
|
blanchet@48321
|
361 |
{outcome : failure option,
|
blanchet@48321
|
362 |
used_facts : (string * stature) list,
|
blanchet@51009
|
363 |
used_from : fact list,
|
blanchet@48321
|
364 |
run_time : Time.time,
|
blanchet@50669
|
365 |
preplay : play Lazy.lazy,
|
blanchet@48321
|
366 |
message : play -> string,
|
blanchet@48321
|
367 |
message_tail : string}
|
blanchet@35867
|
368 |
|
blanchet@43051
|
369 |
type prover =
|
blanchet@45520
|
370 |
params -> ((string * string list) list -> string -> minimize_command)
|
blanchet@45520
|
371 |
-> prover_problem -> prover_result
|
blanchet@35867
|
372 |
|
blanchet@38023
|
373 |
(* configuration attributes *)
|
blanchet@38023
|
374 |
|
blanchet@43092
|
375 |
(* Empty string means create files in Isabelle's temporary files directory. *)
|
wenzelm@42616
|
376 |
val dest_dir =
|
wenzelm@42616
|
377 |
Attrib.setup_config_string @{binding sledgehammer_dest_dir} (K "")
|
wenzelm@42616
|
378 |
val problem_prefix =
|
wenzelm@42616
|
379 |
Attrib.setup_config_string @{binding sledgehammer_problem_prefix} (K "prob")
|
blanchet@48143
|
380 |
val completish =
|
blanchet@48143
|
381 |
Attrib.setup_config_bool @{binding sledgehammer_completish} (K false)
|
wenzelm@28484
|
382 |
|
blanchet@43092
|
383 |
(* In addition to being easier to read, readable names are often much shorter,
|
blanchet@44394
|
384 |
especially if types are mangled in names. This makes a difference for some
|
blanchet@44394
|
385 |
provers (e.g., E). For these reason, short names are enabled by default. *)
|
blanchet@44592
|
386 |
val atp_full_names =
|
blanchet@44592
|
387 |
Attrib.setup_config_bool @{binding sledgehammer_atp_full_names} (K false)
|
blanchet@43092
|
388 |
|
blanchet@42646
|
389 |
val smt_triggers =
|
blanchet@42646
|
390 |
Attrib.setup_config_bool @{binding sledgehammer_smt_triggers} (K true)
|
blanchet@42646
|
391 |
val smt_weights =
|
blanchet@42646
|
392 |
Attrib.setup_config_bool @{binding sledgehammer_smt_weights} (K true)
|
blanchet@42646
|
393 |
val smt_weight_min_facts =
|
blanchet@42646
|
394 |
Attrib.setup_config_int @{binding sledgehammer_smt_weight_min_facts} (K 20)
|
blanchet@41256
|
395 |
|
blanchet@41256
|
396 |
(* FUDGE *)
|
blanchet@42646
|
397 |
val smt_min_weight =
|
blanchet@42646
|
398 |
Attrib.setup_config_int @{binding sledgehammer_smt_min_weight} (K 0)
|
blanchet@42646
|
399 |
val smt_max_weight =
|
blanchet@42646
|
400 |
Attrib.setup_config_int @{binding sledgehammer_smt_max_weight} (K 10)
|
blanchet@42646
|
401 |
val smt_max_weight_index =
|
blanchet@42646
|
402 |
Attrib.setup_config_int @{binding sledgehammer_smt_max_weight_index} (K 200)
|
blanchet@41256
|
403 |
val smt_weight_curve = Unsynchronized.ref (fn x : int => x * x)
|
blanchet@41256
|
404 |
|
blanchet@42646
|
405 |
fun smt_fact_weight ctxt j num_facts =
|
blanchet@42646
|
406 |
if Config.get ctxt smt_weights andalso
|
blanchet@42646
|
407 |
num_facts >= Config.get ctxt smt_weight_min_facts then
|
blanchet@42646
|
408 |
let
|
blanchet@42646
|
409 |
val min = Config.get ctxt smt_min_weight
|
blanchet@42646
|
410 |
val max = Config.get ctxt smt_max_weight
|
blanchet@42646
|
411 |
val max_index = Config.get ctxt smt_max_weight_index
|
blanchet@42646
|
412 |
val curve = !smt_weight_curve
|
blanchet@42646
|
413 |
in
|
blanchet@42646
|
414 |
SOME (max - (max - min + 1) * curve (Int.max (0, max_index - j - 1))
|
blanchet@42646
|
415 |
div curve max_index)
|
blanchet@42646
|
416 |
end
|
blanchet@41256
|
417 |
else
|
blanchet@41256
|
418 |
NONE
|
blanchet@41256
|
419 |
|
blanchet@42646
|
420 |
fun weight_smt_fact ctxt num_facts ((info, th), j) =
|
blanchet@42646
|
421 |
let val thy = Proof_Context.theory_of ctxt in
|
blanchet@42646
|
422 |
(info, (smt_fact_weight ctxt j num_facts, th |> Thm.transfer thy))
|
blanchet@42646
|
423 |
end
|
blanchet@38023
|
424 |
|
blanchet@41313
|
425 |
fun overlord_file_location_for_prover prover =
|
blanchet@41313
|
426 |
(getenv "ISABELLE_HOME_USER", "prob_" ^ prover)
|
blanchet@41313
|
427 |
|
blanchet@43052
|
428 |
fun proof_banner mode name =
|
blanchet@43033
|
429 |
case mode of
|
blanchet@43033
|
430 |
Auto_Try => "Auto Sledgehammer (" ^ quote name ^ ") found a proof"
|
blanchet@43033
|
431 |
| Try => "Sledgehammer (" ^ quote name ^ ") found a proof"
|
blanchet@43052
|
432 |
| _ => "Try this"
|
blanchet@43033
|
433 |
|
blanchet@45561
|
434 |
fun bunch_of_reconstructors needs_full_types lam_trans =
|
blanchet@48800
|
435 |
if needs_full_types then
|
blanchet@48802
|
436 |
[Metis (full_type_enc, lam_trans false),
|
blanchet@48802
|
437 |
Metis (really_full_type_enc, lam_trans false),
|
blanchet@48802
|
438 |
Metis (full_type_enc, lam_trans true),
|
blanchet@48802
|
439 |
Metis (really_full_type_enc, lam_trans true),
|
blanchet@48802
|
440 |
SMT]
|
blanchet@48802
|
441 |
else
|
blanchet@48800
|
442 |
[Metis (partial_type_enc, lam_trans false),
|
blanchet@48800
|
443 |
Metis (full_type_enc, lam_trans false),
|
blanchet@48800
|
444 |
Metis (no_typesN, lam_trans true),
|
blanchet@48800
|
445 |
Metis (really_full_type_enc, lam_trans true),
|
blanchet@48800
|
446 |
SMT]
|
blanchet@45561
|
447 |
|
blanchet@45561
|
448 |
fun extract_reconstructor ({type_enc, lam_trans, ...} : params)
|
blanchet@45561
|
449 |
(Metis (type_enc', lam_trans')) =
|
blanchet@45561
|
450 |
let
|
blanchet@45561
|
451 |
val override_params =
|
blanchet@45561
|
452 |
(if is_none type_enc andalso type_enc' = hd partial_type_encs then
|
blanchet@45561
|
453 |
[]
|
blanchet@45561
|
454 |
else
|
blanchet@45566
|
455 |
[("type_enc", [hd (unalias_type_enc type_enc')])]) @
|
blanchet@45561
|
456 |
(if is_none lam_trans andalso lam_trans' = metis_default_lam_trans then
|
blanchet@45561
|
457 |
[]
|
blanchet@45561
|
458 |
else
|
blanchet@45561
|
459 |
[("lam_trans", [lam_trans'])])
|
blanchet@45561
|
460 |
in (metisN, override_params) end
|
blanchet@45561
|
461 |
| extract_reconstructor _ SMT = (smtN, [])
|
blanchet@45561
|
462 |
|
blanchet@43033
|
463 |
(* based on "Mirabelle.can_apply" and generalized *)
|
blanchet@43034
|
464 |
fun timed_apply timeout tac state i =
|
blanchet@43033
|
465 |
let
|
blanchet@43033
|
466 |
val {context = ctxt, facts, goal} = Proof.goal state
|
blanchet@43033
|
467 |
val full_tac = Method.insert_tac facts i THEN tac ctxt i
|
blanchet@50557
|
468 |
in time_limit timeout (try (Seq.pull o full_tac)) goal end
|
blanchet@43033
|
469 |
|
blanchet@45519
|
470 |
fun tac_for_reconstructor (Metis (type_enc, lam_trans)) =
|
blanchet@45521
|
471 |
metis_tac [type_enc] lam_trans
|
blanchet@45379
|
472 |
| tac_for_reconstructor SMT = SMT_Solver.smt_tac
|
blanchet@43034
|
473 |
|
blanchet@45520
|
474 |
fun timed_reconstructor reconstr debug timeout ths =
|
blanchet@44651
|
475 |
(Config.put Metis_Tactic.verbose debug
|
blanchet@45557
|
476 |
#> Config.put SMT_Config.verbose debug
|
blanchet@45520
|
477 |
#> (fn ctxt => tac_for_reconstructor reconstr ctxt ths))
|
blanchet@43034
|
478 |
|> timed_apply timeout
|
blanchet@43033
|
479 |
|
blanchet@48798
|
480 |
fun is_fact_chained ((_, (sc, _)), _) = sc = Chained
|
blanchet@48798
|
481 |
|
blanchet@48798
|
482 |
fun filter_used_facts keep_chained used =
|
blanchet@48798
|
483 |
filter ((member (op =) used o fst) orf
|
blanchet@48798
|
484 |
(if keep_chained then is_fact_chained else K false))
|
blanchet@43033
|
485 |
|
blanchet@45781
|
486 |
fun play_one_line_proof mode debug verbose timeout pairs state i preferred
|
blanchet@45520
|
487 |
reconstrs =
|
blanchet@43034
|
488 |
let
|
blanchet@45520
|
489 |
fun get_preferred reconstrs =
|
blanchet@45520
|
490 |
if member (op =) reconstrs preferred then preferred
|
blanchet@45520
|
491 |
else List.last reconstrs
|
blanchet@43034
|
492 |
in
|
blanchet@50557
|
493 |
if timeout = SOME Time.zeroTime then
|
blanchet@45520
|
494 |
Trust_Playable (get_preferred reconstrs, NONE)
|
blanchet@45379
|
495 |
else
|
blanchet@50557
|
496 |
let
|
blanchet@50557
|
497 |
val _ =
|
blanchet@50557
|
498 |
if mode = Minimize then Output.urgent_message "Preplaying proof..."
|
blanchet@50557
|
499 |
else ()
|
blanchet@50557
|
500 |
val ths = pairs |> sort_wrt (fst o fst) |> map snd
|
blanchet@50557
|
501 |
fun play [] [] = Failed_to_Play (get_preferred reconstrs)
|
blanchet@50557
|
502 |
| play timed_outs [] =
|
blanchet@50557
|
503 |
Trust_Playable (get_preferred timed_outs, timeout)
|
blanchet@50557
|
504 |
| play timed_out (reconstr :: reconstrs) =
|
blanchet@50557
|
505 |
let
|
blanchet@50557
|
506 |
val _ =
|
blanchet@50557
|
507 |
if verbose then
|
blanchet@50557
|
508 |
"Trying \"" ^ string_for_reconstructor reconstr ^ "\"" ^
|
blanchet@50557
|
509 |
(case timeout of
|
blanchet@50557
|
510 |
SOME timeout => " for " ^ string_from_time timeout
|
blanchet@50557
|
511 |
| NONE => "") ^ "..."
|
blanchet@50557
|
512 |
|> Output.urgent_message
|
blanchet@50557
|
513 |
else
|
blanchet@50557
|
514 |
()
|
blanchet@50557
|
515 |
val timer = Timer.startRealTimer ()
|
blanchet@50557
|
516 |
in
|
blanchet@50557
|
517 |
case timed_reconstructor reconstr debug timeout ths state i of
|
blanchet@50557
|
518 |
SOME (SOME _) => Played (reconstr, Timer.checkRealTimer timer)
|
blanchet@50557
|
519 |
| _ => play timed_out reconstrs
|
blanchet@50557
|
520 |
end
|
blanchet@50557
|
521 |
handle TimeLimit.TimeOut => play (reconstr :: timed_out) reconstrs
|
blanchet@50557
|
522 |
in play [] reconstrs end
|
blanchet@43033
|
523 |
end
|
blanchet@43033
|
524 |
|
blanchet@41313
|
525 |
|
blanchet@41256
|
526 |
(* generic TPTP-based ATPs *)
|
blanchet@40061
|
527 |
|
blanchet@42730
|
528 |
(* Too general means, positive equality literal with a variable X as one
|
blanchet@42730
|
529 |
operand, when X does not occur properly in the other operand. This rules out
|
blanchet@42730
|
530 |
clearly inconsistent facts such as X = a | X = b, though it by no means
|
blanchet@42730
|
531 |
guarantees soundness. *)
|
blanchet@42730
|
532 |
|
blanchet@42730
|
533 |
(* Unwanted equalities are those between a (bound or schematic) variable that
|
blanchet@42730
|
534 |
does not properly occur in the second operand. *)
|
blanchet@42730
|
535 |
val is_exhaustive_finite =
|
blanchet@42730
|
536 |
let
|
blanchet@42730
|
537 |
fun is_bad_equal (Var z) t =
|
blanchet@42730
|
538 |
not (exists_subterm (fn Var z' => z = z' | _ => false) t)
|
blanchet@42730
|
539 |
| is_bad_equal (Bound j) t = not (loose_bvar1 (t, j))
|
blanchet@42730
|
540 |
| is_bad_equal _ _ = false
|
blanchet@42730
|
541 |
fun do_equals t1 t2 = is_bad_equal t1 t2 orelse is_bad_equal t2 t1
|
blanchet@42730
|
542 |
fun do_formula pos t =
|
blanchet@42730
|
543 |
case (pos, t) of
|
blanchet@42730
|
544 |
(_, @{const Trueprop} $ t1) => do_formula pos t1
|
blanchet@42730
|
545 |
| (true, Const (@{const_name all}, _) $ Abs (_, _, t')) =>
|
blanchet@42730
|
546 |
do_formula pos t'
|
blanchet@42730
|
547 |
| (true, Const (@{const_name All}, _) $ Abs (_, _, t')) =>
|
blanchet@42730
|
548 |
do_formula pos t'
|
blanchet@42730
|
549 |
| (false, Const (@{const_name Ex}, _) $ Abs (_, _, t')) =>
|
blanchet@42730
|
550 |
do_formula pos t'
|
blanchet@42730
|
551 |
| (_, @{const "==>"} $ t1 $ t2) =>
|
blanchet@42730
|
552 |
do_formula (not pos) t1 andalso
|
blanchet@42730
|
553 |
(t2 = @{prop False} orelse do_formula pos t2)
|
blanchet@42730
|
554 |
| (_, @{const HOL.implies} $ t1 $ t2) =>
|
blanchet@42730
|
555 |
do_formula (not pos) t1 andalso
|
blanchet@42730
|
556 |
(t2 = @{const False} orelse do_formula pos t2)
|
blanchet@42730
|
557 |
| (_, @{const Not} $ t1) => do_formula (not pos) t1
|
blanchet@42730
|
558 |
| (true, @{const HOL.disj} $ t1 $ t2) => forall (do_formula pos) [t1, t2]
|
blanchet@42730
|
559 |
| (false, @{const HOL.conj} $ t1 $ t2) => forall (do_formula pos) [t1, t2]
|
blanchet@42730
|
560 |
| (true, Const (@{const_name HOL.eq}, _) $ t1 $ t2) => do_equals t1 t2
|
blanchet@42730
|
561 |
| (true, Const (@{const_name "=="}, _) $ t1 $ t2) => do_equals t1 t2
|
blanchet@42730
|
562 |
| _ => false
|
blanchet@42730
|
563 |
in do_formula true end
|
blanchet@42730
|
564 |
|
blanchet@42730
|
565 |
fun has_bound_or_var_of_type pred =
|
blanchet@42730
|
566 |
exists_subterm (fn Var (_, T as Type _) => pred T
|
blanchet@42730
|
567 |
| Abs (_, T as Type _, _) => pred T
|
blanchet@42730
|
568 |
| _ => false)
|
blanchet@42730
|
569 |
|
blanchet@42730
|
570 |
(* Facts are forbidden to contain variables of these types. The typical reason
|
blanchet@42730
|
571 |
is that they lead to unsoundness. Note that "unit" satisfies numerous
|
blanchet@42730
|
572 |
equations like "?x = ()". The resulting clauses will have no type constraint,
|
blanchet@42730
|
573 |
yielding false proofs. Even "bool" leads to many unsound proofs, though only
|
blanchet@42730
|
574 |
for higher-order problems. *)
|
blanchet@42730
|
575 |
|
blanchet@42730
|
576 |
(* Facts containing variables of type "unit" or "bool" or of the form
|
blanchet@42730
|
577 |
"ALL x. x = A | x = B | x = C" are likely to lead to unsound proofs if types
|
blanchet@42730
|
578 |
are omitted. *)
|
blanchet@42944
|
579 |
fun is_dangerous_prop ctxt =
|
blanchet@42944
|
580 |
transform_elim_prop
|
blanchet@44393
|
581 |
#> (has_bound_or_var_of_type (is_type_surely_finite ctxt) orf
|
blanchet@42730
|
582 |
is_exhaustive_finite)
|
blanchet@42730
|
583 |
|
blanchet@39492
|
584 |
(* Important messages are important but not so important that users want to see
|
blanchet@39492
|
585 |
them each time. *)
|
blanchet@44649
|
586 |
val atp_important_message_keep_quotient = 25
|
blanchet@39492
|
587 |
|
blanchet@44416
|
588 |
fun choose_type_enc soundness best_type_enc format =
|
blanchet@44397
|
589 |
the_default best_type_enc
|
blanchet@44397
|
590 |
#> type_enc_from_string soundness
|
blanchet@44416
|
591 |
#> adjust_type_enc format
|
blanchet@42548
|
592 |
|
blanchet@43051
|
593 |
val metis_minimize_max_time = seconds 2.0
|
blanchet@43051
|
594 |
|
blanchet@45561
|
595 |
fun choose_minimize_command params minimize_command name preplay =
|
blanchet@45520
|
596 |
let
|
blanchet@45520
|
597 |
val (name, override_params) =
|
blanchet@45520
|
598 |
case preplay of
|
blanchet@45520
|
599 |
Played (reconstr, time) =>
|
blanchet@45520
|
600 |
if Time.<= (time, metis_minimize_max_time) then
|
blanchet@45561
|
601 |
extract_reconstructor params reconstr
|
blanchet@45520
|
602 |
else
|
blanchet@45520
|
603 |
(name, [])
|
blanchet@45520
|
604 |
| _ => (name, [])
|
blanchet@45520
|
605 |
in minimize_command override_params name end
|
blanchet@43051
|
606 |
|
blanchet@47962
|
607 |
fun repair_monomorph_context max_iters best_max_iters max_new_instances
|
blanchet@47962
|
608 |
best_max_new_instances =
|
blanchet@47962
|
609 |
Config.put Monomorph.max_rounds (max_iters |> the_default best_max_iters)
|
blanchet@47962
|
610 |
#> Config.put Monomorph.max_new_instances
|
blanchet@47962
|
611 |
(max_new_instances |> the_default best_max_new_instances)
|
boehmes@43230
|
612 |
#> Config.put Monomorph.keep_partial_instances false
|
blanchet@43226
|
613 |
|
blanchet@50494
|
614 |
fun suffix_for_mode Auto_Try = "_try"
|
blanchet@44509
|
615 |
| suffix_for_mode Try = "_try"
|
blanchet@44509
|
616 |
| suffix_for_mode Normal = ""
|
blanchet@50494
|
617 |
| suffix_for_mode MaSh = ""
|
blanchet@50494
|
618 |
| suffix_for_mode Auto_Minimize = "_min"
|
blanchet@44509
|
619 |
| suffix_for_mode Minimize = "_min"
|
blanchet@44509
|
620 |
|
blanchet@44423
|
621 |
(* Give the ATPs some slack before interrupting them the hard way. "z3_tptp" on
|
blanchet@43631
|
622 |
Linux appears to be the only ATP that does not honor its time limit. *)
|
blanchet@43690
|
623 |
val atp_timeout_slack = seconds 1.0
|
blanchet@43631
|
624 |
|
blanchet@48331
|
625 |
val mono_max_privileged_facts = 10
|
blanchet@48331
|
626 |
|
blanchet@43021
|
627 |
fun run_atp mode name
|
blanchet@48376
|
628 |
({exec, arguments, proof_delims, known_failures, prem_role, best_slices,
|
blanchet@48376
|
629 |
best_max_mono_iters, best_max_new_mono_instances, ...} : atp_config)
|
blanchet@46301
|
630 |
(params as {debug, verbose, overlord, type_enc, strict, lam_trans,
|
blanchet@48293
|
631 |
uncurried_aliases, max_facts, max_mono_iters,
|
blanchet@50020
|
632 |
max_new_mono_instances, isar_proofs, isar_shrink,
|
blanchet@46409
|
633 |
slice, timeout, preplay_timeout, ...})
|
blanchet@43037
|
634 |
minimize_command
|
blanchet@51010
|
635 |
({state, goal, subgoal, subgoal_count, factss = (_, facts) :: _, (* FIXME *)
|
blanchet@51007
|
636 |
...} : prover_problem) =
|
blanchet@38023
|
637 |
let
|
blanchet@42182
|
638 |
val thy = Proof.theory_of state
|
blanchet@39318
|
639 |
val ctxt = Proof.context_of state
|
blanchet@47946
|
640 |
val atp_mode =
|
blanchet@48143
|
641 |
if Config.get ctxt completish then Sledgehammer_Completish
|
blanchet@47946
|
642 |
else Sledgehammer
|
blanchet@43004
|
643 |
val (_, hyp_ts, concl_t) = strip_subgoal ctxt goal subgoal
|
blanchet@41159
|
644 |
val (dest_dir, problem_prefix) =
|
blanchet@41159
|
645 |
if overlord then overlord_file_location_for_prover name
|
blanchet@41159
|
646 |
else (Config.get ctxt dest_dir, Config.get ctxt problem_prefix)
|
blanchet@40061
|
647 |
val problem_file_name =
|
blanchet@41159
|
648 |
Path.basic (problem_prefix ^ (if overlord then "" else serial_string ()) ^
|
blanchet@44509
|
649 |
suffix_for_mode mode ^ "_" ^ string_of_int subgoal)
|
blanchet@48656
|
650 |
val prob_path =
|
blanchet@40059
|
651 |
if dest_dir = "" then
|
blanchet@40061
|
652 |
File.tmp_path problem_file_name
|
blanchet@40059
|
653 |
else if File.exists (Path.explode dest_dir) then
|
blanchet@40061
|
654 |
Path.append (Path.explode dest_dir) problem_file_name
|
blanchet@39003
|
655 |
else
|
blanchet@40059
|
656 |
error ("No such directory: " ^ quote dest_dir ^ ".")
|
blanchet@48376
|
657 |
val command0 =
|
blanchet@47055
|
658 |
case find_first (fn var => getenv var <> "") (fst exec) of
|
blanchet@48376
|
659 |
SOME var =>
|
blanchet@48376
|
660 |
let
|
blanchet@48376
|
661 |
val pref = getenv var ^ "/"
|
blanchet@48376
|
662 |
val paths = map (Path.explode o prefix pref) (snd exec)
|
blanchet@48376
|
663 |
in
|
blanchet@48376
|
664 |
case find_first File.exists paths of
|
blanchet@48376
|
665 |
SOME path => path
|
blanchet@48376
|
666 |
| NONE => error ("Bad executable: " ^ Path.print (hd paths) ^ ".")
|
blanchet@48376
|
667 |
end
|
blanchet@47055
|
668 |
| NONE => error ("The environment variable " ^ quote (hd (fst exec)) ^
|
blanchet@47055
|
669 |
" is not set.")
|
blanchet@38023
|
670 |
fun split_time s =
|
blanchet@38023
|
671 |
let
|
blanchet@42448
|
672 |
val split = String.tokens (fn c => str c = "\n")
|
blanchet@47737
|
673 |
val (output, t) =
|
blanchet@47737
|
674 |
s |> split |> (try split_last #> the_default ([], "0"))
|
blanchet@47737
|
675 |
|>> cat_lines
|
blanchet@42448
|
676 |
fun as_num f = f >> (fst o read_int)
|
blanchet@42448
|
677 |
val num = as_num (Scan.many1 Symbol.is_ascii_digit)
|
blanchet@42448
|
678 |
val digit = Scan.one Symbol.is_ascii_digit
|
blanchet@42448
|
679 |
val num3 = as_num (digit ::: digit ::: (digit >> single))
|
blanchet@42448
|
680 |
val time = num --| Scan.$$ "." -- num3 >> (fn (a, b) => a * 1000 + b)
|
blanchet@45381
|
681 |
val as_time =
|
blanchet@45381
|
682 |
raw_explode #> Scan.read Symbol.stopper time #> the_default 0
|
blanchet@47737
|
683 |
in (output, as_time t |> Time.fromMilliseconds) end
|
blanchet@48656
|
684 |
fun run () =
|
blanchet@48376
|
685 |
let
|
blanchet@48376
|
686 |
(* If slicing is disabled, we expand the last slice to fill the entire
|
blanchet@48376
|
687 |
time available. *)
|
blanchet@48376
|
688 |
val actual_slices = get_slices slice (best_slices ctxt)
|
blanchet@48376
|
689 |
val num_actual_slices = length actual_slices
|
blanchet@48376
|
690 |
fun monomorphize_facts facts =
|
blanchet@48376
|
691 |
let
|
blanchet@48376
|
692 |
val ctxt =
|
blanchet@48376
|
693 |
ctxt
|
blanchet@48376
|
694 |
|> repair_monomorph_context max_mono_iters best_max_mono_iters
|
blanchet@48376
|
695 |
max_new_mono_instances best_max_new_mono_instances
|
blanchet@48376
|
696 |
(* pseudo-theorem involving the same constants as the subgoal *)
|
blanchet@48376
|
697 |
val subgoal_th =
|
blanchet@48376
|
698 |
Logic.list_implies (hyp_ts, concl_t) |> Skip_Proof.make_thm thy
|
blanchet@48376
|
699 |
val rths =
|
blanchet@48376
|
700 |
facts |> chop mono_max_privileged_facts
|
blanchet@48376
|
701 |
|>> map (pair 1 o snd)
|
blanchet@48376
|
702 |
||> map (pair 2 o snd)
|
blanchet@48376
|
703 |
|> op @
|
blanchet@48376
|
704 |
|> cons (0, subgoal_th)
|
blanchet@48376
|
705 |
in
|
blanchet@48376
|
706 |
Monomorph.monomorph atp_schematic_consts_of rths ctxt |> fst |> tl
|
blanchet@48376
|
707 |
|> curry ListPair.zip (map fst facts)
|
blanchet@48376
|
708 |
|> maps (fn (name, rths) =>
|
blanchet@48376
|
709 |
map (pair name o zero_var_indexes o snd) rths)
|
blanchet@48376
|
710 |
end
|
blanchet@48376
|
711 |
fun run_slice time_left (cache_key, cache_value)
|
blanchet@48716
|
712 |
(slice, (time_frac,
|
blanchet@48376
|
713 |
(key as (best_max_facts, format, best_type_enc,
|
blanchet@48376
|
714 |
best_lam_trans, best_uncurried_aliases),
|
blanchet@48716
|
715 |
extra))) =
|
blanchet@38032
|
716 |
let
|
blanchet@48376
|
717 |
val num_facts =
|
blanchet@48376
|
718 |
length facts |> is_none max_facts ? Integer.min best_max_facts
|
blanchet@48376
|
719 |
val soundness = if strict then Strict else Non_Strict
|
blanchet@48376
|
720 |
val type_enc =
|
blanchet@48376
|
721 |
type_enc |> choose_type_enc soundness best_type_enc format
|
blanchet@48376
|
722 |
val sound = is_type_enc_sound type_enc
|
blanchet@48376
|
723 |
val real_ms = Real.fromInt o Time.toMilliseconds
|
blanchet@48376
|
724 |
val slice_timeout =
|
blanchet@50557
|
725 |
case time_left of
|
blanchet@50557
|
726 |
SOME time_left =>
|
blanchet@50557
|
727 |
((real_ms time_left
|
blanchet@50557
|
728 |
|> (if slice < num_actual_slices - 1 then
|
blanchet@50557
|
729 |
curry Real.min (time_frac * real_ms (the timeout))
|
blanchet@50557
|
730 |
else
|
blanchet@50557
|
731 |
I))
|
blanchet@50557
|
732 |
* 0.001)
|
blanchet@50557
|
733 |
|> seconds |> SOME
|
blanchet@50557
|
734 |
| NONE => NONE
|
blanchet@48376
|
735 |
val generous_slice_timeout =
|
blanchet@50558
|
736 |
if mode = MaSh then NONE
|
blanchet@50558
|
737 |
else Option.map (curry Time.+ atp_timeout_slack) slice_timeout
|
blanchet@48376
|
738 |
val _ =
|
blanchet@48376
|
739 |
if debug then
|
blanchet@48376
|
740 |
quote name ^ " slice #" ^ string_of_int (slice + 1) ^
|
blanchet@48376
|
741 |
" with " ^ string_of_int num_facts ^ " fact" ^
|
blanchet@50557
|
742 |
plural_s num_facts ^
|
blanchet@50557
|
743 |
(case slice_timeout of
|
blanchet@50557
|
744 |
SOME timeout => " for " ^ string_from_time timeout
|
blanchet@50557
|
745 |
| NONE => "") ^ "..."
|
blanchet@48376
|
746 |
|> Output.urgent_message
|
blanchet@48376
|
747 |
else
|
blanchet@48376
|
748 |
()
|
blanchet@48376
|
749 |
val readable_names = not (Config.get ctxt atp_full_names)
|
blanchet@48376
|
750 |
val lam_trans =
|
blanchet@48376
|
751 |
case lam_trans of
|
blanchet@48376
|
752 |
SOME s => s
|
blanchet@48376
|
753 |
| NONE => best_lam_trans
|
blanchet@48376
|
754 |
val uncurried_aliases =
|
blanchet@48376
|
755 |
case uncurried_aliases of
|
blanchet@48376
|
756 |
SOME b => b
|
blanchet@48376
|
757 |
| NONE => best_uncurried_aliases
|
blanchet@48376
|
758 |
val value as (atp_problem, _, fact_names, _, _) =
|
blanchet@48376
|
759 |
if cache_key = SOME key then
|
blanchet@48376
|
760 |
cache_value
|
blanchet@48376
|
761 |
else
|
blanchet@48376
|
762 |
facts
|
blanchet@48376
|
763 |
|> not sound
|
blanchet@48376
|
764 |
? filter_out (is_dangerous_prop ctxt o prop_of o snd)
|
blanchet@48376
|
765 |
|> take num_facts
|
blanchet@48376
|
766 |
|> not (is_type_enc_polymorphic type_enc) ? monomorphize_facts
|
blanchet@48376
|
767 |
|> map (apsnd prop_of)
|
blanchet@48376
|
768 |
|> prepare_atp_problem ctxt format prem_role type_enc atp_mode
|
blanchet@48376
|
769 |
lam_trans uncurried_aliases
|
blanchet@48376
|
770 |
readable_names true hyp_ts concl_t
|
blanchet@48376
|
771 |
fun sel_weights () = atp_problem_selection_weights atp_problem
|
blanchet@48376
|
772 |
fun ord_info () = atp_problem_term_order_info atp_problem
|
blanchet@48376
|
773 |
val ord = effective_term_order ctxt name
|
blanchet@49918
|
774 |
val full_proof = debug orelse isar_proofs
|
blanchet@50927
|
775 |
val args =
|
blanchet@50927
|
776 |
arguments ctxt full_proof extra
|
blanchet@50927
|
777 |
(slice_timeout |> the_default one_day)
|
blanchet@50927
|
778 |
(File.shell_path prob_path) (ord, ord_info, sel_weights)
|
blanchet@48376
|
779 |
val command =
|
blanchet@50927
|
780 |
"(exec 2>&1; " ^ File.shell_path command0 ^ " " ^ args ^ " " ^ ")"
|
blanchet@48532
|
781 |
|> enclose "TIMEFORMAT='%3R'; { time " " ; }"
|
blanchet@48376
|
782 |
val _ =
|
blanchet@48376
|
783 |
atp_problem
|
blanchet@48376
|
784 |
|> lines_for_atp_problem format ord ord_info
|
blanchet@48376
|
785 |
|> cons ("% " ^ command ^ "\n")
|
blanchet@48656
|
786 |
|> File.write_list prob_path
|
blanchet@48376
|
787 |
val ((output, run_time), (atp_proof, outcome)) =
|
blanchet@50557
|
788 |
time_limit generous_slice_timeout Isabelle_System.bash_output
|
blanchet@50557
|
789 |
command
|
blanchet@48376
|
790 |
|>> (if overlord then
|
blanchet@48376
|
791 |
prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n")
|
blanchet@48376
|
792 |
else
|
blanchet@48376
|
793 |
I)
|
blanchet@48376
|
794 |
|> fst |> split_time
|
blanchet@48376
|
795 |
|> (fn accum as (output, _) =>
|
blanchet@48376
|
796 |
(accum,
|
blanchet@48716
|
797 |
extract_tstplike_proof_and_outcome verbose proof_delims
|
blanchet@48716
|
798 |
known_failures output
|
blanchet@48376
|
799 |
|>> atp_proof_from_tstplike_proof atp_problem
|
blanchet@48376
|
800 |
handle UNRECOGNIZED_ATP_PROOF () =>
|
blanchet@48376
|
801 |
([], SOME ProofIncomplete)))
|
blanchet@48376
|
802 |
handle TimeLimit.TimeOut =>
|
blanchet@50557
|
803 |
(("", the slice_timeout), ([], SOME TimedOut))
|
blanchet@48376
|
804 |
val outcome =
|
blanchet@48376
|
805 |
case outcome of
|
blanchet@48376
|
806 |
NONE =>
|
blanchet@48376
|
807 |
(case used_facts_in_unsound_atp_proof ctxt fact_names atp_proof
|
blanchet@48376
|
808 |
|> Option.map (sort string_ord) of
|
blanchet@48376
|
809 |
SOME facts =>
|
blanchet@48376
|
810 |
let
|
blanchet@48376
|
811 |
val failure =
|
blanchet@48376
|
812 |
UnsoundProof (is_type_enc_sound type_enc, facts)
|
blanchet@48376
|
813 |
in
|
blanchet@48376
|
814 |
if debug then (warning (string_for_failure failure); NONE)
|
blanchet@48376
|
815 |
else SOME failure
|
blanchet@48376
|
816 |
end
|
blanchet@48376
|
817 |
| NONE => NONE)
|
blanchet@48376
|
818 |
| _ => outcome
|
blanchet@48376
|
819 |
in ((SOME key, value), (output, run_time, atp_proof, outcome)) end
|
blanchet@48376
|
820 |
val timer = Timer.startRealTimer ()
|
blanchet@48376
|
821 |
fun maybe_run_slice slice
|
blanchet@48376
|
822 |
(result as (cache, (_, run_time0, _, SOME _))) =
|
blanchet@48376
|
823 |
let
|
blanchet@50557
|
824 |
val time_left =
|
blanchet@50557
|
825 |
Option.map
|
blanchet@50557
|
826 |
(fn timeout => Time.- (timeout, Timer.checkRealTimer timer))
|
blanchet@50557
|
827 |
timeout
|
blanchet@48376
|
828 |
in
|
blanchet@50557
|
829 |
if time_left <> NONE andalso
|
blanchet@50557
|
830 |
Time.<= (the time_left, Time.zeroTime) then
|
blanchet@48376
|
831 |
result
|
blanchet@48376
|
832 |
else
|
blanchet@48376
|
833 |
run_slice time_left cache slice
|
blanchet@48376
|
834 |
|> (fn (cache, (output, run_time, atp_proof, outcome)) =>
|
blanchet@48376
|
835 |
(cache, (output, Time.+ (run_time0, run_time),
|
blanchet@48376
|
836 |
atp_proof, outcome)))
|
blanchet@48376
|
837 |
end
|
blanchet@48376
|
838 |
| maybe_run_slice _ result = result
|
blanchet@48376
|
839 |
in
|
blanchet@48376
|
840 |
((NONE, ([], Symtab.empty, Vector.fromList [], [], Symtab.empty)),
|
blanchet@48376
|
841 |
("", Time.zeroTime, [], SOME InternalError))
|
blanchet@48376
|
842 |
|> fold maybe_run_slice actual_slices
|
blanchet@48376
|
843 |
end
|
blanchet@38023
|
844 |
(* If the problem file has not been exported, remove it; otherwise, export
|
blanchet@38023
|
845 |
the proof file too. *)
|
blanchet@48656
|
846 |
fun clean_up () =
|
blanchet@48656
|
847 |
if dest_dir = "" then (try File.rm prob_path; ()) else ()
|
blanchet@48656
|
848 |
fun export (_, (output, _, _, _)) =
|
blanchet@48376
|
849 |
if dest_dir = "" then ()
|
blanchet@48656
|
850 |
else File.write (Path.explode (Path.implode prob_path ^ "_proof")) output
|
blanchet@46407
|
851 |
val ((_, (_, pool, fact_names, _, sym_tab)),
|
blanchet@46407
|
852 |
(output, run_time, atp_proof, outcome)) =
|
blanchet@48656
|
853 |
with_cleanup clean_up run () |> tap export
|
blanchet@39492
|
854 |
val important_message =
|
blanchet@43021
|
855 |
if mode = Normal andalso
|
blanchet@42609
|
856 |
random_range 0 (atp_important_message_keep_quotient - 1) = 0 then
|
blanchet@39492
|
857 |
extract_important_message output
|
blanchet@39492
|
858 |
else
|
blanchet@39492
|
859 |
""
|
blanchet@43261
|
860 |
val (used_facts, preplay, message, message_tail) =
|
blanchet@38023
|
861 |
case outcome of
|
blanchet@38023
|
862 |
NONE =>
|
blanchet@43033
|
863 |
let
|
blanchet@45551
|
864 |
val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof
|
blanchet@45590
|
865 |
val needs_full_types = is_typed_helper_used_in_atp_proof atp_proof
|
blanchet@45521
|
866 |
val reconstrs =
|
blanchet@45554
|
867 |
bunch_of_reconstructors needs_full_types
|
blanchet@45560
|
868 |
(lam_trans_from_atp_proof atp_proof
|
blanchet@46405
|
869 |
o (fn desperate => if desperate then hide_lamsN
|
blanchet@46405
|
870 |
else metis_default_lam_trans))
|
blanchet@43033
|
871 |
in
|
blanchet@43052
|
872 |
(used_facts,
|
blanchet@50669
|
873 |
Lazy.lazy (fn () =>
|
blanchet@50669
|
874 |
let
|
blanchet@50669
|
875 |
val used_pairs =
|
blanchet@51005
|
876 |
facts |> filter_used_facts false used_facts
|
blanchet@50669
|
877 |
in
|
blanchet@50669
|
878 |
play_one_line_proof mode debug verbose preplay_timeout
|
blanchet@50669
|
879 |
used_pairs state subgoal (hd reconstrs) reconstrs
|
blanchet@50669
|
880 |
end),
|
blanchet@43052
|
881 |
fn preplay =>
|
blanchet@43052
|
882 |
let
|
blanchet@49921
|
883 |
val _ =
|
blanchet@49921
|
884 |
if verbose then
|
blanchet@49921
|
885 |
Output.urgent_message "Generating proof text..."
|
blanchet@49921
|
886 |
else
|
blanchet@49921
|
887 |
()
|
blanchet@43052
|
888 |
val isar_params =
|
blanchet@50020
|
889 |
(debug, verbose, preplay_timeout, isar_shrink,
|
blanchet@50004
|
890 |
pool, fact_names, sym_tab, atp_proof, goal)
|
blanchet@43052
|
891 |
val one_line_params =
|
blanchet@43052
|
892 |
(preplay, proof_banner mode name, used_facts,
|
blanchet@45561
|
893 |
choose_minimize_command params minimize_command name preplay,
|
blanchet@43052
|
894 |
subgoal, subgoal_count)
|
blanchet@48799
|
895 |
val num_chained = length (#facts (Proof.goal state))
|
blanchet@48799
|
896 |
in
|
blanchet@49918
|
897 |
proof_text ctxt isar_proofs isar_params num_chained
|
blanchet@48799
|
898 |
one_line_params
|
blanchet@48799
|
899 |
end,
|
blanchet@43261
|
900 |
(if verbose then
|
blanchet@45381
|
901 |
"\nATP real CPU time: " ^ string_from_time run_time ^ "."
|
blanchet@43261
|
902 |
else
|
blanchet@43261
|
903 |
"") ^
|
blanchet@43261
|
904 |
(if important_message <> "" then
|
blanchet@43261
|
905 |
"\n\nImportant message from Dr. Geoff Sutcliffe:\n" ^
|
blanchet@43261
|
906 |
important_message
|
blanchet@43261
|
907 |
else
|
blanchet@43261
|
908 |
""))
|
blanchet@43033
|
909 |
end
|
blanchet@43052
|
910 |
| SOME failure =>
|
blanchet@50669
|
911 |
([], Lazy.value (Failed_to_Play plain_metis),
|
blanchet@45519
|
912 |
fn _ => string_for_failure failure, "")
|
blanchet@38023
|
913 |
in
|
blanchet@51009
|
914 |
{outcome = outcome, used_facts = used_facts, used_from = facts (* ### *),
|
blanchet@51009
|
915 |
run_time = run_time, preplay = preplay, message = message,
|
blanchet@51009
|
916 |
message_tail = message_tail}
|
blanchet@38023
|
917 |
end
|
blanchet@38023
|
918 |
|
blanchet@40669
|
919 |
(* "SMT_Failure.Abnormal_Termination" carries the solver's return code. Until
|
blanchet@40669
|
920 |
these are sorted out properly in the SMT module, we have to interpret these
|
blanchet@40669
|
921 |
ourselves. *)
|
blanchet@40684
|
922 |
val remote_smt_failures =
|
blanchet@43631
|
923 |
[(2, NoLibwwwPerl),
|
blanchet@43631
|
924 |
(22, CantConnect)]
|
blanchet@40684
|
925 |
val z3_failures =
|
blanchet@41236
|
926 |
[(101, OutOfResources),
|
blanchet@41236
|
927 |
(103, MalformedInput),
|
blanchet@50667
|
928 |
(110, MalformedInput),
|
blanchet@50667
|
929 |
(112, TimedOut)]
|
blanchet@40684
|
930 |
val unix_failures =
|
blanchet@48797
|
931 |
[(138, Crashed),
|
blanchet@48797
|
932 |
(139, Crashed)]
|
blanchet@43631
|
933 |
val smt_failures = remote_smt_failures @ z3_failures @ unix_failures
|
blanchet@40555
|
934 |
|
blanchet@42100
|
935 |
fun failure_from_smt_failure (SMT_Failure.Counterexample {is_real_cex, ...}) =
|
blanchet@43050
|
936 |
if is_real_cex then Unprovable else GaveUp
|
blanchet@41222
|
937 |
| failure_from_smt_failure SMT_Failure.Time_Out = TimedOut
|
blanchet@41222
|
938 |
| failure_from_smt_failure (SMT_Failure.Abnormal_Termination code) =
|
blanchet@41222
|
939 |
(case AList.lookup (op =) smt_failures code of
|
blanchet@40684
|
940 |
SOME failure => failure
|
blanchet@41259
|
941 |
| NONE => UnknownError ("Abnormal termination with exit code " ^
|
blanchet@41259
|
942 |
string_of_int code ^ "."))
|
blanchet@41222
|
943 |
| failure_from_smt_failure SMT_Failure.Out_Of_Memory = OutOfResources
|
blanchet@41222
|
944 |
| failure_from_smt_failure (SMT_Failure.Other_Failure msg) =
|
blanchet@42061
|
945 |
UnknownError msg
|
blanchet@40063
|
946 |
|
blanchet@40698
|
947 |
(* FUDGE *)
|
blanchet@42646
|
948 |
val smt_max_slices =
|
blanchet@42646
|
949 |
Attrib.setup_config_int @{binding sledgehammer_smt_max_slices} (K 8)
|
blanchet@42646
|
950 |
val smt_slice_fact_frac =
|
blanchet@42646
|
951 |
Attrib.setup_config_real @{binding sledgehammer_smt_slice_fact_frac} (K 0.5)
|
blanchet@42646
|
952 |
val smt_slice_time_frac =
|
blanchet@42646
|
953 |
Attrib.setup_config_real @{binding sledgehammer_smt_slice_time_frac} (K 0.5)
|
blanchet@42646
|
954 |
val smt_slice_min_secs =
|
blanchet@42646
|
955 |
Attrib.setup_config_int @{binding sledgehammer_smt_slice_min_secs} (K 5)
|
blanchet@40409
|
956 |
|
blanchet@50759
|
957 |
fun smt_filter_loop name
|
blanchet@42724
|
958 |
({debug, verbose, overlord, max_mono_iters,
|
blanchet@45706
|
959 |
max_new_mono_instances, timeout, slice, ...} : params)
|
blanchet@50486
|
960 |
state goal i =
|
blanchet@40409
|
961 |
let
|
blanchet@50759
|
962 |
fun repair_context ctxt =
|
blanchet@50759
|
963 |
ctxt |> select_smt_solver name
|
blanchet@50759
|
964 |
|> Config.put SMT_Config.verbose debug
|
blanchet@50759
|
965 |
|> (if overlord then
|
blanchet@50759
|
966 |
Config.put SMT_Config.debug_files
|
blanchet@50759
|
967 |
(overlord_file_location_for_prover name
|
blanchet@50759
|
968 |
|> (fn (path, name) => path ^ "/" ^ name))
|
blanchet@50759
|
969 |
else
|
blanchet@50759
|
970 |
I)
|
blanchet@50759
|
971 |
|> Config.put SMT_Config.infer_triggers
|
blanchet@50759
|
972 |
(Config.get ctxt smt_triggers)
|
blanchet@50759
|
973 |
val ctxt = Proof.context_of state |> repair_context
|
blanchet@50759
|
974 |
val state = state |> Proof.map_context (K ctxt)
|
blanchet@45706
|
975 |
val max_slices = if slice then Config.get ctxt smt_max_slices else 1
|
blanchet@51009
|
976 |
fun do_slice timeout slice outcome0 time_so_far weighted_facts =
|
blanchet@40553
|
977 |
let
|
blanchet@40553
|
978 |
val timer = Timer.startRealTimer ()
|
blanchet@42724
|
979 |
val state =
|
blanchet@42724
|
980 |
state |> Proof.map_context
|
blanchet@43267
|
981 |
(repair_monomorph_context max_mono_iters
|
blanchet@47962
|
982 |
default_max_mono_iters max_new_mono_instances
|
blanchet@47962
|
983 |
default_max_new_mono_instances)
|
blanchet@42443
|
984 |
val slice_timeout =
|
blanchet@50557
|
985 |
if slice < max_slices andalso timeout <> NONE then
|
blanchet@50557
|
986 |
let val ms = timeout |> the |> Time.toMilliseconds in
|
blanchet@50557
|
987 |
Int.min (ms,
|
blanchet@50557
|
988 |
Int.max (1000 * Config.get ctxt smt_slice_min_secs,
|
blanchet@50557
|
989 |
Real.ceil (Config.get ctxt smt_slice_time_frac
|
blanchet@50557
|
990 |
* Real.fromInt ms)))
|
blanchet@50557
|
991 |
|> Time.fromMilliseconds |> SOME
|
blanchet@50557
|
992 |
end
|
blanchet@40553
|
993 |
else
|
blanchet@40553
|
994 |
timeout
|
blanchet@51009
|
995 |
val num_facts = length weighted_facts
|
blanchet@40553
|
996 |
val _ =
|
blanchet@42614
|
997 |
if debug then
|
blanchet@42614
|
998 |
quote name ^ " slice " ^ string_of_int slice ^ " with " ^
|
blanchet@50557
|
999 |
string_of_int num_facts ^ " fact" ^ plural_s num_facts ^
|
blanchet@50557
|
1000 |
(case slice_timeout of
|
blanchet@50557
|
1001 |
SOME timeout => " for " ^ string_from_time timeout
|
blanchet@50557
|
1002 |
| NONE => "") ^ "..."
|
blanchet@40553
|
1003 |
|> Output.urgent_message
|
blanchet@40553
|
1004 |
else
|
blanchet@40553
|
1005 |
()
|
blanchet@41168
|
1006 |
val birth = Timer.checkRealTimer timer
|
blanchet@41171
|
1007 |
val _ =
|
blanchet@41211
|
1008 |
if debug then Output.urgent_message "Invoking SMT solver..." else ()
|
blanchet@50486
|
1009 |
val state_facts = these (try (#facts o Proof.goal) state)
|
blanchet@41209
|
1010 |
val (outcome, used_facts) =
|
blanchet@51009
|
1011 |
SMT_Solver.smt_filter_preprocess ctxt state_facts goal weighted_facts
|
blanchet@51009
|
1012 |
i
|
blanchet@50557
|
1013 |
|> SMT_Solver.smt_filter_apply (slice_timeout |> the_default one_day)
|
blanchet@41239
|
1014 |
|> (fn {outcome, used_facts} => (outcome, used_facts))
|
blanchet@41209
|
1015 |
handle exn => if Exn.is_interrupt exn then
|
blanchet@41209
|
1016 |
reraise exn
|
blanchet@41209
|
1017 |
else
|
blanchet@42061
|
1018 |
(ML_Compiler.exn_message exn
|
blanchet@41209
|
1019 |
|> SMT_Failure.Other_Failure |> SOME, [])
|
blanchet@41168
|
1020 |
val death = Timer.checkRealTimer timer
|
blanchet@40553
|
1021 |
val outcome0 = if is_none outcome0 then SOME outcome else outcome0
|
blanchet@41168
|
1022 |
val time_so_far = Time.+ (time_so_far, Time.- (death, birth))
|
blanchet@40553
|
1023 |
val too_many_facts_perhaps =
|
blanchet@40553
|
1024 |
case outcome of
|
blanchet@40553
|
1025 |
NONE => false
|
blanchet@40553
|
1026 |
| SOME (SMT_Failure.Counterexample _) => false
|
blanchet@42443
|
1027 |
| SOME SMT_Failure.Time_Out => slice_timeout <> timeout
|
blanchet@42614
|
1028 |
| SOME (SMT_Failure.Abnormal_Termination _) => true (* kind of *)
|
blanchet@40553
|
1029 |
| SOME SMT_Failure.Out_Of_Memory => true
|
blanchet@41211
|
1030 |
| SOME (SMT_Failure.Other_Failure _) => true
|
blanchet@50557
|
1031 |
val timeout =
|
blanchet@50557
|
1032 |
Option.map
|
blanchet@50557
|
1033 |
(fn timeout => Time.- (timeout, Timer.checkRealTimer timer))
|
blanchet@50557
|
1034 |
timeout
|
blanchet@40553
|
1035 |
in
|
blanchet@42443
|
1036 |
if too_many_facts_perhaps andalso slice < max_slices andalso
|
blanchet@50557
|
1037 |
num_facts > 0 andalso
|
blanchet@50557
|
1038 |
(timeout = NONE orelse Time.> (the timeout, Time.zeroTime)) then
|
blanchet@41169
|
1039 |
let
|
blanchet@42614
|
1040 |
val new_num_facts =
|
blanchet@42646
|
1041 |
Real.ceil (Config.get ctxt smt_slice_fact_frac
|
blanchet@42646
|
1042 |
* Real.fromInt num_facts)
|
blanchet@42614
|
1043 |
val _ =
|
blanchet@42614
|
1044 |
if verbose andalso is_some outcome then
|
blanchet@42614
|
1045 |
quote name ^ " invoked with " ^ string_of_int num_facts ^
|
blanchet@42614
|
1046 |
" fact" ^ plural_s num_facts ^ ": " ^
|
blanchet@42614
|
1047 |
string_for_failure (failure_from_smt_failure (the outcome)) ^
|
blanchet@42614
|
1048 |
" Retrying with " ^ string_of_int new_num_facts ^ " fact" ^
|
blanchet@42638
|
1049 |
plural_s new_num_facts ^ "..."
|
blanchet@42614
|
1050 |
|> Output.urgent_message
|
blanchet@42614
|
1051 |
else
|
blanchet@42614
|
1052 |
()
|
blanchet@42443
|
1053 |
in
|
blanchet@51009
|
1054 |
weighted_facts
|
blanchet@51009
|
1055 |
|> take new_num_facts
|
blanchet@51009
|
1056 |
|> do_slice timeout (slice + 1) outcome0 time_so_far
|
blanchet@42443
|
1057 |
end
|
blanchet@40553
|
1058 |
else
|
blanchet@40553
|
1059 |
{outcome = if is_none outcome then NONE else the outcome0,
|
blanchet@51009
|
1060 |
used_facts = used_facts, used_from = map (apsnd snd) weighted_facts,
|
blanchet@51009
|
1061 |
run_time = time_so_far}
|
blanchet@40409
|
1062 |
end
|
blanchet@42443
|
1063 |
in do_slice timeout 1 NONE Time.zeroTime end
|
blanchet@40409
|
1064 |
|
blanchet@43052
|
1065 |
fun run_smt_solver mode name (params as {debug, verbose, preplay_timeout, ...})
|
blanchet@43011
|
1066 |
minimize_command
|
blanchet@51010
|
1067 |
({state, goal, subgoal, subgoal_count, factss = (_, facts) :: _, (* FIXME *)
|
blanchet@51007
|
1068 |
...} : prover_problem) =
|
blanchet@36379
|
1069 |
let
|
blanchet@41242
|
1070 |
val ctxt = Proof.context_of state
|
blanchet@41256
|
1071 |
val num_facts = length facts
|
blanchet@51005
|
1072 |
val facts =
|
blanchet@51005
|
1073 |
facts ~~ (0 upto num_facts - 1)
|
blanchet@51005
|
1074 |
|> map (weight_smt_fact ctxt num_facts)
|
blanchet@51009
|
1075 |
val {outcome, used_facts = used_pairs, used_from, run_time} =
|
blanchet@50759
|
1076 |
smt_filter_loop name params state goal subgoal facts
|
blanchet@45781
|
1077 |
val used_facts = used_pairs |> map fst
|
blanchet@41222
|
1078 |
val outcome = outcome |> Option.map failure_from_smt_failure
|
blanchet@43261
|
1079 |
val (preplay, message, message_tail) =
|
blanchet@40184
|
1080 |
case outcome of
|
blanchet@40184
|
1081 |
NONE =>
|
blanchet@50669
|
1082 |
(Lazy.lazy (fn () =>
|
blanchet@50669
|
1083 |
play_one_line_proof mode debug verbose preplay_timeout used_pairs
|
blanchet@50669
|
1084 |
state subgoal SMT
|
blanchet@50669
|
1085 |
(bunch_of_reconstructors false (fn desperate =>
|
blanchet@50669
|
1086 |
if desperate then liftingN else metis_default_lam_trans))),
|
blanchet@43052
|
1087 |
fn preplay =>
|
blanchet@43052
|
1088 |
let
|
blanchet@43052
|
1089 |
val one_line_params =
|
blanchet@43052
|
1090 |
(preplay, proof_banner mode name, used_facts,
|
blanchet@45561
|
1091 |
choose_minimize_command params minimize_command name preplay,
|
blanchet@43052
|
1092 |
subgoal, subgoal_count)
|
blanchet@48799
|
1093 |
val num_chained = length (#facts (Proof.goal state))
|
blanchet@48799
|
1094 |
in one_line_proof_text num_chained one_line_params end,
|
blanchet@43261
|
1095 |
if verbose then
|
blanchet@45370
|
1096 |
"\nSMT solver real CPU time: " ^ string_from_time run_time ^ "."
|
blanchet@43261
|
1097 |
else
|
blanchet@43261
|
1098 |
"")
|
blanchet@43166
|
1099 |
| SOME failure =>
|
blanchet@50669
|
1100 |
(Lazy.value (Failed_to_Play plain_metis),
|
blanchet@50669
|
1101 |
fn _ => string_for_failure failure, "")
|
blanchet@40063
|
1102 |
in
|
blanchet@51009
|
1103 |
{outcome = outcome, used_facts = used_facts, used_from = used_from,
|
blanchet@51009
|
1104 |
run_time = run_time, preplay = preplay, message = message,
|
blanchet@51009
|
1105 |
message_tail = message_tail}
|
blanchet@40063
|
1106 |
end
|
blanchet@40063
|
1107 |
|
blanchet@45520
|
1108 |
fun run_reconstructor mode name
|
blanchet@45561
|
1109 |
(params as {debug, verbose, timeout, type_enc, lam_trans, ...})
|
blanchet@45379
|
1110 |
minimize_command
|
blanchet@51010
|
1111 |
({state, subgoal, subgoal_count, factss = (_, facts) :: _, ...}
|
blanchet@51007
|
1112 |
: prover_problem) =
|
blanchet@43050
|
1113 |
let
|
blanchet@45520
|
1114 |
val reconstr =
|
blanchet@45520
|
1115 |
if name = metisN then
|
blanchet@45520
|
1116 |
Metis (type_enc |> the_default (hd partial_type_encs),
|
blanchet@45520
|
1117 |
lam_trans |> the_default metis_default_lam_trans)
|
blanchet@45520
|
1118 |
else if name = smtN then
|
blanchet@45520
|
1119 |
SMT
|
blanchet@45520
|
1120 |
else
|
blanchet@45520
|
1121 |
raise Fail ("unknown reconstructor: " ^ quote name)
|
blanchet@51005
|
1122 |
val used_facts = facts |> map fst
|
blanchet@43050
|
1123 |
in
|
blanchet@45379
|
1124 |
case play_one_line_proof (if mode = Minimize then Normal else mode) debug
|
blanchet@51005
|
1125 |
verbose timeout facts state subgoal reconstr
|
blanchet@45520
|
1126 |
[reconstr] of
|
blanchet@43050
|
1127 |
play as Played (_, time) =>
|
blanchet@51009
|
1128 |
{outcome = NONE, used_facts = used_facts, used_from = facts,
|
blanchet@51009
|
1129 |
run_time = time, preplay = Lazy.value play,
|
blanchet@45561
|
1130 |
message =
|
blanchet@45561
|
1131 |
fn play =>
|
blanchet@45561
|
1132 |
let
|
blanchet@45561
|
1133 |
val (_, override_params) = extract_reconstructor params reconstr
|
blanchet@45561
|
1134 |
val one_line_params =
|
blanchet@45561
|
1135 |
(play, proof_banner mode name, used_facts,
|
blanchet@45561
|
1136 |
minimize_command override_params name, subgoal,
|
blanchet@45561
|
1137 |
subgoal_count)
|
blanchet@48799
|
1138 |
val num_chained = length (#facts (Proof.goal state))
|
blanchet@48799
|
1139 |
in one_line_proof_text num_chained one_line_params end,
|
blanchet@43261
|
1140 |
message_tail = ""}
|
blanchet@43052
|
1141 |
| play =>
|
blanchet@43166
|
1142 |
let
|
blanchet@43166
|
1143 |
val failure = case play of Failed_to_Play _ => GaveUp | _ => TimedOut
|
blanchet@43166
|
1144 |
in
|
blanchet@51009
|
1145 |
{outcome = SOME failure, used_facts = [], used_from = [],
|
blanchet@51009
|
1146 |
run_time = Time.zeroTime, preplay = Lazy.value play,
|
blanchet@50669
|
1147 |
message = fn _ => string_for_failure failure, message_tail = ""}
|
blanchet@43050
|
1148 |
end
|
blanchet@43050
|
1149 |
end
|
blanchet@43050
|
1150 |
|
blanchet@43021
|
1151 |
fun get_prover ctxt mode name =
|
wenzelm@42361
|
1152 |
let val thy = Proof_Context.theory_of ctxt in
|
blanchet@45379
|
1153 |
if is_reconstructor name then run_reconstructor mode name
|
blanchet@47606
|
1154 |
else if is_atp thy name then run_atp mode name (get_atp thy name ())
|
blanchet@43052
|
1155 |
else if is_smt_prover ctxt name then run_smt_solver mode name
|
blanchet@43052
|
1156 |
else error ("No such prover: " ^ name ^ ".")
|
blanchet@40941
|
1157 |
end
|
blanchet@40063
|
1158 |
|
wenzelm@28582
|
1159 |
end;
|