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