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