doc-src/TutorialI/Documents/document/Documents.tex
author wenzelm
Fri, 04 Jan 2002 19:19:51 +0100
changeset 12627 08eee994bf99
parent 11866 fbd097aec213
child 12635 e2d44df29c94
permissions -rw-r--r--
updated;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11648
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
     1
%
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
     2
\begin{isabellebody}%
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
     3
\def\isabellecontext{Documents}%
11866
fbd097aec213 updated;
wenzelm
parents: 11648
diff changeset
     4
\isamarkupfalse%
12627
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
     5
%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
     6
\isamarkupsection{Concrete syntax \label{sec:concrete-syntax}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
     7
}
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
     8
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
     9
%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    10
\begin{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    11
Concerning Isabelle's ``inner'' language of simply-typed \isa{{\isasymlambda}}-calculus, the core concept of Isabelle's elaborate infrastructure
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    12
  for concrete syntax is that of general \emph{mixfix
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    13
  annotations}\index{mixfix annotations|bold}.  Associated with any
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    14
  kind of name and type declaration, mixfixes give rise both to
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    15
  grammar productions for the parser and output templates for the
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    16
  pretty printer.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    17
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    18
  In full generality, the whole affair of parser and pretty printer
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    19
  configuration is rather subtle.  Any syntax specifications given by
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    20
  end-users need to interact properly with the existing setup of
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    21
  Isabelle/Pure and Isabelle/HOL; see \cite{isabelle-ref} for further
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    22
  details.  It is particularly important to get the precedence of new
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    23
  syntactic constructs right, avoiding ambiguities with existing
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    24
  elements.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    25
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    26
  \medskip Subsequently we introduce a few simple declaration forms
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    27
  that already cover the most common situations fairly well.%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    28
\end{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    29
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    30
%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    31
\isamarkupsubsection{Infixes%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    32
}
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    33
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    34
%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    35
\begin{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    36
Syntax annotations may be included wherever constants are declared
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    37
  directly or indirectly, including \isacommand{consts},
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    38
  \isacommand{constdefs}, or \isacommand{datatype} (for the
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    39
  constructor operations).  Type-constructors may be annotated as
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    40
  well, although this is less frequently encountered in practice
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    41
  (\isa{{\isacharasterisk}} and \isa{{\isacharplus}} types may come to mind).
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    42
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    43
  Infix declarations\index{infix annotations|bold} provide a useful
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    44
  special case of mixfixes, where users need not care about the full
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    45
  details of priorities, nesting, spacing, etc.  The subsequent
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    46
  example of the exclusive-or operation on boolean values illustrates
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    47
  typical infix declarations.%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    48
\end{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    49
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    50
\isacommand{constdefs}\isanewline
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    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
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    52
\ \ {\isachardoublequote}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    53
%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    54
\begin{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    55
Any curried function with at least two arguments may be associated
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    56
  with infix syntax: \isa{xor\ A\ B} and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} refer to
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    57
  the same expression internally.  In partial applications with less
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    58
  than two operands there is a special notation with \isa{op} prefix:
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    59
  \isa{xor} without arguments is represented as \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}};
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    60
  combined with plain prefix application this turns \isa{xor\ A}
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    61
  into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    62
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    63
  \medskip The string \isa{{\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}} in the above declaration
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    64
  refers to the bit of concrete syntax to represent the operator,
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    65
  while the number \isa{{\isadigit{6}}{\isadigit{0}}} determines the precedence of the whole
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    66
  construct.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    67
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    68
  As it happens, Isabelle/HOL already spends many popular combinations
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    69
  of ASCII symbols for its own use, including both \isa{{\isacharplus}} and
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    70
  \isa{{\isacharplus}{\isacharplus}}.  Slightly more awkward combinations like the present
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    71
  \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} tend to be available for user extensions.  The current
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    72
  arrangement of inner syntax may be inspected via
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    73
  \commdx{print\protect\_syntax}, albeit its output is enormous.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    74
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    75
  Operator precedence also needs some special considerations.  The
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    76
  admissible range is 0--1000.  Very low or high priorities are
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    77
  basically reserved for the meta-logic.  Syntax of Isabelle/HOL
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    78
  mainly uses the range of 10--100: the equality infix \isa{{\isacharequal}} is
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    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
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    80
  HOL forms, or use the mostly unused range 100--900.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    81
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    82
  \medskip The keyword \isakeyword{infixl} specifies an operator that
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    83
  is nested to the \emph{left}: in iterated applications the more
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    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,
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    85
  \isakeyword{infixr} refers to nesting to the \emph{right}, which
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    86
  would turn \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} into \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    87
  In contrast, a \emph{non-oriented} declaration via
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    88
  \isakeyword{infix} would always demand explicit parentheses.
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    89
  
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    90
  Many binary operations observe the associative law, so the exact
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    91
  grouping does not matter.  Nevertheless, formal statements need be
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    92
  given in a particular format, associativity needs to be treated
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    93
  explicitly within the logic.  Exclusive-or is happens to be
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    94
  associative, as shown below.%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    95
\end{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    96
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    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
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    98
\ \ \isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
    99
\isacommand{by}\ {\isacharparenleft}auto\ simp\ add{\isacharcolon}\ xor{\isacharunderscore}def{\isacharparenright}\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   100
%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   101
\begin{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   102
Such rules may be used in simplification to regroup nested
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   103
  expressions as required.  Note that the system would actually print
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   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}}
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   105
  (due to nesting to the left).  We have preferred to give the fully
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   106
  parenthesized form in the text for clarity.%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   107
\end{isamarkuptext}%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   108
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   109
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   110
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   111
\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   112
\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   113
\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   114
\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   115
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   116
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   117
\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   118
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   119
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   120
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   121
\isamarkupfalse%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   122
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   123
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   124
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   125
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   126
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   127
\isamarkuptrue%
08eee994bf99 updated;
wenzelm
parents: 11866
diff changeset
   128
\isamarkuptrue%
11866
fbd097aec213 updated;
wenzelm
parents: 11648
diff changeset
   129
\isamarkupfalse%
11648
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
   130
\end{isabellebody}%
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
   131
%%% Local Variables:
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
   132
%%% mode: latex
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
   133
%%% TeX-master: "root"
d78a82d112e4 *** empty log message ***
wenzelm
parents:
diff changeset
   134
%%% End: