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