doc-src/IsarRef/syntax.tex
author wenzelm
Thu, 17 Jun 2004 14:26:24 +0200
changeset 14960 89cce4e95a22
parent 14955 08ee855c1d94
child 15357 96698f16e3d9
permissions -rw-r--r--
tuned;
wenzelm@7046
     1
wenzelm@13048
     2
\chapter{Syntax primitives}
wenzelm@7046
     3
wenzelm@12618
     4
The rather generic framework of Isabelle/Isar syntax emerges from three main
wenzelm@12618
     5
syntactic categories: \emph{commands} of the top-level Isar engine (covering
wenzelm@12618
     6
theory and proof elements), \emph{methods} for general goal refinements
wenzelm@12618
     7
(analogous to traditional ``tactics''), and \emph{attributes} for operations
wenzelm@12618
     8
on facts (within a certain context).  Here we give a reference of basic
wenzelm@12618
     9
syntactic entities underlying Isabelle/Isar syntax in a bottom-up manner.
wenzelm@12618
    10
Concrete theory and proof language elements will be introduced later on.
wenzelm@7134
    11
wenzelm@7315
    12
\medskip
wenzelm@7046
    13
wenzelm@7315
    14
In order to get started with writing well-formed Isabelle/Isar documents, the
wenzelm@7315
    15
most important aspect to be noted is the difference of \emph{inner} versus
wenzelm@7315
    16
\emph{outer} syntax.  Inner syntax is that of Isabelle types and terms of the
wenzelm@12618
    17
logic, while outer syntax is that of Isabelle/Isar theory sources (including
wenzelm@7895
    18
proofs).  As a general rule, inner syntax entities may occur only as
wenzelm@7895
    19
\emph{atomic entities} within outer syntax.  For example, the string
wenzelm@7895
    20
\texttt{"x + y"} and identifier \texttt{z} are legal term specifications
wenzelm@7895
    21
within a theory, while \texttt{x + y} is not.
wenzelm@7315
    22
wenzelm@7315
    23
\begin{warn}
wenzelm@12618
    24
  Old-style Isabelle theories used to fake parts of the inner syntax of types,
wenzelm@12618
    25
  with rather complicated rules when quotes may be omitted.  Despite the minor
wenzelm@12618
    26
  drawback of requiring quotes more often, the syntax of Isabelle/Isar is
wenzelm@12618
    27
  somewhat simpler and more robust in that respect.
wenzelm@7315
    28
\end{warn}
wenzelm@7315
    29
wenzelm@12618
    30
Printed theory documents usually omit quotes to gain readability (this is a
wenzelm@12618
    31
matter of {\LaTeX} macro setup, say via \verb,\isabellestyle,, see also
wenzelm@12618
    32
\cite{isabelle-sys}).  Experienced users of Isabelle/Isar may easily
wenzelm@12618
    33
reconstruct the lost technical information, while mere readers need not care
wenzelm@12618
    34
about quotes at all.
wenzelm@12618
    35
wenzelm@7466
    36
\medskip
wenzelm@7466
    37
wenzelm@9601
    38
Isabelle/Isar input may contain any number of input termination characters
wenzelm@12618
    39
``\texttt{;}'' (semicolon) to separate commands explicitly.  This is
wenzelm@9601
    40
particularly useful in interactive shell sessions to make clear where the
wenzelm@12618
    41
current command is intended to end.  Otherwise, the interpreter loop will
wenzelm@12618
    42
continue to issue a secondary prompt ``\verb,#,'' until an end-of-command is
wenzelm@13039
    43
clearly recognized from the input syntax, e.g.\ encounter of the next command
wenzelm@12618
    44
keyword.
wenzelm@9601
    45
wenzelm@9601
    46
Advanced interfaces such as Proof~General \cite{proofgeneral} do not require
wenzelm@9601
    47
explicit semicolons, the amount of input text is determined automatically by
wenzelm@12618
    48
inspecting the present content of the Emacs text buffer.  In the printed
wenzelm@12618
    49
presentation of Isabelle/Isar documents semicolons are omitted altogether for
wenzelm@7981
    50
readability.
wenzelm@7466
    51
wenzelm@12618
    52
\begin{warn}
wenzelm@12618
    53
  Proof~General requires certain syntax classification tables in order to
wenzelm@12618
    54
  achieve properly synchronized interaction with the Isabelle/Isar process.
wenzelm@12618
    55
  These tables need to be consistent with the Isabelle version and particular
wenzelm@12618
    56
  logic image to be used in a running session (common object-logics may well
wenzelm@12618
    57
  change the outer syntax).  The standard setup should work correctly with any
wenzelm@12618
    58
  of the ``official'' logic images derived from Isabelle/HOL (including HOLCF
wenzelm@12618
    59
  etc.).  Users of alternative logics may need to tell Proof~General
wenzelm@12618
    60
  explicitly, e.g.\ by giving an option \verb,-k ZF, (in conjunction with
wenzelm@12618
    61
  \verb,-l ZF, to specify the default logic image).
wenzelm@12618
    62
\end{warn}
wenzelm@7315
    63
wenzelm@7315
    64
\section{Lexical matters}\label{sec:lex-syntax}
wenzelm@7315
    65
wenzelm@14955
    66
The Isabelle/Isar outer syntax provides token classes as presented below; most
wenzelm@14955
    67
of these coincide with the inner lexical syntax as presented in
wenzelm@14955
    68
\cite{isabelle-ref}.
wenzelm@7315
    69
wenzelm@9617
    70
\indexoutertoken{ident}\indexoutertoken{longident}\indexoutertoken{symident}
wenzelm@9617
    71
\indexoutertoken{nat}\indexoutertoken{var}\indexoutertoken{typefree}
wenzelm@9617
    72
\indexoutertoken{typevar}\indexoutertoken{string}\indexoutertoken{verbatim}
wenzelm@7315
    73
\begin{matharray}{rcl}
wenzelm@14955
    74
  ident & = & letter\,quasiletter^* \\
wenzelm@14955
    75
  longident & = & ident (\verb,.,ident)^+ \\
wenzelm@14955
    76
  symident & = & sym^+ ~|~ \verb,\<,ident\verb,>, \\
wenzelm@7315
    77
  nat & = & digit^+ \\
ballarin@14212
    78
  var & = & ident ~|~ \verb,?,ident ~|~ \verb,?,ident\verb,.,nat \\
wenzelm@7315
    79
  typefree & = & \verb,',ident \\
ballarin@14212
    80
  typevar & = & typefree ~|~ \verb,?,typefree ~|~ \verb,?,typefree\verb,.,nat \\
wenzelm@7315
    81
  string & = & \verb,", ~\dots~ \verb,", \\
kleing@14483
    82
  verbatim & = & \verb,{*, ~\dots~ \verb,*}, \\[1ex]
kleing@14483
    83
wenzelm@14960
    84
  letter & = & latin ~|~ \verb,\<,latin\verb,>, ~|~ \verb,\<,latin\,latin\verb,>, ~|~ greek ~|~ \\
wenzelm@14960
    85
         &   & \verb,\<^isub>, ~|~ \verb,\<^isup>, \\
wenzelm@14960
    86
  quasiletter & = & letter ~|~ digit ~|~ \verb,_, ~|~ \verb,', \\
wenzelm@14895
    87
  latin & = & \verb,a, ~|~ \dots ~|~ \verb,z, ~|~ \verb,A, ~|~ \dots ~|~ \verb,Z, \\
wenzelm@7315
    88
  digit & = & \verb,0, ~|~ \dots ~|~ \verb,9, \\
wenzelm@7315
    89
  sym & = & \verb,!, ~|~ \verb,#, ~|~ \verb,$, ~|~ \verb,%, ~|~ \verb,&, ~|~  %$
wenzelm@10160
    90
   \verb,*, ~|~ \verb,+, ~|~ \verb,-, ~|~ \verb,/, ~|~ \verb,:, ~|~ \\
wenzelm@10160
    91
  & & \verb,<, ~|~ \verb,=, ~|~ \verb,>, ~|~ \verb,?, ~|~ \texttt{\at} ~|~
wenzelm@10160
    92
  \verb,^, ~|~ \verb,_, ~|~ \verb,`, ~|~ \verb,|, ~|~ \verb,~, \\
wenzelm@14955
    93
greek & = & \verb,\<alpha>, ~|~ \verb,\<beta>, ~|~ \verb,\<gamma>, ~|~ \verb,\<delta>, ~| \\
wenzelm@14955
    94
      &   & \verb,\<epsilon>, ~|~ \verb,\<zeta>, ~|~ \verb,\<eta>, ~|~ \verb,\<theta>, ~| \\
wenzelm@14955
    95
      &   & \verb,\<iota>, ~|~ \verb,\<kappa>, ~|~ \verb,\<mu>, ~|~ \verb,\<nu>, ~| \\
wenzelm@14955
    96
      &   & \verb,\<xi>, ~|~ \verb,\<pi>, ~|~ \verb,\<rho>, ~|~ \verb,\<sigma>, ~| \\
wenzelm@14955
    97
      &   & \verb,\<tau>, ~|~ \verb,\<upsilon>, ~|~ \verb,\<phi>, ~|~ \verb,\<psi>, ~| \\
wenzelm@14955
    98
      &   & \verb,\<omega>, ~|~ \verb,\<Gamma>, ~|~ \verb,\<Delta>, ~|~ \verb,\<Theta>, ~| \\
wenzelm@14955
    99
      &   & \verb,\<Lambda>, ~|~ \verb,\<Xi>, ~|~ \verb,\<Pi>, ~|~ \verb,\<Sigma>, ~| \\
wenzelm@14955
   100
      &   & \verb,\<Upsilon>, ~|~ \verb,\<Phi>, ~|~ \verb,\<Psi>, ~|~ \verb,\<Omega>, \\
wenzelm@7315
   101
\end{matharray}
wenzelm@7315
   102
wenzelm@13039
   103
The syntax of $string$ admits any characters, including newlines; ``\verb|"|''
wenzelm@13039
   104
(double-quote) and ``\verb|\|'' (backslash) need to be escaped by a backslash.
wenzelm@14955
   105
The body of $verbatim$ may consist of any text not containing ``\verb|*}|'';
wenzelm@14955
   106
this allows convenient inclusion of quotes without further escapes.  The greek
wenzelm@14955
   107
letters do \emph{not} include \verb,\<lambda>,, which is already used
wenzelm@14955
   108
differently in the meta-logic.
wenzelm@7315
   109
wenzelm@14955
   110
Common mathematical symbols such as $\forall$ are represented in Isabelle as
wenzelm@14955
   111
\verb,\<forall>,.  There are infinitely many legal symbols like this, although
wenzelm@14955
   112
proper presentation is left to front-end tools such as {\LaTeX} or
wenzelm@14955
   113
Proof~General with the X-Symbol package.  A list of standard Isabelle symbols
wenzelm@14955
   114
that work well with these tools is given in \cite[appendix~A]{isabelle-sys}.
wenzelm@14955
   115
wenzelm@14955
   116
Comments take the form \texttt{(*~\dots~*)} and may be nested, although
wenzelm@14955
   117
user-interface tools may prevent this.  Note that \texttt{(*~\dots~*)}
wenzelm@14955
   118
indicate source comments only, which are stripped after lexical analysis of
wenzelm@14955
   119
the input.  The Isar document syntax also provides formal comments that are
wenzelm@14955
   120
considered as part of the text (see \S\ref{sec:comments}).
wenzelm@12618
   121
wenzelm@12618
   122
\begin{warn}
wenzelm@12618
   123
  Proof~General does not handle nested comments properly; it is also unable to
wenzelm@12618
   124
  keep \verb,(*,\,/\,\verb,{*, and \verb,*),\,/\,\verb,*}, apart, despite
wenzelm@12618
   125
  their rather different meaning.  These are inherent problems of Emacs
wenzelm@13039
   126
  legacy.  Users should not be overly aggressive about nesting or alternating
wenzelm@13039
   127
  these delimiters.
wenzelm@12618
   128
\end{warn}
wenzelm@12618
   129
wenzelm@7046
   130
wenzelm@7046
   131
\section{Common syntax entities}
wenzelm@7046
   132
wenzelm@7335
   133
Subsequently, we introduce several basic syntactic entities, such as names,
wenzelm@7895
   134
terms, and theorem specifications, which have been factored out of the actual
wenzelm@7895
   135
Isar language elements to be described later.
wenzelm@7134
   136
wenzelm@14895
   137
Note that some of the basic syntactic entities introduced below (e.g.\
wenzelm@14895
   138
\railqtok{name}) act much like tokens rather than plain nonterminals (e.g.\
wenzelm@7895
   139
\railnonterm{sort}), especially for the sake of error messages.  E.g.\ syntax
wenzelm@13048
   140
elements like $\CONSTS$ referring to \railqtok{name} or \railqtok{type} would
wenzelm@13048
   141
really report a missing name or type rather than any of the constituent
wenzelm@13048
   142
primitive tokens such as \railtok{ident} or \railtok{string}.
wenzelm@7046
   143
wenzelm@7050
   144
wenzelm@7050
   145
\subsection{Names}
wenzelm@7050
   146
wenzelm@13048
   147
Entity \railqtok{name} usually refers to any name of types, constants,
wenzelm@7167
   148
theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
wenzelm@8548
   149
identifiers are excluded here).  Quoted strings provide an escape for
wenzelm@14895
   150
non-identifier names or those ruled out by outer syntax keywords (e.g.\
wenzelm@7134
   151
\verb|"let"|).  Already existing objects are usually referenced by
wenzelm@13048
   152
\railqtok{nameref}.
wenzelm@7050
   153
wenzelm@7141
   154
\indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
wenzelm@9617
   155
\indexoutertoken{int}
wenzelm@7046
   156
\begin{rail}
wenzelm@8145
   157
  name: ident | symident | string | nat
wenzelm@7046
   158
  ;
wenzelm@7167
   159
  parname: '(' name ')'
wenzelm@7141
   160
  ;
wenzelm@7167
   161
  nameref: name | longident
wenzelm@7046
   162
  ;
wenzelm@9617
   163
  int: nat | '-' nat
wenzelm@9617
   164
  ;
wenzelm@7046
   165
\end{rail}
wenzelm@7046
   166
wenzelm@7050
   167
wenzelm@7315
   168
\subsection{Comments}\label{sec:comments}
wenzelm@7046
   169
wenzelm@13048
   170
Large chunks of plain \railqtok{text} are usually given \railtok{verbatim},
wenzelm@13048
   171
i.e.\ enclosed in \verb|{*|~\dots~\verb|*}|.  For convenience, any of the
wenzelm@13048
   172
smaller text units conforming to \railqtok{nameref} are admitted as well.  A
wenzelm@13048
   173
marginal \railnonterm{comment} is of the form \texttt{--} \railqtok{text}.
wenzelm@13048
   174
Any number of these may occur within Isabelle/Isar commands.
wenzelm@12618
   175
wenzelm@12879
   176
\indexoutertoken{text}\indexouternonterm{comment}
wenzelm@7046
   177
\begin{rail}
wenzelm@7167
   178
  text: verbatim | nameref
wenzelm@7050
   179
  ;
wenzelm@12879
   180
  comment: '--' text
wenzelm@7046
   181
  ;
wenzelm@7046
   182
\end{rail}
wenzelm@7046
   183
wenzelm@7046
   184
wenzelm@7335
   185
\subsection{Type classes, sorts and arities}
wenzelm@7046
   186
wenzelm@8896
   187
Classes are specified by plain names.  Sorts have a very simple inner syntax,
wenzelm@8896
   188
which is either a single class name $c$ or a list $\{c@1, \dots, c@n\}$
wenzelm@8896
   189
referring to the intersection of these classes.  The syntax of type arities is
wenzelm@8896
   190
given directly at the outer level.
wenzelm@7050
   191
wenzelm@11100
   192
\railalias{subseteq}{\isasymsubseteq}
wenzelm@11100
   193
\railterm{subseteq}
wenzelm@11100
   194
wenzelm@14605
   195
\indexouternonterm{sort}\indexouternonterm{arity}
wenzelm@7135
   196
\indexouternonterm{classdecl}
wenzelm@7046
   197
\begin{rail}
wenzelm@11100
   198
  classdecl: name (('<' | subseteq) (nameref + ','))?
wenzelm@7046
   199
  ;
wenzelm@8896
   200
  sort: nameref
wenzelm@7046
   201
  ;
wenzelm@7167
   202
  arity: ('(' (sort + ',') ')')? sort
wenzelm@7046
   203
  ;
wenzelm@7046
   204
\end{rail}
wenzelm@7046
   205
wenzelm@7046
   206
wenzelm@7167
   207
\subsection{Types and terms}\label{sec:types-terms}
wenzelm@7046
   208
wenzelm@7167
   209
The actual inner Isabelle syntax, that of types and terms of the logic, is far
wenzelm@7895
   210
too sophisticated in order to be modelled explicitly at the outer theory
wenzelm@8548
   211
level.  Basically, any such entity has to be quoted to turn it into a single
wenzelm@8548
   212
token (the parsing and type-checking is performed internally later).  For
wenzelm@8548
   213
convenience, a slightly more liberal convention is adopted: quotes may be
wenzelm@13039
   214
omitted for any type or term that is already atomic at the outer level.  For
wenzelm@13039
   215
example, one may just write \texttt{x} instead of \texttt{"x"}.  Note that
wenzelm@8548
   216
symbolic identifiers (e.g.\ \texttt{++} or $\forall$) are available as well,
wenzelm@12618
   217
provided these have not been superseded by commands or other keywords already
wenzelm@12618
   218
(e.g.\ \texttt{=} or \texttt{+}).
wenzelm@7050
   219
wenzelm@7050
   220
\indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
wenzelm@7046
   221
\begin{rail}
wenzelm@7167
   222
  type: nameref | typefree | typevar
wenzelm@7050
   223
  ;
wenzelm@8593
   224
  term: nameref | var
wenzelm@7050
   225
  ;
wenzelm@7167
   226
  prop: term
wenzelm@7050
   227
  ;
wenzelm@7046
   228
\end{rail}
wenzelm@7046
   229
wenzelm@8690
   230
Positional instantiations are indicated by giving a sequence of terms, or the
wenzelm@8690
   231
placeholder ``$\_$'' (underscore), which means to skip a position.
wenzelm@8690
   232
wenzelm@8690
   233
\indexoutertoken{inst}\indexoutertoken{insts}
wenzelm@8690
   234
\begin{rail}
wenzelm@8690
   235
  inst: underscore | term
wenzelm@8690
   236
  ;
wenzelm@8690
   237
  insts: (inst *)
wenzelm@8690
   238
  ;
wenzelm@8690
   239
\end{rail}
wenzelm@8690
   240
wenzelm@7167
   241
Type declarations and definitions usually refer to \railnonterm{typespec} on
wenzelm@7167
   242
the left-hand side.  This models basic type constructor application at the
wenzelm@7167
   243
outer syntax level.  Note that only plain postfix notation is available here,
wenzelm@7167
   244
but no infixes.
wenzelm@7050
   245
wenzelm@7050
   246
\indexouternonterm{typespec}
wenzelm@7050
   247
\begin{rail}
wenzelm@7167
   248
  typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
wenzelm@7050
   249
  ;
wenzelm@7050
   250
\end{rail}
wenzelm@7050
   251
wenzelm@7050
   252
wenzelm@7046
   253
\subsection{Mixfix annotations}
wenzelm@7046
   254
wenzelm@7134
   255
Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
wenzelm@12618
   256
terms.  Some commands such as $\TYPES$ (see \S\ref{sec:types-pure}) admit
wenzelm@12618
   257
infixes only, while $\CONSTS$ (see \S\ref{sec:consts}) and
wenzelm@12618
   258
$\isarkeyword{syntax}$ (see \S\ref{sec:syn-trans}) support the full range of
wenzelm@12618
   259
general mixfixes and binders.
wenzelm@7046
   260
wenzelm@12976
   261
\indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix}
wenzelm@7050
   262
\begin{rail}
wenzelm@11651
   263
  infix: '(' ('infix' | 'infixl' | 'infixr') string? nat ')'
wenzelm@7167
   264
  ;
wenzelm@7175
   265
  mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')'
wenzelm@7050
   266
  ;
wenzelm@12976
   267
  structmixfix: mixfix | '(' 'structure' ')'
wenzelm@12976
   268
  ;
wenzelm@7046
   269
wenzelm@7175
   270
  prios: '[' (nat + ',') ']'
wenzelm@7050
   271
  ;
wenzelm@7050
   272
\end{rail}
wenzelm@7046
   273
wenzelm@13048
   274
Here the \railtok{string} specifications refer to the actual mixfix template
wenzelm@12618
   275
(see also \cite{isabelle-ref}), which may include literal text, spacing,
wenzelm@12618
   276
blocks, and arguments (denoted by ``$_$''); the special symbol \verb,\<index>,
wenzelm@12618
   277
(printed as ``\i'') represents an index argument that specifies an implicit
wenzelm@12618
   278
structure reference (see also \S\ref{sec:locale}).  Infix and binder
wenzelm@12618
   279
declarations provide common abbreviations for particular mixfix declarations.
wenzelm@12618
   280
So in practice, mixfix templates mostly degenerate to literal text for
wenzelm@12618
   281
concrete syntax, such as ``\verb,++,'' for an infix symbol, or ``\verb,++,\i''
wenzelm@12618
   282
for an infix of an implicit structure.
wenzelm@12618
   283
wenzelm@12618
   284
wenzelm@12618
   285
wenzelm@12618
   286
\subsection{Proof methods}\label{sec:syn-meth}
wenzelm@12618
   287
wenzelm@12618
   288
Proof methods are either basic ones, or expressions composed of methods via
wenzelm@12618
   289
``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternative choices),
wenzelm@12618
   290
``\texttt{?}'' (try), ``\texttt{+}'' (repeat at least once).  In practice,
wenzelm@12618
   291
proof methods are usually just a comma separated list of
wenzelm@13048
   292
\railqtok{nameref}~\railnonterm{args} specifications.  Note that parentheses
wenzelm@12618
   293
may be dropped for single method specifications (with no arguments).
wenzelm@12618
   294
wenzelm@12618
   295
\indexouternonterm{method}
wenzelm@12618
   296
\begin{rail}
wenzelm@12618
   297
  method: (nameref | '(' methods ')') (() | '?' | '+')
wenzelm@12618
   298
  ;
wenzelm@12618
   299
  methods: (nameref args | method) + (',' | '|')
wenzelm@12618
   300
  ;
wenzelm@12618
   301
\end{rail}
wenzelm@12618
   302
wenzelm@12618
   303
Proper use of Isar proof methods does \emph{not} involve goal addressing.
wenzelm@12618
   304
Nevertheless, specifying goal ranges may occasionally come in handy in
wenzelm@12618
   305
emulating tactic scripts.  Note that $[n-]$ refers to all goals, starting from
wenzelm@12618
   306
$n$.  All goals may be specified by $[!]$, which is the same as $[1-]$.
wenzelm@12618
   307
wenzelm@12618
   308
\indexouternonterm{goalspec}
wenzelm@12618
   309
\begin{rail}
wenzelm@12618
   310
  goalspec: '[' (nat '-' nat | nat '-' | nat | '!' ) ']'
wenzelm@12618
   311
  ;
wenzelm@12618
   312
\end{rail}
wenzelm@12618
   313
wenzelm@7050
   314
wenzelm@7134
   315
\subsection{Attributes and theorems}\label{sec:syn-att}
wenzelm@7050
   316
wenzelm@7050
   317
Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
wenzelm@7335
   318
``semi-inner'' syntax, in the sense that input conforming to
wenzelm@7335
   319
\railnonterm{args} below is parsed by the attribute a second time.  The
wenzelm@7335
   320
attribute argument specifications may be any sequence of atomic entities
wenzelm@7335
   321
(identifiers, strings etc.), or properly bracketed argument lists.  Below
wenzelm@13048
   322
\railqtok{atom} refers to any atomic entity, including any \railtok{keyword}
wenzelm@13048
   323
conforming to \railtok{symident}.
wenzelm@7050
   324
wenzelm@7050
   325
\indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
wenzelm@7050
   326
\begin{rail}
wenzelm@7466
   327
  atom: nameref | typefree | typevar | var | nat | keyword
wenzelm@7050
   328
  ;
wenzelm@8896
   329
  arg: atom | '(' args ')' | '[' args ']'
wenzelm@7134
   330
  ;
wenzelm@7167
   331
  args: arg *
wenzelm@7134
   332
  ;
wenzelm@7167
   333
  attributes: '[' (nameref args * ',') ']'
wenzelm@7050
   334
  ;
wenzelm@7050
   335
\end{rail}
wenzelm@7050
   336
wenzelm@7895
   337
Theorem specifications come in several flavors: \railnonterm{axmdecl} and
wenzelm@7175
   338
\railnonterm{thmdecl} usually refer to axioms, assumptions or results of goal
wenzelm@7981
   339
statements, while \railnonterm{thmdef} collects lists of existing theorems.
wenzelm@7981
   340
Existing theorems are given by \railnonterm{thmref} and \railnonterm{thmrefs},
wenzelm@7981
   341
the former requires an actual singleton result.  Any of these theorem
wenzelm@7175
   342
specifications may include lists of attributes both on the left and right hand
wenzelm@13039
   343
sides; attributes are applied to any immediately preceding fact.  If names are
wenzelm@13039
   344
omitted, the theorems are not stored within the theorem database of the theory
wenzelm@13039
   345
or proof context; any given attributes are still applied, though.
wenzelm@7050
   346
wenzelm@7135
   347
\indexouternonterm{thmdecl}\indexouternonterm{axmdecl}
wenzelm@7135
   348
\indexouternonterm{thmdef}\indexouternonterm{thmrefs}
wenzelm@7050
   349
\begin{rail}
wenzelm@7167
   350
  axmdecl: name attributes? ':'
wenzelm@7050
   351
  ;
wenzelm@9200
   352
  thmdecl: thmbind ':'
wenzelm@7135
   353
  ;
wenzelm@9200
   354
  thmdef: thmbind '='
wenzelm@7050
   355
  ;
wenzelm@7175
   356
  thmref: nameref attributes?
wenzelm@7175
   357
  ;
wenzelm@7175
   358
  thmrefs: thmref +
wenzelm@7134
   359
  ;
wenzelm@7167
   360
wenzelm@9200
   361
  thmbind: name attributes | name | attributes
wenzelm@7050
   362
  ;
wenzelm@7050
   363
\end{rail}
wenzelm@7050
   364
wenzelm@7050
   365
wenzelm@12618
   366
\subsection{Term patterns and declarations}\label{sec:term-decls}
wenzelm@7050
   367
wenzelm@12618
   368
Wherever explicit propositions (or term fragments) occur in a proof text,
wenzelm@12618
   369
casual binding of schematic term variables may be given specified via patterns
wenzelm@13039
   370
of the form ``$\ISS{p@1\;\dots}{p@n}$''.  There are separate versions
wenzelm@13048
   371
available for \railqtok{term}s and \railqtok{prop}s.  The latter provides a
wenzelm@13048
   372
$\CONCLNAME$ part with patterns referring the (atomic) conclusion of a rule.
wenzelm@7050
   373
wenzelm@12618
   374
\indexouternonterm{termpat}\indexouternonterm{proppat}
wenzelm@7050
   375
\begin{rail}
wenzelm@12618
   376
  termpat: '(' ('is' term +) ')'
wenzelm@7134
   377
  ;
wenzelm@12618
   378
  proppat: '(' (('is' prop +) | 'concl' ('is' prop +) | ('is' prop +) 'concl' ('is' prop +)) ')'
wenzelm@7050
   379
  ;
wenzelm@7050
   380
\end{rail}
wenzelm@7046
   381
wenzelm@12618
   382
Declarations of local variables $x :: \tau$ and logical propositions $a :
wenzelm@12618
   383
\phi$ represent different views on the same principle of introducing a local
wenzelm@12618
   384
scope.  In practice, one may usually omit the typing of $vars$ (due to
wenzelm@13039
   385
type-inference), and the naming of propositions (due to implicit references of
wenzelm@13039
   386
current facts).  In any case, Isar proof elements usually admit to introduce
wenzelm@12618
   387
multiple such items simultaneously.
wenzelm@8532
   388
wenzelm@12618
   389
\indexouternonterm{vars}\indexouternonterm{props}
wenzelm@8532
   390
\begin{rail}
wenzelm@12618
   391
  vars: (name+) ('::' type)?
wenzelm@12618
   392
  ;
wenzelm@12618
   393
  props: thmdecl? (prop proppat? +)
wenzelm@8532
   394
  ;
wenzelm@8532
   395
\end{rail}
wenzelm@8532
   396
wenzelm@12618
   397
The treatment of multiple declarations corresponds to the complementary focus
wenzelm@12618
   398
of $vars$ versus $props$: in ``$x@1~\dots~x@n :: \tau$'' the typing refers to
wenzelm@12618
   399
all variables, while in $a\colon \phi@1~\dots~\phi@n$ the naming refers to all
wenzelm@12618
   400
propositions collectively.  Isar language elements that refer to $vars$ or
wenzelm@12618
   401
$props$ typically admit separate typings or namings via another level of
wenzelm@12618
   402
iteration, with explicit $\AND$ separators; e.g.\ see $\FIXNAME$ and
wenzelm@12618
   403
$\ASSUMENAME$ in \S\ref{sec:proof-context}.
wenzelm@12618
   404
wenzelm@7046
   405
wenzelm@9200
   406
\subsection{Antiquotations}\label{sec:antiq}
wenzelm@9200
   407
wenzelm@10336
   408
\begin{matharray}{rcl}
wenzelm@10336
   409
  thm & : & \isarantiq \\
wenzelm@10336
   410
  prop & : & \isarantiq \\
wenzelm@10336
   411
  term & : & \isarantiq \\
wenzelm@10336
   412
  typ & : & \isarantiq \\
wenzelm@10336
   413
  text & : & \isarantiq \\
wenzelm@10336
   414
  goals & : & \isarantiq \\
nipkow@10351
   415
  subgoals & : & \isarantiq \\
berghofe@13827
   416
  prf & : & \isarantiq \\
berghofe@13827
   417
  full_prf & : & \isarantiq \\
wenzelm@10336
   418
\end{matharray}
wenzelm@10336
   419
wenzelm@9200
   420
The text body of formal comments (see also \S\ref{sec:comments}) may contain
wenzelm@9200
   421
antiquotations of logical entities, such as theorems, terms and types, which
wenzelm@9200
   422
are to be presented in the final output produced by the Isabelle document
wenzelm@9200
   423
preparation system (see also \S\ref{sec:document-prep}).
wenzelm@9200
   424
wenzelm@9601
   425
Thus embedding of
wenzelm@13039
   426
``\texttt{{\at}{\ttlbrace}term~[show_types]~"f(x)~=~a~+~x"{\ttrbrace}}''
wenzelm@13039
   427
within a text block would cause
wenzelm@9200
   428
\isa{(f{\isasymColon}'a~{\isasymRightarrow}~'a)~(x{\isasymColon}'a)~=~(a{\isasymColon}'a)~+~x}
wenzelm@10160
   429
to appear in the final {\LaTeX} document.  Also note that theorem
wenzelm@10160
   430
antiquotations may involve attributes as well.  For example,
wenzelm@10160
   431
\texttt{{\at}{\ttlbrace}thm~sym~[no_vars]{\ttrbrace}} would print the
wenzelm@10160
   432
statement where all schematic variables have been replaced by fixed ones,
wenzelm@12618
   433
which are easier to read.
wenzelm@9200
   434
wenzelm@9728
   435
\indexisarant{thm}\indexisarant{prop}\indexisarant{term}
wenzelm@10355
   436
\indexisarant{typ}\indexisarant{text}\indexisarant{goals}\indexisarant{subgoals}
wenzelm@9200
   437
\begin{rail}
wenzelm@9200
   438
  atsign lbrace antiquotation rbrace
wenzelm@9200
   439
  ;
wenzelm@9200
   440
wenzelm@9200
   441
  antiquotation:
wenzelm@9200
   442
    'thm' options thmrefs |
wenzelm@9200
   443
    'prop' options prop |
wenzelm@9200
   444
    'term' options term |
wenzelm@9728
   445
    'typ' options type |
wenzelm@10319
   446
    'text' options name |
wenzelm@10355
   447
    'goals' options |
berghofe@13827
   448
    'subgoals' options |
berghofe@13827
   449
    'prf' options thmrefs |
berghofe@13827
   450
    'full\_prf' options thmrefs
wenzelm@9200
   451
  ;
wenzelm@9200
   452
  options: '[' (option * ',') ']'
wenzelm@9200
   453
  ;
wenzelm@9200
   454
  option: name | name '=' name
wenzelm@9200
   455
  ;
wenzelm@9200
   456
\end{rail}
wenzelm@9200
   457
wenzelm@9200
   458
Note that the syntax of antiquotations may \emph{not} include source comments
wenzelm@9200
   459
\texttt{(*~\dots~*)} or verbatim text \verb|{*|~\dots~\verb|*}|.
wenzelm@9200
   460
wenzelm@10319
   461
\begin{descr}
wenzelm@14895
   462
wenzelm@10336
   463
\item [$\at\{thm~\vec a\}$] prints theorems $\vec a$. Note that attribute
wenzelm@10336
   464
  specifications may be included as well (see also \S\ref{sec:syn-att}); the
wenzelm@12618
   465
  $no_vars$ operation (see \S\ref{sec:misc-meth-att}) would be particularly
wenzelm@10336
   466
  useful to suppress printing of schematic variables.
wenzelm@13039
   467
wenzelm@10336
   468
\item [$\at\{prop~\phi\}$] prints a well-typed proposition $\phi$.
wenzelm@13039
   469
wenzelm@10336
   470
\item [$\at\{term~t\}$] prints a well-typed term $t$.
wenzelm@13039
   471
wenzelm@10336
   472
\item [$\at\{typ~\tau\}$] prints a well-formed type $\tau$.
wenzelm@14895
   473
wenzelm@10336
   474
\item [$\at\{text~s\}$] prints uninterpreted source text $s$.  This is
wenzelm@10336
   475
  particularly useful to print portions of text according to the Isabelle
wenzelm@10336
   476
  {\LaTeX} output style, without demanding well-formedness (e.g.\ small pieces
wenzelm@13039
   477
  of terms that should not be parsed or type-checked yet).
wenzelm@14895
   478
wenzelm@10336
   479
\item [$\at\{goals\}$] prints the current \emph{dynamic} goal state.  This is
wenzelm@13039
   480
  mainly for support of tactic-emulation scripts within Isar --- presentation
wenzelm@13039
   481
  of goal states does not conform to actual human-readable proof documents.
wenzelm@10319
   482
  Please do not include goal states into document output unless you really
wenzelm@10319
   483
  know what you are doing!
wenzelm@13039
   484
wenzelm@10355
   485
\item [$\at\{subgoals\}$] behaves almost like $goals$, except that it does not
wenzelm@10355
   486
  print the main goal.
wenzelm@13039
   487
berghofe@13827
   488
\item [$\at\{prf~\vec a\}$] prints the (compact) proof terms corresponding to
berghofe@13827
   489
  the theorems $\vec a$. Note that this
berghofe@13827
   490
  requires proof terms to be switched on for the current object logic
berghofe@13827
   491
  (see the ``Proof terms'' section of the Isabelle reference manual
berghofe@13827
   492
  for information on how to do this).
berghofe@13827
   493
berghofe@13827
   494
\item [$\at\{full_prf~\vec a\}$] is like $\at\{prf~\vec a\}$, but displays
berghofe@13827
   495
  the full proof terms, i.e.\ also displays information omitted in
berghofe@13827
   496
  the compact proof term, which is denoted by ``$_$'' placeholders there.
berghofe@13827
   497
wenzelm@10319
   498
\end{descr}
wenzelm@10319
   499
wenzelm@9200
   500
\medskip
wenzelm@9200
   501
wenzelm@10336
   502
The following options are available to tune the output.  Note that most of
wenzelm@9233
   503
these coincide with ML flags of the same names (see also \cite{isabelle-ref}).
wenzelm@9200
   504
\begin{descr}
wenzelm@9233
   505
\item[$show_types = bool$ and $show_sorts = bool$] control printing of
wenzelm@9234
   506
  explicit type and sort constraints.
wenzelm@14707
   507
\item[$show_structs = bool$] controls printing of implicit structures.
wenzelm@9233
   508
\item[$long_names = bool$] forces names of types and constants etc.\ to be
wenzelm@9233
   509
  printed in their fully qualified internal form.
wenzelm@9233
   510
\item[$eta_contract = bool$] prints terms in $\eta$-contracted form.
wenzelm@9200
   511
\item[$display = bool$] indicates if the text is to be output as multi-line
wenzelm@9200
   512
  ``display material'', rather than a small piece of text without line breaks
wenzelm@9200
   513
  (which is the default).
wenzelm@14689
   514
\item[$breaks = bool$] controls line breaks in non-display material.
wenzelm@9200
   515
\item[$quotes = bool$] indicates if the output should be enclosed in double
wenzelm@9200
   516
  quotes.
wenzelm@9233
   517
\item[$mode = name$] adds $name$ to the print mode to be used for presentation
wenzelm@9233
   518
  (see also \cite{isabelle-ref}).  Note that the standard setup for {\LaTeX}
wenzelm@9233
   519
  output is already present by default, including the modes ``$latex$'',
wenzelm@9233
   520
  ``$xsymbols$'', ``$symbols$''.
wenzelm@9728
   521
\item[$margin = nat$ and $indent = nat$] change the margin or indentation for
wenzelm@9728
   522
  pretty printing of display material.
wenzelm@9752
   523
\item[$source = bool$] prints the source text of the antiquotation arguments,
wenzelm@9752
   524
  rather than the actual value.  Note that this does not affect
wenzelm@9752
   525
  well-formedness checks of $thm$, $term$, etc. (only the $text$ antiquotation
wenzelm@9752
   526
  admits arbitrary output).
wenzelm@10319
   527
\item[$goals_limit = nat$] determines the maximum number of goals to be
wenzelm@10319
   528
  printed.
wenzelm@14895
   529
\item[$locale = name$] specifies an alternative context used for evaluating
wenzelm@14919
   530
  and printing the subsequent argument.
wenzelm@9200
   531
\end{descr}
wenzelm@9200
   532
wenzelm@9200
   533
For boolean flags, ``$name = true$'' may be abbreviated as ``$name$''.  All of
wenzelm@9200
   534
the above flags are disabled by default, unless changed from ML.
wenzelm@9200
   535
wenzelm@10336
   536
\medskip Note that antiquotations do not only spare the author from tedious
wenzelm@13039
   537
typing of logical entities, but also achieve some degree of
wenzelm@13039
   538
consistency-checking of informal explanations with formal developments:
wenzelm@13039
   539
well-formedness of terms and types with respect to the current theory or proof
wenzelm@13039
   540
context is ensured here.
wenzelm@9200
   541
wenzelm@14895
   542
%%% Local Variables:
wenzelm@7046
   543
%%% mode: latex
wenzelm@7046
   544
%%% TeX-master: "isar-ref"
wenzelm@14895
   545
%%% End: