doc-src/IsarRef/pure.tex
author wenzelm
Sun Aug 22 21:13:20 1999 +0200 (1999-08-22)
changeset 7315 76a39a3784b5
parent 7175 8263d0b50e12
child 7319 3907d597cae6
permissions -rw-r--r--
checkpoint;
wenzelm@7046
     1
wenzelm@7315
     2
\chapter{Basic Isar elements}\label{ch:pure-syntax}
wenzelm@7167
     3
wenzelm@7315
     4
Subsequently, we introduce the main part of the basic Isar theory and proof
wenzelm@7315
     5
commands as provided by Isabelle/Pure.  Chapter~\ref{ch:gen-tools} describes
wenzelm@7315
     6
further Isar elements as provided by generic tools and packages that are
wenzelm@7315
     7
either part of Pure Isabelle, or pre-loaded by most object logics (such as the
wenzelm@7315
     8
Simplifier).  See chapter~\ref{ch:hol-tools} for actual object-logic specific
wenzelm@7315
     9
elements (for Isabelle/HOL).
wenzelm@7046
    10
wenzelm@7167
    11
\medskip
wenzelm@7167
    12
wenzelm@7167
    13
Isar commands may be either \emph{proper} document constructors, or
wenzelm@7175
    14
\emph{improper commands} (indicated by $^*$).  Some proof methods and
wenzelm@7175
    15
attributes introduced later may be classified as improper as well.  Improper
wenzelm@7175
    16
Isar language elements might be helpful when developing proof documents, while
wenzelm@7175
    17
their use is strongly discouraged for the final version.  Typical examples are
wenzelm@7175
    18
diagnostic commands that print terms or theorems according to the current
wenzelm@7175
    19
context; other commands even emulate old-style tactical theorem proving, which
wenzelm@7175
    20
facilitates porting of legacy proof scripts.
wenzelm@7167
    21
wenzelm@7134
    22
wenzelm@7134
    23
\section{Theory commands}
wenzelm@7134
    24
wenzelm@7167
    25
\subsection{Defining theories}\label{sec:begin-thy}
wenzelm@7134
    26
wenzelm@7134
    27
\indexisarcmd{theory}\indexisarcmd{end}\indexisarcmd{context}
wenzelm@7134
    28
\begin{matharray}{rcl}
wenzelm@7134
    29
  \isarcmd{theory} & : & \isartrans{\cdot}{theory} \\
wenzelm@7134
    30
  \isarcmd{context}^* & : & \isartrans{\cdot}{theory} \\
wenzelm@7134
    31
  \isarcmd{end} & : & \isartrans{theory}{\cdot} \\
wenzelm@7134
    32
\end{matharray}
wenzelm@7134
    33
wenzelm@7134
    34
Isabelle/Isar ``new-style'' theories are either defined via theory files or
wenzelm@7167
    35
interactively.  Both actual theory specifications and proofs are handled
wenzelm@7175
    36
uniformly --- occasionally definitional mechanisms even require some manual
wenzelm@7175
    37
proof.  In contrast, ``old-style'' Isabelle theories support batch processing
wenzelm@7175
    38
only, with the proof scripts collected in separate ML files.
wenzelm@7134
    39
wenzelm@7134
    40
The first command of any theory has to be $\THEORY$, starting a new theory
wenzelm@7175
    41
based on the merge of existing ones.  The theory context may be also changed
wenzelm@7175
    42
by $\CONTEXT$ without creating a new theory.  In both cases, $\END$ concludes
wenzelm@7175
    43
the theory development; it has to be the very last command of any proper
wenzelm@7175
    44
theory file.
wenzelm@7134
    45
wenzelm@7134
    46
\begin{rail}
wenzelm@7134
    47
  'theory' name '=' (name + '+') filespecs? ':'
wenzelm@7134
    48
  ;
wenzelm@7134
    49
  'context' name
wenzelm@7134
    50
  ;
wenzelm@7134
    51
  'end'
wenzelm@7134
    52
  ;;
wenzelm@7134
    53
wenzelm@7167
    54
  filespecs: 'files' ((name | parname) +);
wenzelm@7134
    55
\end{rail}
wenzelm@7134
    56
wenzelm@7167
    57
\begin{descr}
wenzelm@7134
    58
\item [$\THEORY~A = B@1 + \cdots + B@n$] commences a new theory $A$ based on
wenzelm@7175
    59
  existing ones $B@1 + \cdots + B@n$.  Isabelle's theory loader system ensures
wenzelm@7175
    60
  that any of the base theories are properly loaded (and fully up-to-date when
wenzelm@7175
    61
  $\THEORY$ is executed interactively).  The optional $\isarkeyword{files}$
wenzelm@7175
    62
  specification declares additional dependencies on ML files.  Unless put in
wenzelm@7175
    63
  parentheses, any file will be loaded immediately via $\isarcmd{use}$ (see
wenzelm@7175
    64
  also \S\ref{sec:ML}).
wenzelm@7134
    65
  
wenzelm@7167
    66
\item [$\CONTEXT~B$] enters an existing theory context $B$, basically in
wenzelm@7134
    67
  read-only mode, so only a limited set of commands may be performed.  Just as
wenzelm@7134
    68
  for $\THEORY$, the theory loader ensures that $B$ is loaded and up-to-date.
wenzelm@7175
    69
  
wenzelm@7167
    70
\item [$\END$] concludes the current theory definition or context switch.
wenzelm@7175
    71
  Note that this command cannot be undone, instead the theory definition
wenzelm@7175
    72
  itself has to be retracted.
wenzelm@7167
    73
\end{descr}
wenzelm@7134
    74
wenzelm@7134
    75
wenzelm@7167
    76
\subsection{Formal comments}\label{sec:formal-cmt-thy}
wenzelm@7134
    77
wenzelm@7167
    78
\indexisarcmd{title}\indexisarcmd{chapter}\indexisarcmd{section}\indexisarcmd{subsection}
wenzelm@7167
    79
\indexisarcmd{subsubsection}\indexisarcmd{text}
wenzelm@7134
    80
\begin{matharray}{rcl}
wenzelm@7134
    81
  \isarcmd{title} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    82
  \isarcmd{chapter} & : & \isartrans{theory}{theory} \\
wenzelm@7167
    83
  \isarcmd{section} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    84
  \isarcmd{subsection} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    85
  \isarcmd{subsubsection} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    86
  \isarcmd{text} & : & \isartrans{theory}{theory} \\
wenzelm@7134
    87
\end{matharray}
wenzelm@7134
    88
wenzelm@7167
    89
There are several commands to include \emph{formal comments} in theory
wenzelm@7167
    90
specification (a few more are available for proofs, see
wenzelm@7167
    91
\S\ref{sec:formal-cmt-prf}).  In contrast to source-level comments
wenzelm@7134
    92
\verb|(*|\dots\verb|*)|, which are stripped at the lexical level, any text
wenzelm@7134
    93
given as formal comment is meant to be part of the actual document.
wenzelm@7134
    94
Consequently, it would be included in the final printed version.
wenzelm@7134
    95
wenzelm@7134
    96
Apart from plain prose, formal comments may also refer to logical entities of
wenzelm@7175
    97
the theory context (types, terms, theorems etc.).  Proper processing of the
wenzelm@7175
    98
text would then include some further consistency checks with the items
wenzelm@7175
    99
declared in the current theory, e.g.\ type-checking of included
wenzelm@7175
   100
terms.\footnote{The current version of Isabelle/Isar does not process formal
wenzelm@7134
   101
  comments in any such way.  This will be available as part of the automatic
wenzelm@7175
   102
  theory and proof document preparation system (using (PDF){\LaTeX}) that is
wenzelm@7134
   103
  planned for the near future.}
