author | boehmes |
Sun, 04 Oct 2009 11:45:41 +0200 | |
changeset 32868 | 5f1805c6ef2a |
parent 32864 | a226f29d4bdc |
child 32936 | 9491bec20595 |
child 32990 | 717680b14041 |
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); |
32740 | 224 |
log ("Number of successful " ^ tag ^ "metis calls: " ^ str metis_success ^ |
225 |
" (proof: " ^ str metis_proofs ^ ")"); |
|
32549 | 226 |
log ("Number of " ^ tag ^ "metis timeouts: " ^ str metis_timeout); |
32533 | 227 |
log ("Success rate: " ^ percentage metis_success sh_calls ^ "%"); |
32585 | 228 |
log ("Number of successful " ^ tag ^ "metis lemmas: " ^ str metis_lemmas); |
32818 | 229 |
log ("Max number of successful " ^ tag ^ "metis lemmas: " ^ str metis_max_lems); |
32521 | 230 |
log ("Total time for successful metis calls: " ^ str3 (time metis_time)); |
231 |
log ("Average time for successful metis calls: " ^ |
|
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
232 |
str3 (avg_time metis_time metis_success)); |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
233 |
if tag="" |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
234 |
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
|
235 |
else () |
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
236 |
) |
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
237 |
|
32609 | 238 |
fun log_min_data log succs ab_ratios it_ratios = |
239 |
(log ("Number of successful minimizations: " ^ string_of_int succs); |
|
240 |
log ("After/before ratios: " ^ string_of_int ab_ratios); |
|
241 |
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
|
242 |
) |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
243 |
|
32521 | 244 |
in |
245 |
||
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
246 |
fun log_data id log (Data |
32818 | 247 |
(ShData{calls=sh_calls, lemmas=sh_lemmas, max_lems=sh_max_lems, success=sh_success, |
32585 | 248 |
time_isa=sh_time_isa,time_atp=sh_time_atp,time_atp_fail=sh_time_atp_fail}, |
32676 | 249 |
MeData{calls=metis_calls0, proofs=metis_proofs0, |
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
250 |
success=metis_success0, time=metis_time0, timeout=metis_timeout0, |
32818 | 251 |
lemmas=metis_lemmas0,max_lems=metis_max_lems0,posns=metis_posns0}, |
32609 | 252 |
MinData{succs=min_succs, ab_ratios=ab_ratios, it_ratios=it_ratios}, |
32676 | 253 |
MeData{calls=metis_calls, proofs=metis_proofs, |
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
254 |
success=metis_success, time=metis_time, timeout=metis_timeout, |
32818 | 255 |
lemmas=metis_lemmas,max_lems=metis_max_lems,posns=metis_posns})) = |
32521 | 256 |
if sh_calls > 0 |
257 |
then |
|
258 |
(log ("\n\n\nReport #" ^ string_of_int id ^ ":\n"); |
|
32818 | 259 |
log_sh_data log sh_calls sh_success sh_lemmas sh_max_lems sh_time_isa sh_time_atp sh_time_atp_fail; |
32521 | 260 |
log ""; |
32549 | 261 |
if metis_calls > 0 then log_metis_data log "" sh_calls sh_success metis_calls |
32818 | 262 |
metis_success metis_proofs metis_time metis_timeout metis_lemmas metis_max_lems metis_posns else (); |
32549 | 263 |
log ""; |
264 |
if metis_calls0 > 0 |
|
32609 | 265 |
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
|
266 |
log_metis_data log "unminimized " sh_calls sh_success metis_calls0 |
32818 | 267 |
metis_success0 metis_proofs0 metis_time0 metis_timeout0 metis_lemmas0 metis_max_lems0 metis_posns0) |
32549 | 268 |
else () |
269 |
) |
|
32521 | 270 |
else () |
271 |
||
272 |
end |
|
273 |
||
274 |
||
275 |
(* Warning: we implicitly assume single-threaded execution here! *) |
|
32740 | 276 |
val data = Unsynchronized.ref ([] : (int * data) list) |
32521 | 277 |
|
32740 | 278 |
fun init id thy = (Unsynchronized.change data (cons (id, empty_data)); thy) |
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
279 |
fun done id ({log, ...}: Mirabelle.done_args) = |
32521 | 280 |
AList.lookup (op =) (!data) id |
281 |
|> Option.map (log_data id log) |
|
282 |
|> K () |
|
283 |
||
32740 | 284 |
fun change_data id f = (Unsynchronized.change data (AList.map_entry (op =) id f); ()) |
32521 | 285 |
|
286 |
||
32525 | 287 |
fun get_atp thy args = |
288 |
AList.lookup (op =) args proverK |
|
289 |
|> the_default (hd (space_explode " " (AtpManager.get_atps ()))) |
|
290 |
|> (fn name => (name, the (AtpManager.get_prover name thy))) |
|
291 |
||
32521 | 292 |
local |
293 |
||
32536 | 294 |
datatype sh_result = |
295 |
SH_OK of int * int * string list | |
|
296 |
SH_FAIL of int * int | |
|
297 |
SH_ERROR |
|
298 |
||
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
299 |
fun run_sh prover hard_timeout timeout dir st = |
32521 | 300 |
let |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
301 |
val (ctxt, goal) = Proof.get_goal st |
32868
5f1805c6ef2a
avoid exception Option: only apply "the" if needed
boehmes
parents:
32864
diff
changeset
|
302 |
val ctxt' = if is_none dir then ctxt |
5f1805c6ef2a
avoid exception Option: only apply "the" if needed
boehmes
parents:
32864
diff
changeset
|
303 |
else Config.put AtpWrapper.destdir (the dir) ctxt |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
304 |
val atp = prover (AtpWrapper.atp_problem_of_goal |
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
305 |
(AtpManager.get_full_types ()) 1 (ctxt', goal)) |
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
306 |
|
32574
719426c9e1eb
added hard timeout for sledgehammer based on elapsed time (no need to trust ATP's timeout handling);
boehmes
parents:
32571
diff
changeset
|
307 |
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
|
308 |
(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
|
309 |
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
|
310 |
| SOME secs => TimeLimit.timeLimit (Time.fromSeconds secs)) |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
311 |
val (AtpWrapper.Prover_Result {success, message, theorem_names, |
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
312 |
runtime=time_atp, ...}, time_isa) = |
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
313 |
time_limit (Mirabelle.cpu_time atp) timeout |
32521 | 314 |
in |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
315 |
if success then (message, SH_OK (time_isa, time_atp, theorem_names)) |
32536 | 316 |
else (message, SH_FAIL(time_isa, time_atp)) |
32521 | 317 |
end |
32536 | 318 |
handle ResHolClause.TOO_TRIVIAL => ("trivial", SH_OK (0, 0, [])) |
319 |
| 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
|
320 |
| TimeLimit.TimeOut => ("timeout", SH_ERROR) |
32521 | 321 |
|
32454
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
322 |
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
|
323 |
let |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
324 |
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
|
325 |
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
|
326 |
in |
a1a5589207ad
Mirabelle: proper parsing of theorem names found by sledgehammer, respecting test intervals given along with file names
boehmes
parents:
32452
diff
changeset
|
327 |
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
|
328 |
|> 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
|
329 |
|> 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
|
330 |
|> 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
|
331 |
|> 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
|
332 |
|> 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
|
333 |
end |
32452
d84edd022efe
apply metis with found theorems in case sledgehammer was successful
boehmes
parents:
32434
diff
changeset
|
334 |
|
32498
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
335 |
in |
1132c7c13f36
Mirabelle: actions are responsible for handling exceptions,
boehmes
parents:
32496
diff
changeset
|
336 |
|
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
337 |
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
|
338 |
let |
32536 | 339 |
val _ = change_data id inc_sh_calls |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
340 |
val (prover_name, prover) = get_atp (Proof.theory_of st) args |
32525 | 341 |
val dir = AList.lookup (op =) args keepK |
32541 | 342 |
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
|
343 |
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
|
344 |
|> Option.map (fst o read_int o explode) |
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32819
diff
changeset
|
345 |
val (msg, result) = run_sh prover hard_timeout timeout dir st |
32525 | 346 |
in |
32536 | 347 |
case result of |
348 |
SH_OK (time_isa, time_atp, names) => |
|
32818 | 349 |
let fun get_thms name = (name, thms_of_name (Proof.context_of st) name) |
32525 | 350 |
in |
32818 | 351 |
change_data id inc_sh_success; |
352 |
change_data id (inc_sh_lemmas (length names)); |
|
353 |
change_data id (inc_sh_max_lems (length names)); |
|
354 |
change_data id (inc_sh_time_isa time_isa); |
|
355 |
change_data id (inc_sh_time_atp time_atp); |
|
356 |
named_thms := SOME (map get_thms names); |
|
32536 | 357 |
log (sh_tag id ^ "succeeded (" ^ string_of_int time_isa ^ "+" ^ |
358 |
string_of_int time_atp ^ ") [" ^ prover_name ^ "]:\n" ^ msg) |
|
32525 | 359 |
end |
32536 | 360 |
| SH_FAIL (time_isa, time_atp) => |
361 |
let |
|
362 |
val _ = change_data id (inc_sh_time_isa time_isa) |
|
363 |
val _ = change_data id (inc_sh_time_atp_fail time_atp) |
|
364 |
in log (sh_tag id ^ "failed: " ^ msg) end |
|
365 |
| SH_ERROR => log (sh_tag id ^ "failed: " ^ msg) |
|
32525 | 366 |
end |
367 |
||
368 |
end |
|
369 |
||
32521 | 370 |
|
32567
de411627a985
explicitly export type abbreviations (as usual in SML97);
wenzelm
parents:
32564
diff
changeset
|
371 |
fun run_minimize args named_thms id ({pre=st, log, ...}: Mirabelle.run_args) = |
32525 | 372 |
let |
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
373 |
val n0 = length (these (!named_thms)) |
32525 | 374 |
val (prover_name, prover) = get_atp (Proof.theory_of st) args |
375 |
val minimize = AtpMinimal.minimalize prover prover_name |
|
376 |
val timeout = |
|
377 |
AList.lookup (op =) args minimize_timeoutK |
|
378 |
|> Option.map (fst o read_int o explode) |
|
379 |
|> the_default 5 |
|
380 |
val _ = log separator |
|
381 |
in |
|
32571
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
382 |
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
|
383 |
(SOME (named_thms',its), msg) => |
32609 | 384 |
(change_data id inc_min_succs; |
385 |
change_data id (inc_min_ab_ratios ((100 * length named_thms') div n0)); |
|
386 |
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
|
387 |
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
|
388 |
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
|
389 |
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
|
390 |
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
|
391 |
) |
d4bb776874b8
count number of iterations required for minimization (and fixed bug: minimization was always called)
nipkow
parents:
32567
diff
changeset
|
392 |
| (NONE, msg) => log (minimize_tag id ^ "failed: " ^ msg) |
32525 | 393 |
end |
394 |
||
395 |
||
32676 | 396 |
fun run_metis (inc_metis_calls, inc_metis_success, inc_metis_proofs, inc_metis_time, inc_metis_timeout, |
32818 | 397 |
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
|
398 |
({pre=st, timeout, log, pos, ...}: Mirabelle.run_args) = |
32525 | 399 |
let |
32521 | 400 |
fun metis thms ctxt = MetisTools.metis_tac ctxt thms |
401 |
fun apply_metis thms = Mirabelle.can_apply timeout (metis thms) st |
|
402 |
||
403 |
fun with_time (false, t) = "failed (" ^ string_of_int t ^ ")" |
|
404 |
| with_time (true, t) = (change_data id inc_metis_success; |
|
32585 | 405 |
change_data id (inc_metis_lemmas (length named_thms)); |
32818 | 406 |
change_data id (inc_metis_max_lems (length named_thms)); |
32521 | 407 |
change_data id (inc_metis_time t); |
32551
421323205efd
position information is now passed to all actions;
nipkow
parents:
32550
diff
changeset
|
408 |
change_data id (inc_metis_posns pos); |
32676 | 409 |
if name = "proof" then change_data id inc_metis_proofs else (); |
32521 | 410 |
"succeeded (" ^ string_of_int t ^ ")") |
411 |
fun timed_metis thms = with_time (Mirabelle.cpu_time apply_metis thms) |
|
412 |
handle TimeLimit.TimeOut => (change_data id inc_metis_timeout; "timeout") |
|
413 |
| ERROR msg => "error: " ^ msg |
|
414 |
||
32525 | 415 |
val _ = log separator |
32521 | 416 |
val _ = change_data id inc_metis_calls |
417 |
in |
|
32525 | 418 |
maps snd named_thms |
32521 | 419 |
|> timed_metis |
420 |
|> log o prefix (metis_tag id) |
|
421 |
end |
|
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
422 |
|
32676 | 423 |
fun sledgehammer_action args id (st as {log, pre, name, ...}: Mirabelle.run_args) = |
32818 | 424 |
let val goal = Thm.major_prem_of(snd(snd(Proof.get_goal pre))) in |
425 |
if can Logic.dest_conjunction goal orelse can Logic.dest_equals goal |
|
32607 | 426 |
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
|
427 |
let |
32676 | 428 |
val metis_fns = (inc_metis_calls, inc_metis_success, inc_metis_proofs, inc_metis_time, |
32818 | 429 |
inc_metis_timeout, inc_metis_lemmas, inc_metis_max_lems, inc_metis_posns) |
32676 | 430 |
val metis0_fns = (inc_metis_calls0, inc_metis_success0, inc_metis_proofs0, inc_metis_time0, |
32818 | 431 |
inc_metis_timeout0, inc_metis_lemmas0, inc_metis_max_lems0, inc_metis_posns0) |
32740 | 432 |
val named_thms = Unsynchronized.ref (NONE : (string * thm list) list option) |
32612 | 433 |
val minimize = AList.defined (op =) args minimizeK |
434 |
in |
|
435 |
Mirabelle.catch sh_tag (run_sledgehammer args named_thms) id st; |
|
436 |
if is_some (!named_thms) |
|
437 |
then |
|
438 |
(if minimize |
|
32676 | 439 |
then Mirabelle.catch metis_tag (run_metis metis0_fns args name (these (!named_thms))) id st |
32612 | 440 |
else (); |
441 |
if minimize andalso not(null(these(!named_thms))) |
|
442 |
then Mirabelle.catch minimize_tag (run_minimize args named_thms) id st |
|
443 |
else (); |
|
32676 | 444 |
Mirabelle.catch metis_tag (run_metis metis_fns args name (these (!named_thms))) id st) |
32612 | 445 |
else () |
446 |
end |
|
32818 | 447 |
end |
32385
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
448 |
|
32511 | 449 |
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
|
450 |
let |
e7c0d3c0494a
Mirabelle: actions are responsible for catching exceptions and producing suitable log messages (makes log message uniform),
boehmes
parents:
32511
diff
changeset
|
451 |
val _ = AtpManager.set_full_types (AList.defined (op =) args full_typesK) |
32521 | 452 |
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
|
453 |
|
594890623c46
split actions from Mirabelle core (Mirabelle may thus be applied to basic theories in HOL)
boehmes
parents:
diff
changeset
|
454 |
end |