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