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