sultana@48348
|
1 |
(* Title: HOL/Mirabelle/Actions/mirabelle_sledgehammer.ML
|
wenzelm@32564
|
2 |
Author: Jasmin Blanchette and Sascha Boehme and Tobias Nipkow, TU Munich
|
boehmes@32385
|
3 |
*)
|
boehmes@32385
|
4 |
|
boehmes@32385
|
5 |
structure Mirabelle_Sledgehammer : MIRABELLE_ACTION =
|
boehmes@32385
|
6 |
struct
|
boehmes@32385
|
7 |
|
sultana@48351
|
8 |
(*To facilitate synching the description of Mirabelle Sledgehammer parameters
|
sultana@48351
|
9 |
(in ../lib/Tools/mirabelle) with the parameters actually used by this
|
sultana@48351
|
10 |
interface, the former extracts PARAMETER and DESCRIPTION from code below which
|
sultana@48351
|
11 |
has this pattern (provided it appears in a single line):
|
sultana@48351
|
12 |
val .*K = "PARAMETER" (*DESCRIPTION*)
|
sultana@48351
|
13 |
*)
|
sultana@48351
|
14 |
(*NOTE: descriptions mention parameters (particularly NAME) without a defined range.*)
|
sultana@48351
|
15 |
val proverK = "prover" (*=NAME: name of the external prover to call*)
|
sultana@48351
|
16 |
val prover_timeoutK = "prover_timeout" (*=TIME: timeout for invoked ATP (seconds of process time)*)
|
sultana@48351
|
17 |
val keepK = "keep" (*=PATH: path where to keep temporary files created by sledgehammer*)
|
sultana@48351
|
18 |
val minimizeK = "minimize" (*: enable minimization of theorem set found by sledgehammer*)
|
sultana@48351
|
19 |
(*refers to minimization attempted by Mirabelle*)
|
sultana@48351
|
20 |
val minimize_timeoutK = "minimize_timeout" (*=TIME: timeout for each minimization step (seconds of*)
|
sultana@48351
|
21 |
|
sultana@48351
|
22 |
val reconstructorK = "reconstructor" (*=NAME: how to reconstruct proofs (ie. using metis/smt)*)
|
sultana@48351
|
23 |
val metis_ftK = "metis_ft" (*: apply metis with fully-typed encoding to the theorems found by sledgehammer*)
|
sultana@48351
|
24 |
|
sultana@48351
|
25 |
val max_relevantK = "max_relevant" (*=NUM: max. relevant clauses to use*)
|
sultana@48351
|
26 |
val max_callsK = "max_calls" (*=NUM: max. no. of calls to sledgehammer*)
|
sultana@48351
|
27 |
val preplay_timeoutK = "preplay_timeout" (*=TIME: timeout for finding reconstructed proof*)
|
sultana@48351
|
28 |
val sh_minimizeK = "sh_minimize" (*: instruct sledgehammer to run its minimizer*)
|
sultana@48351
|
29 |
|
sultana@48351
|
30 |
val check_trivialK = "check_trivial" (*: check if goals are "trivial" (false by default)*)
|
sultana@48351
|
31 |
val type_encK = "type_enc" (*=STRING: type encoding scheme*)
|
sultana@48351
|
32 |
val lam_transK = "lam_trans" (*=STRING: lambda translation scheme*)
|
sultana@48351
|
33 |
val strictK = "strict" (*=BOOL: run in strict mode*)
|
sultana@48351
|
34 |
val sliceK = "slice" (*=BOOL: allow sledgehammer-level strategy-scheduling*)
|
sultana@48351
|
35 |
val uncurried_aliasesK = "uncurried_aliases" (*=SMART_BOOL: use fresh function names to alias curried applications*)
|
sultana@48351
|
36 |
val e_selection_heuristicK = "e_selection_heuristic" (*: FIXME*)
|
sultana@48351
|
37 |
val term_orderK = "term_order" (*: FIXME*)
|
sultana@48351
|
38 |
val force_sosK = "force_sos" (*: use SOS*)
|
sultana@48351
|
39 |
val max_new_mono_instancesK = "max_new_mono_instances" (*=NUM: max. new monomorphic instances*)
|
sultana@48351
|
40 |
val max_mono_itersK = "max_mono_iters" (*=NUM: max. iterations of monomorphiser*)
|
blanchet@45305
|
41 |
|
boehmes@32521
|
42 |
fun sh_tag id = "#" ^ string_of_int id ^ " sledgehammer: "
|
boehmes@32525
|
43 |
fun minimize_tag id = "#" ^ string_of_int id ^ " minimize (sledgehammer): "
|
blanchet@40915
|
44 |
fun reconstructor_tag reconstructor id =
|
blanchet@40915
|
45 |
"#" ^ string_of_int id ^ " " ^ (!reconstructor) ^ " (sledgehammer): "
|
boehmes@32521
|
46 |
|
boehmes@32525
|
47 |
val separator = "-----"
|
boehmes@32525
|
48 |
|
sultana@48352
|
49 |
(*FIXME sensible to have Mirabelle-level Sledgehammer defaults?*)
|
sultana@48352
|
50 |
(*defaults used in this Mirabelle action*)
|
sultana@47696
|
51 |
val preplay_timeout_default = "4"
|
sultana@48352
|
52 |
val lam_trans_default = "smart"
|
sultana@48352
|
53 |
val uncurried_aliases_default = "smart"
|
sultana@48352
|
54 |
val type_enc_default = "smart"
|
sultana@48352
|
55 |
val strict_default = "false"
|
sultana@48352
|
56 |
val max_relevant_default = "smart"
|
sultana@48352
|
57 |
val slice_default = "true"
|
sultana@48352
|
58 |
val max_calls_default = "10000000"
|
sultana@48352
|
59 |
val trivial_default = "false"
|
sultana@48352
|
60 |
val minimize_timeout_default = 5
|
sultana@47697
|
61 |
|
sultana@47697
|
62 |
(*If a key is present in args then augment a list with its pair*)
|
sultana@47697
|
63 |
(*This is used to avoid fixing default values at the Mirabelle level, and
|
sultana@47697
|
64 |
instead use the default values of the tool (Sledgehammer in this case).*)
|
sultana@47697
|
65 |
fun available_parameter args key label list =
|
sultana@47697
|
66 |
let
|
sultana@47697
|
67 |
val value = AList.lookup (op =) args key
|
sultana@47697
|
68 |
in if is_some value then (label, the value) :: list else list end
|
sultana@47697
|
69 |
|
boehmes@32521
|
70 |
|
nipkow@32549
|
71 |
datatype sh_data = ShData of {
|
nipkow@32549
|
72 |
calls: int,
|
nipkow@32549
|
73 |
success: int,
|
blanchet@39583
|
74 |
nontriv_calls: int,
|
blanchet@39583
|
75 |
nontriv_success: int,
|
nipkow@32585
|
76 |
lemmas: int,
|
nipkow@32810
|
77 |
max_lems: int,
|
nipkow@32549
|
78 |
time_isa: int,
|
blanchet@40243
|
79 |
time_prover: int,
|
blanchet@40243
|
80 |
time_prover_fail: int}
|
boehmes@32521
|
81 |
|
blanchet@40915
|
82 |
datatype re_data = ReData of {
|
nipkow@32549
|
83 |
calls: int,
|
nipkow@32549
|
84 |
success: int,
|
blanchet@39583
|
85 |
nontriv_calls: int,
|
blanchet@39583
|
86 |
nontriv_success: int,
|
nipkow@32676
|
87 |
proofs: int,
|
nipkow@32549
|
88 |
time: int,
|
nipkow@32550
|
89 |
timeout: int,
|
nipkow@32990
|
90 |
lemmas: int * int * int,
|
blanchet@39587
|
91 |
posns: (Position.T * bool) list
|
nipkow@32550
|
92 |
}
|
boehmes@32521
|
93 |
|
nipkow@32571
|
94 |
datatype min_data = MinData of {
|
nipkow@32609
|
95 |
succs: int,
|
blanchet@35866
|
96 |
ab_ratios: int
|
nipkow@32571
|
97 |
}
|
boehmes@32521
|
98 |
|
nipkow@32810
|
99 |
fun make_sh_data
|
blanchet@39583
|
100 |
(calls,success,nontriv_calls,nontriv_success,lemmas,max_lems,time_isa,
|
blanchet@40243
|
101 |
time_prover,time_prover_fail) =
|
blanchet@39583
|
102 |
ShData{calls=calls, success=success, nontriv_calls=nontriv_calls,
|
blanchet@39583
|
103 |
nontriv_success=nontriv_success, lemmas=lemmas, max_lems=max_lems,
|
blanchet@40243
|
104 |
time_isa=time_isa, time_prover=time_prover,
|
blanchet@40243
|
105 |
time_prover_fail=time_prover_fail}
|
boehmes@32521
|
106 |
|
blanchet@35866
|
107 |
fun make_min_data (succs, ab_ratios) =
|
blanchet@35866
|
108 |
MinData{succs=succs, ab_ratios=ab_ratios}
|
nipkow@32571
|
109 |
|
blanchet@40915
|
110 |
fun make_re_data (calls,success,nontriv_calls,nontriv_success,proofs,time,
|
blanchet@39583
|
111 |
timeout,lemmas,posns) =
|
blanchet@40915
|
112 |
ReData{calls=calls, success=success, nontriv_calls=nontriv_calls,
|
blanchet@39583
|
113 |
nontriv_success=nontriv_success, proofs=proofs, time=time,
|
nipkow@32990
|
114 |
timeout=timeout, lemmas=lemmas, posns=posns}
|
boehmes@32521
|
115 |
|
blanchet@39583
|
116 |
val empty_sh_data = make_sh_data (0, 0, 0, 0, 0, 0, 0, 0, 0)
|
blanchet@35871
|
117 |
val empty_min_data = make_min_data (0, 0)
|
blanchet@40915
|
118 |
val empty_re_data = make_re_data (0, 0, 0, 0, 0, 0, 0, (0,0,0), [])
|
boehmes@32521
|
119 |
|
blanchet@39583
|
120 |
fun tuple_of_sh_data (ShData {calls, success, nontriv_calls, nontriv_success,
|
blanchet@39583
|
121 |
lemmas, max_lems, time_isa,
|
blanchet@40243
|
122 |
time_prover, time_prover_fail}) = (calls, success, nontriv_calls,
|
blanchet@40243
|
123 |
nontriv_success, lemmas, max_lems, time_isa, time_prover, time_prover_fail)
|
boehmes@32521
|
124 |
|
blanchet@35866
|
125 |
fun tuple_of_min_data (MinData {succs, ab_ratios}) = (succs, ab_ratios)
|
nipkow@32533
|
126 |
|
blanchet@40915
|
127 |
fun tuple_of_re_data (ReData {calls, success, nontriv_calls, nontriv_success,
|
blanchet@39583
|
128 |
proofs, time, timeout, lemmas, posns}) = (calls, success, nontriv_calls,
|
blanchet@39583
|
129 |
nontriv_success, proofs, time, timeout, lemmas, posns)
|
nipkow@32571
|
130 |
|
boehmes@34033
|
131 |
|
blanchet@40915
|
132 |
datatype reconstructor_mode =
|
blanchet@40915
|
133 |
Unminimized | Minimized | UnminimizedFT | MinimizedFT
|
boehmes@34033
|
134 |
|
boehmes@34033
|
135 |
datatype data = Data of {
|
boehmes@34033
|
136 |
sh: sh_data,
|
boehmes@34033
|
137 |
min: min_data,
|
blanchet@40915
|
138 |
re_u: re_data, (* reconstructor with unminimized set of lemmas *)
|
blanchet@40915
|
139 |
re_m: re_data, (* reconstructor with minimized set of lemmas *)
|
blanchet@40915
|
140 |
re_uft: re_data, (* reconstructor with unminimized set of lemmas and fully-typed *)
|
blanchet@40915
|
141 |
re_mft: re_data, (* reconstructor with minimized set of lemmas and fully-typed *)
|
boehmes@34033
|
142 |
mini: bool (* with minimization *)
|
boehmes@34033
|
143 |
}
|
boehmes@34033
|
144 |
|
blanchet@40915
|
145 |
fun make_data (sh, min, re_u, re_m, re_uft, re_mft, mini) =
|
blanchet@40915
|
146 |
Data {sh=sh, min=min, re_u=re_u, re_m=re_m, re_uft=re_uft, re_mft=re_mft,
|
boehmes@34033
|
147 |
mini=mini}
|
boehmes@34033
|
148 |
|
boehmes@34033
|
149 |
val empty_data = make_data (empty_sh_data, empty_min_data,
|
blanchet@40915
|
150 |
empty_re_data, empty_re_data, empty_re_data, empty_re_data, false)
|
boehmes@34033
|
151 |
|
blanchet@40915
|
152 |
fun map_sh_data f (Data {sh, min, re_u, re_m, re_uft, re_mft, mini}) =
|
boehmes@34033
|
153 |
let val sh' = make_sh_data (f (tuple_of_sh_data sh))
|
blanchet@40915
|
154 |
in make_data (sh', min, re_u, re_m, re_uft, re_mft, mini) end
|
boehmes@34033
|
155 |
|
blanchet@40915
|
156 |
fun map_min_data f (Data {sh, min, re_u, re_m, re_uft, re_mft, mini}) =
|
boehmes@34033
|
157 |
let val min' = make_min_data (f (tuple_of_min_data min))
|
blanchet@40915
|
158 |
in make_data (sh, min', re_u, re_m, re_uft, re_mft, mini) end
|
boehmes@34033
|
159 |
|
blanchet@40915
|
160 |
fun map_re_data f m (Data {sh, min, re_u, re_m, re_uft, re_mft, mini}) =
|
boehmes@34033
|
161 |
let
|
boehmes@34033
|
162 |
fun map_me g Unminimized (u, m, uft, mft) = (g u, m, uft, mft)
|
boehmes@34033
|
163 |
| map_me g Minimized (u, m, uft, mft) = (u, g m, uft, mft)
|
boehmes@34033
|
164 |
| map_me g UnminimizedFT (u, m, uft, mft) = (u, m, g uft, mft)
|
boehmes@34033
|
165 |
| map_me g MinimizedFT (u, m, uft, mft) = (u, m, uft, g mft)
|
boehmes@34033
|
166 |
|
blanchet@40915
|
167 |
val f' = make_re_data o f o tuple_of_re_data
|
boehmes@34033
|
168 |
|
blanchet@40915
|
169 |
val (re_u', re_m', re_uft', re_mft') =
|
blanchet@40915
|
170 |
map_me f' m (re_u, re_m, re_uft, re_mft)
|
blanchet@40915
|
171 |
in make_data (sh, min, re_u', re_m', re_uft', re_mft', mini) end
|
boehmes@34033
|
172 |
|
blanchet@40915
|
173 |
fun set_mini mini (Data {sh, min, re_u, re_m, re_uft, re_mft, ...}) =
|
blanchet@40915
|
174 |
make_data (sh, min, re_u, re_m, re_uft, re_mft, mini)
|
nipkow@32990
|
175 |
|
nipkow@32990
|
176 |
fun inc_max (n:int) (s,sos,m) = (s+n, sos + n*n, Int.max(m,n));
|
nipkow@32536
|
177 |
|
nipkow@32810
|
178 |
val inc_sh_calls = map_sh_data
|
blanchet@40243
|
179 |
(fn (calls, success, nontriv_calls, nontriv_success, lemmas,max_lems, time_isa, time_prover, time_prover_fail)
|
blanchet@40243
|
180 |
=> (calls + 1, success, nontriv_calls, nontriv_success, lemmas, max_lems, time_isa, time_prover, time_prover_fail))
|
boehmes@32521
|
181 |
|
nipkow@32810
|
182 |
val inc_sh_success = map_sh_data
|
blanchet@40243
|
183 |
(fn (calls, success, nontriv_calls, nontriv_success, lemmas,max_lems, time_isa, time_prover, time_prover_fail)
|
blanchet@40243
|
184 |
=> (calls, success + 1, nontriv_calls, nontriv_success, lemmas,max_lems, time_isa, time_prover, time_prover_fail))
|
blanchet@39583
|
185 |
|
blanchet@39583
|
186 |
val inc_sh_nontriv_calls = map_sh_data
|
blanchet@40243
|
187 |
(fn (calls, success, nontriv_calls, nontriv_success, lemmas,max_lems, time_isa, time_prover, time_prover_fail)
|
blanchet@40243
|
188 |
=> (calls, success, nontriv_calls + 1, nontriv_success, lemmas, max_lems, time_isa, time_prover, time_prover_fail))
|
blanchet@39583
|
189 |
|
blanchet@39583
|
190 |
val inc_sh_nontriv_success = map_sh_data
|
blanchet@40243
|
191 |
(fn (calls, success, nontriv_calls, nontriv_success, lemmas,max_lems, time_isa, time_prover, time_prover_fail)
|
blanchet@40243
|
192 |
=> (calls, success, nontriv_calls, nontriv_success + 1, lemmas,max_lems, time_isa, time_prover, time_prover_fail))
|
nipkow@32585
|
193 |
|
nipkow@32810
|
194 |
fun inc_sh_lemmas n = map_sh_data
|
blanchet@40243
|
195 |
(fn (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover,time_prover_fail)
|
blanchet@40243
|
196 |
=> (calls,success,nontriv_calls, nontriv_success, lemmas+n,max_lems,time_isa,time_prover,time_prover_fail))
|
boehmes@32521
|
197 |
|
nipkow@32810
|
198 |
fun inc_sh_max_lems n = map_sh_data
|
blanchet@40243
|
199 |
(fn (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover,time_prover_fail)
|
blanchet@40243
|
200 |
=> (calls,success,nontriv_calls, nontriv_success, lemmas,Int.max(max_lems,n),time_isa,time_prover,time_prover_fail))
|
nipkow@32549
|
201 |
|
nipkow@32810
|
202 |
fun inc_sh_time_isa t = map_sh_data
|
blanchet@40243
|
203 |
(fn (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover,time_prover_fail)
|
blanchet@40243
|
204 |
=> (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa + t,time_prover,time_prover_fail))
|
nipkow@32549
|
205 |
|
blanchet@40243
|
206 |
fun inc_sh_time_prover t = map_sh_data
|
blanchet@40243
|
207 |
(fn (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover,time_prover_fail)
|
blanchet@40243
|
208 |
=> (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover + t,time_prover_fail))
|
nipkow@32571
|
209 |
|
blanchet@40243
|
210 |
fun inc_sh_time_prover_fail t = map_sh_data
|
blanchet@40243
|
211 |
(fn (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover,time_prover_fail)
|
blanchet@40243
|
212 |
=> (calls,success,nontriv_calls, nontriv_success, lemmas,max_lems,time_isa,time_prover,time_prover_fail + t))
|
nipkow@32571
|
213 |
|
nipkow@32810
|
214 |
val inc_min_succs = map_min_data
|
blanchet@35866
|
215 |
(fn (succs,ab_ratios) => (succs+1, ab_ratios))
|
nipkow@32609
|
216 |
|
nipkow@32810
|
217 |
fun inc_min_ab_ratios r = map_min_data
|
blanchet@35866
|
218 |
(fn (succs, ab_ratios) => (succs, ab_ratios+r))
|
nipkow@32549
|
219 |
|
blanchet@40915
|
220 |
val inc_reconstructor_calls = map_re_data
|
blanchet@39583
|
221 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
222 |
=> (calls + 1, success, nontriv_calls, nontriv_success, proofs, time, timeout, lemmas,posns))
|
nipkow@32549
|
223 |
|
blanchet@40915
|
224 |
val inc_reconstructor_success = map_re_data
|
blanchet@39583
|
225 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
226 |
=> (calls, success + 1, nontriv_calls, nontriv_success, proofs, time, timeout, lemmas,posns))
|
blanchet@39583
|
227 |
|
blanchet@40915
|
228 |
val inc_reconstructor_nontriv_calls = map_re_data
|
blanchet@39583
|
229 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
230 |
=> (calls, success, nontriv_calls + 1, nontriv_success, proofs, time, timeout, lemmas,posns))
|
blanchet@39583
|
231 |
|
blanchet@40915
|
232 |
val inc_reconstructor_nontriv_success = map_re_data
|
blanchet@39583
|
233 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
234 |
=> (calls, success, nontriv_calls, nontriv_success + 1, proofs, time, timeout, lemmas,posns))
|
nipkow@32676
|
235 |
|
blanchet@40915
|
236 |
val inc_reconstructor_proofs = map_re_data
|
blanchet@39583
|
237 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
238 |
=> (calls, success, nontriv_calls, nontriv_success, proofs + 1, time, timeout, lemmas,posns))
|
nipkow@32549
|
239 |
|
blanchet@40915
|
240 |
fun inc_reconstructor_time m t = map_re_data
|
blanchet@39583
|
241 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
242 |
=> (calls, success, nontriv_calls, nontriv_success, proofs, time + t, timeout, lemmas,posns)) m
|
nipkow@32549
|
243 |
|
blanchet@40915
|
244 |
val inc_reconstructor_timeout = map_re_data
|
blanchet@39583
|
245 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
246 |
=> (calls, success, nontriv_calls, nontriv_success, proofs, time, timeout + 1, lemmas,posns))
|
nipkow@32549
|
247 |
|
blanchet@40915
|
248 |
fun inc_reconstructor_lemmas m n = map_re_data
|
blanchet@39583
|
249 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
250 |
=> (calls, success, nontriv_calls, nontriv_success, proofs, time, timeout, inc_max n lemmas, posns)) m
|
nipkow@32549
|
251 |
|
blanchet@40915
|
252 |
fun inc_reconstructor_posns m pos = map_re_data
|
blanchet@39583
|
253 |
(fn (calls,success,nontriv_calls, nontriv_success, proofs,time,timeout,lemmas,posns)
|
blanchet@39583
|
254 |
=> (calls, success, nontriv_calls, nontriv_success, proofs, time, timeout, lemmas, pos::posns)) m
|
boehmes@32521
|
255 |
|
blanchet@44961
|
256 |
val str0 = string_of_int o the_default 0
|
blanchet@44961
|
257 |
|
boehmes@32521
|
258 |
local
|
boehmes@32521
|
259 |
|
boehmes@32521
|
260 |
val str = string_of_int
|
boehmes@32521
|
261 |
val str3 = Real.fmt (StringCvt.FIX (SOME 3))
|
boehmes@32521
|
262 |
fun percentage a b = string_of_int (a * 100 div b)
|
boehmes@32521
|
263 |
fun time t = Real.fromInt t / 1000.0
|
boehmes@32521
|
264 |
fun avg_time t n =
|
boehmes@32521
|
265 |
if n > 0 then (Real.fromInt t / 1000.0) / Real.fromInt n else 0.0
|
boehmes@32521
|
266 |
|
boehmes@34033
|
267 |
fun log_sh_data log
|
blanchet@40243
|
268 |
(calls, success, nontriv_calls, nontriv_success, lemmas, max_lems, time_isa, time_prover, time_prover_fail) =
|
nipkow@32810
|
269 |
(log ("Total number of sledgehammer calls: " ^ str calls);
|
nipkow@32810
|
270 |
log ("Number of successful sledgehammer calls: " ^ str success);
|
nipkow@32810
|
271 |
log ("Number of sledgehammer lemmas: " ^ str lemmas);
|
nipkow@32810
|
272 |
log ("Max number of sledgehammer lemmas: " ^ str max_lems);
|
nipkow@32810
|
273 |
log ("Success rate: " ^ percentage success calls ^ "%");
|
blanchet@39583
|
274 |
log ("Total number of nontrivial sledgehammer calls: " ^ str nontriv_calls);
|
blanchet@39583
|
275 |
log ("Number of successful nontrivial sledgehammer calls: " ^ str nontriv_success);
|
nipkow@32810
|
276 |
log ("Total time for sledgehammer calls (Isabelle): " ^ str3 (time time_isa));
|
blanchet@40243
|
277 |
log ("Total time for successful sledgehammer calls (ATP): " ^ str3 (time time_prover));
|
blanchet@40243
|
278 |
log ("Total time for failed sledgehammer calls (ATP): " ^ str3 (time time_prover_fail));
|
nipkow@32536
|
279 |
log ("Average time for sledgehammer calls (Isabelle): " ^
|
nipkow@32810
|
280 |
str3 (avg_time time_isa calls));
|
nipkow@32533
|
281 |
log ("Average time for successful sledgehammer calls (ATP): " ^
|
blanchet@40243
|
282 |
str3 (avg_time time_prover success));
|
nipkow@32536
|
283 |
log ("Average time for failed sledgehammer calls (ATP): " ^
|
blanchet@40243
|
284 |
str3 (avg_time time_prover_fail (calls - success)))
|
nipkow@32533
|
285 |
)
|
boehmes@32521
|
286 |
|
blanchet@39587
|
287 |
fun str_of_pos (pos, triv) =
|
blanchet@48593
|
288 |
str0 (Position.line_of pos) ^ ":" ^ str0 (Position.offset_of pos) ^
|
blanchet@44961
|
289 |
(if triv then "[T]" else "")
|
nipkow@32551
|
290 |
|
blanchet@40915
|
291 |
fun log_re_data log tag sh_calls (re_calls, re_success, re_nontriv_calls,
|
blanchet@40915
|
292 |
re_nontriv_success, re_proofs, re_time, re_timeout,
|
blanchet@40915
|
293 |
(lemmas, lems_sos, lems_max), re_posns) =
|
blanchet@40915
|
294 |
(log ("Total number of " ^ tag ^ "reconstructor calls: " ^ str re_calls);
|
blanchet@40915
|
295 |
log ("Number of successful " ^ tag ^ "reconstructor calls: " ^ str re_success ^
|
blanchet@40915
|
296 |
" (proof: " ^ str re_proofs ^ ")");
|
blanchet@40915
|
297 |
log ("Number of " ^ tag ^ "reconstructor timeouts: " ^ str re_timeout);
|
blanchet@40915
|
298 |
log ("Success rate: " ^ percentage re_success sh_calls ^ "%");
|
blanchet@40915
|
299 |
log ("Total number of nontrivial " ^ tag ^ "reconstructor calls: " ^ str re_nontriv_calls);
|
blanchet@40915
|
300 |
log ("Number of successful nontrivial " ^ tag ^ "reconstructor calls: " ^ str re_nontriv_success ^
|
blanchet@40915
|
301 |
" (proof: " ^ str re_proofs ^ ")");
|
blanchet@40915
|
302 |
log ("Number of successful " ^ tag ^ "reconstructor lemmas: " ^ str lemmas);
|
blanchet@40915
|
303 |
log ("SOS of successful " ^ tag ^ "reconstructor lemmas: " ^ str lems_sos);
|
blanchet@40915
|
304 |
log ("Max number of successful " ^ tag ^ "reconstructor lemmas: " ^ str lems_max);
|
blanchet@40915
|
305 |
log ("Total time for successful " ^ tag ^ "reconstructor calls: " ^ str3 (time re_time));
|
blanchet@40915
|
306 |
log ("Average time for successful " ^ tag ^ "reconstructor calls: " ^
|
blanchet@40915
|
307 |
str3 (avg_time re_time re_success));
|
nipkow@32551
|
308 |
if tag=""
|
blanchet@40915
|
309 |
then log ("Proved: " ^ space_implode " " (map str_of_pos re_posns))
|
nipkow@32551
|
310 |
else ()
|
nipkow@32551
|
311 |
)
|
nipkow@32571
|
312 |
|
blanchet@35866
|
313 |
fun log_min_data log (succs, ab_ratios) =
|
nipkow@32609
|
314 |
(log ("Number of successful minimizations: " ^ string_of_int succs);
|
blanchet@35866
|
315 |
log ("After/before ratios: " ^ string_of_int ab_ratios)
|
nipkow@32571
|
316 |
)
|
nipkow@32571
|
317 |
|
boehmes@32521
|
318 |
in
|
boehmes@32521
|
319 |
|
blanchet@40915
|
320 |
fun log_data id log (Data {sh, min, re_u, re_m, re_uft, re_mft, mini}) =
|
boehmes@34033
|
321 |
let
|
boehmes@34033
|
322 |
val ShData {calls=sh_calls, ...} = sh
|
boehmes@34033
|
323 |
|
blanchet@40915
|
324 |
fun app_if (ReData {calls, ...}) f = if calls > 0 then f () else ()
|
blanchet@40915
|
325 |
fun log_re tag m =
|
blanchet@40915
|
326 |
log_re_data log tag sh_calls (tuple_of_re_data m)
|
blanchet@40915
|
327 |
fun log_reconstructor (tag1, m1) (tag2, m2) = app_if m1 (fn () =>
|
blanchet@40915
|
328 |
(log_re tag1 m1; log ""; app_if m2 (fn () => log_re tag2 m2)))
|
boehmes@34033
|
329 |
in
|
boehmes@34033
|
330 |
if sh_calls > 0
|
boehmes@34033
|
331 |
then
|
boehmes@34033
|
332 |
(log ("\n\n\nReport #" ^ string_of_int id ^ ":\n");
|
boehmes@34033
|
333 |
log_sh_data log (tuple_of_sh_data sh);
|
boehmes@34033
|
334 |
log "";
|
boehmes@34033
|
335 |
if not mini
|
blanchet@40915
|
336 |
then log_reconstructor ("", re_u) ("fully-typed ", re_uft)
|
boehmes@34033
|
337 |
else
|
blanchet@40915
|
338 |
app_if re_u (fn () =>
|
blanchet@40915
|
339 |
(log_reconstructor ("unminimized ", re_u) ("unminimized fully-typed ", re_uft);
|
boehmes@34033
|
340 |
log "";
|
blanchet@40915
|
341 |
app_if re_m (fn () =>
|
boehmes@34033
|
342 |
(log_min_data log (tuple_of_min_data min); log "";
|
blanchet@40915
|
343 |
log_reconstructor ("", re_m) ("fully-typed ", re_mft))))))
|
boehmes@34033
|
344 |
else ()
|
boehmes@34033
|
345 |
end
|
boehmes@32521
|
346 |
|
boehmes@32521
|
347 |
end
|
boehmes@32521
|
348 |
|
boehmes@32521
|
349 |
|
boehmes@32521
|
350 |
(* Warning: we implicitly assume single-threaded execution here! *)
|
wenzelm@32740
|
351 |
val data = Unsynchronized.ref ([] : (int * data) list)
|
boehmes@32521
|
352 |
|
wenzelm@32740
|
353 |
fun init id thy = (Unsynchronized.change data (cons (id, empty_data)); thy)
|
wenzelm@32567
|
354 |
fun done id ({log, ...}: Mirabelle.done_args) =
|
boehmes@32521
|
355 |
AList.lookup (op =) (!data) id
|
boehmes@32521
|
356 |
|> Option.map (log_data id log)
|
boehmes@32521
|
357 |
|> K ()
|
boehmes@32521
|
358 |
|
wenzelm@32740
|
359 |
fun change_data id f = (Unsynchronized.change data (AList.map_entry (op =) id f); ())
|
boehmes@32521
|
360 |
|
boehmes@32521
|
361 |
|
blanchet@43315
|
362 |
fun get_prover ctxt args =
|
boehmes@33016
|
363 |
let
|
blanchet@40243
|
364 |
fun default_prover_name () =
|
blanchet@40250
|
365 |
hd (#provers (Sledgehammer_Isar.default_params ctxt []))
|
wenzelm@47937
|
366 |
handle List.Empty => error "No ATP available."
|
blanchet@41335
|
367 |
fun get_prover name =
|
blanchet@43862
|
368 |
(name, Sledgehammer_Run.get_minimizing_prover ctxt
|
blanchet@43862
|
369 |
Sledgehammer_Provers.Normal name)
|
boehmes@33016
|
370 |
in
|
boehmes@33016
|
371 |
(case AList.lookup (op =) args proverK of
|
blanchet@40243
|
372 |
SOME name => get_prover name
|
blanchet@40243
|
373 |
| NONE => get_prover (default_prover_name ()))
|
boehmes@33016
|
374 |
end
|
boehmes@32525
|
375 |
|
blanchet@47168
|
376 |
type stature = ATP_Problem_Generate.stature
|
blanchet@38991
|
377 |
|
blanchet@40915
|
378 |
(* hack *)
|
blanchet@41605
|
379 |
fun reconstructor_from_msg args msg =
|
blanchet@41605
|
380 |
(case AList.lookup (op =) args reconstructorK of
|
blanchet@41605
|
381 |
SOME name => name
|
blanchet@41605
|
382 |
| NONE =>
|
blanchet@46390
|
383 |
if String.isSubstring "metis (" msg then
|
blanchet@46390
|
384 |
msg |> Substring.full
|
blanchet@46390
|
385 |
|> Substring.position "metis ("
|
blanchet@46390
|
386 |
|> snd |> Substring.position ")"
|
blanchet@46390
|
387 |
|> fst |> Substring.string
|
blanchet@46390
|
388 |
|> suffix ")"
|
blanchet@46390
|
389 |
else if String.isSubstring "metis" msg then
|
blanchet@46390
|
390 |
"metis"
|
blanchet@46390
|
391 |
else
|
blanchet@46390
|
392 |
"smt")
|
blanchet@40915
|
393 |
|
boehmes@32521
|
394 |
local
|
boehmes@32521
|
395 |
|
nipkow@32536
|
396 |
datatype sh_result =
|
blanchet@47168
|
397 |
SH_OK of int * int * (string * stature) list |
|
nipkow@32536
|
398 |
SH_FAIL of int * int |
|
nipkow@32536
|
399 |
SH_ERROR
|
nipkow@32536
|
400 |
|
blanchet@47214
|
401 |
fun run_sh prover_name prover type_enc strict max_relevant slice lam_trans
|
blanchet@47920
|
402 |
uncurried_aliases e_selection_heuristic term_order force_sos
|
blanchet@47920
|
403 |
hard_timeout timeout preplay_timeout sh_minimizeLST
|
blanchet@47920
|
404 |
max_new_mono_instancesLST max_mono_itersLST dir pos st =
|
boehmes@32521
|
405 |
let
|
blanchet@39242
|
406 |
val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
|
blanchet@39242
|
407 |
val i = 1
|
blanchet@44961
|
408 |
fun set_file_name (SOME dir) =
|
blanchet@41585
|
409 |
Config.put Sledgehammer_Provers.dest_dir dir
|
blanchet@44961
|
410 |
#> Config.put Sledgehammer_Provers.problem_prefix
|
blanchet@45283
|
411 |
("prob_" ^ str0 (Position.line_of pos) ^ "__")
|
blanchet@41585
|
412 |
#> Config.put SMT_Config.debug_files
|
blanchet@43929
|
413 |
(dir ^ "/" ^ Name.desymbolize false (ATP_Util.timestamp ()) ^ "_"
|
blanchet@41586
|
414 |
^ serial_string ())
|
blanchet@44961
|
415 |
| set_file_name NONE = I
|
blanchet@39567
|
416 |
val st' =
|
blanchet@47901
|
417 |
st
|
blanchet@47901
|
418 |
|> Proof.map_context
|
blanchet@47901
|
419 |
(set_file_name dir
|
blanchet@47903
|
420 |
#> (Option.map (Config.put ATP_Systems.e_selection_heuristic)
|
blanchet@47903
|
421 |
e_selection_heuristic |> the_default I)
|
blanchet@47920
|
422 |
#> (Option.map (Config.put ATP_Systems.term_order)
|
blanchet@47920
|
423 |
term_order |> the_default I)
|
blanchet@47901
|
424 |
#> (Option.map (Config.put ATP_Systems.force_sos)
|
blanchet@47901
|
425 |
force_sos |> the_default I))
|
blanchet@46577
|
426 |
val params as {relevance_thresholds, max_relevant, slice, ...} =
|
blanchet@40250
|
427 |
Sledgehammer_Isar.default_params ctxt
|
sultana@47697
|
428 |
([("verbose", "true"),
|
blanchet@44493
|
429 |
("type_enc", type_enc),
|
blanchet@47214
|
430 |
("strict", strict),
|
sultana@48352
|
431 |
("lam_trans", lam_trans |> the_default lam_trans_default),
|
sultana@48352
|
432 |
("uncurried_aliases", uncurried_aliases |> the_default uncurried_aliases_default),
|
blanchet@42623
|
433 |
("max_relevant", max_relevant),
|
blanchet@46577
|
434 |
("slice", slice),
|
blanchet@45305
|
435 |
("timeout", string_of_int timeout),
|
blanchet@45305
|
436 |
("preplay_timeout", preplay_timeout)]
|
sultana@47697
|
437 |
|> sh_minimizeLST (*don't confuse the two minimization flags*)
|
sultana@47697
|
438 |
|> max_new_mono_instancesLST
|
sultana@47697
|
439 |
|> max_mono_itersLST)
|
blanchet@40243
|
440 |
val default_max_relevant =
|
blanchet@46577
|
441 |
Sledgehammer_Provers.default_max_relevant_for_prover ctxt slice
|
blanchet@43314
|
442 |
prover_name
|
blanchet@43793
|
443 |
val is_appropriate_prop =
|
blanchet@43793
|
444 |
Sledgehammer_Provers.is_appropriate_prop_for_prover ctxt prover_name
|
blanchet@40615
|
445 |
val is_built_in_const =
|
blanchet@41335
|
446 |
Sledgehammer_Provers.is_built_in_const_for_prover ctxt prover_name
|
blanchet@41189
|
447 |
val relevance_fudge =
|
blanchet@41335
|
448 |
Sledgehammer_Provers.relevance_fudge_for_prover ctxt prover_name
|
blanchet@40251
|
449 |
val relevance_override = {add = [], del = [], only = false}
|
blanchet@43929
|
450 |
val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal i
|
boehmes@32573
|
451 |
val time_limit =
|
boehmes@32573
|
452 |
(case hard_timeout of
|
boehmes@32573
|
453 |
NONE => I
|
boehmes@32573
|
454 |
| SOME secs => TimeLimit.timeLimit (Time.fromSeconds secs))
|
blanchet@43794
|
455 |
fun failed failure =
|
blanchet@46232
|
456 |
({outcome = SOME failure, used_facts = [], run_time = Time.zeroTime,
|
blanchet@46390
|
457 |
preplay =
|
blanchet@47148
|
458 |
K (ATP_Proof_Reconstruct.Failed_to_Play Sledgehammer_Provers.plain_metis),
|
blanchet@44102
|
459 |
message = K "", message_tail = ""}, ~1)
|
blanchet@46232
|
460 |
val ({outcome, used_facts, run_time, preplay, message, message_tail}
|
blanchet@46232
|
461 |
: Sledgehammer_Provers.prover_result,
|
blanchet@41523
|
462 |
time_isa) = time_limit (Mirabelle.cpu_time (fn () =>
|
blanchet@41523
|
463 |
let
|
blanchet@43794
|
464 |
val _ = if is_appropriate_prop concl_t then ()
|
blanchet@43794
|
465 |
else raise Fail "inappropriate"
|
blanchet@45483
|
466 |
val ho_atp = Sledgehammer_Provers.is_ho_atp ctxt prover_name
|
blanchet@41523
|
467 |
val facts =
|
blanchet@45483
|
468 |
Sledgehammer_Filter.nearly_all_facts ctxt ho_atp relevance_override
|
blanchet@45483
|
469 |
chained_ths hyp_ts concl_t
|
blanchet@44217
|
470 |
|> filter (is_appropriate_prop o prop_of o snd)
|
blanchet@45483
|
471 |
|> Sledgehammer_Filter.relevant_facts ctxt relevance_thresholds
|
blanchet@44217
|
472 |
(the_default default_max_relevant max_relevant)
|
blanchet@44217
|
473 |
is_built_in_const relevance_fudge relevance_override
|
blanchet@44217
|
474 |
chained_ths hyp_ts concl_t
|
blanchet@41523
|
475 |
val problem =
|
blanchet@41523
|
476 |
{state = st', goal = goal, subgoal = i,
|
blanchet@41523
|
477 |
subgoal_count = Sledgehammer_Util.subgoal_count st,
|
blanchet@48403
|
478 |
facts = facts |> map Sledgehammer_Provers.Untranslated_Fact}
|
blanchet@46391
|
479 |
in prover params (K (K (K ""))) problem end)) ()
|
blanchet@43794
|
480 |
handle TimeLimit.TimeOut => failed ATP_Proof.TimedOut
|
blanchet@43794
|
481 |
| Fail "inappropriate" => failed ATP_Proof.Inappropriate
|
blanchet@46232
|
482 |
val time_prover = run_time |> Time.toMilliseconds
|
blanchet@44102
|
483 |
val msg = message (preplay ()) ^ message_tail
|
boehmes@32521
|
484 |
in
|
blanchet@36405
|
485 |
case outcome of
|
blanchet@43893
|
486 |
NONE => (msg, SH_OK (time_isa, time_prover, used_facts))
|
blanchet@43893
|
487 |
| SOME _ => (msg, SH_FAIL (time_isa, time_prover))
|
boehmes@32521
|
488 |
end
|
blanchet@38228
|
489 |
handle ERROR msg => ("error: " ^ msg, SH_ERROR)
|
boehmes@32521
|
490 |
|
boehmes@32454
|
491 |
fun thms_of_name ctxt name =
|
boehmes@32454
|
492 |
let
|
wenzelm@36970
|
493 |
val lex = Keyword.get_lexicons
|
wenzelm@43232
|
494 |
val get = maps (Proof_Context.get_fact ctxt o fst)
|
boehmes@32454
|
495 |
in
|
boehmes@32454
|
496 |
Source.of_string name
|
wenzelm@40772
|
497 |
|> Symbol.source
|
wenzelm@36969
|
498 |
|> Token.source {do_recover=SOME false} lex Position.start
|
wenzelm@36969
|
499 |
|> Token.source_proper
|
wenzelm@36969
|
500 |
|> Source.source Token.stopper (Parse_Spec.xthms1 >> get) NONE
|
boehmes@32454
|
501 |
|> Source.exhaust
|
boehmes@32454
|
502 |
end
|
boehmes@32452
|
503 |
|
boehmes@32498
|
504 |
in
|
boehmes@32498
|
505 |
|
blanchet@44961
|
506 |
fun run_sledgehammer trivial args reconstructor named_thms id
|
blanchet@44961
|
507 |
({pre=st, log, pos, ...}: Mirabelle.run_args) =
|
boehmes@32385
|
508 |
let
|
blanchet@39586
|
509 |
val triv_str = if trivial then "[T] " else ""
|
nipkow@32536
|
510 |
val _ = change_data id inc_sh_calls
|
blanchet@39583
|
511 |
val _ = if trivial then () else change_data id inc_sh_nontriv_calls
|
blanchet@43315
|
512 |
val (prover_name, prover) = get_prover (Proof.context_of st) args
|
sultana@48352
|
513 |
val type_enc = AList.lookup (op =) args type_encK |> the_default type_enc_default
|
sultana@48352
|
514 |
val strict = AList.lookup (op =) args strictK |> the_default strict_default
|
sultana@48352
|
515 |
val max_relevant = AList.lookup (op =) args max_relevantK |> the_default max_relevant_default
|
sultana@48352
|
516 |
val slice = AList.lookup (op =) args sliceK |> the_default slice_default
|
blanchet@46385
|
517 |
val lam_trans = AList.lookup (op =) args lam_transK
|
blanchet@47243
|
518 |
val uncurried_aliases = AList.lookup (op =) args uncurried_aliasesK
|
blanchet@47903
|
519 |
val e_selection_heuristic = AList.lookup (op =) args e_selection_heuristicK
|
blanchet@47920
|
520 |
val term_order = AList.lookup (op =) args term_orderK
|
blanchet@44970
|
521 |
val force_sos = AList.lookup (op =) args force_sosK
|
blanchet@43590
|
522 |
|> Option.map (curry (op <>) "false")
|
boehmes@32525
|
523 |
val dir = AList.lookup (op =) args keepK
|
boehmes@32541
|
524 |
val timeout = Mirabelle.get_int_setting args (prover_timeoutK, 30)
|
blanchet@41516
|
525 |
(* always use a hard timeout, but give some slack so that the automatic
|
blanchet@41516
|
526 |
minimizer has a chance to do its magic *)
|
sultana@47696
|
527 |
val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
|
sultana@47696
|
528 |
|> the_default preplay_timeout_default
|
sultana@47697
|
529 |
val sh_minimizeLST = available_parameter args sh_minimizeK "minimize"
|
sultana@47697
|
530 |
val max_new_mono_instancesLST =
|
sultana@47697
|
531 |
available_parameter args max_new_mono_instancesK max_new_mono_instancesK
|
sultana@47697
|
532 |
val max_mono_itersLST = available_parameter args max_mono_itersK max_mono_itersK
|
blanchet@41516
|
533 |
val hard_timeout = SOME (2 * timeout)
|
blanchet@41403
|
534 |
val (msg, result) =
|
blanchet@47214
|
535 |
run_sh prover_name prover type_enc strict max_relevant slice lam_trans
|
blanchet@47920
|
536 |
uncurried_aliases e_selection_heuristic term_order force_sos
|
blanchet@47920
|
537 |
hard_timeout timeout preplay_timeout sh_minimizeLST
|
blanchet@47920
|
538 |
max_new_mono_instancesLST max_mono_itersLST dir pos st
|
boehmes@32525
|
539 |
in
|
nipkow@32536
|
540 |
case result of
|
blanchet@40243
|
541 |
SH_OK (time_isa, time_prover, names) =>
|
blanchet@38939
|
542 |
let
|
blanchet@47168
|
543 |
fun get_thms (name, stature) =
|
blanchet@48025
|
544 |
try (thms_of_name (Proof.context_of st)) name
|
blanchet@48025
|
545 |
|> Option.map (pair (name, stature))
|
boehmes@32525
|
546 |
in
|
nipkow@32810
|
547 |
change_data id inc_sh_success;
|
blanchet@39583
|
548 |
if trivial then () else change_data id inc_sh_nontriv_success;
|
nipkow@32810
|
549 |
change_data id (inc_sh_lemmas (length names));
|
nipkow@32810
|
550 |
change_data id (inc_sh_max_lems (length names));
|
nipkow@32810
|
551 |
change_data id (inc_sh_time_isa time_isa);
|
blanchet@40243
|
552 |
change_data id (inc_sh_time_prover time_prover);
|
blanchet@41605
|
553 |
reconstructor := reconstructor_from_msg args msg;
|
blanchet@39061
|
554 |
named_thms := SOME (map_filter get_thms names);
|
blanchet@39586
|
555 |
log (sh_tag id ^ triv_str ^ "succeeded (" ^ string_of_int time_isa ^ "+" ^
|
blanchet@40243
|
556 |
string_of_int time_prover ^ ") [" ^ prover_name ^ "]:\n" ^ msg)
|
boehmes@32525
|
557 |
end
|
blanchet@40243
|
558 |
| SH_FAIL (time_isa, time_prover) =>
|
nipkow@32536
|
559 |
let
|
nipkow@32536
|
560 |
val _ = change_data id (inc_sh_time_isa time_isa)
|
blanchet@40243
|
561 |
val _ = change_data id (inc_sh_time_prover_fail time_prover)
|
blanchet@39586
|
562 |
in log (sh_tag id ^ triv_str ^ "failed: " ^ msg) end
|
nipkow@32536
|
563 |
| SH_ERROR => log (sh_tag id ^ "failed: " ^ msg)
|
boehmes@32525
|
564 |
end
|
boehmes@32525
|
565 |
|
boehmes@32525
|
566 |
end
|
boehmes@32525
|
567 |
|
blanchet@40915
|
568 |
fun run_minimize args reconstructor named_thms id
|
blanchet@40915
|
569 |
({pre=st, log, ...}: Mirabelle.run_args) =
|
boehmes@32525
|
570 |
let
|
blanchet@40250
|
571 |
val ctxt = Proof.context_of st
|
nipkow@32571
|
572 |
val n0 = length (these (!named_thms))
|
blanchet@43315
|
573 |
val (prover_name, _) = get_prover ctxt args
|
sultana@48352
|
574 |
val type_enc = AList.lookup (op =) args type_encK |> the_default type_enc_default
|
sultana@48352
|
575 |
val strict = AList.lookup (op =) args strictK |> the_default strict_default
|
boehmes@32525
|
576 |
val timeout =
|
boehmes@32525
|
577 |
AList.lookup (op =) args minimize_timeoutK
|
wenzelm@40875
|
578 |
|> Option.map (fst o read_int o raw_explode) (* FIXME Symbol.explode (?) *)
|
sultana@48352
|
579 |
|> the_default minimize_timeout_default
|
sultana@47696
|
580 |
val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
|
sultana@47696
|
581 |
|> the_default preplay_timeout_default
|
sultana@47697
|
582 |
val sh_minimizeLST = available_parameter args sh_minimizeK "minimize"
|
sultana@47697
|
583 |
val max_new_mono_instancesLST =
|
sultana@47697
|
584 |
available_parameter args max_new_mono_instancesK max_new_mono_instancesK
|
sultana@47697
|
585 |
val max_mono_itersLST = available_parameter args max_mono_itersK max_mono_itersK
|
blanchet@43905
|
586 |
val params = Sledgehammer_Isar.default_params ctxt
|
sultana@47697
|
587 |
([("provers", prover_name),
|
blanchet@41403
|
588 |
("verbose", "true"),
|
blanchet@44493
|
589 |
("type_enc", type_enc),
|
blanchet@47214
|
590 |
("strict", strict),
|
blanchet@45305
|
591 |
("timeout", string_of_int timeout),
|
sultana@47697
|
592 |
("preplay_timeout", preplay_timeout)]
|
sultana@47697
|
593 |
|> sh_minimizeLST (*don't confuse the two minimization flags*)
|
sultana@47697
|
594 |
|> max_new_mono_instancesLST
|
sultana@47697
|
595 |
|> max_mono_itersLST)
|
blanchet@37587
|
596 |
val minimize =
|
blanchet@42613
|
597 |
Sledgehammer_Minimize.minimize_facts prover_name params
|
blanchet@43905
|
598 |
true 1 (Sledgehammer_Util.subgoal_count st)
|
boehmes@32525
|
599 |
val _ = log separator
|
blanchet@44102
|
600 |
val (used_facts, (preplay, message, message_tail)) =
|
blanchet@44102
|
601 |
minimize st (these (!named_thms))
|
blanchet@44102
|
602 |
val msg = message (preplay ()) ^ message_tail
|
boehmes@32525
|
603 |
in
|
blanchet@43893
|
604 |
case used_facts of
|
blanchet@43893
|
605 |
SOME named_thms' =>
|
nipkow@32609
|
606 |
(change_data id inc_min_succs;
|
nipkow@32609
|
607 |
change_data id (inc_min_ab_ratios ((100 * length named_thms') div n0));
|
nipkow@32571
|
608 |
if length named_thms' = n0
|
nipkow@32571
|
609 |
then log (minimize_tag id ^ "already minimal")
|
blanchet@41605
|
610 |
else (reconstructor := reconstructor_from_msg args msg;
|
blanchet@40915
|
611 |
named_thms := SOME named_thms';
|
nipkow@32571
|
612 |
log (minimize_tag id ^ "succeeded:\n" ^ msg))
|
nipkow@32571
|
613 |
)
|
blanchet@43893
|
614 |
| NONE => log (minimize_tag id ^ "failed: " ^ msg)
|
boehmes@32525
|
615 |
end
|
boehmes@32525
|
616 |
|
blanchet@45413
|
617 |
fun override_params prover type_enc timeout =
|
blanchet@45413
|
618 |
[("provers", prover),
|
blanchet@45306
|
619 |
("max_relevant", "0"),
|
blanchet@45413
|
620 |
("type_enc", type_enc),
|
blanchet@47214
|
621 |
("strict", "true"),
|
blanchet@46577
|
622 |
("slice", "false"),
|
blanchet@45318
|
623 |
("timeout", timeout |> Time.toSeconds |> string_of_int)]
|
blanchet@45301
|
624 |
|
blanchet@40915
|
625 |
fun run_reconstructor trivial full m name reconstructor named_thms id
|
wenzelm@32567
|
626 |
({pre=st, timeout, log, pos, ...}: Mirabelle.run_args) =
|
boehmes@32525
|
627 |
let
|
blanchet@45319
|
628 |
fun do_reconstructor named_thms ctxt =
|
blanchet@45319
|
629 |
let
|
blanchet@45319
|
630 |
val ref_of_str =
|
blanchet@45319
|
631 |
suffix ";" #> Outer_Syntax.scan Position.none #> Parse_Spec.xthm
|
blanchet@45319
|
632 |
#> fst
|
blanchet@45319
|
633 |
val thms = named_thms |> maps snd
|
blanchet@45319
|
634 |
val facts = named_thms |> map (ref_of_str o fst o fst)
|
blanchet@45319
|
635 |
val relevance_override = {add = facts, del = [], only = true}
|
blanchet@45437
|
636 |
fun my_timeout time_slice =
|
blanchet@45437
|
637 |
timeout |> Time.toReal |> curry Real.* time_slice |> Time.fromReal
|
blanchet@45437
|
638 |
fun sledge_tac time_slice prover type_enc =
|
blanchet@45413
|
639 |
Sledgehammer_Tactics.sledgehammer_as_oracle_tac ctxt
|
blanchet@45437
|
640 |
(override_params prover type_enc (my_timeout time_slice))
|
blanchet@45437
|
641 |
relevance_override
|
blanchet@45319
|
642 |
in
|
blanchet@45319
|
643 |
if !reconstructor = "sledgehammer_tac" then
|
blanchet@47263
|
644 |
sledge_tac 0.2 ATP_Systems.z3_tptpN "mono_native"
|
blanchet@45639
|
645 |
ORELSE' sledge_tac 0.2 ATP_Systems.eN "mono_guards??"
|
blanchet@45639
|
646 |
ORELSE' sledge_tac 0.2 ATP_Systems.vampireN "mono_guards??"
|
blanchet@45639
|
647 |
ORELSE' sledge_tac 0.2 ATP_Systems.spassN "poly_tags"
|
blanchet@47193
|
648 |
ORELSE' Metis_Tactic.metis_tac [] ATP_Problem_Generate.combsN
|
blanchet@47148
|
649 |
ctxt thms
|
blanchet@45319
|
650 |
else if !reconstructor = "smt" then
|
blanchet@45319
|
651 |
SMT_Solver.smt_tac ctxt thms
|
blanchet@46390
|
652 |
else if full then
|
blanchet@47148
|
653 |
Metis_Tactic.metis_tac [ATP_Proof_Reconstruct.full_typesN]
|
blanchet@47148
|
654 |
ATP_Proof_Reconstruct.metis_default_lam_trans ctxt thms
|
blanchet@46390
|
655 |
else if String.isPrefix "metis (" (!reconstructor) then
|
blanchet@46390
|
656 |
let
|
blanchet@46390
|
657 |
val (type_encs, lam_trans) =
|
blanchet@46390
|
658 |
!reconstructor
|
blanchet@46390
|
659 |
|> Outer_Syntax.scan Position.start
|
blanchet@46390
|
660 |
|> filter Token.is_proper |> tl
|
blanchet@46390
|
661 |
|> Metis_Tactic.parse_metis_options |> fst
|
blanchet@47148
|
662 |
|>> the_default [ATP_Proof_Reconstruct.partial_typesN]
|
blanchet@47148
|
663 |
||> the_default ATP_Proof_Reconstruct.metis_default_lam_trans
|
blanchet@46390
|
664 |
in Metis_Tactic.metis_tac type_encs lam_trans ctxt thms end
|
blanchet@45319
|
665 |
else if !reconstructor = "metis" then
|
blanchet@47148
|
666 |
Metis_Tactic.metis_tac [] ATP_Proof_Reconstruct.metis_default_lam_trans ctxt
|
blanchet@46390
|
667 |
thms
|
blanchet@45319
|
668 |
else
|
blanchet@45319
|
669 |
K all_tac
|
blanchet@45319
|
670 |
end
|
blanchet@45319
|
671 |
fun apply_reconstructor named_thms =
|
blanchet@45319
|
672 |
Mirabelle.can_apply timeout (do_reconstructor named_thms) st
|
boehmes@32521
|
673 |
|
boehmes@32521
|
674 |
fun with_time (false, t) = "failed (" ^ string_of_int t ^ ")"
|
blanchet@40915
|
675 |
| with_time (true, t) = (change_data id (inc_reconstructor_success m);
|
blanchet@40915
|
676 |
if trivial then ()
|
blanchet@40915
|
677 |
else change_data id (inc_reconstructor_nontriv_success m);
|
blanchet@40915
|
678 |
change_data id (inc_reconstructor_lemmas m (length named_thms));
|
blanchet@40915
|
679 |
change_data id (inc_reconstructor_time m t);
|
blanchet@40915
|
680 |
change_data id (inc_reconstructor_posns m (pos, trivial));
|
blanchet@40915
|
681 |
if name = "proof" then change_data id (inc_reconstructor_proofs m)
|
blanchet@40915
|
682 |
else ();
|
boehmes@32521
|
683 |
"succeeded (" ^ string_of_int t ^ ")")
|
blanchet@45319
|
684 |
fun timed_reconstructor named_thms =
|
blanchet@45319
|
685 |
(with_time (Mirabelle.cpu_time apply_reconstructor named_thms), true)
|
blanchet@40915
|
686 |
handle TimeLimit.TimeOut => (change_data id (inc_reconstructor_timeout m);
|
boehmes@34048
|
687 |
("timeout", false))
|
boehmes@34048
|
688 |
| ERROR msg => ("error: " ^ msg, false)
|
boehmes@32521
|
689 |
|
boehmes@32525
|
690 |
val _ = log separator
|
blanchet@40915
|
691 |
val _ = change_data id (inc_reconstructor_calls m)
|
blanchet@40915
|
692 |
val _ = if trivial then ()
|
blanchet@40915
|
693 |
else change_data id (inc_reconstructor_nontriv_calls m)
|
boehmes@32521
|
694 |
in
|
blanchet@45319
|
695 |
named_thms
|
blanchet@40915
|
696 |
|> timed_reconstructor
|
blanchet@40915
|
697 |
|>> log o prefix (reconstructor_tag reconstructor id)
|
boehmes@34048
|
698 |
|> snd
|
boehmes@32521
|
699 |
end
|
boehmes@32432
|
700 |
|
blanchet@41524
|
701 |
val try_timeout = seconds 5.0
|
blanchet@39583
|
702 |
|
blanchet@45302
|
703 |
(* crude hack *)
|
blanchet@45302
|
704 |
val num_sledgehammer_calls = Unsynchronized.ref 0
|
blanchet@45302
|
705 |
|
boehmes@34033
|
706 |
fun sledgehammer_action args id (st as {pre, name, ...}: Mirabelle.run_args) =
|
wenzelm@35596
|
707 |
let val goal = Thm.major_prem_of (#goal (Proof.goal pre)) in
|
wenzelm@35596
|
708 |
if can Logic.dest_conjunction goal orelse can Logic.dest_equals goal
|
wenzelm@35596
|
709 |
then () else
|
wenzelm@35596
|
710 |
let
|
blanchet@45302
|
711 |
val max_calls =
|
sultana@48352
|
712 |
AList.lookup (op =) args max_callsK |> the_default max_calls_default
|
blanchet@45302
|
713 |
|> Int.fromString |> the
|
blanchet@45302
|
714 |
val _ = num_sledgehammer_calls := !num_sledgehammer_calls + 1;
|
blanchet@45305
|
715 |
in
|
blanchet@45302
|
716 |
if !num_sledgehammer_calls > max_calls then ()
|
blanchet@45302
|
717 |
else
|
blanchet@45305
|
718 |
let
|
blanchet@45305
|
719 |
val reconstructor = Unsynchronized.ref ""
|
blanchet@45305
|
720 |
val named_thms =
|
blanchet@47168
|
721 |
Unsynchronized.ref (NONE : ((string * stature) * thm list) list option)
|
blanchet@45305
|
722 |
val minimize = AList.defined (op =) args minimizeK
|
blanchet@45305
|
723 |
val metis_ft = AList.defined (op =) args metis_ftK
|
blanchet@45305
|
724 |
val trivial =
|
sultana@48352
|
725 |
if AList.lookup (op =) args check_trivialK |> the_default trivial_default
|
sultana@48072
|
726 |
|> Bool.fromString |> the then
|
sultana@48072
|
727 |
Try0.try0 (SOME try_timeout) ([], [], [], []) pre
|
sultana@48072
|
728 |
handle TimeLimit.TimeOut => false
|
sultana@48072
|
729 |
else false
|
blanchet@45305
|
730 |
fun apply_reconstructor m1 m2 =
|
blanchet@45305
|
731 |
if metis_ft
|
blanchet@45305
|
732 |
then
|
blanchet@45305
|
733 |
if not (Mirabelle.catch_result (reconstructor_tag reconstructor) false
|
blanchet@45305
|
734 |
(run_reconstructor trivial false m1 name reconstructor
|
blanchet@45305
|
735 |
(these (!named_thms))) id st)
|
blanchet@45305
|
736 |
then
|
blanchet@45305
|
737 |
(Mirabelle.catch_result (reconstructor_tag reconstructor) false
|
blanchet@45305
|
738 |
(run_reconstructor trivial true m2 name reconstructor
|
blanchet@45305
|
739 |
(these (!named_thms))) id st; ())
|
blanchet@45305
|
740 |
else ()
|
blanchet@45305
|
741 |
else
|
blanchet@45305
|
742 |
(Mirabelle.catch_result (reconstructor_tag reconstructor) false
|
blanchet@45305
|
743 |
(run_reconstructor trivial false m1 name reconstructor
|
blanchet@45305
|
744 |
(these (!named_thms))) id st; ())
|
blanchet@45305
|
745 |
in
|
blanchet@45305
|
746 |
change_data id (set_mini minimize);
|
blanchet@45305
|
747 |
Mirabelle.catch sh_tag (run_sledgehammer trivial args reconstructor
|
blanchet@45305
|
748 |
named_thms) id st;
|
blanchet@45305
|
749 |
if is_some (!named_thms)
|
blanchet@45302
|
750 |
then
|
blanchet@45305
|
751 |
(apply_reconstructor Unminimized UnminimizedFT;
|
blanchet@45305
|
752 |
if minimize andalso not (null (these (!named_thms)))
|
blanchet@45305
|
753 |
then
|
blanchet@45305
|
754 |
(Mirabelle.catch minimize_tag
|
blanchet@45305
|
755 |
(run_minimize args reconstructor named_thms) id st;
|
blanchet@45305
|
756 |
apply_reconstructor Minimized MinimizedFT)
|
blanchet@45305
|
757 |
else ())
|
blanchet@45305
|
758 |
else ()
|
blanchet@45305
|
759 |
end
|
wenzelm@35596
|
760 |
end
|
nipkow@32810
|
761 |
end
|
boehmes@32385
|
762 |
|
boehmes@32511
|
763 |
fun invoke args =
|
blanchet@44431
|
764 |
Mirabelle.register (init, sledgehammer_action args, done)
|
boehmes@32385
|
765 |
|
boehmes@32385
|
766 |
end
|