doc-src/IsarImplementation/Thy/document/prelim.tex
author wenzelm
Sat, 10 May 2008 14:13:20 +0200
changeset 26873 691f35f855cd
parent 26867 6274cf7e2b8e
child 26902 8db1e960d636
permissions -rw-r--r--
updated generated file;
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$ & \\
21862
13e9febe3080 updated;
wenzelm
parents: 20547
diff changeset
   140
  \isa{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} \\
26867
6274cf7e2b8e updated generated file;
wenzelm
parents: 26854
diff changeset
   143
        &            & \multicolumn{3}{l}{~~\mbox{\isa{\isakeyword{imports}}}} \\
6274cf7e2b8e updated generated file;
wenzelm
parents: 26854
diff changeset
   144
        &            & \multicolumn{3}{l}{~~\mbox{\isa{\isakeyword{begin}}}} \\
18537
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$~~ \\
26867
6274cf7e2b8e updated generated file;
wenzelm
parents: 26854
diff changeset
   150
        &            & \multicolumn{3}{l}{~~\mbox{\isa{\isacommand{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
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   158
  drafts are propagated automatically.  Dynamic updating stops after
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   159
  an explicit \isa{end} only.
20451
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| \\
20547
wenzelm
parents: 20530
diff changeset
   180
  \indexml{Theory.copy}\verb|Theory.copy: theory -> theory| \\
wenzelm
parents: 20530
diff changeset
   181
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   182
  \begin{mldecls}
26854
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   183
  \indexmltype{theory\_ref}\verb|type theory_ref| \\
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   184
  \indexml{Theory.deref}\verb|Theory.deref: theory_ref -> theory| \\
26854
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   185
  \indexml{Theory.check\_thy}\verb|Theory.check_thy: theory -> theory_ref| \\
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   186
  \end{mldecls}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   187
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   188
  \begin{description}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   189
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   190
  \item \verb|theory| represents theory contexts.  This is
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   191
  essentially a linear type!  Most operations destroy the original
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   192
  version, which then becomes ``stale''.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   193
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   194
  \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
   195
  compares theories according to the inherent graph structure of the
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   196
  construction.  This sub-theory relation is a nominal approximation
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   197
  of inclusion (\isa{{\isasymsubseteq}}) of the corresponding content.
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   198
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   199
  \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
   200
  absorbs one theory into the other.  This fails for unrelated
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   201
  theories!
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   202
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   203
  \item \verb|Theory.checkpoint|~\isa{thy} produces a safe
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   204
  stepping stone in the linear development of \isa{thy}.  The next
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   205
  update will result in two related, valid theories.
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   206
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   207
  \item \verb|Theory.copy|~\isa{thy} produces a variant of \isa{thy} that holds a copy of the same data.  The result is not
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   208
  related to the original; the original is unchanched.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   209
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   210
  \item \verb|theory_ref| represents a sliding reference to an
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   211
  always valid theory; updates on the original are propagated
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   212
  automatically.
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   213
24138
bd3fc8ff6bc9 updated;
wenzelm
parents: 22870
diff changeset
   214
  \item \verb|Theory.deref|~\isa{thy{\isacharunderscore}ref} turns a \verb|theory_ref| into an \verb|theory| value.  As the referenced
bd3fc8ff6bc9 updated;
wenzelm
parents: 22870
diff changeset
   215
  theory evolves monotonically over time, later invocations of \verb|Theory.deref| may refer to a larger context.
bd3fc8ff6bc9 updated;
wenzelm
parents: 22870
diff changeset
   216
bd3fc8ff6bc9 updated;
wenzelm
parents: 22870
diff changeset
   217
  \item \verb|Theory.check_thy|~\isa{thy} produces a \verb|theory_ref| from a valid \verb|theory| value.
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   218
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   219
  \end{description}%
20430
wenzelm
parents: 20429
diff changeset
   220
\end{isamarkuptext}%
wenzelm
parents: 20429
diff changeset
   221
\isamarkuptrue%
wenzelm
parents: 20429
diff changeset
   222
%
wenzelm
parents: 20429
diff changeset
   223
\endisatagmlref
wenzelm
parents: 20429
diff changeset
   224
{\isafoldmlref}%
wenzelm
parents: 20429
diff changeset
   225
%
wenzelm
parents: 20429
diff changeset
   226
\isadelimmlref
wenzelm
parents: 20429
diff changeset
   227
%
wenzelm
parents: 20429
diff changeset
   228
\endisadelimmlref
wenzelm
parents: 20429
diff changeset
   229
%
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   230
\isamarkupsubsection{Proof context \label{sec:context-proof}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   231
}
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   232
\isamarkuptrue%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   233
%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   234
\begin{isamarkuptext}%
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   235
\glossary{Proof context}{The static context of a structured proof,
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   236
  acts like a local ``theory'' of the current portion of Isar proof
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   237
  text, generalizes the idea of local hypotheses \isa{{\isasymGamma}} in
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   238
  judgments \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} of natural deduction calculi.  There is a
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   239
  generic notion of introducing and discharging hypotheses.
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   240
  Arbritrary auxiliary context data may be adjoined.}
20429
116255c9209b more on contexts;
wenzelm
parents: 20215
diff changeset
   241
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   242
  A proof context is a container for pure data with a back-reference
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   243
  to the theory it belongs to.  The \isa{init} operation creates a
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   244
  proof context from a given theory.  Modifications to draft theories
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   245
  are propagated to the proof context as usual, but there is also an
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   246
  explicit \isa{transfer} operation to force resynchronization
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   247
  with more substantial updates to the underlying theory.  The actual
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   248
  context data does not require any special bookkeeping, thanks to the
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   249
  lack of destructive features.
20429
116255c9209b more on contexts;
wenzelm
parents: 20215
diff changeset
   250
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   251
  Entities derived in a proof context need to record inherent logical
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   252
  requirements explicitly, since there is no separate context
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   253
  identification as for theories.  For example, hypotheses used in
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   254
  primitive derivations (cf.\ \secref{sec:thms}) are recorded
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   255
  separately within the sequent \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}}, just to make double
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   256
  sure.  Results could still leak into an alien proof context do to
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   257
  programming errors, but Isabelle/Isar includes some extra validity
22504
22b638460a13 fixed typo
haftmann
parents: 21862
diff changeset
   258
  checks in critical positions, notably at the end of a sub-proof.
20429
116255c9209b more on contexts;
wenzelm
parents: 20215
diff changeset
   259
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   260
  Proof contexts may be manipulated arbitrarily, although the common
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   261
  discipline is to follow block structure as a mental model: a given
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   262
  context is extended consecutively, and results are exported back
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   263
  into the original context.  Note that the Isar proof states model
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   264
  block-structured reasoning explicitly, using a stack of proof
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   265
  contexts internally, cf.\ \secref{sec:isar-proof-state}.%
18537
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   266
\end{isamarkuptext}%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   267
\isamarkuptrue%
2681f9e34390 "The Isabelle/Isar Implementation" manual;
wenzelm
parents:
diff changeset
   268
%
20430
wenzelm
parents: 20429
diff changeset
   269
\isadelimmlref
wenzelm
parents: 20429
diff changeset
   270
%
wenzelm
parents: 20429
diff changeset
   271
\endisadelimmlref
wenzelm
parents: 20429
diff changeset
   272
%
wenzelm
parents: 20429
diff changeset
   273
\isatagmlref
wenzelm
parents: 20429
diff changeset
   274
%
wenzelm
parents: 20429
diff changeset
   275
\begin{isamarkuptext}%
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   276
\begin{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   277
  \indexmltype{Proof.context}\verb|type Proof.context| \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   278
  \indexml{ProofContext.init}\verb|ProofContext.init: theory -> Proof.context| \\
26854
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   279
  \indexml{ProofContext.theory\_of}\verb|ProofContext.theory_of: Proof.context -> theory| \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   280
  \indexml{ProofContext.transfer}\verb|ProofContext.transfer: theory -> Proof.context -> Proof.context| \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   281
  \end{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   282
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   283
  \begin{description}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   284
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   285
  \item \verb|Proof.context| represents proof contexts.  Elements
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   286
  of this type are essentially pure values, with a sliding reference
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   287
  to the background theory.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   288
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   289
  \item \verb|ProofContext.init|~\isa{thy} produces a proof context
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   290
  derived from \isa{thy}, initializing all data.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   291
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   292
  \item \verb|ProofContext.theory_of|~\isa{ctxt} selects the
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   293
  background theory from \isa{ctxt}, dereferencing its internal
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   294
  \verb|theory_ref|.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   295
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   296
  \item \verb|ProofContext.transfer|~\isa{thy\ ctxt} promotes the
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   297
  background theory of \isa{ctxt} to the super theory \isa{thy}.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   298
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   299
  \end{description}%
20430
wenzelm
parents: 20429
diff changeset
   300
\end{isamarkuptext}%
wenzelm
parents: 20429
diff changeset
   301
\isamarkuptrue%
wenzelm
parents: 20429
diff changeset
   302
%
wenzelm
parents: 20429
diff changeset
   303
\endisatagmlref
wenzelm
parents: 20429
diff changeset
   304
{\isafoldmlref}%
wenzelm
parents: 20429
diff changeset
   305
%
wenzelm
parents: 20429
diff changeset
   306
\isadelimmlref
wenzelm
parents: 20429
diff changeset
   307
%
wenzelm
parents: 20429
diff changeset
   308
\endisadelimmlref
wenzelm
parents: 20429
diff changeset
   309
%
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   310
\isamarkupsubsection{Generic contexts \label{sec:generic-context}%
20429
116255c9209b more on contexts;
wenzelm
parents: 20215
diff changeset
   311
}
116255c9209b more on contexts;
wenzelm
parents: 20215
diff changeset
   312
\isamarkuptrue%
116255c9209b more on contexts;
wenzelm
parents: 20215
diff changeset
   313
%
20430
wenzelm
parents: 20429
diff changeset
   314
\begin{isamarkuptext}%
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   315
A generic context is the disjoint sum of either a theory or proof
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   316
  context.  Occasionally, this enables uniform treatment of generic
20450
wenzelm
parents: 20449
diff changeset
   317
  context data, typically extra-logical information.  Operations on
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   318
  generic contexts include the usual injections, partial selections,
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   319
  and combinators for lifting operations on either component of the
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   320
  disjoint sum.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   321
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   322
  Moreover, there are total operations \isa{theory{\isacharunderscore}of} and \isa{proof{\isacharunderscore}of} to convert a generic context into either kind: a theory
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   323
  can always be selected from the sum, while a proof context might
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   324
  have to be constructed by an ad-hoc \isa{init} operation.%
20430
wenzelm
parents: 20429
diff changeset
   325
\end{isamarkuptext}%
wenzelm
parents: 20429
diff changeset
   326
\isamarkuptrue%
wenzelm
parents: 20429
diff changeset
   327
%
wenzelm
parents: 20429
diff changeset
   328
\isadelimmlref
wenzelm
parents: 20429
diff changeset
   329
%
wenzelm
parents: 20429
diff changeset
   330
\endisadelimmlref
wenzelm
parents: 20429
diff changeset
   331
%
wenzelm
parents: 20429
diff changeset
   332
\isatagmlref
wenzelm
parents: 20429
diff changeset
   333
%
wenzelm
parents: 20429
diff changeset
   334
\begin{isamarkuptext}%
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   335
\begin{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   336
  \indexmltype{Context.generic}\verb|type Context.generic| \\
26854
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   337
  \indexml{Context.theory\_of}\verb|Context.theory_of: Context.generic -> theory| \\
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   338
  \indexml{Context.proof\_of}\verb|Context.proof_of: Context.generic -> Proof.context| \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   339
  \end{mldecls}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   340
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   341
  \begin{description}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   342
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   343
  \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
   344
  constructors \verb|Context.Theory| and \verb|Context.Proof|.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   345
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   346
  \item \verb|Context.theory_of|~\isa{context} always produces a
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   347
  theory from the generic \isa{context}, using \verb|ProofContext.theory_of| as required.
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   348
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   349
  \item \verb|Context.proof_of|~\isa{context} always produces a
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   350
  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
   351
  context data with each invocation).
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   352
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   353
  \end{description}%
20430
wenzelm
parents: 20429
diff changeset
   354
\end{isamarkuptext}%
wenzelm
parents: 20429
diff changeset
   355
\isamarkuptrue%
wenzelm
parents: 20429
diff changeset
   356
%
wenzelm
parents: 20429
diff changeset
   357
\endisatagmlref
wenzelm
parents: 20429
diff changeset
   358
{\isafoldmlref}%
wenzelm
parents: 20429
diff changeset
   359
%
wenzelm
parents: 20429
diff changeset
   360
\isadelimmlref
wenzelm
parents: 20429
diff changeset
   361
%
wenzelm
parents: 20429
diff changeset
   362
\endisadelimmlref
wenzelm
parents: 20429
diff changeset
   363
%
20477
wenzelm
parents: 20475
diff changeset
   364
\isamarkupsubsection{Context data \label{sec:context-data}%
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   365
}
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   366
\isamarkuptrue%
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   367
%
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   368
\begin{isamarkuptext}%
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   369
The main purpose of theory and proof contexts is to manage arbitrary
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   370
  data.  New data types can be declared incrementally at compile time.
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   371
  There are separate declaration mechanisms for any of the three kinds
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   372
  of contexts: theory, proof, generic.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   373
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   374
  \paragraph{Theory data} may refer to destructive entities, which are
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   375
  maintained in direct correspondence to the linear evolution of
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   376
  theory values, including explicit copies.\footnote{Most existing
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   377
  instances of destructive theory data are merely historical relics
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   378
  (e.g.\ the destructive theorem storage, and destructive hints for
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   379
  the Simplifier and Classical rules).}  A theory data declaration
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   380
  needs to implement the following SML signature:
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   381
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   382
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   383
  \begin{tabular}{ll}
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   384
  \isa{{\isasymtype}\ T} & representing type \\
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   385
  \isa{{\isasymval}\ empty{\isacharcolon}\ T} & empty default value \\
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   386
  \isa{{\isasymval}\ copy{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & refresh impure data \\
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   387
  \isa{{\isasymval}\ extend{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & re-initialize on import \\
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   388
  \isa{{\isasymval}\ merge{\isacharcolon}\ T\ {\isasymtimes}\ T\ {\isasymrightarrow}\ T} & join on import \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   389
  \end{tabular}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   390
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   391
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   392
  \noindent The \isa{empty} value acts as initial default for
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   393
  \emph{any} theory that does not declare actual data content; \isa{copy} maintains persistent integrity for impure data, it is just
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   394
  the identity for pure values; \isa{extend} is acts like a
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   395
  unitary version of \isa{merge}, both operations should also
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   396
  include the functionality of \isa{copy} for impure data.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   397
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   398
  \paragraph{Proof context data} is purely functional.  A declaration
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   399
  needs to implement the following SML signature:
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   400
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   401
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   402
  \begin{tabular}{ll}
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   403
  \isa{{\isasymtype}\ T} & representing type \\
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   404
  \isa{{\isasymval}\ init{\isacharcolon}\ theory\ {\isasymrightarrow}\ T} & produce initial value \\
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   405
  \end{tabular}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   406
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   407
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   408
  \noindent The \isa{init} operation is supposed to produce a pure
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   409
  value from the given background theory.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   410
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   411
  \paragraph{Generic data} provides a hybrid interface for both theory
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   412
  and proof data.  The declaration is essentially the same as for
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   413
  (pure) theory data, without \isa{copy}.  The \isa{init}
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   414
  operation for proof contexts merely selects the current data value
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   415
  from the background theory.
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   416
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   417
  \bigskip A data declaration of type \isa{T} results in the
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   418
  following interface:
20449
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   419
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   420
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   421
  \begin{tabular}{ll}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   422
  \isa{init{\isacharcolon}\ theory\ {\isasymrightarrow}\ theory} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   423
  \isa{get{\isacharcolon}\ context\ {\isasymrightarrow}\ T} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   424
  \isa{put{\isacharcolon}\ T\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   425
  \isa{map{\isacharcolon}\ {\isacharparenleft}T\ {\isasymrightarrow}\ T{\isacharparenright}\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   426
  \end{tabular}
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   427
  \medskip
f8a7a8236c68 more stuff;
wenzelm
parents: 20447
diff changeset
   428
22870
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   429
  \noindent Here \isa{init} is only applicable to impure theory
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   430
  data to install a fresh copy persistently (destructive update on
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   431
  uninitialized has no permanent effect).  The other operations provide
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   432
  access for the particular kind of context (theory, proof, or generic
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   433
  context).  Note that this is a safe interface: there is no other way
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   434
  to access the corresponding data slot of a context.  By keeping
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   435
  these operations private, a component may maintain abstract values
c37e32bdbea2 updated;
wenzelm
parents: 22504
diff changeset
   436
  authentically, without other components interfering.%
20447
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   437
\end{isamarkuptext}%
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   438
\isamarkuptrue%
5b75f1c4d7d6 more on contexts;
wenzelm
parents: 20438
diff changeset
   439
%
20450
wenzelm
parents: 20449
diff changeset
   440
\isadelimmlref
wenzelm
parents: 20449
diff changeset
   441
%
wenzelm
parents: 20449
diff changeset
   442
\endisadelimmlref
wenzelm
parents: 20449
diff changeset
   443
%
wenzelm
parents: 20449
diff changeset
   444
\isatagmlref
wenzelm
parents: 20449
diff changeset
   445
%
wenzelm
parents: 20449
diff changeset
   446
\begin{isamarkuptext}%
wenzelm
parents: 20449
diff changeset
   447
\begin{mldecls}
wenzelm
parents: 20449
diff changeset
   448
  \indexmlfunctor{TheoryDataFun}\verb|functor TheoryDataFun| \\
wenzelm
parents: 20449
diff changeset
   449
  \indexmlfunctor{ProofDataFun}\verb|functor ProofDataFun| \\
wenzelm
parents: 20449
diff changeset
   450
  \indexmlfunctor{GenericDataFun}\verb|functor GenericDataFun| \\
wenzelm
parents: 20449
diff changeset
   451
  \end{mldecls}
wenzelm
parents: 20449
diff changeset
   452
wenzelm
parents: 20449
diff changeset
   453
  \begin{description}
wenzelm
parents: 20449
diff changeset
   454
wenzelm
parents: 20449
diff changeset
   455
  \item \verb|TheoryDataFun|\isa{{\isacharparenleft}spec{\isacharparenright}} declares data for
wenzelm
parents: 20449
diff changeset
   456
  type \verb|theory| according to the specification provided as
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   457
  argument structure.  The resulting structure provides data init and
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   458
  access operations as described above.
20450
wenzelm
parents: 20449
diff changeset
   459
20471
ffafbd4103c0 updated;
wenzelm
parents: 20452
diff changeset
   460
  \item \verb|ProofDataFun|\isa{{\isacharparenleft}spec{\isacharparenright}} is analogous to
ffafbd4103c0 updated;
wenzelm
parents: 20452
diff changeset
   461
  \verb|TheoryDataFun| for type \verb|Proof.context|.
20450
wenzelm
parents: 20449
diff changeset
   462
20471
ffafbd4103c0 updated;
wenzelm
parents: 20452
diff changeset
   463
  \item \verb|GenericDataFun|\isa{{\isacharparenleft}spec{\isacharparenright}} is analogous to
ffafbd4103c0 updated;
wenzelm
parents: 20452
diff changeset
   464
  \verb|TheoryDataFun| for type \verb|Context.generic|.
20450
wenzelm
parents: 20449
diff changeset
   465
wenzelm
parents: 20449
diff changeset
   466
  \end{description}%
wenzelm
parents: 20449
diff changeset
   467
\end{isamarkuptext}%
wenzelm
parents: 20449
diff changeset
   468
\isamarkuptrue%
wenzelm
parents: 20449
diff changeset
   469
%
wenzelm
parents: 20449
diff changeset
   470
\endisatagmlref
wenzelm
parents: 20449
diff changeset
   471
{\isafoldmlref}%
wenzelm
parents: 20449
diff changeset
   472
%
wenzelm
parents: 20449
diff changeset
   473
\isadelimmlref
wenzelm
parents: 20449
diff changeset
   474
%
wenzelm
parents: 20449
diff changeset
   475
\endisadelimmlref
wenzelm
parents: 20449
diff changeset
   476
%
26873
691f35f855cd updated generated file;
wenzelm
parents: 26867
diff changeset
   477
\isamarkupsection{Names \label{sec:names}%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   478
}
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   479
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   480
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   481
\begin{isamarkuptext}%
20477
wenzelm
parents: 20475
diff changeset
   482
In principle, a name is just a string, but there are various
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   483
  convention for encoding additional structure.  For example, ``\isa{Foo{\isachardot}bar{\isachardot}baz}'' is considered as a qualified name consisting of
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   484
  three basic name components.  The individual constituents of a name
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   485
  may have further substructure, e.g.\ the string
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   486
  ``\verb,\,\verb,<alpha>,'' encodes as a single symbol.%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   487
\end{isamarkuptext}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   488
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   489
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   490
\isamarkupsubsection{Strings of symbols%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   491
}
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   492
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   493
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   494
\begin{isamarkuptext}%
20477
wenzelm
parents: 20475
diff changeset
   495
\glossary{Symbol}{The smallest unit of text in Isabelle, subsumes
wenzelm
parents: 20475
diff changeset
   496
  plain ASCII characters as well as an infinite collection of named
wenzelm
parents: 20475
diff changeset
   497
  symbols (for greek, math etc.).}
20471
ffafbd4103c0 updated;
wenzelm
parents: 20452
diff changeset
   498
20477
wenzelm
parents: 20475
diff changeset
   499
  A \emph{symbol} constitutes the smallest textual unit in Isabelle
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   500
  --- raw characters are normally not encountered at all.  Isabelle
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   501
  strings consist of a sequence of symbols, represented as a packed
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   502
  string or a list of strings.  Each symbol is in itself a small
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   503
  string, which has either one of the following forms:
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   504
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   505
  \begin{enumerate}
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   506
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   507
  \item a single ASCII character ``\isa{c}'', for example
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   508
  ``\verb,a,'',
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   509
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   510
  \item a regular symbol ``\verb,\,\verb,<,\isa{ident}\verb,>,'',
20477
wenzelm
parents: 20475
diff changeset
   511
  for example ``\verb,\,\verb,<alpha>,'',
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   512
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   513
  \item a control symbol ``\verb,\,\verb,<^,\isa{ident}\verb,>,'',
20477
wenzelm
parents: 20475
diff changeset
   514
  for example ``\verb,\,\verb,<^bold>,'',
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   515
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   516
  \item a raw symbol ``\verb,\,\verb,<^raw:,\isa{text}\verb,>,''
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   517
  where \isa{text} constists of printable characters excluding
20477
wenzelm
parents: 20475
diff changeset
   518
  ``\verb,.,'' and ``\verb,>,'', for example
wenzelm
parents: 20475
diff changeset
   519
  ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   520
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   521
  \item a 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
   522
  ``\verb,\,\verb,<^raw42>,''.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   523
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   524
  \end{enumerate}
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   525
20477
wenzelm
parents: 20475
diff changeset
   526
  \noindent The \isa{ident} syntax for symbol names is \isa{letter\ {\isacharparenleft}letter\ {\isacharbar}\ digit{\isacharparenright}\isactrlsup {\isacharasterisk}}, where \isa{letter\ {\isacharequal}\ A{\isachardot}{\isachardot}Za{\isachardot}{\isachardot}z} and \isa{digit\ {\isacharequal}\ {\isadigit{0}}{\isachardot}{\isachardot}{\isadigit{9}}}.  There are infinitely many
wenzelm
parents: 20475
diff changeset
   527
  regular symbols and control symbols, but a fixed collection of
wenzelm
parents: 20475
diff changeset
   528
  standard symbols is treated specifically.  For example,
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   529
  ``\verb,\,\verb,<alpha>,'' is classified as a letter, which means it
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   530
  may occur within regular Isabelle identifiers.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   531
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   532
  Since the character set underlying Isabelle symbols is 7-bit ASCII
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   533
  and 8-bit characters are passed through transparently, Isabelle may
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   534
  also process Unicode/UCS data in UTF-8 encoding.  Unicode provides
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   535
  its own collection of mathematical symbols, but there is no built-in
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   536
  link to the standard collection of Isabelle.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   537
20477
wenzelm
parents: 20475
diff changeset
   538
  \medskip Output of Isabelle symbols depends on the print mode
wenzelm
parents: 20475
diff changeset
   539
  (\secref{FIXME}).  For example, the standard {\LaTeX} setup of the
wenzelm
parents: 20475
diff changeset
   540
  Isabelle document preparation system would present
wenzelm
parents: 20475
diff changeset
   541
  ``\verb,\,\verb,<alpha>,'' as \isa{{\isasymalpha}}, and
wenzelm
parents: 20475
diff changeset
   542
  ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as \isa{\isactrlbold {\isasymalpha}}.%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   543
\end{isamarkuptext}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   544
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   545
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   546
\isadelimmlref
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   547
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   548
\endisadelimmlref
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   549
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   550
\isatagmlref
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   551
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   552
\begin{isamarkuptext}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   553
\begin{mldecls}
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   554
  \indexmltype{Symbol.symbol}\verb|type Symbol.symbol| \\
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   555
  \indexml{Symbol.explode}\verb|Symbol.explode: string -> Symbol.symbol list| \\
26854
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   556
  \indexml{Symbol.is\_letter}\verb|Symbol.is_letter: Symbol.symbol -> bool| \\
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   557
  \indexml{Symbol.is\_digit}\verb|Symbol.is_digit: Symbol.symbol -> bool| \\
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   558
  \indexml{Symbol.is\_quasi}\verb|Symbol.is_quasi: Symbol.symbol -> bool| \\
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   559
  \indexml{Symbol.is\_blank}\verb|Symbol.is_blank: Symbol.symbol -> bool| \\
20547
wenzelm
parents: 20530
diff changeset
   560
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   561
  \begin{mldecls}
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
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   568
  \item \verb|Symbol.symbol| represents individual Isabelle
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   569
  symbols; this is an alias for \verb|string|.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   570
20477
wenzelm
parents: 20475
diff changeset
   571
  \item \verb|Symbol.explode|~\isa{str} produces a symbol list
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   572
  from the packed form.  This function supercedes \verb|String.explode| for virtually all purposes of manipulating text in
20477
wenzelm
parents: 20475
diff changeset
   573
  Isabelle!
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   574
20477
wenzelm
parents: 20475
diff changeset
   575
  \item \verb|Symbol.is_letter|, \verb|Symbol.is_digit|, \verb|Symbol.is_quasi|, \verb|Symbol.is_blank| classify standard
wenzelm
parents: 20475
diff changeset
   576
  symbols according to fixed syntactic conventions of Isabelle, cf.\
wenzelm
parents: 20475
diff changeset
   577
  \cite{isabelle-isar-ref}.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   578
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   579
  \item \verb|Symbol.sym| is a concrete datatype that represents
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   580
  the different kinds of symbols explicitly, with constructors \verb|Symbol.Char|, \verb|Symbol.Sym|, \verb|Symbol.Ctrl|, \verb|Symbol.Raw|.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   581
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   582
  \item \verb|Symbol.decode| converts the string representation of a
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   583
  symbol into the datatype version.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   584
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   585
  \end{description}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   586
\end{isamarkuptext}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   587
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   588
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   589
\endisatagmlref
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   590
{\isafoldmlref}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   591
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   592
\isadelimmlref
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   593
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   594
\endisadelimmlref
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   595
%
20477
wenzelm
parents: 20475
diff changeset
   596
\isamarkupsubsection{Basic names \label{sec:basic-names}%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   597
}
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   598
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   599
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   600
\begin{isamarkuptext}%
20477
wenzelm
parents: 20475
diff changeset
   601
A \emph{basic name} essentially consists of a single Isabelle
wenzelm
parents: 20475
diff changeset
   602
  identifier.  There are conventions to mark separate classes of basic
wenzelm
parents: 20475
diff changeset
   603
  names, by attaching a suffix of underscores (\isa{{\isacharunderscore}}): one
wenzelm
parents: 20475
diff changeset
   604
  underscore means \emph{internal name}, two underscores means
wenzelm
parents: 20475
diff changeset
   605
  \emph{Skolem name}, three underscores means \emph{internal Skolem
wenzelm
parents: 20475
diff changeset
   606
  name}.
wenzelm
parents: 20475
diff changeset
   607
wenzelm
parents: 20475
diff changeset
   608
  For example, the basic name \isa{foo} has the internal version
wenzelm
parents: 20475
diff changeset
   609
  \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
   610
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   611
  These special versions provide copies of the basic name space, apart
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   612
  from anything that normally appears in the user text.  For example,
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   613
  system generated variables in Isar proof contexts are usually marked
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   614
  as internal, which prevents mysterious name references like \isa{xaa} to appear in the text.
20477
wenzelm
parents: 20475
diff changeset
   615
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   616
  \medskip Manipulating binding scopes often requires on-the-fly
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   617
  renamings.  A \emph{name context} contains a collection of already
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   618
  used names.  The \isa{declare} operation adds names to the
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   619
  context.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   620
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   621
  The \isa{invents} operation derives a number of fresh names from
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   622
  a given starting point.  For example, the first three names derived
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   623
  from \isa{a} are \isa{a}, \isa{b}, \isa{c}.
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   624
20477
wenzelm
parents: 20475
diff changeset
   625
  The \isa{variants} operation produces fresh names by
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   626
  incrementing tentative names as base-26 numbers (with digits \isa{a{\isachardot}{\isachardot}z}) until all clashes are resolved.  For example, name \isa{foo} results in variants \isa{fooa}, \isa{foob}, \isa{fooc}, \dots, \isa{fooaa}, \isa{fooab} etc.; each renaming
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   627
  step picks the next unused variant from this sequence.%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   628
\end{isamarkuptext}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   629
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   630
%
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   631
\isadelimmlref
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   632
%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   633
\endisadelimmlref
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   634
%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   635
\isatagmlref
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   636
%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   637
\begin{isamarkuptext}%
20477
wenzelm
parents: 20475
diff changeset
   638
\begin{mldecls}
wenzelm
parents: 20475
diff changeset
   639
  \indexml{Name.internal}\verb|Name.internal: string -> string| \\
20547
wenzelm
parents: 20530
diff changeset
   640
  \indexml{Name.skolem}\verb|Name.skolem: string -> string| \\
wenzelm
parents: 20530
diff changeset
   641
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   642
  \begin{mldecls}
20477
wenzelm
parents: 20475
diff changeset
   643
  \indexmltype{Name.context}\verb|type Name.context| \\
wenzelm
parents: 20475
diff changeset
   644
  \indexml{Name.context}\verb|Name.context: Name.context| \\
wenzelm
parents: 20475
diff changeset
   645
  \indexml{Name.declare}\verb|Name.declare: string -> Name.context -> Name.context| \\
wenzelm
parents: 20475
diff changeset
   646
  \indexml{Name.invents}\verb|Name.invents: Name.context -> string -> int -> string list| \\
wenzelm
parents: 20475
diff changeset
   647
  \indexml{Name.variants}\verb|Name.variants: string list -> Name.context -> string list * Name.context| \\
wenzelm
parents: 20475
diff changeset
   648
  \end{mldecls}
wenzelm
parents: 20475
diff changeset
   649
wenzelm
parents: 20475
diff changeset
   650
  \begin{description}
wenzelm
parents: 20475
diff changeset
   651
wenzelm
parents: 20475
diff changeset
   652
  \item \verb|Name.internal|~\isa{name} produces an internal name
wenzelm
parents: 20475
diff changeset
   653
  by adding one underscore.
wenzelm
parents: 20475
diff changeset
   654
wenzelm
parents: 20475
diff changeset
   655
  \item \verb|Name.skolem|~\isa{name} produces a Skolem name by
wenzelm
parents: 20475
diff changeset
   656
  adding two underscores.
wenzelm
parents: 20475
diff changeset
   657
wenzelm
parents: 20475
diff changeset
   658
  \item \verb|Name.context| represents the context of already used
wenzelm
parents: 20475
diff changeset
   659
  names; the initial value is \verb|Name.context|.
wenzelm
parents: 20475
diff changeset
   660
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   661
  \item \verb|Name.declare|~\isa{name} enters a used name into the
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   662
  context.
20477
wenzelm
parents: 20475
diff changeset
   663
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   664
  \item \verb|Name.invents|~\isa{context\ name\ n} produces \isa{n} fresh names derived from \isa{name}.
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   665
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   666
  \item \verb|Name.variants|~\isa{names\ context} produces fresh
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   667
  varians of \isa{names}; the result is entered into the context.
20477
wenzelm
parents: 20475
diff changeset
   668
wenzelm
parents: 20475
diff changeset
   669
  \end{description}%
wenzelm
parents: 20475
diff changeset
   670
\end{isamarkuptext}%
wenzelm
parents: 20475
diff changeset
   671
\isamarkuptrue%
wenzelm
parents: 20475
diff changeset
   672
%
wenzelm
parents: 20475
diff changeset
   673
\endisatagmlref
wenzelm
parents: 20475
diff changeset
   674
{\isafoldmlref}%
wenzelm
parents: 20475
diff changeset
   675
%
wenzelm
parents: 20475
diff changeset
   676
\isadelimmlref
wenzelm
parents: 20475
diff changeset
   677
%
wenzelm
parents: 20475
diff changeset
   678
\endisadelimmlref
wenzelm
parents: 20475
diff changeset
   679
%
wenzelm
parents: 20475
diff changeset
   680
\isamarkupsubsection{Indexed names%
wenzelm
parents: 20475
diff changeset
   681
}
wenzelm
parents: 20475
diff changeset
   682
\isamarkuptrue%
wenzelm
parents: 20475
diff changeset
   683
%
wenzelm
parents: 20475
diff changeset
   684
\begin{isamarkuptext}%
wenzelm
parents: 20475
diff changeset
   685
An \emph{indexed name} (or \isa{indexname}) is a pair of a basic
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   686
  name and a natural number.  This representation allows efficient
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   687
  renaming by incrementing the second component only.  The canonical
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   688
  way to rename two collections of indexnames apart from each other is
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   689
  this: determine the maximum index \isa{maxidx} of the first
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   690
  collection, then increment all indexes of the second collection by
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   691
  \isa{maxidx\ {\isacharplus}\ {\isadigit{1}}}; the maximum index of an empty collection is
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   692
  \isa{{\isacharminus}{\isadigit{1}}}.
20477
wenzelm
parents: 20475
diff changeset
   693
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   694
  Occasionally, basic names and indexed names are injected into the
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   695
  same pair type: the (improper) indexname \isa{{\isacharparenleft}x{\isacharcomma}\ {\isacharminus}{\isadigit{1}}{\isacharparenright}} is used
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   696
  to encode basic names.
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   697
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   698
  \medskip Isabelle syntax observes the following rules for
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   699
  representing an indexname \isa{{\isacharparenleft}x{\isacharcomma}\ i{\isacharparenright}} as a packed string:
20477
wenzelm
parents: 20475
diff changeset
   700
wenzelm
parents: 20475
diff changeset
   701
  \begin{itemize}
wenzelm
parents: 20475
diff changeset
   702
20481
c96f80442ce6 updated;
wenzelm
parents: 20477
diff changeset
   703
  \item \isa{{\isacharquery}x} if \isa{x} does not end with a digit and \isa{i\ {\isacharequal}\ {\isadigit{0}}},
20477
wenzelm
parents: 20475
diff changeset
   704
wenzelm
parents: 20475
diff changeset
   705
  \item \isa{{\isacharquery}xi} if \isa{x} does not end with a digit,
wenzelm
parents: 20475
diff changeset
   706
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   707
  \item \isa{{\isacharquery}x{\isachardot}i} otherwise.
20477
wenzelm
parents: 20475
diff changeset
   708
wenzelm
parents: 20475
diff changeset
   709
  \end{itemize}
wenzelm
parents: 20475
diff changeset
   710
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   711
  Indexnames may acquire large index numbers over time.  Results are
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   712
  normalized towards \isa{{\isadigit{0}}} at certain checkpoints, notably at
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   713
  the end of a proof.  This works by producing variants of the
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   714
  corresponding basic name components.  For example, the collection
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   715
  \isa{{\isacharquery}x{\isadigit{1}}{\isacharcomma}\ {\isacharquery}x{\isadigit{7}}{\isacharcomma}\ {\isacharquery}x{\isadigit{4}}{\isadigit{2}}} becomes \isa{{\isacharquery}x{\isacharcomma}\ {\isacharquery}xa{\isacharcomma}\ {\isacharquery}xb}.%
20477
wenzelm
parents: 20475
diff changeset
   716
\end{isamarkuptext}%
wenzelm
parents: 20475
diff changeset
   717
\isamarkuptrue%
wenzelm
parents: 20475
diff changeset
   718
%
wenzelm
parents: 20475
diff changeset
   719
\isadelimmlref
wenzelm
parents: 20475
diff changeset
   720
%
wenzelm
parents: 20475
diff changeset
   721
\endisadelimmlref
wenzelm
parents: 20475
diff changeset
   722
%
wenzelm
parents: 20475
diff changeset
   723
\isatagmlref
wenzelm
parents: 20475
diff changeset
   724
%
wenzelm
parents: 20475
diff changeset
   725
\begin{isamarkuptext}%
wenzelm
parents: 20475
diff changeset
   726
\begin{mldecls}
wenzelm
parents: 20475
diff changeset
   727
  \indexmltype{indexname}\verb|type indexname| \\
wenzelm
parents: 20475
diff changeset
   728
  \end{mldecls}
wenzelm
parents: 20475
diff changeset
   729
wenzelm
parents: 20475
diff changeset
   730
  \begin{description}
wenzelm
parents: 20475
diff changeset
   731
wenzelm
parents: 20475
diff changeset
   732
  \item \verb|indexname| represents indexed names.  This is an
wenzelm
parents: 20475
diff changeset
   733
  abbreviation for \verb|string * int|.  The second component is
wenzelm
parents: 20475
diff changeset
   734
  usually non-negative, except for situations where \isa{{\isacharparenleft}x{\isacharcomma}\ {\isacharminus}{\isadigit{1}}{\isacharparenright}}
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   735
  is used to embed basic names into this type.
20477
wenzelm
parents: 20475
diff changeset
   736
wenzelm
parents: 20475
diff changeset
   737
  \end{description}%
20451
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   738
\end{isamarkuptext}%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   739
\isamarkuptrue%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   740
%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   741
\endisatagmlref
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   742
{\isafoldmlref}%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   743
%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   744
\isadelimmlref
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   745
%
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   746
\endisadelimmlref
27ea2ba48fa3 misc cleanup;
wenzelm
parents: 20450
diff changeset
   747
%
20477
wenzelm
parents: 20475
diff changeset
   748
\isamarkupsubsection{Qualified names and name spaces%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   749
}
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   750
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   751
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   752
\begin{isamarkuptext}%
20477
wenzelm
parents: 20475
diff changeset
   753
A \emph{qualified name} consists of a non-empty sequence of basic
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   754
  name components.  The packed representation uses a dot as separator,
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   755
  as in ``\isa{A{\isachardot}b{\isachardot}c}''.  The last component is called \emph{base}
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   756
  name, the remaining prefix \emph{qualifier} (which may be empty).
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   757
  The idea of qualified names is to encode nested structures by
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   758
  recording the access paths as qualifiers.  For example, an item
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   759
  named ``\isa{A{\isachardot}b{\isachardot}c}'' may be understood as a local entity \isa{c}, within a local structure \isa{b}, within a global
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   760
  structure \isa{A}.  Typically, name space hierarchies consist of
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   761
  1--2 levels of qualification, but this need not be always so.
20477
wenzelm
parents: 20475
diff changeset
   762
wenzelm
parents: 20475
diff changeset
   763
  The empty name is commonly used as an indication of unnamed
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   764
  entities, whenever this makes any sense.  The basic operations on
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   765
  qualified names are smart enough to pass through such improper names
20477
wenzelm
parents: 20475
diff changeset
   766
  unchanged.
wenzelm
parents: 20475
diff changeset
   767
wenzelm
parents: 20475
diff changeset
   768
  \medskip A \isa{naming} policy tells how to turn a name
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   769
  specification into a fully qualified internal name (by the \isa{full} operation), and how fully qualified names may be accessed
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   770
  externally.  For example, the default naming policy is to prefix an
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   771
  implicit path: \isa{full\ x} produces \isa{path{\isachardot}x}, and the
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   772
  standard accesses for \isa{path{\isachardot}x} include both \isa{x} and
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   773
  \isa{path{\isachardot}x}.  Normally, the naming is implicit in the theory or
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   774
  proof context; there are separate versions of the corresponding.
20477
wenzelm
parents: 20475
diff changeset
   775
wenzelm
parents: 20475
diff changeset
   776
  \medskip A \isa{name\ space} manages a collection of fully
wenzelm
parents: 20475
diff changeset
   777
  internalized names, together with a mapping between external names
wenzelm
parents: 20475
diff changeset
   778
  and internal names (in both directions).  The corresponding \isa{intern} and \isa{extern} operations are mostly used for
wenzelm
parents: 20475
diff changeset
   779
  parsing and printing only!  The \isa{declare} operation augments
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   780
  a name space according to the accesses determined by the naming
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   781
  policy.
20477
wenzelm
parents: 20475
diff changeset
   782
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   783
  \medskip As a general principle, there is a separate name space for
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   784
  each kind of formal entity, e.g.\ logical constant, type
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   785
  constructor, type class, theorem.  It is usually clear from the
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   786
  occurrence in concrete syntax (or from the scope) which kind of
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   787
  entity a name refers to.  For example, the very same name \isa{c} may be used uniformly for a constant, type constructor, and
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   788
  type class.
20477
wenzelm
parents: 20475
diff changeset
   789
20481
c96f80442ce6 updated;
wenzelm
parents: 20477
diff changeset
   790
  There are common schemes to name theorems systematically, according
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   791
  to the name of the main logical entity involved, e.g.\ \isa{c{\isachardot}intro} for a canonical theorem related to constant \isa{c}.
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   792
  This technique of mapping names from one space into another requires
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   793
  some care in order to avoid conflicts.  In particular, theorem names
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   794
  derived from a type constructor or type class are better suffixed in
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   795
  addition to the usual qualification, e.g.\ \isa{c{\isacharunderscore}type{\isachardot}intro}
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   796
  and \isa{c{\isacharunderscore}class{\isachardot}intro} for theorems related to type \isa{c}
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   797
  and class \isa{c}, respectively.%
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   798
\end{isamarkuptext}%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   799
\isamarkuptrue%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   800
%
20477
wenzelm
parents: 20475
diff changeset
   801
\isadelimmlref
wenzelm
parents: 20475
diff changeset
   802
%
wenzelm
parents: 20475
diff changeset
   803
\endisadelimmlref
wenzelm
parents: 20475
diff changeset
   804
%
wenzelm
parents: 20475
diff changeset
   805
\isatagmlref
20438
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   806
%
9060c73a4578 updated;
wenzelm
parents: 20430
diff changeset
   807
\begin{isamarkuptext}%
20477
wenzelm
parents: 20475
diff changeset
   808
\begin{mldecls}
wenzelm
parents: 20475
diff changeset
   809
  \indexml{NameSpace.base}\verb|NameSpace.base: string -> string| \\
20530
448594cbd82b renamed NameSpace.drop_base to NameSpace.qualifier;
wenzelm
parents: 20490
diff changeset
   810
  \indexml{NameSpace.qualifier}\verb|NameSpace.qualifier: string -> string| \\
20477
wenzelm
parents: 20475
diff changeset
   811
  \indexml{NameSpace.append}\verb|NameSpace.append: string -> string -> string| \\
21862
13e9febe3080 updated;
wenzelm
parents: 20547
diff changeset
   812
  \indexml{NameSpace.implode}\verb|NameSpace.implode: string list -> string| \\
13e9febe3080 updated;
wenzelm
parents: 20547
diff changeset
   813
  \indexml{NameSpace.explode}\verb|NameSpace.explode: string -> string list| \\
20547
wenzelm
parents: 20530
diff changeset
   814
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   815
  \begin{mldecls}
20477
wenzelm
parents: 20475
diff changeset
   816
  \indexmltype{NameSpace.naming}\verb|type NameSpace.naming| \\
26854
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   817
  \indexml{NameSpace.default\_naming}\verb|NameSpace.default_naming: NameSpace.naming| \\
9b4aec46ad78 improved treatment of "_" thanks to underscore.sty;
wenzelm
parents: 24138
diff changeset
   818
  \indexml{NameSpace.add\_path}\verb|NameSpace.add_path: string -> NameSpace.naming -> NameSpace.naming| \\
20547
wenzelm
parents: 20530
diff changeset
   819
  \indexml{NameSpace.full}\verb|NameSpace.full: NameSpace.naming -> string -> string| \\
wenzelm
parents: 20530
diff changeset
   820
  \end{mldecls}
wenzelm
parents: 20530
diff changeset
   821
  \begin{mldecls}
20477
wenzelm
parents: 20475
diff changeset
   822
  \indexmltype{NameSpace.T}\verb|type NameSpace.T| \\
wenzelm
parents: 20475
diff changeset
   823
  \indexml{NameSpace.empty}\verb|NameSpace.empty: NameSpace.T| \\
wenzelm
parents: 20475
diff changeset
   824
  \indexml{NameSpace.merge}\verb|NameSpace.merge: NameSpace.T * NameSpace.T -> NameSpace.T| \\
wenzelm
parents: 20475
diff changeset
   825
  \indexml{NameSpace.declare}\verb|NameSpace.declare: NameSpace.naming -> string -> NameSpace.T -> NameSpace.T| \\
wenzelm
parents: 20475
diff changeset
   826
  \indexml{NameSpace.intern}\verb|NameSpace.intern: NameSpace.T -> string -> string| \\
wenzelm
parents: 20475
diff changeset
   827
  \indexml{NameSpace.extern}\verb|NameSpace.extern: NameSpace.T -> string -> string| \\
wenzelm
parents: 20475
diff changeset
   828
  \end{mldecls}
wenzelm
parents: 20475
diff changeset
   829
wenzelm
parents: 20475
diff changeset
   830
  \begin{description}
wenzelm
parents: 20475
diff changeset
   831
wenzelm
parents: 20475
diff changeset
   832
  \item \verb|NameSpace.base|~\isa{name} returns the base name of a
wenzelm
parents: 20475
diff changeset
   833
  qualified name.
wenzelm
parents: 20475
diff changeset
   834
20530
448594cbd82b renamed NameSpace.drop_base to NameSpace.qualifier;
wenzelm
parents: 20490
diff changeset
   835
  \item \verb|NameSpace.qualifier|~\isa{name} returns the qualifier
20477
wenzelm
parents: 20475
diff changeset
   836
  of a qualified name.
wenzelm
parents: 20475
diff changeset
   837
wenzelm
parents: 20475
diff changeset
   838
  \item \verb|NameSpace.append|~\isa{name\isactrlisub {\isadigit{1}}\ name\isactrlisub {\isadigit{2}}}
wenzelm
parents: 20475
diff changeset
   839
  appends two qualified names.
wenzelm
parents: 20475
diff changeset
   840
21862
13e9febe3080 updated;
wenzelm
parents: 20547
diff changeset
   841
  \item \verb|NameSpace.implode|~\isa{name} and \verb|NameSpace.explode|~\isa{names} convert between the packed string
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   842
  representation and the explicit list form of qualified names.
20477
wenzelm
parents: 20475
diff changeset
   843
wenzelm
parents: 20475
diff changeset
   844
  \item \verb|NameSpace.naming| represents the abstract concept of
wenzelm
parents: 20475
diff changeset
   845
  a naming policy.
wenzelm
parents: 20475
diff changeset
   846
wenzelm
parents: 20475
diff changeset
   847
  \item \verb|NameSpace.default_naming| is the default naming policy.
wenzelm
parents: 20475
diff changeset
   848
  In a theory context, this is usually augmented by a path prefix
wenzelm
parents: 20475
diff changeset
   849
  consisting of the theory name.
wenzelm
parents: 20475
diff changeset
   850
wenzelm
parents: 20475
diff changeset
   851
  \item \verb|NameSpace.add_path|~\isa{path\ naming} augments the
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   852
  naming policy by extending its path component.
20477
wenzelm
parents: 20475
diff changeset
   853
wenzelm
parents: 20475
diff changeset
   854
  \item \verb|NameSpace.full|\isa{naming\ name} turns a name
wenzelm
parents: 20475
diff changeset
   855
  specification (usually a basic name) into the fully qualified
wenzelm
parents: 20475
diff changeset
   856
  internal version, according to the given naming policy.
wenzelm
parents: 20475
diff changeset
   857
wenzelm
parents: 20475
diff changeset
   858
  \item \verb|NameSpace.T| represents name spaces.
wenzelm
parents: 20475
diff changeset
   859
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   860
  \item \verb|NameSpace.empty| and \verb|NameSpace.merge|~\isa{{\isacharparenleft}space\isactrlisub {\isadigit{1}}{\isacharcomma}\ space\isactrlisub {\isadigit{2}}{\isacharparenright}} are the canonical operations for
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   861
  maintaining name spaces according to theory data management
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   862
  (\secref{sec:context-data}).
20477
wenzelm
parents: 20475
diff changeset
   863
wenzelm
parents: 20475
diff changeset
   864
  \item \verb|NameSpace.declare|~\isa{naming\ name\ space} enters a
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   865
  fully qualified name into the name space, with external accesses
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   866
  determined by the naming policy.
20477
wenzelm
parents: 20475
diff changeset
   867
wenzelm
parents: 20475
diff changeset
   868
  \item \verb|NameSpace.intern|~\isa{space\ name} internalizes a
wenzelm
parents: 20475
diff changeset
   869
  (partially qualified) external name.
wenzelm
parents: 20475
diff changeset
   870
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   871
  This operation is mostly for parsing!  Note that fully qualified
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   872
  names stemming from declarations are produced via \verb|NameSpace.full| (or its derivatives for \verb|theory| and
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   873
  \verb|Proof.context|).
20477
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
20490
e502690952be updated;
wenzelm
parents: 20481
diff changeset
   878
  This operation is mostly for printing!  Note unqualified names are
20477
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: