author | huffman |
Wed, 08 Nov 2006 00:34:15 +0100 | |
changeset 21238 | c46bc715bdfd |
parent 17196 | d26778f3e6dd |
child 25338 | 6eb185959aec |
permissions | -rw-r--r-- |
11648 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Documents}% |
|
17056 | 4 |
% |
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
% |
|
11 |
\endisatagtheory |
|
12 |
{\isafoldtheory}% |
|
13 |
% |
|
14 |
\isadelimtheory |
|
15 |
% |
|
16 |
\endisadelimtheory |
|
12627 | 17 |
% |
12647 | 18 |
\isamarkupsection{Concrete Syntax \label{sec:concrete-syntax}% |
12627 | 19 |
} |
20 |
\isamarkuptrue% |
|
21 |
% |
|
22 |
\begin{isamarkuptext}% |
|
12767 | 23 |
The core concept of Isabelle's framework for concrete syntax is that |
24 |
of \bfindex{mixfix annotations}. Associated with any kind of |
|
25 |
constant declaration, mixfixes affect both the grammar productions |
|
26 |
for the parser and output templates for the pretty printer. |
|
12627 | 27 |
|
12743 | 28 |
In full generality, parser and pretty printer configuration is a |
12767 | 29 |
subtle affair \cite{isabelle-ref}. Your syntax specifications need |
30 |
to interact properly with the existing setup of Isabelle/Pure and |
|
31 |
Isabelle/HOL\@. To avoid creating ambiguities with existing |
|
32 |
elements, it is particularly important to give new syntactic |
|
12764 | 33 |
constructs the right precedence. |
12627 | 34 |
|
12671 | 35 |
\medskip Subsequently we introduce a few simple syntax declaration |
12743 | 36 |
forms that already cover many common situations fairly well.% |
12627 | 37 |
\end{isamarkuptext}% |
38 |
\isamarkuptrue% |
|
39 |
% |
|
12647 | 40 |
\isamarkupsubsection{Infix Annotations% |
12627 | 41 |
} |
42 |
\isamarkuptrue% |
|
43 |
% |
|
44 |
\begin{isamarkuptext}% |
|
12764 | 45 |
Syntax annotations may be included wherever constants are declared, |
12767 | 46 |
such as \isacommand{consts} and \isacommand{constdefs} --- and also |
47 |
\isacommand{datatype}, which declares constructor operations. |
|
48 |
Type-constructors may be annotated as well, although this is less |
|
49 |
frequently encountered in practice (the infix type \isa{{\isasymtimes}} comes |
|
50 |
to mind). |
|
12627 | 51 |
|
12644 | 52 |
Infix declarations\index{infix annotations} provide a useful special |
12767 | 53 |
case of mixfixes. The following example of the exclusive-or |
54 |
operation on boolean values illustrates typical infix declarations.% |
|
12627 | 55 |
\end{isamarkuptext}% |
17175 | 56 |
\isamarkuptrue% |
57 |
\isacommand{constdefs}\isamarkupfalse% |
|
58 |
\isanewline |
|
59 |
\ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
60 |
\ \ {\isachardoublequoteopen}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequoteclose}% |
|
12627 | 61 |
\begin{isamarkuptext}% |
12652 | 62 |
\noindent Now \isa{xor\ A\ B} and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} refer to the |
63 |
same expression internally. Any curried function with at least two |
|
12767 | 64 |
arguments may be given infix syntax. For partial applications with |
65 |
fewer than two operands, there is a notation using the prefix~\isa{op}. For instance, \isa{xor} without arguments is represented as |
|
66 |
\isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}}; together with ordinary function application, this |
|
12652 | 67 |
turns \isa{xor\ A} into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}. |
12627 | 68 |
|
12747 | 69 |
\medskip The keyword \isakeyword{infixl} seen above specifies an |
70 |
infix operator that is nested to the \emph{left}: in iterated |
|
71 |
applications the more complex expression appears on the left-hand |
|
12767 | 72 |
side, and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} stands for \isa{{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C}. Similarly, \isakeyword{infixr} means nesting to the |
73 |
\emph{right}, reading \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}. A \emph{non-oriented} declaration via \isakeyword{infix} |
|
74 |
would render \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} illegal, but demand explicit |
|
75 |
parentheses to indicate the intended grouping. |
|
12743 | 76 |
|
12747 | 77 |
The string \isa{{\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}} in our annotation refers to the |
78 |
concrete syntax to represent the operator (a literal token), while |
|
12764 | 79 |
the number \isa{{\isadigit{6}}{\isadigit{0}}} determines the precedence of the construct: |
12767 | 80 |
the syntactic priorities of the arguments and result. Isabelle/HOL |
81 |
already uses up many popular combinations of ASCII symbols for its |
|
82 |
own use, including both \isa{{\isacharplus}} and \isa{{\isacharplus}{\isacharplus}}. Longer |
|
83 |
character combinations are more likely to be still available for |
|
84 |
user extensions, such as our~\isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}}. |
|
12627 | 85 |
|
12767 | 86 |
Operator precedences have a range of 0--1000. Very low or high |
87 |
priorities are reserved for the meta-logic. HOL syntax mainly uses |
|
88 |
the range of 10--100: the equality infix \isa{{\isacharequal}} is centered at |
|
89 |
50; logical connectives (like \isa{{\isasymor}} and \isa{{\isasymand}}) are |
|
90 |
below 50; algebraic ones (like \isa{{\isacharplus}} and \isa{{\isacharasterisk}}) are |
|
91 |
above 50. User syntax should strive to coexist with common HOL |
|
92 |
forms, or use the mostly unused range 100--900.% |
|
12627 | 93 |
\end{isamarkuptext}% |
94 |
\isamarkuptrue% |
|
12635 | 95 |
% |
12658 | 96 |
\isamarkupsubsection{Mathematical Symbols \label{sec:syntax-symbols}% |
12635 | 97 |
} |
12627 | 98 |
\isamarkuptrue% |
12635 | 99 |
% |
100 |
\begin{isamarkuptext}% |
|
12767 | 101 |
Concrete syntax based on ASCII characters has inherent limitations. |
102 |
Mathematical notation demands a larger repertoire of glyphs. |
|
103 |
Several standards of extended character sets have been proposed over |
|
104 |
decades, but none has become universally available so far. Isabelle |
|
105 |
has its own notion of \bfindex{symbols} as the smallest entities of |
|
106 |
source text, without referring to internal encodings. There are |
|
107 |
three kinds of such ``generalized characters'': |
|
12635 | 108 |
|
109 |
\begin{enumerate} |
|
110 |
||
12652 | 111 |
\item 7-bit ASCII characters |
12635 | 112 |
|
12652 | 113 |
\item named symbols: \verb,\,\verb,<,$ident$\verb,>, |
12635 | 114 |
|
12652 | 115 |
\item named control symbols: \verb,\,\verb,<^,$ident$\verb,>, |
12635 | 116 |
|
117 |
\end{enumerate} |
|
118 |
||
14486 | 119 |
Here $ident$ is any sequence of letters. |
120 |
This results in an infinite store of symbols, whose |
|
12767 | 121 |
interpretation is left to further front-end tools. For example, the |
122 |
user-interface of Proof~General + X-Symbol and the Isabelle document |
|
123 |
processor (see \S\ref{sec:document-preparation}) display the |
|
124 |
\verb,\,\verb,<forall>, symbol as~\isa{{\isasymforall}}. |
|
12635 | 125 |
|
126 |
A list of standard Isabelle symbols is given in |
|
12767 | 127 |
\cite[appendix~A]{isabelle-sys}. You may introduce your own |
12635 | 128 |
interpretation of further symbols by configuring the appropriate |
12652 | 129 |
front-end tool accordingly, e.g.\ by defining certain {\LaTeX} |
130 |
macros (see also \S\ref{sec:doc-prep-symbols}). There are also a |
|
131 |
few predefined control symbols, such as \verb,\,\verb,<^sub>, and |
|
12635 | 132 |
\verb,\,\verb,<^sup>, for sub- and superscript of the subsequent |
12764 | 133 |
printable symbol, respectively. For example, \verb,A\<^sup>\<star>, is |
12671 | 134 |
output as \isa{A\isactrlsup {\isasymstar}}. |
12635 | 135 |
|
17187 | 136 |
A number of symbols are considered letters by the Isabelle lexer and |
137 |
can be used as part of identifiers. These are the greek letters |
|
138 |
\isa{{\isasymalpha}} (\verb+\+\verb+<alpha>+), \isa{{\isasymbeta}} |
|
139 |
(\verb+\+\verb+<beta>+), etc. (excluding \isa{{\isasymlambda}}), |
|
140 |
special letters like \isa{{\isasymA}} (\verb+\+\verb+<A>+) and \isa{{\isasymAA}} (\verb+\+\verb+<AA>+), and the control symbols |
|
141 |
\verb+\+\verb+<^isub>+ and \verb+\+\verb+<^isup>+ for single letter |
|
142 |
sub and super scripts. This means that the input |
|
14486 | 143 |
|
144 |
\medskip |
|
17187 | 145 |
{\small\noindent \verb,\,\verb,<forall>\,\verb,<alpha>\<^isub>1.,~\verb,\,\verb,<alpha>\<^isub>1 = \,\verb,<Pi>\<^isup>\<A>,} |
14486 | 146 |
|
147 |
\medskip |
|
148 |
\noindent is recognized as the term \isa{{\isasymforall}{\isasymalpha}\isactrlisub {\isadigit{1}}{\isachardot}\ {\isasymalpha}\isactrlisub {\isadigit{1}}\ {\isacharequal}\ {\isasymPi}\isactrlisup {\isasymA}} |
|
17187 | 149 |
by Isabelle. Note that \isa{{\isasymPi}\isactrlisup {\isasymA}} is a single |
150 |
syntactic entity, not an exponentiation. |
|
14486 | 151 |
|
17187 | 152 |
\medskip Replacing our previous definition of \isa{xor} by the |
153 |
following specifies an Isabelle symbol for the new operator:% |
|
12635 | 154 |
\end{isamarkuptext}% |
17175 | 155 |
\isamarkuptrue% |
17056 | 156 |
% |
157 |
\isadelimML |
|
158 |
% |
|
159 |
\endisadelimML |
|
160 |
% |
|
161 |
\isatagML |
|
162 |
% |
|
163 |
\endisatagML |
|
164 |
{\isafoldML}% |
|
165 |
% |
|
166 |
\isadelimML |
|
167 |
% |
|
168 |
\endisadelimML |
|
17175 | 169 |
\isacommand{constdefs}\isamarkupfalse% |
170 |
\isanewline |
|
171 |
\ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymoplus}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
17181 | 172 |
\ \ {\isachardoublequoteopen}A\ {\isasymoplus}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequoteclose}% |
12635 | 173 |
\begin{isamarkuptext}% |
12652 | 174 |
\noindent The X-Symbol package within Proof~General provides several |
175 |
input methods to enter \isa{{\isasymoplus}} in the text. If all fails one may |
|
12767 | 176 |
just type a named entity \verb,\,\verb,<oplus>, by hand; the |
177 |
corresponding symbol will be displayed after further input. |
|
12635 | 178 |
|
12767 | 179 |
\medskip More flexible is to provide alternative syntax forms |
180 |
through the \bfindex{print mode} concept~\cite{isabelle-ref}. By |
|
181 |
convention, the mode of ``$xsymbols$'' is enabled whenever |
|
182 |
Proof~General's X-Symbol mode or {\LaTeX} output is active. Now |
|
183 |
consider the following hybrid declaration of \isa{xor}:% |
|
12635 | 184 |
\end{isamarkuptext}% |
17175 | 185 |
\isamarkuptrue% |
17056 | 186 |
% |
187 |
\isadelimML |
|
188 |
% |
|
189 |
\endisadelimML |
|
190 |
% |
|
191 |
\isatagML |
|
192 |
% |
|
193 |
\endisatagML |
|
194 |
{\isafoldML}% |
|
195 |
% |
|
196 |
\isadelimML |
|
197 |
% |
|
198 |
\endisadelimML |
|
17175 | 199 |
\isacommand{constdefs}\isamarkupfalse% |
12635 | 200 |
\isanewline |
17175 | 201 |
\ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline |
202 |
\ \ {\isachardoublequoteopen}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isasymignore}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
203 |
\isanewline |
|
204 |
\isacommand{syntax}\isamarkupfalse% |
|
205 |
\ {\isacharparenleft}xsymbols{\isacharparenright}\isanewline |
|
17181 | 206 |
\ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymoplus}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}% |
12635 | 207 |
\begin{isamarkuptext}% |
12652 | 208 |
The \commdx{syntax} command introduced here acts like |
12743 | 209 |
\isakeyword{consts}, but without declaring a logical constant. The |
12747 | 210 |
print mode specification of \isakeyword{syntax}, here \isa{{\isacharparenleft}xsymbols{\isacharparenright}}, is optional. Also note that its type merely serves |
211 |
for syntactic purposes, and is \emph{not} checked for consistency |
|
212 |
with the real constant. |
|
12635 | 213 |
|
12672 | 214 |
\medskip We may now write \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} or \isa{A\ {\isasymoplus}\ B} in |
12767 | 215 |
input, while output uses the nicer syntax of $xsymbols$ whenever |
12672 | 216 |
that print mode is active. Such an arrangement is particularly |
12767 | 217 |
useful for interactive development, where users may type ASCII text |
218 |
and see mathematical symbols displayed during proofs.% |
|
12635 | 219 |
\end{isamarkuptext}% |
12627 | 220 |
\isamarkuptrue% |
12635 | 221 |
% |
12647 | 222 |
\isamarkupsubsection{Prefix Annotations% |
12635 | 223 |
} |
12627 | 224 |
\isamarkuptrue% |
12635 | 225 |
% |
226 |
\begin{isamarkuptext}% |
|
12767 | 227 |
Prefix syntax annotations\index{prefix annotation} are another form |
228 |
of mixfixes \cite{isabelle-ref}, without any template arguments or |
|
229 |
priorities --- just some literal syntax. The following example |
|
230 |
associates common symbols with the constructors of a datatype.% |
|
12635 | 231 |
\end{isamarkuptext}% |
17175 | 232 |
\isamarkuptrue% |
233 |
\isacommand{datatype}\isamarkupfalse% |
|
234 |
\ currency\ {\isacharequal}\isanewline |
|
235 |
\ \ \ \ Euro\ nat\ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isasymeuro}{\isachardoublequoteclose}{\isacharparenright}\isanewline |
|
236 |
\ \ {\isacharbar}\ Pounds\ nat\ \ {\isacharparenleft}{\isachardoublequoteopen}{\isasympounds}{\isachardoublequoteclose}{\isacharparenright}\isanewline |
|
237 |
\ \ {\isacharbar}\ Yen\ nat\ \ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isasymyen}{\isachardoublequoteclose}{\isacharparenright}\isanewline |
|
238 |
\ \ {\isacharbar}\ Dollar\ nat\ \ {\isacharparenleft}{\isachardoublequoteopen}{\isachardollar}{\isachardoublequoteclose}{\isacharparenright}% |
|
12635 | 239 |
\begin{isamarkuptext}% |
12652 | 240 |
\noindent Here the mixfix annotations on the rightmost column happen |
241 |
to consist of a single Isabelle symbol each: \verb,\,\verb,<euro>,, |
|
242 |
\verb,\,\verb,<pounds>,, \verb,\,\verb,<yen>,, and \verb,$,. Recall |
|
12747 | 243 |
that a constructor like \isa{Euro} actually is a function \isa{nat\ {\isasymRightarrow}\ currency}. The expression \isa{Euro\ {\isadigit{1}}{\isadigit{0}}} will be |
12652 | 244 |
printed as \isa{{\isasymeuro}\ {\isadigit{1}}{\isadigit{0}}}; only the head of the application is |
12743 | 245 |
subject to our concrete syntax. This rather simple form already |
246 |
achieves conformance with notational standards of the European |
|
247 |
Commission. |
|
12635 | 248 |
|
12767 | 249 |
Prefix syntax works the same way for \isakeyword{consts} or |
12764 | 250 |
\isakeyword{constdefs}.% |
12649 | 251 |
\end{isamarkuptext}% |
252 |
\isamarkuptrue% |
|
253 |
% |
|
254 |
\isamarkupsubsection{Syntax Translations \label{sec:syntax-translations}% |
|
12635 | 255 |
} |
12627 | 256 |
\isamarkuptrue% |
12635 | 257 |
% |
258 |
\begin{isamarkuptext}% |
|
12767 | 259 |
Mixfix syntax annotations merely decorate particular constant |
260 |
application forms with concrete syntax, for instance replacing \ |
|
261 |
\isa{xor\ A\ B} by \isa{A\ {\isasymoplus}\ B}. Occasionally, the |
|
262 |
relationship between some piece of notation and its internal form is |
|
263 |
more complicated. Here we need \bfindex{syntax translations}. |
|
12635 | 264 |
|
12764 | 265 |
Using the \isakeyword{syntax}\index{syntax (command)}, command we |
266 |
introduce uninterpreted notational elements. Then |
|
267 |
\commdx{translations} relate input forms to complex logical |
|
12767 | 268 |
expressions. This provides a simple mechanism for syntactic macros; |
269 |
even heavier transformations may be written in ML |
|
12671 | 270 |
\cite{isabelle-ref}. |
12649 | 271 |
|
12764 | 272 |
\medskip A typical use of syntax translations is to introduce |
12767 | 273 |
relational notation for membership in a set of pair, replacing \ |
274 |
\isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim} by \isa{x\ {\isasymapprox}\ y}.% |
|
12635 | 275 |
\end{isamarkuptext}% |
17175 | 276 |
\isamarkuptrue% |
277 |
\isacommand{consts}\isamarkupfalse% |
|
278 |
\isanewline |
|
279 |
\ \ sim\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}\ set{\isachardoublequoteclose}\isanewline |
|
12649 | 280 |
\isanewline |
17175 | 281 |
\isacommand{syntax}\isamarkupfalse% |
282 |
\isanewline |
|
283 |
\ \ {\isachardoublequoteopen}{\isacharunderscore}sim{\isachardoublequoteclose}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infix}\ {\isachardoublequoteopen}{\isasymapprox}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
284 |
\isacommand{translations}\isamarkupfalse% |
|
285 |
\isanewline |
|
286 |
\ \ {\isachardoublequoteopen}x\ {\isasymapprox}\ y{\isachardoublequoteclose}\ {\isasymrightleftharpoons}\ {\isachardoublequoteopen}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim{\isachardoublequoteclose}% |
|
12635 | 287 |
\begin{isamarkuptext}% |
12649 | 288 |
\noindent Here the name of the dummy constant \isa{{\isacharunderscore}sim} does |
12767 | 289 |
not matter, as long as it is not used elsewhere. Prefixing an |
290 |
underscore is a common convention. The \isakeyword{translations} |
|
12649 | 291 |
declaration already uses concrete syntax on the left-hand side; |
292 |
internally we relate a raw application \isa{{\isacharunderscore}sim\ x\ y} with |
|
293 |
\isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim}. |
|
12635 | 294 |
|
12652 | 295 |
\medskip Another common application of syntax translations is to |
12649 | 296 |
provide variant versions of fundamental relational expressions, such |
297 |
as \isa{{\isasymnoteq}} for negated equalities. The following declaration |
|
298 |
stems from Isabelle/HOL itself:% |
|
299 |
\end{isamarkuptext}% |
|
17175 | 300 |
\isamarkuptrue% |
301 |
\isacommand{syntax}\isamarkupfalse% |
|
302 |
\ {\isachardoublequoteopen}{\isacharunderscore}not{\isacharunderscore}equal{\isachardoublequoteclose}\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ bool{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isasymnoteq}{\isasymignore}{\isachardoublequoteclose}\ {\isadigit{5}}{\isadigit{0}}{\isacharparenright}\isanewline |
|
303 |
\isacommand{translations}\isamarkupfalse% |
|
304 |
\ {\isachardoublequoteopen}x\ {\isasymnoteq}{\isasymignore}\ y{\isachardoublequoteclose}\ {\isasymrightleftharpoons}\ {\isachardoublequoteopen}{\isasymnot}\ {\isacharparenleft}x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequoteclose}% |
|
12649 | 305 |
\begin{isamarkuptext}% |
306 |
\noindent Normally one would introduce derived concepts like this |
|
12652 | 307 |
within the logic, using \isakeyword{consts} + \isakeyword{defs} |
308 |
instead of \isakeyword{syntax} + \isakeyword{translations}. The |
|
12649 | 309 |
present formulation has the virtue that expressions are immediately |
12666 | 310 |
replaced by the ``definition'' upon parsing; the effect is reversed |
311 |
upon printing. |
|
12649 | 312 |
|
12767 | 313 |
This sort of translation is appropriate when the defined concept is |
314 |
a trivial variation on an existing one. On the other hand, syntax |
|
315 |
translations do not scale up well to large hierarchies of concepts. |
|
316 |
Translations do not replace definitions!% |
|
12635 | 317 |
\end{isamarkuptext}% |
12627 | 318 |
\isamarkuptrue% |
12635 | 319 |
% |
12652 | 320 |
\isamarkupsection{Document Preparation \label{sec:document-preparation}% |
12635 | 321 |
} |
322 |
\isamarkuptrue% |
|
323 |
% |
|
12644 | 324 |
\begin{isamarkuptext}% |
12652 | 325 |
Isabelle/Isar is centered around the concept of \bfindex{formal |
12767 | 326 |
proof documents}\index{documents|bold}. The outcome of a formal |
327 |
development effort is meant to be a human-readable record, presented |
|
328 |
as browsable PDF file or printed on paper. The overall document |
|
329 |
structure follows traditional mathematical articles, with sections, |
|
330 |
intermediate explanations, definitions, theorems and proofs. |
|
12644 | 331 |
|
332 |
\medskip The Isabelle document preparation system essentially acts |
|
12671 | 333 |
as a front-end to {\LaTeX}. After checking specifications and |
334 |
proofs formally, the theory sources are turned into typesetting |
|
12767 | 335 |
instructions in a schematic manner. This lets you write authentic |
336 |
reports on theory developments with little effort: many technical |
|
337 |
consistency checks are handled by the system. |
|
12745 | 338 |
|
339 |
Here is an example to illustrate the idea of Isabelle document |
|
12747 | 340 |
preparation.% |
341 |
\end{isamarkuptext}% |
|
17175 | 342 |
\isamarkuptrue% |
12747 | 343 |
% |
344 |
\begin{quotation} |
|
345 |
% |
|
346 |
\begin{isamarkuptext}% |
|
347 |
The following datatype definition of \isa{{\isacharprime}a\ bintree} models |
|
348 |
binary trees with nodes being decorated by elements of type \isa{{\isacharprime}a}.% |
|
12745 | 349 |
\end{isamarkuptext}% |
17175 | 350 |
\isamarkuptrue% |
351 |
\isacommand{datatype}\isamarkupfalse% |
|
352 |
\ {\isacharprime}a\ bintree\ {\isacharequal}\isanewline |
|
353 |
\ \ \ \ \ Leaf\ {\isacharbar}\ Branch\ {\isacharprime}a\ \ {\isachardoublequoteopen}{\isacharprime}a\ bintree{\isachardoublequoteclose}\ \ {\isachardoublequoteopen}{\isacharprime}a\ bintree{\isachardoublequoteclose}% |
|
12745 | 354 |
\begin{isamarkuptext}% |
355 |
\noindent The datatype induction rule generated here is of the form |
|
356 |
\begin{isabelle}% |
|
12749 | 357 |
\ {\isasymlbrakk}P\ Leaf{\isacharsemicolon}\isanewline |
14379 | 358 |
\isaindent{\ \ }{\isasymAnd}a\ bintree{\isadigit{1}}\ bintree{\isadigit{2}}{\isachardot}\isanewline |
359 |
\isaindent{\ \ \ \ \ }{\isasymlbrakk}P\ bintree{\isadigit{1}}{\isacharsemicolon}\ P\ bintree{\isadigit{2}}{\isasymrbrakk}\ {\isasymLongrightarrow}\ P\ {\isacharparenleft}Branch\ a\ bintree{\isadigit{1}}\ bintree{\isadigit{2}}{\isacharparenright}{\isasymrbrakk}\isanewline |
|
12749 | 360 |
\isaindent{\ }{\isasymLongrightarrow}\ P\ bintree% |
12747 | 361 |
\end{isabelle}% |
362 |
\end{isamarkuptext}% |
|
17175 | 363 |
\isamarkuptrue% |
12747 | 364 |
% |
365 |
\end{quotation} |
|
366 |
% |
|
367 |
\begin{isamarkuptext}% |
|
12767 | 368 |
\noindent The above document output has been produced as follows: |
12745 | 369 |
|
370 |
\begin{ttbox} |
|
371 |
text {\ttlbrace}* |
|
372 |
The following datatype definition of {\at}{\ttlbrace}text "'a bintree"{\ttrbrace} |
|
373 |
models binary trees with nodes being decorated by elements |
|
374 |
of type {\at}{\ttlbrace}typ 'a{\ttrbrace}. |
|
375 |
*{\ttrbrace} |
|
376 |
||
377 |
datatype 'a bintree = |
|
378 |
Leaf | Branch 'a "'a bintree" "'a bintree" |
|
12767 | 379 |
\end{ttbox} |
380 |
\begin{ttbox} |
|
12745 | 381 |
text {\ttlbrace}* |
382 |
{\ttback}noindent The datatype induction rule generated here is |
|
383 |
of the form {\at}{\ttlbrace}thm [display] bintree.induct [no_vars]{\ttrbrace} |
|
384 |
*{\ttrbrace} |
|
12767 | 385 |
\end{ttbox}\vspace{-\medskipamount} |
12745 | 386 |
|
12747 | 387 |
\noindent Here we have augmented the theory by formal comments |
12767 | 388 |
(using \isakeyword{text} blocks), the informal parts may again refer |
389 |
to formal entities by means of ``antiquotations'' (such as |
|
12745 | 390 |
\texttt{\at}\verb,{text "'a bintree"}, or |
12747 | 391 |
\texttt{\at}\verb,{typ 'a},), see also \S\ref{sec:doc-prep-text}.% |
12644 | 392 |
\end{isamarkuptext}% |
12635 | 393 |
\isamarkuptrue% |
394 |
% |
|
12647 | 395 |
\isamarkupsubsection{Isabelle Sessions% |
12635 | 396 |
} |
397 |
\isamarkuptrue% |
|
398 |
% |
|
399 |
\begin{isamarkuptext}% |
|
12652 | 400 |
In contrast to the highly interactive mode of Isabelle/Isar theory |
401 |
development, the document preparation stage essentially works in |
|
12671 | 402 |
batch-mode. An Isabelle \bfindex{session} consists of a collection |
12767 | 403 |
of source files that may contribute to an output document. Each |
404 |
session is derived from a single parent, usually an object-logic |
|
405 |
image like \texttt{HOL}. This results in an overall tree structure, |
|
406 |
which is reflected by the output location in the file system |
|
407 |
(usually rooted at \verb,~/isabelle/browser_info,). |
|
12644 | 408 |
|
12684 | 409 |
\medskip The easiest way to manage Isabelle sessions is via |
12686 | 410 |
\texttt{isatool mkdir} (generates an initial session source setup) |
411 |
and \texttt{isatool make} (run sessions controlled by |
|
12684 | 412 |
\texttt{IsaMakefile}). For example, a new session |
413 |
\texttt{MySession} derived from \texttt{HOL} may be produced as |
|
414 |
follows: |
|
415 |
||
416 |
\begin{verbatim} |
|
417 |
isatool mkdir HOL MySession |
|
418 |
isatool make |
|
419 |
\end{verbatim} |
|
420 |
||
12686 | 421 |
The \texttt{isatool make} job also informs about the file-system |
422 |
location of the ultimate results. The above dry run should be able |
|
423 |
to produce some \texttt{document.pdf} (with dummy title, empty table |
|
12743 | 424 |
of contents etc.). Any failure at this stage usually indicates |
17187 | 425 |
technical problems of the {\LaTeX} installation. |
12684 | 426 |
|
427 |
\medskip The detailed arrangement of the session sources is as |
|
12747 | 428 |
follows. |
12644 | 429 |
|
430 |
\begin{itemize} |
|
431 |
||
12671 | 432 |
\item Directory \texttt{MySession} holds the required theory files |
433 |
$T@1$\texttt{.thy}, \dots, $T@n$\texttt{.thy}. |
|
12644 | 434 |
|
435 |
\item File \texttt{MySession/ROOT.ML} holds appropriate ML commands |
|
436 |
for loading all wanted theories, usually just |
|
12666 | 437 |
``\texttt{use_thy"$T@i$";}'' for any $T@i$ in leaf position of the |
12671 | 438 |
dependency graph. |
12644 | 439 |
|
440 |
\item Directory \texttt{MySession/document} contains everything |
|
12652 | 441 |
required for the {\LaTeX} stage; only \texttt{root.tex} needs to be |
442 |
provided initially. |
|
12644 | 443 |
|
12652 | 444 |
The latter file holds appropriate {\LaTeX} code to commence a |
445 |
document (\verb,\documentclass, etc.), and to include the generated |
|
12743 | 446 |
files $T@i$\texttt{.tex} for each theory. Isabelle will generate a |
447 |
file \texttt{session.tex} holding {\LaTeX} commands to include all |
|
12747 | 448 |
generated theory output files in topologically sorted order, so |
449 |
\verb,\input{session}, in the body of \texttt{root.tex} does the job |
|
450 |
in most situations. |
|
12652 | 451 |
|
12682 | 452 |
\item \texttt{IsaMakefile} holds appropriate dependencies and |
453 |
invocations of Isabelle tools to control the batch job. In fact, |
|
12747 | 454 |
several sessions may be managed by the same \texttt{IsaMakefile}. |
12764 | 455 |
See the \emph{Isabelle System Manual} \cite{isabelle-sys} |
456 |
for further details, especially on |
|
12652 | 457 |
\texttt{isatool usedir} and \texttt{isatool make}. |
12644 | 458 |
|
459 |
\end{itemize} |
|
460 |
||
12686 | 461 |
One may now start to populate the directory \texttt{MySession}, and |
12767 | 462 |
the file \texttt{MySession/ROOT.ML} accordingly. The file |
463 |
\texttt{MySession/document/root.tex} should also be adapted at some |
|
12686 | 464 |
point; the default version is mostly self-explanatory. Note that |
465 |
\verb,\isabellestyle, enables fine-tuning of the general appearance |
|
466 |
of characters and mathematical symbols (see also |
|
467 |
\S\ref{sec:doc-prep-symbols}). |
|
12652 | 468 |
|
12686 | 469 |
Especially observe the included {\LaTeX} packages \texttt{isabelle} |
470 |
(mandatory), \texttt{isabellesym} (required for mathematical |
|
12743 | 471 |
symbols), and the final \texttt{pdfsetup} (provides sane defaults |
12764 | 472 |
for \texttt{hyperref}, including URL markup). All three are |
12743 | 473 |
distributed with Isabelle. Further packages may be required in |
12764 | 474 |
particular applications, say for unusual mathematical symbols. |
12644 | 475 |
|
12747 | 476 |
\medskip Any additional files for the {\LaTeX} stage go into the |
477 |
\texttt{MySession/document} directory as well. In particular, |
|
12767 | 478 |
adding a file named \texttt{root.bib} causes an automatic run of |
479 |
\texttt{bibtex} to process a bibliographic database; see also |
|
480 |
\texttt{isatool document} \cite{isabelle-sys}. |
|
12644 | 481 |
|
12652 | 482 |
\medskip Any failure of the document preparation phase in an |
12671 | 483 |
Isabelle batch session leaves the generated sources in their target |
12767 | 484 |
location, identified by the accompanying error message. This lets |
485 |
you trace {\LaTeX} problems with the generated files at hand.% |
|
12644 | 486 |
\end{isamarkuptext}% |
487 |
\isamarkuptrue% |
|
488 |
% |
|
12647 | 489 |
\isamarkupsubsection{Structure Markup% |
12644 | 490 |
} |
491 |
\isamarkuptrue% |
|
492 |
% |
|
493 |
\begin{isamarkuptext}% |
|
12652 | 494 |
The large-scale structure of Isabelle documents follows existing |
495 |
{\LaTeX} conventions, with chapters, sections, subsubsections etc. |
|
496 |
The Isar language includes separate \bfindex{markup commands}, which |
|
12682 | 497 |
do not affect the formal meaning of a theory (or proof), but result |
12666 | 498 |
in corresponding {\LaTeX} elements. |
12644 | 499 |
|
12666 | 500 |
There are separate markup commands depending on the textual context: |
501 |
in header position (just before \isakeyword{theory}), within the |
|
502 |
theory body, or within a proof. The header needs to be treated |
|
503 |
specially here, since ordinary theory and proof commands may only |
|
504 |
occur \emph{after} the initial \isakeyword{theory} specification. |
|
12644 | 505 |
|
12666 | 506 |
\medskip |
12644 | 507 |
|
508 |
\begin{tabular}{llll} |
|
509 |
header & theory & proof & default meaning \\\hline |
|
510 |
& \commdx{chapter} & & \verb,\chapter, \\ |
|
511 |
\commdx{header} & \commdx{section} & \commdx{sect} & \verb,\section, \\ |
|
512 |
& \commdx{subsection} & \commdx{subsect} & \verb,\subsection, \\ |
|
513 |
& \commdx{subsubsection} & \commdx{subsubsect} & \verb,\subsubsection, \\ |
|
514 |
\end{tabular} |
|
515 |
||
516 |
\medskip |
|
517 |
||
518 |
From the Isabelle perspective, each markup command takes a single |
|
12747 | 519 |
$text$ argument (delimited by \verb,",~\isa{{\isasymdots}}~\verb,", or |
520 |
\verb,{,\verb,*,~\isa{{\isasymdots}}~\verb,*,\verb,},). After stripping any |
|
12644 | 521 |
surrounding white space, the argument is passed to a {\LaTeX} macro |
12767 | 522 |
\verb,\isamarkupXYZ, for command \isakeyword{XYZ}. These macros are |
523 |
defined in \verb,isabelle.sty, according to the meaning given in the |
|
524 |
rightmost column above. |
|
12644 | 525 |
|
526 |
\medskip The following source fragment illustrates structure markup |
|
12652 | 527 |
of a theory. Note that {\LaTeX} labels may be included inside of |
528 |
section headings as well. |
|
12644 | 529 |
|
530 |
\begin{ttbox} |
|
531 |
header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace} |
|
532 |
||
15136 | 533 |
theory Foo_Bar |
15141 | 534 |
imports Main |
15136 | 535 |
begin |
12644 | 536 |
|
537 |
subsection {\ttlbrace}* Basic definitions *{\ttrbrace} |
|
538 |
||
539 |
consts |
|
540 |
foo :: \dots |
|
541 |
bar :: \dots |
|
12647 | 542 |
|
12644 | 543 |
defs \dots |
12647 | 544 |
|
12644 | 545 |
subsection {\ttlbrace}* Derived rules *{\ttrbrace} |
546 |
||
547 |
lemma fooI: \dots |
|
548 |
lemma fooE: \dots |
|
549 |
||
12647 | 550 |
subsection {\ttlbrace}* Main theorem {\ttback}label{\ttlbrace}sec:main-theorem{\ttrbrace} *{\ttrbrace} |
12644 | 551 |
|
552 |
theorem main: \dots |
|
553 |
||
554 |
end |
|
12767 | 555 |
\end{ttbox}\vspace{-\medskipamount} |
12644 | 556 |
|
12767 | 557 |
You may occasionally want to change the meaning of markup commands, |
558 |
say via \verb,\renewcommand, in \texttt{root.tex}. For example, |
|
559 |
\verb,\isamarkupheader, is a good candidate for some tuning. We |
|
560 |
could move it up in the hierarchy to become \verb,\chapter,. |
|
12644 | 561 |
|
562 |
\begin{verbatim} |
|
563 |
\renewcommand{\isamarkupheader}[1]{\chapter{#1}} |
|
564 |
\end{verbatim} |
|
565 |
||
12767 | 566 |
\noindent Now we must change the document class given in |
567 |
\texttt{root.tex} to something that supports chapters. A suitable |
|
568 |
command is \verb,\documentclass{report},. |
|
12644 | 569 |
|
12647 | 570 |
\medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to |
571 |
hold the name of the current theory context. This is particularly |
|
12652 | 572 |
useful for document headings: |
12644 | 573 |
|
574 |
\begin{verbatim} |
|
12652 | 575 |
\renewcommand{\isamarkupheader}[1] |
12644 | 576 |
{\chapter{#1}\markright{THEORY~\isabellecontext}} |
577 |
\end{verbatim} |
|
578 |
||
579 |
\noindent Make sure to include something like |
|
12647 | 580 |
\verb,\pagestyle{headings}, in \texttt{root.tex}; the document |
12764 | 581 |
should have more than two pages to show the effect.% |
12644 | 582 |
\end{isamarkuptext}% |
583 |
\isamarkuptrue% |
|
584 |
% |
|
12745 | 585 |
\isamarkupsubsection{Formal Comments and Antiquotations \label{sec:doc-prep-text}% |
12644 | 586 |
} |
587 |
\isamarkuptrue% |
|
588 |
% |
|
589 |
\begin{isamarkuptext}% |
|
12745 | 590 |
Isabelle \bfindex{source comments}, which are of the form |
12747 | 591 |
\verb,(,\verb,*,~\isa{{\isasymdots}}~\verb,*,\verb,),, essentially act like |
592 |
white space and do not really contribute to the content. They |
|
593 |
mainly serve technical purposes to mark certain oddities in the raw |
|
594 |
input text. In contrast, \bfindex{formal comments} are portions of |
|
595 |
text that are associated with formal Isabelle/Isar commands |
|
12682 | 596 |
(\bfindex{marginal comments}), or as standalone paragraphs within a |
12666 | 597 |
theory or proof context (\bfindex{text blocks}). |
12658 | 598 |
|
599 |
\medskip Marginal comments are part of each command's concrete |
|
12671 | 600 |
syntax \cite{isabelle-ref}; the common form is ``\verb,--,~$text$'' |
12747 | 601 |
where $text$ is delimited by \verb,",\isa{{\isasymdots}}\verb,", or |
602 |
\verb,{,\verb,*,~\isa{{\isasymdots}}~\verb,*,\verb,}, as before. Multiple |
|
12671 | 603 |
marginal comments may be given at the same time. Here is a simple |
604 |
example:% |
|
12666 | 605 |
\end{isamarkuptext}% |
17175 | 606 |
\isamarkuptrue% |
607 |
\isacommand{lemma}\isamarkupfalse% |
|
608 |
\ {\isachardoublequoteopen}A\ {\isacharminus}{\isacharminus}{\isachargreater}\ A{\isachardoublequoteclose}\isanewline |
|
12666 | 609 |
\ \ % |
610 |
\isamarkupcmt{a triviality of propositional logic% |
|
611 |
} |
|
612 |
\isanewline |
|
613 |
\ \ % |
|
614 |
\isamarkupcmt{(should not really bother)% |
|
615 |
} |
|
616 |
\isanewline |
|
17056 | 617 |
% |
618 |
\isadelimproof |
|
619 |
\ \ % |
|
620 |
\endisadelimproof |
|
621 |
% |
|
622 |
\isatagproof |
|
17175 | 623 |
\isacommand{by}\isamarkupfalse% |
624 |
\ {\isacharparenleft}rule\ impI{\isacharparenright}\ % |
|
16069 | 625 |
\isamarkupcmt{implicit assumption step involved here% |
626 |
} |
|
17056 | 627 |
% |
628 |
\endisatagproof |
|
629 |
{\isafoldproof}% |
|
630 |
% |
|
631 |
\isadelimproof |
|
632 |
% |
|
633 |
\endisadelimproof |
|
12666 | 634 |
% |
635 |
\begin{isamarkuptext}% |
|
636 |
\noindent The above output has been produced as follows: |
|
12658 | 637 |
|
638 |
\begin{verbatim} |
|
639 |
lemma "A --> A" |
|
640 |
-- "a triviality of propositional logic" |
|
641 |
-- "(should not really bother)" |
|
642 |
by (rule impI) -- "implicit assumption step involved here" |
|
643 |
\end{verbatim} |
|
644 |
||
12671 | 645 |
From the {\LaTeX} viewpoint, ``\verb,--,'' acts like a markup |
646 |
command, associated with the macro \verb,\isamarkupcmt, (taking a |
|
647 |
single argument). |
|
12658 | 648 |
|
12666 | 649 |
\medskip Text blocks are introduced by the commands \bfindex{text} |
650 |
and \bfindex{txt}, for theory and proof contexts, respectively. |
|
651 |
Each takes again a single $text$ argument, which is interpreted as a |
|
652 |
free-form paragraph in {\LaTeX} (surrounded by some additional |
|
12671 | 653 |
vertical space). This behavior may be changed by redefining the |
654 |
{\LaTeX} environments of \verb,isamarkuptext, or |
|
655 |
\verb,isamarkuptxt,, respectively (via \verb,\renewenvironment,) The |
|
656 |
text style of the body is determined by \verb,\isastyletext, and |
|
657 |
\verb,\isastyletxt,; the default setup uses a smaller font within |
|
12747 | 658 |
proofs. This may be changed as follows: |
659 |
||
660 |
\begin{verbatim} |
|
661 |
\renewcommand{\isastyletxt}{\isastyletext} |
|
662 |
\end{verbatim} |
|
12658 | 663 |
|
12767 | 664 |
\medskip The $text$ part of Isabelle markup commands essentially |
665 |
inserts \emph{quoted material} into a formal text, mainly for |
|
666 |
instruction of the reader. An \bfindex{antiquotation} is again a |
|
667 |
formal object embedded into such an informal portion. The |
|
668 |
interpretation of antiquotations is limited to some well-formedness |
|
669 |
checks, with the result being pretty printed to the resulting |
|
670 |
document. Quoted text blocks together with antiquotations provide |
|
671 |
an attractive means of referring to formal entities, with good |
|
672 |
confidence in getting the technical details right (especially syntax |
|
673 |
and types). |
|
12658 | 674 |
|
12666 | 675 |
The general syntax of antiquotations is as follows: |
12658 | 676 |
\texttt{{\at}{\ttlbrace}$name$ $arguments${\ttrbrace}}, or |
677 |
\texttt{{\at}{\ttlbrace}$name$ [$options$] $arguments${\ttrbrace}} |
|
12666 | 678 |
for a comma-separated list of options consisting of a $name$ or |
12767 | 679 |
\texttt{$name$=$value$} each. The syntax of $arguments$ depends on |
680 |
the kind of antiquotation, it generally follows the same conventions |
|
681 |
for types, terms, or theorems as in the formal part of a theory. |
|
12649 | 682 |
|
12767 | 683 |
\medskip This sentence demonstrates quotations and antiquotations: |
684 |
\isa{{\isasymlambda}x\ y{\isachardot}\ x} is a well-typed term. |
|
12658 | 685 |
|
12764 | 686 |
\medskip\noindent The output above was produced as follows: |
12658 | 687 |
\begin{ttbox} |
688 |
text {\ttlbrace}* |
|
12764 | 689 |
This sentence demonstrates quotations and antiquotations: |
12658 | 690 |
{\at}{\ttlbrace}term "%x y. x"{\ttrbrace} is a well-typed term. |
691 |
*{\ttrbrace} |
|
12767 | 692 |
\end{ttbox}\vspace{-\medskipamount} |
12658 | 693 |
|
12764 | 694 |
The notational change from the ASCII character~\verb,%, to the |
12767 | 695 |
symbol~\isa{{\isasymlambda}} reveals that Isabelle printed this term, after |
696 |
parsing and type-checking. Document preparation enables symbolic |
|
697 |
output by default. |
|
12658 | 698 |
|
16523 | 699 |
\medskip The next example includes an option to show the type of all |
700 |
variables. The antiquotation |
|
12767 | 701 |
\texttt{{\at}}\verb,{term [show_types] "%x y. x"}, produces the |
702 |
output \isa{{\isasymlambda}{\isacharparenleft}x{\isasymColon}{\isacharprime}a{\isacharparenright}\ y{\isasymColon}{\isacharprime}b{\isachardot}\ x}. Type inference has figured |
|
703 |
out the most general typings in the present theory context. Terms |
|
704 |
may acquire different typings due to constraints imposed by their |
|
705 |
environment; within a proof, for example, variables are given the |
|
706 |
same types as they have in the main goal statement. |
|
12658 | 707 |
|
12764 | 708 |
\medskip Several further kinds of antiquotations and options are |
12666 | 709 |
available \cite{isabelle-sys}. Here are a few commonly used |
12671 | 710 |
combinations: |
12658 | 711 |
|
712 |
\medskip |
|
713 |
||
714 |
\begin{tabular}{ll} |
|
715 |
\texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\ |
|
716 |
\texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\ |
|
717 |
\texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\ |
|
12666 | 718 |
\texttt{\at}\verb,{prop [display],~$\phi$\verb,}, & print large proposition $\phi$ (with linebreaks) \\ |
12658 | 719 |
\texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\ |
720 |
\texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\ |
|
721 |
\texttt{\at}\verb,{thm,~$a$~\verb,[no_vars]}, & print fact $a$, fixing schematic variables \\ |
|
12747 | 722 |
\texttt{\at}\verb,{thm [source],~$a$\verb,}, & check availability of fact $a$, print its name \\ |
12658 | 723 |
\texttt{\at}\verb,{text,~$s$\verb,}, & print uninterpreted text $s$ \\ |
724 |
\end{tabular} |
|
725 |
||
726 |
\medskip |
|
727 |
||
12666 | 728 |
Note that \attrdx{no_vars} given above is \emph{not} an |
729 |
antiquotation option, but an attribute of the theorem argument given |
|
730 |
here. This might be useful with a diagnostic command like |
|
731 |
\isakeyword{thm}, too. |
|
12658 | 732 |
|
12666 | 733 |
\medskip The \texttt{\at}\verb,{text, $s$\verb,}, antiquotation is |
12658 | 734 |
particularly interesting. Embedding uninterpreted text within an |
12666 | 735 |
informal body might appear useless at first sight. Here the key |
736 |
virtue is that the string $s$ is processed as Isabelle output, |
|
737 |
interpreting Isabelle symbols appropriately. |
|
12658 | 738 |
|
12666 | 739 |
For example, \texttt{\at}\verb,{text "\<forall>\<exists>"}, produces \isa{{\isasymforall}{\isasymexists}}, according to the standard interpretation of these symbol |
740 |
(cf.\ \S\ref{sec:doc-prep-symbols}). Thus we achieve consistent |
|
12658 | 741 |
mathematical notation in both the formal and informal parts of the |
12767 | 742 |
document very easily, independently of the term language of |
743 |
Isabelle. Manual {\LaTeX} code would leave more control over the |
|
744 |
typesetting, but is also slightly more tedious.% |
|
12644 | 745 |
\end{isamarkuptext}% |
746 |
\isamarkuptrue% |
|
747 |
% |
|
12674 | 748 |
\isamarkupsubsection{Interpretation of Symbols \label{sec:doc-prep-symbols}% |
12644 | 749 |
} |
750 |
\isamarkuptrue% |
|
751 |
% |
|
752 |
\begin{isamarkuptext}% |
|
12666 | 753 |
As has been pointed out before (\S\ref{sec:syntax-symbols}), |
12671 | 754 |
Isabelle symbols are the smallest syntactic entities --- a |
12682 | 755 |
straightforward generalization of ASCII characters. While Isabelle |
12666 | 756 |
does not impose any interpretation of the infinite collection of |
12764 | 757 |
named symbols, {\LaTeX} documents use canonical glyphs for certain |
12671 | 758 |
standard symbols \cite[appendix~A]{isabelle-sys}. |
12658 | 759 |
|
12767 | 760 |
The {\LaTeX} code produced from Isabelle text follows a simple |
761 |
scheme. You can tune the final appearance by redefining certain |
|
762 |
macros, say in \texttt{root.tex} of the document. |
|
12671 | 763 |
|
764 |
\begin{enumerate} |
|
12658 | 765 |
|
12671 | 766 |
\item 7-bit ASCII characters: letters \texttt{A\dots Z} and |
12747 | 767 |
\texttt{a\dots z} are output directly, digits are passed as an |
12671 | 768 |
argument to the \verb,\isadigit, macro, other characters are |
769 |
replaced by specifically named macros of the form |
|
12666 | 770 |
\verb,\isacharXYZ,. |
12658 | 771 |
|
12767 | 772 |
\item Named symbols: \verb,\,\verb,<XYZ>, is turned into |
773 |
\verb,{\isasymXYZ},; note the additional braces. |
|
12658 | 774 |
|
12767 | 775 |
\item Named control symbols: \verb,\,\verb,<^XYZ>, is turned into |
776 |
\verb,\isactrlXYZ,; subsequent symbols may act as arguments if the |
|
777 |
control macro is defined accordingly. |
|
12671 | 778 |
|
12666 | 779 |
\end{enumerate} |
780 |
||
12764 | 781 |
You may occasionally wish to give new {\LaTeX} interpretations of |
782 |
named symbols. This merely requires an appropriate definition of |
|
12767 | 783 |
\verb,\isasymXYZ,, for \verb,\,\verb,<XYZ>, (see |
12747 | 784 |
\texttt{isabelle.sty} for working examples). Control symbols are |
785 |
slightly more difficult to get right, though. |
|
12666 | 786 |
|
787 |
\medskip The \verb,\isabellestyle, macro provides a high-level |
|
788 |
interface to tune the general appearance of individual symbols. For |
|
12671 | 789 |
example, \verb,\isabellestyle{it}, uses the italics text style to |
790 |
mimic the general appearance of the {\LaTeX} math mode; double |
|
12743 | 791 |
quotes are not printed at all. The resulting quality of typesetting |
792 |
is quite good, so this should be the default style for work that |
|
793 |
gets distributed to a broader audience.% |
|
12644 | 794 |
\end{isamarkuptext}% |
795 |
\isamarkuptrue% |
|
796 |
% |
|
12652 | 797 |
\isamarkupsubsection{Suppressing Output \label{sec:doc-prep-suppress}% |
12644 | 798 |
} |
799 |
\isamarkuptrue% |
|
800 |
% |
|
801 |
\begin{isamarkuptext}% |
|
12749 | 802 |
By default, Isabelle's document system generates a {\LaTeX} file for |
803 |
each theory that gets loaded while running the session. The |
|
804 |
generated \texttt{session.tex} will include all of these in order of |
|
805 |
appearance, which in turn gets included by the standard |
|
12743 | 806 |
\texttt{root.tex}. Certainly one may change the order or suppress |
12747 | 807 |
unwanted theories by ignoring \texttt{session.tex} and load |
808 |
individual files directly in \texttt{root.tex}. On the other hand, |
|
809 |
such an arrangement requires additional maintenance whenever the |
|
810 |
collection of theories changes. |
|
12647 | 811 |
|
812 |
Alternatively, one may tune the theory loading process in |
|
12652 | 813 |
\texttt{ROOT.ML} itself: traversal of the theory dependency graph |
12671 | 814 |
may be fine-tuned by adding \verb,use_thy, invocations, although |
815 |
topological sorting still has to be observed. Moreover, the ML |
|
816 |
operator \verb,no_document, temporarily disables document generation |
|
12767 | 817 |
while executing a theory loader command. Its usage is like this: |
12647 | 818 |
|
819 |
\begin{verbatim} |
|
12666 | 820 |
no_document use_thy "T"; |
12647 | 821 |
\end{verbatim} |
12644 | 822 |
|
17187 | 823 |
\medskip Theory output may be suppressed more selectively, either |
824 |
via \bfindex{tagged command regions} or \bfindex{ignored material}. |
|
12647 | 825 |
|
17187 | 826 |
Tagged command regions works by annotating commands with named tags, |
827 |
which correspond to certain {\LaTeX} markup that tells how to treat |
|
828 |
particular parts of a document when doing the actual type-setting. |
|
829 |
By default, certain Isabelle/Isar commands are implicitly marked up |
|
830 |
using the predefined tags ``\emph{theory}'' (for theory begin and |
|
831 |
end), ``\emph{proof}'' (for proof commands), and ``\emph{ML}'' (for |
|
832 |
commands involving ML code). Users may add their own tags using the |
|
833 |
\verb,%,\emph{tag} notation right after a command name. In the |
|
834 |
subsequent example we hide a particularly irrelevant proof:% |
|
835 |
\end{isamarkuptext}% |
|
836 |
\isamarkuptrue% |
|
837 |
\isacommand{lemma}\isamarkupfalse% |
|
838 |
\ {\isachardoublequoteopen}x\ {\isacharequal}\ x{\isachardoublequoteclose}% |
|
839 |
\isadeliminvisible |
|
840 |
\ % |
|
841 |
\endisadeliminvisible |
|
842 |
% |
|
843 |
\isataginvisible |
|
844 |
\isacommand{by}\isamarkupfalse% |
|
845 |
\ {\isacharparenleft}simp{\isacharparenright}% |
|
846 |
\endisataginvisible |
|
847 |
{\isafoldinvisible}% |
|
848 |
% |
|
849 |
\isadeliminvisible |
|
850 |
% |
|
851 |
\endisadeliminvisible |
|
852 |
% |
|
853 |
\begin{isamarkuptext}% |
|
854 |
The original source has been ``\verb,lemma "x = x" by %invisible (simp),''. |
|
855 |
Tags observe the structure of proofs; adjacent commands with the |
|
856 |
same tag are joined into a single region. The Isabelle document |
|
857 |
preparation system allows the user to specify how to interpret a |
|
858 |
tagged region, in order to keep, drop, or fold the corresponding |
|
859 |
parts of the document. See the \emph{Isabelle System Manual} |
|
860 |
\cite{isabelle-sys} for further details, especially on |
|
861 |
\texttt{isatool usedir} and \texttt{isatool document}. |
|
12647 | 862 |
|
17187 | 863 |
Ignored material is specified by delimiting the original formal |
864 |
source with special source comments |
|
865 |
\verb,(,\verb,*,\verb,<,\verb,*,\verb,), and |
|
866 |
\verb,(,\verb,*,\verb,>,\verb,*,\verb,),. These parts are stripped |
|
867 |
before the type-setting phase, without affecting the formal checking |
|
868 |
of the theory, of course. For example, we may hide parts of a proof |
|
869 |
that seem unfit for general public inspection. The following |
|
870 |
``fully automatic'' proof is actually a fake:% |
|
12649 | 871 |
\end{isamarkuptext}% |
17175 | 872 |
\isamarkuptrue% |
873 |
\isacommand{lemma}\isamarkupfalse% |
|
874 |
\ {\isachardoublequoteopen}x\ {\isasymnoteq}\ {\isacharparenleft}{\isadigit{0}}{\isacharcolon}{\isacharcolon}int{\isacharparenright}\ {\isasymLongrightarrow}\ {\isadigit{0}}\ {\isacharless}\ x\ {\isacharasterisk}\ x{\isachardoublequoteclose}\isanewline |
|
17056 | 875 |
% |
876 |
\isadelimproof |
|
877 |
\ \ % |
|
878 |
\endisadelimproof |
|
879 |
% |
|
880 |
\isatagproof |
|
17175 | 881 |
\isacommand{by}\isamarkupfalse% |
882 |
\ {\isacharparenleft}auto{\isacharparenright}% |
|
17056 | 883 |
\endisatagproof |
884 |
{\isafoldproof}% |
|
885 |
% |
|
886 |
\isadelimproof |
|
887 |
% |
|
888 |
\endisadelimproof |
|
12649 | 889 |
% |
890 |
\begin{isamarkuptext}% |
|
17187 | 891 |
\noindent The real source of the proof has been as follows: |
12649 | 892 |
|
893 |
\begin{verbatim} |
|
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
13791
diff
changeset
|
894 |
by (auto(*<*)simp add: zero_less_mult_iff(*>*)) |
12658 | 895 |
\end{verbatim} |
896 |
%(* |
|
12649 | 897 |
|
12767 | 898 |
\medskip Suppressing portions of printed text demands care. You |
899 |
should not misrepresent the underlying theory development. It is |
|
900 |
easy to invalidate the visible text by hiding references to |
|
17196 | 901 |
questionable axioms, for example.% |
12635 | 902 |
\end{isamarkuptext}% |
17175 | 903 |
\isamarkuptrue% |
17056 | 904 |
% |
905 |
\isadelimtheory |
|
906 |
% |
|
907 |
\endisadelimtheory |
|
908 |
% |
|
909 |
\isatagtheory |
|
910 |
% |
|
911 |
\endisatagtheory |
|
912 |
{\isafoldtheory}% |
|
913 |
% |
|
914 |
\isadelimtheory |
|
915 |
% |
|
916 |
\endisadelimtheory |
|
11648 | 917 |
\end{isabellebody}% |
918 |
%%% Local Variables: |
|
919 |
%%% mode: latex |
|
920 |
%%% TeX-master: "root" |
|
921 |
%%% End: |