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