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