doc-src/IsarRef/pure.tex
author wenzelm
Thu Jul 06 18:11:48 2000 +0200 (2000-07-06)
changeset 9273 798673f65f02
parent 9238 ad37b21c0dc6
child 9308 4adf25becaa4
permissions -rw-r--r--
allow comment in more commands;
wenzelm@7046
     1
wenzelm@7895
     2
\chapter{Basic Isar Language Elements}\label{ch:pure-syntax}
wenzelm@7167
     3
wenzelm@8515
     4
Subsequently, we introduce the main part of Pure Isar theory and proof
wenzelm@8547
     5
commands, together with fundamental proof methods and attributes.
wenzelm@8515
     6
Chapter~\ref{ch:gen-tools} describes further Isar elements provided by generic
wenzelm@8515
     7
tools and packages (such as the Simplifier) that are either part of Pure
wenzelm@8515
     8
Isabelle or pre-installed by most object logics.  Chapter~\ref{ch:hol-tools}
wenzelm@8515
     9
refers to actual object-logic specific elements of Isabelle/HOL.
wenzelm@7046
    10
wenzelm@7167
    11
\medskip
wenzelm@7167
    12
wenzelm@7167
    13
Isar commands may be either \emph{proper} document constructors, or
wenzelm@7466
    14
\emph{improper commands}.  Some proof methods and attributes introduced later
wenzelm@7466
    15
are classified as improper as well.  Improper Isar language elements, which
wenzelm@7466
    16
are subsequently marked by $^*$, are often helpful when developing proof
wenzelm@7981
    17
documents, while their use is discouraged for the final outcome.  Typical
wenzelm@7981
    18
examples are diagnostic commands that print terms or theorems according to the
wenzelm@7981
    19
current context; other commands even emulate old-style tactical theorem
wenzelm@8547
    20
proving.
wenzelm@7167
    21
wenzelm@7134
    22
wenzelm@7134
    23
\section{Theory commands}
wenzelm@7134
    24
wenzelm@7167
    25
\subsection{Defining theories}\label{sec:begin-thy}
wenzelm@7134
    26
wenzelm@7895
    27
\indexisarcmd{header}\indexisarcmd{theory}\indexisarcmd{end}\indexisarcmd{context}
wenzelm@7134
    28
\begin{matharray}{rcl}
wenzelm@7895
    29
  \isarcmd{header} & : & \isarkeep{toplevel} \\
wenzelm@8510
    30
  \isarcmd{theory} & : & \isartrans{toplevel}{theory} \\
wenzelm@8510
    31
  \isarcmd{context}^* & : & \isartrans{toplevel}{theory} \\
wenzelm@8510
    32
  \isarcmd{end} & : & \isartrans{theory}{toplevel} \\
wenzelm@7134
    33
\end{matharray}
wenzelm@7134
    34
wenzelm@7134
    35
Isabelle/Isar ``new-style'' theories are either defined via theory files or
wenzelm@7981
    36
interactively.  Both theory-level specifications and proofs are handled
wenzelm@7335
    37
uniformly --- occasionally definitional mechanisms even require some explicit
wenzelm@7335
    38
proof as well.  In contrast, ``old-style'' Isabelle theories support batch
wenzelm@7335
    39
processing only, with the proof scripts collected in separate ML files.
wenzelm@7134
    40
wenzelm@7895
    41
The first actual command of any theory has to be $\THEORY$, starting a new
wenzelm@7895
    42
theory based on the merge of existing ones.  Just preceding $\THEORY$, there
wenzelm@7895
    43
may be an optional $\isarkeyword{header}$ declaration, which is relevant to
wenzelm@7895
    44
document preparation only; it acts very much like a special pre-theory markup
wenzelm@7895
    45
command (cf.\ \S\ref{sec:markup-thy} and \S\ref{sec:markup-thy}).  The theory
wenzelm@7895
    46
context may be also changed by $\CONTEXT$ without creating a new theory.  In
wenzelm@7895
    47
both cases, $\END$ concludes the theory development; it has to be the very
wenzelm@8547
    48
last command of any theory file.
wenzelm@7134
    49
wenzelm@7134
    50
\begin{rail}
wenzelm@7895
    51
  'header' text
wenzelm@7895
    52
  ;
wenzelm@7134
    53
  'theory' name '=' (name + '+') filespecs? ':'
wenzelm@7134
    54
  ;
wenzelm@7134
    55
  'context' name
wenzelm@7134
    56
  ;
wenzelm@7134
    57
  'end'
wenzelm@7134
    58
  ;;
wenzelm@7134
    59
wenzelm@7167
    60
  filespecs: 'files' ((name | parname) +);
wenzelm@7134
    61
\end{rail}
wenzelm@7134
    62
wenzelm@7167
    63
\begin{descr}
wenzelm@7895
    64
\item [$\isarkeyword{header}~text$] provides plain text markup just preceding
wenzelm@8547
    65
  the formal beginning of a theory.  In actual document preparation the
wenzelm@7895
    66
  corresponding {\LaTeX} macro \verb,\isamarkupheader, may be redefined to
wenzelm@7895
    67
  produce chapter or section headings.  See also \S\ref{sec:markup-thy} and
wenzelm@7895
    68
  \S\ref{sec:markup-prf} for further markup commands.
wenzelm@7895
    69
  
wenzelm@7981
    70
\item [$\THEORY~A = B@1 + \cdots + B@n\colon$] commences a new theory $A$
wenzelm@7981
    71
  based on existing ones $B@1 + \cdots + B@n$.  Isabelle's theory loader
wenzelm@7981
    72
  system ensures that any of the base theories are properly loaded (and fully
wenzelm@7981
    73
  up-to-date when $\THEORY$ is executed interactively).  The optional
wenzelm@7981
    74
  $\isarkeyword{files}$ specification declares additional dependencies on ML
wenzelm@7981
    75
  files.  Unless put in parentheses, any file will be loaded immediately via
wenzelm@7981
    76
  $\isarcmd{use}$ (see also \S\ref{sec:ML}).  The optional ML file
wenzelm@7981
    77
  \texttt{$A$.ML} that may be associated with any theory should \emph{not} be
wenzelm@7981
    78
  included in $\isarkeyword{files}$, though.
wenzelm@7134
    79
  
wenzelm@7895
    80
\item [$\CONTEXT~B$] enters an existing theory context, basically in read-only
wenzelm@7981
    81
  mode, so only a limited set of commands may be performed without destroying
wenzelm@7981
    82
  the theory.  Just as for $\THEORY$, the theory loader ensures that $B$ is
wenzelm@7981
    83
  loaded and up-to-date.
wenzelm@7175
    84
  
wenzelm@7167
    85
\item [$\END$] concludes the current theory definition or context switch.
wenzelm@7981
    86
Note that this command cannot be undone, but the whole theory definition has
wenzelm@7981
    87
to be retracted.
wenzelm@7167
    88
\end{descr}
wenzelm@7134
    89
wenzelm@7134
    90
wenzelm@7895
    91
\subsection{Theory markup commands}\label{sec:markup-thy}
wenzelm@7134
    92
wenzelm@7895
    93
\indexisarcmd{chapter}\indexisarcmd{section}\indexisarcmd{subsection}
wenzelm@7895
    94
\indexisarcmd{subsubsection}\indexisarcmd{text}\indexisarcmd{text-raw}
wenzelm@7134
    95
\begin{matharray}{rcl}
wenzelm@7134
    96
  \isarcmd{chapter} & : & \isartrans{theory}{theory} \\
wenzelm@7167
    97
  \isarcmd{section} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    98
  \isarcmd{subsection} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    99
  \isarcmd{subsubsection} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   100
  \isarcmd{text} & : & \isartrans{theory}{theory} \\
wenzelm@7895
   101
  \isarcmd{text_raw} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   102
\end{matharray}
wenzelm@7134
   103
wenzelm@7895
   104
Apart from formal comments (see \S\ref{sec:comments}), markup commands provide
wenzelm@7981
   105
a structured way to insert text into the document generated from a theory (see
wenzelm@7895
   106
\cite{isabelle-sys} for more information on Isabelle's document preparation
wenzelm@7895
   107
tools).
wenzelm@7134
   108
wenzelm@7895
   109
\railalias{textraw}{text\_raw}
wenzelm@7895
   110
\railterm{textraw}
wenzelm@7134
   111
wenzelm@7134
   112
\begin{rail}
wenzelm@7895
   113
  ('chapter' | 'section' | 'subsection' | 'subsubsection' | 'text' | textraw) text
wenzelm@7134
   114
  ;
wenzelm@7134
   115
\end{rail}
wenzelm@7134
   116
wenzelm@7167
   117
\begin{descr}
wenzelm@7335
   118
\item [$\isarkeyword{chapter}$, $\isarkeyword{section}$,
wenzelm@7335
   119
  $\isarkeyword{subsection}$, and $\isarkeyword{subsubsection}$] mark chapter
wenzelm@7335
   120
  and section headings.
wenzelm@7895
   121
\item [$\TEXT$] specifies paragraphs of plain text, including references to
wenzelm@7895
   122
  formal entities.\footnote{The latter feature is not yet supported.
wenzelm@7895
   123
    Nevertheless, any source text of the form
wenzelm@7895
   124
    ``\texttt{\at\ttlbrace$\dots$\ttrbrace}'' should be considered as reserved
wenzelm@7895
   125
    for future use.}
wenzelm@7895
   126
\item [$\isarkeyword{text_raw}$] inserts {\LaTeX} source into the output,
wenzelm@7895
   127
  without additional markup.  Thus the full range of document manipulations
wenzelm@7895
   128
  becomes available.  A typical application would be to emit
wenzelm@7895
   129
  \verb,\begin{comment}, and \verb,\end{comment}, commands to exclude certain
wenzelm@7895
   130
  parts from the final document.\footnote{This requires the \texttt{comment}
wenzelm@8547
   131
    package to be included in {\LaTeX}, of course.}
wenzelm@7167
   132
\end{descr}
wenzelm@7134
   133
wenzelm@8684
   134
Any of these markup elements corresponds to a {\LaTeX} command with the name
wenzelm@8684
   135
prefixed by \verb,\isamarkup,.  For the sectioning commands this is a plain
wenzelm@8684
   136
macro with a single argument, e.g.\ \verb,\isamarkupchapter{,\dots\verb,}, for
wenzelm@8684
   137
$\isarkeyword{chapter}$.  The $\isarkeyword{text}$ markup results in a
wenzelm@8684
   138
{\LaTeX} environment \verb,\begin{isamarkuptext}, {\dots}
wenzelm@8684
   139
  \verb,\end{isamarkuptext},, while $\isarkeyword{text_raw}$ causes the text
wenzelm@8684
   140
to be inserted directly into the {\LaTeX} source.
wenzelm@7895
   141
wenzelm@8485
   142
\medskip
wenzelm@8485
   143
wenzelm@8485
   144
Additional markup commands are available for proofs (see
wenzelm@7895
   145
\S\ref{sec:markup-prf}).  Also note that the $\isarkeyword{header}$
wenzelm@8684
   146
declaration (see \S\ref{sec:begin-thy}) admits to insert section markup just
wenzelm@8684
   147
preceding the actual theory definition.
wenzelm@7895
   148
wenzelm@7134
   149
wenzelm@7135
   150
\subsection{Type classes and sorts}\label{sec:classes}
wenzelm@7134
   151
wenzelm@7134
   152
\indexisarcmd{classes}\indexisarcmd{classrel}\indexisarcmd{defaultsort}
wenzelm@7134
   153
\begin{matharray}{rcl}
wenzelm@7134
   154
  \isarcmd{classes} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   155
  \isarcmd{classrel} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   156
  \isarcmd{defaultsort} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   157
\end{matharray}
wenzelm@7134
   158
wenzelm@7134
   159
\begin{rail}
wenzelm@7167
   160
  'classes' (classdecl comment? +)
wenzelm@7134
   161
  ;
wenzelm@7134
   162
  'classrel' nameref '<' nameref comment?
wenzelm@7134
   163
  ;
wenzelm@7134
   164
  'defaultsort' sort comment?
wenzelm@7134
   165
  ;
