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