author | wenzelm |
Wed, 14 Oct 2015 15:10:32 +0200 | |
changeset 61439 | 2bf52eec4e8a |
parent 61416 | b9a3324e4e62 |
child 61458 | 987533262fc2 |
permissions | -rw-r--r-- |
29755 | 1 |
theory Tactic |
2 |
imports Base |
|
3 |
begin |
|
18537 | 4 |
|
58618 | 5 |
chapter \<open>Tactical reasoning\<close> |
18537 | 6 |
|
58618 | 7 |
text \<open>Tactical reasoning works by refining an initial claim in a |
20474 | 8 |
backwards fashion, until a solved form is reached. A @{text "goal"} |
9 |
consists of several subgoals that need to be solved in order to |
|
10 |
achieve the main statement; zero subgoals means that the proof may |
|
11 |
be finished. A @{text "tactic"} is a refinement operation that maps |
|
12 |
a goal to a lazy sequence of potential successors. A @{text |
|
58618 | 13 |
"tactical"} is a combinator for composing tactics.\<close> |
18537 | 14 |
|
15 |
||
58618 | 16 |
section \<open>Goals \label{sec:tactical-goals}\<close> |
18537 | 17 |
|
58618 | 18 |
text \<open> |
29758 | 19 |
Isabelle/Pure represents a goal as a theorem stating that the |
20 |
subgoals imply the main goal: @{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> |
|
21 |
C"}. The outermost goal structure is that of a Horn Clause: i.e.\ |
|
22 |
an iterated implication without any quantifiers\footnote{Recall that |
|
23 |
outermost @{text "\<And>x. \<phi>[x]"} is always represented via schematic |
|
24 |
variables in the body: @{text "\<phi>[?x]"}. These variables may get |
|
25 |
instantiated during the course of reasoning.}. For @{text "n = 0"} |
|
26 |
a goal is called ``solved''. |
|
18537 | 27 |
|
29761 | 28 |
The structure of each subgoal @{text "A\<^sub>i"} is that of a |
29 |
general Hereditary Harrop Formula @{text "\<And>x\<^sub>1 \<dots> |
|
30 |
\<And>x\<^sub>k. H\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> H\<^sub>m \<Longrightarrow> B"}. Here @{text |
|
31 |
"x\<^sub>1, \<dots>, x\<^sub>k"} are goal parameters, i.e.\ |
|
32 |
arbitrary-but-fixed entities of certain types, and @{text |
|
33 |
"H\<^sub>1, \<dots>, H\<^sub>m"} are goal hypotheses, i.e.\ facts that may |
|
34 |
be assumed locally. Together, this forms the goal context of the |
|
35 |
conclusion @{text B} to be established. The goal hypotheses may be |
|
36 |
again arbitrary Hereditary Harrop Formulas, although the level of |
|
37 |
nesting rarely exceeds 1--2 in practice. |
|
18537 | 38 |
|
20451 | 39 |
The main conclusion @{text C} is internally marked as a protected |
29758 | 40 |
proposition, which is represented explicitly by the notation @{text |
34930 | 41 |
"#C"} here. This ensures that the decomposition into subgoals and |
42 |
main conclusion is well-defined for arbitrarily structured claims. |
|
18537 | 43 |
|
61416 | 44 |
\<^medskip> |
45 |
Basic goal management is performed via the following |
|
20451 | 46 |
Isabelle/Pure rules: |
18537 | 47 |
|
48 |
\[ |
|
49 |
\infer[@{text "(init)"}]{@{text "C \<Longrightarrow> #C"}}{} \qquad |
|
20547 | 50 |
\infer[@{text "(finish)"}]{@{text "C"}}{@{text "#C"}} |
18537 | 51 |
\] |
52 |
||
61416 | 53 |
\<^medskip> |
54 |
The following low-level variants admit general reasoning |
|
18537 | 55 |
with protected propositions: |
56 |
||
57 |
\[ |
|
52456 | 58 |
\infer[@{text "(protect n)"}]{@{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> #C"}}{@{text "A\<^sub>1 \<Longrightarrow> \<dots> \<Longrightarrow> A\<^sub>n \<Longrightarrow> C"}} |
59 |
\] |
|
60 |
\[ |
|
61 |
\infer[@{text "(conclude)"}]{@{text "A \<Longrightarrow> \<dots> \<Longrightarrow> C"}}{@{text "A \<Longrightarrow> \<dots> \<Longrightarrow> #C"}} |
|
18537 | 62 |
\] |
58618 | 63 |
\<close> |
18537 | 64 |
|
58618 | 65 |
text %mlref \<open> |
18537 | 66 |
\begin{mldecls} |
67 |
@{index_ML Goal.init: "cterm -> thm"} \\ |
|
32201
3689b647356d
updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents:
30272
diff
changeset
|
68 |
@{index_ML Goal.finish: "Proof.context -> thm -> thm"} \\ |
52456 | 69 |
@{index_ML Goal.protect: "int -> thm -> thm"} \\ |
18537 | 70 |
@{index_ML Goal.conclude: "thm -> thm"} \\ |
71 |
\end{mldecls} |
|
72 |
||
73 |
\begin{description} |
|
74 |
||
61439 | 75 |
\<^descr> @{ML "Goal.init"}~@{text C} initializes a tactical goal from |
20474 | 76 |
the well-formed proposition @{text C}. |
18537 | 77 |
|
61439 | 78 |
\<^descr> @{ML "Goal.finish"}~@{text "ctxt thm"} checks whether theorem |
20474 | 79 |
@{text "thm"} is a solved goal (no subgoals), and concludes the |
32201
3689b647356d
updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents:
30272
diff
changeset
|
80 |
result by removing the goal protection. The context is only |
3689b647356d
updated Variable.focus, SUBPROOF, Obtain.result, Goal.finish;
wenzelm
parents:
30272
diff
changeset
|
81 |
required for printing error messages. |
18537 | 82 |
|
61439 | 83 |
\<^descr> @{ML "Goal.protect"}~@{text "n thm"} protects the statement |
52456 | 84 |
of theorem @{text "thm"}. The parameter @{text n} indicates the |
85 |
number of premises to be retained. |
|
18537 | 86 |
|
61439 | 87 |
\<^descr> @{ML "Goal.conclude"}~@{text "thm"} removes the goal |
20474 | 88 |
protection, even if there are pending subgoals. |
18537 | 89 |
|
90 |
\end{description} |
|
58618 | 91 |
\<close> |
18537 | 92 |
|
93 |
||
58618 | 94 |
section \<open>Tactics\label{sec:tactics}\<close> |
18537 | 95 |
|
58618 | 96 |
text \<open>A @{text "tactic"} is a function @{text "goal \<rightarrow> goal\<^sup>*\<^sup>*"} that |
28781 | 97 |
maps a given goal state (represented as a theorem, cf.\ |
98 |
\secref{sec:tactical-goals}) to a lazy sequence of potential |
|
99 |
successor states. The underlying sequence implementation is lazy |
|
100 |
both in head and tail, and is purely functional in \emph{not} |
|
101 |
supporting memoing.\footnote{The lack of memoing and the strict |
|
57421 | 102 |
nature of ML requires some care when working with low-level |
28781 | 103 |
sequence operations, to avoid duplicate or premature evaluation of |
34930 | 104 |
results. It also means that modified runtime behavior, such as |
105 |
timeout, is very hard to achieve for general tactics.} |
|
18537 | 106 |
|
28781 | 107 |
An \emph{empty result sequence} means that the tactic has failed: in |
34930 | 108 |
a compound tactic expression other tactics might be tried instead, |
28781 | 109 |
or the whole refinement step might fail outright, producing a |
34930 | 110 |
toplevel error message in the end. When implementing tactics from |
111 |
scratch, one should take care to observe the basic protocol of |
|
112 |
mapping regular error conditions to an empty result; only serious |
|
113 |
faults should emerge as exceptions. |
|
28781 | 114 |
|
115 |
By enumerating \emph{multiple results}, a tactic can easily express |
|
116 |
the potential outcome of an internal search process. There are also |
|
117 |
combinators for building proof tools that involve search |
|
118 |
systematically, see also \secref{sec:tacticals}. |
|
119 |
||
61416 | 120 |
\<^medskip> |
121 |
As explained before, a goal state essentially consists of a |
|
34930 | 122 |
list of subgoals that imply the main goal (conclusion). Tactics may |
123 |
operate on all subgoals or on a particularly specified subgoal, but |
|
124 |
must not change the main conclusion (apart from instantiating |
|
125 |
schematic goal variables). |
|
18537 | 126 |
|
28781 | 127 |
Tactics with explicit \emph{subgoal addressing} are of the form |
128 |
@{text "int \<rightarrow> tactic"} and may be applied to a particular subgoal |
|
129 |
(counting from 1). If the subgoal number is out of range, the |
|
130 |
tactic should fail with an empty result sequence, but must not raise |
|
131 |
an exception! |
|
132 |
||
133 |
Operating on a particular subgoal means to replace it by an interval |
|
134 |
of zero or more subgoals in the same place; other subgoals must not |
|
135 |
be affected, apart from instantiating schematic variables ranging |
|
136 |
over the whole goal state. |
|
137 |
||
138 |
A common pattern of composing tactics with subgoal addressing is to |
|
139 |
try the first one, and then the second one only if the subgoal has |
|
140 |
not been solved yet. Special care is required here to avoid bumping |
|
28782 | 141 |
into unrelated subgoals that happen to come after the original |
142 |
subgoal. Assuming that there is only a single initial subgoal is a |
|
143 |
very common error when implementing tactics! |
|
144 |
||
145 |
Tactics with internal subgoal addressing should expose the subgoal |
|
146 |
index as @{text "int"} argument in full generality; a hardwired |
|
34930 | 147 |
subgoal 1 is not acceptable. |
28781 | 148 |
|
61416 | 149 |
\<^medskip> |
150 |
The main well-formedness conditions for proper tactics are |
|
28781 | 151 |
summarized as follows. |
152 |
||
153 |
\begin{itemize} |
|
154 |
||
61416 | 155 |
\<^item> General tactic failure is indicated by an empty result, only |
28781 | 156 |
serious faults may produce an exception. |
157 |
||
61416 | 158 |
\<^item> The main conclusion must not be changed, apart from |
28781 | 159 |
instantiating schematic variables. |
160 |
||
61416 | 161 |
\<^item> A tactic operates either uniformly on all subgoals, or |
28781 | 162 |
specifically on a selected subgoal (without bumping into unrelated |
163 |
subgoals). |
|
164 |
||
61416 | 165 |
\<^item> Range errors in subgoal addressing produce an empty result. |
28781 | 166 |
|
167 |
\end{itemize} |
|
28782 | 168 |
|
169 |
Some of these conditions are checked by higher-level goal |
|
34930 | 170 |
infrastructure (\secref{sec:struct-goals}); others are not checked |
28782 | 171 |
explicitly, and violating them merely results in ill-behaved tactics |
172 |
experienced by the user (e.g.\ tactics that insist in being |
|
34930 | 173 |
applicable only to singleton goals, or prevent composition via |
46260 | 174 |
standard tacticals such as @{ML REPEAT}). |
58618 | 175 |
\<close> |
28782 | 176 |
|
58618 | 177 |
text %mlref \<open> |
28782 | 178 |
\begin{mldecls} |
179 |
@{index_ML_type tactic: "thm -> thm Seq.seq"} \\ |
|
28783 | 180 |
@{index_ML no_tac: tactic} \\ |
181 |
@{index_ML all_tac: tactic} \\ |
|
56491 | 182 |
@{index_ML print_tac: "Proof.context -> string -> tactic"} \\[1ex] |
28783 | 183 |
@{index_ML PRIMITIVE: "(thm -> thm) -> tactic"} \\[1ex] |
28782 | 184 |
@{index_ML SUBGOAL: "(term * int -> tactic) -> int -> tactic"} \\ |
185 |
@{index_ML CSUBGOAL: "(cterm * int -> tactic) -> int -> tactic"} \\ |
|
52463 | 186 |
@{index_ML SELECT_GOAL: "tactic -> int -> tactic"} \\ |
187 |
@{index_ML PREFER_GOAL: "tactic -> int -> tactic"} \\ |
|
28782 | 188 |
\end{mldecls} |
189 |
||
190 |
\begin{description} |
|
191 |
||
61439 | 192 |
\<^descr> Type @{ML_type tactic} represents tactics. The |
39864 | 193 |
well-formedness conditions described above need to be observed. See |
40800
330eb65c9469
Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents:
39864
diff
changeset
|
194 |
also @{file "~~/src/Pure/General/seq.ML"} for the underlying |
39864 | 195 |
implementation of lazy sequences. |
28782 | 196 |
|
61439 | 197 |
\<^descr> Type @{ML_type "int -> tactic"} represents tactics with |
39864 | 198 |
explicit subgoal addressing, with well-formedness conditions as |
199 |
described above. |
|
28782 | 200 |
|
61439 | 201 |
\<^descr> @{ML no_tac} is a tactic that always fails, returning the |
28783 | 202 |
empty sequence. |
203 |
||
61439 | 204 |
\<^descr> @{ML all_tac} is a tactic that always succeeds, returning a |
28783 | 205 |
singleton sequence with unchanged goal state. |
206 |
||
61439 | 207 |
\<^descr> @{ML print_tac}~@{text "ctxt message"} is like @{ML all_tac}, but |
28783 | 208 |
prints a message together with the goal state on the tracing |
209 |
channel. |
|
210 |
||
61439 | 211 |
\<^descr> @{ML PRIMITIVE}~@{text rule} turns a primitive inference rule |
28782 | 212 |
into a tactic with unique result. Exception @{ML THM} is considered |
213 |
a regular tactic failure and produces an empty result; other |
|
214 |
exceptions are passed through. |
|
215 |
||
61439 | 216 |
\<^descr> @{ML SUBGOAL}~@{text "(fn (subgoal, i) => tactic)"} is the |
28783 | 217 |
most basic form to produce a tactic with subgoal addressing. The |
28782 | 218 |
given abstraction over the subgoal term and subgoal number allows to |
219 |
peek at the relevant information of the full goal state. The |
|
220 |
subgoal range is checked as required above. |
|
221 |
||
61439 | 222 |
\<^descr> @{ML CSUBGOAL} is similar to @{ML SUBGOAL}, but passes the |
28783 | 223 |
subgoal as @{ML_type cterm} instead of raw @{ML_type term}. This |
28782 | 224 |
avoids expensive re-certification in situations where the subgoal is |
225 |
used directly for primitive inferences. |
|
226 |
||
61439 | 227 |
\<^descr> @{ML SELECT_GOAL}~@{text "tac i"} confines a tactic to the |
52463 | 228 |
specified subgoal @{text "i"}. This rearranges subgoals and the |
229 |
main goal protection (\secref{sec:tactical-goals}), while retaining |
|
230 |
the syntactic context of the overall goal state (concerning |
|
231 |
schematic variables etc.). |
|
232 |
||
61439 | 233 |
\<^descr> @{ML PREFER_GOAL}~@{text "tac i"} rearranges subgoals to put |
52463 | 234 |
@{text "i"} in front. This is similar to @{ML SELECT_GOAL}, but |
235 |
without changing the main goal protection. |
|
236 |
||
28782 | 237 |
\end{description} |
58618 | 238 |
\<close> |
18537 | 239 |
|
240 |
||
58618 | 241 |
subsection \<open>Resolution and assumption tactics \label{sec:resolve-assume-tac}\<close> |
28783 | 242 |
|
58618 | 243 |
text \<open>\emph{Resolution} is the most basic mechanism for refining a |
28783 | 244 |
subgoal using a theorem as object-level rule. |
245 |
\emph{Elim-resolution} is particularly suited for elimination rules: |
|
246 |
it resolves with a rule, proves its first premise by assumption, and |
|
247 |
finally deletes that assumption from any new subgoals. |
|
248 |
\emph{Destruct-resolution} is like elim-resolution, but the given |
|
249 |
destruction rules are first turned into canonical elimination |
|
250 |
format. \emph{Forward-resolution} is like destruct-resolution, but |
|
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
251 |
without deleting the selected assumption. The @{text "r/e/d/f"} |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
252 |
naming convention is maintained for several different kinds of |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
253 |
resolution rules and tactics. |
28783 | 254 |
|
255 |
Assumption tactics close a subgoal by unifying some of its premises |
|
256 |
against its conclusion. |
|
257 |
||
61416 | 258 |
\<^medskip> |
259 |
All the tactics in this section operate on a subgoal |
|
28783 | 260 |
designated by a positive integer. Other subgoals might be affected |
261 |
indirectly, due to instantiation of schematic variables. |
|
262 |
||
263 |
There are various sources of non-determinism, the tactic result |
|
264 |
sequence enumerates all possibilities of the following choices (if |
|
265 |
applicable): |
|
266 |
||
267 |
\begin{enumerate} |
|
268 |
||
61416 | 269 |
\<^enum> selecting one of the rules given as argument to the tactic; |
28783 | 270 |
|
61416 | 271 |
\<^enum> selecting a subgoal premise to eliminate, unifying it against |
28783 | 272 |
the first premise of the rule; |
273 |
||
61416 | 274 |
\<^enum> unifying the conclusion of the subgoal to the conclusion of |
28783 | 275 |
the rule. |
276 |
||
277 |
\end{enumerate} |
|
278 |
||
279 |
Recall that higher-order unification may produce multiple results |
|
280 |
that are enumerated here. |
|
58618 | 281 |
\<close> |
28783 | 282 |
|
58618 | 283 |
text %mlref \<open> |
28783 | 284 |
\begin{mldecls} |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
285 |
@{index_ML resolve_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
286 |
@{index_ML eresolve_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
287 |
@{index_ML dresolve_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
288 |
@{index_ML forward_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
289 |
@{index_ML biresolve_tac: "Proof.context -> (bool * thm) list -> int -> tactic"} \\[1ex] |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58957
diff
changeset
|
290 |
@{index_ML assume_tac: "Proof.context -> int -> tactic"} \\ |
28783 | 291 |
@{index_ML eq_assume_tac: "int -> tactic"} \\[1ex] |
58957 | 292 |
@{index_ML match_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
293 |
@{index_ML ematch_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
|
294 |
@{index_ML dmatch_tac: "Proof.context -> thm list -> int -> tactic"} \\ |
|
295 |
@{index_ML bimatch_tac: "Proof.context -> (bool * thm) list -> int -> tactic"} \\ |
|
28783 | 296 |
\end{mldecls} |
297 |
||
298 |
\begin{description} |
|
299 |
||
61439 | 300 |
\<^descr> @{ML resolve_tac}~@{text "ctxt thms i"} refines the goal state |
28783 | 301 |
using the given theorems, which should normally be introduction |
302 |
rules. The tactic resolves a rule's conclusion with subgoal @{text |
|
303 |
i}, replacing it by the corresponding versions of the rule's |
|
304 |
premises. |
|
305 |
||
61439 | 306 |
\<^descr> @{ML eresolve_tac}~@{text "ctxt thms i"} performs elim-resolution |
46278 | 307 |
with the given theorems, which are normally be elimination rules. |
308 |
||
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
309 |
Note that @{ML_text "eresolve_tac ctxt [asm_rl]"} is equivalent to @{ML_text |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58963
diff
changeset
|
310 |
"assume_tac ctxt"}, which facilitates mixing of assumption steps with |
46278 | 311 |
genuine eliminations. |
28783 | 312 |
|
61439 | 313 |
\<^descr> @{ML dresolve_tac}~@{text "ctxt thms i"} performs |
28783 | 314 |
destruct-resolution with the given theorems, which should normally |
315 |
be destruction rules. This replaces an assumption by the result of |
|
316 |
applying one of the rules. |
|
317 |
||
61439 | 318 |
\<^descr> @{ML forward_tac} is like @{ML dresolve_tac} except that the |
28783 | 319 |
selected assumption is not deleted. It applies a rule to an |
320 |
assumption, adding the result as a new assumption. |
|
321 |
||
61439 | 322 |
\<^descr> @{ML biresolve_tac}~@{text "ctxt brls i"} refines the proof state |
50072 | 323 |
by resolution or elim-resolution on each rule, as indicated by its |
324 |
flag. It affects subgoal @{text "i"} of the proof state. |
|
325 |
||
326 |
For each pair @{text "(flag, rule)"}, it applies resolution if the |
|
327 |
flag is @{text "false"} and elim-resolution if the flag is @{text |
|
328 |
"true"}. A single tactic call handles a mixture of introduction and |
|
329 |
elimination rules, which is useful to organize the search process |
|
330 |
systematically in proof tools. |
|
331 |
||
61439 | 332 |
\<^descr> @{ML assume_tac}~@{text "ctxt i"} attempts to solve subgoal @{text i} |
28783 | 333 |
by assumption (modulo higher-order unification). |
334 |
||
61439 | 335 |
\<^descr> @{ML eq_assume_tac} is similar to @{ML assume_tac}, but checks |
28783 | 336 |
only for immediate @{text "\<alpha>"}-convertibility instead of using |
337 |
unification. It succeeds (with a unique next state) if one of the |
|
338 |
assumptions is equal to the subgoal's conclusion. Since it does not |
|
339 |
instantiate variables, it cannot make other subgoals unprovable. |
|
340 |
||
61439 | 341 |
\<^descr> @{ML match_tac}, @{ML ematch_tac}, @{ML dmatch_tac}, and @{ML |
50072 | 342 |
bimatch_tac} are similar to @{ML resolve_tac}, @{ML eresolve_tac}, |
343 |
@{ML dresolve_tac}, and @{ML biresolve_tac}, respectively, but do |
|
53096 | 344 |
not instantiate schematic variables in the goal state.% |
345 |
\footnote{Strictly speaking, matching means to treat the unknowns in the goal |
|
346 |
state as constants, but these tactics merely discard unifiers that would |
|
347 |
update the goal state. In rare situations (where the conclusion and |
|
348 |
goal state have flexible terms at the same position), the tactic |
|
349 |
will fail even though an acceptable unifier exists.} |
|
350 |
These tactics were written for a specific application within the classical reasoner. |
|
28783 | 351 |
|
352 |
Flexible subgoals are not updated at will, but are left alone. |
|
353 |
\end{description} |
|
58618 | 354 |
\<close> |
28783 | 355 |
|
356 |
||
58618 | 357 |
subsection \<open>Explicit instantiation within a subgoal context\<close> |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
358 |
|
58618 | 359 |
text \<open>The main resolution tactics (\secref{sec:resolve-assume-tac}) |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
360 |
use higher-order unification, which works well in many practical |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
361 |
situations despite its daunting theoretical properties. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
362 |
Nonetheless, there are important problem classes where unguided |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
363 |
higher-order unification is not so useful. This typically involves |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
364 |
rules like universal elimination, existential introduction, or |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
365 |
equational substitution. Here the unification problem involves |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
366 |
fully flexible @{text "?P ?x"} schemes, which are hard to manage |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
367 |
without further hints. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
368 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
369 |
By providing a (small) rigid term for @{text "?x"} explicitly, the |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
370 |
remaining unification problem is to assign a (large) term to @{text |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
371 |
"?P"}, according to the shape of the given subgoal. This is |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
372 |
sufficiently well-behaved in most practical situations. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
373 |
|
61416 | 374 |
\<^medskip> |
375 |
Isabelle provides separate versions of the standard @{text |
|
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
376 |
"r/e/d/f"} resolution tactics that allow to provide explicit |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
377 |
instantiations of unknowns of the given rule, wrt.\ terms that refer |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
378 |
to the implicit context of the selected subgoal. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
379 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
380 |
An instantiation consists of a list of pairs of the form @{text |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
381 |
"(?x, t)"}, where @{text ?x} is a schematic variable occurring in |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
382 |
the given rule, and @{text t} is a term from the current proof |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
383 |
context, augmented by the local goal parameters of the selected |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
384 |
subgoal; cf.\ the @{text "focus"} operation described in |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
385 |
\secref{sec:variables}. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
386 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
387 |
Entering the syntactic context of a subgoal is a brittle operation, |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
388 |
because its exact form is somewhat accidental, and the choice of |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
389 |
bound variable names depends on the presence of other local and |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
390 |
global names. Explicit renaming of subgoal parameters prior to |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
391 |
explicit instantiation might help to achieve a bit more robustness. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
392 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
393 |
Type instantiations may be given as well, via pairs like @{text |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
394 |
"(?'a, \<tau>)"}. Type instantiations are distinguished from term |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
395 |
instantiations by the syntactic form of the schematic variable. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
396 |
Types are instantiated before terms are. Since term instantiation |
34930 | 397 |
already performs simple type-inference, so explicit type |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
398 |
instantiations are seldom necessary. |
58618 | 399 |
\<close> |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
400 |
|
58618 | 401 |
text %mlref \<open> |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
402 |
\begin{mldecls} |
59763 | 403 |
@{index_ML Rule_Insts.res_inst_tac: "Proof.context -> |
59780 | 404 |
((indexname * Position.T) * string) list -> (binding * string option * mixfix) list -> |
405 |
thm -> int -> tactic"} \\ |
|
59763 | 406 |
@{index_ML Rule_Insts.eres_inst_tac: "Proof.context -> |
59780 | 407 |
((indexname * Position.T) * string) list -> (binding * string option * mixfix) list -> |
408 |
thm -> int -> tactic"} \\ |
|
59763 | 409 |
@{index_ML Rule_Insts.dres_inst_tac: "Proof.context -> |
59780 | 410 |
((indexname * Position.T) * string) list -> (binding * string option * mixfix) list -> |
411 |
thm -> int -> tactic"} \\ |
|
59763 | 412 |
@{index_ML Rule_Insts.forw_inst_tac: "Proof.context -> |
59780 | 413 |
((indexname * Position.T) * string) list -> (binding * string option * mixfix) list -> |
414 |
thm -> int -> tactic"} \\ |
|
415 |
@{index_ML Rule_Insts.subgoal_tac: "Proof.context -> string -> |
|
416 |
(binding * string option * mixfix) list -> int -> tactic"} \\ |
|
417 |
@{index_ML Rule_Insts.thin_tac: "Proof.context -> string -> |
|
418 |
(binding * string option * mixfix) list -> int -> tactic"} \\ |
|
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
419 |
@{index_ML rename_tac: "string list -> int -> tactic"} \\ |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
420 |
\end{mldecls} |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
421 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
422 |
\begin{description} |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
423 |
|
61439 | 424 |
\<^descr> @{ML Rule_Insts.res_inst_tac}~@{text "ctxt insts thm i"} instantiates the |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
425 |
rule @{text thm} with the instantiations @{text insts}, as described |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
426 |
above, and then performs resolution on subgoal @{text i}. |
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
427 |
|
61439 | 428 |
\<^descr> @{ML Rule_Insts.eres_inst_tac} is like @{ML Rule_Insts.res_inst_tac}, |
59763 | 429 |
but performs elim-resolution. |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
430 |
|
61439 | 431 |
\<^descr> @{ML Rule_Insts.dres_inst_tac} is like @{ML Rule_Insts.res_inst_tac}, |
59763 | 432 |
but performs destruct-resolution. |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
433 |
|
61439 | 434 |
\<^descr> @{ML Rule_Insts.forw_inst_tac} is like @{ML Rule_Insts.dres_inst_tac} |
59763 | 435 |
except that the selected assumption is not deleted. |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
436 |
|
61439 | 437 |
\<^descr> @{ML Rule_Insts.subgoal_tac}~@{text "ctxt \<phi> i"} adds the proposition |
46271 | 438 |
@{text "\<phi>"} as local premise to subgoal @{text "i"}, and poses the |
439 |
same as a new subgoal @{text "i + 1"} (in the original context). |
|
440 |
||
61439 | 441 |
\<^descr> @{ML Rule_Insts.thin_tac}~@{text "ctxt \<phi> i"} deletes the specified |
46277 | 442 |
premise from subgoal @{text i}. Note that @{text \<phi>} may contain |
443 |
schematic variables, to abbreviate the intended proposition; the |
|
444 |
first matching subgoal premise will be deleted. Removing useless |
|
445 |
premises from a subgoal increases its readability and can make |
|
446 |
search tactics run faster. |
|
447 |
||
61439 | 448 |
\<^descr> @{ML rename_tac}~@{text "names i"} renames the innermost |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
449 |
parameters of subgoal @{text i} according to the provided @{text |
56579 | 450 |
names} (which need to be distinct identifiers). |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
451 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
452 |
\end{description} |
34930 | 453 |
|
454 |
For historical reasons, the above instantiation tactics take |
|
455 |
unparsed string arguments, which makes them hard to use in general |
|
456 |
ML code. The slightly more advanced @{ML Subgoal.FOCUS} combinator |
|
457 |
of \secref{sec:struct-goals} allows to refer to internal goal |
|
458 |
structure with explicit context management. |
|
58618 | 459 |
\<close> |
28785
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
460 |
|
64163cddf3e6
added section "Explicit instantiation within a subgoal context";
wenzelm
parents:
28783
diff
changeset
|
461 |
|
58618 | 462 |
subsection \<open>Rearranging goal states\<close> |
46274 | 463 |
|
58618 | 464 |
text \<open>In rare situations there is a need to rearrange goal states: |
46274 | 465 |
either the overall collection of subgoals, or the local structure of |
466 |
a subgoal. Various administrative tactics allow to operate on the |
|
58618 | 467 |
concrete presentation these conceptual sets of formulae.\<close> |
46274 | 468 |
|
58618 | 469 |
text %mlref \<open> |
46274 | 470 |
\begin{mldecls} |
471 |
@{index_ML rotate_tac: "int -> int -> tactic"} \\ |
|
46276 | 472 |
@{index_ML distinct_subgoals_tac: tactic} \\ |
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58618
diff
changeset
|
473 |
@{index_ML flexflex_tac: "Proof.context -> tactic"} \\ |
46274 | 474 |
\end{mldecls} |
475 |
||
476 |
\begin{description} |
|
477 |
||
61439 | 478 |
\<^descr> @{ML rotate_tac}~@{text "n i"} rotates the premises of subgoal |
46274 | 479 |
@{text i} by @{text n} positions: from right to left if @{text n} is |
480 |
positive, and from left to right if @{text n} is negative. |
|
481 |
||
61439 | 482 |
\<^descr> @{ML distinct_subgoals_tac} removes duplicate subgoals from a |
46276 | 483 |
proof state. This is potentially inefficient. |
484 |
||
61439 | 485 |
\<^descr> @{ML flexflex_tac} removes all flex-flex pairs from the proof |
46276 | 486 |
state by applying the trivial unifier. This drastic step loses |
487 |
information. It is already part of the Isar infrastructure for |
|
488 |
facts resulting from goals, and rarely needs to be invoked manually. |
|
489 |
||
490 |
Flex-flex constraints arise from difficult cases of higher-order |
|
59763 | 491 |
unification. To prevent this, use @{ML Rule_Insts.res_inst_tac} to |
492 |
instantiate some variables in a rule. Normally flex-flex constraints |
|
493 |
can be ignored; they often disappear as unknowns get instantiated. |
|
46276 | 494 |
|
46274 | 495 |
\end{description} |
58618 | 496 |
\<close> |
46274 | 497 |
|
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
498 |
|
58618 | 499 |
subsection \<open>Raw composition: resolution without lifting\<close> |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
500 |
|
58618 | 501 |
text \<open> |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
502 |
Raw composition of two rules means resolving them without prior |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
503 |
lifting or renaming of unknowns. This low-level operation, which |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
504 |
underlies the resolution tactics, may occasionally be useful for |
52467 | 505 |
special effects. Schematic variables are not renamed by default, so |
506 |
beware of clashes! |
|
58618 | 507 |
\<close> |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
508 |
|
58618 | 509 |
text %mlref \<open> |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
510 |
\begin{mldecls} |
58956
a816aa3ff391
proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents:
58950
diff
changeset
|
511 |
@{index_ML compose_tac: "Proof.context -> (bool * thm * int) -> int -> tactic"} \\ |
52467 | 512 |
@{index_ML Drule.compose: "thm * int * thm -> thm"} \\ |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
513 |
@{index_ML_op COMP: "thm * thm -> thm"} \\ |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
514 |
\end{mldecls} |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
515 |
|
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
516 |
\begin{description} |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
517 |
|
61439 | 518 |
\<^descr> @{ML compose_tac}~@{text "ctxt (flag, rule, m) i"} refines subgoal |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
519 |
@{text "i"} using @{text "rule"}, without lifting. The @{text |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
520 |
"rule"} is taken to have the form @{text "\<psi>\<^sub>1 \<Longrightarrow> \<dots> \<psi>\<^sub>m \<Longrightarrow> \<psi>"}, where |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
521 |
@{text "\<psi>"} need not be atomic; thus @{text "m"} determines the |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
522 |
number of new subgoals. If @{text "flag"} is @{text "true"} then it |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
523 |
performs elim-resolution --- it solves the first premise of @{text |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
524 |
"rule"} by assumption and deletes that assumption. |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
525 |
|
61439 | 526 |
\<^descr> @{ML Drule.compose}~@{text "(thm\<^sub>1, i, thm\<^sub>2)"} uses @{text "thm\<^sub>1"}, |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
527 |
regarded as an atomic formula, to solve premise @{text "i"} of |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
528 |
@{text "thm\<^sub>2"}. Let @{text "thm\<^sub>1"} and @{text "thm\<^sub>2"} be @{text |
52467 | 529 |
"\<psi>"} and @{text "\<phi>\<^sub>1 \<Longrightarrow> \<dots> \<phi>\<^sub>n \<Longrightarrow> \<phi>"}. The unique @{text "s"} that |
53015
a1119cf551e8
standardized symbols via "isabelle update_sub_sup", excluding src/Pure and src/Tools/WWW_Find;
wenzelm
parents:
52820
diff
changeset
|
530 |
unifies @{text "\<psi>"} and @{text "\<phi>\<^sub>i"} yields the theorem @{text "(\<phi>\<^sub>1 \<Longrightarrow> |
52467 | 531 |
\<dots> \<phi>\<^sub>i\<^sub>-\<^sub>1 \<Longrightarrow> \<phi>\<^sub>i\<^sub>+\<^sub>1 \<Longrightarrow> \<dots> \<phi>\<^sub>n \<Longrightarrow> \<phi>)s"}. Multiple results are considered as |
532 |
error (exception @{ML THM}). |
|
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
533 |
|
61439 | 534 |
\<^descr> @{text "thm\<^sub>1 COMP thm\<^sub>2"} is the same as @{text "Drule.compose |
52467 | 535 |
(thm\<^sub>1, 1, thm\<^sub>2)"}. |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
536 |
|
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
537 |
\end{description} |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
538 |
|
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
539 |
\begin{warn} |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
540 |
These low-level operations are stepping outside the structure |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
541 |
imposed by regular rule resolution. Used without understanding of |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
542 |
the consequences, they may produce results that cause problems with |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
543 |
standard rules and tactics later on. |
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
544 |
\end{warn} |
58618 | 545 |
\<close> |
50074
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
546 |
|
0b02aaf7c7c5
some coverage of "resolution without lifting", which should be normally avoided;
wenzelm
parents:
50072
diff
changeset
|
547 |
|
58618 | 548 |
section \<open>Tacticals \label{sec:tacticals}\<close> |
18537 | 549 |
|
58618 | 550 |
text \<open>A \emph{tactical} is a functional combinator for building up |
46258 | 551 |
complex tactics from simpler ones. Common tacticals perform |
552 |
sequential composition, disjunctive choice, iteration, or goal |
|
553 |
addressing. Various search strategies may be expressed via |
|
554 |
tacticals. |
|
58618 | 555 |
\<close> |
46258 | 556 |
|
557 |
||
58618 | 558 |
subsection \<open>Combining tactics\<close> |
46258 | 559 |
|
58618 | 560 |
text \<open>Sequential composition and alternative choices are the most |
46258 | 561 |
basic ways to combine tactics, similarly to ``@{verbatim ","}'' and |
562 |
``@{verbatim "|"}'' in Isar method notation. This corresponds to |
|
46262 | 563 |
@{ML_op "THEN"} and @{ML_op "ORELSE"} in ML, but there are further |
564 |
possibilities for fine-tuning alternation of tactics such as @{ML_op |
|
46258 | 565 |
"APPEND"}. Further details become visible in ML due to explicit |
46262 | 566 |
subgoal addressing. |
58618 | 567 |
\<close> |
46258 | 568 |
|
58618 | 569 |
text %mlref \<open> |
46258 | 570 |
\begin{mldecls} |
46262 | 571 |
@{index_ML_op "THEN": "tactic * tactic -> tactic"} \\ |
572 |
@{index_ML_op "ORELSE": "tactic * tactic -> tactic"} \\ |
|
573 |
@{index_ML_op "APPEND": "tactic * tactic -> tactic"} \\ |
|
46258 | 574 |
@{index_ML "EVERY": "tactic list -> tactic"} \\ |
575 |
@{index_ML "FIRST": "tactic list -> tactic"} \\[0.5ex] |
|
576 |
||
46262 | 577 |
@{index_ML_op "THEN'": "('a -> tactic) * ('a -> tactic) -> 'a -> tactic"} \\ |
578 |
@{index_ML_op "ORELSE'": "('a -> tactic) * ('a -> tactic) -> 'a -> tactic"} \\ |
|
579 |
@{index_ML_op "APPEND'": "('a -> tactic) * ('a -> tactic) -> 'a -> tactic"} \\ |
|
46258 | 580 |
@{index_ML "EVERY'": "('a -> tactic) list -> 'a -> tactic"} \\ |
581 |
@{index_ML "FIRST'": "('a -> tactic) list -> 'a -> tactic"} \\ |
|
582 |
\end{mldecls} |
|
583 |
||
584 |
\begin{description} |
|
18537 | 585 |
|
61439 | 586 |
\<^descr> @{text "tac\<^sub>1"}~@{ML_op THEN}~@{text "tac\<^sub>2"} is the sequential |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
587 |
composition of @{text "tac\<^sub>1"} and @{text "tac\<^sub>2"}. Applied to a goal |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
588 |
state, it returns all states reachable in two steps by applying |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
589 |
@{text "tac\<^sub>1"} followed by @{text "tac\<^sub>2"}. First, it applies @{text |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
590 |
"tac\<^sub>1"} to the goal state, getting a sequence of possible next |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
591 |
states; then, it applies @{text "tac\<^sub>2"} to each of these and |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
592 |
concatenates the results to produce again one flat sequence of |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
593 |
states. |
46258 | 594 |
|
61439 | 595 |
\<^descr> @{text "tac\<^sub>1"}~@{ML_op ORELSE}~@{text "tac\<^sub>2"} makes a choice |
46262 | 596 |
between @{text "tac\<^sub>1"} and @{text "tac\<^sub>2"}. Applied to a state, it |
597 |
tries @{text "tac\<^sub>1"} and returns the result if non-empty; if @{text |
|
598 |
"tac\<^sub>1"} fails then it uses @{text "tac\<^sub>2"}. This is a deterministic |
|
599 |
choice: if @{text "tac\<^sub>1"} succeeds then @{text "tac\<^sub>2"} is excluded |
|
600 |
from the result. |
|
46258 | 601 |
|
61439 | 602 |
\<^descr> @{text "tac\<^sub>1"}~@{ML_op APPEND}~@{text "tac\<^sub>2"} concatenates the |
46262 | 603 |
possible results of @{text "tac\<^sub>1"} and @{text "tac\<^sub>2"}. Unlike |
604 |
@{ML_op "ORELSE"} there is \emph{no commitment} to either tactic, so |
|
605 |
@{ML_op "APPEND"} helps to avoid incompleteness during search, at |
|
606 |
the cost of potential inefficiencies. |
|
39852 | 607 |
|
61439 | 608 |
\<^descr> @{ML EVERY}~@{text "[tac\<^sub>1, \<dots>, tac\<^sub>n]"} abbreviates @{text |
46262 | 609 |
"tac\<^sub>1"}~@{ML_op THEN}~@{text "\<dots>"}~@{ML_op THEN}~@{text "tac\<^sub>n"}. |
610 |
Note that @{ML "EVERY []"} is the same as @{ML all_tac}: it always |
|
611 |
succeeds. |
|
46258 | 612 |
|
61439 | 613 |
\<^descr> @{ML FIRST}~@{text "[tac\<^sub>1, \<dots>, tac\<^sub>n]"} abbreviates @{text |
46262 | 614 |
"tac\<^sub>1"}~@{ML_op ORELSE}~@{text "\<dots>"}~@{ML_op "ORELSE"}~@{text |
615 |
"tac\<^sub>n"}. Note that @{ML "FIRST []"} is the same as @{ML no_tac}: it |
|
616 |
always fails. |
|
46258 | 617 |
|
61439 | 618 |
\<^descr> @{ML_op "THEN'"} is the lifted version of @{ML_op "THEN"}, for |
46266 | 619 |
tactics with explicit subgoal addressing. So @{text |
46264 | 620 |
"(tac\<^sub>1"}~@{ML_op THEN'}~@{text "tac\<^sub>2) i"} is the same as @{text |
621 |
"(tac\<^sub>1 i"}~@{ML_op THEN}~@{text "tac\<^sub>2 i)"}. |
|
46258 | 622 |
|
46264 | 623 |
The other primed tacticals work analogously. |
46258 | 624 |
|
625 |
\end{description} |
|
58618 | 626 |
\<close> |
30272 | 627 |
|
46259 | 628 |
|
58618 | 629 |
subsection \<open>Repetition tacticals\<close> |
46259 | 630 |
|
58618 | 631 |
text \<open>These tacticals provide further control over repetition of |
46259 | 632 |
tactics, beyond the stylized forms of ``@{verbatim "?"}'' and |
58618 | 633 |
``@{verbatim "+"}'' in Isar method expressions.\<close> |
46259 | 634 |
|
58618 | 635 |
text %mlref \<open> |
46259 | 636 |
\begin{mldecls} |
637 |
@{index_ML "TRY": "tactic -> tactic"} \\ |
|
46266 | 638 |
@{index_ML "REPEAT": "tactic -> tactic"} \\ |
639 |
@{index_ML "REPEAT1": "tactic -> tactic"} \\ |
|
46259 | 640 |
@{index_ML "REPEAT_DETERM": "tactic -> tactic"} \\ |
641 |
@{index_ML "REPEAT_DETERM_N": "int -> tactic -> tactic"} \\ |
|
642 |
\end{mldecls} |
|
643 |
||
644 |
\begin{description} |
|
645 |
||
61439 | 646 |
\<^descr> @{ML TRY}~@{text "tac"} applies @{text "tac"} to the goal |
46259 | 647 |
state and returns the resulting sequence, if non-empty; otherwise it |
648 |
returns the original state. Thus, it applies @{text "tac"} at most |
|
649 |
once. |
|
650 |
||
46266 | 651 |
Note that for tactics with subgoal addressing, the combinator can be |
652 |
applied via functional composition: @{ML "TRY"}~@{ML_op o}~@{text |
|
653 |
"tac"}. There is no need for @{verbatim TRY'}. |
|
46259 | 654 |
|
61439 | 655 |
\<^descr> @{ML REPEAT}~@{text "tac"} applies @{text "tac"} to the goal |
46259 | 656 |
state and, recursively, to each element of the resulting sequence. |
657 |
The resulting sequence consists of those states that make @{text |
|
658 |
"tac"} fail. Thus, it applies @{text "tac"} as many times as |
|
659 |
possible (including zero times), and allows backtracking over each |
|
660 |
invocation of @{text "tac"}. @{ML REPEAT} is more general than @{ML |
|
661 |
REPEAT_DETERM}, but requires more space. |
|
662 |
||
61439 | 663 |
\<^descr> @{ML REPEAT1}~@{text "tac"} is like @{ML REPEAT}~@{text "tac"} |
46259 | 664 |
but it always applies @{text "tac"} at least once, failing if this |
665 |
is impossible. |
|
666 |
||
61439 | 667 |
\<^descr> @{ML REPEAT_DETERM}~@{text "tac"} applies @{text "tac"} to the |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
668 |
goal state and, recursively, to the head of the resulting sequence. |
46266 | 669 |
It returns the first state to make @{text "tac"} fail. It is |
670 |
deterministic, discarding alternative outcomes. |
|
671 |
||
61439 | 672 |
\<^descr> @{ML REPEAT_DETERM_N}~@{text "n tac"} is like @{ML |
46266 | 673 |
REPEAT_DETERM}~@{text "tac"} but the number of repetitions is bound |
674 |
by @{text "n"} (where @{ML "~1"} means @{text "\<infinity>"}). |
|
46259 | 675 |
|
676 |
\end{description} |
|
58618 | 677 |
\<close> |
46259 | 678 |
|
58618 | 679 |
text %mlex \<open>The basic tactics and tacticals considered above follow |
46260 | 680 |
some algebraic laws: |
46259 | 681 |
|
46260 | 682 |
\begin{itemize} |
46259 | 683 |
|
61416 | 684 |
\<^item> @{ML all_tac} is the identity element of the tactical @{ML_op |
46262 | 685 |
"THEN"}. |
46259 | 686 |
|
61416 | 687 |
\<^item> @{ML no_tac} is the identity element of @{ML_op "ORELSE"} and |
46262 | 688 |
@{ML_op "APPEND"}. Also, it is a zero element for @{ML_op "THEN"}, |
689 |
which means that @{text "tac"}~@{ML_op THEN}~@{ML no_tac} is |
|
690 |
equivalent to @{ML no_tac}. |
|
46259 | 691 |
|
61416 | 692 |
\<^item> @{ML TRY} and @{ML REPEAT} can be expressed as (recursive) |
46260 | 693 |
functions over more basic combinators (ignoring some internal |
694 |
implementation tricks): |
|
46259 | 695 |
|
46260 | 696 |
\end{itemize} |
58618 | 697 |
\<close> |
46259 | 698 |
|
58618 | 699 |
ML \<open> |
46259 | 700 |
fun TRY tac = tac ORELSE all_tac; |
701 |
fun REPEAT tac st = ((tac THEN REPEAT tac) ORELSE all_tac) st; |
|
58618 | 702 |
\<close> |
46259 | 703 |
|
58618 | 704 |
text \<open>If @{text "tac"} can return multiple outcomes then so can @{ML |
46262 | 705 |
REPEAT}~@{text "tac"}. @{ML REPEAT} uses @{ML_op "ORELSE"} and not |
706 |
@{ML_op "APPEND"}, it applies @{text "tac"} as many times as |
|
46259 | 707 |
possible in each outcome. |
708 |
||
709 |
\begin{warn} |
|
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
710 |
Note the explicit abstraction over the goal state in the ML |
46260 | 711 |
definition of @{ML REPEAT}. Recursive tacticals must be coded in |
712 |
this awkward fashion to avoid infinite recursion of eager functional |
|
713 |
evaluation in Standard ML. The following attempt would make @{ML |
|
714 |
REPEAT}~@{text "tac"} loop: |
|
46259 | 715 |
\end{warn} |
58618 | 716 |
\<close> |
46259 | 717 |
|
59902 | 718 |
ML_val \<open> |
46260 | 719 |
(*BAD -- does not terminate!*) |
720 |
fun REPEAT tac = (tac THEN REPEAT tac) ORELSE all_tac; |
|
58618 | 721 |
\<close> |
46259 | 722 |
|
46263 | 723 |
|
58618 | 724 |
subsection \<open>Applying tactics to subgoal ranges\<close> |
46263 | 725 |
|
58618 | 726 |
text \<open>Tactics with explicit subgoal addressing |
46263 | 727 |
@{ML_type "int -> tactic"} can be used together with tacticals that |
728 |
act like ``subgoal quantifiers'': guided by success of the body |
|
729 |
tactic a certain range of subgoals is covered. Thus the body tactic |
|
46267 | 730 |
is applied to \emph{all} subgoals, \emph{some} subgoal etc. |
46263 | 731 |
|
732 |
Suppose that the goal state has @{text "n \<ge> 0"} subgoals. Many of |
|
733 |
these tacticals address subgoal ranges counting downwards from |
|
734 |
@{text "n"} towards @{text "1"}. This has the fortunate effect that |
|
735 |
newly emerging subgoals are concatenated in the result, without |
|
736 |
interfering each other. Nonetheless, there might be situations |
|
58618 | 737 |
where a different order is desired.\<close> |
46263 | 738 |
|
58618 | 739 |
text %mlref \<open> |
46263 | 740 |
\begin{mldecls} |
741 |
@{index_ML ALLGOALS: "(int -> tactic) -> tactic"} \\ |
|
742 |
@{index_ML SOMEGOAL: "(int -> tactic) -> tactic"} \\ |
|
743 |
@{index_ML FIRSTGOAL: "(int -> tactic) -> tactic"} \\ |
|
46267 | 744 |
@{index_ML HEADGOAL: "(int -> tactic) -> tactic"} \\ |
46263 | 745 |
@{index_ML REPEAT_SOME: "(int -> tactic) -> tactic"} \\ |
746 |
@{index_ML REPEAT_FIRST: "(int -> tactic) -> tactic"} \\ |
|
46267 | 747 |
@{index_ML RANGE: "(int -> tactic) list -> int -> tactic"} \\ |
46263 | 748 |
\end{mldecls} |
749 |
||
750 |
\begin{description} |
|
751 |
||
61439 | 752 |
\<^descr> @{ML ALLGOALS}~@{text "tac"} is equivalent to @{text "tac |
46263 | 753 |
n"}~@{ML_op THEN}~@{text "\<dots>"}~@{ML_op THEN}~@{text "tac 1"}. It |
754 |
applies the @{text tac} to all the subgoals, counting downwards. |
|
755 |
||
61439 | 756 |
\<^descr> @{ML SOMEGOAL}~@{text "tac"} is equivalent to @{text "tac |
46263 | 757 |
n"}~@{ML_op ORELSE}~@{text "\<dots>"}~@{ML_op ORELSE}~@{text "tac 1"}. It |
758 |
applies @{text "tac"} to one subgoal, counting downwards. |
|
759 |
||
61439 | 760 |
\<^descr> @{ML FIRSTGOAL}~@{text "tac"} is equivalent to @{text "tac |
46263 | 761 |
1"}~@{ML_op ORELSE}~@{text "\<dots>"}~@{ML_op ORELSE}~@{text "tac n"}. It |
762 |
applies @{text "tac"} to one subgoal, counting upwards. |
|
763 |
||
61439 | 764 |
\<^descr> @{ML HEADGOAL}~@{text "tac"} is equivalent to @{text "tac 1"}. |
46267 | 765 |
It applies @{text "tac"} unconditionally to the first subgoal. |
766 |
||
61439 | 767 |
\<^descr> @{ML REPEAT_SOME}~@{text "tac"} applies @{text "tac"} once or |
46263 | 768 |
more to a subgoal, counting downwards. |
769 |
||
61439 | 770 |
\<^descr> @{ML REPEAT_FIRST}~@{text "tac"} applies @{text "tac"} once or |
46263 | 771 |
more to a subgoal, counting upwards. |
772 |
||
61439 | 773 |
\<^descr> @{ML RANGE}~@{text "[tac\<^sub>1, \<dots>, tac\<^sub>k] i"} is equivalent to |
46267 | 774 |
@{text "tac\<^sub>k (i + k - 1)"}~@{ML_op THEN}~@{text "\<dots>"}~@{ML_op |
775 |
THEN}~@{text "tac\<^sub>1 i"}. It applies the given list of tactics to the |
|
776 |
corresponding range of subgoals, counting downwards. |
|
777 |
||
46263 | 778 |
\end{description} |
58618 | 779 |
\<close> |
46263 | 780 |
|
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
781 |
|
58618 | 782 |
subsection \<open>Control and search tacticals\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
783 |
|
58618 | 784 |
text \<open>A predicate on theorems @{ML_type "thm -> bool"} can test |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
785 |
whether a goal state enjoys some desirable property --- such as |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
786 |
having no subgoals. Tactics that search for satisfactory goal |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
787 |
states are easy to express. The main search procedures, |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
788 |
depth-first, breadth-first and best-first, are provided as |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
789 |
tacticals. They generate the search tree by repeatedly applying a |
58618 | 790 |
given tactic.\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
791 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
792 |
|
46270 | 793 |
text %mlref "" |
794 |
||
58618 | 795 |
subsubsection \<open>Filtering a tactic's results\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
796 |
|
58618 | 797 |
text \<open> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
798 |
\begin{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
799 |
@{index_ML FILTER: "(thm -> bool) -> tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
800 |
@{index_ML CHANGED: "tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
801 |
\end{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
802 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
803 |
\begin{description} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
804 |
|
61439 | 805 |
\<^descr> @{ML FILTER}~@{text "sat tac"} applies @{text "tac"} to the |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
806 |
goal state and returns a sequence consisting of those result goal |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
807 |
states that are satisfactory in the sense of @{text "sat"}. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
808 |
|
61439 | 809 |
\<^descr> @{ML CHANGED}~@{text "tac"} applies @{text "tac"} to the goal |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
810 |
state and returns precisely those states that differ from the |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
811 |
original state (according to @{ML Thm.eq_thm}). Thus @{ML |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
812 |
CHANGED}~@{text "tac"} always has some effect on the state. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
813 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
814 |
\end{description} |
58618 | 815 |
\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
816 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
817 |
|
58618 | 818 |
subsubsection \<open>Depth-first search\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
819 |
|
58618 | 820 |
text \<open> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
821 |
\begin{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
822 |
@{index_ML DEPTH_FIRST: "(thm -> bool) -> tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
823 |
@{index_ML DEPTH_SOLVE: "tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
824 |
@{index_ML DEPTH_SOLVE_1: "tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
825 |
\end{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
826 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
827 |
\begin{description} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
828 |
|
61439 | 829 |
\<^descr> @{ML DEPTH_FIRST}~@{text "sat tac"} returns the goal state if |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
830 |
@{text "sat"} returns true. Otherwise it applies @{text "tac"}, |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
831 |
then recursively searches from each element of the resulting |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
832 |
sequence. The code uses a stack for efficiency, in effect applying |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
833 |
@{text "tac"}~@{ML_op THEN}~@{ML DEPTH_FIRST}~@{text "sat tac"} to |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
834 |
the state. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
835 |
|
61439 | 836 |
\<^descr> @{ML DEPTH_SOLVE}@{text "tac"} uses @{ML DEPTH_FIRST} to |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
837 |
search for states having no subgoals. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
838 |
|
61439 | 839 |
\<^descr> @{ML DEPTH_SOLVE_1}~@{text "tac"} uses @{ML DEPTH_FIRST} to |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
840 |
search for states having fewer subgoals than the given state. Thus, |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
841 |
it insists upon solving at least one subgoal. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
842 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
843 |
\end{description} |
58618 | 844 |
\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
845 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
846 |
|
58618 | 847 |
subsubsection \<open>Other search strategies\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
848 |
|
58618 | 849 |
text \<open> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
850 |
\begin{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
851 |
@{index_ML BREADTH_FIRST: "(thm -> bool) -> tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
852 |
@{index_ML BEST_FIRST: "(thm -> bool) * (thm -> int) -> tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
853 |
@{index_ML THEN_BEST_FIRST: "tactic -> (thm -> bool) * (thm -> int) -> tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
854 |
\end{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
855 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
856 |
These search strategies will find a solution if one exists. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
857 |
However, they do not enumerate all solutions; they terminate after |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
858 |
the first satisfactory result from @{text "tac"}. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
859 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
860 |
\begin{description} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
861 |
|
61439 | 862 |
\<^descr> @{ML BREADTH_FIRST}~@{text "sat tac"} uses breadth-first |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
863 |
search to find states for which @{text "sat"} is true. For most |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
864 |
applications, it is too slow. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
865 |
|
61439 | 866 |
\<^descr> @{ML BEST_FIRST}~@{text "(sat, dist) tac"} does a heuristic |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
867 |
search, using @{text "dist"} to estimate the distance from a |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
868 |
satisfactory state (in the sense of @{text "sat"}). It maintains a |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
869 |
list of states ordered by distance. It applies @{text "tac"} to the |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
870 |
head of this list; if the result contains any satisfactory states, |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
871 |
then it returns them. Otherwise, @{ML BEST_FIRST} adds the new |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
872 |
states to the list, and continues. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
873 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
874 |
The distance function is typically @{ML size_of_thm}, which computes |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
875 |
the size of the state. The smaller the state, the fewer and simpler |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
876 |
subgoals it has. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
877 |
|
61439 | 878 |
\<^descr> @{ML THEN_BEST_FIRST}~@{text "tac\<^sub>0 (sat, dist) tac"} is like |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
879 |
@{ML BEST_FIRST}, except that the priority queue initially contains |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
880 |
the result of applying @{text "tac\<^sub>0"} to the goal state. This |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
881 |
tactical permits separate tactics for starting the search and |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
882 |
continuing the search. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
883 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
884 |
\end{description} |
58618 | 885 |
\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
886 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
887 |
|
58618 | 888 |
subsubsection \<open>Auxiliary tacticals for searching\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
889 |
|
58618 | 890 |
text \<open> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
891 |
\begin{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
892 |
@{index_ML COND: "(thm -> bool) -> tactic -> tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
893 |
@{index_ML IF_UNSOLVED: "tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
894 |
@{index_ML SOLVE: "tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
895 |
@{index_ML DETERM: "tactic -> tactic"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
896 |
\end{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
897 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
898 |
\begin{description} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
899 |
|
61439 | 900 |
\<^descr> @{ML COND}~@{text "sat tac\<^sub>1 tac\<^sub>2"} applies @{text "tac\<^sub>1"} to |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
901 |
the goal state if it satisfies predicate @{text "sat"}, and applies |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
902 |
@{text "tac\<^sub>2"}. It is a conditional tactical in that only one of |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
903 |
@{text "tac\<^sub>1"} and @{text "tac\<^sub>2"} is applied to a goal state. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
904 |
However, both @{text "tac\<^sub>1"} and @{text "tac\<^sub>2"} are evaluated |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
905 |
because ML uses eager evaluation. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
906 |
|
61439 | 907 |
\<^descr> @{ML IF_UNSOLVED}~@{text "tac"} applies @{text "tac"} to the |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
908 |
goal state if it has any subgoals, and simply returns the goal state |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
909 |
otherwise. Many common tactics, such as @{ML resolve_tac}, fail if |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
910 |
applied to a goal state that has no subgoals. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
911 |
|
61439 | 912 |
\<^descr> @{ML SOLVE}~@{text "tac"} applies @{text "tac"} to the goal |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
913 |
state and then fails iff there are subgoals left. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
914 |
|
61439 | 915 |
\<^descr> @{ML DETERM}~@{text "tac"} applies @{text "tac"} to the goal |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
916 |
state and returns the head of the resulting sequence. @{ML DETERM} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
917 |
limits the search space by making its argument deterministic. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
918 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
919 |
\end{description} |
58618 | 920 |
\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
921 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
922 |
|
58618 | 923 |
subsubsection \<open>Predicates and functions useful for searching\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
924 |
|
58618 | 925 |
text \<open> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
926 |
\begin{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
927 |
@{index_ML has_fewer_prems: "int -> thm -> bool"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
928 |
@{index_ML Thm.eq_thm: "thm * thm -> bool"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
929 |
@{index_ML Thm.eq_thm_prop: "thm * thm -> bool"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
930 |
@{index_ML size_of_thm: "thm -> int"} \\ |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
931 |
\end{mldecls} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
932 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
933 |
\begin{description} |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
934 |
|
61439 | 935 |
\<^descr> @{ML has_fewer_prems}~@{text "n thm"} reports whether @{text |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
936 |
"thm"} has fewer than @{text "n"} premises. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
937 |
|
61439 | 938 |
\<^descr> @{ML Thm.eq_thm}~@{text "(thm\<^sub>1, thm\<^sub>2)"} reports whether @{text |
55547
384bfd19ee61
subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents:
53096
diff
changeset
|
939 |
"thm\<^sub>1"} and @{text "thm\<^sub>2"} are equal. Both theorems must have the |
384bfd19ee61
subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents:
53096
diff
changeset
|
940 |
same conclusions, the same set of hypotheses, and the same set of sort |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
941 |
hypotheses. Names of bound variables are ignored as usual. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
942 |
|
61439 | 943 |
\<^descr> @{ML Thm.eq_thm_prop}~@{text "(thm\<^sub>1, thm\<^sub>2)"} reports whether |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
944 |
the propositions of @{text "thm\<^sub>1"} and @{text "thm\<^sub>2"} are equal. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
945 |
Names of bound variables are ignored. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
946 |
|
61439 | 947 |
\<^descr> @{ML size_of_thm}~@{text "thm"} computes the size of @{text |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
948 |
"thm"}, namely the number of variables, constants and abstractions |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
949 |
in its conclusion. It may serve as a distance function for |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
950 |
@{ML BEST_FIRST}. |
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
951 |
|
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
952 |
\end{description} |
58618 | 953 |
\<close> |
46269
e75181672150
updated "Control and search tacticals" (moved from ref to implementation);
wenzelm
parents:
46267
diff
changeset
|
954 |
|
18537 | 955 |
end |