doc-src/IsarImplementation/Thy/document/prelim.tex
author wenzelm
Thu Aug 31 17:33:55 2006 +0200 (2006-08-31 ago)
changeset 20449 f8a7a8236c68
parent 20447 5b75f1c4d7d6
child 20450 725a91601ed1
permissions -rw-r--r--
more stuff;
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@20429
    26
\isamarkupsection{Contexts \label{sec:context}%
wenzelm@18537
    27
}
wenzelm@18537
    28
\isamarkuptrue%
wenzelm@18537
    29
%
wenzelm@18537
    30
\begin{isamarkuptext}%
wenzelm@20429
    31
A logical context represents the background that is taken for
wenzelm@20429
    32
  granted when formulating statements and composing proofs.  It acts
wenzelm@20429
    33
  as a medium to produce formal content, depending on earlier material
wenzelm@20429
    34
  (declarations, results etc.).
wenzelm@18537
    35
wenzelm@20429
    36
  In particular, derivations within the primitive Pure logic can be
wenzelm@20429
    37
  described as a judgment \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}, meaning that a
wenzelm@20429
    38
  proposition \isa{{\isasymphi}} is derivable from hypotheses \isa{{\isasymGamma}}
wenzelm@20429
    39
  within the theory \isa{{\isasymTheta}}.  There are logical reasons for
wenzelm@20429
    40
  keeping \isa{{\isasymTheta}} and \isa{{\isasymGamma}} separate: theories support type
wenzelm@20429
    41
  constructors and schematic polymorphism of constants and axioms,
wenzelm@20429
    42
  while the inner calculus of \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} is limited to Simple
wenzelm@20429
    43
  Type Theory (with fixed type variables in the assumptions).
wenzelm@18537
    44
wenzelm@20429
    45
  \medskip Contexts and derivations are linked by the following key
wenzelm@20429
    46
  principles:
wenzelm@20429
    47
wenzelm@20429
    48
  \begin{itemize}
wenzelm@20429
    49
wenzelm@20429
    50
  \item Transfer: monotonicity of derivations admits results to be
wenzelm@20429
    51
  transferred into a larger context, i.e.\ \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}
wenzelm@20429
    52
  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
    53
wenzelm@20429
    54
  \item Export: discharge of hypotheses admits results to be exported
wenzelm@20429
    55
  into a smaller context, i.e.\ \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}} implies
wenzelm@20429
    56
  \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
    57
  \isa{{\isasymGamma}} part is affected.
wenzelm@18537
    58
wenzelm@20429
    59
  \end{itemize}
wenzelm@18537
    60
wenzelm@20429
    61
  \medskip Isabelle/Isar provides two different notions of abstract
wenzelm@20429
    62
  containers called \emph{theory context} and \emph{proof context},
wenzelm@20429
    63
  respectively.  These model the main characteristics of the primitive
wenzelm@20429
    64
  \isa{{\isasymTheta}} and \isa{{\isasymGamma}} above, without subscribing to any
wenzelm@20429
    65
  particular kind of content yet.  Instead, contexts merely impose a
wenzelm@20429
    66
  certain policy of managing arbitrary \emph{context data}.  The
wenzelm@20429
    67
  system provides strongly typed mechanisms to declare new kinds of
wenzelm@20429
    68
  data at compile time.
wenzelm@18537
    69
wenzelm@20429
    70
  Thus the internal bootstrap process of Isabelle/Pure eventually
wenzelm@20429
    71
  reaches a stage where certain data slots provide the logical content
wenzelm@20429
    72
  of \isa{{\isasymTheta}} and \isa{{\isasymGamma}} sketched above, but this does not
wenzelm@20429
    73
  stop there!  Various additional data slots support all kinds of
wenzelm@20429
    74
  mechanisms that are not necessarily part of the core logic.
wenzelm@18537
    75
wenzelm@20429
    76
  For example, there would be data for canonical introduction and
wenzelm@20429
    77
  elimination rules for arbitrary operators (depending on the
wenzelm@20429
    78
  object-logic and application), which enables users to perform
wenzelm@20429
    79
  standard proof steps implicitly (cf.\ the \isa{rule} method).
wenzelm@18537
    80
wenzelm@20429
    81
  Isabelle is able to bring forth more and more concepts successively.
wenzelm@20429
    82
  In particular, an object-logic like Isabelle/HOL continues the
wenzelm@20429
    83
  Isabelle/Pure setup by adding specific components for automated
wenzelm@20429
    84
  reasoning (classical reasoner, tableau prover, structured induction
wenzelm@20429
    85
  etc.) and derived specification mechanisms (inductive predicates,
wenzelm@20429
    86
  recursive functions etc.).  All of this is based on the generic data
wenzelm@20429
    87
  management by theory and proof contexts.%
wenzelm@18537
    88
\end{isamarkuptext}%
wenzelm@18537
    89
\isamarkuptrue%
wenzelm@18537
    90
%
wenzelm@18537
    91
\isamarkupsubsection{Theory context \label{sec:context-theory}%
wenzelm@18537
    92
}
wenzelm@18537
    93
\isamarkuptrue%
wenzelm@18537
    94
%
wenzelm@18537
    95
\begin{isamarkuptext}%
wenzelm@20447
    96
\glossary{Theory}{FIXME}
wenzelm@20447
    97
wenzelm@20447
    98
  Each theory is explicitly named and holds a unique identifier.
wenzelm@20429
    99
  There is a separate \emph{theory reference} for pointing backwards
wenzelm@20429
   100
  to the enclosing theory context of derived entities.  Theories are
wenzelm@20429
   101
  related by a (nominal) sub-theory relation, which corresponds to the
wenzelm@20429
   102
  canonical dependency graph: each theory is derived from a certain
wenzelm@20429
   103
  sub-graph of ancestor theories.  The \isa{merge} of two theories
wenzelm@20429
   104
  refers to the least upper bound, which actually degenerates into
wenzelm@20429
   105
  absorption of one theory into the other, due to the nominal
wenzelm@20429
   106
  sub-theory relation this.
wenzelm@18537
   107
wenzelm@20429
   108
  The \isa{begin} operation starts a new theory by importing
wenzelm@20429
   109
  several parent theories and entering a special \isa{draft} mode,
wenzelm@20429
   110
  which is sustained until the final \isa{end} operation.  A draft
wenzelm@20429
   111
  mode theory acts like a linear type, where updates invalidate
wenzelm@20429
   112
  earlier drafts, but theory reference values will be propagated
wenzelm@20429
   113
  automatically.  Thus derived entities that ``belong'' to a draft
wenzelm@20429
   114
  might be transferred spontaneously to a larger context.  An
wenzelm@20447
   115
  invalidated draft is called ``stale''.
wenzelm@20429
   116
wenzelm@20447
   117
  The \isa{checkpoint} operation produces an intermediate stepping
wenzelm@20447
   118
  stone that will survive the next update unscathed: both the original
wenzelm@20447
   119
  and the changed theory remain valid and are related by the
wenzelm@20447
   120
  sub-theory relation.  Checkpointing essentially recovers purely
wenzelm@20447
   121
  functional theory values, at the expense of some extra internal
wenzelm@20447
   122
  bookeeping.
wenzelm@20447
   123
wenzelm@20447
   124
  The \isa{copy} operation produces an auxiliary version that has
wenzelm@20447
   125
  the same data content, but is unrelated to the original: updates of
wenzelm@20447
   126
  the copy do not affect the original, neither does the sub-theory
wenzelm@20447
   127
  relation hold.
wenzelm@20429
   128
wenzelm@20447
   129
  \medskip The example in \figref{fig:ex-theory} below shows a theory
wenzelm@20447
   130
  graph derived from \isa{Pure}. Theory \isa{Length} imports
wenzelm@20447
   131
  \isa{Nat} and \isa{List}.  The theory body consists of a
wenzelm@20447
   132
  sequence of updates, working mostly on drafts.  Intermediate
wenzelm@20447
   133
  checkpoints may occur as well, due to the history mechanism provided
wenzelm@20447
   134
  by the Isar toplevel, cf.\ \secref{sec:isar-toplevel}.
wenzelm@20447
   135
wenzelm@20447
   136
  \begin{figure}[htb]
wenzelm@20447
   137
  \begin{center}
wenzelm@20429
   138
  \begin{tabular}{rcccl}
wenzelm@20447
   139
        &            & \isa{Pure} \\
wenzelm@20447
   140
        &            & \isa{{\isasymdown}} \\
wenzelm@20447
   141
        &            & \isa{FOL} \\
wenzelm@18537
   142
        & $\swarrow$ &              & $\searrow$ & \\
wenzelm@20447
   143
  $Nat$ &            &              &            & \isa{List} \\
wenzelm@18537
   144
        & $\searrow$ &              & $\swarrow$ \\
wenzelm@20447
   145
        &            & \isa{Length} \\
wenzelm@18537
   146
        &            & \multicolumn{3}{l}{~~$\isarkeyword{imports}$} \\
wenzelm@18537
   147
        &            & \multicolumn{3}{l}{~~$\isarkeyword{begin}$} \\
wenzelm@18537
   148
        &            & $\vdots$~~ \\
wenzelm@20447
   149
        &            & \isa{{\isasymbullet}}~~ \\
wenzelm@20447
   150
        &            & $\vdots$~~ \\
wenzelm@20447
   151
        &            & \isa{{\isasymbullet}}~~ \\
wenzelm@20447
   152
        &            & $\vdots$~~ \\
wenzelm@18537
   153
        &            & \multicolumn{3}{l}{~~$\isarkeyword{end}$} \\
wenzelm@20429
   154
  \end{tabular}
wenzelm@20447
   155
  \caption{Theory definition depending on ancestors}\label{fig:ex-theory}
wenzelm@20447
   156
  \end{center}
wenzelm@20447
   157
  \end{figure}%
wenzelm@18537
   158
\end{isamarkuptext}%
wenzelm@18537
   159
\isamarkuptrue%
wenzelm@18537
   160
%
wenzelm@20430
   161
\isadelimmlref
wenzelm@20430
   162
%
wenzelm@20430
   163
\endisadelimmlref
wenzelm@20430
   164
%
wenzelm@20430
   165
\isatagmlref
wenzelm@20430
   166
%
wenzelm@20430
   167
\begin{isamarkuptext}%
wenzelm@20447
   168
\begin{mldecls}
wenzelm@20447
   169
  \indexmltype{theory}\verb|type theory| \\
wenzelm@20447
   170
  \indexml{Theory.subthy}\verb|Theory.subthy: theory * theory -> bool| \\
wenzelm@20447
   171
  \indexml{Theory.merge}\verb|Theory.merge: theory * theory -> theory| \\
wenzelm@20447
   172
  \indexml{Theory.checkpoint}\verb|Theory.checkpoint: theory -> theory| \\
wenzelm@20447
   173
  \indexml{Theory.copy}\verb|Theory.copy: theory -> theory| \\[1ex]
wenzelm@20447
   174
  \indexmltype{theory-ref}\verb|type theory_ref| \\
wenzelm@20447
   175
  \indexml{Theory.self-ref}\verb|Theory.self_ref: theory -> theory_ref| \\
wenzelm@20447
   176
  \indexml{Theory.deref}\verb|Theory.deref: theory_ref -> theory| \\
wenzelm@20447
   177
  \end{mldecls}
wenzelm@20447
   178
wenzelm@20447
   179
  \begin{description}
wenzelm@20447
   180
wenzelm@20447
   181
  \item \verb|theory| represents theory contexts.  This is a
wenzelm@20447
   182
  linear type!  Most operations destroy the old version, which then
wenzelm@20447
   183
  becomes ``stale''.
wenzelm@20447
   184
wenzelm@20447
   185
  \item \verb|Theory.subthy|~\isa{{\isacharparenleft}thy\isactrlsub {\isadigit{1}}{\isacharcomma}\ thy\isactrlsub {\isadigit{2}}{\isacharparenright}}
wenzelm@20447
   186
  compares theories according to the inherent graph structure of the
wenzelm@20447
   187
  construction.  This sub-theory relation is a nominal approximation
wenzelm@20447
   188
  of inclusion (\isa{{\isasymsubseteq}}) of the corresponding content.
wenzelm@20447
   189
wenzelm@20447
   190
  \item \verb|Theory.merge|~\isa{{\isacharparenleft}thy\isactrlsub {\isadigit{1}}{\isacharcomma}\ thy\isactrlsub {\isadigit{2}}{\isacharparenright}}
wenzelm@20447
   191
  absorbs one theory into the other.  This fails for unrelated
wenzelm@20447
   192
  theories!
wenzelm@20447
   193
wenzelm@20447
   194
  \item \verb|Theory.checkpoint|~\isa{thy} produces a safe
wenzelm@20447
   195
  stepping stone in the linear development of \isa{thy}.  The next
wenzelm@20447
   196
  update will result in two related, valid theories.
wenzelm@20447
   197
wenzelm@20447
   198
  \item \verb|Theory.copy|~\isa{thy} produces a variant of \isa{thy} that holds a copy of the same data.  The copy is not related
wenzelm@20447
   199
  to the original, which is not touched at all.
wenzelm@20447
   200
wenzelm@20447
   201
  \item \verb|theory_ref| represents a sliding reference to a
wenzelm@20447
   202
  valid theory --- updates on the original are propagated
wenzelm@20447
   203
  automatically.
wenzelm@20447
   204
wenzelm@20449
   205
  \item \verb|Theory.self_ref|~\isa{thy} and \verb|Theory.deref|~\isa{thy{\isacharunderscore}ref} convert between \verb|theory| and \verb|theory_ref|.  As the referenced theory
wenzelm@20449
   206
  evolves monotonically over time, later invocations of \verb|Theory.deref| may refer to larger contexts.
wenzelm@20447
   207
wenzelm@20447
   208
  \end{description}%
wenzelm@20430
   209
\end{isamarkuptext}%
wenzelm@20430
   210
\isamarkuptrue%
wenzelm@20430
   211
%
wenzelm@20430
   212
\endisatagmlref
wenzelm@20430
   213
{\isafoldmlref}%
wenzelm@20430
   214
%
wenzelm@20430
   215
\isadelimmlref
wenzelm@20430
   216
%
wenzelm@20430
   217
\endisadelimmlref
wenzelm@20430
   218
%
wenzelm@18537
   219
\isamarkupsubsection{Proof context \label{sec:context-proof}%
wenzelm@18537
   220
}
wenzelm@18537
   221
\isamarkuptrue%
wenzelm@18537
   222
%
wenzelm@18537
   223
\begin{isamarkuptext}%
wenzelm@20447
   224
\glossary{Proof context}{The static context of a structured proof,
wenzelm@20447
   225
  acts like a local ``theory'' of the current portion of Isar proof
wenzelm@20447
   226
  text, generalizes the idea of local hypotheses \isa{{\isasymGamma}} in
wenzelm@20447
   227
  judgments \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} of natural deduction calculi.  There is a
wenzelm@20447
   228
  generic notion of introducing and discharging hypotheses.
wenzelm@20447
   229
  Arbritrary auxiliary context data may be adjoined.}
wenzelm@20429
   230
wenzelm@20447
   231
  A proof context is a container for pure data with a back-reference
wenzelm@20449
   232
  to the theory it belongs to.  The \isa{init} operation creates a
wenzelm@20449
   233
  proof context derived from a given theory.  Modifications to draft
wenzelm@20449
   234
  theories are propagated to the proof context as usual, but there is
wenzelm@20449
   235
  also an explicit \isa{transfer} operation to force
wenzelm@20449
   236
  resynchronization with more substantial updates to the underlying
wenzelm@20449
   237
  theory.  The actual context data does not require any special
wenzelm@20449
   238
  bookkeeping, thanks to the lack of destructive features.
wenzelm@20429
   239
wenzelm@20447
   240
  Entities derived in a proof context need to record inherent logical
wenzelm@20447
   241
  requirements explicitly, since there is no separate context
wenzelm@20447
   242
  identification as for theories.  For example, hypotheses used in
wenzelm@20447
   243
  primitive derivations (cf.\ \secref{sec:thm}) are recorded
wenzelm@20447
   244
  separately within the sequent \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}}, just to make double
wenzelm@20447
   245
  sure.  Results could still leak into an alien proof context do to
wenzelm@20447
   246
  programming errors, but Isabelle/Isar includes some extra validity
wenzelm@20447
   247
  checks in critical positions, notably at the end of sub-proof.
wenzelm@20429
   248
wenzelm@20447
   249
  Proof contexts may be produced in arbitrary ways, although the
wenzelm@20447
   250
  common discipline is to follow block structure as a mental model: a
wenzelm@20447
   251
  given context is extended consecutively, and results are exported
wenzelm@20447
   252
  back into the original context.  Note that the Isar proof states
wenzelm@20447
   253
  model block-structured reasoning explicitly, using a stack of proof
wenzelm@20447
   254
  contexts, cf.\ \secref{isar-proof-state}.%
wenzelm@18537
   255
\end{isamarkuptext}%
wenzelm@18537
   256
\isamarkuptrue%
wenzelm@18537
   257
%
wenzelm@20430
   258
\isadelimmlref
wenzelm@20430
   259
%
wenzelm@20430
   260
\endisadelimmlref
wenzelm@20430
   261
%
wenzelm@20430
   262
\isatagmlref
wenzelm@20430
   263
%
wenzelm@20430
   264
\begin{isamarkuptext}%
wenzelm@20449
   265
\begin{mldecls}
wenzelm@20449
   266
  \indexmltype{Proof.context}\verb|type Proof.context| \\
wenzelm@20449
   267
  \indexml{ProofContext.init}\verb|ProofContext.init: theory -> Proof.context| \\
wenzelm@20449
   268
  \indexml{ProofContext.theory-of}\verb|ProofContext.theory_of: Proof.context -> theory| \\
wenzelm@20449
   269
  \indexml{ProofContext.transfer}\verb|ProofContext.transfer: theory -> Proof.context -> Proof.context| \\
wenzelm@20449
   270
  \end{mldecls}
wenzelm@20449
   271
wenzelm@20449
   272
  \begin{description}
wenzelm@20449
   273
wenzelm@20449
   274
  \item \verb|Proof.context| represents proof contexts.  Elements
wenzelm@20449
   275
  of this type are essentially pure values, with a sliding reference
wenzelm@20449
   276
  to the background theory.
wenzelm@20449
   277
wenzelm@20449
   278
  \item \verb|ProofContext.init|~\isa{thy} produces a proof context
wenzelm@20449
   279
  derived from \isa{thy}, initializing all data.
wenzelm@20449
   280
wenzelm@20449
   281
  \item \verb|ProofContext.theory_of|~\isa{ctxt} selects the
wenzelm@20449
   282
  background theory from \isa{ctxt}.
wenzelm@20449
   283
wenzelm@20449
   284
  \item \verb|ProofContext.transfer|~\isa{thy\ ctxt} promotes the
wenzelm@20449
   285
  background theory of \isa{ctxt} to the super theory \isa{thy}.
wenzelm@20449
   286
wenzelm@20449
   287
  \end{description}%
wenzelm@20430
   288
\end{isamarkuptext}%
wenzelm@20430
   289
\isamarkuptrue%
wenzelm@20430
   290
%
wenzelm@20430
   291
\endisatagmlref
wenzelm@20430
   292
{\isafoldmlref}%
wenzelm@20430
   293
%
wenzelm@20430
   294
\isadelimmlref
wenzelm@20430
   295
%
wenzelm@20430
   296
\endisadelimmlref
wenzelm@20430
   297
%
wenzelm@20429
   298
\isamarkupsubsection{Generic contexts%
wenzelm@20429
   299
}
wenzelm@20429
   300
\isamarkuptrue%
wenzelm@20429
   301
%
wenzelm@20430
   302
\begin{isamarkuptext}%
wenzelm@20449
   303
A generic context is the disjoint sum of either a theory or proof
wenzelm@20449
   304
  context.  Occasionally, this simplifies uniform treatment of generic
wenzelm@20449
   305
  context data, typically extralogical information.  Operations on
wenzelm@20449
   306
  generic contexts include the usual injections, partial selections,
wenzelm@20449
   307
  and combinators for lifting operations on either component of the
wenzelm@20449
   308
  disjoint sum.
wenzelm@20449
   309
wenzelm@20449
   310
  Moreover, there are total operations \isa{theory{\isacharunderscore}of} and \isa{proof{\isacharunderscore}of} to convert a generic context into either kind: a theory
wenzelm@20449
   311
  can always be selected, while a proof context may have to be
wenzelm@20449
   312
  constructed by an ad-hoc \isa{init} operation.%
wenzelm@20430
   313
\end{isamarkuptext}%
wenzelm@20430
   314
\isamarkuptrue%
wenzelm@20430
   315
%
wenzelm@20430
   316
\isadelimmlref
wenzelm@20430
   317
%
wenzelm@20430
   318
\endisadelimmlref
wenzelm@20430
   319
%
wenzelm@20430
   320
\isatagmlref
wenzelm@20430
   321
%
wenzelm@20430
   322
\begin{isamarkuptext}%
wenzelm@20449
   323
\begin{mldecls}
wenzelm@20449
   324
  \indexmltype{Context.generic}\verb|type Context.generic| \\
wenzelm@20449
   325
  \indexml{Context.theory-of}\verb|Context.theory_of: Context.generic -> theory| \\
wenzelm@20449
   326
  \indexml{Context.proof-of}\verb|Context.proof_of: Context.generic -> Proof.context| \\
wenzelm@20449
   327
  \end{mldecls}
wenzelm@20449
   328
wenzelm@20449
   329
  \begin{description}
wenzelm@20449
   330
wenzelm@20449
   331
  \item \verb|Context.generic| is the direct sum of \verb|theory| and \verb|Proof.context|, with datatype constructors
wenzelm@20449
   332
  \verb|Context.Theory| and \verb|Context.Proof|.
wenzelm@20449
   333
wenzelm@20449
   334
  \item \verb|Context.theory_of|~\isa{context} always produces a
wenzelm@20449
   335
  theory from the generic \isa{context}, using \verb|ProofContext.theory_of| as required.
wenzelm@20449
   336
wenzelm@20449
   337
  \item \verb|Context.proof_of|~\isa{context} always produces a
wenzelm@20449
   338
  proof context from the generic \isa{context}, using \verb|ProofContext.init| as required.  Note that this re-initializes the
wenzelm@20449
   339
  context data with each invocation.
wenzelm@20449
   340
wenzelm@20449
   341
  \end{description}%
wenzelm@20430
   342
\end{isamarkuptext}%
wenzelm@20430
   343
\isamarkuptrue%
wenzelm@20430
   344
%
wenzelm@20430
   345
\endisatagmlref
wenzelm@20430
   346
{\isafoldmlref}%
wenzelm@20430
   347
%
wenzelm@20430
   348
\isadelimmlref
wenzelm@20430
   349
%
wenzelm@20430
   350
\endisadelimmlref
wenzelm@20430
   351
%
wenzelm@20447
   352
\isamarkupsubsection{Context data%
wenzelm@20447
   353
}
wenzelm@20447
   354
\isamarkuptrue%
wenzelm@20447
   355
%
wenzelm@20447
   356
\begin{isamarkuptext}%
wenzelm@20449
   357
Both theory and proof contexts manage arbitrary data, which is the
wenzelm@20449
   358
  main purpose of contexts in the first place.  Data can be declared
wenzelm@20449
   359
  incrementally at compile --- Isabelle/Pure and major object-logics
wenzelm@20449
   360
  are bootstrapped that way.
wenzelm@20449
   361
wenzelm@20449
   362
  \paragraph{Theory data} may refer to destructive entities, which are
wenzelm@20449
   363
  maintained in correspondence to the linear evolution of theory
wenzelm@20449
   364
  values, or explicit copies.\footnote{Most existing instances of
wenzelm@20449
   365
  destructive theory data are merely historical relics (e.g.\ the
wenzelm@20449
   366
  destructive theorem storage, and destructive hints for the
wenzelm@20449
   367
  Simplifier and Classical rules).}  A theory data declaration needs to
wenzelm@20449
   368
  provide the following information:
wenzelm@20449
   369
wenzelm@20449
   370
  \medskip
wenzelm@20449
   371
  \begin{tabular}{ll}
wenzelm@20449
   372
  \isa{name{\isacharcolon}\ string} \\
wenzelm@20449
   373
  \isa{T} & the ML type \\
wenzelm@20449
   374
  \isa{empty{\isacharcolon}\ T} & initial value \\
wenzelm@20449
   375
  \isa{copy{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & refresh impure data \\
wenzelm@20449
   376
  \isa{extend{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & re-initialize on import \\
wenzelm@20449
   377
  \isa{merge{\isacharcolon}\ T\ {\isasymtimes}\ T\ {\isasymrightarrow}\ T} & join on import \\
wenzelm@20449
   378
  \isa{print{\isacharcolon}\ T\ {\isasymrightarrow}\ unit} & diagnostic output \\
wenzelm@20449
   379
  \end{tabular}
wenzelm@20449
   380
  \medskip
wenzelm@20449
   381
wenzelm@20449
   382
  \noindent The \isa{name} acts as a comment for diagnostic
wenzelm@20449
   383
  messages; \isa{copy} is just the identity for pure data; \isa{extend} is acts like a unitary version of \isa{merge}, both
wenzelm@20449
   384
  should also include the functionality of \isa{copy} for impure
wenzelm@20449
   385
  data.
wenzelm@20449
   386
wenzelm@20449
   387
  \paragraph{Proof context data} is purely functional.  It is declared
wenzelm@20449
   388
  by providing the following information:
wenzelm@20449
   389
wenzelm@20449
   390
  \medskip
wenzelm@20449
   391
  \begin{tabular}{ll}
wenzelm@20449
   392
  \isa{name{\isacharcolon}\ string} \\
wenzelm@20449
   393
  \isa{T} & the ML type \\
wenzelm@20449
   394
  \isa{init{\isacharcolon}\ theory\ {\isasymrightarrow}\ T} & produce initial value \\
wenzelm@20449
   395
  \isa{print{\isacharcolon}\ T\ {\isasymrightarrow}\ unit} & diagnostic output \\
wenzelm@20449
   396
  \end{tabular}
wenzelm@20449
   397
  \medskip
wenzelm@20449
   398
wenzelm@20449
   399
  \noindent The \isa{init} operation is supposed to produce a pure
wenzelm@20449
   400
  value from the given background theory.  The rest is analogous to
wenzelm@20449
   401
  (pure) theory data.
wenzelm@20449
   402
wenzelm@20449
   403
  \paragraph{Generic data} provides a hybrid interface for both kinds.
wenzelm@20449
   404
  The declaration is essentially the same as for pure theory data,
wenzelm@20449
   405
  without \isa{copy} (it is always the identity).  The \isa{init} operation for proof contexts selects the current data value
wenzelm@20449
   406
  from the background theory.
wenzelm@20449
   407
wenzelm@20449
   408
  \bigskip In any case, a data declaration of type \isa{T} results
wenzelm@20449
   409
  in the following interface:
wenzelm@20449
   410
wenzelm@20449
   411
  \medskip
wenzelm@20449
   412
  \begin{tabular}{ll}
wenzelm@20449
   413
  \isa{init{\isacharcolon}\ theory\ {\isasymrightarrow}\ theory} \\
wenzelm@20449
   414
  \isa{get{\isacharcolon}\ context\ {\isasymrightarrow}\ T} \\
wenzelm@20449
   415
  \isa{put{\isacharcolon}\ T\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
wenzelm@20449
   416
  \isa{map{\isacharcolon}\ {\isacharparenleft}T\ {\isasymrightarrow}\ T{\isacharparenright}\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
wenzelm@20449
   417
  \isa{print{\isacharcolon}\ context\ {\isasymrightarrow}\ unit}
wenzelm@20449
   418
  \end{tabular}
wenzelm@20449
   419
  \medskip
wenzelm@20449
   420
wenzelm@20449
   421
  \noindent Here \isa{init} needs to be applied to the current
wenzelm@20449
   422
  theory context once, in order to register the initial setup.  The
wenzelm@20449
   423
  other operations provide access for the particular kind of context
wenzelm@20449
   424
  (theory, proof, or generic context).  Note that this is a safe
wenzelm@20449
   425
  interface: there is no other way to access the corresponding data
wenzelm@20449
   426
  slot within a context.  By keeping these operations private, a
wenzelm@20449
   427
  component may maintain abstract values authentically, without other
wenzelm@20449
   428
  components interfering.%
wenzelm@20447
   429
\end{isamarkuptext}%
wenzelm@20447
   430
\isamarkuptrue%
wenzelm@20447
   431
%
wenzelm@20438
   432
\isamarkupsection{Named entities%
wenzelm@20438
   433
}
wenzelm@20438
   434
\isamarkuptrue%
wenzelm@20438
   435
%
wenzelm@20438
   436
\begin{isamarkuptext}%
wenzelm@20438
   437
Named entities of different kinds (logical constant, type,
wenzelm@20438
   438
type class, theorem, method etc.) live in separate name spaces.  It is
wenzelm@20438
   439
usually clear from the occurrence of a name which kind of entity it
wenzelm@20438
   440
refers to.  For example, proof method \isa{foo} vs.\ theorem
wenzelm@20438
   441
\isa{foo} vs.\ logical constant \isa{foo} are easily
wenzelm@20438
   442
distinguished by means of the syntactic context.  A notable exception
wenzelm@20438
   443
are logical identifiers within a term (\secref{sec:terms}): constants,
wenzelm@20438
   444
fixed variables, and bound variables all share the same identifier
wenzelm@20438
   445
syntax, but are distinguished by their scope.
wenzelm@20438
   446
wenzelm@20438
   447
Each name space is organized as a collection of \emph{qualified
wenzelm@20438
   448
names}, which consist of a sequence of basic name components separated
wenzelm@20438
   449
by dots: \isa{Bar{\isachardot}bar{\isachardot}foo}, \isa{Bar{\isachardot}foo}, and \isa{foo}
wenzelm@20438
   450
are examples for valid qualified names.  Name components are
wenzelm@20438
   451
subdivided into \emph{symbols}, which constitute the smallest textual
wenzelm@20438
   452
unit in Isabelle --- raw characters are normally not encountered
wenzelm@20438
   453
directly.%
wenzelm@20438
   454
\end{isamarkuptext}%
wenzelm@20438
   455
\isamarkuptrue%
wenzelm@20438
   456
%
wenzelm@20438
   457
\isamarkupsubsection{Strings of symbols%
wenzelm@20438
   458
}
wenzelm@20438
   459
\isamarkuptrue%
wenzelm@20438
   460
%
wenzelm@20438
   461
\begin{isamarkuptext}%
wenzelm@20438
   462
Isabelle strings consist of a sequence of
wenzelm@20438
   463
symbols\glossary{Symbol}{The smalles unit of text in Isabelle,
wenzelm@20438
   464
subsumes plain ASCII characters as well as an infinite collection of
wenzelm@20438
   465
named symbols (for greek, math etc.).}, which are either packed as an
wenzelm@20438
   466
actual \isa{string}, or represented as a list.  Each symbol is in
wenzelm@20438
   467
itself a small string of the following form:
wenzelm@20438
   468
wenzelm@20438
   469
\begin{enumerate}
wenzelm@20438
   470
wenzelm@20438
   471
\item either a singleton ASCII character ``\isa{c}'' (with
wenzelm@20438
   472
character code 0--127), for example ``\verb,a,'',
wenzelm@20438
   473
wenzelm@20438
   474
\item or a regular symbol ``\verb,\,\verb,<,\isa{ident}\verb,>,'',
wenzelm@20438
   475
for example ``\verb,\,\verb,<alpha>,'',
wenzelm@20438
   476
wenzelm@20438
   477
\item or a control symbol ``\verb,\,\verb,<^,\isa{ident}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'',
wenzelm@20438
   478
wenzelm@20438
   479
\item or a raw control symbol ``\verb,\,\verb,<^raw:,\isa{{\isasymdots}}\verb,>,'' where ``\isa{{\isasymdots}}'' refers to any
wenzelm@20438
   480
printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or
wenzelm@20438
   481
non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
wenzelm@20438
   482
wenzelm@20438
   483
\item or a numbered raw control symbol ``\verb,\,\verb,<^raw,\isa{nnn}\verb,>, where \isa{nnn} are digits, for example
wenzelm@20438
   484
``\verb,\,\verb,<^raw42>,''.
wenzelm@20438
   485
wenzelm@20438
   486
\end{enumerate}
wenzelm@20438
   487
wenzelm@20438
   488
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@20438
   489
control symbols available, but a certain collection of standard
wenzelm@20438
   490
symbols is treated specifically.  For example,
wenzelm@20438
   491
``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter,
wenzelm@20438
   492
which means it may occur within regular Isabelle identifier syntax.
wenzelm@20438
   493
wenzelm@20438
   494
Output of symbols depends on the print mode (\secref{sec:print-mode}).
wenzelm@20438
   495
For example, the standard {\LaTeX} setup of the Isabelle document
wenzelm@20438
   496
preparation system would present ``\verb,\,\verb,<alpha>,'' as \isa{{\isasymalpha}}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as \isa{\isactrlbold {\isasymalpha}}.
wenzelm@20438
   497
wenzelm@20438
   498
\medskip It is important to note that the character set underlying
wenzelm@20438
   499
Isabelle symbols is plain 7-bit ASCII.  Since 8-bit characters are
wenzelm@20438
   500
passed through transparently, Isabelle may easily process actual
wenzelm@20438
   501
Unicode/UCS data (using the well-known UTF-8 encoding, for example).
wenzelm@20438
   502
Unicode provides its own collection of mathematical symbols, but there
wenzelm@20438
   503
is presently no link to Isabelle's named ones; both kinds of symbols
wenzelm@20438
   504
coexist independently.%
wenzelm@20438
   505
\end{isamarkuptext}%
wenzelm@20438
   506
\isamarkuptrue%
wenzelm@20438
   507
%
wenzelm@20438
   508
\isadelimmlref
wenzelm@20438
   509
%
wenzelm@20438
   510
\endisadelimmlref
wenzelm@20438
   511
%
wenzelm@20438
   512
\isatagmlref
wenzelm@20438
   513
%
wenzelm@20438
   514
\begin{isamarkuptext}%
wenzelm@20438
   515
\begin{mldecls}
wenzelm@20438
   516
  \indexmltype{Symbol.symbol}\verb|type Symbol.symbol| \\
wenzelm@20438
   517
  \indexml{Symbol.explode}\verb|Symbol.explode: string -> Symbol.symbol list| \\
wenzelm@20438
   518
  \indexml{Symbol.is-letter}\verb|Symbol.is_letter: Symbol.symbol -> bool| \\
wenzelm@20438
   519
  \indexml{Symbol.is-digit}\verb|Symbol.is_digit: Symbol.symbol -> bool| \\
wenzelm@20438
   520
  \indexml{Symbol.is-quasi}\verb|Symbol.is_quasi: Symbol.symbol -> bool| \\
wenzelm@20438
   521
  \indexml{Symbol.is-blank}\verb|Symbol.is_blank: Symbol.symbol -> bool| \\
wenzelm@20438
   522
  \indexmltype{Symbol.sym}\verb|type Symbol.sym| \\
wenzelm@20438
   523
  \indexml{Symbol.decode}\verb|Symbol.decode: Symbol.symbol -> Symbol.sym| \\
wenzelm@20438
   524
  \end{mldecls}
wenzelm@20438
   525
wenzelm@20438
   526
  \begin{description}
wenzelm@20438
   527
wenzelm@20438
   528
  \item \verb|Symbol.symbol| represents Isabelle symbols; this type
wenzelm@20438
   529
  is merely an alias for \verb|string|, but emphasizes the
wenzelm@20438
   530
  specific format encountered here.
wenzelm@20438
   531
wenzelm@20447
   532
  \item \verb|Symbol.explode|~\isa{s} produces a symbol list from
wenzelm@20447
   533
  the packed form usually encountered as user input.  This function
wenzelm@20447
   534
  replaces \verb|String.explode| for virtually all purposes of
wenzelm@20447
   535
  manipulating text in Isabelle!  Plain \verb|implode| may be used
wenzelm@20447
   536
  for the reverse operation.
wenzelm@20438
   537
wenzelm@20438
   538
  \item \verb|Symbol.is_letter|, \verb|Symbol.is_digit|, \verb|Symbol.is_quasi|, \verb|Symbol.is_blank| classify certain symbols
wenzelm@20438
   539
  (both ASCII and several named ones) according to fixed syntactic
wenzelm@20438
   540
  convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}.
wenzelm@20438
   541
wenzelm@20438
   542
  \item \verb|Symbol.sym| is a concrete datatype that represents
wenzelm@20438
   543
  the different kinds of symbols explicitly as \verb|Symbol.Char|,
wenzelm@20438
   544
  \verb|Symbol.Sym|, \verb|Symbol.Ctrl|, or \verb|Symbol.Raw|.
wenzelm@20438
   545
wenzelm@20438
   546
  \item \verb|Symbol.decode| converts the string representation of a
wenzelm@20438
   547
  symbol into the explicit datatype version.
wenzelm@20438
   548
wenzelm@20438
   549
  \end{description}%
wenzelm@20438
   550
\end{isamarkuptext}%
wenzelm@20438
   551
\isamarkuptrue%
wenzelm@20438
   552
%
wenzelm@20438
   553
\endisatagmlref
wenzelm@20438
   554
{\isafoldmlref}%
wenzelm@20438
   555
%
wenzelm@20438
   556
\isadelimmlref
wenzelm@20438
   557
%
wenzelm@20438
   558
\endisadelimmlref
wenzelm@20438
   559
%
wenzelm@20438
   560
\isamarkupsubsection{Qualified names and name spaces%
wenzelm@20438
   561
}
wenzelm@20438
   562
\isamarkuptrue%
wenzelm@20438
   563
%
wenzelm@20438
   564
\isadelimFIXME
wenzelm@20438
   565
%
wenzelm@20438
   566
\endisadelimFIXME
wenzelm@20438
   567
%
wenzelm@20438
   568
\isatagFIXME
wenzelm@20438
   569
%
wenzelm@20438
   570
\begin{isamarkuptext}%
wenzelm@20438
   571
Qualified names are constructed according to implicit naming
wenzelm@20438
   572
principles of the present context.
wenzelm@20438
   573
wenzelm@20438
   574
wenzelm@20438
   575
The last component is called \emph{base name}; the remaining prefix of
wenzelm@20438
   576
qualification may be empty.
wenzelm@20438
   577
wenzelm@20438
   578
Some practical conventions help to organize named entities more
wenzelm@20438
   579
systematically:
wenzelm@20438
   580
wenzelm@20438
   581
\begin{itemize}
wenzelm@20438
   582
wenzelm@20438
   583
\item Names are qualified first by the theory name, second by an
wenzelm@20438
   584
optional ``structure''.  For example, a constant \isa{c} declared
wenzelm@20438
   585
as part of a certain structure \isa{b} (say a type definition) in
wenzelm@20438
   586
theory \isa{A} will be named \isa{A{\isachardot}b{\isachardot}c} internally.
wenzelm@20438
   587
wenzelm@20438
   588
\item
wenzelm@20438
   589
wenzelm@20438
   590
\item
wenzelm@20438
   591
wenzelm@20438
   592
\item
wenzelm@20438
   593
wenzelm@20438
   594
\item
wenzelm@20438
   595
wenzelm@20438
   596
\end{itemize}
wenzelm@20438
   597
wenzelm@20438
   598
Names of different kinds of entities are basically independent, but
wenzelm@20438
   599
some practical naming conventions relate them to each other.  For
wenzelm@20438
   600
example, a constant \isa{foo} may be accompanied with theorems
wenzelm@20438
   601
\isa{foo{\isachardot}intro}, \isa{foo{\isachardot}elim}, \isa{foo{\isachardot}simps} etc.  The
wenzelm@20438
   602
same may happen for a type \isa{foo}, which is then apt to cause
wenzelm@20438
   603
clashes in the theorem name space!  To avoid this, we occasionally
wenzelm@20438
   604
follow an additional convention of suffixes that determine the
wenzelm@20438
   605
original kind of entity that a name has been derived.  For example,
wenzelm@20438
   606
constant \isa{foo} is associated with theorem \isa{foo{\isachardot}intro},
wenzelm@20438
   607
type \isa{foo} with theorem \isa{foo{\isacharunderscore}type{\isachardot}intro}, and type
wenzelm@20438
   608
class \isa{foo} with \isa{foo{\isacharunderscore}class{\isachardot}intro}.%
wenzelm@20438
   609
\end{isamarkuptext}%
wenzelm@20438
   610
\isamarkuptrue%
wenzelm@20438
   611
%
wenzelm@20438
   612
\endisatagFIXME
wenzelm@20438
   613
{\isafoldFIXME}%
wenzelm@20438
   614
%
wenzelm@20438
   615
\isadelimFIXME
wenzelm@20438
   616
%
wenzelm@20438
   617
\endisadelimFIXME
wenzelm@20438
   618
%
wenzelm@20438
   619
\isamarkupsection{Structured output%
wenzelm@20438
   620
}
wenzelm@20438
   621
\isamarkuptrue%
wenzelm@20438
   622
%
wenzelm@20438
   623
\isamarkupsubsection{Pretty printing%
wenzelm@20438
   624
}
wenzelm@20438
   625
\isamarkuptrue%
wenzelm@20438
   626
%
wenzelm@20438
   627
\begin{isamarkuptext}%
wenzelm@20438
   628
FIXME%
wenzelm@20438
   629
\end{isamarkuptext}%
wenzelm@20438
   630
\isamarkuptrue%
wenzelm@20438
   631
%
wenzelm@20438
   632
\isamarkupsubsection{Output channels%
wenzelm@20438
   633
}
wenzelm@20438
   634
\isamarkuptrue%
wenzelm@20438
   635
%
wenzelm@20438
   636
\begin{isamarkuptext}%
wenzelm@20438
   637
FIXME%
wenzelm@20438
   638
\end{isamarkuptext}%
wenzelm@20438
   639
\isamarkuptrue%
wenzelm@20438
   640
%
wenzelm@20438
   641
\isamarkupsubsection{Print modes%
wenzelm@20438
   642
}
wenzelm@20438
   643
\isamarkuptrue%
wenzelm@20438
   644
%
wenzelm@20438
   645
\begin{isamarkuptext}%
wenzelm@20438
   646
FIXME%
wenzelm@20438
   647
\end{isamarkuptext}%
wenzelm@20438
   648
\isamarkuptrue%
wenzelm@20438
   649
%
wenzelm@18537
   650
\isadelimtheory
wenzelm@18537
   651
%
wenzelm@18537
   652
\endisadelimtheory
wenzelm@18537
   653
%
wenzelm@18537
   654
\isatagtheory
wenzelm@18537
   655
\isacommand{end}\isamarkupfalse%
wenzelm@18537
   656
%
wenzelm@18537
   657
\endisatagtheory
wenzelm@18537
   658
{\isafoldtheory}%
wenzelm@18537
   659
%
wenzelm@18537
   660
\isadelimtheory
wenzelm@18537
   661
%
wenzelm@18537
   662
\endisadelimtheory
wenzelm@18537
   663
\isanewline
wenzelm@18537
   664
\end{isabellebody}%
wenzelm@18537
   665
%%% Local Variables:
wenzelm@18537
   666
%%% mode: latex
wenzelm@18537
   667
%%% TeX-master: "root"
wenzelm@18537
   668
%%% End: