doc-src/IsarRef/conversion.tex
author wenzelm
Fri, 08 Mar 2002 15:53:15 +0100
changeset 13048 8b2eb3b78cc3
parent 13042 d8a345d9e067
child 13625 ca86e84ce200
permissions -rw-r--r--
tuned;
wenzelm@9607
     1
wenzelm@13048
     2
\chapter{Isabelle/Isar conversion guide}\label{ap:conv}
wenzelm@9607
     3
wenzelm@10111
     4
Subsequently, we give a few practical hints on working in a mixed environment
wenzelm@10153
     5
of old Isabelle ML proof scripts and new Isabelle/Isar theories.  There are
wenzelm@10111
     6
basically three ways to cope with this issue.
wenzelm@10111
     7
\begin{enumerate}
wenzelm@10111
     8
\item Do not convert old sources at all, but communicate directly at the level
wenzelm@10160
     9
  of \emph{internal} theory and theorem values.
wenzelm@10153
    10
\item Port old-style theory files to new-style ones (very easy), and ML proof
wenzelm@10153
    11
  scripts to Isar tactic-emulation scripts (quite easy).
wenzelm@10160
    12
\item Actually redo ML proof scripts as human-readable Isar proof texts
wenzelm@10111
    13
  (probably hard, depending who wrote the original scripts).
wenzelm@10111
    14
\end{enumerate}
wenzelm@10111
    15
wenzelm@10111
    16
wenzelm@9607
    17
\section{No conversion}
wenzelm@9607
    18
wenzelm@10153
    19
Internally, Isabelle is able to handle both old and new-style theories at the
wenzelm@10153
    20
same time; the theory loader automatically detects the input format.  In any
wenzelm@10153
    21
case, the results are certain internal ML values of type \texttt{theory} and
wenzelm@10153
    22
\texttt{thm}.  These may be accessed from either classic Isabelle or
wenzelm@10153
    23
Isabelle/Isar, provided that some minimal precautions are observed.
wenzelm@10153
    24
wenzelm@10111
    25
wenzelm@10111
    26
\subsection{Referring to theorem and theory values}
wenzelm@10111
    27
wenzelm@10111
    28
\begin{ttbox}
wenzelm@10111
    29
thm         : xstring -> thm
wenzelm@10111
    30
thms        : xstring -> thm list
wenzelm@10111
    31
the_context : unit -> theory
wenzelm@10111
    32
theory      : string -> theory
wenzelm@10111
    33
\end{ttbox}
wenzelm@10111
    34
wenzelm@10153
    35
These functions provide general means to refer to logical objects from ML.
wenzelm@10153
    36
Old-style theories used to emit many ML bindings of theorems and theories, but
wenzelm@10153
    37
this is no longer done in new-style Isabelle/Isar theories.
wenzelm@10111
    38
wenzelm@10111
    39
\begin{descr}
wenzelm@10111
    40
\item [$\mathtt{thm}~name$ and $\mathtt{thms}~name$] retrieve theorems stored
wenzelm@10111
    41
  in the current theory context, including any ancestor node.
wenzelm@13048
    42
wenzelm@10111
    43
  The convention of old-style theories was to bind any theorem as an ML value
wenzelm@10153
    44
  as well.  New-style theories no longer do this, so ML code may require
wenzelm@10111
    45
  \texttt{thm~"foo"} rather than just \texttt{foo}.
wenzelm@13048
    46
wenzelm@10111
    47
\item [$\mathtt{the_context()}$] refers to the current theory context.
wenzelm@13048
    48
wenzelm@10111
    49
  Old-style theories often use the ML binding \texttt{thy}, which is
wenzelm@10153
    50
  dynamically created by the ML code generated from old theory source.  This
wenzelm@10160
    51
  is no longer the recommended way in any case!  Function \texttt{the_context}
wenzelm@10160
    52
  should be used for old scripts as well.
wenzelm@13048
    53
wenzelm@10111
    54
\item [$\mathtt{theory}~name$] retrieves the named theory from the global
wenzelm@10153
    55
  theory-loader database.
wenzelm@13048
    56
wenzelm@10153
    57
  The ML code generated from old-style theories would include an ML binding
wenzelm@10111
    58
  $name\mathtt{.thy}$ as part of an ML structure.
wenzelm@10111
    59
\end{descr}
wenzelm@10111
    60
wenzelm@10111
    61
wenzelm@10153
    62
\subsection{Storing theorem values}
wenzelm@10111
    63
wenzelm@10111
    64
\begin{ttbox}
wenzelm@10111
    65
qed        : string -> unit
wenzelm@10111
    66
bind_thm   : string * thm -> unit
wenzelm@10111
    67
bind_thms  : string * thm list -> unit
wenzelm@10111
    68
\end{ttbox}
wenzelm@10111
    69
wenzelm@10160
    70
ML proof scripts have to be well-behaved by storing theorems properly within
wenzelm@10111
    71
the current theory context, in order to enable new-style theories to retrieve
wenzelm@13041
    72
these later.
wenzelm@10111
    73
wenzelm@10111
    74
\begin{descr}
wenzelm@13048
    75
wenzelm@10111
    76
\item [$\mathtt{qed}~name$] is the canonical way to conclude a proof script in
wenzelm@10111
    77
  ML.  This already manages entry in the theorem database of the current
wenzelm@10111
    78
  theory context.
wenzelm@13048
    79
wenzelm@10111
    80
\item [$\mathtt{bind_thm}~(name, thm)$ and $\mathtt{bind_thms}~(name, thms)$]
wenzelm@10160
    81
  store theorems that have been produced in ML in an ad-hoc manner.
wenzelm@13041
    82
wenzelm@10111
    83
\end{descr}
wenzelm@10111
    84
wenzelm@10153
    85
Note that the original ``LCF-system'' approach of binding theorem values on
wenzelm@10160
    86
the ML toplevel only has long been given up in Isabelle!  Despite of this, old
wenzelm@10160
    87
legacy proof scripts occasionally contain code such as \texttt{val foo =
wenzelm@10160
    88
  result();} which is ill-behaved in several respects.  Apart from preventing
wenzelm@10160
    89
access from Isar theories, it also omits the result from the WWW presentation,
wenzelm@10160
    90
for example.
wenzelm@10111
    91
wenzelm@10153
    92
wenzelm@10153
    93
\subsection{ML declarations in Isar}
wenzelm@10111
    94
wenzelm@10111
    95
\begin{matharray}{rcl}
wenzelm@10111
    96
  \isarcmd{ML} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@10153
    97
  \isarcmd{ML_setup} & : & \isartrans{theory}{theory} \\
wenzelm@10111
    98
\end{matharray}
wenzelm@10111
    99
wenzelm@10153
   100
Isabelle/Isar theories may contain ML declarations as well.  For example, an
wenzelm@10153
   101
old-style theorem binding may be mimicked as follows.
wenzelm@10111
   102
\[
wenzelm@10111
   103
\isarkeyword{ML}~\{*~\mbox{\texttt{val foo = thm "foo"}}~*\}
wenzelm@10111
   104
\]
wenzelm@10160
   105
Note that this command cannot be undone, so invalid theorem bindings in ML may
wenzelm@10160
   106
persist.  Also note that the current theory may not be modified; use
wenzelm@10153
   107
$\isarkeyword{ML_setup}$ for declarations that act on the current context.
wenzelm@10111
   108
wenzelm@9607
   109
wenzelm@10153
   110
\section{Porting theories and proof scripts}\label{sec:port-scripts}
wenzelm@9607
   111
wenzelm@10111
   112
Porting legacy theory and ML files to proper Isabelle/Isar theories has
wenzelm@10111
   113
several advantages.  For example, the Proof~General user interface
wenzelm@10153
   114
\cite{proofgeneral} for Isabelle/Isar is more robust and more comfortable to
wenzelm@10153
   115
use than the version for classic Isabelle.  This is due to the fact that the
wenzelm@10153
   116
generic ML toplevel has been replaced by a separate Isar interaction loop,
wenzelm@10153
   117
with full control over input synchronization and error conditions.
wenzelm@10111
   118
wenzelm@10153
   119
Furthermore, the Isabelle document preparation system (see also
wenzelm@10153
   120
\cite{isabelle-sys}) only works properly with new-style theories.  Output of
wenzelm@10153
   121
old-style sources is at the level of individual characters (and symbols),
wenzelm@10153
   122
without proper document markup as in Isabelle/Isar theories.
wenzelm@10111
   123
wenzelm@10111
   124
wenzelm@10153
   125
\subsection{Theories}
wenzelm@10111
   126
wenzelm@10153
   127
Basically, the Isabelle/Isar theory syntax is a proper superset of the classic
wenzelm@10153
   128
one.  Only a few quirks and legacy problems have been eliminated, resulting in
wenzelm@10153
   129
simpler rules and less special cases.  The main changes of theory syntax are
wenzelm@10153
   130
as follows.
wenzelm@10111
   131
wenzelm@10111
   132
\begin{itemize}
wenzelm@10153
   133
\item Quoted strings may contain arbitrary white space, and span several lines
wenzelm@10153
   134
  without requiring \verb,\,\,\dots\verb,\, escapes.
wenzelm@10153
   135
\item Names may always be quoted.
wenzelm@13048
   136
wenzelm@10153
   137
  The old syntax would occasionally demand plain identifiers vs.\ quoted
wenzelm@10153
   138
  strings to accommodate certain syntactic features.
wenzelm@10111
   139
\item Types and terms have to be \emph{atomic} as far as the theory syntax is
wenzelm@10153
   140
  concerned; this typically requires quoting of input strings, e.g.\ ``$x +
wenzelm@10153
   141
  y$''.
wenzelm@13048
   142
wenzelm@10111
   143
  The old theory syntax used to fake part of the syntax of types in order to
wenzelm@10153
   144
  require less quoting in common cases; this was hard to predict, though.  On
wenzelm@10153
   145
  the other hand, Isar does not require quotes for simple terms, such as plain
wenzelm@10153
   146
  identifiers $x$, numerals $1$, or symbols $\forall$ (input as
wenzelm@10153
   147
  \verb,\<forall>,).
wenzelm@10153
   148
\item Theorem declarations require an explicit colon to separate the name from
wenzelm@10160
   149
  the statement (the name is usually optional).  Cf.\ the syntax of $\DEFS$ in
wenzelm@10160
   150
  \S\ref{sec:consts}, or $\THEOREMNAME$ in \S\ref{sec:axms-thms}.
wenzelm@10111
   151
\end{itemize}
wenzelm@10111
   152
wenzelm@10160
   153
Note that Isabelle/Isar error messages are usually quite explicit about the
wenzelm@10160
   154
