89 (* proof references *) |
89 (* proof references *) |
90 fun refs (Obtain (_, _, _, _, By_Metis (lfs, _))) = lookup_indices lfs |
90 fun refs (Obtain (_, _, _, _, By_Metis (lfs, _))) = lookup_indices lfs |
91 | refs (Prove (_, _, _, By_Metis (lfs, _))) = lookup_indices lfs |
91 | refs (Prove (_, _, _, By_Metis (lfs, _))) = lookup_indices lfs |
92 | refs (Prove (_, _, _, Case_Split (cases, (lfs, _)))) = |
92 | refs (Prove (_, _, _, Case_Split (cases, (lfs, _)))) = |
93 lookup_indices lfs @ maps (maps refs) cases |
93 lookup_indices lfs @ maps (maps refs) cases |
|
94 | refs (Prove (_, _, _, Subblock proof)) = maps refs proof |
94 | refs _ = [] |
95 | refs _ = [] |
95 val refed_by_vect = |
96 val refed_by_vect = |
96 Vector.tabulate (n, (fn _ => [])) |
97 Vector.tabulate (n, (fn _ => [])) |
97 |> fold_index (fn (i, step) => fold (update (cons i)) (refs step)) proof |
98 |> fold_index (fn (i, step) => fold (update (cons i)) (refs step)) proof |
98 |> Vector.map rev (* after rev, indices are sorted in ascending order *) |
99 |> Vector.map rev (* after rev, indices are sorted in ascending order *) |
216 | enrich_with_step (Obtain (_, _, l, t, _)) = enrich_with_fact l t |
217 | enrich_with_step (Obtain (_, _, l, t, _)) = enrich_with_fact l t |
217 | enrich_with_step (Prove (_, l, t, _)) = enrich_with_fact l t |
218 | enrich_with_step (Prove (_, l, t, _)) = enrich_with_fact l t |
218 | enrich_with_step _ = I |
219 | enrich_with_step _ = I |
219 val rich_ctxt = fold enrich_with_step proof ctxt |
220 val rich_ctxt = fold enrich_with_step proof ctxt |
220 |
221 |
221 (* Shrink case_splits and top-levl *) |
222 (* Shrink subproofs (case_splits and subblocks) and top-levl *) |
222 val ((proof, top_level_time), lower_level_time) = |
223 val ((proof, top_level_time), lower_level_time) = |
223 proof |> do_case_splits rich_ctxt |
224 proof |> do_subproof rich_ctxt |
224 |>> shrink_top_level on_top_level rich_ctxt |
225 |>> shrink_top_level on_top_level rich_ctxt |
225 in |
226 in |
226 (proof, add_preplay_time lower_level_time top_level_time) |
227 (proof, add_preplay_time lower_level_time top_level_time) |
227 end |
228 end |
228 |
229 |
229 and do_case_splits ctxt proof = |
230 and do_subproof ctxt proof = |
230 let |
231 let |
231 fun shrink_each_and_collect_time shrink candidates = |
232 fun shrink_each_and_collect_time shrink candidates = |
232 let fun f_m cand time = shrink cand ||> add_preplay_time time |
233 let fun f_m cand time = shrink cand ||> add_preplay_time time |
233 in fold_map f_m candidates zero_preplay_time end |
234 in fold_map f_m candidates zero_preplay_time end |
234 val shrink_case_split = |
235 val shrink_subproof = |
235 shrink_each_and_collect_time (do_proof false ctxt) |
236 shrink_each_and_collect_time (do_proof false ctxt) |
236 fun shrink (Prove (qs, l, t, Case_Split (cases, facts))) = |
237 fun shrink (Prove (qs, l, t, Case_Split (cases, facts))) = |
237 let val (cases, time) = shrink_case_split cases |
238 let val (cases, time) = shrink_subproof cases |
238 in (Prove (qs, l, t, Case_Split (cases, facts)), time) end |
239 in (Prove (qs, l, t, Case_Split (cases, facts)), time) end |
|
240 | shrink (Prove (qs, l, t, Subblock proof)) = |
|
241 let val ([proof], time) = shrink_subproof [proof] |
|
242 in (Prove (qs, l, t, Subblock proof), time) end |
239 | shrink step = (step, zero_preplay_time) |
243 | shrink step = (step, zero_preplay_time) |
240 in |
244 in |
241 shrink_each_and_collect_time shrink proof |
245 shrink_each_and_collect_time shrink proof |
242 end |
246 end |
243 in |
247 in |