doc-src/TutorialI/Documents/document/Documents.tex
author wenzelm
Sat, 05 Jan 2002 01:27:32 +0100
changeset 12642 40fbd988b59b
parent 12635 e2d44df29c94
child 12644 a107eeffd557
permissions -rw-r--r--
updated;
wenzelm@11648
     1
%
wenzelm@11648
     2
\begin{isabellebody}%
wenzelm@11648
     3
\def\isabellecontext{Documents}%
wenzelm@11866
     4
\isamarkupfalse%
wenzelm@12627
     5
%
wenzelm@12627
     6
\isamarkupsection{Concrete syntax \label{sec:concrete-syntax}%
wenzelm@12627
     7
}
wenzelm@12627
     8
\isamarkuptrue%
wenzelm@12627
     9
%
wenzelm@12627
    10
\begin{isamarkuptext}%
wenzelm@12627
    11
Concerning Isabelle's ``inner'' language of simply-typed \isa{{\isasymlambda}}-calculus, the core concept of Isabelle's elaborate infrastructure
wenzelm@12627
    12
  for concrete syntax is that of general \emph{mixfix
wenzelm@12627
    13
  annotations}\index{mixfix annotations|bold}.  Associated with any
wenzelm@12627
    14
  kind of name and type declaration, mixfixes give rise both to
wenzelm@12627
    15
  grammar productions for the parser and output templates for the
wenzelm@12627
    16
  pretty printer.
wenzelm@12627
    17
wenzelm@12627
    18
  In full generality, the whole affair of parser and pretty printer
wenzelm@12627
    19
  configuration is rather subtle.  Any syntax specifications given by
wenzelm@12627
    20
  end-users need to interact properly with the existing setup of
wenzelm@12627
    21
  Isabelle/Pure and Isabelle/HOL; see \cite{isabelle-ref} for further
wenzelm@12627
    22
  details.  It is particularly important to get the precedence of new
wenzelm@12627
    23
  syntactic constructs right, avoiding ambiguities with existing
wenzelm@12627
    24
  elements.
wenzelm@12627
    25
wenzelm@12627
    26
  \medskip Subsequently we introduce a few simple declaration forms
wenzelm@12627
    27
  that already cover the most common situations fairly well.%
wenzelm@12627
    28
\end{isamarkuptext}%
wenzelm@12627
    29
\isamarkuptrue%
wenzelm@12627
    30
%
wenzelm@12627
    31
\isamarkupsubsection{Infixes%
wenzelm@12627
    32
}
wenzelm@12627
    33
\isamarkuptrue%
wenzelm@12627
    34
%
wenzelm@12627
    35
\begin{isamarkuptext}%
wenzelm@12627
    36
Syntax annotations may be included wherever constants are declared
wenzelm@12627
    37
  directly or indirectly, including \isacommand{consts},
wenzelm@12627
    38
  \isacommand{constdefs}, or \isacommand{datatype} (for the
wenzelm@12627
    39
  constructor operations).  Type-constructors may be annotated as
wenzelm@12627
    40
  well, although this is less frequently encountered in practice
wenzelm@12627
    41
  (\isa{{\isacharasterisk}} and \isa{{\isacharplus}} types may come to mind).
wenzelm@12627
    42
wenzelm@12627
    43
  Infix declarations\index{infix annotations|bold} provide a useful
wenzelm@12627
    44
  special case of mixfixes, where users need not care about the full
wenzelm@12627
    45
  details of priorities, nesting, spacing, etc.  The subsequent
wenzelm@12627
    46
  example of the exclusive-or operation on boolean values illustrates
wenzelm@12627
    47
  typical infix declarations.%
wenzelm@12627
    48
\end{isamarkuptext}%
wenzelm@12627
    49
\isamarkuptrue%
wenzelm@12627
    50
\isacommand{constdefs}\isanewline
wenzelm@12627
    51
\ \ 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
    52
\ \ {\isachardoublequote}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
wenzelm@12627
    53
%
wenzelm@12627
    54
\begin{isamarkuptext}%
wenzelm@12627
    55
Any curried function with at least two arguments may be associated
wenzelm@12627
    56
  with infix syntax: \isa{xor\ A\ B} and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} refer to
wenzelm@12627
    57
  the same expression internally.  In partial applications with less
wenzelm@12627
    58
  than two operands there is a special notation with \isa{op} prefix:
wenzelm@12627
    59
  \isa{xor} without arguments is represented as \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}};
wenzelm@12627
    60
  combined with plain prefix application this turns \isa{xor\ A}
wenzelm@12627
    61
  into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}.
wenzelm@12627
    62
wenzelm@12627
    63
  \medskip The string \isa{{\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}} in the above declaration
wenzelm@12627
    64
  refers to the bit of concrete syntax to represent the operator,
wenzelm@12627
    65
  while the number \isa{{\isadigit{6}}{\isadigit{0}}} determines the precedence of the whole
wenzelm@12627
    66
  construct.
wenzelm@12627
    67
wenzelm@12627
    68
  As it happens, Isabelle/HOL already spends many popular combinations
wenzelm@12627
    69
  of ASCII symbols for its own use, including both \isa{{\isacharplus}} and
wenzelm@12627
    70
  \isa{{\isacharplus}{\isacharplus}}.  Slightly more awkward combinations like the present
wenzelm@12627
    71
  \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} tend to be available for user extensions.  The current
wenzelm@12627
    72
  arrangement of inner syntax may be inspected via
wenzelm@12627
    73
  \commdx{print\protect\_syntax}, albeit its output is enormous.
wenzelm@12627
    74
wenzelm@12627
    75
  Operator precedence also needs some special considerations.  The
wenzelm@12627
    76
  admissible range is 0--1000.  Very low or high priorities are
wenzelm@12627
    77
  basically reserved for the meta-logic.  Syntax of Isabelle/HOL
wenzelm@12627
    78
  mainly uses the range of 10--100: the equality infix \isa{{\isacharequal}} is
wenzelm@12627
    79
  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
    80
  HOL forms, or use the mostly unused range 100--900.
wenzelm@12627
    81
wenzelm@12627
    82
  \medskip The keyword \isakeyword{infixl} specifies an operator that
wenzelm@12627
    83
  is nested to the \emph{left}: in iterated applications the more
wenzelm@12627
    84
  complex expression appears on the left-hand side: \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,
wenzelm@12635
    85
  \isakeyword{infixr} refers to nesting to the \emph{right}, reading
wenzelm@12635
    86
  \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}.  In contrast,
wenzelm@12635
    87
  a \emph{non-oriented} declaration via \isakeyword{infix} would
wenzelm@12635
    88
  always demand explicit parentheses.
wenzelm@12627
    89
  
wenzelm@12627
    90
  Many binary operations observe the associative law, so the exact
wenzelm@12627
    91
  grouping does not matter.  Nevertheless, formal statements need be
wenzelm@12627
    92
  given in a particular format, associativity needs to be treated
wenzelm@12627
    93
  explicitly within the logic.  Exclusive-or is happens to be
wenzelm@12627
    94
  associative, as shown below.%
wenzelm@12627
    95
\end{isamarkuptext}%
wenzelm@12627
    96
\isamarkuptrue%
wenzelm@12627
    97
\isacommand{lemma}\ xor{\isacharunderscore}assoc{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C\ {\isacharequal}\ A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}{\isachardoublequote}\isanewline
wenzelm@12627
    98
\ \ \isamarkupfalse%
wenzelm@12627
    99
\isacommand{by}\ {\isacharparenleft}auto\ simp\ add{\isacharcolon}\ xor{\isacharunderscore}def{\isacharparenright}\isamarkupfalse%
wenzelm@12627
   100
%
wenzelm@12627
   101
\begin{isamarkuptext}%
wenzelm@12627
   102
Such rules may be used in simplification to regroup nested
wenzelm@12627
   103
  expressions as required.  Note that the system would actually print
wenzelm@12627
   104
  the above statement as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C\ {\isacharequal}\ A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}
wenzelm@12627
   105
  (due to nesting to the left).  We have preferred to give the fully
wenzelm@12635
   106
  parenthesized form in the text for clarity.  Only in rare situations
wenzelm@12635
   107
  one may consider to force parentheses by use of non-oriented infix
wenzelm@12635
   108
  syntax; equality would probably be a typical candidate.%
wenzelm@12627
   109
\end{isamarkuptext}%
wenzelm@12627
   110
\isamarkuptrue%
wenzelm@12635
   111
%
wenzelm@12635
   112
\isamarkupsubsection{Mathematical symbols \label{sec:thy-present-symbols}%
wenzelm@12635
   113
}
wenzelm@12627
   114
\isamarkuptrue%
wenzelm@12635
   115
%
wenzelm@12635
   116
\begin{isamarkuptext}%
wenzelm@12635
   117
Concrete syntax based on plain ASCII characters has its inherent
wenzelm@12635
   118
  limitations.  Rich mathematical notation demands a larger repertoire
wenzelm@12635
   119
  of symbols.  Several standards of extended character sets have been
wenzelm@12635
   120
  proposed over decades, but none has become universally available so
wenzelm@12635
   121
  far, not even Unicode\index{Unicode}.
wenzelm@12635
   122
wenzelm@12635
   123
  Isabelle supports a generic notion of
wenzelm@12635
   124
  \emph{symbols}\index{symbols|bold} as the smallest entities of
wenzelm@12635
   125
  source text, without referring to internal encodings.  Such
wenzelm@12635
   126
  ``generalized characters'' may be of one of the following three
wenzelm@12635
   127
  kinds:
wenzelm@12635
   128
wenzelm@12635
   129
  \begin{enumerate}
wenzelm@12635
   130
wenzelm@12635
   131
  \item Traditional 7-bit ASCII characters.
wenzelm@12635
   132
wenzelm@12635
   133
  \item Named symbols: \verb,\,\verb,<,$ident$\verb,>, (or
wenzelm@12635
   134
  \verb,\\,\verb,<,$ident$\verb,>,).
wenzelm@12635
   135
wenzelm@12635
   136
  \item Named control symbols: \verb,\,\verb,<^,$ident$\verb,>, (or
wenzelm@12635
   137
  \verb,\\,\verb,<^,$ident$\verb,>,).
wenzelm@12635
   138
wenzelm@12635
   139
  \end{enumerate}
wenzelm@12635
   140
wenzelm@12635
   141
  Here $ident$ may be any identifier according to the usual Isabelle
wenzelm@12635
   142
  conventions.  This results in an infinite store of symbols, whose
wenzelm@12635
   143
  interpretation is left to further front-end tools.  For example, the
wenzelm@12635
   144
  \verb,\,\verb,<forall>, symbol of Isabelle is really displayed as
wenzelm@12635
   145
  $\forall$ --- both by the user-interface of Proof~General + X-Symbol
wenzelm@12635
   146
  and the Isabelle document processor (see \S\ref{FIXME}).
wenzelm@12635
   147
wenzelm@12635
   148
  A list of standard Isabelle symbols is given in
wenzelm@12635
   149
  \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
wenzelm@12635
   150
  interpretation of further symbols by configuring the appropriate
wenzelm@12635
   151
  front-end tool accordingly, e.g.\ defining appropriate {\LaTeX}
wenzelm@12635
   152
  macros for document preparation.  There are also a few predefined
wenzelm@12635
   153
  control symbols, such as \verb,\,\verb,<^sub>, and
wenzelm@12635
   154
  \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
wenzelm@12635
   155
  (printable) symbol, respectively.
wenzelm@12635
   156
wenzelm@12635
   157
  \medskip The following version of our \isa{xor} definition uses a
wenzelm@12635
   158
  standard Isabelle symbol to achieve typographically pleasing output.%
wenzelm@12635
   159
\end{isamarkuptext}%
wenzelm@12627
   160
\isamarkuptrue%
wenzelm@12627
   161
\isamarkupfalse%
wenzelm@12627
   162
\isamarkupfalse%
wenzelm@12635
   163
\isacommand{constdefs}\isanewline
wenzelm@12635
   164
\ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline
wenzelm@12635
   165
\ \ {\isachardoublequote}A\ {\isasymoplus}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
wenzelm@12627
   166
\isamarkupfalse%
wenzelm@12635
   167
%
wenzelm@12635
   168
\begin{isamarkuptext}%
wenzelm@12635
   169
The X-Symbol package within Proof~General provides several input
wenzelm@12635
   170
  methods to enter \isa{{\isasymoplus}} in the text.  If all fails one may just
wenzelm@12635
   171
  type \verb,\,\verb,<oplus>, by hand; the display is adapted
wenzelm@12635
   172
  immediately after continuing further input.
wenzelm@12635
   173
wenzelm@12635
   174
  \medskip A slightly more refined scheme is to provide alternative
wenzelm@12635
   175
  syntax via the \emph{print mode}\index{print mode} concept of
wenzelm@12635
   176
  Isabelle (see also \cite{isabelle-ref}).  By convention, the mode
wenzelm@12635
   177
  ``$xsymbols$'' is enabled whenever X-Symbol is active.  Consider the
wenzelm@12635
   178
  following hybrid declaration of \isa{xor}.%
wenzelm@12635
   179
\end{isamarkuptext}%
wenzelm@12627
   180
\isamarkuptrue%
wenzelm@12627
   181
\isamarkupfalse%
wenzelm@12635
   182
\isamarkupfalse%
wenzelm@12635
   183
\isacommand{constdefs}\isanewline
wenzelm@12635
   184
\ \ 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
   185
\ \ {\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
   186
\isanewline
wenzelm@12635
   187
\isamarkupfalse%
wenzelm@12635
   188
\isacommand{syntax}\ {\isacharparenleft}xsymbols{\isacharparenright}\isanewline
wenzelm@12635
   189
\ \ 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
   190
\isamarkupfalse%
wenzelm@12635
   191
%
wenzelm@12635
   192
\begin{isamarkuptext}%
wenzelm@12635
   193
Here the \commdx{syntax} command acts like \isakeyword{consts}, but
wenzelm@12635
   194
  without declaring a logical constant, and with an optional print
wenzelm@12635
   195
  mode specification.  Note that the type declaration given here
wenzelm@12635
   196
  merely serves for syntactic purposes, and is not checked for
wenzelm@12635
   197
  consistency with the real constant.
wenzelm@12635
   198
wenzelm@12635
   199
  \medskip Now we may write either \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} or \isa{{\isasymoplus}} in
wenzelm@12635
   200
  input, while output uses the nicer syntax of $xsymbols$, provided
wenzelm@12635
   201
  that print mode is presently active.  This scheme is particularly
wenzelm@12635
   202
  useful for interactive development, with the user typing plain ASCII
wenzelm@12635
   203
  text, but gaining improved visual feedback from the system (say in
wenzelm@12635
   204
  current goal output).
wenzelm@12635
   205
wenzelm@12635
   206
  \begin{warn}
wenzelm@12635
   207
  Using alternative syntax declarations easily results in varying
wenzelm@12635
   208
  versions of input sources.  Isabelle provides no systematic way to
wenzelm@12635
   209
  convert alternative expressions back and forth.  Print modes only
wenzelm@12635
   210
  affect situations where formal entities are pretty printed by the
wenzelm@12635
   211
  Isabelle process (e.g.\ output of terms and types), but not the
wenzelm@12635
   212
  original theory text.
wenzelm@12635
   213
  \end{warn}
wenzelm@12635
   214
wenzelm@12635
   215
  \medskip The following variant makes the alternative \isa{{\isasymoplus}}
wenzelm@12635
   216
  notation only available for output.  Thus we may enforce input
wenzelm@12635
   217
  sources to refer to plain ASCII only.%
wenzelm@12635
   218
\end{isamarkuptext}%
wenzelm@12627
   219
\isamarkuptrue%
wenzelm@12635
   220
\isacommand{syntax}\ {\isacharparenleft}xsymbols\ \isakeyword{output}{\isacharparenright}\isanewline
wenzelm@12635
   221
\ \ 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
   222
%
wenzelm@12635
   223
\isamarkupsubsection{Prefixes%
wenzelm@12635
   224
}
wenzelm@12627
   225
\isamarkuptrue%
wenzelm@12635
   226
%
wenzelm@12635
   227
\begin{isamarkuptext}%
wenzelm@12635
   228
Prefix syntax annotations\index{prefix annotation|bold} are just a
wenzelm@12635
   229
  very degenerate of the general mixfix form \cite{isabelle-ref},
wenzelm@12635
   230
  without any template arguments or priorities --- just some piece of
wenzelm@12635
   231
  literal syntax.
wenzelm@12635
   232
wenzelm@12635
   233
  The following example illustrates this idea idea by associating
wenzelm@12635
   234
  common symbols with the constructors of a currency datatype.%
wenzelm@12635
   235
\end{isamarkuptext}%
wenzelm@12627
   236
\isamarkuptrue%
wenzelm@12635
   237
\isacommand{datatype}\ currency\ {\isacharequal}\isanewline
wenzelm@12635
   238
\ \ \ \ Euro\ nat\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymeuro}{\isachardoublequote}{\isacharparenright}\isanewline
wenzelm@12635
   239
\ \ {\isacharbar}\ Pounds\ nat\ \ {\isacharparenleft}{\isachardoublequote}{\isasympounds}{\isachardoublequote}{\isacharparenright}\isanewline
wenzelm@12635
   240
\ \ {\isacharbar}\ Yen\ nat\ \ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymyen}{\isachardoublequote}{\isacharparenright}\isanewline
wenzelm@12635
   241
\ \ {\isacharbar}\ Dollar\ nat\ \ {\isacharparenleft}{\isachardoublequote}{\isachardollar}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
wenzelm@12635
   242
%
wenzelm@12635
   243
\begin{isamarkuptext}%
wenzelm@12635
   244
Here the degenerate mixfix annotations on the rightmost column
wenzelm@12635
   245
  happen to consist of a single Isabelle symbol each:
wenzelm@12635
   246
  \verb,\,\verb,<euro>,, \verb,\,\verb,<pounds>,,
wenzelm@12642
   247
  \verb,\,\verb,<yen>,, and \verb,$,.
wenzelm@12635
   248
wenzelm@12635
   249
  Recall that a constructor like \isa{Euro} actually is a function
wenzelm@12635
   250
  \isa{nat\ {\isasymRightarrow}\ currency}.  An expression like \isa{Euro\ {\isadigit{1}}{\isadigit{0}}} will
wenzelm@12635
   251
  be printed as \isa{{\isasymeuro}\ {\isadigit{1}}{\isadigit{0}}}.  Merely the head of the application is
wenzelm@12635
   252
  subject to our trivial concrete syntax; this form is sufficient to
wenzelm@12635
   253
  achieve fair conformance to EU~Commission standards of currency
wenzelm@12635
   254
  notation.
wenzelm@12635
   255
wenzelm@12635
   256
  \medskip Certainly, the same idea of prefix syntax also works for
wenzelm@12635
   257
  \isakeyword{consts}, \isakeyword{constdefs} etc.  For example, we
wenzelm@12635
   258
  might introduce a (slightly unrealistic) function to calculate an
wenzelm@12635
   259
  abstract currency value, by cases on the datatype constructors and
wenzelm@12635
   260
  fixed exchange rates.%
wenzelm@12635
   261
\end{isamarkuptext}%
wenzelm@12627
   262
\isamarkuptrue%
wenzelm@12635
   263
\isacommand{consts}\isanewline
wenzelm@12635
   264
\ \ currency\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}currency\ {\isasymRightarrow}\ nat{\isachardoublequote}\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymcurrency}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
wenzelm@12635
   265
%
wenzelm@12635
   266
\begin{isamarkuptext}%
wenzelm@12635
   267
\noindent The funny symbol encountered here is that of
wenzelm@12635
   268
  \verb,\<currency>,.%
wenzelm@12635
   269
\end{isamarkuptext}%
wenzelm@12627
   270
\isamarkuptrue%
wenzelm@12635
   271
%
wenzelm@12635
   272
\isamarkupsubsection{Syntax translations \label{sec:def-translations}%
wenzelm@12635
   273
}
wenzelm@12627
   274
\isamarkuptrue%
wenzelm@12635
   275
%
wenzelm@12635
   276
\begin{isamarkuptext}%
wenzelm@12635
   277
FIXME
wenzelm@12635
   278
wenzelm@12635
   279
\index{syntax translations|(}%
wenzelm@12635
   280
\index{translations@\isacommand {translations} (command)|(}
wenzelm@12635
   281
Isabelle offers an additional definitional facility,
wenzelm@12635
   282
\textbf{syntax translations}.
wenzelm@12635
   283
They resemble macros: upon parsing, the defined concept is immediately
wenzelm@12635
   284
replaced by its definition.  This effect is reversed upon printing.  For example,
wenzelm@12635
   285
the symbol \isa{{\isasymnoteq}} is defined via a syntax translation:%
wenzelm@12635
   286
\end{isamarkuptext}%
wenzelm@12627
   287
\isamarkuptrue%
wenzelm@12635
   288
\isacommand{translations}\ {\isachardoublequote}x\ {\isasymnoteq}\ y{\isachardoublequote}\ {\isasymrightleftharpoons}\ {\isachardoublequote}{\isasymnot}{\isacharparenleft}x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
wenzelm@12635
   289
%
wenzelm@12635
   290
\begin{isamarkuptext}%
wenzelm@12635
   291
\index{$IsaEqTrans@\isasymrightleftharpoons}
wenzelm@12635
   292
\noindent
wenzelm@12635
   293
Internally, \isa{{\isasymnoteq}} never appears.
wenzelm@12635
   294
wenzelm@12635
   295
In addition to \isa{{\isasymrightleftharpoons}} there are
wenzelm@12635
   296
\isa{{\isasymrightharpoonup}}\index{$IsaEqTrans1@\isasymrightharpoonup}
wenzelm@12635
   297
and \isa{{\isasymleftharpoondown}}\index{$IsaEqTrans2@\isasymleftharpoondown}
wenzelm@12635
   298
for uni-directional translations, which only affect
wenzelm@12635
   299
parsing or printing.  This tutorial will not cover the details of
wenzelm@12635
   300
translations.  We have mentioned the concept merely because it
wenzelm@12635
   301
crops up occasionally; a number of HOL's built-in constructs are defined
wenzelm@12635
   302
via translations.  Translations are preferable to definitions when the new 
wenzelm@12635
   303
concept is a trivial variation on an existing one.  For example, we
wenzelm@12635
   304
don't need to derive new theorems about \isa{{\isasymnoteq}}, since existing theorems
wenzelm@12635
   305
about \isa{{\isacharequal}} still apply.%
wenzelm@12635
   306
\index{syntax translations|)}%
wenzelm@12635
   307
\index{translations@\isacommand {translations} (command)|)}%
wenzelm@12635
   308
\end{isamarkuptext}%
wenzelm@12627
   309
\isamarkuptrue%
wenzelm@12635
   310
%
wenzelm@12635
   311
\isamarkupsection{Document preparation%
wenzelm@12635
   312
}
wenzelm@12627
   313
\isamarkuptrue%
wenzelm@12635
   314
%
wenzelm@12635
   315
\isamarkupsubsection{Batch-mode sessions%
wenzelm@12635
   316
}
wenzelm@12635
   317
\isamarkuptrue%
wenzelm@12635
   318
%
wenzelm@12635
   319
\isamarkupsubsection{{\LaTeX} macros%
wenzelm@12635
   320
}
wenzelm@12635
   321
\isamarkuptrue%
wenzelm@12635
   322
%
wenzelm@12635
   323
\isamarkupsubsubsection{Structure markup%
wenzelm@12635
   324
}
wenzelm@12635
   325
\isamarkuptrue%
wenzelm@12635
   326
%
wenzelm@12635
   327
\isamarkupsubsubsection{Symbols and characters%
wenzelm@12635
   328
}
wenzelm@12635
   329
\isamarkuptrue%
wenzelm@12635
   330
%
wenzelm@12635
   331
\begin{isamarkuptext}%
wenzelm@12635
   332
FIXME%
wenzelm@12635
   333
\end{isamarkuptext}%
wenzelm@12627
   334
\isamarkuptrue%
wenzelm@11866
   335
\isamarkupfalse%
wenzelm@11648
   336
\end{isabellebody}%
wenzelm@11648
   337
%%% Local Variables:
wenzelm@11648
   338
%%% mode: latex
wenzelm@11648
   339
%%% TeX-master: "root"
wenzelm@11648
   340
%%% End: