| author | wenzelm |
| Mon, 27 Oct 2025 15:16:32 +0100 | |
| changeset 83417 | b51e4a526897 |
| parent 82808 | cb93bd70c561 |
| permissions | -rw-r--r-- |
| 10805 | 1 |
(* Title: Pure/tactic.ML |
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
| 0 | 3 |
|
| 29276 | 4 |
Fundamental tactics. |
| 0 | 5 |
*) |
6 |
||
| 82805 | 7 |
signature TACTIC = |
| 11774 | 8 |
sig |
| 23223 | 9 |
val trace_goalno_tac: (int -> tactic) -> int -> tactic |
| 36546 | 10 |
val rule_by_tactic: Proof.context -> tactic -> thm -> thm |
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58957
diff
changeset
|
11 |
val assume_tac: Proof.context -> int -> tactic |
| 23223 | 12 |
val eq_assume_tac: int -> tactic |
|
58956
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents:
58950
diff
changeset
|
13 |
val compose_tac: Proof.context -> (bool * thm * int) -> int -> tactic |
| 23223 | 14 |
val make_elim: thm -> thm |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
15 |
val biresolve0_tac: (bool * thm) list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
16 |
val biresolve_tac: Proof.context -> (bool * thm) list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
17 |
val resolve0_tac: thm list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
18 |
val resolve_tac: Proof.context -> thm list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
19 |
val eresolve0_tac: thm list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
20 |
val eresolve_tac: Proof.context -> thm list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
21 |
val forward_tac: Proof.context -> thm list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
22 |
val dresolve0_tac: thm list -> int -> tactic |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
23 |
val dresolve_tac: Proof.context -> thm list -> int -> tactic |
| 60774 | 24 |
val ares_tac: Proof.context -> thm list -> int -> tactic |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
25 |
val solve_tac: Proof.context -> thm list -> int -> tactic |
| 58957 | 26 |
val bimatch_tac: Proof.context -> (bool * thm) list -> int -> tactic |
27 |
val match_tac: Proof.context -> thm list -> int -> tactic |
|
28 |
val ematch_tac: Proof.context -> thm list -> int -> tactic |
|
29 |
val dmatch_tac: Proof.context -> thm list -> int -> tactic |
|
|
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58837
diff
changeset
|
30 |
val flexflex_tac: Proof.context -> tactic |
| 23223 | 31 |
val distinct_subgoals_tac: tactic |
| 46704 | 32 |
val cut_tac: thm -> int -> tactic |
| 23223 | 33 |
val cut_rules_tac: thm list -> int -> tactic |
34 |
val cut_facts_tac: thm list -> int -> tactic |
|
35 |
val filter_thms: (term * term -> bool) -> int * term * thm list -> thm list |
|
|
27243
d549b5b0f344
removed obsolete global instantiation tactics (cf. Isar/rule_insts.ML);
wenzelm
parents:
27209
diff
changeset
|
36 |
val rename_tac: string list -> int -> tactic |
| 23223 | 37 |
val rotate_tac: int -> int -> tactic |
38 |
val defer_tac: int -> tactic |
|
| 49865 | 39 |
val prefer_tac: int -> tactic |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
40 |
val filter_prems_tac: Proof.context -> (term -> bool) -> int -> tactic |
| 11774 | 41 |
end; |
| 0 | 42 |
|
| 11774 | 43 |
structure Tactic: TACTIC = |
| 0 | 44 |
struct |
45 |
||
| 1501 | 46 |
(*Discover which goal is chosen: SOMEGOAL(trace_goalno_tac tac) *) |
| 10817 | 47 |
fun trace_goalno_tac tac i st = |
| 4270 | 48 |
case Seq.pull(tac i st) of |
| 15531 | 49 |
NONE => Seq.empty |
| 12262 | 50 |
| seqcell => (tracing ("Subgoal " ^ string_of_int i ^ " selected");
|
| 10805 | 51 |
Seq.make(fn()=> seqcell)); |
| 0 | 52 |
|
53 |
(*Makes a rule by applying a tactic to an existing rule*) |
|
| 36546 | 54 |
fun rule_by_tactic ctxt tac rl = |
|
19925
3f9341831812
eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents:
19743
diff
changeset
|
55 |
let |
|
52087
f3075fc4f5f6
more precise treatment of theory vs. Proof.context;
wenzelm
parents:
51602
diff
changeset
|
56 |
val thy = Proof_Context.theory_of ctxt; |
| 36546 | 57 |
val ctxt' = Variable.declare_thm rl ctxt; |
|
52087
f3075fc4f5f6
more precise treatment of theory vs. Proof.context;
wenzelm
parents:
51602
diff
changeset
|
58 |
val ((_, [st]), ctxt'') = Variable.import true [Thm.transfer thy rl] ctxt'; |
|
19925
3f9341831812
eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents:
19743
diff
changeset
|
59 |
in |
|
3f9341831812
eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents:
19743
diff
changeset
|
60 |
(case Seq.pull (tac st) of |
|
3f9341831812
eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents:
19743
diff
changeset
|
61 |
NONE => raise THM ("rule_by_tactic", 0, [rl])
|
| 36546 | 62 |
| SOME (st', _) => zero_var_indexes (singleton (Variable.export ctxt'' ctxt') st')) |
| 2688 | 63 |
end; |
| 10817 | 64 |
|
|
19925
3f9341831812
eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents:
19743
diff
changeset
|
65 |
|
| 0 | 66 |
(*** Basic tactics ***) |
67 |
||
68 |
(*** The following fail if the goal number is out of range: |
|
69 |
thus (REPEAT (resolve_tac rules i)) stops once subgoal i disappears. *) |
|
70 |
||
71 |
(*Solve subgoal i by assumption*) |
|
|
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58957
diff
changeset
|
72 |
fun assume_tac ctxt i = PRIMSEQ (Thm.assumption (SOME ctxt) i); |
| 0 | 73 |
|
74 |
(*Solve subgoal i by assumption, using no unification*) |
|
| 31945 | 75 |
fun eq_assume_tac i = PRIMITIVE (Thm.eq_assumption i); |
| 0 | 76 |
|
| 23223 | 77 |
|
| 0 | 78 |
(** Resolution/matching tactics **) |
79 |
||
80 |
(*The composition rule/state: no lifting or var renaming. |
|
| 31945 | 81 |
The arg = (bires_flg, orule, m); see Thm.bicompose for explanation.*) |
|
58956
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents:
58950
diff
changeset
|
82 |
fun compose_tac ctxt arg i = |
|
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents:
58950
diff
changeset
|
83 |
PRIMSEQ (Thm.bicompose (SOME ctxt) {flatten = true, match = false, incremented = false} arg i);
|
| 0 | 84 |
|
| 67721 | 85 |
(*Converts a "destruct" rule like P \<and> Q \<Longrightarrow> P to an "elimination" rule |
86 |
like \<lbrakk>P \<and> Q; P \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R *) |
|
| 0 | 87 |
fun make_elim rl = zero_var_indexes (rl RS revcut_rl); |
88 |
||
89 |
(*Attack subgoal i by resolution, using flags to indicate elimination rules*) |
|
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
90 |
fun biresolve0_tac brules i = PRIMSEQ (Thm.biresolution NONE false brules i); |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
91 |
fun biresolve_tac ctxt brules i = PRIMSEQ (Thm.biresolution (SOME ctxt) false brules i); |
| 0 | 92 |
|
93 |
(*Resolution: the simple case, works for introduction rules*) |
|
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
94 |
fun resolve0_tac rules = biresolve0_tac (map (pair false) rules); |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
95 |
fun resolve_tac ctxt rules = biresolve_tac ctxt (map (pair false) rules); |
| 0 | 96 |
|
97 |
(*Resolution with elimination rules only*) |
|
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
98 |
fun eresolve0_tac rules = biresolve0_tac (map (pair true) rules); |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
99 |
fun eresolve_tac ctxt rules = biresolve_tac ctxt (map (pair true) rules); |
| 0 | 100 |
|
101 |
(*Forward reasoning using destruction rules.*) |
|
| 60776 | 102 |
fun forward_tac ctxt rls = resolve_tac ctxt (map make_elim rls) THEN' assume_tac ctxt; |
| 0 | 103 |
|
104 |
(*Like forward_tac, but deletes the assumption after use.*) |
|
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
105 |
fun dresolve0_tac rls = eresolve0_tac (map make_elim rls); |
|
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
106 |
fun dresolve_tac ctxt rls = eresolve_tac ctxt (map make_elim rls); |
| 0 | 107 |
|
| 60774 | 108 |
(*Use an assumption or some rules*) |
109 |
fun ares_tac ctxt rules = assume_tac ctxt ORELSE' resolve_tac ctxt rules; |
|
| 0 | 110 |
|
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
111 |
fun solve_tac ctxt rules = resolve_tac ctxt rules THEN_ALL_NEW assume_tac ctxt; |
| 5263 | 112 |
|
| 0 | 113 |
(*Matching tactics -- as above, but forbid updating of state*) |
| 58957 | 114 |
fun bimatch_tac ctxt brules i = PRIMSEQ (Thm.biresolution (SOME ctxt) true brules i); |
115 |
fun match_tac ctxt rules = bimatch_tac ctxt (map (pair false) rules); |
|
116 |
fun ematch_tac ctxt rules = bimatch_tac ctxt (map (pair true) rules); |
|
117 |
fun dmatch_tac ctxt rls = ematch_tac ctxt (map make_elim rls); |
|
| 0 | 118 |
|
119 |
(*Smash all flex-flex disagreement pairs in the proof state.*) |
|
|
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58837
diff
changeset
|
120 |
fun flexflex_tac ctxt = PRIMSEQ (Thm.flexflex_rule (SOME ctxt)); |
| 0 | 121 |
|
|
19056
6ac9dfe98e54
sane version of distinct_subgoals_tac, based on composition with Drule.distinct_prems_rl;
wenzelm
parents:
18977
diff
changeset
|
122 |
(*Remove duplicate subgoals.*) |
|
69101
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
123 |
fun distinct_subgoals_tac st = |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
124 |
let |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
125 |
val subgoals = Thm.cprems_of st; |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
126 |
val (tab, n) = |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
127 |
(subgoals, (Ctermtab.empty, 0)) |-> fold (fn ct => fn (tab, i) => |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
128 |
if Ctermtab.defined tab ct then (tab, i) |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
129 |
else (Ctermtab.update (ct, i) tab, i + 1)); |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
130 |
val st' = |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
131 |
if n = length subgoals then st |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
132 |
else |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
133 |
let |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
134 |
val thy = Thm.theory_of_thm st; |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
135 |
fun cert_prop i = Thm.global_cterm_of thy (Free (Name.bound i, propT)); |
|
22560
f19ddf96c323
now exports distinct_subgoal_tac (needed by MetisAPI)
paulson
parents:
22360
diff
changeset
|
136 |
|
|
69101
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
137 |
val As = map (cert_prop o the o Ctermtab.lookup tab) subgoals; |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
138 |
val As' = map cert_prop (0 upto (n - 1)); |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
139 |
val C = cert_prop n; |
|
22560
f19ddf96c323
now exports distinct_subgoal_tac (needed by MetisAPI)
paulson
parents:
22360
diff
changeset
|
140 |
|
|
69101
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
141 |
val template = Drule.list_implies (As, C); |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
142 |
val inst = |
| 74282 | 143 |
Frees.build |
144 |
(Frees.add (dest_Free (Thm.term_of C), Thm.cconcl_of st) #> |
|
145 |
Ctermtab.fold (fn (ct, i) => Frees.add ((Name.bound i, propT), ct)) tab); |
|
|
69101
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
146 |
in |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
147 |
Thm.assume template |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
148 |
|> fold (Thm.elim_implies o Thm.assume) As |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
149 |
|> fold_rev Thm.implies_intr As' |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
150 |
|> Thm.implies_intr template |
| 74282 | 151 |
|> Thm.instantiate_frees (TFrees.empty, inst) |
|
69101
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
152 |
|> Thm.elim_implies st |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
153 |
end; |
|
991a3feaf270
more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents:
68825
diff
changeset
|
154 |
in Seq.single st' end; |
|
3409
c0466958df5d
Tidying of signature. More robust renaming in freeze_thaw.
paulson
parents:
2814
diff
changeset
|
155 |
|
| 1951 | 156 |
|
|
270
d506ea00c825
tactic/make_elim_preserve: recoded to avoid using lift_inst_rule. Instead
lcp
parents:
230
diff
changeset
|
157 |
(*** Applications of cut_rl ***) |
| 0 | 158 |
|
159 |
(*The conclusion of the rule gets assumed in subgoal i, |
|
160 |
while subgoal i+1,... are the premises of the rule.*) |
|
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59164
diff
changeset
|
161 |
fun cut_tac rule i = resolve0_tac [cut_rl] i THEN resolve0_tac [rule] (i + 1); |
| 0 | 162 |
|
|
13650
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
paulson
parents:
13559
diff
changeset
|
163 |
(*"Cut" a list of rules into the goal. Their premises will become new |
|
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
paulson
parents:
13559
diff
changeset
|
164 |
subgoals.*) |
| 46704 | 165 |
fun cut_rules_tac ths i = EVERY (map (fn th => cut_tac th i) ths); |
|
13650
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
paulson
parents:
13559
diff
changeset
|
166 |
|
|
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
paulson
parents:
13559
diff
changeset
|
167 |
(*As above, but inserts only facts (unconditional theorems); |
|
31bd2a8cdbe2
fixing the cut_tac method to work when there are no instantiations and the
paulson
parents:
13559
diff
changeset
|
168 |
generates no additional subgoals. *) |
| 20232 | 169 |
fun cut_facts_tac ths = cut_rules_tac (filter Thm.no_prems ths); |
| 0 | 170 |
|
171 |
||
172 |
(**** Indexing and filtering of theorems ****) |
|
173 |
||
174 |
(*Returns the list of potentially resolvable theorems for the goal "prem", |
|
| 10805 | 175 |
using the predicate could(subgoal,concl). |
| 0 | 176 |
Resulting list is no longer than "limit"*) |
177 |
fun filter_thms could (limit, prem, ths) = |
|
178 |
let val pb = Logic.strip_assums_concl prem; (*delete assumptions*) |
|
179 |
fun filtr (limit, []) = [] |
|
| 10805 | 180 |
| filtr (limit, th::ths) = |
181 |
if limit=0 then [] |
|
| 59582 | 182 |
else if could(pb, Thm.concl_of th) then th :: filtr(limit-1, ths) |
| 10805 | 183 |
else filtr(limit,ths) |
| 0 | 184 |
in filtr(limit,ths) end; |
185 |
||
186 |
||
|
27243
d549b5b0f344
removed obsolete global instantiation tactics (cf. Isar/rule_insts.ML);
wenzelm
parents:
27209
diff
changeset
|
187 |
(*Renaming of parameters in a subgoal*) |
|
d549b5b0f344
removed obsolete global instantiation tactics (cf. Isar/rule_insts.ML);
wenzelm
parents:
27209
diff
changeset
|
188 |
fun rename_tac xs i = |
| 59584 | 189 |
case find_first (not o Symbol_Pos.is_identifier) xs of |
| 15531 | 190 |
SOME x => error ("Not an identifier: " ^ x)
|
| 31945 | 191 |
| NONE => PRIMITIVE (Thm.rename_params_rule (xs, i)); |
| 9535 | 192 |
|
| 1501 | 193 |
(*rotate_tac n i: rotate the assumptions of subgoal i by n positions, from |
194 |
right to left if n is positive, and from left to right if n is negative.*) |
|
|
2672
85d7e800d754
Replaced "flat" by the Basis Library function List.concat
paulson
parents:
2580
diff
changeset
|
195 |
fun rotate_tac 0 i = all_tac |
| 31945 | 196 |
| rotate_tac k i = PRIMITIVE (Thm.rotate_rule k i); |
| 1209 | 197 |
|
| 59749 | 198 |
(*Rotate the given subgoal to be the last.*) |
| 31945 | 199 |
fun defer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1); |
|
7248
322151fe6f02
new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents:
6979
diff
changeset
|
200 |
|
| 59749 | 201 |
(*Rotate the given subgoal to be the first.*) |
| 49865 | 202 |
fun prefer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1 #> Thm.permute_prems 0 ~1); |
203 |
||
| 59749 | 204 |
(*Remove premises that do not satisfy pred; fails if all prems satisfy pred.*) |
205 |
fun filter_prems_tac ctxt pred = |
|
206 |
let |
|
207 |
fun Then NONE tac = SOME tac |
|
208 |
| Then (SOME tac) tac' = SOME (tac THEN' tac'); |
|
209 |
fun thins H (tac, n) = |
|
210 |
if pred H then (tac, n + 1) |
|
211 |
else (Then tac (rotate_tac n THEN' eresolve_tac ctxt [thin_rl]), 0); |
|
212 |
in |
|
213 |
SUBGOAL (fn (goal, i) => |
|
214 |
let val Hs = Logic.strip_assums_hyp goal in |
|
215 |
(case fst (fold thins Hs (NONE, 0)) of |
|
216 |
NONE => no_tac |
|
217 |
| SOME tac => tac i) |
|
218 |
end) |
|
| 5974 | 219 |
end; |
220 |
||
| 0 | 221 |
end; |
| 1501 | 222 |
|
| 82805 | 223 |
open Tactic; |