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
|
12665
|
316 |
is very useful to produce formally derived texts. Unstructured
|
|
317 |
proof scripts given here may be just ignored by readers, or
|
|
318 |
intentionally suppressed from the text by the writer (see also
|
|
319 |
\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
|
|
336 |
of theory source files that contribute to a single output document
|
|
337 |
eventually. Each session is derived from a single parent one,
|
|
338 |
usually an object-logic image like \texttt{HOL}. This results in an
|
|
339 |
overall tree structure, which is reflected by the output location in
|
|
340 |
the 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 |
|
12665
|
367 |
\item \texttt{IsaMakefile} outside of the directory
|
12645
|
368 |
\texttt{MySession} holds appropriate dependencies and invocations of
|
12653
|
369 |
Isabelle tools to control the batch job. In fact, several sessions
|
|
370 |
may be controlled by the same \texttt{IsaMakefile}. See also
|
|
371 |
\cite{isabelle-sys} for further details, especially on
|
|
372 |
\texttt{isatool usedir} and \texttt{isatool make}.
|
12645
|
373 |
|
|
374 |
\end{itemize}
|
|
375 |
|
|
376 |
With everything put in its proper place, \texttt{isatool make}
|
|
377 |
should be sufficient to process the Isabelle session completely,
|
12653
|
378 |
with the generated document appearing in its proper place.
|
12645
|
379 |
|
12665
|
380 |
\medskip In reality, users may want to have \texttt{isatool mkdir}
|
12653
|
381 |
generate an initial working setup without further ado. For example,
|
12670
|
382 |
a new session \texttt{MySession} derived from \texttt{HOL} may be
|
12653
|
383 |
produced as follows:
|
12645
|
384 |
|
|
385 |
\begin{verbatim}
|
|
386 |
isatool mkdir HOL MySession
|
|
387 |
isatool make
|
|
388 |
\end{verbatim}
|
|
389 |
|
12653
|
390 |
This processes the session with sensible default options, including
|
|
391 |
verbose mode to tell the user where the ultimate results will
|
12670
|
392 |
appear. The above dry run should already be able to produce a
|
|
393 |
single page of output (with a dummy title, empty table of contents
|
|
394 |
etc.). Any failure at that stage is likely to indicate technical
|
|
395 |
problems with the user's {\LaTeX} installation.\footnote{Especially
|
|
396 |
make sure that \texttt{pdflatex} is present; if all fails one may
|
|
397 |
fall back on DVI output by changing \texttt{usedir} options in
|
|
398 |
\texttt{IsaMakefile} \cite{isabelle-sys}.}
|
12645
|
399 |
|
12653
|
400 |
\medskip One may now start to populate the directory
|
12645
|
401 |
\texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
|
|
402 |
accordingly. \texttt{MySession/document/root.tex} should be also
|
12653
|
403 |
adapted at some point; the default version is mostly
|
12670
|
404 |
self-explanatory. Note that \verb,\isabellestyle, enables
|
12659
|
405 |
fine-tuning of the general appearance of characters and mathematical
|
|
406 |
symbols (see also \S\ref{sec:doc-prep-symbols}).
|
12653
|
407 |
|
12670
|
408 |
Especially observe inclusion of the {\LaTeX} packages
|
12653
|
409 |
\texttt{isabelle} (mandatory), and \texttt{isabellesym} (required
|
|
410 |
for mathematical symbols), and the final \texttt{pdfsetup} (provides
|
|
411 |
handsome defaults for \texttt{hyperref}, including URL markup).
|
12670
|
412 |
Further packages may be required in particular applications, e.g.\
|
|
413 |
for unusual Isabelle symbols.
|
12645
|
414 |
|
12672
|
415 |
\medskip Additional files for the {\LaTeX} stage may be included in
|
|
416 |
the directory \texttt{MySession/document}, too, such as {\TeX}
|
|
417 |
sources or graphics). In particular, adding \texttt{root.bib} here
|
12670
|
418 |
(with that specific name) causes an automatic run of \texttt{bibtex}
|
|
419 |
to process a bibliographic database; see also \texttt{isatool
|
|
420 |
document} covered in \cite{isabelle-sys}.
|
12645
|
421 |
|
12653
|
422 |
\medskip Any failure of the document preparation phase in an
|
12670
|
423 |
Isabelle batch session leaves the generated sources in their target
|
|
424 |
location (as pointed out by the accompanied error message). This
|
|
425 |
enables users to trace {\LaTeX} at the file positions of the
|
|
426 |
generated material.
|
12645
|
427 |
*}
|
|
428 |
|
|
429 |
|
12648
|
430 |
subsection {* Structure Markup *}
|
12645
|
431 |
|
12653
|
432 |
text {*
|
|
433 |
The large-scale structure of Isabelle documents follows existing
|
|
434 |
{\LaTeX} conventions, with chapters, sections, subsubsections etc.
|
|
435 |
The Isar language includes separate \bfindex{markup commands}, which
|
|
436 |
do not effect the formal content of a theory (or proof), but result
|
12665
|
437 |
in corresponding {\LaTeX} elements.
|
12645
|
438 |
|
12665
|
439 |
There are separate markup commands depending on the textual context:
|
|
440 |
in header position (just before \isakeyword{theory}), within the
|
|
441 |
theory body, or within a proof. The header needs to be treated
|
|
442 |
specially here, since ordinary theory and proof commands may only
|
|
443 |
occur \emph{after} the initial \isakeyword{theory} specification.
|
12645
|
444 |
|
12665
|
445 |
\medskip
|
12645
|
446 |
|
|
447 |
\begin{tabular}{llll}
|
|
448 |
header & theory & proof & default meaning \\\hline
|
|
449 |
& \commdx{chapter} & & \verb,\chapter, \\
|
|
450 |
\commdx{header} & \commdx{section} & \commdx{sect} & \verb,\section, \\
|
|
451 |
& \commdx{subsection} & \commdx{subsect} & \verb,\subsection, \\
|
|
452 |
& \commdx{subsubsection} & \commdx{subsubsect} & \verb,\subsubsection, \\
|
|
453 |
\end{tabular}
|
|
454 |
|
|
455 |
\medskip
|
|
456 |
|
|
457 |
From the Isabelle perspective, each markup command takes a single
|
12659
|
458 |
$text$ argument (delimited by \verb,",\dots\verb,", or
|
12653
|
459 |
\verb,{,\verb,*,~\dots~\verb,*,\verb,},). After stripping any
|
12645
|
460 |
surrounding white space, the argument is passed to a {\LaTeX} macro
|
12653
|
461 |
\verb,\isamarkupXYZ, for any command \isakeyword{XYZ}. These macros
|
|
462 |
are defined in \verb,isabelle.sty, according to the meaning given in
|
|
463 |
the rightmost column above.
|
12645
|
464 |
|
|
465 |
\medskip The following source fragment illustrates structure markup
|
12653
|
466 |
of a theory. Note that {\LaTeX} labels may be included inside of
|
|
467 |
section headings as well.
|
12645
|
468 |
|
|
469 |
\begin{ttbox}
|
|
470 |
header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
|
|
471 |
|
|
472 |
theory Foo_Bar = Main:
|
|
473 |
|
|
474 |
subsection {\ttlbrace}* Basic definitions *{\ttrbrace}
|
|
475 |
|
|
476 |
consts
|
|
477 |
foo :: \dots
|
|
478 |
bar :: \dots
|
12648
|
479 |
|
12645
|
480 |
defs \dots
|
12648
|
481 |
|
12645
|
482 |
subsection {\ttlbrace}* Derived rules *{\ttrbrace}
|
|
483 |
|
|
484 |
lemma fooI: \dots
|
|
485 |
lemma fooE: \dots
|
|
486 |
|
12648
|
487 |
subsection {\ttlbrace}* Main theorem {\ttback}label{\ttlbrace}sec:main-theorem{\ttrbrace} *{\ttrbrace}
|
12645
|
488 |
|
|
489 |
theorem main: \dots
|
|
490 |
|
|
491 |
end
|
|
492 |
\end{ttbox}
|
|
493 |
|
12653
|
494 |
Users may occasionally want to change the meaning of markup
|
12665
|
495 |
commands, say via \verb,\renewcommand, in \texttt{root.tex};
|
12670
|
496 |
\verb,\isamarkupheader, is a good candidate for some tuning, e.g.\
|
12653
|
497 |
moving it up in the hierarchy to become \verb,\chapter,.
|
12645
|
498 |
|
|
499 |
\begin{verbatim}
|
|
500 |
\renewcommand{\isamarkupheader}[1]{\chapter{#1}}
|
|
501 |
\end{verbatim}
|
|
502 |
|
12653
|
503 |
\noindent Certainly, this requires to change the default
|
12645
|
504 |
\verb,\documentclass{article}, in \texttt{root.tex} to something
|
|
505 |
that supports the notion of chapters in the first place, e.g.\
|
12648
|
506 |
\verb,\documentclass{report},.
|
12645
|
507 |
|
12648
|
508 |
\medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to
|
|
509 |
hold the name of the current theory context. This is particularly
|
12653
|
510 |
useful for document headings:
|
12645
|
511 |
|
|
512 |
\begin{verbatim}
|
12653
|
513 |
\renewcommand{\isamarkupheader}[1]
|
12645
|
514 |
{\chapter{#1}\markright{THEORY~\isabellecontext}}
|
|
515 |
\end{verbatim}
|
|
516 |
|
|
517 |
\noindent Make sure to include something like
|
12648
|
518 |
\verb,\pagestyle{headings}, in \texttt{root.tex}; the document
|
|
519 |
should have more than 2 pages to show the effect.
|
12645
|
520 |
*}
|
|
521 |
|
|
522 |
|
12648
|
523 |
subsection {* Formal Comments and Antiquotations *}
|
12645
|
524 |
|
|
525 |
text {*
|
12665
|
526 |
Isabelle source comments, which are of the form
|
|
527 |
\verb,(,\verb,*,~\dots~\verb,*,\verb,),, essentially act like white
|
|
528 |
space and do not really contribute to the content. They mainly
|
|
529 |
serve technical purposes to mark certain oddities in the raw input
|
|
530 |
text. In contrast, \bfindex{formal comments} are portions of text
|
|
531 |
that are associated with formal Isabelle/Isar commands
|
|
532 |
(\bfindex{marginal comments}), or as stanalone paragraphs within a
|
|
533 |
theory or proof context (\bfindex{text blocks}).
|
12659
|
534 |
|
|
535 |
\medskip Marginal comments are part of each command's concrete
|
12670
|
536 |
syntax \cite{isabelle-ref}; the common form is ``\verb,--,~$text$''
|
12665
|
537 |
where $text$ is delimited by \verb,",\dots\verb,", or
|
12670
|
538 |
\verb,{,\verb,*,~\dots~\verb,*,\verb,}, as before. Multiple
|
|
539 |
marginal comments may be given at the same time. Here is a simple
|
|
540 |
example:
|
12665
|
541 |
*}
|
|
542 |
|
|
543 |
lemma "A --> A"
|
|
544 |
-- "a triviality of propositional logic"
|
|
545 |
-- "(should not really bother)"
|
|
546 |
by (rule impI) -- "implicit assumption step involved here"
|
|
547 |
|
|
548 |
text {*
|
|
549 |
\noindent The above output has been produced as follows:
|
12659
|
550 |
|
|
551 |
\begin{verbatim}
|
|
552 |
lemma "A --> A"
|
|
553 |
-- "a triviality of propositional logic"
|
|
554 |
-- "(should not really bother)"
|
|
555 |
by (rule impI) -- "implicit assumption step involved here"
|
|
556 |
\end{verbatim}
|
|
557 |
|
12670
|
558 |
From the {\LaTeX} viewpoint, ``\verb,--,'' acts like a markup
|
|
559 |
command, associated with the macro \verb,\isamarkupcmt, (taking a
|
|
560 |
single argument).
|
12659
|
561 |
|
12665
|
562 |
\medskip Text blocks are introduced by the commands \bfindex{text}
|
|
563 |
and \bfindex{txt}, for theory and proof contexts, respectively.
|
|
564 |
Each takes again a single $text$ argument, which is interpreted as a
|
|
565 |
free-form paragraph in {\LaTeX} (surrounded by some additional
|
12670
|
566 |
vertical space). This behavior may be changed by redefining the
|
|
567 |
{\LaTeX} environments of \verb,isamarkuptext, or
|
|
568 |
\verb,isamarkuptxt,, respectively (via \verb,\renewenvironment,) The
|
|
569 |
text style of the body is determined by \verb,\isastyletext, and
|
|
570 |
\verb,\isastyletxt,; the default setup uses a smaller font within
|
|
571 |
proofs.
|
12659
|
572 |
|
|
573 |
\medskip The $text$ part of each of the various markup commands
|
12670
|
574 |
considered so far essentially inserts \emph{quoted material} into a
|
|
575 |
formal text, mainly for instruction of the reader. An
|
|
576 |
\bfindex{antiquotation} is again a formal object embedded into such
|
|
577 |
an informal portion. The interpretation of antiquotations is
|
|
578 |
limited to some well-formedness checks, with the result being pretty
|
|
579 |
printed to the resulting document. So quoted text blocks together
|
|
580 |
with antiquotations provide very handsome means to reference formal
|
|
581 |
entities with good confidence in getting the technical details right
|
|
582 |
(especially syntax and types).
|
12659
|
583 |
|
12665
|
584 |
The general syntax of antiquotations is as follows:
|
12659
|
585 |
\texttt{{\at}{\ttlbrace}$name$ $arguments${\ttrbrace}}, or
|
|
586 |
\texttt{{\at}{\ttlbrace}$name$ [$options$] $arguments${\ttrbrace}}
|
12665
|
587 |
for a comma-separated list of options consisting of a $name$ or
|
12670
|
588 |
\texttt{$name$=$value$}. The syntax of $arguments$ depends on the
|
|
589 |
kind of antiquotation, it generally follows the same conventions for
|
|
590 |
types, terms, or theorems as in the formal part of a theory.
|
12645
|
591 |
|
12665
|
592 |
\medskip Here is an example of the quotation-antiquotation
|
12659
|
593 |
technique: @{term "%x y. x"} is a well-typed term.
|
|
594 |
|
12665
|
595 |
\medskip\noindent The above output has been produced as follows:
|
12659
|
596 |
\begin{ttbox}
|
|
597 |
text {\ttlbrace}*
|
12665
|
598 |
Here is an example of the quotation-antiquotation technique:
|
12659
|
599 |
{\at}{\ttlbrace}term "%x y. x"{\ttrbrace} is a well-typed term.
|
|
600 |
*{\ttrbrace}
|
|
601 |
\end{ttbox}
|
|
602 |
|
|
603 |
From the notational change of the ASCII character \verb,%, to the
|
|
604 |
symbol @{text \<lambda>} we see that the term really got printed by the
|
12670
|
605 |
system (after parsing and type-checking) --- document preparation
|
12665
|
606 |
enables symbolic output by default.
|
12659
|
607 |
|
12665
|
608 |
\medskip The next example includes an option to modify the
|
|
609 |
\verb,show_types, flag of Isabelle:
|
12659
|
610 |
\texttt{{\at}}\verb,{term [show_types] "%x y. x"}, produces @{term
|
12670
|
611 |
[show_types] "%x y. x"}. Type-inference has figured out the most
|
|
612 |
general typings in the present (theory) context. Note that term
|
|
613 |
fragments may acquire different typings due to constraints imposed
|
|
614 |
by previous text (say within a proof), e.g.\ due to the main goal
|
|
615 |
statement given beforehand.
|
12659
|
616 |
|
|
617 |
\medskip Several further kinds of antiquotations (and options) are
|
12665
|
618 |
available \cite{isabelle-sys}. Here are a few commonly used
|
12670
|
619 |
combinations:
|
12659
|
620 |
|
|
621 |
\medskip
|
12651
|
622 |
|
12659
|
623 |
\begin{tabular}{ll}
|
|
624 |
\texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\
|
|
625 |
\texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\
|
|
626 |
\texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\
|
12665
|
627 |
\texttt{\at}\verb,{prop [display],~$\phi$\verb,}, & print large proposition $\phi$ (with linebreaks) \\
|
12659
|
628 |
\texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\
|
|
629 |
\texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\
|
|
630 |
\texttt{\at}\verb,{thm,~$a$~\verb,[no_vars]}, & print fact $a$, fixing schematic variables \\
|
12665
|
631 |
\texttt{\at}\verb,{thm [source],~$a$\verb,}, & check validity of fact $a$, print its name \\
|
12659
|
632 |
\texttt{\at}\verb,{text,~$s$\verb,}, & print uninterpreted text $s$ \\
|
|
633 |
\end{tabular}
|
|
634 |
|
|
635 |
\medskip
|
|
636 |
|
12665
|
637 |
Note that \attrdx{no_vars} given above is \emph{not} an
|
|
638 |
antiquotation option, but an attribute of the theorem argument given
|
|
639 |
here. This might be useful with a diagnostic command like
|
|
640 |
\isakeyword{thm}, too.
|
12659
|
641 |
|
12665
|
642 |
\medskip The \texttt{\at}\verb,{text, $s$\verb,}, antiquotation is
|
12659
|
643 |
particularly interesting. Embedding uninterpreted text within an
|
12665
|
644 |
informal body might appear useless at first sight. Here the key
|
|
645 |
virtue is that the string $s$ is processed as Isabelle output,
|
|
646 |
interpreting Isabelle symbols appropriately.
|
12659
|
647 |
|
12665
|
648 |
For example, \texttt{\at}\verb,{text "\<forall>\<exists>"}, produces @{text
|
|
649 |
"\<forall>\<exists>"}, according to the standard interpretation of these symbol
|
|
650 |
(cf.\ \S\ref{sec:doc-prep-symbols}). Thus we achieve consistent
|
12659
|
651 |
mathematical notation in both the formal and informal parts of the
|
12665
|
652 |
document very easily. Manual {\LaTeX} code would leave more control
|
|
653 |
over the type-setting, but is also slightly more tedious.
|
12645
|
654 |
*}
|
|
655 |
|
|
656 |
|
12659
|
657 |
subsection {* Interpretation of symbols \label{sec:doc-prep-symbols} *}
|
12645
|
658 |
|
|
659 |
text {*
|
12665
|
660 |
As has been pointed out before (\S\ref{sec:syntax-symbols}),
|
12670
|
661 |
Isabelle symbols are the smallest syntactic entities --- a
|
12665
|
662 |
straight-forward generalization of ASCII characters. While Isabelle
|
|
663 |
does not impose any interpretation of the infinite collection of
|
12670
|
664 |
named symbols, {\LaTeX} documents show canonical glyphs for certain
|
|
665 |
standard symbols \cite[appendix~A]{isabelle-sys}.
|
12659
|
666 |
|
12665
|
667 |
The {\LaTeX} code produced from Isabelle text follows a relatively
|
12670
|
668 |
simple scheme. Users may wish to tune the final appearance by
|
|
669 |
redefining certain macros, say in \texttt{root.tex} of the document.
|
|
670 |
|
|
671 |
\begin{enumerate}
|
12659
|
672 |
|
12670
|
673 |
\item 7-bit ASCII characters: letters \texttt{A\dots Z} and
|
|
674 |
\texttt{a\dots z} are output verbatim, digits are passed as an
|
|
675 |
argument to the \verb,\isadigit, macro, other characters are
|
|
676 |
replaced by specifically named macros of the form
|
12665
|
677 |
\verb,\isacharXYZ,.
|
12659
|
678 |
|
|
679 |
\item Named symbols: \verb,\,\verb,<,$XYZ$\verb,>, become
|
12670
|
680 |
\verb,{\isasym,$XYZ$\verb,}, each (note the additional braces).
|
12659
|
681 |
|
12670
|
682 |
\item Named control symbols: \verb,{\isasym,$XYZ$\verb,}, become
|
|
683 |
\verb,\isactrl,$XYZ$ each; subsequent symbols may act as arguments
|
|
684 |
if the corresponding macro is defined accordingly.
|
|
685 |
|
12659
|
686 |
\end{enumerate}
|
12665
|
687 |
|
12670
|
688 |
Users may occasionally wish to give new {\LaTeX} interpretations of
|
|
689 |
named symbols; this merely requires an appropriate definition of
|
|
690 |
\verb,\,\verb,<,$XYZ$\verb,>, (see \texttt{isabelle.sty} for working
|
|
691 |
examples). Control symbols are slightly more difficult to get
|
|
692 |
right, though.
|
12665
|
693 |
|
|
694 |
\medskip The \verb,\isabellestyle, macro provides a high-level
|
|
695 |
interface to tune the general appearance of individual symbols. For
|
12670
|
696 |
example, \verb,\isabellestyle{it}, uses the italics text style to
|
|
697 |
mimic the general appearance of the {\LaTeX} math mode; double
|
|
698 |
quotes are not printed at all. The resulting quality of
|
|
699 |
type-setting is quite good, so this should usually be the default
|
|
700 |
style for real production work that gets distributed to a broader
|
|
701 |
audience.
|
12645
|
702 |
*}
|
|
703 |
|
|
704 |
|
12653
|
705 |
subsection {* Suppressing Output \label{sec:doc-prep-suppress} *}
|
12645
|
706 |
|
|
707 |
text {*
|
12670
|
708 |
By default, Isabelle's document system generates a {\LaTeX} source
|
|
709 |
file for each theory that happens to get loaded while running the
|
|
710 |
session. The generated \texttt{session.tex} will include all of
|
|
711 |
these in order of appearance, which in turn gets included by the
|
|
712 |
standard \texttt{root.tex}. Certainly one may change the order or
|
|
713 |
suppress unwanted theories by ignoring \texttt{session.tex} and
|
12653
|
714 |
include individual files in \texttt{root.tex} by hand. On the other
|
|
715 |
hand, such an arrangement requires additional maintenance chores
|
|
716 |
whenever the collection of theories changes.
|
12648
|
717 |
|
|
718 |
Alternatively, one may tune the theory loading process in
|
12653
|
719 |
\texttt{ROOT.ML} itself: traversal of the theory dependency graph
|
12670
|
720 |
may be fine-tuned by adding \verb,use_thy, invocations, although
|
|
721 |
topological sorting still has to be observed. Moreover, the ML
|
|
722 |
operator \verb,no_document, temporarily disables document generation
|
|
723 |
while executing a theory loader command; its usage is like this:
|
12648
|
724 |
|
|
725 |
\begin{verbatim}
|
12665
|
726 |
no_document use_thy "T";
|
12648
|
727 |
\end{verbatim}
|
12645
|
728 |
|
12670
|
729 |
\medskip Theory output may be also suppressed in smaller portions.
|
|
730 |
For example, research articles, or slides usually do not include the
|
|
731 |
formal content in full. In order to delimit \bfindex{ignored
|
12653
|
732 |
material} special source comments
|
12648
|
733 |
\verb,(,\verb,*,\verb,<,\verb,*,\verb,), and
|
12653
|
734 |
\verb,(,\verb,*,\verb,>,\verb,*,\verb,), may be included in the
|
|
735 |
text. Only the document preparation system is affected, the formal
|
12670
|
736 |
checking the theory is performed unchanged.
|
12648
|
737 |
|
|
738 |
In the following example we suppress the slightly formalistic
|
12653
|
739 |
\isakeyword{theory} + \isakeyword{end} surroundings a theory.
|
12648
|
740 |
|
|
741 |
\medskip
|
|
742 |
|
|
743 |
\begin{tabular}{l}
|
|
744 |
\verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
|
12665
|
745 |
\texttt{theory T = Main:} \\
|
12648
|
746 |
\verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
|
|
747 |
~~$\vdots$ \\
|
|
748 |
\verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
|
|
749 |
\texttt{end} \\
|
|
750 |
\verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
|
|
751 |
\end{tabular}
|
|
752 |
|
|
753 |
\medskip
|
|
754 |
|
12670
|
755 |
Text may be suppressed in a fine grained manner. We may even drop
|
|
756 |
vital parts of a formal proof, pretending that things have been
|
|
757 |
simpler than in reality. For example, the following ``fully
|
|
758 |
automatic'' proof is actually a fake:
|
12651
|
759 |
*}
|
|
760 |
|
|
761 |
lemma "x \<noteq> (0::int) \<Longrightarrow> 0 < x * x"
|
|
762 |
by (auto(*<*)simp add: int_less_le(*>*))
|
|
763 |
|
|
764 |
text {*
|
|
765 |
\noindent Here the real source of the proof has been as follows:
|
|
766 |
|
|
767 |
\begin{verbatim}
|
|
768 |
by (auto(*<*)simp add: int_less_le(*>*))
|
12659
|
769 |
\end{verbatim}
|
|
770 |
%(*
|
12651
|
771 |
|
12653
|
772 |
\medskip Ignoring portions of printed does demand some care by the
|
12670
|
773 |
writer. First of all, the writer is responsible not to obfuscate
|
|
774 |
the underlying formal development in an unduly manner. It is fairly
|
12653
|
775 |
easy to invalidate the remaining visible text, e.g.\ by referencing
|
|
776 |
questionable formal items (strange definitions, arbitrary axioms
|
|
777 |
etc.) that have been hidden from sight beforehand.
|
12651
|
778 |
|
12670
|
779 |
Authentic reports of formal theories, say as part of a library,
|
|
780 |
usually should refrain from suppressing parts of the text at all.
|
|
781 |
Other users may need the full information for their own derivative
|
|
782 |
work. If a particular formalization appears inadequate for general
|
|
783 |
public coverage, it is often more appropriate to think of a better
|
|
784 |
way in the first place.
|
|
785 |
|
|
786 |
\medskip Some technical subtleties of the
|
12665
|
787 |
\verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
|
12670
|
788 |
elements need to be kept in mind, too --- the system performs little
|
|
789 |
sanity checks here. Arguments of markup commands and formal
|
12651
|
790 |
comments must not be hidden, otherwise presentation fails. Open and
|
|
791 |
close parentheses need to be inserted carefully; it is fairly easy
|
12653
|
792 |
to hide the wrong parts, especially after rearranging the sources.
|
12651
|
793 |
|
12629
|
794 |
*}
|
|
795 |
|
11647
|
796 |
(*<*)
|
|
797 |
end
|
|
798 |
(*>*)
|