wenzelm@7134
   104
wenzelm@7134
   105
\begin{rail}
wenzelm@7134
   106
  'title' text text? text?
wenzelm@7134
   107
  ;
wenzelm@7167
   108
  ('chapter' | 'section' | 'subsection' | 'subsubsection' | 'text') text
wenzelm@7134
   109
  ;
wenzelm@7134
   110
\end{rail}
wenzelm@7134
   111
wenzelm@7167
   112
\begin{descr}
wenzelm@7134
   113
\item [$\isarkeyword{title}~title~author~date$] specifies the document title
wenzelm@7175
   114
  just as in typical {\LaTeX} documents.
wenzelm@7167
   115
\item [$\isarkeyword{chapter}~text$, $\isarkeyword{section}~text$,
wenzelm@7175
   116
  $\isarkeyword{subsection}~text$, and $\isarkeyword{subsubsection}~text$]
wenzelm@7315
   117
  mark chapter and section headings.
wenzelm@7134
   118
\item [$\TEXT~text$] specifies an actual body of prose text, including
wenzelm@7315
   119
  references to formal entities.\footnote{The latter feature is not yet
wenzelm@7315
   120
    exploited.  Nevertheless, any text of the form \texttt{\at\{\dots\}}
wenzelm@7315
   121
    should be considered as reserved for future use.}
wenzelm@7167
   122
\end{descr}
wenzelm@7134
   123
wenzelm@7134
   124
wenzelm@7135
   125
\subsection{Type classes and sorts}\label{sec:classes}
wenzelm@7134
   126
wenzelm@7134
   127
\indexisarcmd{classes}\indexisarcmd{classrel}\indexisarcmd{defaultsort}
wenzelm@7134
   128
\begin{matharray}{rcl}
wenzelm@7134
   129
  \isarcmd{classes} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   130
  \isarcmd{classrel} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   131
  \isarcmd{defaultsort} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   132
\end{matharray}
wenzelm@7134
   133
wenzelm@7134
   134
\begin{rail}
wenzelm@7167
   135
  'classes' (classdecl comment? +)
wenzelm@7134
   136
  ;
wenzelm@7134
   137
  'classrel' nameref '<' nameref comment?
wenzelm@7134
   138
  ;
wenzelm@7134
   139
  'defaultsort' sort comment?
wenzelm@7134
   140
  ;
wenzelm@7134
   141
\end{rail}
wenzelm@7134
   142
wenzelm@7167
   143
\begin{descr}
wenzelm@7175
   144
\item [$\isarkeyword{classes}~c<\vec c ~\dots$] declares class $c$ to be a
wenzelm@7175
   145
  subclass of existing classes $\vec c$.  Cyclic class structures are ruled
wenzelm@7175
   146
  out.
wenzelm@7134
   147
\item [$\isarkeyword{classrel}~c@1<c@2$] states a subclass relation between
wenzelm@7134
   148
  existing classes $c@1$ and $c@2$.  This is done axiomatically!  The
wenzelm@7175
   149
  $\isarkeyword{instance}$ command (see \S\ref{sec:axclass}) provides a way
wenzelm@7175
   150
  introduce proven class relations.
wenzelm@7134
   151
\item [$\isarkeyword{defaultsort}~s$] makes sort $s$ the new default sort for
wenzelm@7175
   152
  any type variables input without sort constraints.  Usually, the default
wenzelm@7134
   153
  sort would be only changed when defining new logics.
wenzelm@7167
   154
\end{descr}
wenzelm@7134
   155
wenzelm@7134
   156
wenzelm@7315
   157
\subsection{Primitive types and type abbreviations}\label{sec:types-pure}
wenzelm@7134
   158
wenzelm@7134
   159
\indexisarcmd{typedecl}\indexisarcmd{types}\indexisarcmd{nonterminals}\indexisarcmd{arities}
wenzelm@7134
   160
\begin{matharray}{rcl}
wenzelm@7134
   161
  \isarcmd{types} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   162
  \isarcmd{typedecl} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   163
  \isarcmd{nonterminals} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   164
  \isarcmd{arities} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   165
\end{matharray}
wenzelm@7134
   166
wenzelm@7134
   167
\begin{rail}
wenzelm@7134
   168
  'types' (typespec '=' type infix? comment? +)
wenzelm@7134
   169
  ;
wenzelm@7134
   170
  'typedecl' typespec infix? comment?
wenzelm@7134
   171
  ;
wenzelm@7134
   172
  'nonterminals' (name +) comment?
wenzelm@7134
   173
  ;
wenzelm@7134
   174
  'arities' (nameref '::' arity comment? +)
wenzelm@7134
   175
  ;
wenzelm@7134
   176
\end{rail}
wenzelm@7134
   177
wenzelm@7167
   178
\begin{descr}
wenzelm@7134
   179
\item [$\TYPES~(\vec\alpha)t = \tau~\dots$] introduces \emph{type synonym}
wenzelm@7134
   180
  $(\vec\alpha)t$ for existing type $\tau$.  Unlike actual type definitions,
wenzelm@7134
   181
  as are available in Isabelle/HOL for example, type synonyms are just purely
wenzelm@7134
   182
  syntactic abbreviations, without any logical significance.  Internally, type
wenzelm@7134
   183
  synonyms are fully expanded, as may be observed when printing terms or
wenzelm@7134
   184
  theorems.
wenzelm@7134
   185
\item [$\isarkeyword{typedecl}~(\vec\alpha)t$] declares a new type constructor
wenzelm@7134
   186
  $t$, intended as an actual logical type.  Note that some logics such as
wenzelm@7134
   187
  Isabelle/HOL provide their own version of $\isarkeyword{typedecl}$.
wenzelm@7175
   188
\item [$\isarkeyword{nonterminals}~\vec c$] declares $0$-ary type constructors
wenzelm@7175
   189
  $\vec c$ to act as purely syntactic types, i.e.\ nonterminal symbols of
wenzelm@7175
   190
  Isabelle's inner syntax of terms or types.
wenzelm@7134
   191
\item [$\isarkeyword{arities}~t::(\vec s)s~\dots$] augments Isabelle's
wenzelm@7134
   192
  order-sorted signature of types by new type constructor arities.  This is
wenzelm@7175
   193
  done axiomatically!  The $\isarkeyword{instance}$ command (see
wenzelm@7175
   194
  \S\ref{sec:axclass}) provides a way introduce proven type arities.
wenzelm@7167
   195
\end{descr}
wenzelm@7134
   196
wenzelm@7134
   197
wenzelm@7134
   198
\subsection{Constants and simple definitions}
wenzelm@7134
   199
wenzelm@7175
   200
\indexisarcmd{consts}\indexisarcmd{defs}\indexisarcmd{constdefs}\indexoutertoken{constdecl}
wenzelm@7134
   201
\begin{matharray}{rcl}
wenzelm@7134
   202
  \isarcmd{consts} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   203
  \isarcmd{defs} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   204
  \isarcmd{constdefs} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   205
\end{matharray}
wenzelm@7134
   206
wenzelm@7134
   207
\begin{rail}
wenzelm@7134
   208
  'consts' (constdecl +)
wenzelm@7134
   209
  ;
wenzelm@7134
   210
  'defs' (thmdecl? prop comment? +)
wenzelm@7134
   211
  ;
wenzelm@7134
   212
  'constdefs' (constdecl prop comment? +)
wenzelm@7134
   213
  ;
wenzelm@7134
   214
wenzelm@7134
   215
  constdecl: name '::' type mixfix? comment?
wenzelm@7134
   216
  ;
wenzelm@7134
   217
\end{rail}
wenzelm@7134
   218
wenzelm@7167
   219
\begin{descr}
wenzelm@7175
   220
\item [$\CONSTS~c::\sigma~\dots$] declares constant $c$ to have any instance
wenzelm@7175
   221
  of type scheme $\sigma$.  The optional mixfix annotations may attach
wenzelm@7175
   222
  concrete syntax constants.
wenzelm@7134
   223
\item [$\DEFS~name: eqn~\dots$] introduces $eqn$ as a definitional axiom for
wenzelm@7134
   224
  some existing constant.  See \cite[\S6]{isabelle-ref} for more details on
wenzelm@7134
   225
  the form of equations admitted as constant definitions.
wenzelm@7175
   226
\item [$\isarkeyword{constdefs}~c::\sigma~eqn~\dots$] combines constant
wenzelm@7134
   227
  declarations and definitions, using canonical name $c_def$ for the
wenzelm@7134
   228
  definitional axiom.
wenzelm@7167
   229
\end{descr}
wenzelm@7134
   230
wenzelm@7134
   231
wenzelm@7167
   232
\subsection{Syntax and translations}
wenzelm@7134
   233
wenzelm@7134
   234
\indexisarcmd{syntax}\indexisarcmd{translations}
wenzelm@7134
   235
\begin{matharray}{rcl}
wenzelm@7134
   236
  \isarcmd{syntax} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   237
  \isarcmd{translations} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   238
\end{matharray}
wenzelm@7134
   239
wenzelm@7134
   240
\begin{rail}
wenzelm@7134
   241
  'syntax' ('(' name 'output'? ')')? (constdecl +)
wenzelm@7134
   242
  ;
wenzelm@7134
   243
  'translations' (transpat ('==' | '=>' | '<=') transpat comment? +)
wenzelm@7134
   244
  ;
wenzelm@7134
   245
  transpat: ('(' nameref ')')? string
wenzelm@7134
   246
  ;
wenzelm@7134
   247
\end{rail}
wenzelm@7134
   248
wenzelm@7167
   249
\begin{descr}
wenzelm@7175
   250
\item [$\isarkeyword{syntax}~(mode)~decls$] is similar to $\CONSTS~decls$,
wenzelm@7175
   251
  except that the actual logical signature extension is omitted.  Thus the
wenzelm@7175
   252
  context free grammar of Isabelle's inner syntax may be augmented in
wenzelm@7175
   253
  arbitrary ways.  The $mode$ argument refers to the print mode that the
wenzelm@7175
   254
  grammar rules belong; unless there is the \texttt{output} flag given, all
wenzelm@7175
   255
  productions are added both to the input and output grammar.
wenzelm@7175
   256
\item [$\isarkeyword{translations}~rules$] specifies syntactic translation
wenzelm@7175
   257
  rules (also known as \emph{macros}): parse/print rules (\texttt{==}), parse
wenzelm@7175
   258
  rules (\texttt{=>}), print rules (\texttt{<=}).  Translation patterns may be
wenzelm@7134
   259
  prefixed by the syntactic category to be used for parsing; the default is
wenzelm@7134
   260
  \texttt{logic}.
wenzelm@7167
   261
\end{descr}
wenzelm@7134
   262
wenzelm@7134
   263
wenzelm@7134
   264
\subsection{Axioms and theorems}
wenzelm@7134
   265
wenzelm@7134
   266
\indexisarcmd{axioms}\indexisarcmd{theorems}\indexisarcmd{lemmas}
wenzelm@7134
   267
\begin{matharray}{rcl}
wenzelm@7134
   268
  \isarcmd{axioms} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   269
  \isarcmd{theorems} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   270
  \isarcmd{lemmas} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   271
\end{matharray}
wenzelm@7134
   272
wenzelm@7134
   273
\begin{rail}
wenzelm@7135
   274
  'axioms' (axmdecl prop comment? +)
wenzelm@7134
   275
  ;
wenzelm@7134
   276
  ('theorems' | 'lemmas') thmdef? thmrefs
wenzelm@7134
   277
  ;
wenzelm@7134
   278
\end{rail}
wenzelm@7134
   279
wenzelm@7167
   280
\begin{descr}
wenzelm@7134
   281
\item [$\isarkeyword{axioms}~name: \phi~\dots$] introduces arbitrary
wenzelm@7134
   282
  statements as logical axioms.  In fact, axioms are ``axiomatic theorems'',
wenzelm@7175
   283
  and may be referred just as any other theorem later.
wenzelm@7134
   284
  
wenzelm@7134
   285
  Axioms are usually only introduced when declaring new logical systems.
wenzelm@7175
   286
  Everyday work is typically done the hard way, with proper definitions and
wenzelm@7134
   287
  actual theorems.
wenzelm@7134
   288
\item [$\isarkeyword{theorems}~name = thms$] stores lists of existing theorems
wenzelm@7175
   289
  as $name$.  Typical applications would also involve attributes (to augment
wenzelm@7175
   290
  the default simpset, for example).
wenzelm@7134
   291
\item [$\isarkeyword{lemmas}$] is similar to $\isarkeyword{theorems}$, but
wenzelm@7134
   292
  tags the results as ``lemma''.
wenzelm@7167
   293
\end{descr}
wenzelm@7134
   294
wenzelm@7134
   295
wenzelm@7167
   296
\subsection{Name spaces}
wenzelm@7134
   297
wenzelm@7167
   298
\indexisarcmd{global}\indexisarcmd{local}
wenzelm@7134
   299
\begin{matharray}{rcl}
wenzelm@7134
   300
  \isarcmd{global} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   301
  \isarcmd{local} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   302
\end{matharray}
wenzelm@7134
   303
wenzelm@7315
   304
Isabelle organises any kind of names (of types, constants, theorems etc.)  by
wenzelm@7175
   305
hierarchically structured name spaces.  Normally the user never has to control
wenzelm@7315
   306
the behaviour of name space entry by hand, yet the following commands provide
wenzelm@7175
   307
some way to do so.
wenzelm@7175
   308
wenzelm@7167
   309
\begin{descr}
wenzelm@7167
   310
\item [$\isarkeyword{global}$ and $\isarkeyword{local}$] change the current
wenzelm@7167
   311
  name declaration mode.  Initially, theories start in $\isarkeyword{local}$
wenzelm@7167
   312
  mode, causing all names to be automatically qualified by the theory name.
wenzelm@7167
   313
  Changing this to $\isarkeyword{global}$ causes all names to be declared as
wenzelm@7175
   314
  base names only, until $\isarkeyword{local}$ is declared again.
wenzelm@7167
   315
\end{descr}
wenzelm@7134
   316
wenzelm@7134
   317
wenzelm@7167
   318
\subsection{Incorporating ML code}\label{sec:ML}
wenzelm@7134
   319
wenzelm@7134
   320
\indexisarcmd{use}\indexisarcmd{ML}\indexisarcmd{setup}
wenzelm@7134
   321
\begin{matharray}{rcl}
wenzelm@7134
   322
  \isarcmd{use} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@7134
   323
  \isarcmd{ML} & : & \isartrans{\cdot}{\cdot} \\
wenzelm@7175
   324
  \isarcmd{setup} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   325
\end{matharray}
wenzelm@7134
   326
wenzelm@7134
   327
\begin{rail}
wenzelm@7134
   328
  'use' name
wenzelm@7134
   329
  ;
wenzelm@7134
   330
  'ML' text
wenzelm@7134
   331
  ;
wenzelm@7134
   332
  'setup' text
wenzelm@7134
   333
  ;
wenzelm@7134
   334
\end{rail}
wenzelm@7134
   335
wenzelm@7167
   336
\begin{descr}
wenzelm@7175
   337
\item [$\isarkeyword{use}~file$] reads and executes ML commands from $file$.
wenzelm@7175
   338
  The current theory context (if present) is passed down to the ML session.
wenzelm@7175
   339
  Furthermore, the file name is checked with the $\isarkeyword{files}$
wenzelm@7175
   340
  dependency declaration given in the theory header (see also
wenzelm@7175
   341
  \S\ref{sec:begin-thy}).
wenzelm@7175
   342
\item [$\isarkeyword{ML}~text$] reads and executes ML commands from $text$.
wenzelm@7175
   343
  The theory context is passed just as for $\isarkeyword{use}$.
wenzelm@7167
   344
\item [$\isarkeyword{setup}~text$] changes the current theory context by
wenzelm@7175
   345
  applying setup functions $text$, which has to be an ML expression of type
wenzelm@7175
   346
  $(theory \to theory)~list$.  The $\isarkeyword{setup}$ command is the usual
wenzelm@7315
   347
  way to initialise object-logic specific tools and packages written in ML.
wenzelm@7167
   348
\end{descr}
wenzelm@7134
   349
wenzelm@7134
   350
wenzelm@7167
   351
\subsection{Syntax translation functions}
wenzelm@7134
   352
wenzelm@7167
   353
\indexisarcmd{parse-ast-translation}\indexisarcmd{parse-translation}
wenzelm@7167
   354
\indexisarcmd{print-translation}\indexisarcmd{typed-print-translation}
wenzelm@7167
   355
\indexisarcmd{print-ast-translation}\indexisarcmd{token-translation}
wenzelm@7134
   356
\begin{matharray}{rcl}
wenzelm@7134
   357
  \isarcmd{parse_ast_translation} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   358
  \isarcmd{parse_translation} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   359
  \isarcmd{print_translation} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   360
  \isarcmd{typed_print_translation} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   361
  \isarcmd{print_ast_translation} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   362
  \isarcmd{token_translation} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   363
\end{matharray}
wenzelm@7134
   364
wenzelm@7134
   365
Syntax translation functions written in ML admit almost arbitrary
wenzelm@7134
   366
manipulations of Isabelle's inner syntax.  Any of the above commands have a
wenzelm@7134
   367
single \railqtoken{text} argument that refers to an ML expression of
wenzelm@7134
   368
appropriate type.  See \cite[\S8]{isabelle-ref} for more information on syntax
wenzelm@7134
   369
transformations.
wenzelm@7134
   370
wenzelm@7134
   371
wenzelm@7134
   372
\subsection{Oracles}
wenzelm@7134
   373
wenzelm@7134
   374
\indexisarcmd{oracle}
wenzelm@7134
   375
\begin{matharray}{rcl}
wenzelm@7134
   376
  \isarcmd{oracle} & : & \isartrans{theory}{theory} \\
wenzelm@7134
   377
\end{matharray}
wenzelm@7134
   378
wenzelm@7175
   379
Oracles provide an interface to external reasoning systems, without giving up
wenzelm@7175
   380
control completely --- each theorem carries a derivation object recording any
wenzelm@7175
   381
oracle invocation.  See \cite[\S6]{isabelle-ref} for more information.
wenzelm@7175
   382
wenzelm@7134
   383
\begin{rail}
wenzelm@7134
   384
  'oracle' name '=' text comment?
wenzelm@7134
   385
  ;
wenzelm@7134
   386
\end{rail}
wenzelm@7134
   387
wenzelm@7167
   388
\begin{descr}
wenzelm@7175
   389
\item [$\isarkeyword{oracle}~name=text$] declares oracle $name$ to be ML
wenzelm@7315
   390
  function $text$, which has to be of type $Sign\mathord.sg \times
wenzelm@7315
   391
  Object\mathord.T \to term)$.
wenzelm@7167
   392
\end{descr}
wenzelm@7134
   393
wenzelm@7134
   394
wenzelm@7134
   395
\section{Proof commands}
wenzelm@7134
   396
wenzelm@7315
   397
Proof commands provide transitions of Isar/VM machine configurations, which
wenzelm@7315
   398
are block-structured, consisting of a stack of nodes with three main
wenzelm@7315
   399
components: logical \emph{proof context}, local \emph{facts}, and open
wenzelm@7315
   400
\emph{goals}.  Isar/VM transitions are \emph{typed} according to the following
wenzelm@7315
   401
three three different modes of operation:
wenzelm@7167
   402
\begin{descr}
wenzelm@7167
   403
\item [$proof(prove)$] means that a new goal has just been stated that is now
wenzelm@7167
   404
  to be \emph{proven}; the next command may refine it by some proof method
wenzelm@7175
   405
  ($\approx$ tactic), and enter a sub-proof to establish the final result.
wenzelm@7167
   406
\item [$proof(state)$] is like an internal theory mode: the context may be
wenzelm@7175
   407
  augmented by \emph{stating} additional assumptions, intermediate result etc.
wenzelm@7175
   408
\item [$proof(chain)$] is an intermediate mode between $proof(state)$ and
wenzelm@7315
   409
  $proof(prove)$: existing facts have been just picked up in order to use them
wenzelm@7315
   410
  when refining the goal to be claimed next.
wenzelm@7167
   411
\end{descr}
wenzelm@7134
   412
wenzelm@7167
   413
wenzelm@7167
   414
\subsection{Formal comments}\label{sec:formal-cmt-prf}
wenzelm@7167
   415
wenzelm@7167
   416
\indexisarcmd{sect}\indexisarcmd{subsect}\indexisarcmd{subsect}\indexisarcmd{txt}
wenzelm@7134
   417
\begin{matharray}{rcl}
wenzelm@7167
   418
  \isarcmd{sect} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7167
   419
  \isarcmd{subsect} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7167
   420
  \isarcmd{subsubsect} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7167
   421
  \isarcmd{txt} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   422
\end{matharray}
wenzelm@7134
   423
wenzelm@7175
   424
These formal comments in proof mode closely correspond to the ones of theory
wenzelm@7175
   425
mode (see \S\ref{sec:formal-cmt-thy}).
wenzelm@7175
   426
wenzelm@7134
   427
\begin{rail}
wenzelm@7167
   428
  ('sect' | 'subsect' | 'subsubsect' | 'txt') text
wenzelm@7134
   429
  ;
wenzelm@7134
   430
\end{rail}
wenzelm@7134
   431
wenzelm@7134
   432
wenzelm@7315
   433
\subsection{Proof context}\label{sec:proof-context}
wenzelm@7134
   434
wenzelm@7315
   435
\indexisarcmd{fix}\indexisarcmd{assume}\indexisarcmd{presume}\indexisarcmd{def}
wenzelm@7134
   436
\begin{matharray}{rcl}
wenzelm@7134
   437
  \isarcmd{fix} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   438
  \isarcmd{assume} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   439
  \isarcmd{presume} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   440
  \isarcmd{def} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   441
\end{matharray}
wenzelm@7134
   442
wenzelm@7315
   443
The logical proof context consists of fixed variables and assumptions.  The
wenzelm@7315
   444
former closely correspond to Skolem constants, or meta-level universal
wenzelm@7315
   445
quantification as provided by the Isabelle/Pure logical framework.
wenzelm@7315
   446
Introducing some \emph{arbitrary, but fixed} variable via $\FIX x$ results in
wenzelm@7315
   447
a local entity that may be used in the subsequent proof as any other variable
wenzelm@7315
   448
or constant.  Furthermore, any result $\phi[x]$ exported from the current
wenzelm@7315
   449
context will be universally closed wrt.\ $x$ at the outermost level (this is
wenzelm@7315
   450
expressed using Isabelle's meta-variables).
wenzelm@7315
   451
wenzelm@7315
   452
Similarly, introducing some assumption $\chi$ has two effects.  On the one
wenzelm@7315
   453
hand, a local theorem is created that may be used as a fact in subsequent
wenzelm@7315
   454
proof steps.  On the other hand, any result $\phi$ exported from the context
wenzelm@7315
   455
becomes conditional wrt.\ the assumption.  Thus, solving an enclosing goal
wenzelm@7315
   456
using this result would basically introduce a new subgoal stemming from the
wenzelm@7315
   457
assumption.  How this situation is handled depends on the actual version of
wenzelm@7315
   458
assumption command used: while $\ASSUMENAME$ solves the subgoal by unifying
wenzelm@7315
   459
with some premise of the goal, $\PRESUMENAME$ leaves the subgoal unchanged to
wenzelm@7315
   460
be proved later by the user.
wenzelm@7315
   461
wenzelm@7315
   462
Local definitions, introduced by $\DEF{a}{x \equiv t}$, are achieved by
wenzelm@7315
   463
combining $\FIX x$ with another version of assumption that causes any
wenzelm@7315
   464
hypothetical equation $x = t$ to be eliminated by reflexivity.  Thus,
wenzelm@7315
   465
exporting some result $\phi[x]$ simply yields $\phi[t]$.
wenzelm@7175
   466
wenzelm@7134
   467
\begin{rail}
wenzelm@7134
   468
  'fix' (var +) comment?
wenzelm@7134
   469
  ;
wenzelm@7315
   470
  ('assume' | 'presume') (assm comment? + 'and')
wenzelm@7134
   471
  ;
wenzelm@7175
   472
  'def' thmdecl? \\ var '==' term termpat? comment?
wenzelm@7134
   473
  ;
wenzelm@7134
   474
wenzelm@7134
   475
  var: name ('::' type)?
wenzelm@7134
   476
  ;
wenzelm@7315
   477
  assm: thmdecl? (prop proppat? +)
wenzelm@7315
   478
  ;
wenzelm@7134
   479
\end{rail}
wenzelm@7134
   480
wenzelm@7167
   481
\begin{descr}
wenzelm@7315
   482
\item [$\FIX{x}$] introduces a local \emph{arbitrary, but fixed} variable $x$.
wenzelm@7315
   483
\item [$\ASSUME{a}{\Phi}$ and $\PRESUME{a}{\Phi}$] introduce local theorems
wenzelm@7315
   484
  $\Phi$.  Subsequent results used to solve some enclosing goal (e.g.\ via
wenzelm@7315
   485
  $\SHOWNAME$) are handled as follows: $\ASSUMENAME$ expects to be able to
wenzelm@7315
   486
  unify with existing premises in the goal, while $\PRESUMENAME$ leaves $\Phi$
wenzelm@7315
   487
  as new subgoals.  Note that several lists of assumptions may be given
wenzelm@7315
   488
  (separated by \railterm{and}); the resulting list of current facts consists
wenzelm@7315
   489
  of all of these.
wenzelm@7315
   490
\item [$\DEF{a}{x \equiv t}$] introduces a local (non-polymorphic) definition.
wenzelm@7315
   491
  In results exported from the context, $x$ is replaced by $t$.  Basically,
wenzelm@7315
   492
  $\DEF{}{x \equiv t}$ abbreviates $\FIX{x}~\PRESUME{}{x \equiv t}$ (the
wenzelm@7315
   493
  resulting hypothetical equation is solved by reflexivity, though).
wenzelm@7167
   494
\end{descr}
wenzelm@7167
   495
wenzelm@7315
   496
The internal register $prems$\indexisarreg{prems} refers to all current
wenzelm@7315
   497
assumptions as a list of theorems.
wenzelm@7315
   498
wenzelm@7167
   499
wenzelm@7167
   500
\subsection{Facts and forward chaining}
wenzelm@7167
   501
wenzelm@7167
   502
\indexisarcmd{note}\indexisarcmd{then}\indexisarcmd{from}\indexisarcmd{with}
wenzelm@7167
   503
\begin{matharray}{rcl}
wenzelm@7167
   504
  \isarcmd{note} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7167
   505
  \isarcmd{then} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@7167
   506
  \isarcmd{from} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@7167
   507
  \isarcmd{with} & : & \isartrans{proof(state)}{proof(chain)} \\
wenzelm@7167
   508
\end{matharray}
wenzelm@7167
   509
wenzelm@7315
   510
New facts are established either by assumption or proof of local statements
wenzelm@7315
   511
(via $\HAVENAME$ or $\SHOWNAME$).  Any facts will usually be involved in
wenzelm@7315
   512
proofs of further results: either as explicit arguments of proof methods or
wenzelm@7315
   513
when forward chaining towards the next goal via $\THEN$ (and variants).
wenzelm@7175
   514
wenzelm@7167
   515
\begin{rail}
wenzelm@7167
   516
  'note' thmdef? thmrefs comment?
wenzelm@7167
   517
  ;
wenzelm@7167
   518
  'then' comment?
wenzelm@7167
   519
  ;
wenzelm@7167
   520
  ('from' | 'with') thmrefs comment?
wenzelm@7167
   521
  ;
wenzelm@7167
   522
\end{rail}
wenzelm@7167
   523
wenzelm@7167
   524
\begin{descr}
wenzelm@7175
   525
\item [$\NOTE{a}{\vec b}$] recalls existing facts $\vec b$, binding the result
wenzelm@7175
   526
  as $a$.  Note that attributes may be involved as well, both on the left and
wenzelm@7175
   527
  right hand sides.
wenzelm@7167
   528
\item [$\THEN$] indicates forward chaining by the current facts in order to
wenzelm@7175
   529
  establish the goal to be claimed next.  The initial proof method invoked to
wenzelm@7175
   530
  solve that will be offered these facts to do ``anything appropriate'' (see
wenzelm@7175
   531
  also \S\ref{sec:proof-steps}).  For example, method $rule$ (see
wenzelm@7167
   532
  \S\ref{sec:pure-meth}) would do an elimination rather than an introduction.
wenzelm@7175
   533
\item [$\FROM{\vec b}$] abbreviates $\NOTE{}{\vec b}~\THEN$; also note that
wenzelm@7167
   534
  $\THEN$ is equivalent to $\FROM{facts}$.
wenzelm@7175
   535
\item [$\WITH{\vec b}$] abbreviates $\FROM{\vec b~facts}$; thus the forward
wenzelm@7175
   536
  chaining is from earlier facts together with the current ones.
wenzelm@7167
   537
\end{descr}
wenzelm@7167
   538
wenzelm@7315
   539
Note that the internal register of \emph{current facts} may be referred as
wenzelm@7315
   540
theorem list $facts$.\indexisarreg{facts}
wenzelm@7315
   541
wenzelm@7167
   542
wenzelm@7167
   543
\subsection{Goal statements}
wenzelm@7167
   544
wenzelm@7167
   545
\indexisarcmd{theorem}\indexisarcmd{lemma}
wenzelm@7167
   546
\indexisarcmd{have}\indexisarcmd{show}\indexisarcmd{hence}\indexisarcmd{thus}
wenzelm@7167
   547
\begin{matharray}{rcl}
wenzelm@7167
   548
  \isarcmd{theorem} & : & \isartrans{theory}{proof(prove)} \\
wenzelm@7167
   549
  \isarcmd{lemma} & : & \isartrans{theory}{proof(prove)} \\
wenzelm@7167
   550
  \isarcmd{have} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@7167
   551
  \isarcmd{show} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@7167
   552
  \isarcmd{hence} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@7167
   553
  \isarcmd{thus} & : & \isartrans{proof(state)}{proof(prove)} \\
wenzelm@7167
   554
\end{matharray}
wenzelm@7167
   555
wenzelm@7175
   556
Proof mode is entered from theory mode by initial goal commands $\THEOREMNAME$
wenzelm@7175
   557
and $\LEMMANAME$.  New local goals may be claimed within proof mode: four
wenzelm@7175
   558
variants are available, indicating whether the result is meant to solve some
wenzelm@7175
   559
pending goal and whether forward chaining is employed.
wenzelm@7175
   560
wenzelm@7167
   561
\begin{rail}
wenzelm@7167
   562
  ('theorem' | 'lemma') goal
wenzelm@7167
   563
  ;
wenzelm@7167
   564
  ('have' | 'show' | 'hence' | 'thus') goal
wenzelm@7167
   565
  ;
wenzelm@7167
   566
wenzelm@7167
   567
  goal: thmdecl? proppat comment?
wenzelm@7167
   568
  ;
wenzelm@7167
   569
\end{rail}
wenzelm@7167
   570
wenzelm@7167
   571
\begin{descr}
wenzelm@7167
   572
\item [$\THEOREM{name}{\phi}$] enters proof mode with $\phi$ as main goal,
wenzelm@7175
   573
  eventually resulting in some theorem $\turn \phi$, which will be stored in
wenzelm@7175
   574
  the theory.
wenzelm@7167
   575
\item [$\LEMMANAME$] is similar to $\THEOREMNAME$, but tags the result as
wenzelm@7167
   576
  ``lemma''.
wenzelm@7167
   577
\item [$\HAVE{name}{\phi}$] claims a local goal, eventually resulting in a
wenzelm@7167
   578
  theorem with the current assumption context as hypotheses.
wenzelm@7175
   579
\item [$\SHOW{name}{\phi}$] is similar to $\HAVE{name}{\phi}$, but solves some
wenzelm@7175
   580
  pending goal with the result \emph{exported} into the corresponding context.
wenzelm@7167
   581
\item [$\HENCE{name}{\phi}$] abbreviates $\THEN~\HAVE{name}{\phi}$, i.e.\ 
wenzelm@7167
   582
  claims a local goal to be proven by forward chaining the current facts.
wenzelm@7167
   583
\item [$\THUS{name}{\phi}$] abbreviates $\THEN~\SHOW{name}{\phi}$.
wenzelm@7167
   584
\end{descr}
wenzelm@7167
   585
wenzelm@7167
   586
wenzelm@7167
   587
\subsection{Initial and terminal proof steps}\label{sec:proof-steps}
wenzelm@7167
   588
wenzelm@7175
   589
\indexisarcmd{proof}\indexisarcmd{qed}\indexisarcmd{by}
wenzelm@7175
   590
\indexisarcmd{.}\indexisarcmd{..}\indexisarcmd{sorry}
wenzelm@7175
   591
\begin{matharray}{rcl}
wenzelm@7175
   592
  \isarcmd{proof} & : & \isartrans{proof(prove)}{proof(state)} \\
wenzelm@7175
   593
  \isarcmd{qed} & : & \isartrans{proof(state)}{proof(state) ~|~ theory} \\
wenzelm@7175
   594
  \isarcmd{by} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   595
  \isarcmd{.\,.} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   596
  \isarcmd{.} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   597
  \isarcmd{sorry} & : & \isartrans{proof(prove)}{proof(state) ~|~ theory} \\
wenzelm@7175
   598
\end{matharray}
wenzelm@7175
   599
wenzelm@7167
   600
Arbitrary goal refinements via tactics is considered harmful.  Consequently
wenzelm@7167
   601
the Isar framework admits proof methods to be invoked in two places only.
wenzelm@7167
   602
\begin{enumerate}
wenzelm@7175
   603
\item An \emph{initial} refinement step $\PROOF{m@1}$ reduces a newly stated
wenzelm@7175
   604
  intermediate goal to a number of sub-goals that are to be solved later.
wenzelm@7175
   605
  Facts are passed to $m@1$ for forward chaining if so indicated by
wenzelm@7175
   606
  $proof(chain)$ mode.
wenzelm@7167
   607
  
wenzelm@7175
   608
\item A \emph{terminal} conclusion step $\QED{m@2}$ solves any remaining
wenzelm@7167
   609
  pending goals completely.  No facts are passed to $m@2$.
wenzelm@7167
   610
\end{enumerate}
wenzelm@7167
   611
wenzelm@7167
   612
The only other proper way to affect pending goals is by $\SHOWNAME$, which
wenzelm@7167
   613
involves an explicit statement of what is solved.
wenzelm@7167
   614
wenzelm@7175
   615
\medskip
wenzelm@7175
   616
wenzelm@7167
   617
Also note that initial proof methods should either solve the goal completely,
wenzelm@7167
   618
or constitute some well-understood deterministic reduction to new sub-goals.
wenzelm@7167
   619
Arbitrary automatic proof tools that are prone leave a large number of badly
wenzelm@7167
   620
structured sub-goals are no help in continuing the proof document in any
wenzelm@7175
   621
intelligible way.  A much better technique would be to $\SHOWNAME$ some
wenzelm@7175
   622
non-trivial reduction as an explicit rule, which is solved completely by some
wenzelm@7175
   623
automated method, and then applied to some pending goal.
wenzelm@7167
   624
wenzelm@7175
   625
\medskip
wenzelm@7175
   626
wenzelm@7175
   627
Unless given explicitly by the user, the default initial method is
wenzelm@7175
   628
``$default$'', which is usually set up to apply a single standard elimination
wenzelm@7175
   629
or introduction rule according to the topmost symbol involved.  The default
wenzelm@7175
   630
terminal method is ``$finish$''; it solves all goals by assumption.
wenzelm@7167
   631
wenzelm@7167
   632
\begin{rail}
wenzelm@7167
   633
  'proof' interest? meth? comment?
wenzelm@7167
   634
  ;
wenzelm@7167
   635
  'qed' meth? comment?
wenzelm@7167
   636
  ;
wenzelm@7167
   637
  'by' meth meth? comment?
wenzelm@7167
   638
  ;
wenzelm@7167
   639
  ('.' | '..' | 'sorry') comment?
wenzelm@7167
   640
  ;
wenzelm@7167
   641
wenzelm@7167
   642
  meth: method interest?
wenzelm@7167
   643
  ;
wenzelm@7167
   644
\end{rail}
wenzelm@7167
   645
wenzelm@7167
   646
\begin{descr}
wenzelm@7175
   647
\item [$\PROOF{m@1}$] refines the pending goal by proof method $m@1$; facts
wenzelm@7175
   648
  for forward chaining are passed if so indicated by $proof(chain)$.
wenzelm@7175
   649
\item [$\QED{m@2}$] refines any remaining goals by proof method $m@1$ and
wenzelm@7167
   650
  concludes the sub-proof.  If the goal had been $\SHOWNAME$, some pending
wenzelm@7167
   651
  sub-goal is solved as well by the rule resulting from the result exported to
wenzelm@7175
   652
  the enclosing goal context.  Thus $\QEDNAME$ may fail for two reasons:
wenzelm@7175
   653
  either $m@2$ fails to solve all remaining goals completely, or the resulting
wenzelm@7175
   654
  rule does not resolve with any enclosing goal.  Debugging such a situation
wenzelm@7175
   655
  might involve temporarily changing $\SHOWNAME$ into $\HAVENAME$, or
wenzelm@7175
   656
  weakening the local context by replacing $\ASSUMENAME$ by $\PRESUMENAME$.
wenzelm@7175
   657
\item [$\BYY{m@1}{m@2}$] is a \emph{terminal proof}; it abbreviates
wenzelm@7175
   658
  $\PROOF{m@1}~\QED{m@2}$, with automatic backtracking across both methods.
wenzelm@7175
   659
  Debugging an unsuccessful $\BYY{m@1}{m@2}$ commands might be done by simply
wenzelm@7175
   660
  expanding the abbreviation by hand; note that $\PROOF{m@1}$ is usually
wenzelm@7175
   661
  sufficient to see what is going wrong.
wenzelm@7175
   662
\item [$\DDOT$] is a \emph{default proof}; it abbreviates $\BY{default}$.
wenzelm@7175
   663
\item [$\DOT$] is a \emph{trivial proof}, it abbreviates $\BY{-}$, where
wenzelm@7175
   664
  method ``$-$'' does nothing except inserting any facts into the proof state.
wenzelm@7167
   665
\item [$\isarkeyword{sorry}$] is a \emph{fake proof}; provided that
wenzelm@7167
   666
  \texttt{quick_and_dirty} is enabled, $\isarkeyword{sorry}$ pretends to solve
wenzelm@7167
   667
  the goal without much ado.  Of course, the result is a fake theorem only,
wenzelm@7175
   668
  involving some oracle in its internal derivation object (this is indicated
wenzelm@7175
   669
  as $[!]$ in the printed result.  The main application of
wenzelm@7167
   670
  $\isarkeyword{sorry}$ is to support top-down proof development.
wenzelm@7167
   671
\end{descr}
wenzelm@7134
   672
wenzelm@7134
   673
wenzelm@7315
   674
\subsection{Improper proof steps}
wenzelm@7315
   675
wenzelm@7315
   676
The following commands emulate unstructured tactic scripts to some extent.
wenzelm@7315
   677
While these are anathema for writing proper Isar proof documents, they might
wenzelm@7315
   678
come in handy for exploring and debugging.
wenzelm@7315
   679
wenzelm@7315
   680
\indexisarcmd{apply}\indexisarcmd{then-apply}\indexisarcmd{back}
wenzelm@7315
   681
\begin{matharray}{rcl}
wenzelm@7315
   682
  \isarcmd{apply}^* & : & \isartrans{proof}{proof} \\
wenzelm@7315
   683
  \isarcmd{then_apply}^* & : & \isartrans{proof}{proof} \\
wenzelm@7315
   684
  \isarcmd{back}^* & : & \isartrans{proof}{proof} \\
wenzelm@7315
   685
\end{matharray}
wenzelm@7315
   686
wenzelm@7315
   687
\railalias{thenapply}{then\_apply}
wenzelm@7315
   688
\railterm{thenapply}
wenzelm@7315
   689
wenzelm@7315
   690
\begin{rail}
wenzelm@7315
   691
  'apply' method
wenzelm@7315
   692
  ;
wenzelm@7315
   693
  thenapply method
wenzelm@7315
   694
  ;
wenzelm@7315
   695
  'back'
wenzelm@7315
   696
  ;
wenzelm@7315
   697
\end{rail}
wenzelm@7315
   698
wenzelm@7315
   699
\begin{descr}
wenzelm@7315
   700
\item [$\isarkeyword{apply}~m$] applies proof method $m$ in the
wenzelm@7315
   701
  plain-old-tactic sense.  Facts for forward chaining are ignored.
wenzelm@7315
   702
\item [$\isarkeyword{then_apply}~m$] is similar to $\isarkeyword{apply}$, but
wenzelm@7315
   703
  observes the goal's facts.
wenzelm@7315
   704
\item [$\isarkeyword{back}$] does back-tracking over the result sequence of
wenzelm@7315
   705
  the last proof command.  Basically, any proof command may return multiple
wenzelm@7315
   706
  results.
wenzelm@7315
   707
\end{descr}
wenzelm@7315
   708
wenzelm@7315
   709
wenzelm@7315
   710
\subsection{Term abbreviations}\label{sec:term-abbrev}
wenzelm@7315
   711
wenzelm@7315
   712
\indexisarcmd{let}
wenzelm@7315
   713
\begin{matharray}{rcl}
wenzelm@7315
   714
  \isarcmd{let} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7315
   715
  \isarkeyword{is} & : & syntax \\
wenzelm@7315
   716
\end{matharray}
wenzelm@7315
   717
wenzelm@7315
   718
Abbreviations may be either bound by explicit $\LET{p \equiv t}$ statements,
wenzelm@7315
   719
or by annotating assumptions or goal statements ($\ASSUMENAME$, $\SHOWNAME$
wenzelm@7315
   720
etc.) with a list of patterns $\IS{p@1 \dots p@n}$.  In both cases,
wenzelm@7315
   721
higher-order matching is applied to bind extra-logical text
wenzelm@7315
   722
variables\index{text variables}, which may be either of the form $\VVar{x}$
wenzelm@7315
   723
(token class \railtoken{textvar}, see \S\ref{sec:lex-syntax}) or nameless
wenzelm@7315
   724
dummies ``\verb,_,'' (underscore).\index{dummy variables} Note that in the
wenzelm@7315
   725
$\LETNAME$ form the patterns occur on the left-hand side, while the $\ISNAME$
wenzelm@7315
   726
patterns are in postfix position.
wenzelm@7315
   727
wenzelm@7315
   728
Note that term abbreviations are quite different from actual local definitions
wenzelm@7315
   729
as introduced via $\DEFNAME$ (see \S\ref{sec:proof-context}).  The latter are
wenzelm@7315
   730
visible within the logic as actual equations, while abbreviations disappear
wenzelm@7315
   731
during the input process just after type checking.
wenzelm@7315
   732
wenzelm@7315
   733
\begin{rail}
wenzelm@7315
   734
  'let' ((term + 'as') '=' term comment? + 'and')
wenzelm@7315
   735
  ;  
wenzelm@7315
   736
\end{rail}
wenzelm@7315
   737
wenzelm@7315
   738
The syntax of $\ISNAME$ patterns follows \railnonterm{termpat} or
wenzelm@7315
   739
\railnonterm{proppat} (see \S\ref{sec:term-pats}).
wenzelm@7315
   740
wenzelm@7315
   741
\begin{descr}
wenzelm@7315
   742
\item [$\LET{\vec p = \vec t}$] binds any text variables in patters $\vec p$
wenzelm@7315
   743
  by simultaneous higher-order matching against terms $\vec t$.
wenzelm@7315
   744
\item [$\IS{\vec p}$] resembles $\LETNAME$, but matches $\vec p$ against the
wenzelm@7315
   745
  preceding statement.  Also note that $\ISNAME$ is not a separate command,
wenzelm@7315
   746
  but part of others (such as $\ASSUMENAME$, $\HAVENAME$ etc.).
wenzelm@7315
   747
\end{descr}
wenzelm@7315
   748
wenzelm@7315
   749
Furthermore, a few automatic term abbreviations\index{automatic abbreviation}
wenzelm@7315
   750
for goals and facts are available.  For any open goal, $\VVar{thesis}$ refers
wenzelm@7315
   751
to its object-logic statement, $\VVar{thesis_prop}$ to the full proposition
wenzelm@7315
   752
(which may be a rule), and $\VVar{thesis_concl}$ to its (atomic) conclusion.
wenzelm@7315
   753
wenzelm@7315
   754
Facts (i.e.\ assumptions and finished goals) that have an application $f(x)$
wenzelm@7315
   755
as object-logic statement get $x$ bound to the special text variable
wenzelm@7315
   756
``$\dots$'' (three dots).  The canonical application of this feature are
wenzelm@7315
   757
calculational proofs, see \S\ref{sec:calculation}.
wenzelm@7315
   758
wenzelm@7315
   759
wenzelm@7134
   760
\subsection{Block structure}
wenzelm@7134
   761
wenzelm@7167
   762
While Isar is inherently block-structured, opening and closing blocks is
wenzelm@7167
   763
mostly handled rather casually, with little explicit user-intervention.  Any
wenzelm@7167
   764
local goal statement automatically opens \emph{two} blocks, which are closed
wenzelm@7167
   765
again when concluding the sub-proof (by $\QEDNAME$ etc.).  Sections of
wenzelm@7167
   766
different context within a sub-proof are typically switched via
wenzelm@7167
   767
$\isarkeyword{next}$, which is just a single block-close followed by
wenzelm@7167
   768
block-open again.  Thus the effect of $\isarkeyword{next}$ is to reset the
wenzelm@7167
   769
proof context to that of the head of the sub-proof.  Note that there is no
wenzelm@7175
   770
goal focus involved here!
wenzelm@7167
   771
wenzelm@7175
   772
For slightly more advanced applications, there are explicit block parentheses
wenzelm@7175
   773
as well.  These typically achieve a strong forward style of reasoning.
wenzelm@7167
   774
wenzelm@7134
   775
\indexisarcmd{next}\indexisarcmd{\{\{}\indexisarcmd{\}\}}
wenzelm@7134
   776
\begin{matharray}{rcl}
wenzelm@7134
   777
  \isarcmd{next} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   778
  \isarcmd{\{\{} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   779
  \isarcmd{\}\}} & : & \isartrans{proof(state)}{proof(state)} \\
wenzelm@7134
   780
\end{matharray}
wenzelm@7134
   781
wenzelm@7167
   782
\begin{descr}
wenzelm@7167
   783
\item [$\isarkeyword{next}$] switches to a fresh block within a sub-proof,
wenzelm@7167
   784
  resetting the context to the initial one.
wenzelm@7167
   785
\item [$\isarkeyword{\{\{}$ and $\isarkeyword{\}\}}$] explicitly open and
wenzelm@7167
   786
  close blocks.  Any current facts pass through $\isarkeyword{\{\{}$
wenzelm@7167
   787
  unchanged, while $\isarkeyword{\}\}}$ causes them to be \emph{exported} into
wenzelm@7315
   788
  the enclosing context.  Thus fixed variables are generalised, assumptions
wenzelm@7167
   789
  discharged, and local definitions eliminated.
wenzelm@7167
   790
\end{descr}
wenzelm@7134
   791
wenzelm@7134
   792
wenzelm@7134
   793
\section{Other commands}
wenzelm@7134
   794
wenzelm@7315
   795
The following commands are not part of the actual proper or improper
wenzelm@7315
   796
Isabelle/Isar syntax, but assist interactive development, for example.  Also
wenzelm@7315
   797
note that $undo$ does not apply here, since the theory or proof configuration
wenzelm@7315
   798
is not changed.
wenzelm@7315
   799
wenzelm@7134
   800
\subsection{Diagnostics}
wenzelm@7134
   801
wenzelm@7134
   802
\indexisarcmd{typ}\indexisarcmd{term}\indexisarcmd{prop}\indexisarcmd{thm}
wenzelm@7134
   803
\begin{matharray}{rcl}
wenzelm@7134
   804
  \isarcmd{typ} & : & \isarkeep{theory~|~proof} \\
wenzelm@7134
   805
  \isarcmd{term} & : & \isarkeep{theory~|~proof} \\
wenzelm@7134
   806
  \isarcmd{prop} & : & \isarkeep{theory~|~proof} \\
wenzelm@7134
   807
  \isarcmd{thm} & : & \isarkeep{theory~|~proof} \\
wenzelm@7134
   808
\end{matharray}
wenzelm@7134
   809
wenzelm@7134
   810
\begin{rail}
wenzelm@7134
   811
  'typ' type
wenzelm@7134
   812
  ;
wenzelm@7134
   813
  'term' term
wenzelm@7134
   814
  ;
wenzelm@7134
   815
  'prop' prop
wenzelm@7134
   816
  ;
wenzelm@7134
   817
  'thm' thmrefs
wenzelm@7134
   818
  ;
wenzelm@7134
   819
\end{rail}
wenzelm@7134
   820
wenzelm@7167
   821
\begin{descr}
wenzelm@7134
   822
\item [$\isarkeyword{typ}~\tau$, $\isarkeyword{term}~t$,
wenzelm@7134
   823
  $\isarkeyword{prop}~\phi$] read and print types / terms / propositions
wenzelm@7134
   824
  according to the current theory or proof context.
wenzelm@7134
   825
\item [$\isarkeyword{thm}~thms$] retrieves lists of theorems from the current
wenzelm@7134
   826
  theory or proof context.  Note that any attributes included in the theorem
wenzelm@7175
   827
  specifications are applied to a temporary context derived from the current
wenzelm@7175
   828
  theory or proof; the result is discarded.
wenzelm@7167
   829
\end{descr}
wenzelm@7134
   830
wenzelm@7134
   831
wenzelm@7134
   832
\subsection{System operations}
wenzelm@7134
   833
wenzelm@7167
   834
\indexisarcmd{cd}\indexisarcmd{pwd}\indexisarcmd{use-thy}\indexisarcmd{use-thy-only}
wenzelm@7167
   835
\indexisarcmd{update-thy}\indexisarcmd{update-thy-only}
wenzelm@7134
   836
\begin{matharray}{rcl}
wenzelm@7134
   837
  \isarcmd{cd} & : & \isarkeep{\cdot} \\
wenzelm@7134
   838
  \isarcmd{pwd} & : & \isarkeep{\cdot} \\
wenzelm@7134
   839
  \isarcmd{use_thy} & : & \isarkeep{\cdot} \\
wenzelm@7134
   840
  \isarcmd{use_thy_only} & : & \isarkeep{\cdot} \\
wenzelm@7134
   841
  \isarcmd{update_thy} & : & \isarkeep{\cdot} \\
wenzelm@7134
   842
  \isarcmd{update_thy_only} & : & \isarkeep{\cdot} \\
wenzelm@7134
   843
\end{matharray}
wenzelm@7134
   844
wenzelm@7167
   845
\begin{descr}
wenzelm@7134
   846
\item [$\isarkeyword{cd}~name$] changes the current directory of the Isabelle
wenzelm@7134
   847
  process.
wenzelm@7134
   848
\item [$\isarkeyword{pwd}~$] prints the current working directory.
wenzelm@7175
   849
\item [$\isarkeyword{use_thy}$, $\isarkeyword{use_thy_only}$,
wenzelm@7175
   850
  $\isarkeyword{update_thy}$, and $\isarkeyword{update_thy_only}$] load some
wenzelm@7175
   851
  theory given as $name$ argument.  These commands are exactly the same as the
wenzelm@7175
   852
  corresponding ML functions (see also \cite[\S1 and \S6]{isabelle-ref}).
wenzelm@7175
   853
  Note that both the ML and Isar versions of these commands may load new- and
wenzelm@7175
   854
  old-style theories alike.
wenzelm@7167
   855
\end{descr}
wenzelm@7134
   856
wenzelm@7134
   857
wenzelm@7046
   858
%%% Local Variables: 
wenzelm@7046
   859
%%% mode: latex
wenzelm@7046
   860
%%% TeX-master: "isar-ref"
wenzelm@7046
   861
%%% End: