doc-src/IsarRef/Thy/document/ML_Tactic.tex
author wenzelm
Wed, 07 May 2008 15:32:31 +0200
changeset 26846 2e6726015771
child 26852 a31203f58b20
permissions -rw-r--r--
removed obsolete conversion guide -- converted only section on tactics;
wenzelm@26846
     1
%
wenzelm@26846
     2
\begin{isabellebody}%
wenzelm@26846
     3
\def\isabellecontext{ML{\isacharunderscore}Tactic}%
wenzelm@26846
     4
%
wenzelm@26846
     5
\isadelimtheory
wenzelm@26846
     6
\isanewline
wenzelm@26846
     7
\isanewline
wenzelm@26846
     8
%
wenzelm@26846
     9
\endisadelimtheory
wenzelm@26846
    10
%
wenzelm@26846
    11
\isatagtheory
wenzelm@26846
    12
\isacommand{theory}\isamarkupfalse%
wenzelm@26846
    13
\ ML{\isacharunderscore}Tactic\isanewline
wenzelm@26846
    14
\isakeyword{imports}\ Main\isanewline
wenzelm@26846
    15
\isakeyword{begin}%
wenzelm@26846
    16
\endisatagtheory
wenzelm@26846
    17
{\isafoldtheory}%
wenzelm@26846
    18
%
wenzelm@26846
    19
\isadelimtheory
wenzelm@26846
    20
%
wenzelm@26846
    21
\endisadelimtheory
wenzelm@26846
    22
%
wenzelm@26846
    23
\isamarkupchapter{ML tactic expressions \label{sec:conv-tac}%
wenzelm@26846
    24
}
wenzelm@26846
    25
\isamarkuptrue%
wenzelm@26846
    26
%
wenzelm@26846
    27
\begin{isamarkuptext}%
wenzelm@26846
    28
Isar Proof methods closely resemble traditional tactics, when used
wenzelm@26846
    29
  in unstructured sequences of \mbox{\isa{\isacommand{apply}}} commands.
wenzelm@26846
    30
  Isabelle/Isar provides emulations for all major ML tactics of
wenzelm@26846
    31
  classic Isabelle --- mostly for the sake of easy porting of existing
wenzelm@26846
    32
  developments, as actual Isar proof texts would demand much less
wenzelm@26846
    33
  diversity of proof methods.
wenzelm@26846
    34
wenzelm@26846
    35
  Unlike tactic expressions in ML, Isar proof methods provide proper
wenzelm@26846
    36
  concrete syntax for additional arguments, options, modifiers etc.
wenzelm@26846
    37
  Thus a typical method text is usually more concise than the
wenzelm@26846
    38
  corresponding ML tactic.  Furthermore, the Isar versions of classic
wenzelm@26846
    39
  Isabelle tactics often cover several variant forms by a single
wenzelm@26846
    40
  method with separate options to tune the behavior.  For example,
wenzelm@26846
    41
  method \mbox{\isa{simp}} replaces all of \verb|simp_tac|~/ \verb|asm_simp_tac|~/ \verb|full_simp_tac|~/ \verb|asm_full_simp_tac|, there
wenzelm@26846
    42
  is also concrete syntax for augmenting the Simplifier context (the
wenzelm@26846
    43
  current ``simpset'') in a convenient way.%
wenzelm@26846
    44
\end{isamarkuptext}%
wenzelm@26846
    45
\isamarkuptrue%
wenzelm@26846
    46
%
wenzelm@26846
    47
\isamarkupsection{Resolution tactics%
wenzelm@26846
    48
}
wenzelm@26846
    49
\isamarkuptrue%
wenzelm@26846
    50
%
wenzelm@26846
    51
\begin{isamarkuptext}%
wenzelm@26846
    52
Classic Isabelle provides several variant forms of tactics for
wenzelm@26846
    53
  single-step rule applications (based on higher-order resolution).
wenzelm@26846
    54
  The space of resolution tactics has the following main dimensions.
wenzelm@26846
    55
wenzelm@26846
    56
  \begin{enumerate}
wenzelm@26846
    57
wenzelm@26846
    58
  \item The ``mode'' of resolution: intro, elim, destruct, or forward
wenzelm@26846
    59
  (e.g.\ \verb|resolve_tac|, \verb|eresolve_tac|, \verb|dresolve_tac|,
wenzelm@26846
    60
  \verb|forward_tac|).
wenzelm@26846
    61
wenzelm@26846
    62
  \item Optional explicit instantiation (e.g.\ \verb|resolve_tac| vs.\
wenzelm@26846
    63
  \verb|res_inst_tac|).
wenzelm@26846
    64
wenzelm@26846
    65
  \item Abbreviations for singleton arguments (e.g.\ \verb|resolve_tac|
wenzelm@26846
    66
  vs.\ \verb|rtac|).
wenzelm@26846
    67
wenzelm@26846
    68
  \end{enumerate}
wenzelm@26846
    69
wenzelm@26846
    70
  Basically, the set of Isar tactic emulations \mbox{\isa{rule{\isacharunderscore}tac}},
wenzelm@26846
    71
  \mbox{\isa{erule{\isacharunderscore}tac}}, \mbox{\isa{drule{\isacharunderscore}tac}}, \mbox{\isa{frule{\isacharunderscore}tac}} (see
wenzelm@26846
    72
  \secref{sec:tactics}) would be sufficient to cover the four modes,
wenzelm@26846
    73
  either with or without instantiation, and either with single or
wenzelm@26846
    74
  multiple arguments.  Although it is more convenient in most cases to
wenzelm@26846
    75
  use the plain \mbox{\isa{rule}} method (see
wenzelm@26846
    76
  \secref{sec:pure-meth-att}), or any of its ``improper'' variants
wenzelm@26846
    77
  \mbox{\isa{erule}}, \mbox{\isa{drule}}, \mbox{\isa{frule}} (see
wenzelm@26846
    78
  \secref{sec:misc-meth-att}).  Note that explicit goal addressing is
wenzelm@26846
    79
  only supported by the actual \mbox{\isa{rule{\isacharunderscore}tac}} version.
wenzelm@26846
    80
wenzelm@26846
    81
  With this in mind, plain resolution tactics correspond to Isar
wenzelm@26846
    82
  methods as follows.
wenzelm@26846
    83
wenzelm@26846
    84
  \medskip
wenzelm@26846
    85
  \begin{tabular}{lll}
wenzelm@26846
    86
    \verb|rtac|~\isa{{\isachardoublequote}a\ {\isadigit{1}}{\isachardoublequote}} & & \isa{{\isachardoublequote}rule\ a{\isachardoublequote}} \\
wenzelm@26846
    87
    \verb|resolve_tac|~\isa{{\isachardoublequote}{\isacharbrackleft}a\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}\ {\isadigit{1}}{\isachardoublequote}} & & \isa{{\isachardoublequote}rule\ a\isactrlsub {\isadigit{1}}\ {\isasymdots}{\isachardoublequote}} \\
wenzelm@26846
    88
    \verb|res_inst_tac|~\isa{{\isachardoublequote}{\isacharbrackleft}{\isacharparenleft}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ t\isactrlsub {\isadigit{1}}{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}\ a\ {\isadigit{1}}{\isachardoublequote}} & &
wenzelm@26846
    89
    \isa{{\isachardoublequote}rule{\isacharunderscore}tac\ x\isactrlsub {\isadigit{1}}\ {\isacharequal}\ t\isactrlsub {\isadigit{1}}\ {\isasymAND}\ {\isasymdots}\ {\isasymIN}\ a{\isachardoublequote}} \\[0.5ex]
wenzelm@26846
    90
    \verb|rtac|~\isa{{\isachardoublequote}a\ i{\isachardoublequote}} & & \isa{{\isachardoublequote}rule{\isacharunderscore}tac\ {\isacharbrackleft}i{\isacharbrackright}\ a{\isachardoublequote}} \\
wenzelm@26846
    91
    \verb|resolve_tac|~\isa{{\isachardoublequote}{\isacharbrackleft}a\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}\ i{\isachardoublequote}} & & \isa{{\isachardoublequote}rule{\isacharunderscore}tac\ {\isacharbrackleft}i{\isacharbrackright}\ a\isactrlsub {\isadigit{1}}\ {\isasymdots}{\isachardoublequote}} \\
wenzelm@26846
    92
    \verb|res_inst_tac|~\isa{{\isachardoublequote}{\isacharbrackleft}{\isacharparenleft}x\isactrlsub {\isadigit{1}}{\isacharcomma}\ t\isactrlsub {\isadigit{1}}{\isacharparenright}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}\ a\ i{\isachardoublequote}} & &
wenzelm@26846
    93
    \isa{{\isachardoublequote}rule{\isacharunderscore}tac\ {\isacharbrackleft}i{\isacharbrackright}\ x\isactrlsub {\isadigit{1}}\ {\isacharequal}\ t\isactrlsub {\isadigit{1}}\ {\isasymAND}\ {\isasymdots}\ {\isasymIN}\ a{\isachardoublequote}} \\
wenzelm@26846
    94
  \end{tabular}
wenzelm@26846
    95
  \medskip
wenzelm@26846
    96
wenzelm@26846
    97
  Note that explicit goal addressing may be usually avoided by
wenzelm@26846
    98
  changing the order of subgoals with \mbox{\isa{\isacommand{defer}}} or \mbox{\isa{\isacommand{prefer}}} (see \secref{sec:tactic-commands}).%
wenzelm@26846
    99
\end{isamarkuptext}%
wenzelm@26846
   100
\isamarkuptrue%
wenzelm@26846
   101
%
wenzelm@26846
   102
\isamarkupsection{Simplifier tactics%
wenzelm@26846
   103
}
wenzelm@26846
   104
\isamarkuptrue%
wenzelm@26846
   105
%
wenzelm@26846
   106
\begin{isamarkuptext}%
wenzelm@26846
   107
The main Simplifier tactics \verb|simp_tac| and variants (cf.\
wenzelm@26846
   108
  \cite{isabelle-ref}) are all covered by the \mbox{\isa{simp}} and
wenzelm@26846
   109
  \mbox{\isa{simp{\isacharunderscore}all}} methods (see \secref{sec:simplifier}).  Note that
wenzelm@26846
   110
  there is no individual goal addressing available, simplification
wenzelm@26846
   111
  acts either on the first goal (\mbox{\isa{simp}}) or all goals
wenzelm@26846
   112
  (\mbox{\isa{simp{\isacharunderscore}all}}).
wenzelm@26846
   113
wenzelm@26846
   114
  \medskip
wenzelm@26846
   115
  \begin{tabular}{lll}
wenzelm@26846
   116
    \verb|asm_full_simp_tac|~\isa{{\isachardoublequote}{\isacharat}{\isacharbraceleft}simpset{\isacharbraceright}\ {\isadigit{1}}{\isachardoublequote}} & & \mbox{\isa{simp}} \\
wenzelm@26846
   117
    \verb|ALLGOALS|~(\verb|asm_full_simp_tac|~\isa{{\isachardoublequote}{\isacharat}{\isacharbraceleft}simpset{\isacharbraceright}{\isachardoublequote}}) & & \mbox{\isa{simp{\isacharunderscore}all}} \\[0.5ex]
wenzelm@26846
   118
    \verb|simp_tac|~\isa{{\isachardoublequote}{\isacharat}{\isacharbraceleft}simpset{\isacharbraceright}\ {\isadigit{1}}{\isachardoublequote}} & & \mbox{\isa{simp}}~\isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharparenright}{\isachardoublequote}} \\
wenzelm@26846
   119
    \verb|asm_simp_tac|~\isa{{\isachardoublequote}{\isacharat}{\isacharbraceleft}simpset{\isacharbraceright}\ {\isadigit{1}}{\isachardoublequote}} & & \mbox{\isa{simp}}~\isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}simp{\isacharparenright}{\isachardoublequote}} \\
wenzelm@26846
   120
    \verb|full_simp_tac|~\isa{{\isachardoublequote}{\isacharat}{\isacharbraceleft}simpset{\isacharbraceright}\ {\isadigit{1}}{\isachardoublequote}} & & \mbox{\isa{simp}}~\isa{{\isachardoublequote}{\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}use{\isacharparenright}{\isachardoublequote}} \\
wenzelm@26846
   121
    \verb|asm_lr_simp_tac|~\isa{{\isachardoublequote}{\isacharat}{\isacharbraceleft}simpset{\isacharbraceright}\ {\isadigit{1}}{\isachardoublequote}} & & \mbox{\isa{simp}}~\isa{{\isachardoublequote}{\isacharparenleft}asm{\isacharunderscore}lr{\isacharparenright}{\isachardoublequote}} \\
wenzelm@26846
   122
  \end{tabular}
wenzelm@26846
   123
  \medskip%
wenzelm@26846
   124
\end{isamarkuptext}%
wenzelm@26846
   125
\isamarkuptrue%
wenzelm@26846
   126
%
wenzelm@26846
   127
\isamarkupsection{Classical Reasoner tactics%
wenzelm@26846
   128
}
wenzelm@26846
   129
\isamarkuptrue%
wenzelm@26846
   130
%
wenzelm@26846
   131
\begin{isamarkuptext}%
wenzelm@26846
   132
The Classical Reasoner provides a rather large number of variations
wenzelm@26846
   133
  of automated tactics, such as \verb|blast_tac|, \verb|fast_tac|, \verb|clarify_tac| etc.\ (see \cite{isabelle-ref}).  The corresponding
wenzelm@26846
   134
  Isar methods usually share the same base name, such as \mbox{\isa{blast}}, \mbox{\isa{fast}}, \mbox{\isa{clarify}} etc.\ (see
wenzelm@26846
   135
  \secref{sec:classical}).%
wenzelm@26846
   136
\end{isamarkuptext}%
wenzelm@26846
   137
\isamarkuptrue%
wenzelm@26846
   138
%
wenzelm@26846
   139
\isamarkupsection{Miscellaneous tactics%
wenzelm@26846
   140
}
wenzelm@26846
   141
\isamarkuptrue%
wenzelm@26846
   142
%
wenzelm@26846
   143
\begin{isamarkuptext}%
wenzelm@26846
   144
There are a few additional tactics defined in various theories of
wenzelm@26846
   145
  Isabelle/HOL, some of these also in Isabelle/FOL or Isabelle/ZF.
wenzelm@26846
   146
  The most common ones of these may be ported to Isar as follows.
wenzelm@26846
   147
wenzelm@26846
   148
  \medskip
wenzelm@26846
   149
  \begin{tabular}{lll}
wenzelm@26846
   150
    \verb|stac|~\isa{{\isachardoublequote}a\ {\isadigit{1}}{\isachardoublequote}} & & \isa{{\isachardoublequote}subst\ a{\isachardoublequote}} \\
wenzelm@26846
   151
    \verb|hyp_subst_tac|~\isa{{\isadigit{1}}} & & \isa{hypsubst} \\
wenzelm@26846
   152
    \verb|strip_tac|~\isa{{\isadigit{1}}} & \isa{{\isachardoublequote}{\isasymapprox}{\isachardoublequote}} & \isa{{\isachardoublequote}intro\ strip{\isachardoublequote}} \\
wenzelm@26846
   153
    \verb|split_all_tac|~\isa{{\isadigit{1}}} & & \isa{{\isachardoublequote}simp\ {\isacharparenleft}no{\isacharunderscore}asm{\isacharunderscore}simp{\isacharparenright}\ only{\isacharcolon}\ split{\isacharunderscore}tupled{\isacharunderscore}all{\isachardoublequote}} \\
wenzelm@26846
   154
      & \isa{{\isachardoublequote}{\isasymapprox}{\isachardoublequote}} & \isa{{\isachardoublequote}simp\ only{\isacharcolon}\ split{\isacharunderscore}tupled{\isacharunderscore}all{\isachardoublequote}} \\
wenzelm@26846
   155
      & \isa{{\isachardoublequote}{\isasymlless}{\isachardoublequote}} & \isa{{\isachardoublequote}clarify{\isachardoublequote}} \\
wenzelm@26846
   156
  \end{tabular}%
wenzelm@26846
   157
\end{isamarkuptext}%
wenzelm@26846
   158
\isamarkuptrue%
wenzelm@26846
   159
%
wenzelm@26846
   160
\isamarkupsection{Tacticals%
wenzelm@26846
   161
}
wenzelm@26846
   162
\isamarkuptrue%
wenzelm@26846
   163
%
wenzelm@26846
   164
\begin{isamarkuptext}%
wenzelm@26846
   165
Classic Isabelle provides a huge amount of tacticals for combination
wenzelm@26846
   166
  and modification of existing tactics.  This has been greatly reduced
wenzelm@26846
   167
  in Isar, providing the bare minimum of combinators only: ``\isa{{\isachardoublequote}{\isacharcomma}{\isachardoublequote}}'' (sequential composition), ``\isa{{\isachardoublequote}{\isacharbar}{\isachardoublequote}}'' (alternative
wenzelm@26846
   168
  choices), ``\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}'' (try), ``\isa{{\isachardoublequote}{\isacharplus}{\isachardoublequote}}'' (repeat at least
wenzelm@26846
   169
  once).  These are usually sufficient in practice; if all fails,
wenzelm@26846
   170
  arbitrary ML tactic code may be invoked via the \mbox{\isa{tactic}}
wenzelm@26846
   171
  method (see \secref{sec:tactics}).
wenzelm@26846
   172
wenzelm@26846
   173
  \medskip Common ML tacticals may be expressed directly in Isar as
wenzelm@26846
   174
  follows:
wenzelm@26846
   175
wenzelm@26846
   176
  \medskip
wenzelm@26846
   177
  \begin{tabular}{lll}
wenzelm@26846
   178
    \isa{{\isachardoublequote}tac\isactrlsub {\isadigit{1}}{\isachardoublequote}}~\verb|THEN|~\isa{{\isachardoublequote}tac\isactrlsub {\isadigit{2}}{\isachardoublequote}} & & \isa{{\isachardoublequote}meth\isactrlsub {\isadigit{1}}{\isacharcomma}\ meth\isactrlsub {\isadigit{2}}{\isachardoublequote}} \\
wenzelm@26846
   179
    \isa{{\isachardoublequote}tac\isactrlsub {\isadigit{1}}{\isachardoublequote}}~\verb|ORELSE|~\isa{{\isachardoublequote}tac\isactrlsub {\isadigit{2}}{\isachardoublequote}} & & \isa{{\isachardoublequote}meth\isactrlsub {\isadigit{1}}\ {\isacharbar}\ meth\isactrlsub {\isadigit{2}}{\isachardoublequote}} \\
wenzelm@26846
   180
    \verb|TRY|~\isa{tac} & & \isa{{\isachardoublequote}meth{\isacharquery}{\isachardoublequote}} \\
wenzelm@26846
   181
    \verb|REPEAT1|~\isa{tac} & & \isa{{\isachardoublequote}meth{\isacharplus}{\isachardoublequote}} \\
wenzelm@26846
   182
    \verb|REPEAT|~\isa{tac} & & \isa{{\isachardoublequote}{\isacharparenleft}meth{\isacharplus}{\isacharparenright}{\isacharquery}{\isachardoublequote}} \\
wenzelm@26846
   183
    \verb|EVERY|~\isa{{\isachardoublequote}{\isacharbrackleft}tac\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}{\isachardoublequote}} & & \isa{{\isachardoublequote}meth\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isachardoublequote}} \\
wenzelm@26846
   184
    \verb|FIRST|~\isa{{\isachardoublequote}{\isacharbrackleft}tac\isactrlsub {\isadigit{1}}{\isacharcomma}\ {\isasymdots}{\isacharbrackright}{\isachardoublequote}} & & \isa{{\isachardoublequote}meth\isactrlsub {\isadigit{1}}\ {\isacharbar}\ {\isasymdots}{\isachardoublequote}} \\
wenzelm@26846
   185
  \end{tabular}
wenzelm@26846
   186
  \medskip
wenzelm@26846
   187
wenzelm@26846
   188
  \medskip \verb|CHANGED| (see \cite{isabelle-ref}) is usually not
wenzelm@26846
   189
  required in Isar, since most basic proof methods already fail unless
wenzelm@26846
   190
  there is an actual change in the goal state.  Nevertheless, ``\isa{{\isachardoublequote}{\isacharquery}{\isachardoublequote}}''  (try) may be used to accept \emph{unchanged} results as
wenzelm@26846
   191
  well.
wenzelm@26846
   192
wenzelm@26846
   193
  \medskip \verb|ALLGOALS|, \verb|SOMEGOAL| etc.\ (see
wenzelm@26846
   194
  \cite{isabelle-ref}) are not available in Isar, since there is no
wenzelm@26846
   195
  direct goal addressing.  Nevertheless, some basic methods address
wenzelm@26846
   196
  all goals internally, notably \mbox{\isa{simp{\isacharunderscore}all}} (see
wenzelm@26846
   197
  \secref{sec:simplifier}).  Also note that \verb|ALLGOALS| can be
wenzelm@26846
   198
  often replaced by ``\isa{{\isachardoublequote}{\isacharplus}{\isachardoublequote}}'' (repeat at least once), although
wenzelm@26846
   199
  this usually has a different operational behavior, such as solving
wenzelm@26846
   200
  goals in a different order.
wenzelm@26846
   201
wenzelm@26846
   202
  \medskip Iterated resolution, such as \verb|REPEAT (FIRSTGOAL|\isasep\isanewline%
wenzelm@26846
   203
\verb|  (resolve_tac \<dots>))|, is usually better expressed using the \mbox{\isa{intro}} and \mbox{\isa{elim}} methods of Isar (see
wenzelm@26846
   204
  \secref{sec:classical}).%
wenzelm@26846
   205
\end{isamarkuptext}%
wenzelm@26846
   206
\isamarkuptrue%
wenzelm@26846
   207
%
wenzelm@26846
   208
\isadelimtheory
wenzelm@26846
   209
%
wenzelm@26846
   210
\endisadelimtheory
wenzelm@26846
   211
%
wenzelm@26846
   212
\isatagtheory
wenzelm@26846
   213
\isacommand{end}\isamarkupfalse%
wenzelm@26846
   214
%
wenzelm@26846
   215
\endisatagtheory
wenzelm@26846
   216
{\isafoldtheory}%
wenzelm@26846
   217
%
wenzelm@26846
   218
\isadelimtheory
wenzelm@26846
   219
%
wenzelm@26846
   220
\endisadelimtheory
wenzelm@26846
   221
\isanewline
wenzelm@26846
   222
\end{isabellebody}%
wenzelm@26846
   223
%%% Local Variables:
wenzelm@26846
   224
%%% mode: latex
wenzelm@26846
   225
%%% TeX-master: "root"
wenzelm@26846
   226
%%% End: