doc-src/TutorialI/Documents/Documents.thy
author wenzelm
Sun, 06 Jan 2002 16:51:48 +0100
changeset 12651 930df4604b36
parent 12648 16d4b8c09086
child 12653 a55c066624eb
permissions -rw-r--r--
some more ...;
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
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
     5
section {* Concrete Syntax \label{sec:concrete-syntax} *}
12629
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
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    10
  for concrete syntax is that of general \bfindex{mixfix annotations}.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    11
  Associated with any kind of name and type declaration, mixfixes give
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    12
  rise both to grammar productions for the parser and output templates
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    13
  for the pretty printer.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    14
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    15
  In full generality, the whole affair of parser and pretty printer
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    16
  configuration is rather subtle.  Any syntax specifications given by
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    17
  end-users need to interact properly with the existing setup of
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    18
  Isabelle/Pure and Isabelle/HOL; see \cite{isabelle-ref} for further
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    19
  details.  It is particularly important to get the precedence of new
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    20
  syntactic constructs right, avoiding ambiguities with existing
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    21
  elements.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    22
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    23
  \medskip Subsequently we introduce a few simple declaration forms
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    24
  that already cover the most common situations fairly well.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    25
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    26
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    27
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
    28
subsection {* Infix Annotations *}
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    29
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    30
text {*
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    31
  Syntax annotations may be included wherever constants are declared
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    32
  directly or indirectly, including \isacommand{consts},
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    33
  \isacommand{constdefs}, or \isacommand{datatype} (for the
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    34
  constructor operations).  Type-constructors may be annotated as
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    35
  well, although this is less frequently encountered in practice
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    36
  (@{text "*"} and @{text "+"} types may come to mind).
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    37
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    38
  Infix declarations\index{infix annotations} provide a useful special
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    39
  case of mixfixes, where users need not care about the full details
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    40
  of priorities, nesting, spacing, etc.  The subsequent example of the
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    41
  exclusive-or operation on boolean values illustrates typical infix
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
    42
  declarations.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    43
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    44
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    45
constdefs
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    46
  xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]" 60)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    47
  "A [+] B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    48
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    49
text {*
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    50
  Any curried function with at least two arguments may be associated
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    51
  with infix syntax: @{text "xor A B"} and @{text "A [+] B"} refer to
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    52
  the same expression internally.  In partial applications with less
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    53
  than two operands there is a special notation with \isa{op} prefix:
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    54
  @{text xor} without arguments is represented as @{text "op [+]"};
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    55
  combined with plain prefix application this turns @{text "xor A"}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    56
  into @{text "op [+] A"}.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    57
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    58
  \medskip The string @{text [source] "[+]"} in the above declaration
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    59
  refers to the bit of concrete syntax to represent the operator,
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    60
  while the number @{text 60} determines the precedence of the whole
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    61
  construct.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    62
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    63
  As it happens, Isabelle/HOL already spends many popular combinations
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    64
  of ASCII symbols for its own use, including both @{text "+"} and
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    65
  @{text "++"}.  Slightly more awkward combinations like the present
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    66
  @{text "[+]"} tend to be available for user extensions.  The current
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    67
  arrangement of inner syntax may be inspected via
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    68
  \commdx{print\protect\_syntax}, albeit its output is enormous.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    69
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    70
  Operator precedence also needs some special considerations.  The
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    71
  admissible range is 0--1000.  Very low or high priorities are
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    72
  basically reserved for the meta-logic.  Syntax of Isabelle/HOL
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    73
  mainly uses the range of 10--100: the equality infix @{text "="} is
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    74
  centered at 50, logical connectives (like @{text "\<or>"} and @{text
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    75
  "\<and>"}) are below 50, and algebraic ones (like @{text "+"} and @{text
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    76
  "*"}) above 50.  User syntax should strive to coexist with common
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    77
  HOL forms, or use the mostly unused range 100--900.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    78
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    79
  \medskip The keyword \isakeyword{infixl} specifies an operator that
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    80
  is nested to the \emph{left}: in iterated applications the more
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    81
  complex expression appears on the left-hand side: @{term "A [+] B
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    82
  [+] C"} stands for @{text "(A [+] B) [+] C"}.  Similarly,
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
    83
  \isakeyword{infixr} refers to nesting to the \emph{right}, reading
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
    84
  @{term "A [+] B [+] C"} as @{text "A [+] (B [+] C)"}.  In contrast,
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
    85
  a \emph{non-oriented} declaration via \isakeyword{infix} would
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
    86
  always demand explicit parentheses.
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
    87
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    88
  Many binary operations observe the associative law, so the exact
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    89
  grouping does not matter.  Nevertheless, formal statements need be
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    90
  given in a particular format, associativity needs to be treated
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    91
  explicitly within the logic.  Exclusive-or is happens to be
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    92
  associative, as shown below.
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    93
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    94
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    95
lemma xor_assoc: "(A [+] B) [+] C = A [+] (B [+] C)"
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    96
  by (auto simp add: xor_def)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    97
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    98
text {*
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
    99
  Such rules may be used in simplification to regroup nested
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   100
  expressions as required.  Note that the system would actually print
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   101
  the above statement as @{term "A [+] B [+] C = A [+] (B [+] C)"}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   102
  (due to nesting to the left).  We have preferred to give the fully
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   103
  parenthesized form in the text for clarity.  Only in rare situations
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   104
  one may consider to force parentheses by use of non-oriented infix
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   105
  syntax; equality would probably be a typical candidate.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   106
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   107
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   108
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   109
subsection {* Mathematical Symbols *}
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   110
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   111
text {*
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   112
  Concrete syntax based on plain ASCII characters has its inherent
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   113
  limitations.  Rich mathematical notation demands a larger repertoire
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   114
  of symbols.  Several standards of extended character sets have been
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   115
  proposed over decades, but none has become universally available so
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   116
  far, not even Unicode\index{Unicode}.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   117
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   118
  Isabelle supports a generic notion of \bfindex{symbols} as the
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   119
  smallest entities of source text, without referring to internal
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   120
  encodings.  Such ``generalized characters'' may be of one of the
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   121
  following three kinds:
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   122
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   123
  \begin{enumerate}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   124
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   125
  \item Traditional 7-bit ASCII characters.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   126
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   127
  \item Named symbols: \verb,\,\verb,<,$ident$\verb,>, (or
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   128
  \verb,\\,\verb,<,$ident$\verb,>,).
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   129
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   130
  \item Named control symbols: \verb,\,\verb,<^,$ident$\verb,>, (or
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   131
  \verb,\\,\verb,<^,$ident$\verb,>,).
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   132
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   133
  \end{enumerate}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   134
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   135
  Here $ident$ may be any identifier according to the usual Isabelle
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   136
  conventions.  This results in an infinite store of symbols, whose
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   137
  interpretation is left to further front-end tools.  For example, the
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   138
  \verb,\,\verb,<forall>, symbol of Isabelle is really displayed as
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   139
  $\forall$ --- both by the user-interface of Proof~General + X-Symbol
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   140
  and the Isabelle document processor (see \S\ref{sec:document-prep}).
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   141
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   142
  A list of standard Isabelle symbols is given in
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   143
  \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   144
  interpretation of further symbols by configuring the appropriate
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   145
  front-end tool accordingly, e.g.\ defining appropriate {\LaTeX}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   146
  macros for document preparation.  There are also a few predefined
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   147
  control symbols, such as \verb,\,\verb,<^sub>, and
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   148
  \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   149
  (printable) symbol, respectively.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   150
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   151
  \medskip The following version of our @{text xor} definition uses a
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   152
  standard Isabelle symbol to achieve typographically pleasing output.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   153
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   154
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   155
(*<*)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   156
hide const xor
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   157
ML_setup {* Context.>> (Theory.add_path "1") *}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   158
(*>*)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   159
constdefs
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   160
  xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>" 60)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   161
  "A \<oplus> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   162
(*<*)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   163
local
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   164
(*>*)
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   165
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   166
text {*
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   167
  The X-Symbol package within Proof~General provides several input
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   168
  methods to enter @{text \<oplus>} in the text.  If all fails one may just
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   169
  type \verb,\,\verb,<oplus>, by hand; the display is adapted
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   170
  immediately after continuing further input.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   171
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   172
  \medskip A slightly more refined scheme is to provide alternative
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   173
  syntax via the \bfindex{print mode} concept of Isabelle (see also
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   174
  \cite{isabelle-ref}).  By convention, the mode ``$xsymbols$'' is
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   175
  enabled whenever X-Symbol is active.  Consider the following hybrid
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   176
  declaration of @{text xor}.
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   177
*}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   178
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   179
(*<*)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   180
hide const xor
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   181
ML_setup {* Context.>> (Theory.add_path "2") *}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   182
(*>*)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   183
constdefs
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   184
  xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]\<ignore>" 60)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   185
  "A [+]\<ignore> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   186
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   187
syntax (xsymbols)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   188
  xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>\<ignore>" 60)
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   189
(*<*)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   190
local
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   191
(*>*)
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   192
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   193
text {*
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   194
  Here the \commdx{syntax} command acts like \isakeyword{consts}, but
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   195
  without declaring a logical constant, and with an optional print
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   196
  mode specification.  Note that the type declaration given here
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   197
  merely serves for syntactic purposes, and is not checked for
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   198
  consistency with the real constant.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   199
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   200
  \medskip Now we may write either @{text "[+]"} or @{text "\<oplus>"} in
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   201
  input, while output uses the nicer syntax of $xsymbols$, provided
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   202
  that print mode is presently active.  This scheme is particularly
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   203
  useful for interactive development, with the user typing plain ASCII
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   204
  text, but gaining improved visual feedback from the system (say in
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   205
  current goal output).
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   206
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   207
  \begin{warn}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   208
  Using alternative syntax declarations easily results in varying
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   209
  versions of input sources.  Isabelle provides no systematic way to
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   210
  convert alternative expressions back and forth.  Print modes only
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   211
  affect situations where formal entities are pretty printed by the
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   212
  Isabelle process (e.g.\ output of terms and types), but not the
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   213
  original theory text.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   214
  \end{warn}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   215
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   216
  \medskip The following variant makes the alternative @{text \<oplus>}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   217
  notation only available for output.  Thus we may enforce input
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   218
  sources to refer to plain ASCII only.
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   219
*}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   220
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   221
syntax (xsymbols output)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   222
  xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>\<ignore>" 60)
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   223
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   224
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   225
subsection {* Prefix Annotations *}
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   226
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   227
text {*
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   228
  Prefix syntax annotations\index{prefix annotation} are just a very
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   229
  degenerate of the general mixfix form \cite{isabelle-ref}, without
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   230
  any template arguments or priorities --- just some piece of literal
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   231
  syntax.
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   232
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   233
  The following example illustrates this idea idea by associating
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   234
  common symbols with the constructors of a currency datatype.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   235
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   236
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   237
datatype currency =
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   238
    Euro nat    ("\<euro>")
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   239
  | Pounds nat  ("\<pounds>")
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   240
  | Yen nat     ("\<yen>")
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   241
  | Dollar nat  ("$")
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   242
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   243
text {*
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   244
  \noindent Here the degenerate mixfix annotations on the rightmost
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   245
  column happen to consist of a single Isabelle symbol each:
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   246
  \verb,\,\verb,<euro>,, \verb,\,\verb,<pounds>,,
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   247
  \verb,\,\verb,<yen>,, and \verb,$,.
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   248
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   249
  Recall that a constructor like @{text Euro} actually is a function
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   250
  @{typ "nat \<Rightarrow> currency"}.  An expression like @{text "Euro 10"} will
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   251
  be printed as @{term "\<euro> 10"}; only the head of the application is
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   252
  subject to our concrete syntax.  This simple form already achieves
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   253
  conformance with notational standards of the European Commission.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   254
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   255
  \medskip Certainly, the same idea of prefix syntax also works for
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   256
  \isakeyword{consts}, \isakeyword{constdefs} etc.  The slightly
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   257
  unusual syntax declaration below decorates the existing @{typ
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   258
  currency} type with the international currency symbol @{text \<currency>}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   259
  (\verb,\,\verb,<currency>,).
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   260
*}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   261
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   262
syntax
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   263
  currency :: type    ("\<currency>")
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   264
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   265
text {*
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   266
  \noindent Here @{typ type} refers to the builtin syntactic category
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   267
  of Isabelle types.  We could now write down funny things like @{text
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   268
  "\<euro> :: nat \<Rightarrow> \<currency>"}, for example.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   269
*}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   270
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   271
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   272
subsection {* Syntax Translations \label{sec:syntax-translations} *}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   273
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   274
text{*
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   275
  Mixfix syntax annotations work well for those situations, where a
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   276
  constant application forms needs to be decorated by concrete syntax.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   277
  Just reconsider @{text "xor A B"} versus @{text "A \<oplus> B"} covered
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   278
  before.  Occasionally, the relationship between some piece of
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   279
  notation and its internal form is slightly more involved.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   280
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   281
  Here the concept of \bfindex{syntax translations} enters the scene.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   282
  Using the raw \isakeyword{syntax}\index{syntax (command)} command we
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   283
  introduce uninterpreted notational elements, while
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   284
  \commdx{translations} relates the input forms with certain logical
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   285
  expressions.  This essentially provides a simple mechanism for for
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   286
  syntactic macros; even heavier transformations may be programmed in
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   287
  ML \cite{isabelle-ref}.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   288
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   289
  \medskip A typical example of syntax translations is to decorate an
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   290
  relational expression (i.e.\ set membership of tuples) with nice
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   291
  symbolic notation, such as @{text "(x, y) \<in> sim"} versus @{text "x \<approx>
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   292
  y"}.
12635
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   293
*}
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   294
e2d44df29c94 more on concrete syntax;
wenzelm
parents: 12629
diff changeset
   295
consts
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   296
  sim :: "('a \<times> 'a) set"
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   297
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   298
syntax
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   299
  "_sim" :: "'a \<Rightarrow> 'a \<Rightarrow> bool"    (infix "\<approx>" 50)
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   300
translations
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   301
  "x \<approx> y" \<rightleftharpoons> "(x, y) \<in> sim"
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   302
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   303
text {*
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   304
  \noindent Here the name of the dummy constant @{text "_sim"} does
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   305
  not really matter, as long as it is not used otherwise.  Prefixing
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   306
  an underscore is a common convention.  The \isakeyword{translations}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   307
  declaration already uses concrete syntax on the left-hand side;
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   308
  internally we relate a raw application @{text "_sim x y"} with
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   309
  @{text "(x, y) \<in> sim"}.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   310
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   311
  \medskip Another useful application of syntax translations is to
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   312
  provide variant versions of fundamental relational expressions, such
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   313
  as @{text \<noteq>} for negated equalities.  The following declaration
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   314
  stems from Isabelle/HOL itself:
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   315
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   316
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   317
syntax "_not_equal" :: "'a \<Rightarrow> 'a \<Rightarrow> bool"    (infixl "\<noteq>\<ignore>" 50)
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   318
translations "x \<noteq>\<ignore> y" \<rightleftharpoons> "\<not> (x = y)"
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   319
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   320
text {*
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   321
  \noindent Normally one would introduce derived concepts like this
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   322
  within the logic, using \isakeyword{consts} and \isakeyword{defs}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   323
  instead of \isakeyword{syntax} and \isakeyword{translations}.  The
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   324
  present formulation has the virtue that expressions are immediately
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   325
  replaced by its ``definition'' upon parsing; the effect is reversed
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   326
  upon printing.  Internally, @{text"\<noteq>"} never appears.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   327
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   328
  Simulating definitions via translations is adequate for very basic
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   329
  variations of fundamental logical concepts, when the new
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   330
  representation is a trivial variation on an existing one.  On the
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   331
  other hand, syntax translations do not scale up well to large
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   332
  hierarchies of concepts built on each other.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   333
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   334
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   335
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   336
section {* Document Preparation \label{sec:document-prep} *}
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   337
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   338
text {*
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   339
  Isabelle/Isar is centered around a certain notion of \bfindex{formal
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   340
  proof documents}\index{documents|bold}: ultimately the result of the
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   341
  user's theory development efforts is a human-readable record --- as
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   342
  a browsable PDF file or printed on paper.  The overall document
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   343
  structure follows traditional mathematical articles, with
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   344
  sectioning, explanations, definitions, theorem statements, and
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   345
  proofs.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   346
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   347
  The Isar proof language \cite{Wenzel-PhD}, which is not covered in
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   348
  this book, admits to write formal proof texts that are acceptable
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   349
  both to the machine and human readers at the same time.  Thus
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   350
  marginal comments and explanations may be kept at a minimum.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   351
  Nevertheless, Isabelle document output is still useful without
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   352
  actual Isar proof texts; formal specifications usually deserve their
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   353
  own coverage in the text, while unstructured proof scripts may be
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   354
  just ignore by readers (or intentionally suppressed from the text).
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   355
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   356
  \medskip The Isabelle document preparation system essentially acts
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   357
  like a formal front-end for {\LaTeX}.  After checking definitions
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   358
  and proofs the theory sources are turned into typesetting
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   359
  instructions, so the final document is known to observe quite strong
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   360
  ``soundness'' properties.  This enables users to write authentic
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   361
  reports on formal theory developments with little additional effort,
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   362
  the most tedious consistency checks are handled by the system.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   363
*}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   364
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   365
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   366
subsection {* Isabelle Sessions *}
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   367
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   368
text {*
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   369
  In contrast to the highly interactive mode of the formal parts of
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   370
  Isabelle/Isar theory development, the document preparation stage
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   371
  essentially works in batch-mode.  This revolves around the concept
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   372
  of a \bfindex{session}, which essentially consists of a collection
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   373
  of theory source files that contribute to a single output document.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   374
  Each session is derived from a parent one (usually an object-logic
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   375
  image such as \texttt{HOL}); this results in an overall tree
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   376
  structure of Isabelle sessions.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   377
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   378
  The canonical arrangement of source files of a session called
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   379
  \texttt{MySession} is as follows:
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   380
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   381
  \begin{itemize}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   382
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   383
  \item Directory \texttt{MySession} contains the required theory
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   384
  files, say $A@1$\texttt{.thy}, \dots, $A@n$\texttt{.thy}.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   385
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   386
  \item File \texttt{MySession/ROOT.ML} holds appropriate ML commands
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   387
  for loading all wanted theories, usually just
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   388
  \texttt{use_thy~"$A@i$"} for any $A@i$ in leaf position of the
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   389
  theory dependency graph.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   390
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   391
  \item Directory \texttt{MySession/document} contains everything
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   392
  required for the {\LaTeX} stage, but only \texttt{root.tex} needs to
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   393
  be provided initially.  The latter file holds appropriate {\LaTeX}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   394
  code to commence a document (\verb,\documentclass, etc.), and to
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   395
  include the generated files $A@i$\texttt{.tex} for each theory.  The
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   396
  generated file \texttt{session.tex} holds {\LaTeX} commands to
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   397
  include \emph{all} theory output files in topologically sorted
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   398
  order.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   399
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   400
  \item In addition an \texttt{IsaMakefile} outside of directory
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   401
  \texttt{MySession} holds appropriate dependencies and invocations of
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   402
  Isabelle tools to control the batch job.  The details are covered in
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   403
  \cite{isabelle-sys}; \texttt{isatool usedir} is the most important
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   404
  entry point.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   405
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   406
  \end{itemize}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   407
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   408
  With everything put in its proper place, \texttt{isatool make}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   409
  should be sufficient to process the Isabelle session completely,
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   410
  with the generated document appearing in its proper place (within
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   411
  \verb,~/isabelle/browser_info,).
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   412
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   413
  In practice, users may want to have \texttt{isatool mkdir} generate
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   414
  an initial working setup without further ado.  For example, an empty
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   415
  session \texttt{MySession} derived from \texttt{HOL} may be produced
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   416
  as follows:
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   417
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   418
\begin{verbatim}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   419
  isatool mkdir HOL MySession
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   420
  isatool make
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   421
\end{verbatim}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   422
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   423
  This runs the session with sensible default options, including
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   424
  verbose mode to tell the user where the result will appear.  The
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   425
  above dry run should produce should produce a single page of output
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   426
  (with a dummy title, empty table of contents etc.).  Any failure at
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   427
  that stage is likely to indicate some technical problems with your
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   428
  {\LaTeX} installation.\footnote{Especially make sure that
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   429
  \texttt{pdflatex} is present.}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   430
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   431
  \medskip Users may now start to populate the directory
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   432
  \texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   433
  accordingly.  \texttt{MySession/document/root.tex} should be also
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   434
  adapted at some point; the generated version is mostly
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   435
  self-explanatory.  The default versions includes the
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   436
  \texttt{isabelle} (mandatory) and \texttt{isabellesym} (required for
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   437
  mathematical symbols); further packages may required, e.g.\ for
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   438
  unusual Isabelle symbols.
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   439
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   440
  Realistic applications may demand additional files in
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   441
  \texttt{MySession/document} for the {\LaTeX} stage, such as
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   442
  \texttt{root.bib} for the bibliographic database.\footnote{Using
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   443
  that particular name of \texttt{root.bib}, the Isabelle document
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   444
  processor (actually \texttt{isatool document} \cite{isabelle-sys})
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   445
  will be smart enough to invoke \texttt{bibtex} accordingly.}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   446
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   447
  \medskip Failure of the document preparation phase in an Isabelle
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   448
  batch session leaves the generated sources in there target location
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   449
  (as pointed out by the accompanied error message).  In case of
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   450
  {\LaTeX} errors, users may trace error messages at the file position
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   451
  of the generated text.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   452
*}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   453
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   454
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   455
subsection {* Structure Markup *}
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   456
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   457
subsubsection {* Sections *}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   458
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   459
text {*
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   460
  The large-scale structure of Isabelle documents closely follows
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   461
  {\LaTeX} convention, with chapters, sections, subsubsections etc.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   462
  The formal Isar language includes separate structure \bfindex{markup
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   463
  commands}, which do not effect the formal content of a theory (or
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   464
  proof), but results in corresponding {\LaTeX} elements issued to the
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   465
  output.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   466
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   467
  There are different markup commands for different formal contexts:
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   468
  in header position (just before a \isakeyword{theory} command),
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   469
  within the theory body, or within a proof.  Note that the header
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   470
  needs to be treated specially, since ordinary theory and proof
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   471
  commands may only occur \emph{after} the initial \isakeyword{theory}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   472
  specification.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   473
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   474
  \smallskip
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   475
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   476
  \begin{tabular}{llll}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   477
  header & theory & proof & default meaning \\\hline
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   478
    & \commdx{chapter} & & \verb,\chapter, \\
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   479
  \commdx{header} & \commdx{section} & \commdx{sect} & \verb,\section, \\
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   480
    & \commdx{subsection} & \commdx{subsect} & \verb,\subsection, \\
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   481
    & \commdx{subsubsection} & \commdx{subsubsect} & \verb,\subsubsection, \\
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   482
  \end{tabular}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   483
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   484
  \medskip
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   485
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   486
  From the Isabelle perspective, each markup command takes a single
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   487
  text argument (delimited by \verb,",\dots\verb,", or
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   488
  \verb,{,\verb,*,~\dots~\verb,*,\verb,},).  After stripping
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   489
  surrounding white space, the argument is passed to a {\LaTeX} macro
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   490
  \verb,\isamarkupXXX, for any command \isakeyword{XXX}.  The latter
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   491
  are defined in \verb,isabelle.sty, according to the rightmost column
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   492
  above.
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   493
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   494
  \medskip The following source fragment illustrates structure markup
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   495
  of a theory.  Note that {\LaTeX} labels may well be included inside
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   496
  of section headings as well.
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   497
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   498
  \begin{ttbox}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   499
  header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   500
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   501
  theory Foo_Bar = Main:
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   502
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   503
  subsection {\ttlbrace}* Basic definitions *{\ttrbrace}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   504
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   505
  consts
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   506
    foo :: \dots
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   507
    bar :: \dots
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   508
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   509
  defs \dots
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   510
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   511
  subsection {\ttlbrace}* Derived rules *{\ttrbrace}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   512
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   513
  lemma fooI: \dots
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   514
  lemma fooE: \dots
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   515
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   516
  subsection {\ttlbrace}* Main theorem {\ttback}label{\ttlbrace}sec:main-theorem{\ttrbrace} *{\ttrbrace}
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   517
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   518
  theorem main: \dots
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   519
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   520
  end
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   521
  \end{ttbox}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   522
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   523
  Users may occasionally want to change the meaning of some markup
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   524
  commands, typically via appropriate use of \verb,\renewcommand, in
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   525
  \texttt{root.tex}.  The \verb,\isamarkupheader, is a good candidate
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   526
  for some adaption, e.g.\ moving it up in the hierarchy to become
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   527
  \verb,\chapter,.
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   528
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   529
\begin{verbatim}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   530
  \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   531
\end{verbatim}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   532
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   533
  Certainly, this requires to change the default
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   534
  \verb,\documentclass{article}, in \texttt{root.tex} to something
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   535
  that supports the notion of chapters in the first place, e.g.\
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   536
  \verb,\documentclass{report},.
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   537
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   538
  \medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   539
  hold the name of the current theory context.  This is particularly
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   540
  useful for document headings or footings, e.g.\ like this:
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   541
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   542
\begin{verbatim}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   543
  \renewcommand{\isamarkupheader}[1]%
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   544
  {\chapter{#1}\markright{THEORY~\isabellecontext}}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   545
\end{verbatim}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   546
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   547
  \noindent Make sure to include something like
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   548
  \verb,\pagestyle{headings}, in \texttt{root.tex}; the document
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   549
  should have more than 2 pages to show the effect.
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   550
*}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   551
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   552
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   553
subsection {* Formal Comments and Antiquotations *}
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   554
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   555
text {*
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   556
  Comments of the form \verb,(,\verb,*,~\dots~\verb,*,\verb,),
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   557
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   558
  FIXME
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   559
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   560
*}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   561
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   562
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   563
subsection {* Symbols and Characters *}
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   564
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   565
text {*
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   566
  FIXME \verb,\isabellestyle,
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   567
*}
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   568
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   569
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   570
subsection {* Suppressing Output *}
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   571
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   572
text {*
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   573
  By default Isabelle's document system generates a {\LaTeX} source
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   574
  file for each theory that happens to get loaded during the session.
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   575
  The generated \texttt{session.tex} file will include all of these in
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   576
  order of appearance, which in turn gets included by the standard
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   577
  \texttt{root.tex} file.  Certainly one may change the order of
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   578
  appearance or suppress unwanted theories by ignoring
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   579
  \texttt{session.tex} and include individual files in
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   580
  \texttt{root.tex} by hand.  On the other hand, such an arrangement
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   581
  requires additional efforts for maintenance.
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   582
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   583
  Alternatively, one may tune the theory loading process in
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   584
  \texttt{ROOT.ML}: traversal of the theory dependency graph may be
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   585
  fine-tuned by adding further \verb,use_thy, invocations, although
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   586
  topological sorting needs to be preserved.  Moreover, the ML
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   587
  operator \verb,no_document, temporarily disables document generation
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   588
  while executing a theory loader command; the usage is like this:
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   589
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   590
\begin{verbatim}
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   591
  no_document use_thy "Aux";
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   592
\end{verbatim}
12645
3af5de958a1a some text on document preparation;
wenzelm
parents: 12642
diff changeset
   593
12648
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   594
  Theory output may be also suppressed \emph{partially} as well.
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   595
  Typical applications include research papers or slides based on
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   596
  formal developments --- these usually do not show the full formal
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   597
  content.  The special source comments
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   598
  \verb,(,\verb,*,\verb,<,\verb,*,\verb,), and
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   599
  \verb,(,\verb,*,\verb,>,\verb,*,\verb,), are interpreted by the
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   600
  document generator as open and close parenthesis for
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   601
  \bfindex{ignored material}.  Any text inside of (potentially nested)
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   602
  \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\dots~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   603
  parentheses is just ignored from the output --- after correct formal
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   604
  checking.
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   605
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   606
  In the following example we suppress the slightly formalistic
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   607
  \isakeyword{theory} and \isakeyword{end} part of a theory text.
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   608
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   609
  \medskip
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   610
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   611
  \begin{tabular}{l}
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   612
  \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   613
  \texttt{theory A = Main:} \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   614
  \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   615
  ~~$\vdots$ \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   616
  \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   617
  \texttt{end} \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   618
  \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   619
  \end{tabular}
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   620
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   621
  \medskip
16d4b8c09086 some more text;
wenzelm
parents: 12645
diff changeset
   622
12651
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   623
  Text may be suppressed at a very fine grain; thus we may even drop
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   624
  vital parts of the formal text, preventing that things have been
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   625
  simpler than in reality.  For example, the following ``fully
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   626
  automatic'' proof is actually a fake:
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   627
*}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   628
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   629
lemma "x \<noteq> (0::int) \<Longrightarrow> 0 < x * x"
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   630
  by (auto(*<*)simp add: int_less_le(*>*))
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   631
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   632
text {*
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   633
  \noindent Here the real source of the proof has been as follows:
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   634
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   635
\begin{verbatim}
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   636
  by (auto(*<*)simp add: int_less_le(*>*))
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   637
\end{verbatim} %(*
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   638
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   639
  \medskip Ignoring portions of printed text generally demands some
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   640
  care by the user.  First of all, the writer is responsible not to
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   641
  obfuscate the underlying formal development in an unduly manner.  It
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   642
  is fairly easy to scramble the remaining visible text by referring
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   643
  to questionable formal items (strange definitions, arbitrary axioms
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   644
  etc.) that have been hidden from sight.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   645
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   646
  Some minor technical subtleties of the
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   647
  \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   648
  elements need to be observed as well, as the system performs little
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   649
  sanity checks here.  Arguments of markup commands and formal
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   650
  comments must not be hidden, otherwise presentation fails.  Open and
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   651
  close parentheses need to be inserted carefully; it is fairly easy
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   652
  to hide just the wrong parts, especially after rearranging the
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   653
  sources.
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   654
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   655
  \medskip Authentic reports of formal theories, say as part of a
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   656
  library, should usually refrain from suppressing parts of the text
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   657
  at all.  Other users may need the full information for their own
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   658
  derivative work.  If a particular formalization works out as too
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   659
  ugly for general public coverage, it is often better to think of a
930df4604b36 some more ...;
wenzelm
parents: 12648
diff changeset
   660
  better way in the first place.
12629
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   661
*}
281aa36829d8 beginnings of concrete syntax;
wenzelm
parents: 11647
diff changeset
   662
11647
0538cb0f7999 initial setup for chapter on document preparation;
wenzelm
parents:
diff changeset
   663
(*<*)
0538cb0f7999 initial setup for chapter on document preparation;
wenzelm
parents:
diff changeset
   664
end
0538cb0f7999 initial setup for chapter on document preparation;
wenzelm
parents:
diff changeset
   665
(*>*)