3 \index{tactics|(} |
3 \index{tactics|(} |
4 Tactics have type \mltydx{tactic}. They are essentially |
4 Tactics have type \mltydx{tactic}. They are essentially |
5 functions from theorems to theorem sequences, where the theorems represent |
5 functions from theorems to theorem sequences, where the theorems represent |
6 states of a backward proof. Tactics seldom need to be coded from scratch, |
6 states of a backward proof. Tactics seldom need to be coded from scratch, |
7 as functions; instead they are expressed using basic tactics and tacticals. |
7 as functions; instead they are expressed using basic tactics and tacticals. |
|
8 |
|
9 This chapter only presents the primitive tactics. Substantial proofs require |
|
10 the power of simplification (Chapter~\ref{simp-chap}) and classical reasoning |
|
11 (Chapter~\ref{chap:classical}). |
8 |
12 |
9 \section{Resolution and assumption tactics} |
13 \section{Resolution and assumption tactics} |
10 {\bf Resolution} is Isabelle's basic mechanism for refining a subgoal using |
14 {\bf Resolution} is Isabelle's basic mechanism for refining a subgoal using |
11 a rule. {\bf Elim-resolution} is particularly suited for elimination |
15 a rule. {\bf Elim-resolution} is particularly suited for elimination |
12 rules, while {\bf destruct-resolution} is particularly suited for |
16 rules, while {\bf destruct-resolution} is particularly suited for |
157 result as a new assumption. |
161 result as a new assumption. |
158 \end{ttdescription} |
162 \end{ttdescription} |
159 |
163 |
160 |
164 |
161 \section{Other basic tactics} |
165 \section{Other basic tactics} |
162 \subsection{Definitions and meta-level rewriting} |
|
163 \index{tactics!meta-rewriting|bold}\index{meta-rewriting|bold} |
|
164 \index{definitions} |
|
165 |
|
166 Definitions in Isabelle have the form $t\equiv u$, where $t$ is typically a |
|
167 constant or a constant applied to a list of variables, for example $\it |
|
168 sqr(n)\equiv n\times n$. (Conditional definitions, $\phi\Imp t\equiv u$, |
|
169 are not supported.) {\bf Unfolding} the definition ${t\equiv u}$ means using |
|
170 it as a rewrite rule, replacing~$t$ by~$u$ throughout a theorem. {\bf |
|
171 Folding} $t\equiv u$ means replacing~$u$ by~$t$. Rewriting continues until |
|
172 no rewrites are applicable to any subterm. |
|
173 |
|
174 There are rules for unfolding and folding definitions; Isabelle does not do |
|
175 this automatically. The corresponding tactics rewrite the proof state, |
|
176 yielding a single next state. See also the {\tt goalw} command, which is the |
|
177 easiest way of handling definitions. |
|
178 \begin{ttbox} |
|
179 rewrite_goals_tac : thm list -> tactic |
|
180 rewrite_tac : thm list -> tactic |
|
181 fold_goals_tac : thm list -> tactic |
|
182 fold_tac : thm list -> tactic |
|
183 \end{ttbox} |
|
184 \begin{ttdescription} |
|
185 \item[\ttindexbold{rewrite_goals_tac} {\it defs}] |
|
186 unfolds the {\it defs} throughout the subgoals of the proof state, while |
|
187 leaving the main goal unchanged. Use \ttindex{SELECT_GOAL} to restrict it to a |
|
188 particular subgoal. |
|
189 |
|
190 \item[\ttindexbold{rewrite_tac} {\it defs}] |
|
191 unfolds the {\it defs} throughout the proof state, including the main goal |
|
192 --- not normally desirable! |
|
193 |
|
194 \item[\ttindexbold{fold_goals_tac} {\it defs}] |
|
195 folds the {\it defs} throughout the subgoals of the proof state, while |
|
196 leaving the main goal unchanged. |
|
197 |
|
198 \item[\ttindexbold{fold_tac} {\it defs}] |
|
199 folds the {\it defs} throughout the proof state. |
|
200 \end{ttdescription} |
|
201 |
|
202 |
|
203 \subsection{Tactic shortcuts} |
166 \subsection{Tactic shortcuts} |
204 \index{shortcuts!for tactics} |
167 \index{shortcuts!for tactics} |
205 \index{tactics!resolution}\index{tactics!assumption} |
168 \index{tactics!resolution}\index{tactics!assumption} |
206 \index{tactics!meta-rewriting} |
169 \index{tactics!meta-rewriting} |
207 \begin{ttbox} |
170 \begin{ttbox} |
244 cut_facts_tac : thm list -> int -> tactic |
207 cut_facts_tac : thm list -> int -> tactic |
245 cut_inst_tac : (string*string)list -> thm -> int -> tactic |
208 cut_inst_tac : (string*string)list -> thm -> int -> tactic |
246 subgoal_tac : string -> int -> tactic |
209 subgoal_tac : string -> int -> tactic |
247 subgoal_tacs : string list -> int -> tactic |
210 subgoal_tacs : string list -> int -> tactic |
248 \end{ttbox} |
211 \end{ttbox} |
249 These tactics add assumptions to a given subgoal. |
212 These tactics add assumptions to a subgoal. |
250 \begin{ttdescription} |
213 \begin{ttdescription} |
251 \item[\ttindexbold{cut_facts_tac} {\it thms} {\it i}] |
214 \item[\ttindexbold{cut_facts_tac} {\it thms} {\it i}] |
252 adds the {\it thms} as new assumptions to subgoal~$i$. Once they have |
215 adds the {\it thms} as new assumptions to subgoal~$i$. Once they have |
253 been inserted as assumptions, they become subject to tactics such as {\tt |
216 been inserted as assumptions, they become subject to tactics such as {\tt |
254 eresolve_tac} and {\tt rewrite_goals_tac}. Only rules with no premises |
217 eresolve_tac} and {\tt rewrite_goals_tac}. Only rules with no premises |
270 uses {\tt subgoal_tac} to add the members of the list of {\it |
233 uses {\tt subgoal_tac} to add the members of the list of {\it |
271 formulae} as assumptions to subgoal~$i$. |
234 formulae} as assumptions to subgoal~$i$. |
272 \end{ttdescription} |
235 \end{ttdescription} |
273 |
236 |
274 |
237 |
|
238 \subsection{``Putting off'' a subgoal} |
|
239 \begin{ttbox} |
|
240 defer_tac : int -> tactic |
|
241 \end{ttbox} |
|
242 \begin{ttdescription} |
|
243 \item[\ttindexbold{defer_tac} {\it i}] |
|
244 moves subgoal~$i$ to the last position in the proof state. It can be |
|
245 useful when correcting a proof script: if the tactic given for subgoal~$i$ |
|
246 fails, calling {\tt defer_tac} instead will let you continue with the rest |
|
247 of the script. |
|
248 |
|
249 The tactic fails if subgoal~$i$ does not exist or if the proof state |
|
250 contains type unknowns. |
|
251 \end{ttdescription} |
|
252 |
|
253 |
|
254 \subsection{Definitions and meta-level rewriting} |
|
255 \index{tactics!meta-rewriting|bold}\index{meta-rewriting|bold} |
|
256 \index{definitions} |
|
257 |
|
258 Definitions in Isabelle have the form $t\equiv u$, where $t$ is typically a |
|
259 constant or a constant applied to a list of variables, for example $\it |
|
260 sqr(n)\equiv n\times n$. (Conditional definitions, $\phi\Imp t\equiv u$, |
|
261 are not supported.) {\bf Unfolding} the definition ${t\equiv u}$ means using |
|
262 it as a rewrite rule, replacing~$t$ by~$u$ throughout a theorem. {\bf |
|
263 Folding} $t\equiv u$ means replacing~$u$ by~$t$. Rewriting continues until |
|
264 no rewrites are applicable to any subterm. |
|
265 |
|
266 There are rules for unfolding and folding definitions; Isabelle does not do |
|
267 this automatically. The corresponding tactics rewrite the proof state, |
|
268 yielding a single next state. See also the {\tt goalw} command, which is the |
|
269 easiest way of handling definitions. |
|
270 \begin{ttbox} |
|
271 rewrite_goals_tac : thm list -> tactic |
|
272 rewrite_tac : thm list -> tactic |
|
273 fold_goals_tac : thm list -> tactic |
|
274 fold_tac : thm list -> tactic |
|
275 \end{ttbox} |
|
276 \begin{ttdescription} |
|
277 \item[\ttindexbold{rewrite_goals_tac} {\it defs}] |
|
278 unfolds the {\it defs} throughout the subgoals of the proof state, while |
|
279 leaving the main goal unchanged. Use \ttindex{SELECT_GOAL} to restrict it to a |
|
280 particular subgoal. |
|
281 |
|
282 \item[\ttindexbold{rewrite_tac} {\it defs}] |
|
283 unfolds the {\it defs} throughout the proof state, including the main goal |
|
284 --- not normally desirable! |
|
285 |
|
286 \item[\ttindexbold{fold_goals_tac} {\it defs}] |
|
287 folds the {\it defs} throughout the subgoals of the proof state, while |
|
288 leaving the main goal unchanged. |
|
289 |
|
290 \item[\ttindexbold{fold_tac} {\it defs}] |
|
291 folds the {\it defs} throughout the proof state. |
|
292 \end{ttdescription} |
|
293 |
|
294 |
275 \subsection{Theorems useful with tactics} |
295 \subsection{Theorems useful with tactics} |
276 \index{theorems!of pure theory} |
296 \index{theorems!of pure theory} |
277 \begin{ttbox} |
297 \begin{ttbox} |
278 asm_rl: thm |
298 asm_rl: thm |
279 cut_rl: thm |
299 cut_rl: thm |
404 \section{Managing lots of rules} |
424 \section{Managing lots of rules} |
405 These operations are not intended for interactive use. They are concerned |
425 These operations are not intended for interactive use. They are concerned |
406 with the processing of large numbers of rules in automatic proof |
426 with the processing of large numbers of rules in automatic proof |
407 strategies. Higher-order resolution involving a long list of rules is |
427 strategies. Higher-order resolution involving a long list of rules is |
408 slow. Filtering techniques can shorten the list of rules given to |
428 slow. Filtering techniques can shorten the list of rules given to |
409 resolution, and can also detect whether a given subgoal is too flexible, |
429 resolution, and can also detect whether a subgoal is too flexible, |
410 with too many rules applicable. |
430 with too many rules applicable. |
411 |
431 |
412 \subsection{Combined resolution and elim-resolution} \label{biresolve_tac} |
432 \subsection{Combined resolution and elim-resolution} \label{biresolve_tac} |
413 \index{tactics!resolution} |
433 \index{tactics!resolution} |
414 \begin{ttbox} |
434 \begin{ttbox} |