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