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