problem at hand.  So in cases of doubt, input syntax may be just as well tried
wenzelm@10160
   155
out interactively.
wenzelm@10111
   156
wenzelm@10111
   157
wenzelm@10153
   158
\subsection{Goal statements}\label{sec:conv-goal}
wenzelm@10111
   159
wenzelm@10239
   160
\subsubsection{Simple goals}
wenzelm@10239
   161
wenzelm@10153
   162
In ML the canonical a goal statement together with a complete proof script is
wenzelm@10153
   163
as follows:
wenzelm@10111
   164
\begin{ttbox}
wenzelm@10153
   165
 Goal "\(\phi\)";
wenzelm@10153
   166
 by \(tac@1\);
wenzelm@10153
   167
   \(\vdots\)
wenzelm@10153
   168
 qed "\(name\)";
wenzelm@10111
   169
\end{ttbox}
wenzelm@10153
   170
This form may be turned into an Isar tactic-emulation script like this:
wenzelm@10111
   171
\begin{matharray}{l}
wenzelm@10239
   172
  \LEMMA{name}{\texttt"{\phi}\texttt"} \\
wenzelm@10223
   173
  \quad \APPLY{meth@1} \\
wenzelm@10153
   174
  \qquad \vdots \\
wenzelm@10223
   175
  \quad \DONE \\
wenzelm@10111
   176
\end{matharray}
wenzelm@13013
   177
Note that the main statement may be $\THEOREMNAME$ or $\COROLLARYNAME$ as
wenzelm@13013
   178
well.  See \S\ref{sec:conv-tac} for further details on how to convert actual
wenzelm@13013
   179
tactic expressions into proof methods.
wenzelm@10111
   180
wenzelm@10111
   181
\medskip Classic Isabelle provides many variant forms of goal commands, see
wenzelm@10239
   182
also \cite{isabelle-ref} for further details.  The second most common one is
wenzelm@10111
   183
\texttt{Goalw}, which expands definitions before commencing the actual proof
wenzelm@10111
   184
script.
wenzelm@10111
   185
\begin{ttbox}
wenzelm@10153
   186
 Goalw [\(def@1\), \(\dots\)] "\(\phi\)";
wenzelm@10111
   187
\end{ttbox}
wenzelm@10239
   188
This may be replaced by using the $unfold$ proof method explicitly.
wenzelm@10111
   189
\begin{matharray}{l}
wenzelm@10239
   190
\LEMMA{name}{\texttt"{\phi}\texttt"} \\
wenzelm@13042
   191
\quad \APPLY{(unfold~def@1~\dots)} \\
wenzelm@10111
   192
\end{matharray}
wenzelm@10111
   193
wenzelm@10111
   194
wenzelm@10239
   195
\subsubsection{Deriving rules}
wenzelm@10239
   196
wenzelm@10239
   197
Deriving non-atomic meta-level propositions requires special precautions in
wenzelm@10239
   198
classic Isabelle: the primitive \texttt{goal} command decomposes a statement
wenzelm@10239
   199
into the atomic conclusion and a list of assumptions, which are exhibited as
wenzelm@10239
   200
ML values of type \texttt{thm}.  After the proof is finished, these premises
wenzelm@13013
   201
are discharged again, resulting in the original rule statement.  The ``long
wenzelm@13013
   202
format'' of Isabelle/Isar goal statements admits to emulate this technique
wenzelm@13041
   203
nicely.  The general ML goal statement for derived rules looks like this:
wenzelm@10239
   204
\begin{ttbox}
wenzelm@10239
   205
 val [\(prem@1\), \dots] = goal "\(\phi@1 \Imp \dots \Imp \psi\)";
wenzelm@10239
   206
 by \(tac@1\);
wenzelm@10239
   207
   \(\vdots\)
wenzelm@13013
   208
 qed "\(a\)"
wenzelm@10239
   209
\end{ttbox}
wenzelm@13013
   210
This form may be turned into a tactic-emulation script as follows:
wenzelm@10239
   211
\begin{matharray}{l}
wenzelm@13013
   212
  \LEMMA{a}{} \\
wenzelm@13013
   213
  \quad \ASSUMES{prem@1}{\texttt"\phi@1\texttt"}~\AND~\dots \\
wenzelm@13013
   214
  \quad \SHOWS{}{\texttt"{\psi}\texttt"} \\
wenzelm@10239
   215
  \qquad \APPLY{meth@1} \\
wenzelm@10239
   216
  \qquad\quad \vdots \\
wenzelm@10239
   217
  \qquad \DONE \\
wenzelm@10239
   218
\end{matharray}
wenzelm@10239
   219
wenzelm@10239
   220
\medskip In practice, actual rules are often rather direct consequences of
wenzelm@10239
   221
corresponding atomic statements, typically stemming from the definition of a
wenzelm@10239
   222
new concept.  In that case, the general scheme for deriving rules may be
wenzelm@11498
   223
greatly simplified, using one of the standard automated proof tools, such as
wenzelm@13041
   224
$simp$, $blast$, or $auto$.  This could work as follows:
wenzelm@10239
   225
\begin{matharray}{l}
wenzelm@10239
   226
  \LEMMA{}{\texttt"{\phi@1 \Imp \dots \Imp \psi}\texttt"} \\
wenzelm@13042
   227
  \quad \BYY{(unfold~defs)}{blast} \\
wenzelm@10239
   228
\end{matharray}
wenzelm@10239
   229
Note that classic Isabelle would support this form only in the special case
wenzelm@10239
   230
where $\phi@1$, \dots are atomic statements (when using the standard
wenzelm@10239
   231
\texttt{Goal} command).  Otherwise the special treatment of rules would be
wenzelm@10239
   232
applied, disturbing this simple setup.
wenzelm@10239
   233
wenzelm@10239
   234
\medskip Occasionally, derived rules would be established by first proving an
wenzelm@10239
   235
appropriate atomic statement (using $\forall$ and $\longrightarrow$ of the
wenzelm@10239
   236
object-logic), and putting the final result into ``rule format''.  In classic
wenzelm@10239
   237
Isabelle this would usually proceed as follows:
wenzelm@10239
   238
\begin{ttbox}
wenzelm@10239
   239
 Goal "\(\phi\)";
wenzelm@10239
   240
 by \(tac@1\);
wenzelm@10239
   241
   \(\vdots\)
wenzelm@10239
   242
 qed_spec_mp "\(name\)";
wenzelm@10239
   243
\end{ttbox}
wenzelm@10239
   244
The operation performed by \texttt{qed_spec_mp} is also performed by the Isar
wenzelm@12618
   245
attribute ``$rule_format$'', see also \S\ref{sec:object-logic}.  Thus the
wenzelm@10239
   246
corresponding Isar text may look like this:
wenzelm@10239
   247
\begin{matharray}{l}
wenzelm@10239
   248
  \LEMMA{name~[rule_format]}{\texttt"{\phi}\texttt"} \\
wenzelm@10239
   249
  \quad \APPLY{meth@1} \\
wenzelm@10239
   250
  \qquad \vdots \\
wenzelm@10239
   251
  \quad \DONE \\
wenzelm@10239
   252
\end{matharray}
wenzelm@10239
   253
Note plain ``$rule_format$'' actually performs a slightly different operation:
wenzelm@10239
   254
it fully replaces object-level implication and universal quantification
wenzelm@10239
   255
throughout the whole result statement.  This is the right thing in most cases.
wenzelm@10239
   256
For historical reasons, \texttt{qed_spec_mp} would only operate on the
wenzelm@10239
   257
conclusion; one may get this exact behavior by using
wenzelm@10239
   258
``$rule_format~(no_asm)$'' instead.
wenzelm@10111
   259
wenzelm@13013
   260
\medskip Actually ``$rule_format$'' is a bit unpleasant to work with, since
wenzelm@13013
   261
the final result statement is not shown in the text.  An alternative is to
wenzelm@13013
   262
state the resulting rule in the intended form in the first place, and have the
wenzelm@13013
   263
initial refinement step turn it into internal object-logic form using the
wenzelm@13013
   264
$atomize$ method indicated below.  The remaining script is unchanged.
wenzelm@13013
   265
wenzelm@13013
   266
\begin{matharray}{l}
wenzelm@13013
   267
  \LEMMA{name}{\texttt"{\All{\vec x}\vec\phi \Imp \psi}\texttt"} \\
wenzelm@13042
   268
  \quad \APPLY{(atomize~(full))} \\
wenzelm@13013
   269
  \quad \APPLY{meth@1} \\
wenzelm@13013
   270
  \qquad \vdots \\
wenzelm@13013
   271
  \quad \DONE \\
wenzelm@13013
   272
\end{matharray}
wenzelm@13013
   273
wenzelm@13041
   274
In many situations the $atomize$ step above is actually unnecessary,
wenzelm@13041
   275
especially if the subsequent script mainly consists of automated tools.
wenzelm@13041
   276
wenzelm@13013
   277
wenzelm@10153
   278
\subsection{Tactics}\label{sec:conv-tac}
wenzelm@10111
   279
wenzelm@10153
   280
Isar Proof methods closely resemble traditional tactics, when used in
wenzelm@10223
   281
unstructured sequences of $\APPLYNAME$ commands (cf.\ \S\ref{sec:conv-goal}).
wenzelm@10223
   282
Isabelle/Isar provides emulations for all major ML tactics of classic Isabelle
wenzelm@10223
   283
--- mostly for the sake of easy porting of existing developments, as actual
wenzelm@10223
   284
Isar proof texts would demand much less diversity of proof methods.
wenzelm@10111
   285
wenzelm@10153
   286
Unlike tactic expressions in ML, Isar proof methods provide proper concrete
wenzelm@10153
   287
syntax for additional arguments, options, modifiers etc.  Thus a typical
wenzelm@10153
   288
method text is usually more concise than the corresponding ML tactic.
wenzelm@10153
   289
Furthermore, the Isar versions of classic Isabelle tactics often cover several
wenzelm@10160
   290
variant forms by a single method with separate options to tune the behavior.
wenzelm@10160
   291
For example, method $simp$ replaces all of \texttt{simp_tac}~/
wenzelm@10160
   292
\texttt{asm_simp_tac}~/ \texttt{full_simp_tac}~/ \texttt{asm_full_simp_tac},
wenzelm@10153
   293
there is also concrete syntax for augmenting the Simplifier context (the
wenzelm@13041
   294
current ``simpset'') in a convenient way.
wenzelm@10111
   295
wenzelm@10111
   296
wenzelm@10153
   297
\subsubsection{Resolution tactics}
wenzelm@9798
   298
wenzelm@10153
   299
Classic Isabelle provides several variant forms of tactics for single-step
wenzelm@10160
   300
rule applications (based on higher-order resolution).  The space of resolution
wenzelm@10153
   301
tactics has the following main dimensions.
wenzelm@10153
   302
\begin{enumerate}
wenzelm@13048
   303
\item The ``mode'' of resolution: intro, elim, destruct, or forward (e.g.\
wenzelm@10153
   304
  \texttt{resolve_tac}, \texttt{eresolve_tac}, \texttt{dresolve_tac},
wenzelm@10153
   305
  \texttt{forward_tac}).
wenzelm@13048
   306
\item Optional explicit instantiation (e.g.\ \texttt{resolve_tac} vs.\
wenzelm@10153
   307
  \texttt{res_inst_tac}).
wenzelm@13048
   308
\item Abbreviations for singleton arguments (e.g.\ \texttt{resolve_tac} vs.\
wenzelm@10153
   309
  \texttt{rtac}).
wenzelm@10153
   310
\end{enumerate}
wenzelm@10153
   311
wenzelm@10153
   312
Basically, the set of Isar tactic emulations $rule_tac$, $erule_tac$,
wenzelm@10153
   313
$drule_tac$, $frule_tac$ (see \S\ref{sec:tactics}) would be sufficient to
wenzelm@10153
   314
cover the four modes, either with or without instantiation, and either with
wenzelm@10153
   315
single or multiple arguments.  Although it is more convenient in most cases to
wenzelm@10153
   316
use the plain $rule$ method (see \S\ref{sec:pure-meth-att}), or any of its
wenzelm@10153
   317
``improper'' variants $erule$, $drule$, $frule$ (see
wenzelm@12618
   318
\S\ref{sec:misc-meth-att}).  Note that explicit goal addressing is only
wenzelm@10160
   319
supported by the actual $rule_tac$ version.
wenzelm@10153
   320
wenzelm@10160
   321
With this in mind, plain resolution tactics may be ported as follows.
wenzelm@10153
   322
\begin{matharray}{lll}
wenzelm@9798
   323
  \texttt{rtac}~a~1 & & rule~a \\
wenzelm@10153
   324
  \texttt{resolve_tac}~[a@1, \dots]~1 & & rule~a@1~\dots \\
wenzelm@10153
   325
  \texttt{res_inst_tac}~[(x@1, t@1), \dots]~a~1 & &
wenzelm@10153
   326
  rule_tac~x@1 = t@1~and~\dots~in~a \\[0.5ex]
wenzelm@10153
   327
  \texttt{rtac}~a~i & & rule_tac~[i]~a \\
wenzelm@10153
   328
  \texttt{resolve_tac}~[a@1, \dots]~i & & rule_tac~[i]~a@1~\dots \\
wenzelm@10153
   329
  \texttt{res_inst_tac}~[(x@1, t@1), \dots]~a~i & &
wenzelm@10153
   330
  rule_tac~[i]~x@1 = t@1~and~\dots~in~a \\
wenzelm@9798
   331
\end{matharray}
wenzelm@9798
   332
wenzelm@10153
   333
Note that explicit goal addressing may be usually avoided by changing the
wenzelm@10153
   334
order of subgoals with $\isarkeyword{defer}$ or $\isarkeyword{prefer}$ (see
wenzelm@10153
   335
\S\ref{sec:tactic-commands}).
wenzelm@9798
   336
wenzelm@10740
   337
\medskip Some further (less frequently used) combinations of basic resolution
wenzelm@10740
   338
tactics may be expressed as follows.
wenzelm@10740
   339
\begin{matharray}{lll}
wenzelm@10740
   340
  \texttt{ares_tac}~[a@1, \dots]~1 & & assumption~|~rule~a@1~\dots \\
wenzelm@10740
   341
  \texttt{eatac}~a~n~1 & & erule~(n)~a \\
wenzelm@10740
   342
  \texttt{datac}~a~n~1 & & drule~(n)~a \\
wenzelm@10740
   343
  \texttt{fatac}~a~n~1 & & frule~(n)~a \\
wenzelm@10740
   344
\end{matharray}
wenzelm@10740
   345
wenzelm@9607
   346
wenzelm@10153
   347
\subsubsection{Simplifier tactics}
wenzelm@9607
   348
wenzelm@10153
   349
The main Simplifier tactics \texttt{Simp_tac}, \texttt{simp_tac} and variants
wenzelm@10153
   350
(cf.\ \cite{isabelle-ref}) are all covered by the $simp$ and $simp_all$
wenzelm@13048
   351
methods (see \S\ref{sec:simplifier}).  Note that there is no individual goal
wenzelm@13048
   352
addressing available, simplification acts either on the first goal ($simp$) or
wenzelm@13048
   353
all goals ($simp_all$).
wenzelm@9607
   354
wenzelm@10153
   355
\begin{matharray}{lll}
wenzelm@10153
   356
  \texttt{Asm_full_simp_tac 1} & & simp \\
wenzelm@10153
   357
  \texttt{ALLGOALS Asm_full_simp_tac} & & simp_all \\[0.5ex]
wenzelm@10153
   358
  \texttt{Simp_tac 1} & & simp~(no_asm) \\
wenzelm@10153
   359
  \texttt{Asm_simp_tac 1} & & simp~(no_asm_simp) \\
wenzelm@10153
   360
  \texttt{Full_simp_tac 1} & & simp~(no_asm_use) \\
wenzelm@10153
   361
\end{matharray}
wenzelm@10153
   362
wenzelm@10153
   363
Isar also provides separate method modifier syntax for augmenting the
wenzelm@13048
   364
Simplifier context (see \S\ref{sec:simplifier}), which is known as the
wenzelm@13048
   365
``simpset'' in ML.  A typical ML expression with simpset changes looks like
wenzelm@13048
   366
this:
wenzelm@10153
   367
\begin{ttbox}
wenzelm@10153
   368
asm_full_simp_tac (simpset () addsimps [\(a@1\), \(\dots\)] delsimps [\(b@1\), \(\dots\)]) 1
wenzelm@10153
   369
\end{ttbox}
wenzelm@10153
   370
The corresponding Isar text is as follows:
wenzelm@10153
   371
\[
wenzelm@10153
   372
simp~add:~a@1~\dots~del:~b@1~\dots
wenzelm@10153
   373
\]
wenzelm@10153
   374
Global declarations of Simplifier rules (e.g.\ \texttt{Addsimps}) are covered
wenzelm@10153
   375
by application of attributes, see \S\ref{sec:conv-decls} for more information.
wenzelm@10153
   376
wenzelm@10153
   377
wenzelm@10153
   378
\subsubsection{Classical Reasoner tactics}
wenzelm@10153
   379
wenzelm@10153
   380
The Classical Reasoner provides a rather large number of variations of
wenzelm@10153
   381
automated tactics, such as \texttt{Blast_tac}, \texttt{Fast_tac},
wenzelm@10153
   382
\texttt{Clarify_tac} etc.\ (see \cite{isabelle-ref}).  The corresponding Isar
wenzelm@10160
   383
methods usually share the same base name, such as $blast$, $fast$, $clarify$
wenzelm@13048
   384
etc.\ (see \S\ref{sec:classical}).
wenzelm@10153
   385
wenzelm@10153
   386
Similar to the Simplifier, there is separate method modifier syntax for
wenzelm@10153
   387
augmenting the Classical Reasoner context, which is known as the ``claset'' in
wenzelm@10153
   388
ML.  A typical ML expression with claset changes looks like this:
wenzelm@10153
   389
\begin{ttbox}
wenzelm@10153
   390
blast_tac (claset () addIs [\(a@1\), \(\dots\)] addSEs [\(b@1\), \(\dots\)]) 1
wenzelm@10153
   391
\end{ttbox}
wenzelm@10153
   392
The corresponding Isar text is as follows:
wenzelm@10153
   393
\[
wenzelm@10153
   394
blast~intro:~a@1~\dots~elim!:~b@1~\dots
wenzelm@10153
   395
\]
wenzelm@10153
   396
Global declarations of Classical Reasoner rules (e.g.\ \texttt{AddIs}) are
wenzelm@10153
   397
covered by application of attributes, see \S\ref{sec:conv-decls} for more
wenzelm@10153
   398
information.
wenzelm@10153
   399
wenzelm@10153
   400
wenzelm@10153
   401
\subsubsection{Miscellaneous tactics}
wenzelm@10153
   402
wenzelm@10153
   403
There are a few additional tactics defined in various theories of
wenzelm@10153
   404
Isabelle/HOL, some of these also in Isabelle/FOL or Isabelle/ZF.  The most
wenzelm@10153
   405
common ones of these may be ported to Isar as follows.
wenzelm@10153
   406
wenzelm@10153
   407
\begin{matharray}{lll}
wenzelm@10153
   408
  \texttt{stac}~a~1 & & subst~a \\
wenzelm@10153
   409
  \texttt{hyp_subst_tac}~1 & & hypsubst \\
wenzelm@10153
   410
  \texttt{strip_tac}~1 & \approx & intro~strip \\
wenzelm@10153
   411
  \texttt{split_all_tac}~1 & & simp~(no_asm_simp)~only:~split_tupled_all \\
wenzelm@10153
   412
                         & \approx & simp~only:~split_tupled_all \\
wenzelm@10153
   413
                         & \ll & clarify \\
wenzelm@10153
   414
\end{matharray}
wenzelm@10153
   415
wenzelm@10153
   416
wenzelm@10153
   417
\subsubsection{Tacticals}
wenzelm@10153
   418
wenzelm@10153
   419
Classic Isabelle provides a huge amount of tacticals for combination and
wenzelm@10153
   420
modification of existing tactics.  This has been greatly reduced in Isar,
wenzelm@10153
   421
providing the bare minimum of combinators only: ``$,$'' (sequential
wenzelm@10153
   422
composition), ``$|$'' (alternative choices), ``$?$'' (try), ``$+$'' (repeat at
wenzelm@10160
   423
least once).  These are usually sufficient in practice; if all fails,
wenzelm@10160
   424
arbitrary ML tactic code may be invoked via the $tactic$ method (see
wenzelm@10153
   425
\S\ref{sec:tactics}).
wenzelm@10153
   426
wenzelm@10153
   427
\medskip Common ML tacticals may be expressed directly in Isar as follows:
wenzelm@10153
   428
\begin{matharray}{lll}
wenzelm@10153
   429
tac@1~\texttt{THEN}~tac@2 & & meth@1, meth@2 \\
wenzelm@10153
   430
tac@1~\texttt{ORELSE}~tac@2 & & meth@1~|~meth@2 \\
wenzelm@10153
   431
\texttt{TRY}~tac & & meth? \\
wenzelm@10153
   432
\texttt{REPEAT1}~tac & & meth+ \\
wenzelm@10153
   433
\texttt{REPEAT}~tac & & (meth+)? \\
wenzelm@10153
   434
\texttt{EVERY}~[tac@1, \dots] & & meth@1, \dots \\
wenzelm@10153
   435
\texttt{FIRST}~[tac@1, \dots] & & meth@1~|~\dots \\
wenzelm@10153
   436
\end{matharray}
wenzelm@10153
   437
wenzelm@10153
   438
\medskip \texttt{CHANGED} (see \cite{isabelle-ref}) is usually not required in
wenzelm@10153
   439
Isar, since most basic proof methods already fail unless there is an actual
wenzelm@10153
   440
change in the goal state.  Nevertheless, ``$?$'' (try) may be used to accept
wenzelm@10153
   441
\emph{unchanged} results as well.
wenzelm@10153
   442
wenzelm@10153
   443
\medskip \texttt{ALLGOALS}, \texttt{SOMEGOAL} etc.\ (see \cite{isabelle-ref})
wenzelm@10160
   444
are not available in Isar, since there is no direct goal addressing.
wenzelm@10160
   445
Nevertheless, some basic methods address all goals internally, notably
wenzelm@13048
   446
$simp_all$ (see \S\ref{sec:simplifier}).  Also note that \texttt{ALLGOALS} may
wenzelm@13048
   447
be often replaced by ``$+$'' (repeat at least once), although this usually has
wenzelm@13048
   448
a different operational behavior, such as solving goals in a different order.
wenzelm@10153
   449
wenzelm@10153
   450
\medskip Iterated resolution, such as
wenzelm@10153
   451
\texttt{REPEAT~(FIRSTGOAL~(resolve_tac~$\dots$))}, is usually better expressed
wenzelm@13048
   452
using the $intro$ and $elim$ methods of Isar (see \S\ref{sec:classical}).
wenzelm@10153
   453
wenzelm@10153
   454
wenzelm@10153
   455
\subsection{Declarations and ad-hoc operations}\label{sec:conv-decls}
wenzelm@10153
   456
wenzelm@10153
   457
Apart from proof commands and tactic expressions, almost all of the remaining
wenzelm@10153
   458
ML code occurring in legacy proof scripts are either global context
wenzelm@10153
   459
declarations (such as \texttt{Addsimps}) or ad-hoc operations on theorems
wenzelm@10153
   460
(such as \texttt{RS}).  In Isar both of these are covered by theorem
wenzelm@10153
   461
expressions with \emph{attributes}.
wenzelm@10153
   462
wenzelm@10153
   463
\medskip Theorem operations may be attached as attributes in the very place
wenzelm@10153
   464
where theorems are referenced, say within a method argument.  The subsequent
wenzelm@13041
   465
ML combinators may be expressed directly in Isar as follows.
wenzelm@10153
   466
\begin{matharray}{lll}
wenzelm@10153
   467
  thm@1~\texttt{RS}~thm@2 & & thm@1~[THEN~thm@2] \\
wenzelm@10160
   468
  thm@1~\texttt{RSN}~(i, thm@2) & & thm@1~[THEN~[i]~thm@2] \\
wenzelm@10153
   469
  thm@1~\texttt{COMP}~thm@2 & & thm@1~[COMP~thm@2] \\
wenzelm@10153
   470
  \relax[thm@1, \dots]~\texttt{MRS}~thm & & thm~[OF~thm@1~\dots] \\
wenzelm@10153
   471
  \texttt{read_instantiate}~[(x@1, t@1), \dots]~thm & & thm~[where~x@1 = t@1~and~\dots] \\
wenzelm@13041
   472
  \texttt{make_elim}~thm & & thm~[elim_format] \\
wenzelm@10153
   473
  \texttt{standard}~thm & & thm~[standard] \\
wenzelm@10153
   474
\end{matharray}
wenzelm@10160
   475
wenzelm@10160
   476
Note that $OF$ is often more readable as $THEN$; likewise positional
wenzelm@13041
   477
instantiation with $of$ is often more appropriate than $where$.
wenzelm@10153
   478
wenzelm@10153
   479
The special ML command \texttt{qed_spec_mp} of Isabelle/HOL and FOL may be
wenzelm@10160
   480
replaced by passing the result of a proof through $rule_format$.
wenzelm@10153
   481
wenzelm@10223
   482
\medskip Global ML declarations may be expressed using the $\DECLARE$ command
wenzelm@10223
   483
(see \S\ref{sec:tactic-commands}) together with appropriate attributes.  The
wenzelm@10223
   484
most common ones are as follows.
wenzelm@10153
   485
\begin{matharray}{lll}
wenzelm@10223
   486
  \texttt{Addsimps}~[thm] & & \DECLARE~thm~[simp] \\
wenzelm@10223
   487
  \texttt{Delsimps}~[thm] & & \DECLARE~thm~[simp~del] \\
wenzelm@10223
   488
  \texttt{Addsplits}~[thm] & & \DECLARE~thm~[split] \\
wenzelm@10223
   489
  \texttt{Delsplits}~[thm] & & \DECLARE~thm~[split~del] \\[0.5ex]
wenzelm@10223
   490
  \texttt{AddIs}~[thm] & & \DECLARE~thm~[intro] \\
wenzelm@10223
   491
  \texttt{AddEs}~[thm] & & \DECLARE~thm~[elim] \\
wenzelm@10223
   492
  \texttt{AddDs}~[thm] & & \DECLARE~thm~[dest] \\
wenzelm@10223
   493
  \texttt{AddSIs}~[thm] & & \DECLARE~thm~[intro!] \\
wenzelm@10223
   494
  \texttt{AddSEs}~[thm] & & \DECLARE~thm~[elim!] \\
wenzelm@10223
   495
  \texttt{AddSDs}~[thm] & & \DECLARE~thm~[dest!] \\[0.5ex]
wenzelm@10223
   496
  \texttt{AddIffs}~[thm] & & \DECLARE~thm~[iff] \\
wenzelm@10153
   497
\end{matharray}
wenzelm@13041
   498
Note that explicit $\DECLARE$ commands are rarely needed in practice; Isar
wenzelm@13041
   499
admits to declare theorems on-the-fly wherever they emerge.  Consider the
wenzelm@10223
   500
following ML idiom:
wenzelm@10153
   501
\begin{ttbox}
wenzelm@10153
   502
Goal "\(\phi\)";
wenzelm@10153
   503
 \(\vdots\)
wenzelm@10153
   504
qed "name";
wenzelm@10153
   505
Addsimps [name];
wenzelm@10153
   506
\end{ttbox}
wenzelm@13041
   507
This may be expressed more succinctly in Isar like this:
wenzelm@10153
   508
\begin{matharray}{l}
wenzelm@10153
   509
  \LEMMA{name~[simp]}{\phi} \\
wenzelm@10153
   510
  \quad\vdots
wenzelm@10153
   511
\end{matharray}
wenzelm@10160
   512
The $name$ may be even omitted, although this would make it difficult to
wenzelm@10160
   513
declare the theorem otherwise later (e.g.\ as $[simp~del]$).
wenzelm@10153
   514
wenzelm@10153
   515
wenzelm@12621
   516
\section{Writing actual Isar proof texts}
wenzelm@10153
   517
wenzelm@10153
   518
Porting legacy ML proof scripts into Isar tactic emulation scripts (see
wenzelm@10160
   519
\S\ref{sec:port-scripts}) is mainly a technical issue, since the basic
wenzelm@10160
   520
representation of formal ``proof script'' is preserved.  In contrast,
wenzelm@10160
   521
converting existing Isabelle developments into actual human-readably Isar
wenzelm@10153
   522
proof texts is more involved, due to the fundamental change of the underlying
wenzelm@10153
   523
paradigm.
wenzelm@10153
   524
wenzelm@10153
   525
This issue is comparable to that of converting programs written in a low-level
wenzelm@10160
   526
programming languages (say Assembler) into higher-level ones (say Haskell).
wenzelm@10160
   527
In order to accomplish this, one needs a working knowledge of the target
wenzelm@10153
   528
language, as well an understanding of the \emph{original} idea of the piece of
wenzelm@10153
   529
code expressed in the low-level language.
wenzelm@10153
   530
wenzelm@10153
   531
As far as Isar proofs are concerned, it is usually much easier to re-use only
wenzelm@13041
   532
definitions and the main statements, while following the arrangement of proof
wenzelm@13041
   533
scripts only very loosely.  Ideally, one would also have some \emph{informal}
wenzelm@13041
   534
proof outlines available for guidance as well.  In the worst case, obscure
wenzelm@13041
   535
proof scripts would have to be re-engineered by tracing forth and backwards,
wenzelm@13041
   536
and by educated guessing!
wenzelm@10153
   537
wenzelm@10153
   538
\medskip This is a possible schedule to embark on actual conversion of legacy
wenzelm@10153
   539
proof scripts into Isar proof texts.
wenzelm@13041
   540
wenzelm@10153
   541
\begin{enumerate}
wenzelm@13041
   542
wenzelm@10153
   543
\item Port ML scripts to Isar tactic emulation scripts (see
wenzelm@10153
   544
  \S\ref{sec:port-scripts}).
wenzelm@13041
   545
wenzelm@10153
   546
\item Get sufficiently acquainted with Isabelle/Isar proof
wenzelm@10153
   547
  development.\footnote{As there is still no Isar tutorial around, it is best
wenzelm@10160
   548
    to look at existing Isar examples, see also \S\ref{sec:isar-howto}.}
wenzelm@13041
   549
wenzelm@10153
   550
\item Recover the proof structure of a few important theorems.
wenzelm@13041
   551
wenzelm@10153
   552
\item Rephrase the original intention of the course of reasoning in terms of
wenzelm@10153
   553
  Isar proof language elements.
wenzelm@13041
   554
wenzelm@10153
   555
\end{enumerate}
wenzelm@10153
   556
wenzelm@13041
   557
Certainly, rewriting formal reasoning in Isar requires some additional effort.
wenzelm@10160
   558
On the other hand, one gains a human-readable representation of
wenzelm@10160
   559
machine-checked formal proof.  Depending on the context of application, this
wenzelm@10160
   560
might be even indispensable to start with!
wenzelm@10160
   561
wenzelm@13048
   562
%%% Local Variables:
wenzelm@9607
   563
%%% mode: latex
wenzelm@9607
   564
%%% TeX-master: "isar-ref"
wenzelm@13048
   565
%%% End: