doc-src/IsarImplementation/Thy/document/prelim.tex
author wenzelm
Sat, 10 May 2008 14:13:20 +0200
changeset 26873 691f35f855cd
parent 26867 6274cf7e2b8e
child 26902 8db1e960d636
permissions -rw-r--r--
updated generated file;
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@20451
    31
A logical context represents the background that is required for
wenzelm@20451
    32
  formulating statements and composing proofs.  It acts as a medium to
wenzelm@20451
    33
  produce formal content, depending on earlier material (declarations,
wenzelm@20451
    34
  results etc.).
wenzelm@18537
    35
wenzelm@20451
    36
  For example, derivations within the Isabelle/Pure logic can be
wenzelm@20451
    37
  described as a judgment \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}, which means 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@20451
    40
  keeping \isa{{\isasymTheta}} and \isa{{\isasymGamma}} separate: theories can be
wenzelm@20451
    41
  liberal about supporting type constructors and schematic
wenzelm@20451
    42
  polymorphism of constants and axioms, while the inner calculus of
wenzelm@20451
    43
  \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} is strictly limited to Simple Type Theory (with
wenzelm@20451
    44
  fixed type variables in the assumptions).
wenzelm@18537
    45
wenzelm@20429
    46
  \medskip Contexts and derivations are linked by the following key
wenzelm@20429
    47
  principles:
wenzelm@18537
    48
wenzelm@20429
    49
  \begin{itemize}
wenzelm@18537
    50
wenzelm@20429
    51
  \item Transfer: monotonicity of derivations admits results to be
wenzelm@20451
    52
  transferred into a \emph{larger} context, i.e.\ \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}} implies \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\isactrlsub {\isacharprime}\ {\isasymphi}} for contexts \isa{{\isasymTheta}{\isacharprime}\ {\isasymsupseteq}\ {\isasymTheta}} and \isa{{\isasymGamma}{\isacharprime}\ {\isasymsupseteq}\ {\isasymGamma}}.
wenzelm@18537
    53
wenzelm@20429
    54
  \item Export: discharge of hypotheses admits results to be exported
wenzelm@20451
    55
  into a \emph{smaller} context, i.e.\ \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}
wenzelm@20451
    56
  implies \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymDelta}\ {\isasymLongrightarrow}\ {\isasymphi}} where \isa{{\isasymGamma}{\isacharprime}\ {\isasymsupseteq}\ {\isasymGamma}} and
wenzelm@20451
    57
  \isa{{\isasymDelta}\ {\isacharequal}\ {\isasymGamma}{\isacharprime}\ {\isacharminus}\ {\isasymGamma}}.  Note that \isa{{\isasymTheta}} remains unchanged here,
wenzelm@20451
    58
  only the \isa{{\isasymGamma}} part is affected.
wenzelm@18537
    59
wenzelm@20429
    60
  \end{itemize}
wenzelm@18537
    61
wenzelm@20451
    62
  \medskip By modeling the main characteristics of the primitive
wenzelm@20451
    63
  \isa{{\isasymTheta}} and \isa{{\isasymGamma}} above, and abstracting over any
wenzelm@20451
    64
  particular logical content, we arrive at the fundamental notions of
wenzelm@20451
    65
  \emph{theory context} and \emph{proof context} in Isabelle/Isar.
wenzelm@20451
    66
  These implement a certain policy to manage arbitrary \emph{context
wenzelm@20451
    67
  data}.  There is a strongly-typed mechanism to declare new kinds of
wenzelm@20429
    68
  data at compile time.
wenzelm@18537
    69
wenzelm@20451
    70
  The internal bootstrap process of Isabelle/Pure eventually reaches a
wenzelm@20451
    71
  stage where certain data slots provide the logical content of \isa{{\isasymTheta}} and \isa{{\isasymGamma}} sketched above, but this does not stop there!
wenzelm@20451
    72
  Various additional data slots support all kinds of mechanisms that
wenzelm@20451
    73
  are not necessarily part of the core logic.
wenzelm@18537
    74
wenzelm@20429
    75
  For example, there would be data for canonical introduction and
wenzelm@20429
    76
  elimination rules for arbitrary operators (depending on the
wenzelm@20429
    77
  object-logic and application), which enables users to perform
wenzelm@20451
    78
  standard proof steps implicitly (cf.\ the \isa{rule} method
wenzelm@20451
    79
  \cite{isabelle-isar-ref}).
wenzelm@20429
    80
wenzelm@20451
    81
  \medskip Thus Isabelle/Isar is able to bring forth more and more
wenzelm@20451
    82
  concepts successively.  In particular, an object-logic like
wenzelm@20451
    83
  Isabelle/HOL continues the Isabelle/Pure setup by adding specific
wenzelm@20451
    84
  components for automated reasoning (classical reasoner, tableau
wenzelm@20451
    85
  prover, structured induction etc.) and derived specification
wenzelm@20451
    86
  mechanisms (inductive predicates, recursive functions etc.).  All of
wenzelm@20451
    87
  this is ultimately based on the generic data management by theory
wenzelm@20451
    88
  and proof contexts introduced here.%
wenzelm@18537
    89
\end{isamarkuptext}%
wenzelm@18537
    90
\isamarkuptrue%
wenzelm@18537
    91
%
wenzelm@18537
    92
\isamarkupsubsection{Theory context \label{sec:context-theory}%
wenzelm@18537
    93
}
wenzelm@18537
    94
\isamarkuptrue%
wenzelm@18537
    95
%
wenzelm@18537
    96
\begin{isamarkuptext}%
wenzelm@20447
    97
\glossary{Theory}{FIXME}
wenzelm@20447
    98
wenzelm@20451
    99
  A \emph{theory} is a data container with explicit named and unique
wenzelm@20451
   100
  identifier.  Theories are related by a (nominal) sub-theory
wenzelm@20451
   101
  relation, which corresponds to the dependency graph of the original
wenzelm@20451
   102
  construction; each theory is derived from a certain sub-graph of
wenzelm@20451
   103
  ancestor theories.
wenzelm@20451
   104
wenzelm@20451
   105
  The \isa{merge} operation produces the least upper bound of two
wenzelm@20451
   106
  theories, which actually degenerates into absorption of one theory
wenzelm@20451
   107
  into the other (due to the nominal sub-theory relation).
wenzelm@18537
   108
wenzelm@20429
   109
  The \isa{begin} operation starts a new theory by importing
wenzelm@20429
   110
  several parent theories and entering a special \isa{draft} mode,
wenzelm@20429
   111
  which is sustained until the final \isa{end} operation.  A draft
wenzelm@20451
   112
  theory acts like a linear type, where updates invalidate earlier
wenzelm@20451
   113
  versions.  An invalidated draft is called ``stale''.
wenzelm@20429
   114
wenzelm@20447
   115
  The \isa{checkpoint} operation produces an intermediate stepping
wenzelm@20451
   116
  stone that will survive the next update: both the original and the
wenzelm@20451
   117
  changed theory remain valid and are related by the sub-theory
wenzelm@20451
   118
  relation.  Checkpointing essentially recovers purely functional
wenzelm@20451
   119
  theory values, at the expense of some extra internal bookkeeping.
wenzelm@20429
   120
wenzelm@20447
   121
  The \isa{copy} operation produces an auxiliary version that has
wenzelm@20447
   122
  the same data content, but is unrelated to the original: updates of
wenzelm@20447
   123
  the copy do not affect the original, neither does the sub-theory
wenzelm@20447
   124
  relation hold.
wenzelm@20447
   125
wenzelm@20447
   126
  \medskip The example in \figref{fig:ex-theory} below shows a theory
wenzelm@20451
   127
  graph derived from \isa{Pure}, with theory \isa{Length}
wenzelm@20451
   128
  importing \isa{Nat} and \isa{List}.  The body of \isa{Length} consists of a sequence of updates, working mostly on
wenzelm@20451
   129
  drafts.  Intermediate checkpoints may occur as well, due to the
wenzelm@20451
   130
  history mechanism provided by the Isar top-level, cf.\
wenzelm@20451
   131
  \secref{sec:isar-toplevel}.
wenzelm@20447
   132
wenzelm@20447
   133
  \begin{figure}[htb]
wenzelm@20447
   134
  \begin{center}
wenzelm@20429
   135
  \begin{tabular}{rcccl}
wenzelm@20447
   136
        &            & \isa{Pure} \\
wenzelm@20447
   137
        &            & \isa{{\isasymdown}} \\
wenzelm@20447
   138
        &            & \isa{FOL} \\
wenzelm@18537
   139
        & $\swarrow$ &              & $\searrow$ & \\
wenzelm@21862
   140
  \isa{Nat} &    &              &            & \isa{List} \\
wenzelm@18537
   141
        & $\searrow$ &              & $\swarrow$ \\
wenzelm@20447
   142
        &            & \isa{Length} \\
wenzelm@26867
   143
        &            & \multicolumn{3}{l}{~~\mbox{\isa{\isakeyword{imports}}}} \\
wenzelm@26867
   144
        &            & \multicolumn{3}{l}{~~\mbox{\isa{\isakeyword{begin}}}} \\
wenzelm@18537
   145
        &            & $\vdots$~~ \\
wenzelm@20447
   146
        &            & \isa{{\isasymbullet}}~~ \\
wenzelm@20447
   147
        &            & $\vdots$~~ \\
wenzelm@20447
   148
        &            & \isa{{\isasymbullet}}~~ \\
wenzelm@20447
   149
        &            & $\vdots$~~ \\
wenzelm@26867
   150
        &            & \multicolumn{3}{l}{~~\mbox{\isa{\isacommand{end}}}} \\
wenzelm@20429
   151
  \end{tabular}
wenzelm@20451
   152
  \caption{A theory definition depending on ancestors}\label{fig:ex-theory}
wenzelm@20447
   153
  \end{center}
wenzelm@20451
   154
  \end{figure}
wenzelm@20451
   155
wenzelm@20451
   156
  \medskip There is a separate notion of \emph{theory reference} for
wenzelm@20451
   157
  maintaining a live link to an evolving theory context: updates on
wenzelm@20490
   158
  drafts are propagated automatically.  Dynamic updating stops after
wenzelm@20490
   159
  an explicit \isa{end} only.
wenzelm@20451
   160
wenzelm@20451
   161
  Derived entities may store a theory reference in order to indicate
wenzelm@20451
   162
  the context they belong to.  This implicitly assumes monotonic
wenzelm@20451
   163
  reasoning, because the referenced context may become larger without
wenzelm@20451
   164
  further notice.%
wenzelm@18537
   165
\end{isamarkuptext}%
wenzelm@18537
   166
\isamarkuptrue%
wenzelm@18537
   167
%
wenzelm@20430
   168
\isadelimmlref
wenzelm@20430
   169
%
wenzelm@20430
   170
\endisadelimmlref
wenzelm@20430
   171
%
wenzelm@20430
   172
\isatagmlref
wenzelm@20430
   173
%
wenzelm@20430
   174
\begin{isamarkuptext}%
wenzelm@20447
   175
\begin{mldecls}
wenzelm@20447
   176
  \indexmltype{theory}\verb|type theory| \\
wenzelm@20447
   177
  \indexml{Theory.subthy}\verb|Theory.subthy: theory * theory -> bool| \\
wenzelm@20447
   178
  \indexml{Theory.merge}\verb|Theory.merge: theory * theory -> theory| \\
wenzelm@20447
   179
  \indexml{Theory.checkpoint}\verb|Theory.checkpoint: theory -> theory| \\
wenzelm@20547
   180
  \indexml{Theory.copy}\verb|Theory.copy: theory -> theory| \\
wenzelm@20547
   181
  \end{mldecls}
wenzelm@20547
   182
  \begin{mldecls}
wenzelm@26854
   183
  \indexmltype{theory\_ref}\verb|type theory_ref| \\
wenzelm@20447
   184
  \indexml{Theory.deref}\verb|Theory.deref: theory_ref -> theory| \\
wenzelm@26854
   185
  \indexml{Theory.check\_thy}\verb|Theory.check_thy: theory -> theory_ref| \\
wenzelm@20447
   186
  \end{mldecls}
wenzelm@20447
   187
wenzelm@20447
   188
  \begin{description}
wenzelm@20447
   189
wenzelm@20451
   190
  \item \verb|theory| represents theory contexts.  This is
wenzelm@20451
   191
  essentially a linear type!  Most operations destroy the original
wenzelm@20451
   192
  version, which then becomes ``stale''.
wenzelm@20447
   193
wenzelm@20447
   194
  \item \verb|Theory.subthy|~\isa{{\isacharparenleft}thy\isactrlsub {\isadigit{1}}{\isacharcomma}\ thy\isactrlsub {\isadigit{2}}{\isacharparenright}}
wenzelm@20447
   195
  compares theories according to the inherent graph structure of the
wenzelm@20447
   196
  construction.  This sub-theory relation is a nominal approximation
wenzelm@20447
   197
  of inclusion (\isa{{\isasymsubseteq}}) of the corresponding content.
wenzelm@20447
   198
wenzelm@20447
   199
  \item \verb|Theory.merge|~\isa{{\isacharparenleft}thy\isactrlsub {\isadigit{1}}{\isacharcomma}\ thy\isactrlsub {\isadigit{2}}{\isacharparenright}}
wenzelm@20447
   200
  absorbs one theory into the other.  This fails for unrelated
wenzelm@20447
   201
  theories!
wenzelm@20447
   202
wenzelm@20447
   203
  \item \verb|Theory.checkpoint|~\isa{thy} produces a safe
wenzelm@20447
   204
  stepping stone in the linear development of \isa{thy}.  The next
wenzelm@20447
   205
  update will result in two related, valid theories.
wenzelm@20447
   206
wenzelm@20451
   207
  \item \verb|Theory.copy|~\isa{thy} produces a variant of \isa{thy} that holds a copy of the same data.  The result is not
wenzelm@20451
   208
  related to the original; the original is unchanched.
wenzelm@20447
   209
wenzelm@20451
   210
  \item \verb|theory_ref| represents a sliding reference to an
wenzelm@20451
   211
  always valid theory; updates on the original are propagated
wenzelm@20447
   212
  automatically.
wenzelm@20447
   213
wenzelm@24138
   214
  \item \verb|Theory.deref|~\isa{thy{\isacharunderscore}ref} turns a \verb|theory_ref| into an \verb|theory| value.  As the referenced
wenzelm@24138
   215
  theory evolves monotonically over time, later invocations of \verb|Theory.deref| may refer to a larger context.
wenzelm@24138
   216
wenzelm@24138
   217
  \item \verb|Theory.check_thy|~\isa{thy} produces a \verb|theory_ref| from a valid \verb|theory| value.
wenzelm@20447
   218
wenzelm@20447
   219
  \end{description}%
wenzelm@20430
   220
\end{isamarkuptext}%
wenzelm@20430
   221
\isamarkuptrue%
wenzelm@20430
   222
%
wenzelm@20430
   223
\endisatagmlref
wenzelm@20430
   224
{\isafoldmlref}%
wenzelm@20430
   225
%
wenzelm@20430
   226
\isadelimmlref
wenzelm@20430
   227
%
wenzelm@20430
   228
\endisadelimmlref
wenzelm@20430
   229
%
wenzelm@18537
   230
\isamarkupsubsection{Proof context \label{sec:context-proof}%
wenzelm@18537
   231
}
wenzelm@18537
   232
\isamarkuptrue%
wenzelm@18537
   233
%
wenzelm@18537
   234
\begin{isamarkuptext}%
wenzelm@20447
   235
\glossary{Proof context}{The static context of a structured proof,
wenzelm@20447
   236
  acts like a local ``theory'' of the current portion of Isar proof
wenzelm@20447
   237
  text, generalizes the idea of local hypotheses \isa{{\isasymGamma}} in
wenzelm@20447
   238
  judgments \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} of natural deduction calculi.  There is a