wenzelm@7134
   166
\end{rail}
wenzelm@7134
   167
wenzelm@7167
   168
\begin{descr}
wenzelm@7335
   169
\item [$\isarkeyword{classes}~c<\vec c$] declares class $c$ to be a subclass
wenzelm@7335
   170
  of existing classes $\vec c$.  Cyclic class structures are ruled out.
wenzelm@7134
   171
\item [$\isarkeyword{classrel}~c@1<c@2$] states a subclass relation between
wenzelm@7134
   172
  existing classes $c@1$ and $c@2$.  This is done axiomatically!  The
wenzelm@7895
   173
  $\isarkeyword{instance}$ command (see \S\ref{sec:axclass}) provides a way to
wenzelm@7175
   174
  introduce proven class relations.
wenzelm@7134
   175
\item [$\isarkeyword{defaultsort}~s$] makes sort $s$ the new default sort for
wenzelm@7895
   176
  any type variables given without sort constraints.  Usually, the default
wenzelm@8547
   177
  sort would be only changed when defining new object-logics.
wenzelm@7167
   178
\end{descr}
wenzelm@7134
   179
wenzelm@7134
   180
wenzelm@7315
   181
\subsection{Primitive types and type abbreviations}\label{sec:types-pure}
wenzelm@7134
   182
wenzelm@7134
   183
\indexisarcmd{typedecl}\indexisarcmd{types}\indexisarcmd{nonterminals}\indexisarcmd{arities}
wenzelm@7134
   184
\begin{matharray}{rcl}
wenzelm@7134
   185
  \isarcmd{types} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   186
  \isarcmd{typedecl} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   187
  \isarcmd{nonterminals} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   188
  \isarcmd{arities} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   189
\end{matharray}
wenzelm@7134
   190
wenzelm@7134
   191
\begin{rail}
wenzelm@7134
   192
  'types' (typespec '=' type infix? comment? +)
wenzelm@7134
   193
  ;
wenzelm@7134
   194
  'typedecl' typespec infix? comment?
wenzelm@7134
   195
  ;
wenzelm@7134
   196
  'nonterminals' (name +) comment?
wenzelm@7134
   197
  ;
wenzelm@7134
   198
  'arities' (nameref '::' arity comment? +)
wenzelm@7134
   199
  ;
wenzelm@7134
   200
\end{rail}
wenzelm@7134
   201
wenzelm@7167
   202
\begin{descr}
wenzelm@7335
   203
\item [$\TYPES~(\vec\alpha)t = \tau$] introduces \emph{type synonym}
wenzelm@7134
   204
  $(\vec\alpha)t$ for existing type $\tau$.  Unlike actual type definitions,
wenzelm@7134
   205
  as are available in Isabelle/HOL for example, type synonyms are just purely
wenzelm@7895
   206
  syntactic abbreviations without any logical significance.  Internally, type
wenzelm@7981
   207
  synonyms are fully expanded.
wenzelm@7134
   208
\item [$\isarkeyword{typedecl}~(\vec\alpha)t$] declares a new type constructor
wenzelm@7895
   209
  $t$, intended as an actual logical type.  Note that object-logics such as
wenzelm@7895
   210
  Isabelle/HOL override $\isarkeyword{typedecl}$ by their own version.
wenzelm@7175
   211
\item [$\isarkeyword{nonterminals}~\vec c$] declares $0$-ary type constructors
wenzelm@7175
   212
  $\vec c$ to act as purely syntactic types, i.e.\ nonterminal symbols of
wenzelm@7175
   213
  Isabelle's inner syntax of terms or types.
wenzelm@7335
   214
\item [$\isarkeyword{arities}~t::(\vec s)s$] augments Isabelle's order-sorted
wenzelm@7335
   215
  signature of types by new type constructor arities.  This is done
wenzelm@7335
   216
  axiomatically!  The $\isarkeyword{instance}$ command (see
wenzelm@7895
   217
  \S\ref{sec:axclass}) provides a way to introduce proven type arities.
wenzelm@7167
   218
\end{descr}
wenzelm@7134
   219
wenzelm@7134
   220
wenzelm@7981
   221
\subsection{Constants and simple definitions}\label{sec:consts}
wenzelm@7134
   222
wenzelm@7175
   223
\indexisarcmd{consts}\indexisarcmd{defs}\indexisarcmd{constdefs}\indexoutertoken{constdecl}
wenzelm@7134
   224
\begin{matharray}{rcl}
wenzelm@7134
   225
  \isarcmd{consts} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   226
  \isarcmd{defs} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   227
  \isarcmd{constdefs} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   228
\end{matharray}
wenzelm@7134
   229
wenzelm@7134
   230
\begin{rail}
wenzelm@7134
   231
  'consts' (constdecl +)
wenzelm@7134
   232
  ;
wenzelm@7608
   233
  'defs' (axmdecl prop comment? +)
wenzelm@7134
   234
  ;
wenzelm@7134
   235
  'constdefs' (constdecl prop comment? +)
wenzelm@7134
   236
  ;
wenzelm@7134
   237
wenzelm@7134
   238
  constdecl: name '::' type mixfix? comment?
wenzelm@7134
   239
  ;
wenzelm@7134
   240
\end{rail}
wenzelm@7134
   241
wenzelm@7167
   242
\begin{descr}
wenzelm@7335
   243
\item [$\CONSTS~c::\sigma$] declares constant $c$ to have any instance of type
wenzelm@7335
   244
  scheme $\sigma$.  The optional mixfix annotations may attach concrete syntax
wenzelm@7895
   245
  to the constants declared.
wenzelm@7335
   246
\item [$\DEFS~name: eqn$] introduces $eqn$ as a definitional axiom for some
wenzelm@7335
   247
  existing constant.  See \cite[\S6]{isabelle-ref} for more details on the
wenzelm@7335
   248
  form of equations admitted as constant definitions.
wenzelm@7335
   249
\item [$\isarkeyword{constdefs}~c::\sigma~eqn$] combines declarations and
wenzelm@8547
   250
  definitions of constants, using the canonical name $c_def$ for the
wenzelm@8547
   251
  definitional axiom.
wenzelm@7167
   252
\end{descr}
wenzelm@7134
   253
wenzelm@7134
   254
wenzelm@7981
   255
\subsection{Syntax and translations}\label{sec:syn-trans}
wenzelm@7134
   256
wenzelm@7134
   257
\indexisarcmd{syntax}\indexisarcmd{translations}
wenzelm@7134
   258
\begin{matharray}{rcl}
wenzelm@7134
   259
  \isarcmd{syntax} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   260
  \isarcmd{translations} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   261
\end{matharray}
wenzelm@7134
   262
wenzelm@7134
   263
\begin{rail}
wenzelm@7134
   264
  'syntax' ('(' name 'output'? ')')? (constdecl +)
wenzelm@7134
   265
  ;
wenzelm@7134
   266
  'translations' (transpat ('==' | '=>' | '<=') transpat comment? +)
wenzelm@7134
   267
  ;
wenzelm@7134
   268
  transpat: ('(' nameref ')')? string
wenzelm@7134
   269
  ;
wenzelm@7134
   270
\end{rail}
wenzelm@7134
   271
wenzelm@7167
   272
\begin{descr}
wenzelm@7175
   273
\item [$\isarkeyword{syntax}~(mode)~decls$] is similar to $\CONSTS~decls$,
wenzelm@7175
   274
  except that the actual logical signature extension is omitted.  Thus the
wenzelm@7175
   275
  context free grammar of Isabelle's inner syntax may be augmented in
wenzelm@7335
   276
  arbitrary ways, independently of the logic.  The $mode$ argument refers to
wenzelm@8547
   277
  the print mode that the grammar rules belong; unless the \texttt{output}
wenzelm@8547
   278
  flag is given, all productions are added both to the input and output
wenzelm@8547
   279
  grammar.
wenzelm@7175
   280
\item [$\isarkeyword{translations}~rules$] specifies syntactic translation
wenzelm@7981
   281
  rules (i.e.\ \emph{macros}): parse~/ print rules (\texttt{==}), parse rules
wenzelm@7895
   282
  (\texttt{=>}), or print rules (\texttt{<=}).  Translation patterns may be
wenzelm@7895
   283
  prefixed by the syntactic category to be used for parsing; the default is
wenzelm@7134
   284
  \texttt{logic}.
wenzelm@7167
   285
\end{descr}
wenzelm@7134
   286
wenzelm@7134
   287
wenzelm@7134
   288
\subsection{Axioms and theorems}
wenzelm@7134
   289
wenzelm@7134
   290
\indexisarcmd{axioms}\indexisarcmd{theorems}\indexisarcmd{lemmas}
wenzelm@7134
   291
\begin{matharray}{rcl}
wenzelm@7134
   292
  \isarcmd{axioms} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   293
  \isarcmd{theorems} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   294
  \isarcmd{lemmas} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   295
\end{matharray}
wenzelm@7134
   296
wenzelm@7134
   297
\begin{rail}
wenzelm@7135
   298
  'axioms' (axmdecl prop comment? +)
wenzelm@7134
   299
  ;
wenzelm@9199
   300
  ('theorems' | 'lemmas') (thmdef? thmrefs comment? + 'and')
wenzelm@7134
   301
  ;
wenzelm@7134
   302
\end{rail}
wenzelm@7134
   303
wenzelm@7167
   304
\begin{descr}
wenzelm@7335
   305
\item [$\isarkeyword{axioms}~a: \phi$] introduces arbitrary statements as
wenzelm@7895
   306
  axioms of the meta-logic.  In fact, axioms are ``axiomatic theorems'', and
wenzelm@7895
   307
  may be referred later just as any other theorem.
wenzelm@7134
   308
  
wenzelm@7134
   309
  Axioms are usually only introduced when declaring new logical systems.
wenzelm@7175
   310
  Everyday work is typically done the hard way, with proper definitions and
wenzelm@8547
   311
  actual proven theorems.
wenzelm@7335
   312
\item [$\isarkeyword{theorems}~a = \vec b$] stores lists of existing theorems.
wenzelm@8547
   313
  Typical applications would also involve attributes, to declare Simplifier
wenzelm@8547
   314
  rules, for example.
wenzelm@7134
   315
\item [$\isarkeyword{lemmas}$] is similar to $\isarkeyword{theorems}$, but
wenzelm@7134
   316
  tags the results as ``lemma''.
wenzelm@7167
   317
\end{descr}
wenzelm@7134
   318
wenzelm@7134
   319
wenzelm@7167
   320
\subsection{Name spaces}
wenzelm@7134
   321
wenzelm@8726
   322
\indexisarcmd{global}\indexisarcmd{local}\indexisarcmd{hide}
wenzelm@7134
   323
\begin{matharray}{rcl}
wenzelm@7134
   324
  \isarcmd{global} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   325
  \isarcmd{local} & : & \isartrans{theory}{theory} \\
wenzelm@8726
   326
  \isarcmd{hide} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   327
\end{matharray}
wenzelm@7134
   328
wenzelm@8726
   329
\begin{rail}
wenzelm@8726
   330
  'global' comment?
wenzelm@8726
   331
  ;
wenzelm@8726
   332
  'local' comment?
wenzelm@8726
   333
  ;
wenzelm@8726
   334
  'hide' name (nameref + ) comment?
wenzelm@8726
   335
  ;
wenzelm@8726
   336
\end{rail}
wenzelm@8726
   337
wenzelm@7895
   338
Isabelle organizes any kind of name declarations (of types, constants,
wenzelm@8547
   339
theorems etc.) by separate hierarchically structured name spaces.  Normally
wenzelm@8726
   340
the user does not have to control the behavior of name spaces by hand, yet the
wenzelm@8726
   341
following commands provide some way to do so.
wenzelm@7175
   342
wenzelm@7167
   343
\begin{descr}
wenzelm@7167
   344
\item [$\isarkeyword{global}$ and $\isarkeyword{local}$] change the current
wenzelm@7167
   345
  name declaration mode.  Initially, theories start in $\isarkeyword{local}$
wenzelm@7167
   346
  mode, causing all names to be automatically qualified by the theory name.
wenzelm@7895
   347
  Changing this to $\isarkeyword{global}$ causes all names to be declared
wenzelm@7895
   348
  without the theory prefix, until $\isarkeyword{local}$ is declared again.
wenzelm@8726
   349
  
wenzelm@8726
   350
  Note that global names are prone to get hidden accidently later, when
wenzelm@8726
   351
  qualified names of the same base name are introduced.
wenzelm@8726
   352
  
wenzelm@8726
   353
\item [$\isarkeyword{hide}~space~names$] removes declarations from a given
wenzelm@8726
   354
  name space (which may be $class$, $type$, or $const$).  Hidden objects
wenzelm@8726
   355
  remain valid within the logic, but are inaccessible from user input.  In
wenzelm@8726
   356
  output, the special qualifier ``$\mathord?\mathord?$'' is prefixed to the
wenzelm@8726
   357
  full internal name.
wenzelm@8726
   358
  
wenzelm@8726
   359
  Unqualified (global) names may not be hidden deliberately.
wenzelm@7167
   360
\end{descr}
wenzelm@7134
   361
wenzelm@7134
   362
wenzelm@7167
   363
\subsection{Incorporating ML code}\label{sec:ML}
wenzelm@7134
   364
wenzelm@8682
   365
\indexisarcmd{use}\indexisarcmd{ML}\indexisarcmd{ML-command}
wenzelm@8682
   366
\indexisarcmd{ML-setup}\indexisarcmd{setup}
wenzelm@9199
   367
\indexisarcmd{method-setup}
wenzelm@7134
   368
\begin{matharray}{rcl}
wenzelm@7134
   369
  \isarcmd{use} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@7134
   370
  \isarcmd{ML} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@8682
   371
  \isarcmd{ML_command} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@7895
   372
  \isarcmd{ML_setup} & : & \isartrans{theory}{theory} \\
wenzelm@7175
   373
  \isarcmd{setup} & : & \isartrans{theory}{theory} \\
wenzelm@9199
   374
  \isarcmd{method_setup} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   375
\end{matharray}
wenzelm@7134
   376
wenzelm@7895
   377
\railalias{MLsetup}{ML\_setup}
wenzelm@7895
   378
\railterm{MLsetup}
wenzelm@7895
   379
wenzelm@9199
   380
\railalias{methodsetup}{method\_setup}
wenzelm@9199
   381
\railterm{methodsetup}
wenzelm@9199
   382
wenzelm@8682
   383
\railalias{MLcommand}{ML\_command}
wenzelm@8682
   384
\railterm{MLcommand}
wenzelm@8682
   385
wenzelm@7134
   386
\begin{rail}
wenzelm@9273
   387
  'use' name comment?
wenzelm@7134
   388
  ;
wenzelm@9273
   389
  ('ML' | MLcommand | MLsetup | 'setup') text comment?
wenzelm@7134
   390
  ;
wenzelm@9199
   391
  methodsetup name '=' text text comment?
wenzelm@9199
   392
  ;
wenzelm@7134
   393
\end{rail}
wenzelm@7134
   394
wenzelm@7167
   395
\begin{descr}
wenzelm@7175
   396
\item [$\isarkeyword{use}~file$] reads and executes ML commands from $file$.
wenzelm@7466
   397
  The current theory context (if present) is passed down to the ML session,
wenzelm@7981
   398
  but may not be modified.  Furthermore, the file name is checked with the
wenzelm@7466
   399
  $\isarkeyword{files}$ dependency declaration given in the theory header (see
wenzelm@7466
   400
  also \S\ref{sec:begin-thy}).
wenzelm@7466
   401
  
wenzelm@8682
   402
\item [$\isarkeyword{ML}~text$ and $\isarkeyword{ML_command}~text$] execute ML
wenzelm@8682
   403
  commands from $text$.  The theory context is passed in the same way as for
wenzelm@8682
   404
  $\isarkeyword{use}$, but may not be changed.  Note that
wenzelm@8682
   405
  $\isarkeyword{ML_command}$ is less verbose than plain $\isarkeyword{ML}$.
wenzelm@7895
   406
  
wenzelm@7895
   407
\item [$\isarkeyword{ML_setup}~text$] executes ML commands from $text$.  The
wenzelm@7895
   408
  theory context is passed down to the ML session, and fetched back
wenzelm@7895
   409
  afterwards.  Thus $text$ may actually change the theory as a side effect.
wenzelm@7895
   410
  
wenzelm@7167
   411
\item [$\isarkeyword{setup}~text$] changes the current theory context by
wenzelm@8379
   412
  applying $text$, which refers to an ML expression of type
wenzelm@8379
   413
  \texttt{(theory~->~theory)~list}.  The $\isarkeyword{setup}$ command is the
wenzelm@8547
   414
  canonical way to initialize any object-logic specific tools and packages
wenzelm@8547
   415
  written in ML.
wenzelm@9199
   416
  
wenzelm@9199
   417
\item [$\isarkeyword{method_setup}~name = text~description$] defines a proof
wenzelm@9199
   418
  method in the current theory.  The given $text$ has to be an ML expression
wenzelm@9199
   419
  of type \texttt{Args.src -> Proof.context -> Proof.method}.  Parsing
wenzelm@9199
   420
  concrete method syntax from \texttt{Args.src} input can be quite tedious in
wenzelm@9199
   421
  general.  The following simple examples are for methods without any explicit
wenzelm@9199
   422
  arguments, or a list of theorems, respectively.
wenzelm@9199
   423
wenzelm@9199
   424
{\footnotesize
wenzelm@9199
   425
\begin{verbatim}
wenzelm@9199
   426
Method.no_args (Method.METHOD (fn facts => foobar_tac))
wenzelm@9199
   427
Method.thms_args (fn thms => (Method.METHOD (fn facts => foobar_tac)))
wenzelm@9199
   428
\end{verbatim}
wenzelm@9199
   429
}
wenzelm@9199
   430
wenzelm@9199
   431
Note that mere tactic emulations may ignore the \texttt{facts} parameter
wenzelm@9199
   432
above.  Proper proof methods would do something ``appropriate'' with the list
wenzelm@9199
   433
of current facts, though.  Single-rule methods usually do strict
wenzelm@9199
   434
forward-chaining (e.g.\ by using \texttt{Method.multi_resolves}), while
wenzelm@9199
   435
automatic ones just insert the facts using \texttt{Method.insert_tac} before
wenzelm@9199
   436
applying the main tactic.
wenzelm@7167
   437
\end{descr}
wenzelm@7134
   438
wenzelm@7134
   439
wenzelm@8250
   440
\subsection{Syntax translation functions}
wenzelm@7134
   441
wenzelm@8250
   442
\indexisarcmd{parse-ast-translation}\indexisarcmd{parse-translation}
wenzelm@8250
   443
\indexisarcmd{print-translation}\indexisarcmd{typed-print-translation}
wenzelm@8250
   444
\indexisarcmd{print-ast-translation}\indexisarcmd{token-translation}
wenzelm@8250
   445
\begin{matharray}{rcl}
wenzelm@8250
   446
  \isarcmd{parse_ast_translation} & : & \isartrans{theory}{theory} \\
wenzelm@8250
   447
  \isarcmd{parse_translation} & : & \isartrans{theory}{theory} \\
wenzelm@8250
   448
  \isarcmd{print_translation} & : & \isartrans{theory}{theory} \\
wenzelm@8250
   449
  \isarcmd{typed_print_translation} & : & \isartrans{theory}{theory} \\
wenzelm@8250
   450
  \isarcmd{print_ast_translation} & : & \isartrans{theory}{theory} \\
wenzelm@8250
   451
  \isarcmd{token_translation} & : & \isartrans{theory}{theory} \\
wenzelm@8250
   452
\end{matharray}
wenzelm@7134
   453
wenzelm@9273
   454
\railalias{parseasttranslation}{parse\_ast\_translation}
wenzelm@9273
   455
\railterm{parseasttranslation}
wenzelm@9273
   456
wenzelm@9273
   457
\railalias{parsetranslation}{parse\_translation}
wenzelm@9273
   458
\railterm{parsetranslation}
wenzelm@9273
   459
wenzelm@9273
   460
\railalias{printtranslation}{print\_translation}
wenzelm@9273
   461
\railterm{printtranslation}
wenzelm@9273
   462
wenzelm@9273
   463
\railalias{typedprinttranslation}{typed\_print\_translation}
wenzelm@9273
   464
\railterm{typedprinttranslation}
wenzelm@9273
   465
wenzelm@9273
   466
\railalias{printasttranslation}{print\_ast\_translation}
wenzelm@9273
   467
\railterm{printasttranslation}
wenzelm@9273
   468
wenzelm@9273
   469
\railalias{tokentranslation}{token\_translation}
wenzelm@9273
   470
\railterm{tokentranslation}
wenzelm@9273
   471
wenzelm@9273
   472
\begin{rail}
wenzelm@9273
   473
  ( parseasttranslation | parsetranslation | printtranslation | typedprinttranslation |
wenzelm@9273
   474
  printasttranslation | tokentranslation ) text comment?
wenzelm@9273
   475
\end{rail}
wenzelm@9273
   476
wenzelm@8250
   477
Syntax translation functions written in ML admit almost arbitrary
wenzelm@8250
   478
manipulations of Isabelle's inner syntax.  Any of the above commands have a
wenzelm@8250
   479
single \railqtoken{text} argument that refers to an ML expression of
wenzelm@8379
   480
appropriate type.
wenzelm@8379
   481
wenzelm@8379
   482
\begin{ttbox}
wenzelm@8379
   483
val parse_ast_translation   : (string * (ast list -> ast)) list
wenzelm@8379
   484
val parse_translation       : (string * (term list -> term)) list
wenzelm@8379
   485
val print_translation       : (string * (term list -> term)) list
wenzelm@8379
   486
val typed_print_translation :
wenzelm@8379
   487
  (string * (bool -> typ -> term list -> term)) list
wenzelm@8379
   488
val print_ast_translation   : (string * (ast list -> ast)) list
wenzelm@8379
   489
val token_translation       :
wenzelm@8379
   490
  (string * string * (string -> string * real)) list
wenzelm@8379
   491
\end{ttbox}
wenzelm@8379
   492
See \cite[\S8]{isabelle-ref} for more information on syntax transformations.
wenzelm@7134
   493
wenzelm@7134
   494
wenzelm@7134
   495
\subsection{Oracles}
wenzelm@7134
   496
wenzelm@7134
   497
\indexisarcmd{oracle}
wenzelm@7134
   498
\begin{matharray}{rcl}
wenzelm@7134
   499
  \isarcmd{oracle} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   500
\end{matharray}
wenzelm@7134
   501
wenzelm@7175
   502
Oracles provide an interface to external reasoning systems, without giving up
wenzelm@7175
   503
control completely --- each theorem carries a derivation object recording any
wenzelm@7175
   504
oracle invocation.  See \cite[\S6]{isabelle-ref} for more information.
wenzelm@7175
   505
wenzelm@7134
   506
\begin{rail}
wenzelm@7134
   507
  'oracle' name '=' text comment?
wenzelm@7134
   508
  ;
wenzelm@7134
   509
\end{rail}
wenzelm@7134
   510
wenzelm@7167
   511
\begin{descr}
wenzelm@7175
   512
\item [$\isarkeyword{oracle}~name=text$] declares oracle $name$ to be ML
wenzelm@8379
   513
  function $text$, which has to be of type
wenzelm@8379
   514
  \texttt{Sign.sg~*~Object.T~->~term}.
wenzelm@7167
   515
\end{descr}
wenzelm@7134
   516
wenzelm@7134
   517
wenzelm@7134
   518
\section{Proof commands}
wenzelm@7134
   519
wenzelm@7987
   520
Proof commands perform transitions of Isar/VM machine configurations, which
wenzelm@7315
   521
are block-structured, consisting of a stack of nodes with three main
wenzelm@7335
   522
components: logical proof context, current facts, and open goals.  Isar/VM
wenzelm@8547
   523
transitions are \emph{typed} according to the following three different modes
wenzelm@8547
   524
of operation:
wenzelm@7167
   525
\begin{descr}
wenzelm@7167
   526
\item [$proof(prove)$] means that a new goal has just been stated that is now
wenzelm@8547
   527
  to be \emph{proven}; the next command may refine it by some proof method,
wenzelm@8547
   528
  and enter a sub-proof to establish the actual result.
wenzelm@7167
   529
\item [$proof(state)$] is like an internal theory mode: the context may be
wenzelm@7987
   530
  augmented by \emph{stating} additional assumptions, intermediate results
wenzelm@7987
   531
  etc.
wenzelm@7895
   532
\item [$proof(chain)$] is intermediate between $proof(state)$ and
wenzelm@7987
   533
  $proof(prove)$: existing facts (i.e.\ the contents of the special ``$this$''
wenzelm@7987
   534
  register) have been just picked up in order to be used when refining the
wenzelm@7987
   535
  goal claimed next.
wenzelm@7167
   536
\end{descr}
wenzelm@7134
   537
wenzelm@7167
   538
wenzelm@7895
   539
\subsection{Proof markup commands}\label{sec:markup-prf}
wenzelm@7167
   540
wenzelm@7987
   541
\indexisarcmd{sect}\indexisarcmd{subsect}\indexisarcmd{subsubsect}
wenzelm@7895
   542
\indexisarcmd{txt}\indexisarcmd{txt-raw}
wenzelm@7134
   543
\begin{matharray}{rcl}
wenzelm@8101
   544
  \isarcmd{sect} & : & \isartrans{proof}{proof} \\
wenzelm@8101
   545
  \isarcmd{subsect} & : & \isartrans{proof}{proof} \\
wenzelm@8101
   546
  \isarcmd{subsubsect} & : & \isartrans{proof}{proof} \\
wenzelm@8101
   547
  \isarcmd{txt} & : & \isartrans{proof}{proof} \\
wenzelm@8101
   548
  \isarcmd{txt_raw} & : & \isartrans{proof}{proof} \\
wenzelm@7134
   549
\end{matharray}
wenzelm@7134
   550
wenzelm@7895
   551
These markup commands for proof mode closely correspond to the ones of theory
wenzelm@8684
   552
mode (see \S\ref{sec:markup-thy}).
wenzelm@7895
   553
wenzelm@7895
   554
\railalias{txtraw}{txt\_raw}
wenzelm@7895
   555
\railterm{txtraw}
wenzelm@7175
   556
wenzelm@7134
   557
\begin{rail}
wenzelm@7895
   558
  ('sect' | 'subsect' | 'subsubsect' | 'txt' | txtraw) text
wenzelm@7134
   559
  ;
wenzelm@7134
   560
\end{rail}
wenzelm@7134
   561
wenzelm@7134
   562
wenzelm@7315
   563
\subsection{Proof context}\label{sec:proof-context}
wenzelm@7134
   564
wenzelm@7315
   565
\indexisarcmd{fix}\indexisarcmd{assume}\indexisarcmd{presume}\indexisarcmd{def}
wenzelm@7134
   566
\begin{matharray}{rcl}
wenzelm@7134
   567
  \isarcmd{fix} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   568
  \isarcmd{assume} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   569
  \isarcmd{presume} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   570
  \isarcmd{def} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   571
\end{matharray}
wenzelm@7134
   572
wenzelm@7315
   573
The logical proof context consists of fixed variables and assumptions.  The
wenzelm@7315
   574
former closely correspond to Skolem constants, or meta-level universal
wenzelm@7315
   575
quantification as provided by the Isabelle/Pure logical framework.
wenzelm@7315
   576
Introducing some \emph{arbitrary, but fixed} variable via $\FIX x$ results in
wenzelm@7987
   577
a local value that may be used in the subsequent proof as any other variable
wenzelm@7895
   578
or constant.  Furthermore, any result $\edrv \phi[x]$ exported from the
wenzelm@7987
   579
context will be universally closed wrt.\ $x$ at the outermost level: $\edrv
wenzelm@7987
   580
\All x \phi$ (this is expressed using Isabelle's meta-variables).
wenzelm@7315
   581
wenzelm@7315
   582
Similarly, introducing some assumption $\chi$ has two effects.  On the one
wenzelm@7315
   583
hand, a local theorem is created that may be used as a fact in subsequent
wenzelm@7895
   584
proof steps.  On the other hand, any result $\chi \drv \phi$ exported from the
wenzelm@7895
   585
context becomes conditional wrt.\ the assumption: $\edrv \chi \Imp \phi$.
wenzelm@7895
   586
Thus, solving an enclosing goal using such a result would basically introduce
wenzelm@7895
   587
a new subgoal stemming from the assumption.  How this situation is handled
wenzelm@7895
   588
depends on the actual version of assumption command used: while $\ASSUMENAME$
wenzelm@7895
   589
insists on solving the subgoal by unification with some premise of the goal,
wenzelm@7895
   590
$\PRESUMENAME$ leaves the subgoal unchanged in order to be proved later by the
wenzelm@7895
   591
user.
wenzelm@7315
   592
wenzelm@7319
   593
Local definitions, introduced by $\DEF{}{x \equiv t}$, are achieved by
wenzelm@7987
   594
combining $\FIX x$ with another version of assumption that causes any
wenzelm@7987
   595
hypothetical equation $x \equiv t$ to be eliminated by the reflexivity rule.
wenzelm@7987
   596
Thus, exporting some result $x \equiv t \drv \phi[x]$ yields $\edrv \phi[t]$.
wenzelm@7175
   597
wenzelm@7134
   598
\begin{rail}
wenzelm@7431
   599
  'fix' (vars + 'and') comment?
wenzelm@7134
   600
  ;
wenzelm@7315
   601
  ('assume' | 'presume') (assm comment? + 'and')
wenzelm@7134
   602
  ;
wenzelm@7175
   603
  'def' thmdecl? \\ var '==' term termpat? comment?
wenzelm@7134
   604
  ;
wenzelm@7134
   605
wenzelm@7134
   606
  var: name ('::' type)?
wenzelm@7134
   607
  ;
wenzelm@7458
   608
  vars: (name+) ('::' type)?
wenzelm@7431
   609
  ;
wenzelm@7315
   610
  assm: thmdecl? (prop proppat? +)
wenzelm@7315
   611
  ;
wenzelm@7134
   612
\end{rail}
wenzelm@7134
   613
wenzelm@7167
   614
\begin{descr}
wenzelm@8547
   615
\item [$\FIX{\vec x}$] introduces local \emph{arbitrary, but fixed} variables
wenzelm@8547
   616
  $\vec x$.
wenzelm@8515
   617
\item [$\ASSUME{a}{\vec\phi}$ and $\PRESUME{a}{\vec\phi}$] introduce local
wenzelm@8515
   618
  theorems $\vec\phi$ by assumption.  Subsequent results applied to an
wenzelm@8515
   619
  enclosing goal (e.g.\ by $\SHOWNAME$) are handled as follows: $\ASSUMENAME$
wenzelm@8515
   620
  expects to be able to unify with existing premises in the goal, while
wenzelm@8515
   621
  $\PRESUMENAME$ leaves $\vec\phi$ as new subgoals.
wenzelm@7335
   622
  
wenzelm@7335
   623
  Several lists of assumptions may be given (separated by
wenzelm@7895
   624
  $\isarkeyword{and}$); the resulting list of current facts consists of all of
wenzelm@7895
   625
  these concatenated.
wenzelm@7315
   626
\item [$\DEF{a}{x \equiv t}$] introduces a local (non-polymorphic) definition.
wenzelm@7315
   627
  In results exported from the context, $x$ is replaced by $t$.  Basically,
wenzelm@7987
   628
  $\DEF{}{x \equiv t}$ abbreviates $\FIX{x}~\ASSUME{}{x \equiv t}$, with the
wenzelm@7335
   629
  resulting hypothetical equation solved by reflexivity.
wenzelm@7431
   630
  
wenzelm@7431
   631
  The default name for the definitional equation is $x_def$.
wenzelm@7167
   632
\end{descr}
wenzelm@7167
   633
wenzelm@7895
   634
The special name $prems$\indexisarthm{prems} refers to all assumptions of the
wenzelm@7895
   635
current context as a list of theorems.
wenzelm@7315
   636
wenzelm@7167
   637
wenzelm@7167
   638
\subsection{Facts and forward chaining}
wenzelm@7167
   639
wenzelm@7167
   640
\indexisarcmd{note}\indexisarcmd{then}\indexisarcmd{from}\indexisarcmd{with}
wenzelm@7167
   641
\begin{matharray}{rcl}
wenzelm@7167
   642
  \isarcmd{note} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7167
   643
  \isarcmd{then} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@7167
   644
  \isarcmd{from} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@7167
   645
  \isarcmd{with} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@7167
   646
\end{matharray}
wenzelm@7167
   647
wenzelm@7319
   648
New facts are established either by assumption or proof of local statements.
wenzelm@7335
   649
Any fact will usually be involved in further proofs, either as explicit
wenzelm@8547
   650
arguments of proof methods, or when forward chaining towards the next goal via
wenzelm@7335
   651
$\THEN$ (and variants).  Note that the special theorem name
wenzelm@7987
   652
$this$\indexisarthm{this} refers to the most recently established facts.
wenzelm@7167
   653
\begin{rail}
wenzelm@9199
   654
  'note' (thmdef? thmrefs comment? + 'and')
wenzelm@7167
   655
  ;
wenzelm@7167
   656
  'then' comment?
wenzelm@7167
   657
  ;
wenzelm@9199
   658
  ('from' | 'with') (thmrefs comment? + 'and')
wenzelm@7167
   659
  ;
wenzelm@7167
   660
\end{rail}
wenzelm@7167
   661
wenzelm@7167
   662
\begin{descr}
wenzelm@7175
   663
\item [$\NOTE{a}{\vec b}$] recalls existing facts $\vec b$, binding the result
wenzelm@7175
   664
  as $a$.  Note that attributes may be involved as well, both on the left and
wenzelm@7175
   665
  right hand sides.
wenzelm@7167
   666
\item [$\THEN$] indicates forward chaining by the current facts in order to
wenzelm@7895
   667
  establish the goal to be claimed next.  The initial proof method invoked to
wenzelm@7895
   668
  refine that will be offered the facts to do ``anything appropriate'' (cf.\ 
wenzelm@7895
   669
  also \S\ref{sec:proof-steps}).  For example, method $rule$ (see
wenzelm@8515
   670
  \S\ref{sec:pure-meth-att}) would typically do an elimination rather than an
wenzelm@7895
   671
  introduction.  Automatic methods usually insert the facts into the goal
wenzelm@8547
   672
  state before operation.  This provides a simple scheme to control relevance
wenzelm@8547
   673
  of facts in automated proof search.
wenzelm@7335
   674
\item [$\FROM{\vec b}$] abbreviates $\NOTE{}{\vec b}~\THEN$; thus $\THEN$ is
wenzelm@7458
   675
  equivalent to $\FROM{this}$.
wenzelm@7175
   676
\item [$\WITH{\vec b}$] abbreviates $\FROM{\vec b~facts}$; thus the forward
wenzelm@7175
   677
  chaining is from earlier facts together with the current ones.
wenzelm@7167
   678
\end{descr}
wenzelm@7167
   679
wenzelm@8515
   680
Basic proof methods (such as $rule$, see \S\ref{sec:pure-meth-att}) expect
wenzelm@7895
   681
multiple facts to be given in their proper order, corresponding to a prefix of
wenzelm@7895
   682
the premises of the rule involved.  Note that positions may be easily skipped
wenzelm@8547
   683
using something like $\FROM{\text{\texttt{_}}~a~b}$, for example.  This
wenzelm@8547
   684
involves the trivial rule $\PROP\psi \Imp \PROP\psi$, which happens to be
wenzelm@8547
   685
bound in Isabelle/Pure as ``\texttt{_}''
wenzelm@8547
   686
(underscore).\indexisarthm{_@\texttt{_}}
wenzelm@7389
   687
wenzelm@9238
   688
Forward chaining with an empty list of theorems is the same as not chaining.
wenzelm@9238
   689
Thus $\FROM{nothing}$ has no effect apart from entering $prove(chain)$ mode,
wenzelm@9238
   690
since $nothing$\indexisarthm{nothing} is bound to the empty list of facts.
wenzelm@9238
   691
wenzelm@7167
   692
wenzelm@7167
   693
\subsection{Goal statements}
wenzelm@7167
   694
wenzelm@7167
   695
\indexisarcmd{theorem}\indexisarcmd{lemma}
wenzelm@7167
   696
\indexisarcmd{have}\indexisarcmd{show}\indexisarcmd{hence}\indexisarcmd{thus}
wenzelm@7167
   697
\begin{matharray}{rcl}
wenzelm@7167
   698
  \isarcmd{theorem} & : & \isartrans{theory}{proof(prove)} \\
wenzelm@7167
   699
  \isarcmd{lemma} & : & \isartrans{theory}{proof(prove)} \\
wenzelm@7987
   700
  \isarcmd{have} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
wenzelm@7987
   701
  \isarcmd{show} & : & \isartrans{proof(state) ~|~ proof(chain)}{proof(prove)} \\
wenzelm@7167
   702
  \isarcmd{hence} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@7167
   703
  \isarcmd{thus} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@7167
   704
\end{matharray}
wenzelm@7167
   705
wenzelm@7175
   706
Proof mode is entered from theory mode by initial goal commands $\THEOREMNAME$
wenzelm@7895
   707
and $\LEMMANAME$.  New local goals may be claimed within proof mode as well.
wenzelm@7895
   708
Four variants are available, indicating whether the result is meant to solve
wenzelm@8547
   709
some pending goal or whether forward chaining is indicated.
wenzelm@7175
   710
wenzelm@7167
   711
\begin{rail}
wenzelm@7167
   712
  ('theorem' | 'lemma') goal
wenzelm@7167
   713
  ;
wenzelm@7167
   714
  ('have' | 'show' | 'hence' | 'thus') goal
wenzelm@7167
   715
  ;
wenzelm@7167
   716
wenzelm@8632
   717
  goal: thmdecl? prop proppat? comment?
wenzelm@7167
   718
  ;
wenzelm@7167
   719
\end{rail}
wenzelm@7167
   720
wenzelm@7167
   721
\begin{descr}
wenzelm@7335
   722
\item [$\THEOREM{a}{\phi}$] enters proof mode with $\phi$ as main goal,
wenzelm@8547
   723
  eventually resulting in some theorem $\turn \phi$ to be put back into the
wenzelm@8547
   724
  theory.
wenzelm@7987
   725
\item [$\LEMMA{a}{\phi}$] is similar to $\THEOREMNAME$, but tags the result as
wenzelm@7167
   726
  ``lemma''.
wenzelm@7335
   727
\item [$\HAVE{a}{\phi}$] claims a local goal, eventually resulting in a
wenzelm@7167
   728
  theorem with the current assumption context as hypotheses.
wenzelm@7335
   729
\item [$\SHOW{a}{\phi}$] is similar to $\HAVE{a}{\phi}$, but solves some
wenzelm@7895
   730
  pending goal with the result \emph{exported} into the corresponding context
wenzelm@7895
   731
  (cf.\ \S\ref{sec:proof-context}).
wenzelm@7895
   732
\item [$\HENCENAME$] abbreviates $\THEN~\HAVENAME$, i.e.\ claims a local goal
wenzelm@7895
   733
  to be proven by forward chaining the current facts.  Note that $\HENCENAME$
wenzelm@7895
   734
  is also equivalent to $\FROM{this}~\HAVENAME$.
wenzelm@7895
   735
\item [$\THUSNAME$] abbreviates $\THEN~\SHOWNAME$.  Note that $\THUSNAME$ is
wenzelm@7895
   736
  also equivalent to $\FROM{this}~\SHOWNAME$.
wenzelm@7167
   737
\end{descr}
wenzelm@7167
   738
wenzelm@8991
   739
Note that any goal statement causes some term abbreviations (such as
wenzelm@8991
   740
$\Var{thesis}$, $\dots$) to be bound automatically, see also
wenzelm@8991
   741
\S\ref{sec:term-abbrev}.  Furthermore, the local context of a (non-atomic)
wenzelm@8991
   742
goal is provided via the case name $antecedent$\indexisarcase{antecedent}, see
wenzelm@8991
   743
also \S\ref{sec:cases}.
wenzelm@8991
   744
wenzelm@7167
   745
wenzelm@7167
   746
\subsection{Initial and terminal proof steps}\label{sec:proof-steps}
wenzelm@7167
   747
wenzelm@7175
   748
\indexisarcmd{proof}\indexisarcmd{qed}\indexisarcmd{by}
wenzelm@7175
   749
\indexisarcmd{.}\indexisarcmd{..}\indexisarcmd{sorry}
wenzelm@7175
   750
\begin{matharray}{rcl}
wenzelm@7175
   751
  \isarcmd{proof} & : & \isartrans{proof(prove)}{proof(state)} \\
wenzelm@7175
   752
  \isarcmd{qed} & : & \isartrans{proof(state)}{proof(state) ~|~ theory} \\
wenzelm@7175
   753
  \isarcmd{by} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   754
  \isarcmd{.\,.} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   755
  \isarcmd{.} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   756
  \isarcmd{sorry} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   757
\end{matharray}
wenzelm@7175
   758
wenzelm@8547
   759
Arbitrary goal refinement via tactics is considered harmful.  Properly, the
wenzelm@7335
   760
Isar framework admits proof methods to be invoked in two places only.
wenzelm@7167
   761
\begin{enumerate}
wenzelm@7175
   762
\item An \emph{initial} refinement step $\PROOF{m@1}$ reduces a newly stated
wenzelm@7335
   763
  goal to a number of sub-goals that are to be solved later.  Facts are passed
wenzelm@7895
   764
  to $m@1$ for forward chaining, if so indicated by $proof(chain)$ mode.
wenzelm@7167
   765
  
wenzelm@7987
   766
\item A \emph{terminal} conclusion step $\QED{m@2}$ is intended to solve
wenzelm@7987
   767
  remaining goals.  No facts are passed to $m@2$.
wenzelm@7167
   768
\end{enumerate}
wenzelm@7167
   769
wenzelm@8547
   770
The only other proper way to affect pending goals is by $\SHOWNAME$, which
wenzelm@8547
   771
involves an explicit statement of what is to be solved.
wenzelm@7167
   772
wenzelm@7175
   773
\medskip
wenzelm@7175
   774
wenzelm@7167
   775
Also note that initial proof methods should either solve the goal completely,
wenzelm@7895
   776
or constitute some well-understood reduction to new sub-goals.  Arbitrary
wenzelm@7895
   777
automatic proof tools that are prone leave a large number of badly structured
wenzelm@7895
   778
sub-goals are no help in continuing the proof document in any intelligible
wenzelm@7987
   779
way.
wenzelm@7167
   780
wenzelm@7175
   781
\medskip
wenzelm@7175
   782
wenzelm@8547
   783
Unless given explicitly by the user, the default initial method is ``$rule$'',
wenzelm@8547
   784
which applies a single standard elimination or introduction rule according to
wenzelm@8547
   785
the topmost symbol involved.  There is no separate default terminal method.
wenzelm@8547
   786
Any remaining goals are always solved by assumption in the very last step.
wenzelm@7167
   787
wenzelm@7167
   788
\begin{rail}
wenzelm@7167
   789
  'proof' interest? meth? comment?
wenzelm@7167
   790
  ;
wenzelm@7167
   791
  'qed' meth? comment?
wenzelm@7167
   792
  ;
wenzelm@7167
   793
  'by' meth meth? comment?
wenzelm@7167
   794
  ;
wenzelm@7167
   795
  ('.' | '..' | 'sorry') comment?
wenzelm@7167
   796
  ;
wenzelm@7167
   797
wenzelm@7167
   798
  meth: method interest?
wenzelm@7167
   799
  ;
wenzelm@7167
   800
\end{rail}
wenzelm@7167
   801
wenzelm@7167
   802
\begin{descr}
wenzelm@7335
   803
\item [$\PROOF{m@1}$] refines the goal by proof method $m@1$; facts for
wenzelm@7335
   804
  forward chaining are passed if so indicated by $proof(chain)$ mode.
wenzelm@7335
   805
\item [$\QED{m@2}$] refines any remaining goals by proof method $m@2$ and
wenzelm@7895
   806
  concludes the sub-proof by assumption.  If the goal had been $\SHOWNAME$ (or
wenzelm@7895
   807
  $\THUSNAME$), some pending sub-goal is solved as well by the rule resulting
wenzelm@7895
   808
  from the result \emph{exported} into the enclosing goal context.  Thus
wenzelm@7895
   809
  $\QEDNAME$ may fail for two reasons: either $m@2$ fails, or the resulting
wenzelm@7895
   810
  rule does not fit to any pending goal\footnote{This includes any additional
wenzelm@7895
   811
    ``strong'' assumptions as introduced by $\ASSUMENAME$.} of the enclosing
wenzelm@7895
   812
  context.  Debugging such a situation might involve temporarily changing
wenzelm@7895
   813
  $\SHOWNAME$ into $\HAVENAME$, or weakening the local context by replacing
wenzelm@7895
   814
  some occurrences of $\ASSUMENAME$ by $\PRESUMENAME$.
wenzelm@7895
   815
\item [$\BYY{m@1}{m@2}$] is a \emph{terminal proof}\index{proof!terminal}; it
wenzelm@7987
   816
  abbreviates $\PROOF{m@1}~\QED{m@2}$, with backtracking across both methods,
wenzelm@7987
   817
  though.  Debugging an unsuccessful $\BYY{m@1}{m@2}$ commands might be done
wenzelm@7895
   818
  by expanding its definition; in many cases $\PROOF{m@1}$ is already
wenzelm@7175
   819
  sufficient to see what is going wrong.
wenzelm@7895
   820
\item [``$\DDOT$''] is a \emph{default proof}\index{proof!default}; it
wenzelm@8515
   821
  abbreviates $\BY{rule}$.
wenzelm@7895
   822
\item [``$\DOT$''] is a \emph{trivial proof}\index{proof!trivial}; it
wenzelm@8195
   823
  abbreviates $\BY{this}$.
wenzelm@8379
   824
\item [$\SORRY$] is a \emph{fake proof}\index{proof!fake}; provided that the
wenzelm@8379
   825
  \texttt{quick_and_dirty} flag is enabled, $\SORRY$ pretends to solve the
wenzelm@8515
   826
  goal without further ado.  Of course, the result would be a fake theorem
wenzelm@8515
   827
  only, involving some oracle in its internal derivation object (this is
wenzelm@8515
   828
  indicated as ``$[!]$'' in the printed result).  The main application of
wenzelm@8515
   829
  $\SORRY$ is to support experimentation and top-down proof development.
wenzelm@8515
   830
\end{descr}
wenzelm@8515
   831
wenzelm@8515
   832
wenzelm@8515
   833
\subsection{Fundamental methods and attributes}\label{sec:pure-meth-att}
wenzelm@8515
   834
wenzelm@8547
   835
The following proof methods and attributes refer to basic logical operations
wenzelm@8547
   836
of Isar.  Further methods and attributes are provided by several generic and
wenzelm@8547
   837
object-logic specific tools and packages (see chapters \ref{ch:gen-tools} and
wenzelm@8547
   838
\ref{ch:hol-tools}).
wenzelm@8515
   839
wenzelm@8515
   840
\indexisarmeth{assumption}\indexisarmeth{this}\indexisarmeth{rule}\indexisarmeth{$-$}
wenzelm@8515
   841
\indexisaratt{intro}\indexisaratt{elim}\indexisaratt{dest}
wenzelm@8515
   842
\indexisaratt{OF}\indexisaratt{of}
wenzelm@8515
   843
\begin{matharray}{rcl}
wenzelm@8515
   844
  assumption & : & \isarmeth \\
wenzelm@8515
   845
  this & : & \isarmeth \\
wenzelm@8515
   846
  rule & : & \isarmeth \\
wenzelm@8515
   847
  - & : & \isarmeth \\
wenzelm@8515
   848
  OF & : & \isaratt \\
wenzelm@8515
   849
  of & : & \isaratt \\
wenzelm@8515
   850
  intro & : & \isaratt \\
wenzelm@8515
   851
  elim & : & \isaratt \\
wenzelm@8515
   852
  dest & : & \isaratt \\
wenzelm@8515
   853
  delrule & : & \isaratt \\
wenzelm@8515
   854
\end{matharray}
wenzelm@8515
   855
wenzelm@8515
   856
\begin{rail}
wenzelm@8547
   857
  'rule' thmrefs?
wenzelm@8515
   858
  ;
wenzelm@8515
   859
  'OF' thmrefs
wenzelm@8515
   860
  ;
wenzelm@8693
   861
  'of' insts ('concl' ':' insts)?
wenzelm@8515
   862
  ;
wenzelm@8515
   863
\end{rail}
wenzelm@8515
   864
wenzelm@8515
   865
\begin{descr}
wenzelm@8515
   866
\item [$assumption$] solves some goal by a single assumption step.  Any facts
wenzelm@8515
   867
  given (${} \le 1$) are guaranteed to participate in the refinement.  Recall
wenzelm@8515
   868
  that $\QEDNAME$ (see \S\ref{sec:proof-steps}) already concludes any
wenzelm@8515
   869
  remaining sub-goals by assumption.
wenzelm@8515
   870
\item [$this$] applies all of the current facts directly as rules.  Recall
wenzelm@8515
   871
  that ``$\DOT$'' (dot) abbreviates $\BY{this}$.
wenzelm@8547
   872
\item [$rule~\vec a$] applies some rule given as argument in backward manner;
wenzelm@8515
   873
  facts are used to reduce the rule before applying it to the goal.  Thus
wenzelm@8515
   874
  $rule$ without facts is plain \emph{introduction}, while with facts it
wenzelm@8515
   875
  becomes \emph{elimination}.
wenzelm@8515
   876
  
wenzelm@8547
   877
  When no arguments are given, the $rule$ method tries to pick appropriate
wenzelm@8547
   878
  rules automatically, as declared in the current context using the $intro$,
wenzelm@8547
   879
  $elim$, $dest$ attributes (see below).  This is the default behavior of
wenzelm@8547
   880
  $\PROOFNAME$ and ``$\DDOT$'' (double-dot) steps (see
wenzelm@8515
   881
  \S\ref{sec:proof-steps}).
wenzelm@8515
   882
\item [``$-$''] does nothing but insert the forward chaining facts as premises
wenzelm@8515
   883
  into the goal.  Note that command $\PROOFNAME$ without any method actually
wenzelm@8515
   884
  performs a single reduction step using the $rule$ method; thus a plain
wenzelm@8515
   885
  \emph{do-nothing} proof step would be $\PROOF{-}$ rather than $\PROOFNAME$
wenzelm@8515
   886
  alone.
wenzelm@8547
   887
\item [$OF~\vec a$] applies some theorem to given rules $\vec a$ (in
wenzelm@8547
   888
  parallel).  This corresponds to the \texttt{MRS} operator in ML
wenzelm@8547
   889
  \cite[\S5]{isabelle-ref}, but note the reversed order.  Positions may be
wenzelm@8547
   890
  skipped by including ``$\_$'' (underscore) as argument.
wenzelm@8547
   891
\item [$of~\vec t$] performs positional instantiation.  The terms $\vec t$ are
wenzelm@8515
   892
  substituted for any schematic variables occurring in a theorem from left to
wenzelm@8515
   893
  right; ``\texttt{_}'' (underscore) indicates to skip a position.  Arguments
wenzelm@8515
   894
  following a ``$concl\colon$'' specification refer to positions of the
wenzelm@8515
   895
  conclusion of a rule.
wenzelm@8515
   896
\item [$intro$, $elim$, and $dest$] declare introduction, elimination, and
wenzelm@8515
   897
  destruct rules, respectively.  Note that the classical reasoner (see
wenzelm@8515
   898
  \S\ref{sec:classical-basic}) introduces different versions of these
wenzelm@8515
   899
  attributes, and the $rule$ method, too.  In object-logics with classical
wenzelm@8515
   900
  reasoning enabled, the latter version should be used all the time to avoid
wenzelm@8515
   901
  confusion!
wenzelm@8515
   902
\item [$delrule$] undeclares introduction or elimination rules.
wenzelm@7315
   903
\end{descr}
wenzelm@7315
   904
wenzelm@7315
   905
wenzelm@7315
   906
\subsection{Term abbreviations}\label{sec:term-abbrev}
wenzelm@7315
   907
wenzelm@7315
   908
\indexisarcmd{let}
wenzelm@7315
   909
\begin{matharray}{rcl}
wenzelm@7315
   910
  \isarcmd{let} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7315
   911
  \isarkeyword{is} & : & syntax \\
wenzelm@7315
   912
\end{matharray}
wenzelm@7315
   913
wenzelm@7315
   914
Abbreviations may be either bound by explicit $\LET{p \equiv t}$ statements,
wenzelm@7987
   915
or by annotating assumptions or goal statements with a list of patterns
wenzelm@7987
   916
$\ISS{p@1\;\dots}{p@n}$.  In both cases, higher-order matching is invoked to
wenzelm@7987
   917
bind extra-logical term variables, which may be either named schematic
wenzelm@7987
   918
variables of the form $\Var{x}$, or nameless dummies ``\texttt{_}''
wenzelm@7987
   919
(underscore).\indexisarvar{_@\texttt{_}} Note that in the $\LETNAME$ form the
wenzelm@7987
   920
patterns occur on the left-hand side, while the $\ISNAME$ patterns are in
wenzelm@7987
   921
postfix position.
wenzelm@7315
   922
wenzelm@8620
   923
Polymorphism of term bindings is handled in Hindley-Milner style, as in ML.
wenzelm@8620
   924
Type variables referring to local assumptions or open goal statements are
wenzelm@8620
   925
\emph{fixed}, while those of finished results or bound by $\LETNAME$ may occur
wenzelm@8620
   926
in \emph{arbitrary} instances later.  Even though actual polymorphism should
wenzelm@8620
   927
be rarely used in practice, this mechanism is essential to achieve proper
wenzelm@8620
   928
incremental type-inference, as the user proceeds to build up the Isar proof
wenzelm@8620
   929
text.
wenzelm@8620
   930
wenzelm@8620
   931
\medskip
wenzelm@8620
   932
wenzelm@7319
   933
Term abbreviations are quite different from actual local definitions as
wenzelm@7319
   934
introduced via $\DEFNAME$ (see \S\ref{sec:proof-context}).  The latter are
wenzelm@7315
   935
visible within the logic as actual equations, while abbreviations disappear
wenzelm@8620
   936
during the input process just after type checking.  Also note that $\DEFNAME$
wenzelm@8620
   937
does not support polymorphism.
wenzelm@7315
   938
wenzelm@7315
   939
\begin{rail}
wenzelm@8664
   940
  'let' ((term + 'and') '=' term comment? + 'and')
wenzelm@7315
   941
  ;  
wenzelm@7315
   942
\end{rail}
wenzelm@7315
   943
wenzelm@7315
   944
The syntax of $\ISNAME$ patterns follows \railnonterm{termpat} or
wenzelm@7315
   945
\railnonterm{proppat} (see \S\ref{sec:term-pats}).
wenzelm@7315
   946
wenzelm@7315
   947
\begin{descr}
wenzelm@7315
   948
\item [$\LET{\vec p = \vec t}$] binds any text variables in patters $\vec p$
wenzelm@7315
   949
  by simultaneous higher-order matching against terms $\vec t$.
wenzelm@7315
   950
\item [$\IS{\vec p}$] resembles $\LETNAME$, but matches $\vec p$ against the
wenzelm@7315
   951
  preceding statement.  Also note that $\ISNAME$ is not a separate command,
wenzelm@7315
   952
  but part of others (such as $\ASSUMENAME$, $\HAVENAME$ etc.).
wenzelm@7315
   953
\end{descr}
wenzelm@7315
   954
wenzelm@7988
   955
A few \emph{automatic} term abbreviations\index{term abbreviations} for goals
wenzelm@7988
   956
and facts are available as well.  For any open goal,
wenzelm@7466
   957
$\Var{thesis_prop}$\indexisarvar{thesis-prop} refers to the full proposition
wenzelm@7466
   958
(which may be a rule), $\Var{thesis_concl}$\indexisarvar{thesis-concl} to its
wenzelm@7466
   959
(atomic) conclusion, and $\Var{thesis}$\indexisarvar{thesis} to its
wenzelm@8547
   960
object-level statement.  The latter two abstract over any meta-level
wenzelm@7987
   961
parameters.
wenzelm@7315
   962
wenzelm@7466
   963
Fact statements resulting from assumptions or finished goals are bound as
wenzelm@7466
   964
$\Var{this_prop}$\indexisarvar{this-prop},
wenzelm@7466
   965
$\Var{this_concl}$\indexisarvar{this-concl}, and
wenzelm@7466
   966
$\Var{this}$\indexisarvar{this}, similar to $\Var{thesis}$ above.  In case
wenzelm@7466
   967
$\Var{this}$ refers to an object-logic statement that is an application
wenzelm@7895
   968
$f(t)$, then $t$ is bound to the special text variable
wenzelm@7466
   969
``$\dots$''\indexisarvar{\dots} (three dots).  The canonical application of
wenzelm@7987
   970
the latter are calculational proofs (see \S\ref{sec:calculation}).
wenzelm@7315
   971
wenzelm@7315
   972
wenzelm@7134
   973
\subsection{Block structure}
wenzelm@7134
   974
wenzelm@8896
   975
\indexisarcmd{next}\indexisarcmd{\{}\indexisarcmd{\}}
wenzelm@7397
   976
\begin{matharray}{rcl}
wenzelm@8448
   977
  \NEXT & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7974
   978
  \BG & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7974
   979
  \EN & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7397
   980
\end{matharray}
wenzelm@7397
   981
wenzelm@9030
   982
\railalias{lbrace}{\ttlbrace}
wenzelm@9030
   983
\railterm{lbrace}
wenzelm@9030
   984
wenzelm@9030
   985
\railalias{rbrace}{\ttrbrace}
wenzelm@9030
   986
\railterm{rbrace}
wenzelm@9030
   987
wenzelm@9030
   988
\begin{rail}
wenzelm@9030
   989
  'next' comment?
wenzelm@9030
   990
  ;
wenzelm@9030
   991
  lbrace comment?
wenzelm@9030
   992
  ;
wenzelm@9030
   993
  rbrace comment?
wenzelm@9030
   994
  ;
wenzelm@9030
   995
\end{rail}
wenzelm@9030
   996
wenzelm@7167
   997
While Isar is inherently block-structured, opening and closing blocks is
wenzelm@7167
   998
mostly handled rather casually, with little explicit user-intervention.  Any
wenzelm@7167
   999
local goal statement automatically opens \emph{two} blocks, which are closed
wenzelm@7167
  1000
again when concluding the sub-proof (by $\QEDNAME$ etc.).  Sections of
wenzelm@8448
  1001
different context within a sub-proof may be switched via $\NEXT$, which is
wenzelm@8448
  1002
just a single block-close followed by block-open again.  Thus the effect of
wenzelm@8448
  1003
$\NEXT$ to reset the local proof context. There is no goal focus involved
wenzelm@8448
  1004
here!
wenzelm@7167
  1005
wenzelm@7175
  1006
For slightly more advanced applications, there are explicit block parentheses
wenzelm@7895
  1007
as well.  These typically achieve a stronger forward style of reasoning.
wenzelm@7167
  1008
wenzelm@7167
  1009
\begin{descr}
wenzelm@8448
  1010
\item [$\NEXT$] switches to a fresh block within a sub-proof, resetting the
wenzelm@8448
  1011
  local context to the initial one.
wenzelm@8896
  1012
\item [$\BG$ and $\EN$] explicitly open and close blocks.  Any current facts
wenzelm@8896
  1013
  pass through ``$\BG$'' unchanged, while ``$\EN$'' causes any result to be
wenzelm@7895
  1014
  \emph{exported} into the enclosing context.  Thus fixed variables are
wenzelm@7895
  1015
  generalized, assumptions discharged, and local definitions unfolded (cf.\ 
wenzelm@7895
  1016
  \S\ref{sec:proof-context}).  There is no difference of $\ASSUMENAME$ and
wenzelm@7895
  1017
  $\PRESUMENAME$ in this mode of forward reasoning --- in contrast to plain
wenzelm@7895
  1018
  backward reasoning with the result exported at $\SHOWNAME$ time.
wenzelm@7167
  1019
\end{descr}
wenzelm@7134
  1020
wenzelm@7134
  1021
wenzelm@8533
  1022
\subsection{Emulating tactic scripts}\label{sec:tactical-proof}
wenzelm@8515
  1023
wenzelm@8515
  1024
The following elements emulate unstructured tactic scripts to some extent.
wenzelm@8515
  1025
While these are anathema for writing proper Isar proof documents, they might
wenzelm@8515
  1026
come in handy for interactive exploration and debugging, or even actual
wenzelm@8515
  1027
tactical proof within new-style theories (to benefit from document
wenzelm@8515
  1028
preparation, for example).
wenzelm@8515
  1029
wenzelm@8946
  1030
\indexisarcmd{apply}\indexisarcmd{done}\indexisarcmd{apply-end}
wenzelm@8515
  1031
\indexisarcmd{defer}\indexisarcmd{prefer}\indexisarcmd{back}
wenzelm@8515
  1032
\begin{matharray}{rcl}
wenzelm@8533
  1033
  \isarcmd{apply}^* & : & \isartrans{proof(prove)}{proof(prove)} \\
wenzelm@8946
  1034
  \isarcmd{done}^* & : & \isartrans{proof(prove)}{proof(state)} \\
wenzelm@8533
  1035
  \isarcmd{apply_end}^* & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@8533
  1036
  \isarcmd{defer}^* & : & \isartrans{proof}{proof} \\
wenzelm@8533
  1037
  \isarcmd{prefer}^* & : & \isartrans{proof}{proof} \\
wenzelm@8533
  1038
  \isarcmd{back}^* & : & \isartrans{proof}{proof} \\
wenzelm@8515
  1039
\end{matharray}
wenzelm@8515
  1040
wenzelm@8515
  1041
\railalias{applyend}{apply\_end}
wenzelm@8515
  1042
\railterm{applyend}
wenzelm@8515
  1043
wenzelm@8515
  1044
\begin{rail}
wenzelm@8682
  1045
  'apply' method comment?
wenzelm@8515
  1046
  ;
wenzelm@8946
  1047
  'done' comment?
wenzelm@8946
  1048
  ;
wenzelm@8682
  1049
  applyend method comment?
wenzelm@8515
  1050
  ;
wenzelm@8682
  1051
  'defer' nat? comment?
wenzelm@8515
  1052
  ;
wenzelm@8682
  1053
  'prefer' nat comment?
wenzelm@8515
  1054
  ;
wenzelm@9273
  1055
  'back' comment?
wenzelm@9273
  1056
  ;
wenzelm@8515
  1057
\end{rail}
wenzelm@8515
  1058
wenzelm@8515
  1059
\begin{descr}
wenzelm@8547
  1060
\item [$\isarkeyword{apply}~(m)$] applies proof method $m$ in initial
wenzelm@8547
  1061
  position, but unlike $\PROOFNAME$ it retains ``$proof(prove)$'' mode.  Thus
wenzelm@8946
  1062
  consecutive method applications may be given just as in tactic scripts.
wenzelm@8515
  1063
  
wenzelm@8881
  1064
  Facts are passed to $m$ as indicated by the goal's forward-chain mode, and
wenzelm@8881
  1065
  are \emph{consumed} afterwards.  Thus any further $\isarkeyword{apply}$
wenzelm@8881
  1066
  command would always work in a purely backward manner.
wenzelm@8946
  1067
  
wenzelm@8946
  1068
\item [$\isarkeyword{done}$] completes a proof script, provided that the
wenzelm@8947
  1069
  current goal state is already solved completely.  Note that actual
wenzelm@8947
  1070
  structured proof commands (e.g.\ ``$\DOT$'' or $\SORRY$) may be used to
wenzelm@8947
  1071
  conclude proof scripts as well.
wenzelm@8881
  1072
wenzelm@8515
  1073
\item [$\isarkeyword{apply_end}~(m)$] applies proof method $m$ as if in
wenzelm@8515
  1074
  terminal position.  Basically, this simulates a multi-step tactic script for
wenzelm@8515
  1075
  $\QEDNAME$, but may be given anywhere within the proof body.
wenzelm@8515
  1076
  
wenzelm@8515
  1077
  No facts are passed to $m$.  Furthermore, the static context is that of the
wenzelm@8515
  1078
  enclosing goal (as for actual $\QEDNAME$).  Thus the proof method may not
wenzelm@8515
  1079
  refer to any assumptions introduced in the current body, for example.
wenzelm@8515
  1080
\item [$\isarkeyword{defer}~n$ and $\isarkeyword{prefer}~n$] shuffle the list
wenzelm@8515
  1081
  of pending goals: $defer$ puts off goal $n$ to the end of the list ($n = 1$
wenzelm@8515
  1082
  by default), while $prefer$ brings goal $n$ to the top.
wenzelm@8515
  1083
\item [$\isarkeyword{back}$] does back-tracking over the result sequence of
wenzelm@8515
  1084
  the latest proof command.\footnote{Unlike the ML function \texttt{back}
wenzelm@8515
  1085
    \cite{isabelle-ref}, the Isar command does not search upwards for further
wenzelm@8515
  1086
    branch points.} Basically, any proof command may return multiple results.
wenzelm@9006
  1087
\end{descr}
wenzelm@9006
  1088
wenzelm@9006
  1089
Any proper Isar proof method may be used with tactic script commands such as
wenzelm@9006
  1090
$\isarkeyword{apply}$.  A few additional emulations of actual tactics are
wenzelm@9006
  1091
provided as well; these would be never used in actual structured proofs, of
wenzelm@9006
  1092
course.
wenzelm@9006
  1093
wenzelm@9006
  1094
\indexisarmeth{tactic}\indexisarmeth{insert}
wenzelm@9006
  1095
\indexisarmeth{res-inst-tac}\indexisarmeth{eres-inst-tac}
wenzelm@9006
  1096
\indexisarmeth{dres-inst-tac}\indexisarmeth{forw-inst-tac}
wenzelm@9006
  1097
\indexisarmeth{subgoal-tac}
wenzelm@9006
  1098
\begin{matharray}{rcl}
wenzelm@9006
  1099
  tactic^* & : & \isarmeth \\
wenzelm@9006
  1100
  insert^* & : & \isarmeth \\
wenzelm@9006
  1101
  res_inst_tac^* & : & \isarmeth \\
wenzelm@9006
  1102
  eres_inst_tac^* & : & \isarmeth \\
wenzelm@9006
  1103
  dres_inst_tac^* & : & \isarmeth \\
wenzelm@9006
  1104
  forw_inst_tac^* & : & \isarmeth \\
wenzelm@9006
  1105
  subgoal_tac^* & : & \isarmeth \\
wenzelm@9006
  1106
\end{matharray}
wenzelm@9006
  1107
wenzelm@9006
  1108
\railalias{resinsttac}{res\_inst\_tac}
wenzelm@9006
  1109
\railterm{resinsttac}
wenzelm@9006
  1110
wenzelm@9006
  1111
\railalias{eresinsttac}{eres\_inst\_tac}
wenzelm@9006
  1112
\railterm{eresinsttac}
wenzelm@9006
  1113
wenzelm@9006
  1114
\railalias{dresinsttac}{dres\_inst\_tac}
wenzelm@9006
  1115
\railterm{dresinsttac}
wenzelm@9006
  1116
wenzelm@9006
  1117
\railalias{forwinsttac}{forw\_inst\_tac}
wenzelm@9006
  1118
\railterm{forwinsttac}
wenzelm@9006
  1119
wenzelm@9006
  1120
\railalias{subgoaltac}{subgoal\_tac}
wenzelm@9006
  1121
\railterm{subgoaltac}
wenzelm@9006
  1122
wenzelm@9006
  1123
\begin{rail}
wenzelm@9006
  1124
  'tactic' text
wenzelm@9006
  1125
  ;
wenzelm@9006
  1126
  'insert' thmrefs
wenzelm@9006
  1127
  ;
wenzelm@9006
  1128
  ( resinsttac | eresinsttac | dresinsttac | forwinsttac ) goalspec? \\
wenzelm@9006
  1129
    ((name '=' term) + 'and') 'in' thmref
wenzelm@9006
  1130
  ;
wenzelm@9006
  1131
  subgoaltac goalspec? prop
wenzelm@9006
  1132
  ;
wenzelm@9006
  1133
\end{rail}
wenzelm@9006
  1134
wenzelm@9006
  1135
\begin{descr}
wenzelm@8515
  1136
\item [$tactic~text$] produces a proof method from any ML text of type
wenzelm@8547
  1137
  \texttt{tactic}.  Apart from the usual ML environment and the current
wenzelm@8515
  1138
  implicit theory context, the ML code may refer to the following locally
wenzelm@8515
  1139
  bound values:
wenzelm@9006
  1140
wenzelm@8515
  1141
%%FIXME ttbox produces too much trailing space (why?)
wenzelm@8515
  1142
{\footnotesize\begin{verbatim}
wenzelm@8515
  1143
val ctxt  : Proof.context
wenzelm@8515
  1144
val facts : thm list
wenzelm@8515
  1145
val thm   : string -> thm
wenzelm@8515
  1146
val thms  : string -> thm list
wenzelm@8515
  1147
\end{verbatim}}
wenzelm@8515
  1148
  Here \texttt{ctxt} refers to the current proof context, \texttt{facts}
wenzelm@8515
  1149
  indicates any current facts for forward-chaining, and
wenzelm@8515
  1150
  \texttt{thm}~/~\texttt{thms} retrieve named facts (including global
wenzelm@8515
  1151
  theorems) from the context.
wenzelm@8696
  1152
\item [$insert~\vec a$] inserts theorems as facts into all goals of the proof
wenzelm@8696
  1153
  state; the current facts indicated for forward chaining are ignored!
wenzelm@8533
  1154
\item [$res_inst_tac$ etc.] do resolution of rules with explicit
wenzelm@8533
  1155
  instantiation.  This works the same way as the corresponding ML tactics, see
wenzelm@8533
  1156
  \cite[\S3]{isabelle-ref}.
wenzelm@8533
  1157
  
wenzelm@8533
  1158
  It is very important to note that the instantiations are read and
wenzelm@8533
  1159
  type-checked according to the dynamic goal state, rather than the static
wenzelm@8533
  1160
  proof context!  In particular, locally fixed variables and term
wenzelm@8533
  1161
  abbreviations may not be included in the term specifications.
wenzelm@8547
  1162
\item [$subgoal_tac~\phi$] emulates the ML tactic of the same name, see
wenzelm@8533
  1163
  \cite[\S3]{isabelle-ref}.  Syntactically, the given proposition is handled
wenzelm@8533
  1164
  as the instantiations in $res_inst_tac$ etc.
wenzelm@8533
  1165
  
wenzelm@8533
  1166
  Note that the proper Isar command $\PRESUMENAME$ achieves a similar effect
wenzelm@8533
  1167
  as $subgoal_tac$.
wenzelm@8515
  1168
\end{descr}
wenzelm@8515
  1169
wenzelm@8515
  1170
wenzelm@8515
  1171
\subsection{Meta-linguistic features}
wenzelm@8515
  1172
wenzelm@8515
  1173
\indexisarcmd{oops}
wenzelm@8515
  1174
\begin{matharray}{rcl}
wenzelm@8515
  1175
  \isarcmd{oops} & : & \isartrans{proof}{theory} \\
wenzelm@8515
  1176
\end{matharray}
wenzelm@8515
  1177
wenzelm@8515
  1178
The $\OOPS$ command discontinues the current proof attempt, while considering
wenzelm@8515
  1179
the partial proof text as properly processed.  This is conceptually quite
wenzelm@8515
  1180
different from ``faking'' actual proofs via $\SORRY$ (see
wenzelm@8515
  1181
\S\ref{sec:proof-steps}): $\OOPS$ does not observe the proof structure at all,
wenzelm@8515
  1182
but goes back right to the theory level.  Furthermore, $\OOPS$ does not
wenzelm@8515
  1183
produce any result theorem --- there is no claim to be able to complete the
wenzelm@8515
  1184
proof anyhow.
wenzelm@8515
  1185
wenzelm@8515
  1186
A typical application of $\OOPS$ is to explain Isar proofs \emph{within} the
wenzelm@8515
  1187
system itself, in conjunction with the document preparation tools of Isabelle
wenzelm@8515
  1188
described in \cite{isabelle-sys}.  Thus partial or even wrong proof attempts
wenzelm@8515
  1189
can be discussed in a logically sound manner.  Note that the Isabelle {\LaTeX}
wenzelm@8515
  1190
macros can be easily adapted to print something like ``$\dots$'' instead of an
wenzelm@8515
  1191
``$\OOPS$'' keyword.
wenzelm@8515
  1192
wenzelm@8547
  1193
\medskip The $\OOPS$ command is undoable, unlike $\isarkeyword{kill}$ (see
wenzelm@8547
  1194
\S\ref{sec:history}).  The effect is to get back to the theory \emph{before}
wenzelm@8547
  1195
the opening of the proof.
wenzelm@8515
  1196
wenzelm@8515
  1197
wenzelm@7134
  1198
\section{Other commands}
wenzelm@7134
  1199
wenzelm@8448
  1200
\subsection{Diagnostics}\label{sec:diag}
wenzelm@7134
  1201
wenzelm@8485
  1202
\indexisarcmd{pr}\indexisarcmd{thm}\indexisarcmd{term}\indexisarcmd{prop}\indexisarcmd{typ}
wenzelm@8485
  1203
\indexisarcmd{print-facts}\indexisarcmd{print-binds}
wenzelm@7134
  1204
\begin{matharray}{rcl}
wenzelm@8515
  1205
  \isarcmd{pr}^* & : & \isarkeep{\cdot} \\
wenzelm@8515
  1206
  \isarcmd{thm}^* & : & \isarkeep{theory~|~proof} \\
wenzelm@8515
  1207
  \isarcmd{term}^* & : & \isarkeep{theory~|~proof} \\
wenzelm@8515
  1208
  \isarcmd{prop}^* & : & \isarkeep{theory~|~proof} \\
wenzelm@8515
  1209
  \isarcmd{typ}^* & : & \isarkeep{theory~|~proof} \\
wenzelm@8515
  1210
  \isarcmd{print_facts}^* & : & \isarkeep{proof} \\
wenzelm@8515
  1211
  \isarcmd{print_binds}^* & : & \isarkeep{proof} \\
wenzelm@7134
  1212
\end{matharray}
wenzelm@7134
  1213
wenzelm@7335
  1214
These commands are not part of the actual Isabelle/Isar syntax, but assist
wenzelm@7335
  1215
interactive development.  Also note that $undo$ does not apply here, since the
wenzelm@7335
  1216
theory or proof configuration is not changed.
wenzelm@7335
  1217
wenzelm@7134
  1218
\begin{rail}
wenzelm@8485
  1219
  'pr' modes? nat?
wenzelm@7134
  1220
  ;
wenzelm@8485
  1221
  'thm' modes? thmrefs
wenzelm@8485
  1222
  ;
wenzelm@8485
  1223
  'term' modes? term
wenzelm@7134
  1224
  ;
wenzelm@8485
  1225
  'prop' modes? prop
wenzelm@7134
  1226
  ;
wenzelm@8485
  1227
  'typ' modes? type
wenzelm@8485
  1228
  ;
wenzelm@8485
  1229
wenzelm@8485
  1230
  modes: '(' (name + ) ')'
wenzelm@7134
  1231
  ;
wenzelm@7134
  1232
\end{rail}
wenzelm@7134
  1233
wenzelm@7167
  1234
\begin{descr}
wenzelm@8883
  1235
\item [$\isarkeyword{pr}~n$] prints the current proof state (if present),
wenzelm@8883
  1236
  including the proof context, current facts and goals.  The optional argument
wenzelm@8883
  1237
  $n$ affects the implicit limit of goals to be displayed, which is initially
wenzelm@8883
  1238
  10.  Omitting the limit leaves the current value unchanged.
wenzelm@8547
  1239
\item [$\isarkeyword{thm}~\vec a$] retrieves theorems from the current theory
wenzelm@8547
  1240
  or proof context.  Note that any attributes included in the theorem
wenzelm@7974
  1241
  specifications are applied to a temporary context derived from the current
wenzelm@8547
  1242
  theory or proof; the result is discarded, i.e.\ attributes involved in $\vec
wenzelm@8547
  1243
  a$ do not have any permanent effect.
wenzelm@7987
  1244
\item [$\isarkeyword{term}~t$, $\isarkeyword{prop}~\phi$] read, type-check and
wenzelm@7987
  1245
  print terms or propositions according to the current theory or proof
wenzelm@7895
  1246
  context; the inferred type of $t$ is output as well.  Note that these
wenzelm@7895
  1247
  commands are also useful in inspecting the current environment of term
wenzelm@7895
  1248
  abbreviations.
wenzelm@7974
  1249
\item [$\isarkeyword{typ}~\tau$] reads and prints types of the meta-logic
wenzelm@7974
  1250
  according to the current theory or proof context.
wenzelm@8379
  1251
\item [$\isarkeyword{print_facts}$] prints any named facts of the current
wenzelm@8379
  1252
  context, including assumptions and local results.
wenzelm@8379
  1253
\item [$\isarkeyword{print_binds}$] prints all term abbreviations present in
wenzelm@8379
  1254
  the context.
wenzelm@8485
  1255
\end{descr}
wenzelm@8485
  1256
wenzelm@8485
  1257
The basic diagnostic commands above admit a list of $modes$ to be specified,
wenzelm@8485
  1258
which is appended to the current print mode (see also \cite{isabelle-ref}).
wenzelm@8485
  1259
Thus the output behavior may be modified according particular print mode
wenzelm@8485
  1260
features.
wenzelm@8485
  1261
wenzelm@8485
  1262
For example, $\isarkeyword{pr}~(latex~xsymbols~symbols)$ would print the
wenzelm@8485
  1263
current proof state with mathematical symbols and special characters
wenzelm@8485
  1264
represented in {\LaTeX} source, according to the Isabelle style
wenzelm@8547
  1265
\cite{isabelle-sys}.  The resulting text can be directly pasted into a
wenzelm@8547
  1266
\verb,\begin{isabelle},\dots\verb,\end{isabelle}, environment.  Note that
wenzelm@8547
  1267
$\isarkeyword{pr}~(latex)$ is sufficient to achieve the same output, if the
wenzelm@8547
  1268
current Isabelle session has the other modes already activated, say due to
wenzelm@8547
  1269
some particular user interface configuration such as Proof~General
wenzelm@8510
  1270
\cite{proofgeneral,Aspinall:TACAS:2000} with X-Symbol mode \cite{x-symbol}.
wenzelm@8485
  1271
wenzelm@8485
  1272
wenzelm@8485
  1273
\subsection{History commands}\label{sec:history}
wenzelm@8485
  1274
wenzelm@8485
  1275
\indexisarcmd{undo}\indexisarcmd{redo}\indexisarcmd{kill}
wenzelm@8485
  1276
\begin{matharray}{rcl}
wenzelm@8485
  1277
  \isarcmd{undo}^{{*}{*}} & : & \isarkeep{\cdot} \\
wenzelm@8485
  1278
  \isarcmd{redo}^{{*}{*}} & : & \isarkeep{\cdot} \\
wenzelm@8485
  1279
  \isarcmd{kill}^{{*}{*}} & : & \isarkeep{\cdot} \\
wenzelm@8485
  1280
\end{matharray}
wenzelm@8485
  1281
wenzelm@8485
  1282
The Isabelle/Isar top-level maintains a two-stage history, for theory and
wenzelm@8485
  1283
proof state transformation.  Basically, any command can be undone using
wenzelm@8485
  1284
$\isarkeyword{undo}$, excluding mere diagnostic elements.  Its effect may be
wenzelm@8485
  1285
revoked via $\isarkeyword{redo}$, unless the corresponding the
wenzelm@8485
  1286
$\isarkeyword{undo}$ step has crossed the beginning of a proof or theory.  The
wenzelm@8485
  1287
$\isarkeyword{kill}$ command aborts the current history node altogether,
wenzelm@8485
  1288
discontinuing a proof or even the whole theory.  This operation is \emph{not}
wenzelm@8485
  1289
undoable.
wenzelm@8485
  1290
wenzelm@8485
  1291
\begin{warn}
wenzelm@8547
  1292
  History commands should never be used with user interfaces such as
wenzelm@8547
  1293
  Proof~General \cite{proofgeneral,Aspinall:TACAS:2000}, which takes care of
wenzelm@8547
  1294
  stepping forth and back itself.  Interfering by manual $\isarkeyword{undo}$,
wenzelm@8510
  1295
  $\isarkeyword{redo}$, or even $\isarkeyword{kill}$ commands would quickly
wenzelm@8510
  1296
  result in utter confusion.
wenzelm@8485
  1297
\end{warn}
wenzelm@8485
  1298
wenzelm@8379
  1299
wenzelm@7134
  1300
\subsection{System operations}
wenzelm@7134
  1301
wenzelm@7167
  1302
\indexisarcmd{cd}\indexisarcmd{pwd}\indexisarcmd{use-thy}\indexisarcmd{use-thy-only}
wenzelm@7167
  1303
\indexisarcmd{update-thy}\indexisarcmd{update-thy-only}
wenzelm@7134
  1304
\begin{matharray}{rcl}
wenzelm@8515
  1305
  \isarcmd{cd}^* & : & \isarkeep{\cdot} \\
wenzelm@8515
  1306
  \isarcmd{pwd}^* & : & \isarkeep{\cdot} \\
wenzelm@8515
  1307
  \isarcmd{use_thy}^* & : & \isarkeep{\cdot} \\
wenzelm@8515
  1308
  \isarcmd{use_thy_only}^* & : & \isarkeep{\cdot} \\
wenzelm@8515
  1309
  \isarcmd{update_thy}^* & : & \isarkeep{\cdot} \\
wenzelm@8515
  1310
  \isarcmd{update_thy_only}^* & : & \isarkeep{\cdot} \\
wenzelm@7134
  1311
\end{matharray}
wenzelm@7134
  1312
wenzelm@7167
  1313
\begin{descr}
wenzelm@7134
  1314
\item [$\isarkeyword{cd}~name$] changes the current directory of the Isabelle
wenzelm@7134
  1315
  process.
wenzelm@7134
  1316
\item [$\isarkeyword{pwd}~$] prints the current working directory.
wenzelm@7175
  1317
\item [$\isarkeyword{use_thy}$, $\isarkeyword{use_thy_only}$,
wenzelm@7987
  1318
  $\isarkeyword{update_thy}$, $\isarkeyword{update_thy_only}$] load some
wenzelm@7895
  1319
  theory given as $name$ argument.  These commands are basically the same as
wenzelm@7987
  1320
  the corresponding ML functions\footnote{The ML versions also change the
wenzelm@7987
  1321
    implicit theory context to that of the theory loaded.}  (see also
wenzelm@7987
  1322
  \cite[\S1,\S6]{isabelle-ref}).  Note that both the ML and Isar versions may
wenzelm@7987
  1323
  load new- and old-style theories alike.
wenzelm@7167
  1324
\end{descr}
wenzelm@7134
  1325
wenzelm@7987
  1326
These system commands are scarcely used when working with the Proof~General
wenzelm@7987
  1327
interface, since loading of theories is done fully transparently.
wenzelm@7134
  1328
wenzelm@8379
  1329
wenzelm@7046
  1330
%%% Local Variables: 
wenzelm@7046
  1331
%%% mode: latex
wenzelm@7046
  1332
%%% TeX-master: "isar-ref"
wenzelm@7046
  1333
%%% End: