301 (*rotate_tac n i: rotate the assumptions of subgoal i by n positions, from |
301 (*rotate_tac n i: rotate the assumptions of subgoal i by n positions, from |
302 right to left if n is positive, and from left to right if n is negative.*) |
302 right to left if n is positive, and from left to right if n is negative.*) |
303 fun rotate_tac 0 i = all_tac |
303 fun rotate_tac 0 i = all_tac |
304 | rotate_tac k i = PRIMITIVE (Thm.rotate_rule k i); |
304 | rotate_tac k i = PRIMITIVE (Thm.rotate_rule k i); |
305 |
305 |
306 (*Rotates the given subgoal to be the last.*) |
306 (*Rotate the given subgoal to be the last.*) |
307 fun defer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1); |
307 fun defer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1); |
308 |
308 |
309 (*Rotates the given subgoal to be the first.*) |
309 (*Rotate the given subgoal to be the first.*) |
310 fun prefer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1 #> Thm.permute_prems 0 ~1); |
310 fun prefer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1 #> Thm.permute_prems 0 ~1); |
311 |
311 |
312 (* remove premises that do not satisfy p; fails if all prems satisfy p *) |
312 (*Remove premises that do not satisfy pred; fails if all prems satisfy pred.*) |
313 fun filter_prems_tac ctxt p = |
313 fun filter_prems_tac ctxt pred = |
314 let fun Then NONE tac = SOME tac |
314 let |
315 | Then (SOME tac) tac' = SOME(tac THEN' tac'); |
315 fun Then NONE tac = SOME tac |
316 fun thins H (tac,n) = |
316 | Then (SOME tac) tac' = SOME (tac THEN' tac'); |
317 if p H then (tac,n+1) |
317 fun thins H (tac, n) = |
318 else (Then tac (rotate_tac n THEN' eresolve_tac ctxt [thin_rl]),0); |
318 if pred H then (tac, n + 1) |
319 in SUBGOAL(fn (subg,n) => |
319 else (Then tac (rotate_tac n THEN' eresolve_tac ctxt [thin_rl]), 0); |
320 let val Hs = Logic.strip_assums_hyp subg |
320 in |
321 in case fst(fold thins Hs (NONE,0)) of |
321 SUBGOAL (fn (goal, i) => |
322 NONE => no_tac | SOME tac => tac n |
322 let val Hs = Logic.strip_assums_hyp goal in |
323 end) |
323 (case fst (fold thins Hs (NONE, 0)) of |
|
324 NONE => no_tac |
|
325 | SOME tac => tac i) |
|
326 end) |
324 end; |
327 end; |
325 |
328 |
326 end; |
329 end; |
327 |
330 |
328 structure Basic_Tactic: BASIC_TACTIC = Tactic; |
331 structure Basic_Tactic: BASIC_TACTIC = Tactic; |