doc-src/IsarImplementation/Thy/document/prelim.tex
author wenzelm
Tue Aug 29 18:49:33 2006 +0200 (2006-08-29 ago)
changeset 20429 116255c9209b
parent 20215 96a4b3b7a6aa
child 20430 fd646e926983
permissions -rw-r--r--
more on contexts;
wenzelm@18537
     1
%
wenzelm@18537
     2
\begin{isabellebody}%
wenzelm@18537
     3
\def\isabellecontext{prelim}%
wenzelm@18537
     4
%
wenzelm@18537
     5
\isadelimtheory
wenzelm@18537
     6
\isanewline
wenzelm@18537
     7
\isanewline
wenzelm@18537
     8
\isanewline
wenzelm@18537
     9
%
wenzelm@18537
    10
\endisadelimtheory
wenzelm@18537
    11
%
wenzelm@18537
    12
\isatagtheory
wenzelm@18537
    13
\isacommand{theory}\isamarkupfalse%
wenzelm@18537
    14
\ prelim\ \isakeyword{imports}\ base\ \isakeyword{begin}%
wenzelm@18537
    15
\endisatagtheory
wenzelm@18537
    16
{\isafoldtheory}%
wenzelm@18537
    17
%
wenzelm@18537
    18
\isadelimtheory
wenzelm@18537
    19
%
wenzelm@18537
    20
\endisadelimtheory
wenzelm@18537
    21
%
wenzelm@18537
    22
\isamarkupchapter{Preliminaries%
wenzelm@18537
    23
}
wenzelm@18537
    24
\isamarkuptrue%
wenzelm@18537
    25
%
wenzelm@18537
    26
\isamarkupsection{Named entities%
wenzelm@18537
    27
}
wenzelm@18537
    28
\isamarkuptrue%
wenzelm@18537
    29
%
wenzelm@18537
    30
\begin{isamarkuptext}%
wenzelm@18537
    31
Named entities of different kinds (logical constant, type,
wenzelm@18537
    32
type class, theorem, method etc.) live in separate name spaces.  It is
wenzelm@18537
    33
usually clear from the occurrence of a name which kind of entity it
wenzelm@18537
    34
refers to.  For example, proof method \isa{foo} vs.\ theorem
wenzelm@18537
    35
\isa{foo} vs.\ logical constant \isa{foo} are easily
wenzelm@18537
    36
distinguished by means of the syntactic context.  A notable exception
wenzelm@18537
    37
are logical identifiers within a term (\secref{sec:terms}): constants,
wenzelm@18537
    38
fixed variables, and bound variables all share the same identifier
wenzelm@18537
    39
syntax, but are distinguished by their scope.
wenzelm@18537
    40
wenzelm@18537
    41
Each name space is organized as a collection of \emph{qualified
wenzelm@18537
    42
names}, which consist of a sequence of basic name components separated
wenzelm@18537
    43
by dots: \isa{Bar{\isachardot}bar{\isachardot}foo}, \isa{Bar{\isachardot}foo}, and \isa{foo}
wenzelm@18537
    44
are examples for valid qualified names.  Name components are
wenzelm@18537
    45
subdivided into \emph{symbols}, which constitute the smallest textual
wenzelm@18537
    46
unit in Isabelle --- raw characters are normally not encountered
wenzelm@18537
    47
directly.%
wenzelm@18537
    48
\end{isamarkuptext}%
wenzelm@18537
    49
\isamarkuptrue%
wenzelm@18537
    50
%
wenzelm@18537
    51
\isamarkupsubsection{Strings of symbols%
wenzelm@18537
    52
}
wenzelm@18537
    53
\isamarkuptrue%
wenzelm@18537
    54
%
wenzelm@18537
    55
\begin{isamarkuptext}%
wenzelm@18537
    56
Isabelle strings consist of a sequence of
wenzelm@18537
    57
symbols\glossary{Symbol}{The smalles unit of text in Isabelle,
wenzelm@18537
    58
subsumes plain ASCII characters as well as an infinite collection of
wenzelm@18537
    59
named symbols (for greek, math etc.).}, which are either packed as an
wenzelm@18537
    60
actual \isa{string}, or represented as a list.  Each symbol is in
wenzelm@18537
    61
itself a small string of the following form:
wenzelm@18537
    62
wenzelm@18537
    63
\begin{enumerate}
wenzelm@18537
    64
wenzelm@18537
    65
\item either a singleton ASCII character ``\isa{c}'' (with
wenzelm@18537
    66
character code 0--127), for example ``\verb,a,'',
wenzelm@18537
    67
wenzelm@18537
    68
\item or a regular symbol ``\verb,\,\verb,<,\isa{ident}\verb,>,'',
wenzelm@18537
    69
for example ``\verb,\,\verb,<alpha>,'',
wenzelm@18537
    70
wenzelm@18537
    71
\item or a control symbol ``\verb,\,\verb,<^,\isa{ident}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'',
wenzelm@18537
    72
wenzelm@20206
    73
\item or a raw control symbol ``\verb,\,\verb,<^raw:,\isa{{\isasymdots}}\verb,>,'' where ``\isa{{\isasymdots}}'' refers to any
wenzelm@20206
    74
printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or
wenzelm@20215
    75
non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
wenzelm@18537
    76
wenzelm@18537
    77
\item or a numbered raw control symbol ``\verb,\,\verb,<^raw,\isa{nnn}\verb,>, where \isa{nnn} are digits, for example
wenzelm@18537
    78
``\verb,\,\verb,<^raw42>,''.
wenzelm@18537
    79
wenzelm@18537
    80
\end{enumerate}
wenzelm@18537
    81
wenzelm@18537
    82
The \isa{ident} syntax for symbol names is \isa{letter\ {\isacharparenleft}letter\ {\isacharbar}\ digit{\isacharparenright}\isactrlsup {\isacharasterisk}}, where \isa{letter\ {\isacharequal}\ A{\isachardot}{\isachardot}Za{\isachardot}{\isachardot}Z} and \isa{digit\ {\isacharequal}\ {\isadigit{0}}{\isachardot}{\isachardot}{\isadigit{9}}}.  There are infinitely many regular symbols and
wenzelm@18537
    83
control symbols available, but a certain collection of standard
wenzelm@18537
    84
symbols is treated specifically.  For example,
wenzelm@18537
    85
``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter,
wenzelm@18537
    86
which means it may occur within regular Isabelle identifier syntax.
wenzelm@18537
    87
wenzelm@18537
    88
Output of symbols depends on the print mode (\secref{sec:print-mode}).
wenzelm@18537
    89
For example, the standard {\LaTeX} setup of the Isabelle document
wenzelm@18537
    90
preparation system would present ``\verb,\,\verb,<alpha>,'' as \isa{{\isasymalpha}}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as \isa{\isactrlbold {\isasymalpha}}.
wenzelm@18537
    91
wenzelm@18537
    92
\medskip It is important to note that the character set underlying
wenzelm@18537
    93
Isabelle symbols is plain 7-bit ASCII.  Since 8-bit characters are
wenzelm@18537
    94
passed through transparently, Isabelle may easily process actual
wenzelm@18537
    95
Unicode/UCS data (using the well-known UTF-8 encoding, for example).
wenzelm@18537
    96
Unicode provides its own collection of mathematical symbols, but there
wenzelm@18537
    97
is presently no link to Isabelle's named ones; both kinds of symbols
wenzelm@18537
    98
coexist independently.%
wenzelm@18537
    99
\end{isamarkuptext}%
wenzelm@18537
   100
\isamarkuptrue%
wenzelm@18537
   101
%
wenzelm@18537
   102
\isadelimmlref
wenzelm@18537
   103
%
wenzelm@18537
   104
\endisadelimmlref
wenzelm@18537
   105
%
wenzelm@18537
   106
\isatagmlref
wenzelm@18537
   107
%
wenzelm@18537
   108
\begin{isamarkuptext}%
wenzelm@18537
   109
\begin{mldecls}
wenzelm@18537
   110
  \indexmltype{Symbol.symbol}\verb|type Symbol.symbol| \\
wenzelm@18537
   111
  \indexml{Symbol.explode}\verb|Symbol.explode: string -> Symbol.symbol list| \\
wenzelm@18537
   112
  \indexml{Symbol.is-letter}\verb|Symbol.is_letter: Symbol.symbol -> bool| \\
wenzelm@18537
   113
  \indexml{Symbol.is-digit}\verb|Symbol.is_digit: Symbol.symbol -> bool| \\
wenzelm@18537
   114
  \indexml{Symbol.is-quasi}\verb|Symbol.is_quasi: Symbol.symbol -> bool| \\
wenzelm@18537
   115
  \indexml{Symbol.is-blank}\verb|Symbol.is_blank: Symbol.symbol -> bool| \\
wenzelm@18537
   116
  \indexmltype{Symbol.sym}\verb|type Symbol.sym| \\
wenzelm@18537
   117
  \indexml{Symbol.decode}\verb|Symbol.decode: Symbol.symbol -> Symbol.sym| \\
wenzelm@18537
   118
  \end{mldecls}
wenzelm@18537
   119
wenzelm@18537
   120
  \begin{description}
wenzelm@18537
   121
wenzelm@18537
   122
  \item \verb|Symbol.symbol| represents Isabelle symbols; this type
wenzelm@18537
   123
  is merely an alias for \verb|string|, but emphasizes the
wenzelm@18537
   124
  specific format encountered here.
wenzelm@18537
   125
wenzelm@18537
   126
  \item \verb|Symbol.explode|~\isa{s} produces an actual symbol
wenzelm@18537
   127
  list from the packed form usually encountered as user input.  This
wenzelm@18537
   128
  function replaces \verb|String.explode| for virtually all purposes
wenzelm@18537
   129
  of manipulating text in Isabelle!  Plain \isa{implode} may be
wenzelm@18537
   130
  used for the reverse operation.
wenzelm@18537
   131
wenzelm@18537
   132
  \item \verb|Symbol.is_letter|, \verb|Symbol.is_digit|, \verb|Symbol.is_quasi|, \verb|Symbol.is_blank| classify certain symbols
wenzelm@18537
   133
  (both ASCII and several named ones) according to fixed syntactic
wenzelm@18537
   134
  convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}.
wenzelm@18537
   135
wenzelm@18537
   136
  \item \verb|Symbol.sym| is a concrete datatype that represents
wenzelm@18537
   137
  the different kinds of symbols explicitly as \verb|Symbol.Char|,
wenzelm@18537
   138
  \verb|Symbol.Sym|, \verb|Symbol.Ctrl|, or \verb|Symbol.Raw|.
wenzelm@18537
   139
wenzelm@18537
   140
  \item \verb|Symbol.decode| converts the string representation of a
wenzelm@18537
   141
  symbol into the explicit datatype version.
wenzelm@18537
   142
wenzelm@18537
   143
  \end{description}%
wenzelm@18537
   144
\end{isamarkuptext}%
wenzelm@18537
   145
\isamarkuptrue%
wenzelm@18537
   146
%
wenzelm@18537
   147
\endisatagmlref
wenzelm@18537
   148
{\isafoldmlref}%
wenzelm@18537
   149
%
wenzelm@18537
   150
\isadelimmlref
wenzelm@18537
   151
%
wenzelm@18537
   152
\endisadelimmlref
wenzelm@18537
   153
%
wenzelm@20429
   154
\isamarkupsubsection{Simple names%
wenzelm@20429
   155
}
wenzelm@20429
   156
\isamarkuptrue%
wenzelm@20429
   157
%
wenzelm@20429
   158
\begin{isamarkuptext}%
wenzelm@20429
   159
FIXME%
wenzelm@20429
   160
\end{isamarkuptext}%
wenzelm@20429
   161
\isamarkuptrue%
wenzelm@20429
   162
%
wenzelm@18537
   163
\isamarkupsubsection{Qualified names and name spaces%
wenzelm@18537
   164
}
wenzelm@18537
   165
\isamarkuptrue%
wenzelm@18537
   166
%
wenzelm@18537
   167
\isadelimFIXME
wenzelm@18537
   168
%
wenzelm@18537
   169
\endisadelimFIXME
wenzelm@18537
   170
%
wenzelm@18537
   171
\isatagFIXME
wenzelm@18537
   172
%
wenzelm@18537
   173
\begin{isamarkuptext}%
wenzelm@18537
   174
Qualified names are constructed according to implicit naming
wenzelm@18537
   175
principles of the present context.
wenzelm@18537
   176
wenzelm@18537
   177
wenzelm@18537
   178
The last component is called \emph{base name}; the remaining prefix of
wenzelm@18537
   179
qualification may be empty.
wenzelm@18537
   180
wenzelm@18537
   181
Some practical conventions help to organize named entities more
wenzelm@18537
   182
systematically:
wenzelm@18537
   183
wenzelm@18537
   184
\begin{itemize}
wenzelm@18537
   185
wenzelm@18537
   186
\item Names are qualified first by the theory name, second by an
wenzelm@18537
   187
optional ``structure''.  For example, a constant \isa{c} declared
wenzelm@18537
   188
as part of a certain structure \isa{b} (say a type definition) in
wenzelm@18537
   189
theory \isa{A} will be named \isa{A{\isachardot}b{\isachardot}c} internally.
wenzelm@18537
   190
wenzelm@18537
   191
\item
wenzelm@18537
   192
wenzelm@18537
   193
\item
wenzelm@18537
   194
wenzelm@18537
   195
\item
wenzelm@18537
   196
wenzelm@18537
   197
\item
wenzelm@18537
   198
wenzelm@18537
   199
\end{itemize}
wenzelm@18537
   200
wenzelm@18537
   201
Names of different kinds of entities are basically independent, but
wenzelm@18537
   202
some practical naming conventions relate them to each other.  For
wenzelm@18537
   203
example, a constant \isa{foo} may be accompanied with theorems
wenzelm@18537
   204
\isa{foo{\isachardot}intro}, \isa{foo{\isachardot}elim}, \isa{foo{\isachardot}simps} etc.  The
wenzelm@18537
   205
same may happen for a type \isa{foo}, which is then apt to cause
wenzelm@18537
   206
clashes in the theorem name space!  To avoid this, we occasionally
wenzelm@18537
   207
follow an additional convention of suffixes that determine the
wenzelm@18537
   208
original kind of entity that a name has been derived.  For example,
wenzelm@18537
   209
constant \isa{foo} is associated with theorem \isa{foo{\isachardot}intro},
wenzelm@18537
   210
type \isa{foo} with theorem \isa{foo{\isacharunderscore}type{\isachardot}intro}, and type
wenzelm@18537
   211
class \isa{foo} with \isa{foo{\isacharunderscore}class{\isachardot}intro}.%
wenzelm@18537
   212
\end{isamarkuptext}%
wenzelm@18537
   213
\isamarkuptrue%
wenzelm@18537
   214
%
wenzelm@18537
   215
\endisatagFIXME
wenzelm@18537
   216
{\isafoldFIXME}%
wenzelm@18537
   217
%
wenzelm@18537
   218
\isadelimFIXME
wenzelm@18537
   219
%
wenzelm@18537
   220
\endisadelimFIXME
wenzelm@18537
   221
%
wenzelm@18537
   222
\isamarkupsection{Structured output%
wenzelm@18537
   223
}
wenzelm@18537
   224
\isamarkuptrue%
wenzelm@18537
   225
%
wenzelm@18537
   226
\isamarkupsubsection{Pretty printing%
wenzelm@18537
   227
}
wenzelm@18537
   228
\isamarkuptrue%
wenzelm@18537
   229
%
wenzelm@18537
   230
\begin{isamarkuptext}%
wenzelm@18537
   231
FIXME%
wenzelm@18537
   232
\end{isamarkuptext}%
wenzelm@18537
   233
\isamarkuptrue%
wenzelm@18537
   234
%
wenzelm@18537
   235
\isamarkupsubsection{Output channels%
wenzelm@18537
   236
}
wenzelm@18537
   237
\isamarkuptrue%
wenzelm@18537
   238
%
wenzelm@18537
   239
\begin{isamarkuptext}%
wenzelm@18537
   240
FIXME%
wenzelm@18537
   241
\end{isamarkuptext}%
wenzelm@18537
   242
\isamarkuptrue%
wenzelm@18537
   243
%
wenzelm@18537
   244
\isamarkupsubsection{Print modes%
wenzelm@18537
   245
}
wenzelm@18537
   246
\isamarkuptrue%
wenzelm@18537
   247
%
wenzelm@18537
   248
\begin{isamarkuptext}%
wenzelm@18537
   249
FIXME%
wenzelm@18537
   250
\end{isamarkuptext}%
wenzelm@18537
   251
\isamarkuptrue%
wenzelm@18537
   252
%
wenzelm@20429
   253
\isamarkupsection{Contexts \label{sec:context}%
wenzelm@18537
   254
}
wenzelm@18537
   255
\isamarkuptrue%
wenzelm@18537
   256
%
wenzelm@18537
   257
\begin{isamarkuptext}%
wenzelm@20429
   258
A logical context represents the background that is taken for
wenzelm@20429
   259
  granted when formulating statements and composing proofs.  It acts
wenzelm@20429
   260
  as a medium to produce formal content, depending on earlier material
wenzelm@20429
   261
  (declarations, results etc.).
wenzelm@18537
   262
wenzelm@20429
   263
  In particular, derivations within the primitive Pure logic can be
wenzelm@20429
   264
  described as a judgment \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}, meaning that a
wenzelm@20429
   265
  proposition \isa{{\isasymphi}} is derivable from hypotheses \isa{{\isasymGamma}}
wenzelm@20429
   266
  within the theory \isa{{\isasymTheta}}.  There are logical reasons for
wenzelm@20429
   267
  keeping \isa{{\isasymTheta}} and \isa{{\isasymGamma}} separate: theories support type
wenzelm@20429
   268
  constructors and schematic polymorphism of constants and axioms,
wenzelm@20429
   269
  while the inner calculus of \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} is limited to Simple
wenzelm@20429
   270
  Type Theory (with fixed type variables in the assumptions).
wenzelm@18537
   271
wenzelm@20429
   272
  \medskip Contexts and derivations are linked by the following key
wenzelm@20429
   273
  principles:
wenzelm@20429
   274
wenzelm@20429
   275
  \begin{itemize}
wenzelm@20429
   276
wenzelm@20429
   277
  \item Transfer: monotonicity of derivations admits results to be
wenzelm@20429
   278
  transferred into a larger context, i.e.\ \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}
wenzelm@20429
   279
  implies \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\isactrlsub {\isacharprime}\ {\isasymphi}} for contexts \isa{{\isasymTheta}{\isacharprime}\ {\isasymsupseteq}\ {\isasymTheta}} and \isa{{\isasymGamma}{\isacharprime}\ {\isasymsupseteq}\ {\isasymGamma}}.
wenzelm@20429
   280
wenzelm@20429
   281
  \item Export: discharge of hypotheses admits results to be exported
wenzelm@20429
   282
  into a smaller context, i.e.\ \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}} implies
wenzelm@20429
   283
  \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymDelta}\ {\isasymLongrightarrow}\ {\isasymphi}} where \isa{{\isasymGamma}{\isacharprime}\ {\isasymsupseteq}\ {\isasymGamma}} and \isa{{\isasymDelta}\ {\isacharequal}\ {\isasymGamma}{\isacharprime}\ {\isacharminus}\ {\isasymGamma}}.  Note that \isa{{\isasymTheta}} remains unchanged here, only the
wenzelm@20429
   284
  \isa{{\isasymGamma}} part is affected.
wenzelm@18537
   285
wenzelm@20429
   286
  \end{itemize}
wenzelm@18537
   287
wenzelm@20429
   288
  \medskip Isabelle/Isar provides two different notions of abstract
wenzelm@20429
   289
  containers called \emph{theory context} and \emph{proof context},
wenzelm@20429
   290
  respectively.  These model the main characteristics of the primitive
wenzelm@20429
   291
  \isa{{\isasymTheta}} and \isa{{\isasymGamma}} above, without subscribing to any
wenzelm@20429
   292
  particular kind of content yet.  Instead, contexts merely impose a
wenzelm@20429
   293
  certain policy of managing arbitrary \emph{context data}.  The
wenzelm@20429
   294
  system provides strongly typed mechanisms to declare new kinds of
wenzelm@20429
   295
  data at compile time.
wenzelm@18537
   296
wenzelm@20429
   297
  Thus the internal bootstrap process of Isabelle/Pure eventually
wenzelm@20429
   298
  reaches a stage where certain data slots provide the logical content
wenzelm@20429
   299
  of \isa{{\isasymTheta}} and \isa{{\isasymGamma}} sketched above, but this does not
wenzelm@20429
   300
  stop there!  Various additional data slots support all kinds of
wenzelm@20429
   301
  mechanisms that are not necessarily part of the core logic.
wenzelm@18537
   302
wenzelm@20429
   303
  For example, there would be data for canonical introduction and
wenzelm@20429
   304
  elimination rules for arbitrary operators (depending on the
wenzelm@20429
   305
  object-logic and application), which enables users to perform
wenzelm@20429
   306
  standard proof steps implicitly (cf.\ the \isa{rule} method).
wenzelm@18537
   307
wenzelm@20429
   308
  Isabelle is able to bring forth more and more concepts successively.
wenzelm@20429
   309
  In particular, an object-logic like Isabelle/HOL continues the
wenzelm@20429
   310
  Isabelle/Pure setup by adding specific components for automated
wenzelm@20429
   311
  reasoning (classical reasoner, tableau prover, structured induction
wenzelm@20429
   312
  etc.) and derived specification mechanisms (inductive predicates,
wenzelm@20429
   313
  recursive functions etc.).  All of this is based on the generic data
wenzelm@20429
   314
  management by theory and proof contexts.%
wenzelm@18537
   315
\end{isamarkuptext}%
wenzelm@18537
   316
\isamarkuptrue%
wenzelm@18537
   317
%
wenzelm@18537
   318
\isamarkupsubsection{Theory context \label{sec:context-theory}%
wenzelm@18537
   319
}
wenzelm@18537
   320
\isamarkuptrue%
wenzelm@18537
   321
%
wenzelm@18537
   322
\begin{isamarkuptext}%
wenzelm@20429
   323
Each theory is explicitly named and holds a unique identifier.
wenzelm@20429
   324
  There is a separate \emph{theory reference} for pointing backwards
wenzelm@20429
   325
  to the enclosing theory context of derived entities.  Theories are
wenzelm@20429
   326
  related by a (nominal) sub-theory relation, which corresponds to the
wenzelm@20429
   327
  canonical dependency graph: each theory is derived from a certain
wenzelm@20429
   328
  sub-graph of ancestor theories.  The \isa{merge} of two theories
wenzelm@20429
   329
  refers to the least upper bound, which actually degenerates into
wenzelm@20429
   330
  absorption of one theory into the other, due to the nominal
wenzelm@20429
   331
  sub-theory relation this.
wenzelm@18537
   332
wenzelm@20429
   333
  The \isa{begin} operation starts a new theory by importing
wenzelm@20429
   334
  several parent theories and entering a special \isa{draft} mode,
wenzelm@20429
   335
  which is sustained until the final \isa{end} operation.  A draft
wenzelm@20429
   336
  mode theory acts like a linear type, where updates invalidate
wenzelm@20429
   337
  earlier drafts, but theory reference values will be propagated
wenzelm@20429
   338
  automatically.  Thus derived entities that ``belong'' to a draft
wenzelm@20429
   339
  might be transferred spontaneously to a larger context.  An
wenzelm@20429
   340
  invalidated draft is called ``stale''.  The \isa{copy} operation
wenzelm@20429
   341
  produces an auxiliary version with the same data content, but is
wenzelm@20429
   342
  unrelated to the original: updates of the copy do not affect the
wenzelm@20429
   343
  original, neither does the sub-theory relation hold.
wenzelm@20429
   344
wenzelm@20429
   345
  The example below shows a theory graph derived from \isa{Pure}.
wenzelm@20429
   346
  Theory \isa{Length} imports \isa{Nat} and \isa{List}.
wenzelm@20429
   347
  The linear draft mode is enabled during the ``\isa{{\isasymdots}}'' stage of
wenzelm@20429
   348
  the theory body.
wenzelm@20429
   349
wenzelm@20429
   350
  \bigskip
wenzelm@20429
   351
  \begin{tabular}{rcccl}
wenzelm@18537
   352
        &            & $Pure$ \\
wenzelm@18537
   353
        &            & $\downarrow$ \\
wenzelm@18537
   354
        &            & $FOL$ \\
wenzelm@18537
   355
        & $\swarrow$ &              & $\searrow$ & \\
wenzelm@18537
   356
  $Nat$ &            &              &            & $List$ \\
wenzelm@18537
   357
        & $\searrow$ &              & $\swarrow$ \\
wenzelm@18537
   358
        &            & $Length$ \\
wenzelm@18537
   359
        &            & \multicolumn{3}{l}{~~$\isarkeyword{imports}$} \\
wenzelm@18537
   360
        &            & \multicolumn{3}{l}{~~$\isarkeyword{begin}$} \\
wenzelm@18537
   361
        &            & $\vdots$~~ \\
wenzelm@18537
   362
        &            & \multicolumn{3}{l}{~~$\isarkeyword{end}$} \\
wenzelm@20429
   363
  \end{tabular}
wenzelm@20429
   364
wenzelm@20429
   365
  \medskip In practice, derived theory operations mostly operate
wenzelm@20429
   366
  drafts, namely the body of the current portion of theory that the
wenzelm@20429
   367
  user happens to be composing.
wenzelm@18537
   368
wenzelm@20429
   369
 \medskip There is also a builtin theory history mechanism that amends for
wenzelm@20429
   370
  the destructive behaviour of theory drafts.  The \isa{checkpoint} operation produces an intermediate stepping stone that
wenzelm@20429
   371
  survives the next update unscathed: both the original and the
wenzelm@20429
   372
  changed theory remain valid and are related by the sub-theory
wenzelm@20429
   373
  relation.  This recovering of pure theory values comes at the cost
wenzelm@20429
   374
  of extra internal bookeeping.  The cumulative effect of
wenzelm@20429
   375
  checkpointing is purged by the \isa{finish} operation.
wenzelm@18537
   376
wenzelm@20429
   377
  History operations are usually managed by the system, e.g.\ notably
wenzelm@20429
   378
  in the Isar transaction loop.
wenzelm@18537
   379
wenzelm@20429
   380
  \medskip
wenzelm@20429
   381
  FIXME theory data%
wenzelm@18537
   382
\end{isamarkuptext}%
wenzelm@18537
   383
\isamarkuptrue%
wenzelm@18537
   384
%
wenzelm@18537
   385
\isamarkupsubsection{Proof context \label{sec:context-proof}%
wenzelm@18537
   386
}
wenzelm@18537
   387
\isamarkuptrue%
wenzelm@18537
   388
%
wenzelm@18537
   389
\begin{isamarkuptext}%
wenzelm@20429
   390
A proof context is an arbitrary container that is initialized from a
wenzelm@20429
   391
  given theory.  The result contains a back-reference to the theory it
wenzelm@20429
   392
  belongs to, together with pure data.  No further bookkeeping is
wenzelm@20429
   393
  required here, thanks to the lack of destructive features.
wenzelm@20429
   394
wenzelm@20429
   395
  There is no restriction on producing proof contexts, although the
wenzelm@20429
   396
  usual discipline is to follow block structure as a mental model: a
wenzelm@20429
   397
  given context is extended consecutively, results are exported back
wenzelm@20429
   398
  into the original context.  In particular, the concept of Isar proof
wenzelm@20429
   399
  state models block-structured reasoning explicitly, using a stack of
wenzelm@20429
   400
  proof contexts.
wenzelm@20429
   401
wenzelm@20429
   402
  Due to the lack of identification and back-referencing, entities
wenzelm@20429
   403
  derived in a proof context need to record inherent logical
wenzelm@20429
   404
  requirements explicitly.  For example, hypotheses used in a
wenzelm@20429
   405
  derivation will be recorded separately within the sequent \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}}, just to make double sure.  Results could leak into an alien
wenzelm@20429
   406
  proof context do to programming errors, but Isabelle/Isar
wenzelm@20429
   407
  occasionally includes extra validity checks at the end of a
wenzelm@20429
   408
  sub-proof.
wenzelm@20429
   409
wenzelm@20429
   410
  \medskip
wenzelm@20429
   411
  FIXME proof data
wenzelm@18537
   412
wenzelm@18537
   413
\glossary{Proof context}{The static context of a structured proof,
wenzelm@18537
   414
acts like a local ``theory'' of the current portion of Isar proof
wenzelm@18537
   415
text, generalizes the idea of local hypotheses \isa{{\isasymGamma}} in
wenzelm@18537
   416
judgments \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} of natural deduction calculi.  There is a
wenzelm@18537
   417
generic notion of introducing and discharging hypotheses.  Arbritrary
wenzelm@18537
   418
auxiliary context data may be adjoined.}%
wenzelm@18537
   419
\end{isamarkuptext}%
wenzelm@18537
   420
\isamarkuptrue%
wenzelm@18537
   421
%
wenzelm@20429
   422
\isamarkupsubsection{Generic contexts%
wenzelm@20429
   423
}
wenzelm@20429
   424
\isamarkuptrue%
wenzelm@20429
   425
%
wenzelm@18537
   426
\isadelimtheory
wenzelm@18537
   427
%
wenzelm@18537
   428
\endisadelimtheory
wenzelm@18537
   429
%
wenzelm@18537
   430
\isatagtheory
wenzelm@18537
   431
\isacommand{end}\isamarkupfalse%
wenzelm@18537
   432
%
wenzelm@18537
   433
\endisatagtheory
wenzelm@18537
   434
{\isafoldtheory}%
wenzelm@18537
   435
%
wenzelm@18537
   436
\isadelimtheory
wenzelm@18537
   437
%
wenzelm@18537
   438
\endisadelimtheory
wenzelm@18537
   439
\isanewline
wenzelm@18537
   440
\end{isabellebody}%
wenzelm@18537
   441
%%% Local Variables:
wenzelm@18537
   442
%%% mode: latex
wenzelm@18537
   443
%%% TeX-master: "root"
wenzelm@18537
   444
%%% End: