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