wenzelm@20447
   239
  generic notion of introducing and discharging hypotheses.
wenzelm@20447
   240
  Arbritrary auxiliary context data may be adjoined.}
wenzelm@20429
   241
wenzelm@20447
   242
  A proof context is a container for pure data with a back-reference
wenzelm@20449
   243
  to the theory it belongs to.  The \isa{init} operation creates a
wenzelm@20451
   244
  proof context from a given theory.  Modifications to draft theories
wenzelm@20451
   245
  are propagated to the proof context as usual, but there is also an
wenzelm@20451
   246
  explicit \isa{transfer} operation to force resynchronization
wenzelm@20451
   247
  with more substantial updates to the underlying theory.  The actual
wenzelm@20451
   248
  context data does not require any special bookkeeping, thanks to the
wenzelm@20451
   249
  lack of destructive features.
wenzelm@20429
   250
wenzelm@20447
   251
  Entities derived in a proof context need to record inherent logical
wenzelm@20447
   252
  requirements explicitly, since there is no separate context
wenzelm@20447
   253
  identification as for theories.  For example, hypotheses used in
wenzelm@20451
   254
  primitive derivations (cf.\ \secref{sec:thms}) are recorded
wenzelm@20447
   255
  separately within the sequent \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}}, just to make double
wenzelm@20447
   256
  sure.  Results could still leak into an alien proof context do to
wenzelm@20447
   257
  programming errors, but Isabelle/Isar includes some extra validity
haftmann@22504
   258
  checks in critical positions, notably at the end of a sub-proof.
wenzelm@20429
   259
wenzelm@20451
   260
  Proof contexts may be manipulated arbitrarily, although the common
wenzelm@20451
   261
  discipline is to follow block structure as a mental model: a given
wenzelm@20451
   262
  context is extended consecutively, and results are exported back
wenzelm@20451
   263
  into the original context.  Note that the Isar proof states model
wenzelm@20451
   264
  block-structured reasoning explicitly, using a stack of proof
wenzelm@20451
   265
  contexts internally, cf.\ \secref{sec:isar-proof-state}.%
wenzelm@18537
   266
\end{isamarkuptext}%
wenzelm@18537
   267
\isamarkuptrue%
wenzelm@18537
   268
%
wenzelm@20430
   269
\isadelimmlref
wenzelm@20430
   270
%
wenzelm@20430
   271
\endisadelimmlref
wenzelm@20430
   272
%
wenzelm@20430
   273
\isatagmlref
wenzelm@20430
   274
%
wenzelm@20430
   275
\begin{isamarkuptext}%
wenzelm@20449
   276
\begin{mldecls}
wenzelm@20449
   277
  \indexmltype{Proof.context}\verb|type Proof.context| \\
wenzelm@20449
   278
  \indexml{ProofContext.init}\verb|ProofContext.init: theory -> Proof.context| \\
wenzelm@26854
   279
  \indexml{ProofContext.theory\_of}\verb|ProofContext.theory_of: Proof.context -> theory| \\
wenzelm@20449
   280
  \indexml{ProofContext.transfer}\verb|ProofContext.transfer: theory -> Proof.context -> Proof.context| \\
wenzelm@20449
   281
  \end{mldecls}
wenzelm@20449
   282
wenzelm@20449
   283
  \begin{description}
wenzelm@20449
   284
wenzelm@20449
   285
  \item \verb|Proof.context| represents proof contexts.  Elements
wenzelm@20449
   286
  of this type are essentially pure values, with a sliding reference
wenzelm@20449
   287
  to the background theory.
wenzelm@20449
   288
wenzelm@20449
   289
  \item \verb|ProofContext.init|~\isa{thy} produces a proof context
wenzelm@20449
   290
  derived from \isa{thy}, initializing all data.
wenzelm@20449
   291
wenzelm@20449
   292
  \item \verb|ProofContext.theory_of|~\isa{ctxt} selects the
wenzelm@20451
   293
  background theory from \isa{ctxt}, dereferencing its internal
wenzelm@20451
   294
  \verb|theory_ref|.
wenzelm@20449
   295
wenzelm@20449
   296
  \item \verb|ProofContext.transfer|~\isa{thy\ ctxt} promotes the
wenzelm@20449
   297
  background theory of \isa{ctxt} to the super theory \isa{thy}.
wenzelm@20449
   298
wenzelm@20449
   299
  \end{description}%
wenzelm@20430
   300
\end{isamarkuptext}%
wenzelm@20430
   301
\isamarkuptrue%
wenzelm@20430
   302
%
wenzelm@20430
   303
\endisatagmlref
wenzelm@20430
   304
{\isafoldmlref}%
wenzelm@20430
   305
%
wenzelm@20430
   306
\isadelimmlref
wenzelm@20430
   307
%
wenzelm@20430
   308
\endisadelimmlref
wenzelm@20430
   309
%
wenzelm@20451
   310
\isamarkupsubsection{Generic contexts \label{sec:generic-context}%
wenzelm@20429
   311
}
wenzelm@20429
   312
\isamarkuptrue%
wenzelm@20429
   313
%
wenzelm@20430
   314
\begin{isamarkuptext}%
wenzelm@20449
   315
A generic context is the disjoint sum of either a theory or proof
wenzelm@20451
   316
  context.  Occasionally, this enables uniform treatment of generic
wenzelm@20450
   317
  context data, typically extra-logical information.  Operations on
wenzelm@20449
   318
  generic contexts include the usual injections, partial selections,
wenzelm@20449
   319
  and combinators for lifting operations on either component of the
wenzelm@20449
   320
  disjoint sum.
wenzelm@20449
   321
wenzelm@20449
   322
  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@20451
   323
  can always be selected from the sum, while a proof context might
wenzelm@20451
   324
  have to be constructed by an ad-hoc \isa{init} operation.%
wenzelm@20430
   325
\end{isamarkuptext}%
wenzelm@20430
   326
\isamarkuptrue%
wenzelm@20430
   327
%
wenzelm@20430
   328
\isadelimmlref
wenzelm@20430
   329
%
wenzelm@20430
   330
\endisadelimmlref
wenzelm@20430
   331
%
wenzelm@20430
   332
\isatagmlref
wenzelm@20430
   333
%
wenzelm@20430
   334
\begin{isamarkuptext}%
wenzelm@20449
   335
\begin{mldecls}
wenzelm@20449
   336
  \indexmltype{Context.generic}\verb|type Context.generic| \\
wenzelm@26854
   337
  \indexml{Context.theory\_of}\verb|Context.theory_of: Context.generic -> theory| \\
wenzelm@26854
   338
  \indexml{Context.proof\_of}\verb|Context.proof_of: Context.generic -> Proof.context| \\
wenzelm@20449
   339
  \end{mldecls}
wenzelm@20449
   340
wenzelm@20449
   341
  \begin{description}
wenzelm@20449
   342
wenzelm@20451
   343
  \item \verb|Context.generic| is the direct sum of \verb|theory| and \verb|Proof.context|, with the datatype
wenzelm@20451
   344
  constructors \verb|Context.Theory| and \verb|Context.Proof|.
wenzelm@20449
   345
wenzelm@20449
   346
  \item \verb|Context.theory_of|~\isa{context} always produces a
wenzelm@20449
   347
  theory from the generic \isa{context}, using \verb|ProofContext.theory_of| as required.
wenzelm@20449
   348
wenzelm@20449
   349
  \item \verb|Context.proof_of|~\isa{context} always produces a
wenzelm@20451
   350
  proof context from the generic \isa{context}, using \verb|ProofContext.init| as required (note that this re-initializes the
wenzelm@20451
   351
  context data with each invocation).
wenzelm@20449
   352
wenzelm@20449
   353
  \end{description}%
wenzelm@20430
   354
\end{isamarkuptext}%
wenzelm@20430
   355
\isamarkuptrue%
wenzelm@20430
   356
%
wenzelm@20430
   357
\endisatagmlref
wenzelm@20430
   358
{\isafoldmlref}%
wenzelm@20430
   359
%
wenzelm@20430
   360
\isadelimmlref
wenzelm@20430
   361
%
wenzelm@20430
   362
\endisadelimmlref
wenzelm@20430
   363
%
wenzelm@20477
   364
\isamarkupsubsection{Context data \label{sec:context-data}%
wenzelm@20447
   365
}
wenzelm@20447
   366
\isamarkuptrue%
wenzelm@20447
   367
%
wenzelm@20447
   368
\begin{isamarkuptext}%
wenzelm@20451
   369
The main purpose of theory and proof contexts is to manage arbitrary
wenzelm@20451
   370
  data.  New data types can be declared incrementally at compile time.
wenzelm@20451
   371
  There are separate declaration mechanisms for any of the three kinds
wenzelm@20451
   372
  of contexts: theory, proof, generic.
wenzelm@20449
   373
wenzelm@20449
   374
  \paragraph{Theory data} may refer to destructive entities, which are
wenzelm@20451
   375
  maintained in direct correspondence to the linear evolution of
wenzelm@20451
   376
  theory values, including explicit copies.\footnote{Most existing
wenzelm@20451
   377
  instances of destructive theory data are merely historical relics
wenzelm@20451
   378
  (e.g.\ the destructive theorem storage, and destructive hints for
wenzelm@20451
   379
  the Simplifier and Classical rules).}  A theory data declaration
wenzelm@22870
   380
  needs to implement the following SML signature:
wenzelm@20449
   381
wenzelm@20449
   382
  \medskip
wenzelm@20449
   383
  \begin{tabular}{ll}
wenzelm@22870
   384
  \isa{{\isasymtype}\ T} & representing type \\
wenzelm@22870
   385
  \isa{{\isasymval}\ empty{\isacharcolon}\ T} & empty default value \\
wenzelm@22870
   386
  \isa{{\isasymval}\ copy{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & refresh impure data \\
wenzelm@22870
   387
  \isa{{\isasymval}\ extend{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & re-initialize on import \\
wenzelm@22870
   388
  \isa{{\isasymval}\ merge{\isacharcolon}\ T\ {\isasymtimes}\ T\ {\isasymrightarrow}\ T} & join on import \\
wenzelm@20449
   389
  \end{tabular}
wenzelm@20449
   390
  \medskip
wenzelm@20449
   391
wenzelm@22870
   392
  \noindent The \isa{empty} value acts as initial default for
wenzelm@22870
   393
  \emph{any} theory that does not declare actual data content; \isa{copy} maintains persistent integrity for impure data, it is just
wenzelm@22870
   394
  the identity for pure values; \isa{extend} is acts like a
wenzelm@22870
   395
  unitary version of \isa{merge}, both operations should also
wenzelm@22870
   396
  include the functionality of \isa{copy} for impure data.
wenzelm@20449
   397
wenzelm@20451
   398
  \paragraph{Proof context data} is purely functional.  A declaration
wenzelm@22870
   399
  needs to implement the following SML signature:
wenzelm@20449
   400
wenzelm@20449
   401
  \medskip
wenzelm@20449
   402
  \begin{tabular}{ll}
wenzelm@22870
   403
  \isa{{\isasymtype}\ T} & representing type \\
wenzelm@22870
   404
  \isa{{\isasymval}\ init{\isacharcolon}\ theory\ {\isasymrightarrow}\ T} & produce initial value \\
wenzelm@20449
   405
  \end{tabular}
wenzelm@20449
   406
  \medskip
wenzelm@20449
   407
wenzelm@20449
   408
  \noindent The \isa{init} operation is supposed to produce a pure
wenzelm@22870
   409
  value from the given background theory.
wenzelm@20449
   410
wenzelm@20451
   411
  \paragraph{Generic data} provides a hybrid interface for both theory
wenzelm@20451
   412
  and proof data.  The declaration is essentially the same as for
wenzelm@22870
   413
  (pure) theory data, without \isa{copy}.  The \isa{init}
wenzelm@22870
   414
  operation for proof contexts merely selects the current data value
wenzelm@22870
   415
  from the background theory.
wenzelm@20449
   416
wenzelm@22870
   417
  \bigskip A data declaration of type \isa{T} results in the
wenzelm@22870
   418
  following interface:
wenzelm@20449
   419
wenzelm@20449
   420
  \medskip
wenzelm@20449
   421
  \begin{tabular}{ll}
wenzelm@20449
   422
  \isa{init{\isacharcolon}\ theory\ {\isasymrightarrow}\ theory} \\
wenzelm@20449
   423
  \isa{get{\isacharcolon}\ context\ {\isasymrightarrow}\ T} \\
wenzelm@20449
   424
  \isa{put{\isacharcolon}\ T\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
wenzelm@20449
   425
  \isa{map{\isacharcolon}\ {\isacharparenleft}T\ {\isasymrightarrow}\ T{\isacharparenright}\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
wenzelm@20449
   426
  \end{tabular}
wenzelm@20449
   427
  \medskip
wenzelm@20449
   428
wenzelm@22870
   429
  \noindent Here \isa{init} is only applicable to impure theory
wenzelm@22870
   430
  data to install a fresh copy persistently (destructive update on
wenzelm@22870
   431
  uninitialized has no permanent effect).  The other operations provide
wenzelm@22870
   432
  access for the particular kind of context (theory, proof, or generic
wenzelm@22870
   433
  context).  Note that this is a safe interface: there is no other way
wenzelm@22870
   434
  to access the corresponding data slot of a context.  By keeping
wenzelm@22870
   435
  these operations private, a component may maintain abstract values
wenzelm@22870
   436
  authentically, without other components interfering.%
wenzelm@20447
   437
\end{isamarkuptext}%
wenzelm@20447
   438
\isamarkuptrue%
wenzelm@20447
   439
%
wenzelm@20450
   440
\isadelimmlref
wenzelm@20450
   441
%
wenzelm@20450
   442
\endisadelimmlref
wenzelm@20450
   443
%
wenzelm@20450
   444
\isatagmlref
wenzelm@20450
   445
%
wenzelm@20450
   446
\begin{isamarkuptext}%
wenzelm@20450
   447
\begin{mldecls}
wenzelm@20450
   448
  \indexmlfunctor{TheoryDataFun}\verb|functor TheoryDataFun| \\
wenzelm@20450
   449
  \indexmlfunctor{ProofDataFun}\verb|functor ProofDataFun| \\
wenzelm@20450
   450
  \indexmlfunctor{GenericDataFun}\verb|functor GenericDataFun| \\
wenzelm@20450
   451
  \end{mldecls}
wenzelm@20450
   452
wenzelm@20450
   453
  \begin{description}
wenzelm@20450
   454
wenzelm@20450
   455
  \item \verb|TheoryDataFun|\isa{{\isacharparenleft}spec{\isacharparenright}} declares data for
wenzelm@20450
   456
  type \verb|theory| according to the specification provided as
wenzelm@20451
   457
  argument structure.  The resulting structure provides data init and
wenzelm@20451
   458
  access operations as described above.
wenzelm@20450
   459
wenzelm@20471
   460
  \item \verb|ProofDataFun|\isa{{\isacharparenleft}spec{\isacharparenright}} is analogous to
wenzelm@20471
   461
  \verb|TheoryDataFun| for type \verb|Proof.context|.
wenzelm@20450
   462
wenzelm@20471
   463
  \item \verb|GenericDataFun|\isa{{\isacharparenleft}spec{\isacharparenright}} is analogous to
wenzelm@20471
   464
  \verb|TheoryDataFun| for type \verb|Context.generic|.
wenzelm@20450
   465
wenzelm@20450
   466
  \end{description}%
wenzelm@20450
   467
\end{isamarkuptext}%
wenzelm@20450
   468
\isamarkuptrue%
wenzelm@20450
   469
%
wenzelm@20450
   470
\endisatagmlref
wenzelm@20450
   471
{\isafoldmlref}%
wenzelm@20450
   472
%
wenzelm@20450
   473
\isadelimmlref
wenzelm@20450
   474
%
wenzelm@20450
   475
\endisadelimmlref
wenzelm@20450
   476
%
wenzelm@26873
   477
\isamarkupsection{Names \label{sec:names}%
wenzelm@20438
   478
}
wenzelm@20438
   479
\isamarkuptrue%
wenzelm@20438
   480
%
wenzelm@20438
   481
\begin{isamarkuptext}%
wenzelm@20477
   482
In principle, a name is just a string, but there are various
wenzelm@20490
   483
  convention for encoding additional structure.  For example, ``\isa{Foo{\isachardot}bar{\isachardot}baz}'' is considered as a qualified name consisting of
wenzelm@20490
   484
  three basic name components.  The individual constituents of a name
wenzelm@20490
   485
  may have further substructure, e.g.\ the string
wenzelm@20490
   486
  ``\verb,\,\verb,<alpha>,'' encodes as a single symbol.%
wenzelm@20438
   487
\end{isamarkuptext}%
wenzelm@20438
   488
\isamarkuptrue%
wenzelm@20438
   489
%
wenzelm@20438
   490
\isamarkupsubsection{Strings of symbols%
wenzelm@20438
   491
}
wenzelm@20438
   492
\isamarkuptrue%
wenzelm@20438
   493
%
wenzelm@20438
   494
\begin{isamarkuptext}%
wenzelm@20477
   495
\glossary{Symbol}{The smallest unit of text in Isabelle, subsumes
wenzelm@20477
   496
  plain ASCII characters as well as an infinite collection of named
wenzelm@20477
   497
  symbols (for greek, math etc.).}
wenzelm@20471
   498
wenzelm@20477
   499
  A \emph{symbol} constitutes the smallest textual unit in Isabelle
wenzelm@20490
   500
  --- raw characters are normally not encountered at all.  Isabelle
wenzelm@20490
   501
  strings consist of a sequence of symbols, represented as a packed
wenzelm@20490
   502
  string or a list of strings.  Each symbol is in itself a small
wenzelm@20490
   503
  string, which has either one of the following forms:
wenzelm@20438
   504
wenzelm@20451
   505
  \begin{enumerate}
wenzelm@20438
   506
wenzelm@20490
   507
  \item a single ASCII character ``\isa{c}'', for example
wenzelm@20490
   508
  ``\verb,a,'',
wenzelm@20438
   509
wenzelm@20490
   510
  \item a regular symbol ``\verb,\,\verb,<,\isa{ident}\verb,>,'',
wenzelm@20477
   511
  for example ``\verb,\,\verb,<alpha>,'',
wenzelm@20438
   512
wenzelm@20490
   513
  \item a control symbol ``\verb,\,\verb,<^,\isa{ident}\verb,>,'',
wenzelm@20477
   514
  for example ``\verb,\,\verb,<^bold>,'',
wenzelm@20438
   515
wenzelm@20490
   516
  \item a raw symbol ``\verb,\,\verb,<^raw:,\isa{text}\verb,>,''
wenzelm@20490
   517
  where \isa{text} constists of printable characters excluding
wenzelm@20477
   518
  ``\verb,.,'' and ``\verb,>,'', for example
wenzelm@20477
   519
  ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
wenzelm@20438
   520
wenzelm@20490
   521
  \item a numbered raw control symbol ``\verb,\,\verb,<^raw,\isa{n}\verb,>, where \isa{n} consists of digits, for example
wenzelm@20451
   522
  ``\verb,\,\verb,<^raw42>,''.
wenzelm@20438
   523
wenzelm@20451
   524
  \end{enumerate}
wenzelm@20438
   525
wenzelm@20477
   526
  \noindent 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
wenzelm@20477
   527
  regular symbols and control symbols, but a fixed collection of
wenzelm@20477
   528
  standard symbols is treated specifically.  For example,
wenzelm@20490
   529
  ``\verb,\,\verb,<alpha>,'' is classified as a letter, which means it
wenzelm@20490
   530
  may occur within regular Isabelle identifiers.
wenzelm@20438
   531
wenzelm@20490
   532
  Since the character set underlying Isabelle symbols is 7-bit ASCII
wenzelm@20490
   533
  and 8-bit characters are passed through transparently, Isabelle may
wenzelm@20490
   534
  also process Unicode/UCS data in UTF-8 encoding.  Unicode provides
wenzelm@20490
   535
  its own collection of mathematical symbols, but there is no built-in
wenzelm@20490
   536
  link to the standard collection of Isabelle.
wenzelm@20477
   537
wenzelm@20477
   538
  \medskip Output of Isabelle symbols depends on the print mode
wenzelm@20477
   539
  (\secref{FIXME}).  For example, the standard {\LaTeX} setup of the
wenzelm@20477
   540
  Isabelle document preparation system would present
wenzelm@20451
   541
  ``\verb,\,\verb,<alpha>,'' as \isa{{\isasymalpha}}, and
wenzelm@20477
   542
  ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as \isa{\isactrlbold {\isasymalpha}}.%
wenzelm@20438
   543
\end{isamarkuptext}%
wenzelm@20438
   544
\isamarkuptrue%
wenzelm@20438
   545
%
wenzelm@20438
   546
\isadelimmlref
wenzelm@20438
   547
%
wenzelm@20438
   548
\endisadelimmlref
wenzelm@20438
   549
%
wenzelm@20438
   550
\isatagmlref
wenzelm@20438
   551
%
wenzelm@20438
   552
\begin{isamarkuptext}%
wenzelm@20438
   553
\begin{mldecls}
wenzelm@20438
   554
  \indexmltype{Symbol.symbol}\verb|type Symbol.symbol| \\
wenzelm@20438
   555
  \indexml{Symbol.explode}\verb|Symbol.explode: string -> Symbol.symbol list| \\
wenzelm@26854
   556
  \indexml{Symbol.is\_letter}\verb|Symbol.is_letter: Symbol.symbol -> bool| \\
wenzelm@26854
   557
  \indexml{Symbol.is\_digit}\verb|Symbol.is_digit: Symbol.symbol -> bool| \\
wenzelm@26854
   558
  \indexml{Symbol.is\_quasi}\verb|Symbol.is_quasi: Symbol.symbol -> bool| \\
wenzelm@26854
   559
  \indexml{Symbol.is\_blank}\verb|Symbol.is_blank: Symbol.symbol -> bool| \\
wenzelm@20547
   560
  \end{mldecls}
wenzelm@20547
   561
  \begin{mldecls}
wenzelm@20438
   562
  \indexmltype{Symbol.sym}\verb|type Symbol.sym| \\
wenzelm@20438
   563
  \indexml{Symbol.decode}\verb|Symbol.decode: Symbol.symbol -> Symbol.sym| \\
wenzelm@20438
   564
  \end{mldecls}
wenzelm@20438
   565
wenzelm@20438
   566
  \begin{description}
wenzelm@20438
   567
wenzelm@20490
   568
  \item \verb|Symbol.symbol| represents individual Isabelle
wenzelm@20490
   569
  symbols; this is an alias for \verb|string|.
wenzelm@20438
   570
wenzelm@20477
   571
  \item \verb|Symbol.explode|~\isa{str} produces a symbol list
wenzelm@20490
   572
  from the packed form.  This function supercedes \verb|String.explode| for virtually all purposes of manipulating text in
wenzelm@20477
   573
  Isabelle!
wenzelm@20438
   574
wenzelm@20477
   575
  \item \verb|Symbol.is_letter|, \verb|Symbol.is_digit|, \verb|Symbol.is_quasi|, \verb|Symbol.is_blank| classify standard
wenzelm@20477
   576
  symbols according to fixed syntactic conventions of Isabelle, cf.\
wenzelm@20477
   577
  \cite{isabelle-isar-ref}.
wenzelm@20438
   578
wenzelm@20438
   579
  \item \verb|Symbol.sym| is a concrete datatype that represents
wenzelm@20490
   580
  the different kinds of symbols explicitly, with constructors \verb|Symbol.Char|, \verb|Symbol.Sym|, \verb|Symbol.Ctrl|, \verb|Symbol.Raw|.
wenzelm@20438
   581
wenzelm@20438
   582
  \item \verb|Symbol.decode| converts the string representation of a
wenzelm@20451
   583
  symbol into the datatype version.
wenzelm@20438
   584
wenzelm@20438
   585
  \end{description}%
wenzelm@20438
   586
\end{isamarkuptext}%
wenzelm@20438
   587
\isamarkuptrue%
wenzelm@20438
   588
%
wenzelm@20438
   589
\endisatagmlref
wenzelm@20438
   590
{\isafoldmlref}%
wenzelm@20438
   591
%
wenzelm@20438
   592
\isadelimmlref
wenzelm@20438
   593
%
wenzelm@20438
   594
\endisadelimmlref
wenzelm@20438
   595
%
wenzelm@20477
   596
\isamarkupsubsection{Basic names \label{sec:basic-names}%
wenzelm@20438
   597
}
wenzelm@20438
   598
\isamarkuptrue%
wenzelm@20438
   599
%
wenzelm@20438
   600
\begin{isamarkuptext}%
wenzelm@20477
   601
A \emph{basic name} essentially consists of a single Isabelle
wenzelm@20477
   602
  identifier.  There are conventions to mark separate classes of basic
wenzelm@20477
   603
  names, by attaching a suffix of underscores (\isa{{\isacharunderscore}}): one
wenzelm@20477
   604
  underscore means \emph{internal name}, two underscores means
wenzelm@20477
   605
  \emph{Skolem name}, three underscores means \emph{internal Skolem
wenzelm@20477
   606
  name}.
wenzelm@20471
   607
wenzelm@20477
   608
  For example, the basic name \isa{foo} has the internal version
wenzelm@20477
   609
  \isa{foo{\isacharunderscore}}, with Skolem versions \isa{foo{\isacharunderscore}{\isacharunderscore}} and \isa{foo{\isacharunderscore}{\isacharunderscore}{\isacharunderscore}}, respectively.
wenzelm@20438
   610
wenzelm@20490
   611
  These special versions provide copies of the basic name space, apart
wenzelm@20490
   612
  from anything that normally appears in the user text.  For example,
wenzelm@20490
   613
  system generated variables in Isar proof contexts are usually marked
wenzelm@20490
   614
  as internal, which prevents mysterious name references like \isa{xaa} to appear in the text.
wenzelm@20438
   615
wenzelm@20490
   616
  \medskip Manipulating binding scopes often requires on-the-fly
wenzelm@20490
   617
  renamings.  A \emph{name context} contains a collection of already
wenzelm@20490
   618
  used names.  The \isa{declare} operation adds names to the
wenzelm@20490
   619
  context.
wenzelm@20438
   620
wenzelm@20490
   621
  The \isa{invents} operation derives a number of fresh names from
wenzelm@20490
   622
  a given starting point.  For example, the first three names derived
wenzelm@20490
   623
  from \isa{a} are \isa{a}, \isa{b}, \isa{c}.
wenzelm@20477
   624
wenzelm@20477
   625
  The \isa{variants} operation produces fresh names by
wenzelm@20490
   626
  incrementing tentative names as base-26 numbers (with digits \isa{a{\isachardot}{\isachardot}z}) until all clashes are resolved.  For example, name \isa{foo} results in variants \isa{fooa}, \isa{foob}, \isa{fooc}, \dots, \isa{fooaa}, \isa{fooab} etc.; each renaming
wenzelm@20490
   627
  step picks the next unused variant from this sequence.%
wenzelm@20438
   628
\end{isamarkuptext}%
wenzelm@20438
   629
\isamarkuptrue%
wenzelm@20438
   630
%
wenzelm@20451
   631
\isadelimmlref
wenzelm@20451
   632
%
wenzelm@20451
   633
\endisadelimmlref
wenzelm@20451
   634
%
wenzelm@20451
   635
\isatagmlref
wenzelm@20451
   636
%
wenzelm@20451
   637
\begin{isamarkuptext}%
wenzelm@20477
   638
\begin{mldecls}
wenzelm@20477
   639
  \indexml{Name.internal}\verb|Name.internal: string -> string| \\
wenzelm@20547
   640
  \indexml{Name.skolem}\verb|Name.skolem: string -> string| \\
wenzelm@20547
   641
  \end{mldecls}
wenzelm@20547
   642
  \begin{mldecls}
wenzelm@20477
   643
  \indexmltype{Name.context}\verb|type Name.context| \\
wenzelm@20477
   644
  \indexml{Name.context}\verb|Name.context: Name.context| \\
wenzelm@20477
   645
  \indexml{Name.declare}\verb|Name.declare: string -> Name.context -> Name.context| \\
wenzelm@20477
   646
  \indexml{Name.invents}\verb|Name.invents: Name.context -> string -> int -> string list| \\
wenzelm@20477
   647
  \indexml{Name.variants}\verb|Name.variants: string list -> Name.context -> string list * Name.context| \\
wenzelm@20477
   648
  \end{mldecls}
wenzelm@20477
   649
wenzelm@20477
   650
  \begin{description}
wenzelm@20477
   651
wenzelm@20477
   652
  \item \verb|Name.internal|~\isa{name} produces an internal name
wenzelm@20477
   653
  by adding one underscore.
wenzelm@20477
   654
wenzelm@20477
   655
  \item \verb|Name.skolem|~\isa{name} produces a Skolem name by
wenzelm@20477
   656
  adding two underscores.
wenzelm@20477
   657
wenzelm@20477
   658
  \item \verb|Name.context| represents the context of already used
wenzelm@20477
   659
  names; the initial value is \verb|Name.context|.
wenzelm@20477
   660
wenzelm@20490
   661
  \item \verb|Name.declare|~\isa{name} enters a used name into the
wenzelm@20490
   662
  context.
wenzelm@20477
   663
wenzelm@20490
   664
  \item \verb|Name.invents|~\isa{context\ name\ n} produces \isa{n} fresh names derived from \isa{name}.
wenzelm@20490
   665
wenzelm@20490
   666
  \item \verb|Name.variants|~\isa{names\ context} produces fresh
wenzelm@20490
   667
  varians of \isa{names}; the result is entered into the context.
wenzelm@20477
   668
wenzelm@20477
   669
  \end{description}%
wenzelm@20451
   670
\end{isamarkuptext}%
wenzelm@20451
   671
\isamarkuptrue%
wenzelm@20451
   672
%
wenzelm@20451
   673
\endisatagmlref
wenzelm@20451
   674
{\isafoldmlref}%
wenzelm@20451
   675
%
wenzelm@20451
   676
\isadelimmlref
wenzelm@20451
   677
%
wenzelm@20451
   678
\endisadelimmlref
wenzelm@20451
   679
%
wenzelm@20477
   680
\isamarkupsubsection{Indexed names%
wenzelm@20438
   681
}
wenzelm@20438
   682
\isamarkuptrue%
wenzelm@20438
   683
%
wenzelm@20438
   684
\begin{isamarkuptext}%
wenzelm@20477
   685
An \emph{indexed name} (or \isa{indexname}) is a pair of a basic
wenzelm@20490
   686
  name and a natural number.  This representation allows efficient
wenzelm@20490
   687
  renaming by incrementing the second component only.  The canonical
wenzelm@20490
   688
  way to rename two collections of indexnames apart from each other is
wenzelm@20490
   689
  this: determine the maximum index \isa{maxidx} of the first
wenzelm@20490
   690
  collection, then increment all indexes of the second collection by
wenzelm@20490
   691
  \isa{maxidx\ {\isacharplus}\ {\isadigit{1}}}; the maximum index of an empty collection is
wenzelm@20490
   692
  \isa{{\isacharminus}{\isadigit{1}}}.
wenzelm@20477
   693
wenzelm@20490
   694
  Occasionally, basic names and indexed names are injected into the
wenzelm@20490
   695
  same pair type: the (improper) indexname \isa{{\isacharparenleft}x{\isacharcomma}\ {\isacharminus}{\isadigit{1}}{\isacharparenright}} is used
wenzelm@20490
   696
  to encode basic names.
wenzelm@20490
   697
wenzelm@20490
   698
  \medskip Isabelle syntax observes the following rules for
wenzelm@20490
   699
  representing an indexname \isa{{\isacharparenleft}x{\isacharcomma}\ i{\isacharparenright}} as a packed string:
wenzelm@20477
   700
wenzelm@20477
   701
  \begin{itemize}
wenzelm@20477
   702
wenzelm@20481
   703
  \item \isa{{\isacharquery}x} if \isa{x} does not end with a digit and \isa{i\ {\isacharequal}\ {\isadigit{0}}},
wenzelm@20477
   704
wenzelm@20477
   705
  \item \isa{{\isacharquery}xi} if \isa{x} does not end with a digit,
wenzelm@20477
   706
wenzelm@20490
   707
  \item \isa{{\isacharquery}x{\isachardot}i} otherwise.
wenzelm@20477
   708
wenzelm@20477
   709
  \end{itemize}
wenzelm@20477
   710
wenzelm@20490
   711
  Indexnames may acquire large index numbers over time.  Results are
wenzelm@20490
   712
  normalized towards \isa{{\isadigit{0}}} at certain checkpoints, notably at
wenzelm@20490
   713
  the end of a proof.  This works by producing variants of the
wenzelm@20490
   714
  corresponding basic name components.  For example, the collection
wenzelm@20490
   715
  \isa{{\isacharquery}x{\isadigit{1}}{\isacharcomma}\ {\isacharquery}x{\isadigit{7}}{\isacharcomma}\ {\isacharquery}x{\isadigit{4}}{\isadigit{2}}} becomes \isa{{\isacharquery}x{\isacharcomma}\ {\isacharquery}xa{\isacharcomma}\ {\isacharquery}xb}.%
wenzelm@20438
   716
\end{isamarkuptext}%
wenzelm@20438
   717
\isamarkuptrue%
wenzelm@20438
   718
%
wenzelm@20477
   719
\isadelimmlref
wenzelm@20477
   720
%
wenzelm@20477
   721
\endisadelimmlref
wenzelm@20477
   722
%
wenzelm@20477
   723
\isatagmlref
wenzelm@20477
   724
%
wenzelm@20477
   725
\begin{isamarkuptext}%
wenzelm@20477
   726
\begin{mldecls}
wenzelm@20477
   727
  \indexmltype{indexname}\verb|type indexname| \\
wenzelm@20477
   728
  \end{mldecls}
wenzelm@20477
   729
wenzelm@20477
   730
  \begin{description}
wenzelm@20477
   731
wenzelm@20477
   732
  \item \verb|indexname| represents indexed names.  This is an
wenzelm@20477
   733
  abbreviation for \verb|string * int|.  The second component is
wenzelm@20477
   734
  usually non-negative, except for situations where \isa{{\isacharparenleft}x{\isacharcomma}\ {\isacharminus}{\isadigit{1}}{\isacharparenright}}
wenzelm@20490
   735
  is used to embed basic names into this type.
wenzelm@20477
   736
wenzelm@20477
   737
  \end{description}%
wenzelm@20477
   738
\end{isamarkuptext}%
wenzelm@20477
   739
\isamarkuptrue%
wenzelm@20477
   740
%
wenzelm@20477
   741
\endisatagmlref
wenzelm@20477
   742
{\isafoldmlref}%
wenzelm@20477
   743
%
wenzelm@20477
   744
\isadelimmlref
wenzelm@20477
   745
%
wenzelm@20477
   746
\endisadelimmlref
wenzelm@20477
   747
%
wenzelm@20477
   748
\isamarkupsubsection{Qualified names and name spaces%
wenzelm@20438
   749
}
wenzelm@20438
   750
\isamarkuptrue%
wenzelm@20438
   751
%
wenzelm@20438
   752
\begin{isamarkuptext}%
wenzelm@20477
   753
A \emph{qualified name} consists of a non-empty sequence of basic
wenzelm@20490
   754
  name components.  The packed representation uses a dot as separator,
wenzelm@20490
   755
  as in ``\isa{A{\isachardot}b{\isachardot}c}''.  The last component is called \emph{base}
wenzelm@20490
   756
  name, the remaining prefix \emph{qualifier} (which may be empty).
wenzelm@20490
   757
  The idea of qualified names is to encode nested structures by
wenzelm@20490
   758
  recording the access paths as qualifiers.  For example, an item
wenzelm@20490
   759
  named ``\isa{A{\isachardot}b{\isachardot}c}'' may be understood as a local entity \isa{c}, within a local structure \isa{b}, within a global
wenzelm@20490
   760
  structure \isa{A}.  Typically, name space hierarchies consist of
wenzelm@20490
   761
  1--2 levels of qualification, but this need not be always so.
wenzelm@20477
   762
wenzelm@20477
   763
  The empty name is commonly used as an indication of unnamed
wenzelm@20490
   764
  entities, whenever this makes any sense.  The basic operations on
wenzelm@20490
   765
  qualified names are smart enough to pass through such improper names
wenzelm@20477
   766
  unchanged.
wenzelm@20477
   767
wenzelm@20477
   768
  \medskip A \isa{naming} policy tells how to turn a name
wenzelm@20490
   769
  specification into a fully qualified internal name (by the \isa{full} operation), and how fully qualified names may be accessed
wenzelm@20490
   770
  externally.  For example, the default naming policy is to prefix an
wenzelm@20490
   771
  implicit path: \isa{full\ x} produces \isa{path{\isachardot}x}, and the
wenzelm@20490
   772
  standard accesses for \isa{path{\isachardot}x} include both \isa{x} and
wenzelm@20490
   773
  \isa{path{\isachardot}x}.  Normally, the naming is implicit in the theory or
wenzelm@20490
   774
  proof context; there are separate versions of the corresponding.
wenzelm@20477
   775
wenzelm@20477
   776
  \medskip A \isa{name\ space} manages a collection of fully
wenzelm@20477
   777
  internalized names, together with a mapping between external names
wenzelm@20477
   778
  and internal names (in both directions).  The corresponding \isa{intern} and \isa{extern} operations are mostly used for
wenzelm@20477
   779
  parsing and printing only!  The \isa{declare} operation augments
wenzelm@20490
   780
  a name space according to the accesses determined by the naming
wenzelm@20490
   781
  policy.
wenzelm@20477
   782
wenzelm@20490
   783
  \medskip As a general principle, there is a separate name space for
wenzelm@20490
   784
  each kind of formal entity, e.g.\ logical constant, type
wenzelm@20490
   785
  constructor, type class, theorem.  It is usually clear from the
wenzelm@20490
   786
  occurrence in concrete syntax (or from the scope) which kind of
wenzelm@20490
   787
  entity a name refers to.  For example, the very same name \isa{c} may be used uniformly for a constant, type constructor, and
wenzelm@20490
   788
  type class.
wenzelm@20477
   789
wenzelm@20481
   790
  There are common schemes to name theorems systematically, according
wenzelm@20490
   791
  to the name of the main logical entity involved, e.g.\ \isa{c{\isachardot}intro} for a canonical theorem related to constant \isa{c}.
wenzelm@20490
   792
  This technique of mapping names from one space into another requires
wenzelm@20490
   793
  some care in order to avoid conflicts.  In particular, theorem names
wenzelm@20490
   794
  derived from a type constructor or type class are better suffixed in
wenzelm@20490
   795
  addition to the usual qualification, e.g.\ \isa{c{\isacharunderscore}type{\isachardot}intro}
wenzelm@20490
   796
  and \isa{c{\isacharunderscore}class{\isachardot}intro} for theorems related to type \isa{c}
wenzelm@20490
   797
  and class \isa{c}, respectively.%
wenzelm@20438
   798
\end{isamarkuptext}%
wenzelm@20438
   799
\isamarkuptrue%
wenzelm@20438
   800
%
wenzelm@20477
   801
\isadelimmlref
wenzelm@20477
   802
%
wenzelm@20477
   803
\endisadelimmlref
wenzelm@20477
   804
%
wenzelm@20477
   805
\isatagmlref
wenzelm@20477
   806
%
wenzelm@20477
   807
\begin{isamarkuptext}%
wenzelm@20477
   808
\begin{mldecls}
wenzelm@20477
   809
  \indexml{NameSpace.base}\verb|NameSpace.base: string -> string| \\
wenzelm@20530
   810
  \indexml{NameSpace.qualifier}\verb|NameSpace.qualifier: string -> string| \\
wenzelm@20477
   811
  \indexml{NameSpace.append}\verb|NameSpace.append: string -> string -> string| \\
wenzelm@21862
   812
  \indexml{NameSpace.implode}\verb|NameSpace.implode: string list -> string| \\
wenzelm@21862
   813
  \indexml{NameSpace.explode}\verb|NameSpace.explode: string -> string list| \\
wenzelm@20547
   814
  \end{mldecls}
wenzelm@20547
   815
  \begin{mldecls}
wenzelm@20477
   816
  \indexmltype{NameSpace.naming}\verb|type NameSpace.naming| \\
wenzelm@26854
   817
  \indexml{NameSpace.default\_naming}\verb|NameSpace.default_naming: NameSpace.naming| \\
wenzelm@26854
   818
  \indexml{NameSpace.add\_path}\verb|NameSpace.add_path: string -> NameSpace.naming -> NameSpace.naming| \\
wenzelm@20547
   819
  \indexml{NameSpace.full}\verb|NameSpace.full: NameSpace.naming -> string -> string| \\
wenzelm@20547
   820
  \end{mldecls}
wenzelm@20547
   821
  \begin{mldecls}
wenzelm@20477
   822
  \indexmltype{NameSpace.T}\verb|type NameSpace.T| \\
wenzelm@20477
   823
  \indexml{NameSpace.empty}\verb|NameSpace.empty: NameSpace.T| \\
wenzelm@20477
   824
  \indexml{NameSpace.merge}\verb|NameSpace.merge: NameSpace.T * NameSpace.T -> NameSpace.T| \\
wenzelm@20477
   825
  \indexml{NameSpace.declare}\verb|NameSpace.declare: NameSpace.naming -> string -> NameSpace.T -> NameSpace.T| \\
wenzelm@20477
   826
  \indexml{NameSpace.intern}\verb|NameSpace.intern: NameSpace.T -> string -> string| \\
wenzelm@20477
   827
  \indexml{NameSpace.extern}\verb|NameSpace.extern: NameSpace.T -> string -> string| \\
wenzelm@20477
   828
  \end{mldecls}
wenzelm@20477
   829
wenzelm@20477
   830
  \begin{description}
wenzelm@20477
   831
wenzelm@20477
   832
  \item \verb|NameSpace.base|~\isa{name} returns the base name of a
wenzelm@20477
   833
  qualified name.
wenzelm@20477
   834
wenzelm@20530
   835
  \item \verb|NameSpace.qualifier|~\isa{name} returns the qualifier
wenzelm@20477
   836
  of a qualified name.
wenzelm@20477
   837
wenzelm@20477
   838
  \item \verb|NameSpace.append|~\isa{name\isactrlisub {\isadigit{1}}\ name\isactrlisub {\isadigit{2}}}
wenzelm@20477
   839
  appends two qualified names.
wenzelm@20477
   840
wenzelm@21862
   841
  \item \verb|NameSpace.implode|~\isa{name} and \verb|NameSpace.explode|~\isa{names} convert between the packed string
wenzelm@20490
   842
  representation and the explicit list form of qualified names.
wenzelm@20477
   843
wenzelm@20477
   844
  \item \verb|NameSpace.naming| represents the abstract concept of
wenzelm@20477
   845
  a naming policy.
wenzelm@20477
   846
wenzelm@20477
   847
  \item \verb|NameSpace.default_naming| is the default naming policy.
wenzelm@20477
   848
  In a theory context, this is usually augmented by a path prefix
wenzelm@20477
   849
  consisting of the theory name.
wenzelm@20477
   850
wenzelm@20477
   851
  \item \verb|NameSpace.add_path|~\isa{path\ naming} augments the
wenzelm@20490
   852
  naming policy by extending its path component.
wenzelm@20477
   853
wenzelm@20477
   854
  \item \verb|NameSpace.full|\isa{naming\ name} turns a name
wenzelm@20477
   855
  specification (usually a basic name) into the fully qualified
wenzelm@20477
   856
  internal version, according to the given naming policy.
wenzelm@20477
   857
wenzelm@20477
   858
  \item \verb|NameSpace.T| represents name spaces.
wenzelm@20477
   859
wenzelm@20490
   860
  \item \verb|NameSpace.empty| and \verb|NameSpace.merge|~\isa{{\isacharparenleft}space\isactrlisub {\isadigit{1}}{\isacharcomma}\ space\isactrlisub {\isadigit{2}}{\isacharparenright}} are the canonical operations for
wenzelm@20490
   861
  maintaining name spaces according to theory data management
wenzelm@20490
   862
  (\secref{sec:context-data}).
wenzelm@20477
   863
wenzelm@20477
   864
  \item \verb|NameSpace.declare|~\isa{naming\ name\ space} enters a
wenzelm@20490
   865
  fully qualified name into the name space, with external accesses
wenzelm@20490
   866
  determined by the naming policy.
wenzelm@20477
   867
wenzelm@20477
   868
  \item \verb|NameSpace.intern|~\isa{space\ name} internalizes a
wenzelm@20477
   869
  (partially qualified) external name.
wenzelm@20477
   870
wenzelm@20490
   871
  This operation is mostly for parsing!  Note that fully qualified
wenzelm@20490
   872
  names stemming from declarations are produced via \verb|NameSpace.full| (or its derivatives for \verb|theory| and
wenzelm@20490
   873
  \verb|Proof.context|).
wenzelm@20477
   874
wenzelm@20477
   875
  \item \verb|NameSpace.extern|~\isa{space\ name} externalizes a
wenzelm@20477
   876
  (fully qualified) internal name.
wenzelm@20477
   877
wenzelm@20490
   878
  This operation is mostly for printing!  Note unqualified names are
wenzelm@20477
   879
  produced via \verb|NameSpace.base|.
wenzelm@20477
   880
wenzelm@20477
   881
  \end{description}%
wenzelm@20477
   882
\end{isamarkuptext}%
wenzelm@20438
   883
\isamarkuptrue%
wenzelm@20438
   884
%
wenzelm@20477
   885
\endisatagmlref
wenzelm@20477
   886
{\isafoldmlref}%
wenzelm@20477
   887
%
wenzelm@20477
   888
\isadelimmlref
wenzelm@20477
   889
%
wenzelm@20477
   890
\endisadelimmlref
wenzelm@20438
   891
%
wenzelm@18537
   892
\isadelimtheory
wenzelm@18537
   893
%
wenzelm@18537
   894
\endisadelimtheory
wenzelm@18537
   895
%
wenzelm@18537
   896
\isatagtheory
wenzelm@18537
   897
\isacommand{end}\isamarkupfalse%
wenzelm@18537
   898
%
wenzelm@18537
   899
\endisatagtheory
wenzelm@18537
   900
{\isafoldtheory}%
wenzelm@18537
   901
%
wenzelm@18537
   902
\isadelimtheory
wenzelm@18537
   903
%
wenzelm@18537
   904
\endisadelimtheory
wenzelm@18537
   905
\isanewline
wenzelm@18537
   906
\end{isabellebody}%
wenzelm@18537
   907
%%% Local Variables:
wenzelm@18537
   908
%%% mode: latex
wenzelm@18537
   909
%%% TeX-master: "root"
wenzelm@18537
   910
%%% End: