author | nipkow |
Thu, 01 Oct 2009 11:35:13 +0200 | |
changeset 32818 | 6c91e668b15e |
parent 32676 | b1c85a117dec |
child 32819 | 004b251ac927 |
permissions | -rw-r--r-- |
32564 | 1 |
(* Title: HOL/Mirabelle/Tools/mirabelle_sledgehammer.ML |
2 |
Author: Jasmin Blanchette and Sascha Boehme and Tobias Nipkow, TU Munich |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
3 |
*) |
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
4 |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
5 |
structure Mirabelle_Sledgehammer : MIRABELLE_ACTION = |
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
6 |
struct |
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
7 |
|
32521 | 8 |
val proverK = "prover" |
32541 | 9 |
val prover_timeoutK = "prover_timeout" |
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
10 |
val prover_hard_timeoutK = "prover_hard_timeout" |
32521 | 11 |
val keepK = "keep" |
12 |
val full_typesK = "full_types" |
|
32525 | 13 |
val minimizeK = "minimize" |
14 |
val minimize_timeoutK = "minimize_timeout" |
|
32521 | 15 |
|
16 |
fun sh_tag id = "#" ^ string_of_int id ^ " sledgehammer: " |
|
32525 | 17 |
fun minimize_tag id = "#" ^ string_of_int id ^ " minimize (sledgehammer): " |
32521 | 18 |
fun metis_tag id = "#" ^ string_of_int id ^ " metis (sledgehammer): " |
19 |
||
32525 | 20 |
val separator = "-----" |
21 |
||
32521 | 22 |
|
32549 | 23 |
datatype sh_data = ShData of { |
24 |
calls: int, |
|
25 |
success: int, |
|
32585 | 26 |
lemmas: int, |
32818 | 27 |
max_lems: int, |
32549 | 28 |
time_isa: int, |
29 |
time_atp: int, |
|
30 |
time_atp_fail: int} |
|
31 |
||
32 |
datatype me_data = MeData of { |
|
33 |
calls: int, |
|
34 |
success: int, |
|
32676 | 35 |
proofs: int, |
32549 | 36 |
time: int, |
32550 | 37 |
timeout: int, |
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
38 |
lemmas: int, |
32818 | 39 |
max_lems: int, |
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
40 |
posns: Position.T list |
32550 | 41 |
} |
32549 | 42 |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
43 |
datatype min_data = MinData of { |
32609 | 44 |
succs: int, |
45 |
ab_ratios: int, |
|
46 |
it_ratios: int |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
47 |
} |
32521 | 48 |
|
32549 | 49 |
(* The first me_data component is only used if "minimize" is on. |
50 |
Then it records how metis behaves with un-minimized lemmas. |
|
51 |
*) |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
52 |
datatype data = Data of sh_data * me_data * min_data * me_data |
32549 | 53 |
|
32818 | 54 |
fun make_sh_data |
55 |
(calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail) = |
|
56 |
ShData{calls=calls, success=success, lemmas=lemmas, max_lems=max_lems, |
|
57 |
time_isa=time_isa, time_atp=time_atp, time_atp_fail=time_atp_fail} |
|
32521 | 58 |
|
32609 | 59 |
fun make_min_data (succs, ab_ratios, it_ratios) = |
60 |
MinData{succs=succs, ab_ratios=ab_ratios, it_ratios=it_ratios} |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
61 |
|
32818 | 62 |
fun make_me_data (calls,success,proofs,time,timeout,lemmas,max_lems,posns) = |
63 |
MeData{calls=calls, success=success, proofs=proofs, time=time, |
|
64 |
timeout=timeout, lemmas=lemmas, max_lems=max_lems, posns=posns} |
|
32549 | 65 |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
66 |
val empty_data = |
32818 | 67 |
Data(make_sh_data (0, 0, 0, 0, 0, 0, 0), |
68 |
make_me_data(0, 0, 0, 0, 0, 0, 0, []), |
|
32609 | 69 |
MinData{succs=0, ab_ratios=0, it_ratios=0}, |
32818 | 70 |
make_me_data(0, 0, 0, 0, 0, 0, 0, [])) |
32521 | 71 |
|
32549 | 72 |
fun map_sh_data f |
32818 | 73 |
(Data(ShData{calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail}, |
74 |
meda0, minda, meda)) = |
|
75 |
Data (make_sh_data (f (calls,success,lemmas,max_lems, |
|
76 |
time_isa,time_atp,time_atp_fail)), |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
77 |
meda0, minda, meda) |
32521 | 78 |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
79 |
fun map_min_data f |
32609 | 80 |
(Data(shda, meda0, MinData{succs,ab_ratios,it_ratios}, meda)) = |
81 |
Data(shda, meda0, make_min_data(f(succs,ab_ratios,it_ratios)), meda) |
|
32521 | 82 |
|
32818 | 83 |
fun map_me_data0 f (Data (shda, MeData{calls,success,proofs,time,timeout,lemmas,max_lems,posns}, minda, meda)) = |
84 |
Data(shda, make_me_data(f (calls,success,proofs,time,timeout,lemmas,max_lems,posns)), minda, meda) |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
85 |
|
32818 | 86 |
fun map_me_data f (Data (shda, meda0, minda, MeData{calls,success,proofs,time,timeout,lemmas,max_lems,posns})) = |
87 |
Data(shda, meda0, minda, make_me_data(f (calls,success,proofs,time,timeout,lemmas,max_lems,posns))) |
|
32521 | 88 |
|
32818 | 89 |
val inc_sh_calls = map_sh_data |
90 |
(fn (calls, success, lemmas,max_lems, time_isa, time_atp, time_atp_fail) |
|
91 |
=> (calls + 1, success, lemmas,max_lems, time_isa, time_atp, time_atp_fail)) |
|
32549 | 92 |
|
32818 | 93 |
val inc_sh_success = map_sh_data |
94 |
(fn (calls, success, lemmas,max_lems, time_isa, time_atp, time_atp_fail) |
|
95 |
=> (calls, success + 1, lemmas,max_lems, time_isa, time_atp, time_atp_fail)) |
|
32585 | 96 |
|
32818 | 97 |
fun inc_sh_lemmas n = map_sh_data |
98 |
(fn (calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail) |
|
99 |
=> (calls,success,lemmas+n,max_lems,time_isa,time_atp,time_atp_fail)) |
|
32521 | 100 |
|
32818 | 101 |
fun inc_sh_max_lems n = map_sh_data |
102 |
(fn (calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail) |
|
103 |
=> (calls,success,lemmas,Int.max(max_lems,n),time_isa,time_atp,time_atp_fail)) |
|
32549 | 104 |
|
32818 | 105 |
fun inc_sh_time_isa t = map_sh_data |
106 |
(fn (calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail) |
|
107 |
=> (calls,success,lemmas,max_lems,time_isa + t,time_atp,time_atp_fail)) |
|
108 |
||
109 |
fun inc_sh_time_atp t = map_sh_data |
|
110 |
(fn (calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail) |
|
111 |
=> (calls,success,lemmas,max_lems,time_isa,time_atp + t,time_atp_fail)) |
|
32521 | 112 |
|
32818 | 113 |
fun inc_sh_time_atp_fail t = map_sh_data |
114 |
(fn (calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail) |
|
115 |
=> (calls,success,lemmas,max_lems,time_isa,time_atp,time_atp_fail + t)) |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
116 |
|
32818 | 117 |
val inc_min_succs = map_min_data |
118 |
(fn (succs,ab_ratios,it_ratios) => (succs+1, ab_ratios, it_ratios)) |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
119 |
|
32818 | 120 |
fun inc_min_ab_ratios r = map_min_data |
121 |
(fn (succs, ab_ratios, it_ratios) => (succs, ab_ratios+r, it_ratios)) |
|
32609 | 122 |
|
32818 | 123 |
fun inc_min_it_ratios r = map_min_data |
124 |
(fn (succs, ab_ratios, it_ratios) => (succs, ab_ratios, it_ratios+r)) |
|
32549 | 125 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
126 |
val inc_metis_calls = map_me_data |
32818 | 127 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
128 |
=> (calls + 1, success, proofs, time, timeout, lemmas,max_lems,posns)) |
|
32533 | 129 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
130 |
val inc_metis_success = map_me_data |
32818 | 131 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
132 |
=> (calls, success + 1, proofs, time, timeout, lemmas,max_lems,posns)) |
|
32676 | 133 |
|
134 |
val inc_metis_proofs = map_me_data |
|
32818 | 135 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
136 |
=> (calls, success, proofs + 1, time, timeout, lemmas,max_lems,posns)) |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
137 |
|
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
138 |
fun inc_metis_time t = map_me_data |
32818 | 139 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
140 |
=> (calls, success, proofs, time + t, timeout, lemmas,max_lems,posns)) |
|
32536 | 141 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
142 |
val inc_metis_timeout = map_me_data |
32818 | 143 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
144 |
=> (calls, success, proofs, time, timeout + 1, lemmas,max_lems,posns)) |
|
32549 | 145 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
146 |
fun inc_metis_lemmas n = map_me_data |
32818 | 147 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
148 |
=> (calls, success, proofs, time, timeout, lemmas+n, max_lems, posns)) |
|
149 |
||
150 |
fun inc_metis_max_lems n = map_me_data |
|
151 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
|
152 |
=> (calls,success,proofs,time,timeout,lemmas,Int.max(max_lems,n), posns)) |
|
32550 | 153 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
154 |
fun inc_metis_posns pos = map_me_data |
32818 | 155 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
156 |
=> (calls, success, proofs, time, timeout, lemmas,max_lems, pos::posns)) |
|
32521 | 157 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
158 |
val inc_metis_calls0 = map_me_data0 |
32818 | 159 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
160 |
=> (calls + 1, success, proofs, time, timeout, lemmas,max_lems,posns)) |
|
32549 | 161 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
162 |
val inc_metis_success0 = map_me_data0 |
32818 | 163 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
164 |
=> (calls, success + 1, proofs, time, timeout, lemmas,max_lems,posns)) |
|
32676 | 165 |
|
166 |
val inc_metis_proofs0 = map_me_data0 |
|
32818 | 167 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
168 |
=> (calls, success, proofs + 1, time, timeout, lemmas,max_lems,posns)) |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
169 |
|
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
170 |
fun inc_metis_time0 t = map_me_data0 |
32818 | 171 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
172 |
=> (calls, success, proofs, time + t, timeout, lemmas,max_lems,posns)) |
|
32521 | 173 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
174 |
val inc_metis_timeout0 = map_me_data0 |
32818 | 175 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
176 |
=> (calls, success, proofs, time, timeout + 1, lemmas,max_lems,posns)) |
|
32549 | 177 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
178 |
fun inc_metis_lemmas0 n = map_me_data0 |
32818 | 179 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
180 |
=> (calls, success, proofs, time, timeout, lemmas+n, max_lems, posns)) |
|
181 |
||
182 |
fun inc_metis_max_lems0 n = map_me_data0 |
|
183 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
|
184 |
=> (calls,success,proofs,time,timeout,lemmas,Int.max(max_lems,n), posns)) |
|
32521 | 185 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
186 |
fun inc_metis_posns0 pos = map_me_data0 |
32818 | 187 |
(fn (calls,success,proofs,time,timeout,lemmas,max_lems,posns) |
188 |
=> (calls, success, proofs, time, timeout, lemmas,max_lems, pos::posns)) |
|
32521 | 189 |
|
190 |
local |
|
191 |
||
192 |
val str = string_of_int |
|
193 |
val str3 = Real.fmt (StringCvt.FIX (SOME 3)) |
|
194 |
fun percentage a b = string_of_int (a * 100 div b) |
|
195 |
fun time t = Real.fromInt t / 1000.0 |
|
196 |
fun avg_time t n = |
|
197 |
if n > 0 then (Real.fromInt t / 1000.0) / Real.fromInt n else 0.0 |
|
198 |
||
32818 | 199 |
fun log_sh_data log calls success lemmas max_lems time_isa time_atp time_atp_fail = |
200 |
(log ("Total number of sledgehammer calls: " ^ str calls); |
|
201 |
log ("Number of successful sledgehammer calls: " ^ str success); |
|
202 |
log ("Number of sledgehammer lemmas: " ^ str lemmas); |
|
203 |
log ("Max number of sledgehammer lemmas: " ^ str max_lems); |
|
204 |
log ("Success rate: " ^ percentage success calls ^ "%"); |
|
205 |
log ("Total time for sledgehammer calls (Isabelle): " ^ str3 (time time_isa)); |
|
206 |
log ("Total time for successful sledgehammer calls (ATP): " ^ str3 (time time_atp)); |
|
207 |
log ("Total time for failed sledgehammer calls (ATP): " ^ str3 (time time_atp_fail)); |
|
32536 | 208 |
log ("Average time for sledgehammer calls (Isabelle): " ^ |
32818 | 209 |
str3 (avg_time time_isa calls)); |
32533 | 210 |
log ("Average time for successful sledgehammer calls (ATP): " ^ |
32818 | 211 |
str3 (avg_time time_atp success)); |
32536 | 212 |
log ("Average time for failed sledgehammer calls (ATP): " ^ |
32818 | 213 |
str3 (avg_time time_atp_fail (calls - success))) |
32533 | 214 |
) |
32521 | 215 |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
216 |
|
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
217 |
fun str_of_pos pos = |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
218 |
let val str0 = string_of_int o the_default 0 |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
219 |
in str0 (Position.line_of pos) ^ ":" ^ str0 (Position.column_of pos) end |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
220 |
|
32676 | 221 |
fun log_metis_data log tag sh_calls sh_success metis_calls metis_success metis_proofs metis_time |
32818 | 222 |
metis_timeout metis_lemmas metis_max_lems metis_posns = |
32549 | 223 |
(log ("Total number of " ^ tag ^ "metis calls: " ^ str metis_calls); |
32676 | 224 |
log ("Number of successful " ^ tag ^ "metis calls: " ^ str metis_success ^ " (proof: " ^ str metis_proofs ^ ")"); |
32549 | 225 |
log ("Number of " ^ tag ^ "metis timeouts: " ^ str metis_timeout); |
32533 | 226 |
log ("Success rate: " ^ percentage metis_success sh_calls ^ "%"); |
32585 | 227 |
log ("Number of successful " ^ tag ^ "metis lemmas: " ^ str metis_lemmas); |
32818 | 228 |
log ("Max number of successful " ^ tag ^ "metis lemmas: " ^ str metis_max_lems); |
32521 | 229 |
log ("Total time for successful metis calls: " ^ str3 (time metis_time)); |
230 |
log ("Average time for successful metis calls: " ^ |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
231 |
str3 (avg_time metis_time metis_success)); |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
232 |
if tag="" |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
233 |
then log ("Proved: " ^ space_implode " " (map str_of_pos metis_posns)) |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
234 |
else () |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
235 |
) |
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
236 |
|
32609 | 237 |
fun log_min_data log succs ab_ratios it_ratios = |
238 |
(log ("Number of successful minimizations: " ^ string_of_int succs); |
|
239 |
log ("After/before ratios: " ^ string_of_int ab_ratios); |
|
240 |
log ("Iterations ratios: " ^ string_of_int it_ratios) |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
241 |
) |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
242 |
|
32521 | 243 |
in |
244 |
||
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
245 |
fun log_data id log (Data |
32818 | 246 |
(ShData{calls=sh_calls, lemmas=sh_lemmas, max_lems=sh_max_lems, success=sh_success, |
32585 | 247 |
time_isa=sh_time_isa,time_atp=sh_time_atp,time_atp_fail=sh_time_atp_fail}, |
32676 | 248 |
MeData{calls=metis_calls0, proofs=metis_proofs0, |
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
249 |
success=metis_success0, time=metis_time0, timeout=metis_timeout0, |
32818 | 250 |
lemmas=metis_lemmas0,max_lems=metis_max_lems0,posns=metis_posns0}, |
32609 | 251 |
MinData{succs=min_succs, ab_ratios=ab_ratios, it_ratios=it_ratios}, |
32676 | 252 |
MeData{calls=metis_calls, proofs=metis_proofs, |
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
253 |
success=metis_success, time=metis_time, timeout=metis_timeout, |
32818 | 254 |
lemmas=metis_lemmas,max_lems=metis_max_lems,posns=metis_posns})) = |
32521 | 255 |
if sh_calls > 0 |
256 |
then |
|
257 |
(log ("\n\n\nReport #" ^ string_of_int id ^ ":\n"); |
|
32818 | 258 |
log_sh_data log sh_calls sh_success sh_lemmas sh_max_lems sh_time_isa sh_time_atp sh_time_atp_fail; |
32521 | 259 |
log ""; |
32549 | 260 |
if metis_calls > 0 then log_metis_data log "" sh_calls sh_success metis_calls |
32818 | 261 |
metis_success metis_proofs metis_time metis_timeout metis_lemmas metis_max_lems metis_posns else (); |
32549 | 262 |
log ""; |
263 |
if metis_calls0 > 0 |
|
32609 | 264 |
then (log_min_data log min_succs ab_ratios it_ratios; log ""; |
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
265 |
log_metis_data log "unminimized " sh_calls sh_success metis_calls0 |
32818 | 266 |
metis_success0 metis_proofs0 metis_time0 metis_timeout0 metis_lemmas0 metis_max_lems0 metis_posns0) |
32549 | 267 |
else () |
268 |
) |
|
32521 | 269 |
else () |
270 |
||
271 |
end |
|
272 |
||
273 |
||
274 |
(* Warning: we implicitly assume single-threaded execution here! *) |
|
275 |
val data = ref ([] : (int * data) list) |
|
276 |
||
277 |
fun init id thy = (change data (cons (id, empty_data)); thy) |
|
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
278 |
fun done id ({log, ...}: Mirabelle.done_args) = |
32521 | 279 |
AList.lookup (op =) (!data) id |
280 |
|> Option.map (log_data id log) |
|
281 |
|> K () |
|
282 |
||
283 |
fun change_data id f = (change data (AList.map_entry (op =) id f); ()) |
|
284 |
||
285 |
||
32525 | 286 |
fun get_atp thy args = |
287 |
AList.lookup (op =) args proverK |
|
288 |
|> the_default (hd (space_explode " " (AtpManager.get_atps ()))) |
|
289 |
|> (fn name => (name, the (AtpManager.get_prover name thy))) |
|
290 |
||
32521 | 291 |
local |
292 |
||
293 |
fun safe init done f x = |
|
294 |
let |
|
295 |
val y = init x |
|
296 |
val z = Exn.capture f y |
|
297 |
val _ = done y |
|
298 |
in Exn.release z end |
|
299 |
||
300 |
fun init_sh NONE = !AtpWrapper.destdir |
|
301 |
| init_sh (SOME path) = |
|
302 |
let |
|
303 |
(* Warning: we implicitly assume single-threaded execution here! *) |
|
304 |
val old = !AtpWrapper.destdir |
|
305 |
val _ = AtpWrapper.destdir := path |
|
306 |
in old end |
|
307 |
||
308 |
fun done_sh path = AtpWrapper.destdir := path |
|
309 |
||
32536 | 310 |
datatype sh_result = |
311 |
SH_OK of int * int * string list | |
|
312 |
SH_FAIL of int * int | |
|
313 |
SH_ERROR |
|
314 |
||
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
315 |
fun run_sh (prover_name, prover) hard_timeout timeout st _ = |
32521 | 316 |
let |
32541 | 317 |
val atp = prover timeout NONE NONE prover_name 1 |
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
318 |
val time_limit = |
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
319 |
(case hard_timeout of |
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
320 |
NONE => I |
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
321 |
| SOME secs => TimeLimit.timeLimit (Time.fromSeconds secs)) |
32536 | 322 |
val ((success, (message, thm_names), time_atp, _, _, _), time_isa) = |
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
323 |
time_limit (Mirabelle.cpu_time atp) (Proof.get_goal st) |
32521 | 324 |
in |
32536 | 325 |
if success then (message, SH_OK (time_isa, time_atp, thm_names)) |
326 |
else (message, SH_FAIL(time_isa, time_atp)) |
|
32521 | 327 |
end |
32536 | 328 |
handle ResHolClause.TOO_TRIVIAL => ("trivial", SH_OK (0, 0, [])) |
329 |
| ERROR msg => ("error: " ^ msg, SH_ERROR) |
|
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
330 |
| TimeLimit.TimeOut => ("timeout", SH_ERROR) |
32521 | 331 |
|
32454
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
332 |
fun thms_of_name ctxt name = |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
333 |
let |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
334 |
val lex = OuterKeyword.get_lexicons |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
335 |
val get = maps (ProofContext.get_fact ctxt o fst) |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
336 |
in |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
337 |
Source.of_string name |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
338 |
|> Symbol.source {do_recover=false} |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
339 |
|> OuterLex.source {do_recover=SOME false} lex Position.start |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
340 |
|> OuterLex.source_proper |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
341 |
|> Source.source OuterLex.stopper (SpecParse.xthms1 >> get) NONE |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
342 |
|> Source.exhaust |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
343 |
end |
32452
d84edd022efe
apply metis with found theorems in case sledgehammer was successful
boehmes
parents:
32434
diff
changeset
|
344 |
|
32498
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
345 |
in |
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
346 |
|
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
347 |
fun run_sledgehammer args named_thms id ({pre=st, log, ...}: Mirabelle.run_args) = |
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
348 |
let |
32536 | 349 |
val _ = change_data id inc_sh_calls |
32525 | 350 |
val atp as (prover_name, _) = get_atp (Proof.theory_of st) args |
351 |
val dir = AList.lookup (op =) args keepK |
|
32541 | 352 |
val timeout = Mirabelle.get_int_setting args (prover_timeoutK, 30) |
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
353 |
val hard_timeout = AList.lookup (op =) args prover_hard_timeoutK |
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
354 |
|> Option.map (fst o read_int o explode) |
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
355 |
val (msg, result) = safe init_sh done_sh |
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
356 |
(run_sh atp hard_timeout timeout st) dir |
32525 | 357 |
in |
32536 | 358 |
case result of |
359 |
SH_OK (time_isa, time_atp, names) => |
|
32818 | 360 |
let fun get_thms name = (name, thms_of_name (Proof.context_of st) name) |
32525 | 361 |
in |
32818 | 362 |
change_data id inc_sh_success; |
363 |
change_data id (inc_sh_lemmas (length names)); |
|
364 |
change_data id (inc_sh_max_lems (length names)); |
|
365 |
change_data id (inc_sh_time_isa time_isa); |
|
366 |
change_data id (inc_sh_time_atp time_atp); |
|
367 |
named_thms := SOME (map get_thms names); |
|
32536 | 368 |
log (sh_tag id ^ "succeeded (" ^ string_of_int time_isa ^ "+" ^ |
369 |
string_of_int time_atp ^ ") [" ^ prover_name ^ "]:\n" ^ msg) |
|
32525 | 370 |
end |
32536 | 371 |
| SH_FAIL (time_isa, time_atp) => |
372 |
let |
|
373 |
val _ = change_data id (inc_sh_time_isa time_isa) |
|
374 |
val _ = change_data id (inc_sh_time_atp_fail time_atp) |
|
375 |
in log (sh_tag id ^ "failed: " ^ msg) end |
|
376 |
| SH_ERROR => log (sh_tag id ^ "failed: " ^ msg) |
|
32525 | 377 |
end |
378 |
||
379 |
end |
|
380 |
||
32521 | 381 |
|
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
382 |
fun run_minimize args named_thms id ({pre=st, log, ...}: Mirabelle.run_args) = |
32525 | 383 |
let |
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
384 |
val n0 = length (these (!named_thms)) |
32525 | 385 |
val (prover_name, prover) = get_atp (Proof.theory_of st) args |
386 |
val minimize = AtpMinimal.minimalize prover prover_name |
|
387 |
val timeout = |
|
388 |
AList.lookup (op =) args minimize_timeoutK |
|
389 |
|> Option.map (fst o read_int o explode) |
|
390 |
|> the_default 5 |
|
391 |
val _ = log separator |
|
392 |
in |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
393 |
case minimize timeout st (these (!named_thms)) of |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
394 |
(SOME (named_thms',its), msg) => |
32609 | 395 |
(change_data id inc_min_succs; |
396 |
change_data id (inc_min_ab_ratios ((100 * length named_thms') div n0)); |
|
397 |
change_data id (inc_min_it_ratios ((100*its) div n0)); |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
398 |
if length named_thms' = n0 |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
399 |
then log (minimize_tag id ^ "already minimal") |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
400 |
else (named_thms := SOME named_thms'; |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
401 |
log (minimize_tag id ^ "succeeded:\n" ^ msg)) |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
402 |
) |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
403 |
| (NONE, msg) => log (minimize_tag id ^ "failed: " ^ msg) |
32525 | 404 |
end |
405 |
||
406 |
||
32676 | 407 |
fun run_metis (inc_metis_calls, inc_metis_success, inc_metis_proofs, inc_metis_time, inc_metis_timeout, |
32818 | 408 |
inc_metis_lemmas, inc_metis_max_lems, inc_metis_posns) args name named_thms id |
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
409 |
({pre=st, timeout, log, pos, ...}: Mirabelle.run_args) = |
32525 | 410 |
let |
32521 | 411 |
fun metis thms ctxt = MetisTools.metis_tac ctxt thms |
412 |
fun apply_metis thms = Mirabelle.can_apply timeout (metis thms) st |
|
413 |
||
414 |
fun with_time (false, t) = "failed (" ^ string_of_int t ^ ")" |
|
415 |
| with_time (true, t) = (change_data id inc_metis_success; |
|
32585 | 416 |
change_data id (inc_metis_lemmas (length named_thms)); |
32818 | 417 |
change_data id (inc_metis_max_lems (length named_thms)); |
32521 | 418 |
change_data id (inc_metis_time t); |
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
419 |
change_data id (inc_metis_posns pos); |
32676 | 420 |
if name = "proof" then change_data id inc_metis_proofs else (); |
32521 | 421 |
"succeeded (" ^ string_of_int t ^ ")") |
422 |
fun timed_metis thms = with_time (Mirabelle.cpu_time apply_metis thms) |
|
423 |
handle TimeLimit.TimeOut => (change_data id inc_metis_timeout; "timeout") |
|
424 |
| ERROR msg => "error: " ^ msg |
|
425 |
||
32525 | 426 |
val _ = log separator |
32521 | 427 |
val _ = change_data id inc_metis_calls |
428 |
in |
|
32525 | 429 |
maps snd named_thms |
32521 | 430 |
|> timed_metis |
431 |
|> log o prefix (metis_tag id) |
|
432 |
end |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
433 |
|
32676 | 434 |
fun sledgehammer_action args id (st as {log, pre, name, ...}: Mirabelle.run_args) = |
32818 | 435 |
let val goal = Thm.major_prem_of(snd(snd(Proof.get_goal pre))) in |
436 |
if can Logic.dest_conjunction goal orelse can Logic.dest_equals goal |
|
32607 | 437 |
then () else |
32515
e7c0d3c0494a
Mirabelle: actions are responsible for catching exceptions and producing suitable log messages (makes log message uniform),
boehmes
parents:
32511
diff
changeset
|
438 |
let |
32676 | 439 |
val metis_fns = (inc_metis_calls, inc_metis_success, inc_metis_proofs, inc_metis_time, |
32818 | 440 |
inc_metis_timeout, inc_metis_lemmas, inc_metis_max_lems, inc_metis_posns) |
32676 | 441 |
val metis0_fns = (inc_metis_calls0, inc_metis_success0, inc_metis_proofs0, inc_metis_time0, |
32818 | 442 |
inc_metis_timeout0, inc_metis_lemmas0, inc_metis_max_lems0, inc_metis_posns0) |
32525 | 443 |
val named_thms = ref (NONE : (string * thm list) list option) |
32612 | 444 |
val minimize = AList.defined (op =) args minimizeK |
445 |
in |
|
446 |
Mirabelle.catch sh_tag (run_sledgehammer args named_thms) id st; |
|
447 |
if is_some (!named_thms) |
|
448 |
then |
|
449 |
(if minimize |
|
32676 | 450 |
then Mirabelle.catch metis_tag (run_metis metis0_fns args name (these (!named_thms))) id st |
32612 | 451 |
else (); |
452 |
if minimize andalso not(null(these(!named_thms))) |
|
453 |
then Mirabelle.catch minimize_tag (run_minimize args named_thms) id st |
|
454 |
else (); |
|
32676 | 455 |
Mirabelle.catch metis_tag (run_metis metis_fns args name (these (!named_thms))) id st) |
32612 | 456 |
else () |
457 |
end |
|
32818 | 458 |
end |
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
459 |
|
32511 | 460 |
fun invoke args = |
32515
e7c0d3c0494a
Mirabelle: actions are responsible for catching exceptions and producing suitable log messages (makes log message uniform),
boehmes
parents:
32511
diff
changeset
|
461 |
let |
e7c0d3c0494a
Mirabelle: actions are responsible for catching exceptions and producing suitable log messages (makes log message uniform),
boehmes
parents:
32511
diff
changeset
|
462 |
val _ = AtpManager.set_full_types (AList.defined (op =) args full_typesK) |
32521 | 463 |
in Mirabelle.register (init, sledgehammer_action args, done) end |
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
464 |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
465 |
end |