equal
deleted
inserted
replaced
7 |
7 |
8 signature SLEDGEHAMMER_SHRINK = |
8 signature SLEDGEHAMMER_SHRINK = |
9 sig |
9 sig |
10 type isar_step = Sledgehammer_Proof.isar_step |
10 type isar_step = Sledgehammer_Proof.isar_step |
11 val shrink_proof : |
11 val shrink_proof : |
12 bool -> Proof.context -> string -> string -> bool -> Time.time -> real |
12 bool -> Proof.context -> string -> string -> bool -> Time.time option |
13 -> isar_step list -> isar_step list * (bool * (bool * Time.time)) |
13 -> real -> isar_step list -> isar_step list * (bool * (bool * Time.time)) |
14 end |
14 end |
15 |
15 |
16 structure Sledgehammer_Shrink : SLEDGEHAMMER_SHRINK = |
16 structure Sledgehammer_Shrink : SLEDGEHAMMER_SHRINK = |
17 struct |
17 struct |
18 |
18 |
44 fun pop_max tab = pop tab (the (Inttab.max_key tab)) |
44 fun pop_max tab = pop tab (the (Inttab.max_key tab)) |
45 fun add_list tab xs = fold (Inttab.insert_list (op =)) xs tab |
45 fun add_list tab xs = fold (Inttab.insert_list (op =)) xs tab |
46 |
46 |
47 (* Timing *) |
47 (* Timing *) |
48 fun ext_time_add (b1, t1) (b2, t2) = (b1 orelse b2, Time.+(t1,t2)) |
48 fun ext_time_add (b1, t1) (b2, t2) = (b1 orelse b2, Time.+(t1,t2)) |
49 val no_time = (false, seconds 0.0) |
49 val no_time = (false, Time.zeroTime) |
50 fun take_time timeout tac arg = |
50 fun take_time timeout tac arg = |
51 let val timing = Timing.start () in |
51 let val timing = Timing.start () in |
52 (TimeLimit.timeLimit timeout tac arg; |
52 (TimeLimit.timeLimit timeout tac arg; |
53 Timing.result timing |> #cpu |> SOME) |
53 Timing.result timing |> #cpu |> SOME) |
54 handle TimeLimit.TimeOut => NONE |
54 handle TimeLimit.TimeOut => NONE |
57 |
57 |
58 (* Main function for shrinking proofs *) |
58 (* Main function for shrinking proofs *) |
59 fun shrink_proof debug ctxt type_enc lam_trans preplay preplay_timeout |
59 fun shrink_proof debug ctxt type_enc lam_trans preplay preplay_timeout |
60 isar_shrink proof = |
60 isar_shrink proof = |
61 let |
61 let |
|
62 (* 60 seconds seems like a good interpreation of "no timeout" *) |
|
63 val preplay_timeout = preplay_timeout |> the_default (seconds 60.0) |
|
64 |
62 (* handle metis preplay fail *) |
65 (* handle metis preplay fail *) |
63 local |
66 local |
64 open Unsynchronized |
67 open Unsynchronized |
65 val metis_fail = ref false |
68 val metis_fail = ref false |
66 in |
69 in |
67 fun handle_metis_fail try_metis () = |
70 fun handle_metis_fail try_metis () = |
68 try_metis () handle _ => (metis_fail := true ; SOME (seconds 0.0)) |
71 try_metis () handle _ => (metis_fail := true; SOME Time.zeroTime) |
69 fun get_time lazy_time = |
72 fun get_time lazy_time = |
70 if !metis_fail then SOME (seconds 0.0) else Lazy.force lazy_time |
73 if !metis_fail then SOME Time.zeroTime else Lazy.force lazy_time |
71 val metis_fail = fn () => !metis_fail |
74 val metis_fail = fn () => !metis_fail |
72 end |
75 end |
73 |
76 |
74 (* Shrink top level proof - do not shrink case splits *) |
77 (* Shrink top level proof - do not shrink case splits *) |
75 fun shrink_top_level on_top_level ctxt proof = |
78 fun shrink_top_level on_top_level ctxt proof = |
118 |>> map string_for_label |
121 |>> map string_for_label |
119 |> op @ |
122 |> op @ |
120 |> maps (thms_of_name ctxt) |
123 |> maps (thms_of_name ctxt) |
121 |
124 |
122 fun try_metis timeout (succedent, Prove (_, _, t, byline)) = |
125 fun try_metis timeout (succedent, Prove (_, _, t, byline)) = |
123 if not preplay then (fn () => SOME (seconds 0.0)) else |
126 if not preplay then (fn () => SOME Time.zeroTime) else |
124 (case byline of |
127 (case byline of |
125 By_Metis fact_names => |
128 By_Metis fact_names => |
126 let |
129 let |
127 val facts = resolve_fact_names fact_names |
130 val facts = resolve_fact_names fact_names |
128 val goal = |
131 val goal = |
152 fun tac {context = ctxt, prems = _} = |
155 fun tac {context = ctxt, prems = _} = |
153 Metis_Tactic.metis_tac [type_enc] lam_trans ctxt facts 1 |
156 Metis_Tactic.metis_tac [type_enc] lam_trans ctxt facts 1 |
154 in |
157 in |
155 take_time timeout (fn () => goal tac) |
158 take_time timeout (fn () => goal tac) |
156 end) |
159 end) |
157 | try_metis _ _ = (fn () => SOME (seconds 0.0) ) |
160 | try_metis _ _ = (fn () => SOME Time.zeroTime) |
158 |
161 |
159 val try_metis_quietly = the_default NONE oo try oo try_metis |
162 val try_metis_quietly = the_default NONE oo try oo try_metis |
160 |
163 |
161 (* cache metis preplay times in lazy time vector *) |
164 (* cache metis preplay times in lazy time vector *) |
162 val metis_time = |
165 val metis_time = |
193 in |
196 in |
194 case try_metis_quietly timeout (NONE, s12) () of |
197 case try_metis_quietly timeout (NONE, s12) () of |
195 NONE => (NONE, metis_time) |
198 NONE => (NONE, metis_time) |
196 | some_t12 => |
199 | some_t12 => |
197 (SOME s12, metis_time |
200 (SOME s12, metis_time |
198 |> replace (seconds 0.0 |> SOME |> Lazy.value) i |
201 |> replace (Time.zeroTime |> SOME |> Lazy.value) i |
199 |> replace (Lazy.value some_t12) j) |
202 |> replace (Lazy.value some_t12) j) |
200 |
203 |
201 end)) |
204 end)) |
202 |
205 |
203 fun merge_steps metis_time proof_vect refed_by cand_tab n' n_metis' = |
206 fun merge_steps metis_time proof_vect refed_by cand_tab n' n_metis' = |