wenzelm@30296
|
1 |
%
|
wenzelm@30296
|
2 |
\begin{isabellebody}%
|
wenzelm@30296
|
3 |
\def\isabellecontext{Prelim}%
|
wenzelm@30296
|
4 |
%
|
wenzelm@30296
|
5 |
\isadelimtheory
|
wenzelm@30296
|
6 |
%
|
wenzelm@30296
|
7 |
\endisadelimtheory
|
wenzelm@30296
|
8 |
%
|
wenzelm@30296
|
9 |
\isatagtheory
|
wenzelm@30296
|
10 |
\isacommand{theory}\isamarkupfalse%
|
wenzelm@30296
|
11 |
\ Prelim\isanewline
|
wenzelm@30296
|
12 |
\isakeyword{imports}\ Base\isanewline
|
wenzelm@30296
|
13 |
\isakeyword{begin}%
|
wenzelm@30296
|
14 |
\endisatagtheory
|
wenzelm@30296
|
15 |
{\isafoldtheory}%
|
wenzelm@30296
|
16 |
%
|
wenzelm@30296
|
17 |
\isadelimtheory
|
wenzelm@30296
|
18 |
%
|
wenzelm@30296
|
19 |
\endisadelimtheory
|
wenzelm@30296
|
20 |
%
|
wenzelm@30296
|
21 |
\isamarkupchapter{Preliminaries%
|
wenzelm@30296
|
22 |
}
|
wenzelm@30296
|
23 |
\isamarkuptrue%
|
wenzelm@30296
|
24 |
%
|
wenzelm@30296
|
25 |
\isamarkupsection{Contexts \label{sec:context}%
|
wenzelm@30296
|
26 |
}
|
wenzelm@30296
|
27 |
\isamarkuptrue%
|
wenzelm@30296
|
28 |
%
|
wenzelm@30296
|
29 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
30 |
A logical context represents the background that is required for
|
wenzelm@30296
|
31 |
formulating statements and composing proofs. It acts as a medium to
|
wenzelm@30296
|
32 |
produce formal content, depending on earlier material (declarations,
|
wenzelm@30296
|
33 |
results etc.).
|
wenzelm@30296
|
34 |
|
wenzelm@30296
|
35 |
For example, derivations within the Isabelle/Pure logic can be
|
wenzelm@30296
|
36 |
described as a judgment \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}, which means that a
|
wenzelm@30296
|
37 |
proposition \isa{{\isasymphi}} is derivable from hypotheses \isa{{\isasymGamma}}
|
wenzelm@30296
|
38 |
within the theory \isa{{\isasymTheta}}. There are logical reasons for
|
wenzelm@30296
|
39 |
keeping \isa{{\isasymTheta}} and \isa{{\isasymGamma}} separate: theories can be
|
wenzelm@30296
|
40 |
liberal about supporting type constructors and schematic
|
wenzelm@30296
|
41 |
polymorphism of constants and axioms, while the inner calculus of
|
wenzelm@30296
|
42 |
\isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}} is strictly limited to Simple Type Theory (with
|
wenzelm@30296
|
43 |
fixed type variables in the assumptions).
|
wenzelm@30296
|
44 |
|
wenzelm@30296
|
45 |
\medskip Contexts and derivations are linked by the following key
|
wenzelm@30296
|
46 |
principles:
|
wenzelm@30296
|
47 |
|
wenzelm@30296
|
48 |
\begin{itemize}
|
wenzelm@30296
|
49 |
|
wenzelm@30296
|
50 |
\item Transfer: monotonicity of derivations admits results to be
|
wenzelm@30296
|
51 |
transferred into a \emph{larger} context, i.e.\ \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}} implies \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\isactrlsub {\isacharprime}\ {\isasymphi}} for contexts \isa{{\isasymTheta}{\isacharprime}\ {\isasymsupseteq}\ {\isasymTheta}} and \isa{{\isasymGamma}{\isacharprime}\ {\isasymsupseteq}\ {\isasymGamma}}.
|
wenzelm@30296
|
52 |
|
wenzelm@30296
|
53 |
\item Export: discharge of hypotheses admits results to be exported
|
wenzelm@30296
|
54 |
into a \emph{smaller} context, i.e.\ \isa{{\isasymGamma}{\isacharprime}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymphi}}
|
wenzelm@30296
|
55 |
implies \isa{{\isasymGamma}\ {\isasymturnstile}\isactrlsub {\isasymTheta}\ {\isasymDelta}\ {\isasymLongrightarrow}\ {\isasymphi}} where \isa{{\isasymGamma}{\isacharprime}\ {\isasymsupseteq}\ {\isasymGamma}} and
|
wenzelm@30296
|
56 |
\isa{{\isasymDelta}\ {\isacharequal}\ {\isasymGamma}{\isacharprime}\ {\isacharminus}\ {\isasymGamma}}. Note that \isa{{\isasymTheta}} remains unchanged here,
|
wenzelm@30296
|
57 |
only the \isa{{\isasymGamma}} part is affected.
|
wenzelm@30296
|
58 |
|
wenzelm@30296
|
59 |
\end{itemize}
|
wenzelm@30296
|
60 |
|
wenzelm@30296
|
61 |
\medskip By modeling the main characteristics of the primitive
|
wenzelm@30296
|
62 |
\isa{{\isasymTheta}} and \isa{{\isasymGamma}} above, and abstracting over any
|
wenzelm@30296
|
63 |
particular logical content, we arrive at the fundamental notions of
|
wenzelm@30296
|
64 |
\emph{theory context} and \emph{proof context} in Isabelle/Isar.
|
wenzelm@30296
|
65 |
These implement a certain policy to manage arbitrary \emph{context
|
wenzelm@30296
|
66 |
data}. There is a strongly-typed mechanism to declare new kinds of
|
wenzelm@30296
|
67 |
data at compile time.
|
wenzelm@30296
|
68 |
|
wenzelm@30296
|
69 |
The internal bootstrap process of Isabelle/Pure eventually reaches a
|
wenzelm@30296
|
70 |
stage where certain data slots provide the logical content of \isa{{\isasymTheta}} and \isa{{\isasymGamma}} sketched above, but this does not stop there!
|
wenzelm@30296
|
71 |
Various additional data slots support all kinds of mechanisms that
|
wenzelm@30296
|
72 |
are not necessarily part of the core logic.
|
wenzelm@30296
|
73 |
|
wenzelm@30296
|
74 |
For example, there would be data for canonical introduction and
|
wenzelm@30296
|
75 |
elimination rules for arbitrary operators (depending on the
|
wenzelm@30296
|
76 |
object-logic and application), which enables users to perform
|
wenzelm@30296
|
77 |
standard proof steps implicitly (cf.\ the \isa{rule} method
|
wenzelm@30296
|
78 |
\cite{isabelle-isar-ref}).
|
wenzelm@30296
|
79 |
|
wenzelm@30296
|
80 |
\medskip Thus Isabelle/Isar is able to bring forth more and more
|
wenzelm@30296
|
81 |
concepts successively. In particular, an object-logic like
|
wenzelm@30296
|
82 |
Isabelle/HOL continues the Isabelle/Pure setup by adding specific
|
wenzelm@30296
|
83 |
components for automated reasoning (classical reasoner, tableau
|
wenzelm@30296
|
84 |
prover, structured induction etc.) and derived specification
|
wenzelm@30296
|
85 |
mechanisms (inductive predicates, recursive functions etc.). All of
|
wenzelm@30296
|
86 |
this is ultimately based on the generic data management by theory
|
wenzelm@30296
|
87 |
and proof contexts introduced here.%
|
wenzelm@30296
|
88 |
\end{isamarkuptext}%
|
wenzelm@30296
|
89 |
\isamarkuptrue%
|
wenzelm@30296
|
90 |
%
|
wenzelm@30296
|
91 |
\isamarkupsubsection{Theory context \label{sec:context-theory}%
|
wenzelm@30296
|
92 |
}
|
wenzelm@30296
|
93 |
\isamarkuptrue%
|
wenzelm@30296
|
94 |
%
|
wenzelm@30296
|
95 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
96 |
A \emph{theory} is a data container with explicit name and
|
wenzelm@35001
|
97 |
unique identifier. Theories are related by a (nominal) sub-theory
|
wenzelm@30296
|
98 |
relation, which corresponds to the dependency graph of the original
|
wenzelm@30296
|
99 |
construction; each theory is derived from a certain sub-graph of
|
wenzelm@35001
|
100 |
ancestor theories. To this end, the system maintains a set of
|
wenzelm@35001
|
101 |
symbolic ``identification stamps'' within each theory.
|
wenzelm@30296
|
102 |
|
wenzelm@35001
|
103 |
In order to avoid the full-scale overhead of explicit sub-theory
|
wenzelm@35001
|
104 |
identification of arbitrary intermediate stages, a theory is
|
wenzelm@35001
|
105 |
switched into \isa{draft} mode under certain circumstances. A
|
wenzelm@35001
|
106 |
draft theory acts like a linear type, where updates invalidate
|
wenzelm@35001
|
107 |
earlier versions. An invalidated draft is called \emph{stale}.
|
wenzelm@30296
|
108 |
|
wenzelm@35001
|
109 |
The \isa{checkpoint} operation produces a safe stepping stone
|
wenzelm@35001
|
110 |
that will survive the next update without becoming stale: both the
|
wenzelm@35001
|
111 |
old and the new theory remain valid and are related by the
|
wenzelm@35001
|
112 |
sub-theory relation. Checkpointing essentially recovers purely
|
wenzelm@35001
|
113 |
functional theory values, at the expense of some extra internal
|
wenzelm@35001
|
114 |
bookkeeping.
|
wenzelm@30296
|
115 |
|
wenzelm@30296
|
116 |
The \isa{copy} operation produces an auxiliary version that has
|
wenzelm@30296
|
117 |
the same data content, but is unrelated to the original: updates of
|
wenzelm@30296
|
118 |
the copy do not affect the original, neither does the sub-theory
|
wenzelm@30296
|
119 |
relation hold.
|
wenzelm@30296
|
120 |
|
wenzelm@35001
|
121 |
The \isa{merge} operation produces the least upper bound of two
|
wenzelm@35001
|
122 |
theories, which actually degenerates into absorption of one theory
|
wenzelm@35001
|
123 |
into the other (according to the nominal sub-theory relation).
|
wenzelm@35001
|
124 |
|
wenzelm@35001
|
125 |
The \isa{begin} operation starts a new theory by importing
|
wenzelm@35001
|
126 |
several parent theories and entering a special mode of nameless
|
wenzelm@35001
|
127 |
incremental updates, until the final \isa{end} operation is
|
wenzelm@35001
|
128 |
performed.
|
wenzelm@35001
|
129 |
|
wenzelm@30296
|
130 |
\medskip The example in \figref{fig:ex-theory} below shows a theory
|
wenzelm@30296
|
131 |
graph derived from \isa{Pure}, with theory \isa{Length}
|
wenzelm@30296
|
132 |
importing \isa{Nat} and \isa{List}. The body of \isa{Length} consists of a sequence of updates, working mostly on
|
wenzelm@35001
|
133 |
drafts internally, while transaction boundaries of Isar top-level
|
wenzelm@35001
|
134 |
commands (\secref{sec:isar-toplevel}) are guaranteed to be safe
|
wenzelm@35001
|
135 |
checkpoints.
|
wenzelm@30296
|
136 |
|
wenzelm@30296
|
137 |
\begin{figure}[htb]
|
wenzelm@30296
|
138 |
\begin{center}
|
wenzelm@30296
|
139 |
\begin{tabular}{rcccl}
|
wenzelm@30296
|
140 |
& & \isa{Pure} \\
|
wenzelm@30296
|
141 |
& & \isa{{\isasymdown}} \\
|
wenzelm@30296
|
142 |
& & \isa{FOL} \\
|
wenzelm@30296
|
143 |
& $\swarrow$ & & $\searrow$ & \\
|
wenzelm@30296
|
144 |
\isa{Nat} & & & & \isa{List} \\
|
wenzelm@30296
|
145 |
& $\searrow$ & & $\swarrow$ \\
|
wenzelm@30296
|
146 |
& & \isa{Length} \\
|
wenzelm@30296
|
147 |
& & \multicolumn{3}{l}{~~\hyperlink{keyword.imports}{\mbox{\isa{\isakeyword{imports}}}}} \\
|
wenzelm@30296
|
148 |
& & \multicolumn{3}{l}{~~\hyperlink{keyword.begin}{\mbox{\isa{\isakeyword{begin}}}}} \\
|
wenzelm@30296
|
149 |
& & $\vdots$~~ \\
|
wenzelm@30296
|
150 |
& & \isa{{\isasymbullet}}~~ \\
|
wenzelm@30296
|
151 |
& & $\vdots$~~ \\
|
wenzelm@30296
|
152 |
& & \isa{{\isasymbullet}}~~ \\
|
wenzelm@30296
|
153 |
& & $\vdots$~~ \\
|
wenzelm@30296
|
154 |
& & \multicolumn{3}{l}{~~\hyperlink{command.end}{\mbox{\isa{\isacommand{end}}}}} \\
|
wenzelm@30296
|
155 |
\end{tabular}
|
wenzelm@30296
|
156 |
\caption{A theory definition depending on ancestors}\label{fig:ex-theory}
|
wenzelm@30296
|
157 |
\end{center}
|
wenzelm@30296
|
158 |
\end{figure}
|
wenzelm@30296
|
159 |
|
wenzelm@30296
|
160 |
\medskip There is a separate notion of \emph{theory reference} for
|
wenzelm@30296
|
161 |
maintaining a live link to an evolving theory context: updates on
|
wenzelm@30296
|
162 |
drafts are propagated automatically. Dynamic updating stops after
|
wenzelm@30296
|
163 |
an explicit \isa{end} only.
|
wenzelm@30296
|
164 |
|
wenzelm@30296
|
165 |
Derived entities may store a theory reference in order to indicate
|
wenzelm@30296
|
166 |
the context they belong to. This implicitly assumes monotonic
|
wenzelm@30296
|
167 |
reasoning, because the referenced context may become larger without
|
wenzelm@30296
|
168 |
further notice.%
|
wenzelm@30296
|
169 |
\end{isamarkuptext}%
|
wenzelm@30296
|
170 |
\isamarkuptrue%
|
wenzelm@30296
|
171 |
%
|
wenzelm@30296
|
172 |
\isadelimmlref
|
wenzelm@30296
|
173 |
%
|
wenzelm@30296
|
174 |
\endisadelimmlref
|
wenzelm@30296
|
175 |
%
|
wenzelm@30296
|
176 |
\isatagmlref
|
wenzelm@30296
|
177 |
%
|
wenzelm@30296
|
178 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
179 |
\begin{mldecls}
|
wenzelm@30296
|
180 |
\indexdef{}{ML type}{theory}\verb|type theory| \\
|
wenzelm@30296
|
181 |
\indexdef{}{ML}{Theory.subthy}\verb|Theory.subthy: theory * theory -> bool| \\
|
wenzelm@30296
|
182 |
\indexdef{}{ML}{Theory.checkpoint}\verb|Theory.checkpoint: theory -> theory| \\
|
wenzelm@30296
|
183 |
\indexdef{}{ML}{Theory.copy}\verb|Theory.copy: theory -> theory| \\
|
wenzelm@35001
|
184 |
\indexdef{}{ML}{Theory.merge}\verb|Theory.merge: theory * theory -> theory| \\
|
wenzelm@35001
|
185 |
\indexdef{}{ML}{Theory.begin\_theory}\verb|Theory.begin_theory: string -> theory list -> theory| \\
|
wenzelm@30296
|
186 |
\end{mldecls}
|
wenzelm@30296
|
187 |
\begin{mldecls}
|
wenzelm@30296
|
188 |
\indexdef{}{ML type}{theory\_ref}\verb|type theory_ref| \\
|
wenzelm@30296
|
189 |
\indexdef{}{ML}{Theory.deref}\verb|Theory.deref: theory_ref -> theory| \\
|
wenzelm@30296
|
190 |
\indexdef{}{ML}{Theory.check\_thy}\verb|Theory.check_thy: theory -> theory_ref| \\
|
wenzelm@30296
|
191 |
\end{mldecls}
|
wenzelm@30296
|
192 |
|
wenzelm@30296
|
193 |
\begin{description}
|
wenzelm@30296
|
194 |
|
wenzelm@30296
|
195 |
\item \verb|theory| represents theory contexts. This is
|
wenzelm@35001
|
196 |
essentially a linear type, with explicit runtime checking! Most
|
wenzelm@35001
|
197 |
internal theory operations destroy the original version, which then
|
wenzelm@35001
|
198 |
becomes ``stale''.
|
wenzelm@30296
|
199 |
|
wenzelm@35001
|
200 |
\item \verb|Theory.subthy|~\isa{{\isacharparenleft}thy\isactrlsub {\isadigit{1}}{\isacharcomma}\ thy\isactrlsub {\isadigit{2}}{\isacharparenright}} compares theories
|
wenzelm@35001
|
201 |
according to the intrinsic graph structure of the construction.
|
wenzelm@35001
|
202 |
This sub-theory relation is a nominal approximation of inclusion
|
wenzelm@35001
|
203 |
(\isa{{\isasymsubseteq}}) of the corresponding content (according to the
|
wenzelm@35001
|
204 |
semantics of the ML modules that implement the data).
|
wenzelm@30296
|
205 |
|
wenzelm@30296
|
206 |
\item \verb|Theory.checkpoint|~\isa{thy} produces a safe
|
wenzelm@35001
|
207 |
stepping stone in the linear development of \isa{thy}. This
|
wenzelm@35001
|
208 |
changes the old theory, but the next update will result in two
|
wenzelm@35001
|
209 |
related, valid theories.
|
wenzelm@30296
|
210 |
|
wenzelm@35001
|
211 |
\item \verb|Theory.copy|~\isa{thy} produces a variant of \isa{thy} with the same data. The copy is not related to the original,
|
wenzelm@35001
|
212 |
but the original is unchanged.
|
wenzelm@35001
|
213 |
|
wenzelm@35001
|
214 |
\item \verb|Theory.merge|~\isa{{\isacharparenleft}thy\isactrlsub {\isadigit{1}}{\isacharcomma}\ thy\isactrlsub {\isadigit{2}}{\isacharparenright}} absorbs one theory
|
wenzelm@35001
|
215 |
into the other, without changing \isa{thy\isactrlsub {\isadigit{1}}} or \isa{thy\isactrlsub {\isadigit{2}}}.
|
wenzelm@35001
|
216 |
This version of ad-hoc theory merge fails for unrelated theories!
|
wenzelm@35001
|
217 |
|
wenzelm@35001
|
218 |
\item \verb|Theory.begin_theory|~\isa{name\ parents} constructs
|
wenzelm@35001
|
219 |
a new theory based on the given parents. This {\ML} function is
|
wenzelm@35001
|
220 |
normally not invoked directly.
|
wenzelm@30296
|
221 |
|
wenzelm@30296
|
222 |
\item \verb|theory_ref| represents a sliding reference to an
|
wenzelm@30296
|
223 |
always valid theory; updates on the original are propagated
|
wenzelm@30296
|
224 |
automatically.
|
wenzelm@30296
|
225 |
|
wenzelm@30296
|
226 |
\item \verb|Theory.deref|~\isa{thy{\isacharunderscore}ref} turns a \verb|theory_ref| into an \verb|theory| value. As the referenced
|
wenzelm@30296
|
227 |
theory evolves monotonically over time, later invocations of \verb|Theory.deref| may refer to a larger context.
|
wenzelm@30296
|
228 |
|
wenzelm@30296
|
229 |
\item \verb|Theory.check_thy|~\isa{thy} produces a \verb|theory_ref| from a valid \verb|theory| value.
|
wenzelm@30296
|
230 |
|
wenzelm@30296
|
231 |
\end{description}%
|
wenzelm@30296
|
232 |
\end{isamarkuptext}%
|
wenzelm@30296
|
233 |
\isamarkuptrue%
|
wenzelm@30296
|
234 |
%
|
wenzelm@30296
|
235 |
\endisatagmlref
|
wenzelm@30296
|
236 |
{\isafoldmlref}%
|
wenzelm@30296
|
237 |
%
|
wenzelm@30296
|
238 |
\isadelimmlref
|
wenzelm@30296
|
239 |
%
|
wenzelm@30296
|
240 |
\endisadelimmlref
|
wenzelm@30296
|
241 |
%
|
wenzelm@30296
|
242 |
\isamarkupsubsection{Proof context \label{sec:context-proof}%
|
wenzelm@30296
|
243 |
}
|
wenzelm@30296
|
244 |
\isamarkuptrue%
|
wenzelm@30296
|
245 |
%
|
wenzelm@30296
|
246 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
247 |
A proof context is a container for pure data with a
|
wenzelm@35001
|
248 |
back-reference to the theory it belongs to. The \isa{init}
|
wenzelm@35001
|
249 |
operation creates a proof context from a given theory.
|
wenzelm@35001
|
250 |
Modifications to draft theories are propagated to the proof context
|
wenzelm@35001
|
251 |
as usual, but there is also an explicit \isa{transfer} operation
|
wenzelm@35001
|
252 |
to force resynchronization with more substantial updates to the
|
wenzelm@35001
|
253 |
underlying theory.
|
wenzelm@30296
|
254 |
|
wenzelm@35001
|
255 |
Entities derived in a proof context need to record logical
|
wenzelm@30296
|
256 |
requirements explicitly, since there is no separate context
|
wenzelm@35001
|
257 |
identification or symbolic inclusion as for theories. For example,
|
wenzelm@35001
|
258 |
hypotheses used in primitive derivations (cf.\ \secref{sec:thms})
|
wenzelm@35001
|
259 |
are recorded separately within the sequent \isa{{\isasymGamma}\ {\isasymturnstile}\ {\isasymphi}}, just to
|
wenzelm@35001
|
260 |
make double sure. Results could still leak into an alien proof
|
wenzelm@35001
|
261 |
context due to programming errors, but Isabelle/Isar includes some
|
wenzelm@35001
|
262 |
extra validity checks in critical positions, notably at the end of a
|
wenzelm@35001
|
263 |
sub-proof.
|
wenzelm@30296
|
264 |
|
wenzelm@30296
|
265 |
Proof contexts may be manipulated arbitrarily, although the common
|
wenzelm@30296
|
266 |
discipline is to follow block structure as a mental model: a given
|
wenzelm@30296
|
267 |
context is extended consecutively, and results are exported back
|
wenzelm@35001
|
268 |
into the original context. Note that an Isar proof state models
|
wenzelm@30296
|
269 |
block-structured reasoning explicitly, using a stack of proof
|
wenzelm@35001
|
270 |
contexts internally. For various technical reasons, the background
|
wenzelm@35001
|
271 |
theory of an Isar proof state must not be changed while the proof is
|
wenzelm@35001
|
272 |
still under construction!%
|
wenzelm@30296
|
273 |
\end{isamarkuptext}%
|
wenzelm@30296
|
274 |
\isamarkuptrue%
|
wenzelm@30296
|
275 |
%
|
wenzelm@30296
|
276 |
\isadelimmlref
|
wenzelm@30296
|
277 |
%
|
wenzelm@30296
|
278 |
\endisadelimmlref
|
wenzelm@30296
|
279 |
%
|
wenzelm@30296
|
280 |
\isatagmlref
|
wenzelm@30296
|
281 |
%
|
wenzelm@30296
|
282 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
283 |
\begin{mldecls}
|
wenzelm@30296
|
284 |
\indexdef{}{ML type}{Proof.context}\verb|type Proof.context| \\
|
wenzelm@30296
|
285 |
\indexdef{}{ML}{ProofContext.init}\verb|ProofContext.init: theory -> Proof.context| \\
|
wenzelm@30296
|
286 |
\indexdef{}{ML}{ProofContext.theory\_of}\verb|ProofContext.theory_of: Proof.context -> theory| \\
|
wenzelm@30296
|
287 |
\indexdef{}{ML}{ProofContext.transfer}\verb|ProofContext.transfer: theory -> Proof.context -> Proof.context| \\
|
wenzelm@30296
|
288 |
\end{mldecls}
|
wenzelm@30296
|
289 |
|
wenzelm@30296
|
290 |
\begin{description}
|
wenzelm@30296
|
291 |
|
wenzelm@30296
|
292 |
\item \verb|Proof.context| represents proof contexts. Elements
|
wenzelm@30296
|
293 |
of this type are essentially pure values, with a sliding reference
|
wenzelm@30296
|
294 |
to the background theory.
|
wenzelm@30296
|
295 |
|
wenzelm@30296
|
296 |
\item \verb|ProofContext.init|~\isa{thy} produces a proof context
|
wenzelm@30296
|
297 |
derived from \isa{thy}, initializing all data.
|
wenzelm@30296
|
298 |
|
wenzelm@30296
|
299 |
\item \verb|ProofContext.theory_of|~\isa{ctxt} selects the
|
wenzelm@30296
|
300 |
background theory from \isa{ctxt}, dereferencing its internal
|
wenzelm@30296
|
301 |
\verb|theory_ref|.
|
wenzelm@30296
|
302 |
|
wenzelm@30296
|
303 |
\item \verb|ProofContext.transfer|~\isa{thy\ ctxt} promotes the
|
wenzelm@30296
|
304 |
background theory of \isa{ctxt} to the super theory \isa{thy}.
|
wenzelm@30296
|
305 |
|
wenzelm@30296
|
306 |
\end{description}%
|
wenzelm@30296
|
307 |
\end{isamarkuptext}%
|
wenzelm@30296
|
308 |
\isamarkuptrue%
|
wenzelm@30296
|
309 |
%
|
wenzelm@30296
|
310 |
\endisatagmlref
|
wenzelm@30296
|
311 |
{\isafoldmlref}%
|
wenzelm@30296
|
312 |
%
|
wenzelm@30296
|
313 |
\isadelimmlref
|
wenzelm@30296
|
314 |
%
|
wenzelm@30296
|
315 |
\endisadelimmlref
|
wenzelm@30296
|
316 |
%
|
wenzelm@30296
|
317 |
\isamarkupsubsection{Generic contexts \label{sec:generic-context}%
|
wenzelm@30296
|
318 |
}
|
wenzelm@30296
|
319 |
\isamarkuptrue%
|
wenzelm@30296
|
320 |
%
|
wenzelm@30296
|
321 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
322 |
A generic context is the disjoint sum of either a theory or proof
|
wenzelm@30296
|
323 |
context. Occasionally, this enables uniform treatment of generic
|
wenzelm@30296
|
324 |
context data, typically extra-logical information. Operations on
|
wenzelm@30296
|
325 |
generic contexts include the usual injections, partial selections,
|
wenzelm@30296
|
326 |
and combinators for lifting operations on either component of the
|
wenzelm@30296
|
327 |
disjoint sum.
|
wenzelm@30296
|
328 |
|
wenzelm@30296
|
329 |
Moreover, there are total operations \isa{theory{\isacharunderscore}of} and \isa{proof{\isacharunderscore}of} to convert a generic context into either kind: a theory
|
wenzelm@30296
|
330 |
can always be selected from the sum, while a proof context might
|
wenzelm@35001
|
331 |
have to be constructed by an ad-hoc \isa{init} operation, which
|
wenzelm@35001
|
332 |
incurs a small runtime overhead.%
|
wenzelm@30296
|
333 |
\end{isamarkuptext}%
|
wenzelm@30296
|
334 |
\isamarkuptrue%
|
wenzelm@30296
|
335 |
%
|
wenzelm@30296
|
336 |
\isadelimmlref
|
wenzelm@30296
|
337 |
%
|
wenzelm@30296
|
338 |
\endisadelimmlref
|
wenzelm@30296
|
339 |
%
|
wenzelm@30296
|
340 |
\isatagmlref
|
wenzelm@30296
|
341 |
%
|
wenzelm@30296
|
342 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
343 |
\begin{mldecls}
|
wenzelm@30296
|
344 |
\indexdef{}{ML type}{Context.generic}\verb|type Context.generic| \\
|
wenzelm@30296
|
345 |
\indexdef{}{ML}{Context.theory\_of}\verb|Context.theory_of: Context.generic -> theory| \\
|
wenzelm@30296
|
346 |
\indexdef{}{ML}{Context.proof\_of}\verb|Context.proof_of: Context.generic -> Proof.context| \\
|
wenzelm@30296
|
347 |
\end{mldecls}
|
wenzelm@30296
|
348 |
|
wenzelm@30296
|
349 |
\begin{description}
|
wenzelm@30296
|
350 |
|
wenzelm@30296
|
351 |
\item \verb|Context.generic| is the direct sum of \verb|theory| and \verb|Proof.context|, with the datatype
|
wenzelm@30296
|
352 |
constructors \verb|Context.Theory| and \verb|Context.Proof|.
|
wenzelm@30296
|
353 |
|
wenzelm@30296
|
354 |
\item \verb|Context.theory_of|~\isa{context} always produces a
|
wenzelm@30296
|
355 |
theory from the generic \isa{context}, using \verb|ProofContext.theory_of| as required.
|
wenzelm@30296
|
356 |
|
wenzelm@30296
|
357 |
\item \verb|Context.proof_of|~\isa{context} always produces a
|
wenzelm@30296
|
358 |
proof context from the generic \isa{context}, using \verb|ProofContext.init| as required (note that this re-initializes the
|
wenzelm@30296
|
359 |
context data with each invocation).
|
wenzelm@30296
|
360 |
|
wenzelm@30296
|
361 |
\end{description}%
|
wenzelm@30296
|
362 |
\end{isamarkuptext}%
|
wenzelm@30296
|
363 |
\isamarkuptrue%
|
wenzelm@30296
|
364 |
%
|
wenzelm@30296
|
365 |
\endisatagmlref
|
wenzelm@30296
|
366 |
{\isafoldmlref}%
|
wenzelm@30296
|
367 |
%
|
wenzelm@30296
|
368 |
\isadelimmlref
|
wenzelm@30296
|
369 |
%
|
wenzelm@30296
|
370 |
\endisadelimmlref
|
wenzelm@30296
|
371 |
%
|
wenzelm@30296
|
372 |
\isamarkupsubsection{Context data \label{sec:context-data}%
|
wenzelm@30296
|
373 |
}
|
wenzelm@30296
|
374 |
\isamarkuptrue%
|
wenzelm@30296
|
375 |
%
|
wenzelm@30296
|
376 |
\begin{isamarkuptext}%
|
wenzelm@33526
|
377 |
The main purpose of theory and proof contexts is to manage
|
wenzelm@33526
|
378 |
arbitrary (pure) data. New data types can be declared incrementally
|
wenzelm@33526
|
379 |
at compile time. There are separate declaration mechanisms for any
|
wenzelm@33526
|
380 |
of the three kinds of contexts: theory, proof, generic.
|
wenzelm@30296
|
381 |
|
wenzelm@33526
|
382 |
\paragraph{Theory data} declarations need to implement the following
|
wenzelm@33526
|
383 |
SML signature:
|
wenzelm@30296
|
384 |
|
wenzelm@30296
|
385 |
\medskip
|
wenzelm@30296
|
386 |
\begin{tabular}{ll}
|
wenzelm@30296
|
387 |
\isa{{\isasymtype}\ T} & representing type \\
|
wenzelm@30296
|
388 |
\isa{{\isasymval}\ empty{\isacharcolon}\ T} & empty default value \\
|
wenzelm@30296
|
389 |
\isa{{\isasymval}\ extend{\isacharcolon}\ T\ {\isasymrightarrow}\ T} & re-initialize on import \\
|
wenzelm@30296
|
390 |
\isa{{\isasymval}\ merge{\isacharcolon}\ T\ {\isasymtimes}\ T\ {\isasymrightarrow}\ T} & join on import \\
|
wenzelm@30296
|
391 |
\end{tabular}
|
wenzelm@30296
|
392 |
\medskip
|
wenzelm@30296
|
393 |
|
wenzelm@30296
|
394 |
\noindent The \isa{empty} value acts as initial default for
|
wenzelm@33526
|
395 |
\emph{any} theory that does not declare actual data content; \isa{extend} is acts like a unitary version of \isa{merge}.
|
wenzelm@30296
|
396 |
|
wenzelm@35001
|
397 |
Implementing \isa{merge} can be tricky. The general idea is
|
wenzelm@35001
|
398 |
that \isa{merge\ {\isacharparenleft}data\isactrlsub {\isadigit{1}}{\isacharcomma}\ data\isactrlsub {\isadigit{2}}{\isacharparenright}} inserts those parts of \isa{data\isactrlsub {\isadigit{2}}} into \isa{data\isactrlsub {\isadigit{1}}} that are not yet present, while
|
wenzelm@35001
|
399 |
keeping the general order of things. The \verb|Library.merge|
|
wenzelm@35001
|
400 |
function on plain lists may serve as canonical template.
|
wenzelm@35001
|
401 |
|
wenzelm@35001
|
402 |
Particularly note that shared parts of the data must not be
|
wenzelm@35001
|
403 |
duplicated by naive concatenation, or a theory graph that is like a
|
wenzelm@35001
|
404 |
chain of diamonds would cause an exponential blowup!
|
wenzelm@35001
|
405 |
|
wenzelm@33526
|
406 |
\paragraph{Proof context data} declarations need to implement the
|
wenzelm@33526
|
407 |
following SML signature:
|
wenzelm@30296
|
408 |
|
wenzelm@30296
|
409 |
\medskip
|
wenzelm@30296
|
410 |
\begin{tabular}{ll}
|
wenzelm@30296
|
411 |
\isa{{\isasymtype}\ T} & representing type \\
|
wenzelm@30296
|
412 |
\isa{{\isasymval}\ init{\isacharcolon}\ theory\ {\isasymrightarrow}\ T} & produce initial value \\
|
wenzelm@30296
|
413 |
\end{tabular}
|
wenzelm@30296
|
414 |
\medskip
|
wenzelm@30296
|
415 |
|
wenzelm@30296
|
416 |
\noindent The \isa{init} operation is supposed to produce a pure
|
wenzelm@35001
|
417 |
value from the given background theory and should be somehow
|
wenzelm@35001
|
418 |
``immediate''. Whenever a proof context is initialized, which
|
wenzelm@35001
|
419 |
happens frequently, the the system invokes the \isa{init}
|
wenzelm@35001
|
420 |
operation of \emph{all} theory data slots ever declared.
|
wenzelm@30296
|
421 |
|
wenzelm@30296
|
422 |
\paragraph{Generic data} provides a hybrid interface for both theory
|
wenzelm@33526
|
423 |
and proof data. The \isa{init} operation for proof contexts is
|
wenzelm@33526
|
424 |
predefined to select the current data value from the background
|
wenzelm@33526
|
425 |
theory.
|
wenzelm@30296
|
426 |
|
wenzelm@35001
|
427 |
\bigskip Any of these data declaration over type \isa{T} result
|
wenzelm@35001
|
428 |
in an ML structure with the following signature:
|
wenzelm@30296
|
429 |
|
wenzelm@30296
|
430 |
\medskip
|
wenzelm@30296
|
431 |
\begin{tabular}{ll}
|
wenzelm@30296
|
432 |
\isa{get{\isacharcolon}\ context\ {\isasymrightarrow}\ T} \\
|
wenzelm@30296
|
433 |
\isa{put{\isacharcolon}\ T\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
|
wenzelm@30296
|
434 |
\isa{map{\isacharcolon}\ {\isacharparenleft}T\ {\isasymrightarrow}\ T{\isacharparenright}\ {\isasymrightarrow}\ context\ {\isasymrightarrow}\ context} \\
|
wenzelm@30296
|
435 |
\end{tabular}
|
wenzelm@30296
|
436 |
\medskip
|
wenzelm@30296
|
437 |
|
wenzelm@35001
|
438 |
\noindent These other operations provide exclusive access for the
|
wenzelm@35001
|
439 |
particular kind of context (theory, proof, or generic context).
|
wenzelm@35001
|
440 |
This interface fully observes the ML discipline for types and
|
wenzelm@35001
|
441 |
scopes: there is no other way to access the corresponding data slot
|
wenzelm@35001
|
442 |
of a context. By keeping these operations private, an Isabelle/ML
|
wenzelm@35001
|
443 |
module may maintain abstract values authentically.%
|
wenzelm@30296
|
444 |
\end{isamarkuptext}%
|
wenzelm@30296
|
445 |
\isamarkuptrue%
|
wenzelm@30296
|
446 |
%
|
wenzelm@30296
|
447 |
\isadelimmlref
|
wenzelm@30296
|
448 |
%
|
wenzelm@30296
|
449 |
\endisadelimmlref
|
wenzelm@30296
|
450 |
%
|
wenzelm@30296
|
451 |
\isatagmlref
|
wenzelm@30296
|
452 |
%
|
wenzelm@30296
|
453 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
454 |
\begin{mldecls}
|
wenzelm@33526
|
455 |
\indexdef{}{ML functor}{Theory\_Data}\verb|functor Theory_Data| \\
|
wenzelm@33526
|
456 |
\indexdef{}{ML functor}{Proof\_Data}\verb|functor Proof_Data| \\
|
wenzelm@33526
|
457 |
\indexdef{}{ML functor}{Generic\_Data}\verb|functor Generic_Data| \\
|
wenzelm@30296
|
458 |
\end{mldecls}
|
wenzelm@30296
|
459 |
|
wenzelm@30296
|
460 |
\begin{description}
|
wenzelm@30296
|
461 |
|
wenzelm@33526
|
462 |
\item \verb|Theory_Data|\isa{{\isacharparenleft}spec{\isacharparenright}} declares data for
|
wenzelm@30296
|
463 |
type \verb|theory| according to the specification provided as
|
wenzelm@30296
|
464 |
argument structure. The resulting structure provides data init and
|
wenzelm@30296
|
465 |
access operations as described above.
|
wenzelm@30296
|
466 |
|
wenzelm@33526
|
467 |
\item \verb|Proof_Data|\isa{{\isacharparenleft}spec{\isacharparenright}} is analogous to
|
wenzelm@33526
|
468 |
\verb|Theory_Data| for type \verb|Proof.context|.
|
wenzelm@30296
|
469 |
|
wenzelm@33526
|
470 |
\item \verb|Generic_Data|\isa{{\isacharparenleft}spec{\isacharparenright}} is analogous to
|
wenzelm@33526
|
471 |
\verb|Theory_Data| for type \verb|Context.generic|.
|
wenzelm@30296
|
472 |
|
wenzelm@30296
|
473 |
\end{description}%
|
wenzelm@30296
|
474 |
\end{isamarkuptext}%
|
wenzelm@30296
|
475 |
\isamarkuptrue%
|
wenzelm@30296
|
476 |
%
|
wenzelm@30296
|
477 |
\endisatagmlref
|
wenzelm@30296
|
478 |
{\isafoldmlref}%
|
wenzelm@30296
|
479 |
%
|
wenzelm@30296
|
480 |
\isadelimmlref
|
wenzelm@30296
|
481 |
%
|
wenzelm@30296
|
482 |
\endisadelimmlref
|
wenzelm@30296
|
483 |
%
|
wenzelm@35001
|
484 |
\isadelimmlex
|
wenzelm@35001
|
485 |
%
|
wenzelm@35001
|
486 |
\endisadelimmlex
|
wenzelm@35001
|
487 |
%
|
wenzelm@35001
|
488 |
\isatagmlex
|
wenzelm@35001
|
489 |
%
|
wenzelm@35001
|
490 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
491 |
The following artificial example demonstrates theory
|
wenzelm@35001
|
492 |
data: we maintain a set of terms that are supposed to be wellformed
|
wenzelm@35001
|
493 |
wrt.\ the enclosing theory. The public interface is as follows:%
|
wenzelm@35001
|
494 |
\end{isamarkuptext}%
|
wenzelm@35001
|
495 |
\isamarkuptrue%
|
wenzelm@35001
|
496 |
%
|
wenzelm@35001
|
497 |
\endisatagmlex
|
wenzelm@35001
|
498 |
{\isafoldmlex}%
|
wenzelm@35001
|
499 |
%
|
wenzelm@35001
|
500 |
\isadelimmlex
|
wenzelm@35001
|
501 |
%
|
wenzelm@35001
|
502 |
\endisadelimmlex
|
wenzelm@35001
|
503 |
%
|
wenzelm@35001
|
504 |
\isadelimML
|
wenzelm@35001
|
505 |
%
|
wenzelm@35001
|
506 |
\endisadelimML
|
wenzelm@35001
|
507 |
%
|
wenzelm@35001
|
508 |
\isatagML
|
wenzelm@35001
|
509 |
\isacommand{ML}\isamarkupfalse%
|
wenzelm@35001
|
510 |
\ {\isacharverbatimopen}\isanewline
|
wenzelm@35001
|
511 |
\ \ signature\ WELLFORMED{\isacharunderscore}TERMS\ {\isacharequal}\isanewline
|
wenzelm@35001
|
512 |
\ \ sig\isanewline
|
wenzelm@35001
|
513 |
\ \ \ \ val\ get{\isacharcolon}\ theory\ {\isacharminus}{\isachargreater}\ term\ list\isanewline
|
wenzelm@35001
|
514 |
\ \ \ \ val\ add{\isacharcolon}\ term\ {\isacharminus}{\isachargreater}\ theory\ {\isacharminus}{\isachargreater}\ theory\isanewline
|
wenzelm@35001
|
515 |
\ \ end{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
516 |
{\isacharverbatimclose}%
|
wenzelm@35001
|
517 |
\endisatagML
|
wenzelm@35001
|
518 |
{\isafoldML}%
|
wenzelm@35001
|
519 |
%
|
wenzelm@35001
|
520 |
\isadelimML
|
wenzelm@35001
|
521 |
%
|
wenzelm@35001
|
522 |
\endisadelimML
|
wenzelm@35001
|
523 |
%
|
wenzelm@35001
|
524 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
525 |
\noindent The implementation uses private theory data
|
wenzelm@35001
|
526 |
internally, and only exposes an operation that involves explicit
|
wenzelm@35001
|
527 |
argument checking wrt.\ the given theory.%
|
wenzelm@35001
|
528 |
\end{isamarkuptext}%
|
wenzelm@35001
|
529 |
\isamarkuptrue%
|
wenzelm@35001
|
530 |
%
|
wenzelm@35001
|
531 |
\isadelimML
|
wenzelm@35001
|
532 |
%
|
wenzelm@35001
|
533 |
\endisadelimML
|
wenzelm@35001
|
534 |
%
|
wenzelm@35001
|
535 |
\isatagML
|
wenzelm@35001
|
536 |
\isacommand{ML}\isamarkupfalse%
|
wenzelm@35001
|
537 |
\ {\isacharverbatimopen}\isanewline
|
wenzelm@35001
|
538 |
\ \ structure\ Wellformed{\isacharunderscore}Terms{\isacharcolon}\ WELLFORMED{\isacharunderscore}TERMS\ {\isacharequal}\isanewline
|
wenzelm@35001
|
539 |
\ \ struct\isanewline
|
wenzelm@35001
|
540 |
\isanewline
|
wenzelm@35001
|
541 |
\ \ structure\ Terms\ {\isacharequal}\ Theory{\isacharunderscore}Data\isanewline
|
wenzelm@35001
|
542 |
\ \ {\isacharparenleft}\isanewline
|
wenzelm@35001
|
543 |
\ \ \ \ type\ T\ {\isacharequal}\ term\ OrdList{\isachardot}T{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
544 |
\ \ \ \ val\ empty\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
545 |
\ \ \ \ val\ extend\ {\isacharequal}\ I{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
546 |
\ \ \ \ fun\ merge\ {\isacharparenleft}ts{\isadigit{1}}{\isacharcomma}\ ts{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\isanewline
|
wenzelm@35419
|
547 |
\ \ \ \ \ \ OrdList{\isachardot}union\ Term{\isacharunderscore}Ord{\isachardot}fast{\isacharunderscore}term{\isacharunderscore}ord\ ts{\isadigit{1}}\ ts{\isadigit{2}}{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
548 |
\ \ {\isacharparenright}\isanewline
|
wenzelm@35001
|
549 |
\isanewline
|
wenzelm@35001
|
550 |
\ \ val\ get\ {\isacharequal}\ Terms{\isachardot}get{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
551 |
\isanewline
|
wenzelm@35001
|
552 |
\ \ fun\ add\ raw{\isacharunderscore}t\ thy\ {\isacharequal}\isanewline
|
wenzelm@35001
|
553 |
\ \ \ \ let\ val\ t\ {\isacharequal}\ Sign{\isachardot}cert{\isacharunderscore}term\ thy\ raw{\isacharunderscore}t\isanewline
|
wenzelm@35419
|
554 |
\ \ \ \ in\ Terms{\isachardot}map\ {\isacharparenleft}OrdList{\isachardot}insert\ Term{\isacharunderscore}Ord{\isachardot}fast{\isacharunderscore}term{\isacharunderscore}ord\ t{\isacharparenright}\ thy\ end{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
555 |
\isanewline
|
wenzelm@35001
|
556 |
\ \ end{\isacharsemicolon}\isanewline
|
wenzelm@35001
|
557 |
{\isacharverbatimclose}%
|
wenzelm@35001
|
558 |
\endisatagML
|
wenzelm@35001
|
559 |
{\isafoldML}%
|
wenzelm@35001
|
560 |
%
|
wenzelm@35001
|
561 |
\isadelimML
|
wenzelm@35001
|
562 |
%
|
wenzelm@35001
|
563 |
\endisadelimML
|
wenzelm@35001
|
564 |
%
|
wenzelm@35001
|
565 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
566 |
We use \verb|term OrdList.T| for reasonably efficient
|
wenzelm@35001
|
567 |
representation of a set of terms: all operations are linear in the
|
wenzelm@35001
|
568 |
number of stored elements. Here we assume that our users do not
|
wenzelm@35001
|
569 |
care about the declaration order, since that data structure forces
|
wenzelm@35001
|
570 |
its own arrangement of elements.
|
wenzelm@35001
|
571 |
|
wenzelm@35001
|
572 |
Observe how the \verb|merge| operation joins the data slots of
|
wenzelm@35001
|
573 |
the two constituents: \verb|OrdList.union| prevents duplication of
|
wenzelm@35001
|
574 |
common data from different branches, thus avoiding the danger of
|
wenzelm@35001
|
575 |
exponential blowup. (Plain list append etc.\ must never be used for
|
wenzelm@35001
|
576 |
theory data merges.)
|
wenzelm@35001
|
577 |
|
wenzelm@35001
|
578 |
\medskip Our intended invariant is achieved as follows:
|
wenzelm@35001
|
579 |
\begin{enumerate}
|
wenzelm@35001
|
580 |
|
wenzelm@35001
|
581 |
\item \verb|Wellformed_Terms.add| only admits terms that have passed
|
wenzelm@35001
|
582 |
the \verb|Sign.cert_term| check of the given theory at that point.
|
wenzelm@35001
|
583 |
|
wenzelm@35001
|
584 |
\item Wellformedness in the sense of \verb|Sign.cert_term| is
|
wenzelm@35001
|
585 |
monotonic wrt.\ the sub-theory relation. So our data can move
|
wenzelm@35001
|
586 |
upwards in the hierarchy (via extension or merges), and maintain
|
wenzelm@35001
|
587 |
wellformedness without further checks.
|
wenzelm@35001
|
588 |
|
wenzelm@35001
|
589 |
\end{enumerate}
|
wenzelm@35001
|
590 |
|
wenzelm@35001
|
591 |
Note that all basic operations of the inference kernel (which
|
wenzelm@35001
|
592 |
includes \verb|Sign.cert_term|) observe this monotonicity principle,
|
wenzelm@35001
|
593 |
but other user-space tools don't. For example, fully-featured
|
wenzelm@35001
|
594 |
type-inference via \verb|Syntax.check_term| (cf.\
|
wenzelm@35001
|
595 |
\secref{sec:term-check}) is not necessarily monotonic wrt.\ the
|
wenzelm@35001
|
596 |
background theory, since constraints of term constants can be
|
wenzelm@35001
|
597 |
strengthened by later declarations, for example.
|
wenzelm@35001
|
598 |
|
wenzelm@35001
|
599 |
In most cases, user-space context data does not have to take such
|
wenzelm@35001
|
600 |
invariants too seriously. The situation is different in the
|
wenzelm@35001
|
601 |
implementation of the inference kernel itself, which uses the very
|
wenzelm@35001
|
602 |
same data mechanisms for types, constants, axioms etc.%
|
wenzelm@35001
|
603 |
\end{isamarkuptext}%
|
wenzelm@35001
|
604 |
\isamarkuptrue%
|
wenzelm@35001
|
605 |
%
|
wenzelm@30296
|
606 |
\isamarkupsection{Names \label{sec:names}%
|
wenzelm@30296
|
607 |
}
|
wenzelm@30296
|
608 |
\isamarkuptrue%
|
wenzelm@30296
|
609 |
%
|
wenzelm@30296
|
610 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
611 |
In principle, a name is just a string, but there are various
|
wenzelm@35001
|
612 |
conventions for representing additional structure. For example,
|
wenzelm@35001
|
613 |
``\isa{Foo{\isachardot}bar{\isachardot}baz}'' is considered as a long name consisting of
|
wenzelm@35001
|
614 |
qualifier \isa{Foo{\isachardot}bar} and base name \isa{baz}. The
|
wenzelm@35001
|
615 |
individual constituents of a name may have further substructure,
|
wenzelm@35001
|
616 |
e.g.\ the string ``\verb,\,\verb,<alpha>,'' encodes as a single
|
wenzelm@35001
|
617 |
symbol.
|
wenzelm@35001
|
618 |
|
wenzelm@35001
|
619 |
\medskip Subsequently, we shall introduce specific categories of
|
wenzelm@35001
|
620 |
names. Roughly speaking these correspond to logical entities as
|
wenzelm@35001
|
621 |
follows:
|
wenzelm@35001
|
622 |
\begin{itemize}
|
wenzelm@35001
|
623 |
|
wenzelm@35001
|
624 |
\item Basic names (\secref{sec:basic-name}): free and bound
|
wenzelm@35001
|
625 |
variables.
|
wenzelm@35001
|
626 |
|
wenzelm@35001
|
627 |
\item Indexed names (\secref{sec:indexname}): schematic variables.
|
wenzelm@35001
|
628 |
|
wenzelm@35001
|
629 |
\item Long names (\secref{sec:long-name}): constants of any kind
|
wenzelm@35001
|
630 |
(type constructors, term constants, other concepts defined in user
|
wenzelm@35001
|
631 |
space). Such entities are typically managed via name spaces
|
wenzelm@35001
|
632 |
(\secref{sec:name-space}).
|
wenzelm@35001
|
633 |
|
wenzelm@35001
|
634 |
\end{itemize}%
|
wenzelm@30296
|
635 |
\end{isamarkuptext}%
|
wenzelm@30296
|
636 |
\isamarkuptrue%
|
wenzelm@30296
|
637 |
%
|
wenzelm@30296
|
638 |
\isamarkupsubsection{Strings of symbols%
|
wenzelm@30296
|
639 |
}
|
wenzelm@30296
|
640 |
\isamarkuptrue%
|
wenzelm@30296
|
641 |
%
|
wenzelm@30296
|
642 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
643 |
A \emph{symbol} constitutes the smallest textual unit in
|
wenzelm@35001
|
644 |
Isabelle --- raw ML characters are normally not encountered at all!
|
wenzelm@35001
|
645 |
Isabelle strings consist of a sequence of symbols, represented as a
|
wenzelm@35001
|
646 |
packed string or an exploded list of strings. Each symbol is in
|
wenzelm@35001
|
647 |
itself a small string, which has either one of the following forms:
|
wenzelm@30296
|
648 |
|
wenzelm@30296
|
649 |
\begin{enumerate}
|
wenzelm@30296
|
650 |
|
wenzelm@35001
|
651 |
\item a single ASCII character ``\isa{c}'' or raw byte in the
|
wenzelm@35001
|
652 |
range of 128\dots 255, for example ``\verb,a,'',
|
wenzelm@30296
|
653 |
|
wenzelm@30296
|
654 |
\item a regular symbol ``\verb,\,\verb,<,\isa{ident}\verb,>,'',
|
wenzelm@30296
|
655 |
for example ``\verb,\,\verb,<alpha>,'',
|
wenzelm@30296
|
656 |
|
wenzelm@30296
|
657 |
\item a control symbol ``\verb,\,\verb,<^,\isa{ident}\verb,>,'',
|
wenzelm@30296
|
658 |
for example ``\verb,\,\verb,<^bold>,'',
|
wenzelm@30296
|
659 |
|
wenzelm@30296
|
660 |
\item a raw symbol ``\verb,\,\verb,<^raw:,\isa{text}\verb,>,''
|
wenzelm@35001
|
661 |
where \isa{text} consists of printable characters excluding
|
wenzelm@30296
|
662 |
``\verb,.,'' and ``\verb,>,'', for example
|
wenzelm@30296
|
663 |
``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
|
wenzelm@30296
|
664 |
|
wenzelm@30296
|
665 |
\item a numbered raw control symbol ``\verb,\,\verb,<^raw,\isa{n}\verb,>, where \isa{n} consists of digits, for example
|
wenzelm@30296
|
666 |
``\verb,\,\verb,<^raw42>,''.
|
wenzelm@30296
|
667 |
|
wenzelm@30296
|
668 |
\end{enumerate}
|
wenzelm@30296
|
669 |
|
wenzelm@30296
|
670 |
\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@30296
|
671 |
regular symbols and control symbols, but a fixed collection of
|
wenzelm@30296
|
672 |
standard symbols is treated specifically. For example,
|
wenzelm@30296
|
673 |
``\verb,\,\verb,<alpha>,'' is classified as a letter, which means it
|
wenzelm@30296
|
674 |
may occur within regular Isabelle identifiers.
|
wenzelm@30296
|
675 |
|
wenzelm@30296
|
676 |
Since the character set underlying Isabelle symbols is 7-bit ASCII
|
wenzelm@35001
|
677 |
and 8-bit characters are passed through transparently, Isabelle can
|
wenzelm@35001
|
678 |
also process Unicode/UCS data in UTF-8 encoding.\footnote{When
|
wenzelm@35001
|
679 |
counting precise source positions internally, bytes in the range of
|
wenzelm@35001
|
680 |
128\dots 191 are ignored. In UTF-8 encoding, this interval covers
|
wenzelm@35001
|
681 |
the additional trailer bytes, so Isabelle happens to count Unicode
|
wenzelm@35001
|
682 |
characters here, not bytes in memory. In ISO-Latin encoding, the
|
wenzelm@35001
|
683 |
ignored range merely includes some extra punctuation characters that
|
wenzelm@35001
|
684 |
even have replacements within the standard collection of Isabelle
|
wenzelm@35001
|
685 |
symbols; the accented letters range is counted properly.} Unicode
|
wenzelm@35001
|
686 |
provides its own collection of mathematical symbols, but within the
|
wenzelm@35001
|
687 |
core Isabelle/ML world there is no link to the standard collection
|
wenzelm@35001
|
688 |
of Isabelle regular symbols.
|
wenzelm@30296
|
689 |
|
wenzelm@30296
|
690 |
\medskip Output of Isabelle symbols depends on the print mode
|
wenzelm@30296
|
691 |
(\secref{print-mode}). For example, the standard {\LaTeX} setup of
|
wenzelm@30296
|
692 |
the Isabelle document preparation system would present
|
wenzelm@30296
|
693 |
``\verb,\,\verb,<alpha>,'' as \isa{{\isasymalpha}}, and
|
wenzelm@35001
|
694 |
``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as \isa{\isactrlbold {\isasymalpha}}. On-screen rendering usually works by mapping a finite
|
wenzelm@35001
|
695 |
subset of Isabelle symbols to suitable Unicode characters.%
|
wenzelm@30296
|
696 |
\end{isamarkuptext}%
|
wenzelm@30296
|
697 |
\isamarkuptrue%
|
wenzelm@30296
|
698 |
%
|
wenzelm@30296
|
699 |
\isadelimmlref
|
wenzelm@30296
|
700 |
%
|
wenzelm@30296
|
701 |
\endisadelimmlref
|
wenzelm@30296
|
702 |
%
|
wenzelm@30296
|
703 |
\isatagmlref
|
wenzelm@30296
|
704 |
%
|
wenzelm@30296
|
705 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
706 |
\begin{mldecls}
|
wenzelm@35001
|
707 |
\indexdef{}{ML type}{Symbol.symbol}\verb|type Symbol.symbol = string| \\
|
wenzelm@30296
|
708 |
\indexdef{}{ML}{Symbol.explode}\verb|Symbol.explode: string -> Symbol.symbol list| \\
|
wenzelm@30296
|
709 |
\indexdef{}{ML}{Symbol.is\_letter}\verb|Symbol.is_letter: Symbol.symbol -> bool| \\
|
wenzelm@30296
|
710 |
\indexdef{}{ML}{Symbol.is\_digit}\verb|Symbol.is_digit: Symbol.symbol -> bool| \\
|
wenzelm@30296
|
711 |
\indexdef{}{ML}{Symbol.is\_quasi}\verb|Symbol.is_quasi: Symbol.symbol -> bool| \\
|
wenzelm@30296
|
712 |
\indexdef{}{ML}{Symbol.is\_blank}\verb|Symbol.is_blank: Symbol.symbol -> bool| \\
|
wenzelm@30296
|
713 |
\end{mldecls}
|
wenzelm@30296
|
714 |
\begin{mldecls}
|
wenzelm@30296
|
715 |
\indexdef{}{ML type}{Symbol.sym}\verb|type Symbol.sym| \\
|
wenzelm@30296
|
716 |
\indexdef{}{ML}{Symbol.decode}\verb|Symbol.decode: Symbol.symbol -> Symbol.sym| \\
|
wenzelm@30296
|
717 |
\end{mldecls}
|
wenzelm@30296
|
718 |
|
wenzelm@30296
|
719 |
\begin{description}
|
wenzelm@30296
|
720 |
|
wenzelm@30296
|
721 |
\item \verb|Symbol.symbol| represents individual Isabelle
|
wenzelm@35001
|
722 |
symbols.
|
wenzelm@30296
|
723 |
|
wenzelm@30296
|
724 |
\item \verb|Symbol.explode|~\isa{str} produces a symbol list
|
wenzelm@30296
|
725 |
from the packed form. This function supercedes \verb|String.explode| for virtually all purposes of manipulating text in
|
wenzelm@35001
|
726 |
Isabelle!\footnote{The runtime overhead for exploded strings is
|
wenzelm@35001
|
727 |
mainly that of the list structure: individual symbols that happen to
|
wenzelm@35001
|
728 |
be a singleton string --- which is the most common case --- do not
|
wenzelm@35001
|
729 |
require extra memory in Poly/ML.}
|
wenzelm@30296
|
730 |
|
wenzelm@30296
|
731 |
\item \verb|Symbol.is_letter|, \verb|Symbol.is_digit|, \verb|Symbol.is_quasi|, \verb|Symbol.is_blank| classify standard
|
wenzelm@30296
|
732 |
symbols according to fixed syntactic conventions of Isabelle, cf.\
|
wenzelm@30296
|
733 |
\cite{isabelle-isar-ref}.
|
wenzelm@30296
|
734 |
|
wenzelm@30296
|
735 |
\item \verb|Symbol.sym| is a concrete datatype that represents
|
wenzelm@30296
|
736 |
the different kinds of symbols explicitly, with constructors \verb|Symbol.Char|, \verb|Symbol.Sym|, \verb|Symbol.Ctrl|, \verb|Symbol.Raw|.
|
wenzelm@30296
|
737 |
|
wenzelm@30296
|
738 |
\item \verb|Symbol.decode| converts the string representation of a
|
wenzelm@30296
|
739 |
symbol into the datatype version.
|
wenzelm@30296
|
740 |
|
wenzelm@35001
|
741 |
\end{description}
|
wenzelm@35001
|
742 |
|
wenzelm@35001
|
743 |
\paragraph{Historical note.} In the original SML90 standard the
|
wenzelm@35001
|
744 |
primitive ML type \verb|char| did not exists, and the basic \verb|explode: string -> string list| operation would produce a list of
|
wenzelm@35001
|
745 |
singleton strings as in Isabelle/ML today. When SML97 came out,
|
wenzelm@35001
|
746 |
Isabelle did not adopt its slightly anachronistic 8-bit characters,
|
wenzelm@35001
|
747 |
but the idea of exploding a string into a list of small strings was
|
wenzelm@35001
|
748 |
extended to ``symbols'' as explained above. Thus Isabelle sources
|
wenzelm@35001
|
749 |
can refer to an infinite store of user-defined symbols, without
|
wenzelm@35001
|
750 |
having to worry about the multitude of Unicode encodings.%
|
wenzelm@30296
|
751 |
\end{isamarkuptext}%
|
wenzelm@30296
|
752 |
\isamarkuptrue%
|
wenzelm@30296
|
753 |
%
|
wenzelm@30296
|
754 |
\endisatagmlref
|
wenzelm@30296
|
755 |
{\isafoldmlref}%
|
wenzelm@30296
|
756 |
%
|
wenzelm@30296
|
757 |
\isadelimmlref
|
wenzelm@30296
|
758 |
%
|
wenzelm@30296
|
759 |
\endisadelimmlref
|
wenzelm@30296
|
760 |
%
|
wenzelm@35001
|
761 |
\isamarkupsubsection{Basic names \label{sec:basic-name}%
|
wenzelm@30296
|
762 |
}
|
wenzelm@30296
|
763 |
\isamarkuptrue%
|
wenzelm@30296
|
764 |
%
|
wenzelm@30296
|
765 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
766 |
A \emph{basic name} essentially consists of a single Isabelle
|
wenzelm@30296
|
767 |
identifier. There are conventions to mark separate classes of basic
|
wenzelm@30296
|
768 |
names, by attaching a suffix of underscores: one underscore means
|
wenzelm@30296
|
769 |
\emph{internal name}, two underscores means \emph{Skolem name},
|
wenzelm@30296
|
770 |
three underscores means \emph{internal Skolem name}.
|
wenzelm@30296
|
771 |
|
wenzelm@30296
|
772 |
For example, the basic name \isa{foo} has the internal version
|
wenzelm@30296
|
773 |
\isa{foo{\isacharunderscore}}, with Skolem versions \isa{foo{\isacharunderscore}{\isacharunderscore}} and \isa{foo{\isacharunderscore}{\isacharunderscore}{\isacharunderscore}}, respectively.
|
wenzelm@30296
|
774 |
|
wenzelm@30296
|
775 |
These special versions provide copies of the basic name space, apart
|
wenzelm@30296
|
776 |
from anything that normally appears in the user text. For example,
|
wenzelm@30296
|
777 |
system generated variables in Isar proof contexts are usually marked
|
wenzelm@35001
|
778 |
as internal, which prevents mysterious names like \isa{xaa} to
|
wenzelm@35001
|
779 |
appear in human-readable text.
|
wenzelm@30296
|
780 |
|
wenzelm@30296
|
781 |
\medskip Manipulating binding scopes often requires on-the-fly
|
wenzelm@30296
|
782 |
renamings. A \emph{name context} contains a collection of already
|
wenzelm@30296
|
783 |
used names. The \isa{declare} operation adds names to the
|
wenzelm@30296
|
784 |
context.
|
wenzelm@30296
|
785 |
|
wenzelm@30296
|
786 |
The \isa{invents} operation derives a number of fresh names from
|
wenzelm@30296
|
787 |
a given starting point. For example, the first three names derived
|
wenzelm@30296
|
788 |
from \isa{a} are \isa{a}, \isa{b}, \isa{c}.
|
wenzelm@30296
|
789 |
|
wenzelm@30296
|
790 |
The \isa{variants} operation produces fresh names by
|
wenzelm@30296
|
791 |
incrementing tentative names as base-26 numbers (with digits \isa{a{\isachardot}{\isachardot}z}) until all clashes are resolved. For example, name \isa{foo} results in variants \isa{fooa}, \isa{foob}, \isa{fooc}, \dots, \isa{fooaa}, \isa{fooab} etc.; each renaming
|
wenzelm@30296
|
792 |
step picks the next unused variant from this sequence.%
|
wenzelm@30296
|
793 |
\end{isamarkuptext}%
|
wenzelm@30296
|
794 |
\isamarkuptrue%
|
wenzelm@30296
|
795 |
%
|
wenzelm@30296
|
796 |
\isadelimmlref
|
wenzelm@30296
|
797 |
%
|
wenzelm@30296
|
798 |
\endisadelimmlref
|
wenzelm@30296
|
799 |
%
|
wenzelm@30296
|
800 |
\isatagmlref
|
wenzelm@30296
|
801 |
%
|
wenzelm@30296
|
802 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
803 |
\begin{mldecls}
|
wenzelm@30296
|
804 |
\indexdef{}{ML}{Name.internal}\verb|Name.internal: string -> string| \\
|
wenzelm@30296
|
805 |
\indexdef{}{ML}{Name.skolem}\verb|Name.skolem: string -> string| \\
|
wenzelm@30296
|
806 |
\end{mldecls}
|
wenzelm@30296
|
807 |
\begin{mldecls}
|
wenzelm@30296
|
808 |
\indexdef{}{ML type}{Name.context}\verb|type Name.context| \\
|
wenzelm@30296
|
809 |
\indexdef{}{ML}{Name.context}\verb|Name.context: Name.context| \\
|
wenzelm@30296
|
810 |
\indexdef{}{ML}{Name.declare}\verb|Name.declare: string -> Name.context -> Name.context| \\
|
wenzelm@30296
|
811 |
\indexdef{}{ML}{Name.invents}\verb|Name.invents: Name.context -> string -> int -> string list| \\
|
wenzelm@30296
|
812 |
\indexdef{}{ML}{Name.variants}\verb|Name.variants: string list -> Name.context -> string list * Name.context| \\
|
wenzelm@30296
|
813 |
\end{mldecls}
|
wenzelm@35001
|
814 |
\begin{mldecls}
|
wenzelm@35001
|
815 |
\indexdef{}{ML}{Variable.names\_of}\verb|Variable.names_of: Proof.context -> Name.context| \\
|
wenzelm@35001
|
816 |
\end{mldecls}
|
wenzelm@30296
|
817 |
|
wenzelm@30296
|
818 |
\begin{description}
|
wenzelm@30296
|
819 |
|
wenzelm@30296
|
820 |
\item \verb|Name.internal|~\isa{name} produces an internal name
|
wenzelm@30296
|
821 |
by adding one underscore.
|
wenzelm@30296
|
822 |
|
wenzelm@30296
|
823 |
\item \verb|Name.skolem|~\isa{name} produces a Skolem name by
|
wenzelm@30296
|
824 |
adding two underscores.
|
wenzelm@30296
|
825 |
|
wenzelm@30296
|
826 |
\item \verb|Name.context| represents the context of already used
|
wenzelm@30296
|
827 |
names; the initial value is \verb|Name.context|.
|
wenzelm@30296
|
828 |
|
wenzelm@30296
|
829 |
\item \verb|Name.declare|~\isa{name} enters a used name into the
|
wenzelm@30296
|
830 |
context.
|
wenzelm@30296
|
831 |
|
wenzelm@30296
|
832 |
\item \verb|Name.invents|~\isa{context\ name\ n} produces \isa{n} fresh names derived from \isa{name}.
|
wenzelm@30296
|
833 |
|
wenzelm@30296
|
834 |
\item \verb|Name.variants|~\isa{names\ context} produces fresh
|
wenzelm@30296
|
835 |
variants of \isa{names}; the result is entered into the context.
|
wenzelm@30296
|
836 |
|
wenzelm@35001
|
837 |
\item \verb|Variable.names_of|~\isa{ctxt} retrieves the context
|
wenzelm@35001
|
838 |
of declared type and term variable names. Projecting a proof
|
wenzelm@35001
|
839 |
context down to a primitive name context is occasionally useful when
|
wenzelm@35001
|
840 |
invoking lower-level operations. Regular management of ``fresh
|
wenzelm@35001
|
841 |
variables'' is done by suitable operations of structure \verb|Variable|, which is also able to provide an official status of
|
wenzelm@35001
|
842 |
``locally fixed variable'' within the logical environment (cf.\
|
wenzelm@35001
|
843 |
\secref{sec:variables}).
|
wenzelm@35001
|
844 |
|
wenzelm@30296
|
845 |
\end{description}%
|
wenzelm@30296
|
846 |
\end{isamarkuptext}%
|
wenzelm@30296
|
847 |
\isamarkuptrue%
|
wenzelm@30296
|
848 |
%
|
wenzelm@30296
|
849 |
\endisatagmlref
|
wenzelm@30296
|
850 |
{\isafoldmlref}%
|
wenzelm@30296
|
851 |
%
|
wenzelm@30296
|
852 |
\isadelimmlref
|
wenzelm@30296
|
853 |
%
|
wenzelm@30296
|
854 |
\endisadelimmlref
|
wenzelm@30296
|
855 |
%
|
wenzelm@35001
|
856 |
\isamarkupsubsection{Indexed names \label{sec:indexname}%
|
wenzelm@30296
|
857 |
}
|
wenzelm@30296
|
858 |
\isamarkuptrue%
|
wenzelm@30296
|
859 |
%
|
wenzelm@30296
|
860 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
861 |
An \emph{indexed name} (or \isa{indexname}) is a pair of a basic
|
wenzelm@30296
|
862 |
name and a natural number. This representation allows efficient
|
wenzelm@30296
|
863 |
renaming by incrementing the second component only. The canonical
|
wenzelm@30296
|
864 |
way to rename two collections of indexnames apart from each other is
|
wenzelm@30296
|
865 |
this: determine the maximum index \isa{maxidx} of the first
|
wenzelm@30296
|
866 |
collection, then increment all indexes of the second collection by
|
wenzelm@30296
|
867 |
\isa{maxidx\ {\isacharplus}\ {\isadigit{1}}}; the maximum index of an empty collection is
|
wenzelm@30296
|
868 |
\isa{{\isacharminus}{\isadigit{1}}}.
|
wenzelm@30296
|
869 |
|
wenzelm@35001
|
870 |
Occasionally, basic names are injected into the same pair type of
|
wenzelm@35001
|
871 |
indexed names: then \isa{{\isacharparenleft}x{\isacharcomma}\ {\isacharminus}{\isadigit{1}}{\isacharparenright}} is used to encode the basic
|
wenzelm@35001
|
872 |
name \isa{x}.
|
wenzelm@30296
|
873 |
|
wenzelm@30296
|
874 |
\medskip Isabelle syntax observes the following rules for
|
wenzelm@30296
|
875 |
representing an indexname \isa{{\isacharparenleft}x{\isacharcomma}\ i{\isacharparenright}} as a packed string:
|
wenzelm@30296
|
876 |
|
wenzelm@30296
|
877 |
\begin{itemize}
|
wenzelm@30296
|
878 |
|
wenzelm@30296
|
879 |
\item \isa{{\isacharquery}x} if \isa{x} does not end with a digit and \isa{i\ {\isacharequal}\ {\isadigit{0}}},
|
wenzelm@30296
|
880 |
|
wenzelm@30296
|
881 |
\item \isa{{\isacharquery}xi} if \isa{x} does not end with a digit,
|
wenzelm@30296
|
882 |
|
wenzelm@30296
|
883 |
\item \isa{{\isacharquery}x{\isachardot}i} otherwise.
|
wenzelm@30296
|
884 |
|
wenzelm@30296
|
885 |
\end{itemize}
|
wenzelm@30296
|
886 |
|
wenzelm@35001
|
887 |
Indexnames may acquire large index numbers after several maxidx
|
wenzelm@35001
|
888 |
shifts have been applied. Results are usually normalized towards
|
wenzelm@35001
|
889 |
\isa{{\isadigit{0}}} at certain checkpoints, notably at the end of a proof.
|
wenzelm@35001
|
890 |
This works by producing variants of the corresponding basic name
|
wenzelm@35001
|
891 |
components. For example, the collection \isa{{\isacharquery}x{\isadigit{1}}{\isacharcomma}\ {\isacharquery}x{\isadigit{7}}{\isacharcomma}\ {\isacharquery}x{\isadigit{4}}{\isadigit{2}}}
|
wenzelm@35001
|
892 |
becomes \isa{{\isacharquery}x{\isacharcomma}\ {\isacharquery}xa{\isacharcomma}\ {\isacharquery}xb}.%
|
wenzelm@30296
|
893 |
\end{isamarkuptext}%
|
wenzelm@30296
|
894 |
\isamarkuptrue%
|
wenzelm@30296
|
895 |
%
|
wenzelm@30296
|
896 |
\isadelimmlref
|
wenzelm@30296
|
897 |
%
|
wenzelm@30296
|
898 |
\endisadelimmlref
|
wenzelm@30296
|
899 |
%
|
wenzelm@30296
|
900 |
\isatagmlref
|
wenzelm@30296
|
901 |
%
|
wenzelm@30296
|
902 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
903 |
\begin{mldecls}
|
wenzelm@30296
|
904 |
\indexdef{}{ML type}{indexname}\verb|type indexname| \\
|
wenzelm@30296
|
905 |
\end{mldecls}
|
wenzelm@30296
|
906 |
|
wenzelm@30296
|
907 |
\begin{description}
|
wenzelm@30296
|
908 |
|
wenzelm@30296
|
909 |
\item \verb|indexname| represents indexed names. This is an
|
wenzelm@30296
|
910 |
abbreviation for \verb|string * int|. The second component is
|
wenzelm@30296
|
911 |
usually non-negative, except for situations where \isa{{\isacharparenleft}x{\isacharcomma}\ {\isacharminus}{\isadigit{1}}{\isacharparenright}}
|
wenzelm@35001
|
912 |
is used to inject basic names into this type. Other negative
|
wenzelm@35001
|
913 |
indexes should not be used.
|
wenzelm@30296
|
914 |
|
wenzelm@30296
|
915 |
\end{description}%
|
wenzelm@30296
|
916 |
\end{isamarkuptext}%
|
wenzelm@30296
|
917 |
\isamarkuptrue%
|
wenzelm@30296
|
918 |
%
|
wenzelm@30296
|
919 |
\endisatagmlref
|
wenzelm@30296
|
920 |
{\isafoldmlref}%
|
wenzelm@30296
|
921 |
%
|
wenzelm@30296
|
922 |
\isadelimmlref
|
wenzelm@30296
|
923 |
%
|
wenzelm@30296
|
924 |
\endisadelimmlref
|
wenzelm@30296
|
925 |
%
|
wenzelm@35001
|
926 |
\isamarkupsubsection{Long names \label{sec:long-name}%
|
wenzelm@30296
|
927 |
}
|
wenzelm@30296
|
928 |
\isamarkuptrue%
|
wenzelm@30296
|
929 |
%
|
wenzelm@30296
|
930 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
931 |
A \emph{long name} consists of a sequence of non-empty name
|
wenzelm@35001
|
932 |
components. The packed representation uses a dot as separator, as
|
wenzelm@35001
|
933 |
in ``\isa{A{\isachardot}b{\isachardot}c}''. The last component is called \emph{base
|
wenzelm@35001
|
934 |
name}, the remaining prefix is called \emph{qualifier} (which may be
|
wenzelm@35001
|
935 |
empty). The qualifier can be understood as the access path to the
|
wenzelm@35001
|
936 |
named entity while passing through some nested block-structure,
|
wenzelm@35001
|
937 |
although our free-form long names do not really enforce any strict
|
wenzelm@35001
|
938 |
discipline.
|
wenzelm@35001
|
939 |
|
wenzelm@35001
|
940 |
For example, an item named ``\isa{A{\isachardot}b{\isachardot}c}'' may be understood as
|
wenzelm@35001
|
941 |
a local entity \isa{c}, within a local structure \isa{b},
|
wenzelm@35001
|
942 |
within a global structure \isa{A}. In practice, long names
|
wenzelm@35001
|
943 |
usually represent 1--3 levels of qualification. User ML code should
|
wenzelm@35001
|
944 |
not make any assumptions about the particular structure of long
|
wenzelm@35001
|
945 |
names!
|
wenzelm@30296
|
946 |
|
wenzelm@30296
|
947 |
The empty name is commonly used as an indication of unnamed
|
wenzelm@35001
|
948 |
entities, or entities that are not entered into the corresponding
|
wenzelm@35001
|
949 |
name space, whenever this makes any sense. The basic operations on
|
wenzelm@35001
|
950 |
long names map empty names again to empty names.%
|
wenzelm@30296
|
951 |
\end{isamarkuptext}%
|
wenzelm@30296
|
952 |
\isamarkuptrue%
|
wenzelm@30296
|
953 |
%
|
wenzelm@30296
|
954 |
\isadelimmlref
|
wenzelm@30296
|
955 |
%
|
wenzelm@30296
|
956 |
\endisadelimmlref
|
wenzelm@30296
|
957 |
%
|
wenzelm@30296
|
958 |
\isatagmlref
|
wenzelm@30296
|
959 |
%
|
wenzelm@30296
|
960 |
\begin{isamarkuptext}%
|
wenzelm@30296
|
961 |
\begin{mldecls}
|
wenzelm@30365
|
962 |
\indexdef{}{ML}{Long\_Name.base\_name}\verb|Long_Name.base_name: string -> string| \\
|
wenzelm@30365
|
963 |
\indexdef{}{ML}{Long\_Name.qualifier}\verb|Long_Name.qualifier: string -> string| \\
|
wenzelm@30365
|
964 |
\indexdef{}{ML}{Long\_Name.append}\verb|Long_Name.append: string -> string -> string| \\
|
wenzelm@30365
|
965 |
\indexdef{}{ML}{Long\_Name.implode}\verb|Long_Name.implode: string list -> string| \\
|
wenzelm@30365
|
966 |
\indexdef{}{ML}{Long\_Name.explode}\verb|Long_Name.explode: string -> string list| \\
|
wenzelm@30296
|
967 |
\end{mldecls}
|
wenzelm@35001
|
968 |
|
wenzelm@35001
|
969 |
\begin{description}
|
wenzelm@35001
|
970 |
|
wenzelm@35001
|
971 |
\item \verb|Long_Name.base_name|~\isa{name} returns the base name
|
wenzelm@35001
|
972 |
of a long name.
|
wenzelm@35001
|
973 |
|
wenzelm@35001
|
974 |
\item \verb|Long_Name.qualifier|~\isa{name} returns the qualifier
|
wenzelm@35001
|
975 |
of a long name.
|
wenzelm@35001
|
976 |
|
wenzelm@35001
|
977 |
\item \verb|Long_Name.append|~\isa{name\isactrlisub {\isadigit{1}}\ name\isactrlisub {\isadigit{2}}} appends two long
|
wenzelm@35001
|
978 |
names.
|
wenzelm@35001
|
979 |
|
wenzelm@35001
|
980 |
\item \verb|Long_Name.implode|~\isa{names} and \verb|Long_Name.explode|~\isa{name} convert between the packed string
|
wenzelm@35001
|
981 |
representation and the explicit list form of long names.
|
wenzelm@35001
|
982 |
|
wenzelm@35001
|
983 |
\end{description}%
|
wenzelm@35001
|
984 |
\end{isamarkuptext}%
|
wenzelm@35001
|
985 |
\isamarkuptrue%
|
wenzelm@35001
|
986 |
%
|
wenzelm@35001
|
987 |
\endisatagmlref
|
wenzelm@35001
|
988 |
{\isafoldmlref}%
|
wenzelm@35001
|
989 |
%
|
wenzelm@35001
|
990 |
\isadelimmlref
|
wenzelm@35001
|
991 |
%
|
wenzelm@35001
|
992 |
\endisadelimmlref
|
wenzelm@35001
|
993 |
%
|
wenzelm@35001
|
994 |
\isamarkupsubsection{Name spaces \label{sec:name-space}%
|
wenzelm@35001
|
995 |
}
|
wenzelm@35001
|
996 |
\isamarkuptrue%
|
wenzelm@35001
|
997 |
%
|
wenzelm@35001
|
998 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
999 |
A \isa{name\ space} manages a collection of long names,
|
wenzelm@35001
|
1000 |
together with a mapping between partially qualified external names
|
wenzelm@35001
|
1001 |
and fully qualified internal names (in both directions). Note that
|
wenzelm@35001
|
1002 |
the corresponding \isa{intern} and \isa{extern} operations
|
wenzelm@35001
|
1003 |
are mostly used for parsing and printing only! The \isa{declare} operation augments a name space according to the accesses
|
wenzelm@35001
|
1004 |
determined by a given binding, and a naming policy from the context.
|
wenzelm@35001
|
1005 |
|
wenzelm@35001
|
1006 |
\medskip A \isa{binding} specifies details about the prospective
|
wenzelm@35001
|
1007 |
long name of a newly introduced formal entity. It consists of a
|
wenzelm@35001
|
1008 |
base name, prefixes for qualification (separate ones for system
|
wenzelm@35001
|
1009 |
infrastructure and user-space mechanisms), a slot for the original
|
wenzelm@35001
|
1010 |
source position, and some additional flags.
|
wenzelm@35001
|
1011 |
|
wenzelm@35001
|
1012 |
\medskip A \isa{naming} provides some additional details for
|
wenzelm@35001
|
1013 |
producing a long name from a binding. Normally, the naming is
|
wenzelm@35001
|
1014 |
implicit in the theory or proof context. The \isa{full}
|
wenzelm@35001
|
1015 |
operation (and its variants for different context types) produces a
|
wenzelm@35001
|
1016 |
fully qualified internal name to be entered into a name space. The
|
wenzelm@35001
|
1017 |
main equation of this ``chemical reaction'' when binding new
|
wenzelm@35001
|
1018 |
entities in a context is as follows:
|
wenzelm@35001
|
1019 |
|
wenzelm@35001
|
1020 |
\smallskip
|
wenzelm@35001
|
1021 |
\begin{tabular}{l}
|
wenzelm@35001
|
1022 |
\isa{binding\ {\isacharplus}\ naming\ {\isasymlongrightarrow}\ long\ name\ {\isacharplus}\ name\ space\ accesses}
|
wenzelm@35001
|
1023 |
\end{tabular}
|
wenzelm@35001
|
1024 |
\smallskip
|
wenzelm@35001
|
1025 |
|
wenzelm@35001
|
1026 |
\medskip As a general principle, there is a separate name space for
|
wenzelm@35001
|
1027 |
each kind of formal entity, e.g.\ fact, logical constant, type
|
wenzelm@35001
|
1028 |
constructor, type class. It is usually clear from the occurrence in
|
wenzelm@35001
|
1029 |
concrete syntax (or from the scope) which kind of entity a name
|
wenzelm@35001
|
1030 |
refers to. For example, the very same name \isa{c} may be used
|
wenzelm@35001
|
1031 |
uniformly for a constant, type constructor, and type class.
|
wenzelm@35001
|
1032 |
|
wenzelm@35001
|
1033 |
There are common schemes to name derived entities systematically
|
wenzelm@35001
|
1034 |
according to the name of the main logical entity involved, e.g.\
|
wenzelm@35001
|
1035 |
fact \isa{c{\isachardot}intro} for a canonical introduction rule related to
|
wenzelm@35001
|
1036 |
constant \isa{c}. This technique of mapping names from one
|
wenzelm@35001
|
1037 |
space into another requires some care in order to avoid conflicts.
|
wenzelm@35001
|
1038 |
In particular, theorem names derived from a type constructor or type
|
wenzelm@35001
|
1039 |
class are better suffixed in addition to the usual qualification,
|
wenzelm@35001
|
1040 |
e.g.\ \isa{c{\isacharunderscore}type{\isachardot}intro} and \isa{c{\isacharunderscore}class{\isachardot}intro} for
|
wenzelm@35001
|
1041 |
theorems related to type \isa{c} and class \isa{c},
|
wenzelm@35001
|
1042 |
respectively.%
|
wenzelm@35001
|
1043 |
\end{isamarkuptext}%
|
wenzelm@35001
|
1044 |
\isamarkuptrue%
|
wenzelm@35001
|
1045 |
%
|
wenzelm@35001
|
1046 |
\isadelimmlref
|
wenzelm@35001
|
1047 |
%
|
wenzelm@35001
|
1048 |
\endisadelimmlref
|
wenzelm@35001
|
1049 |
%
|
wenzelm@35001
|
1050 |
\isatagmlref
|
wenzelm@35001
|
1051 |
%
|
wenzelm@35001
|
1052 |
\begin{isamarkuptext}%
|
wenzelm@35001
|
1053 |
\begin{mldecls}
|
wenzelm@35001
|
1054 |
\indexdef{}{ML type}{binding}\verb|type binding| \\
|
wenzelm@35001
|
1055 |
\indexdef{}{ML}{Binding.empty}\verb|Binding.empty: binding| \\
|
wenzelm@35001
|
1056 |
\indexdef{}{ML}{Binding.name}\verb|Binding.name: string -> binding| \\
|
wenzelm@35001
|
1057 |
\indexdef{}{ML}{Binding.qualify}\verb|Binding.qualify: bool -> string -> binding -> binding| \\
|
wenzelm@35001
|
1058 |
\indexdef{}{ML}{Binding.prefix}\verb|Binding.prefix: bool -> string -> binding -> binding| \\
|
wenzelm@35001
|
1059 |
\indexdef{}{ML}{Binding.conceal}\verb|Binding.conceal: binding -> binding| \\
|
wenzelm@35001
|
1060 |
\indexdef{}{ML}{Binding.str\_of}\verb|Binding.str_of: binding -> string| \\
|
wenzelm@35001
|
1061 |
\end{mldecls}
|
wenzelm@30296
|
1062 |
\begin{mldecls}
|
haftmann@33174
|
1063 |
\indexdef{}{ML type}{Name\_Space.naming}\verb|type Name_Space.naming| \\
|
haftmann@33174
|
1064 |
\indexdef{}{ML}{Name\_Space.default\_naming}\verb|Name_Space.default_naming: Name_Space.naming| \\
|
haftmann@33174
|
1065 |
\indexdef{}{ML}{Name\_Space.add\_path}\verb|Name_Space.add_path: string -> Name_Space.naming -> Name_Space.naming| \\
|
haftmann@33174
|
1066 |
\indexdef{}{ML}{Name\_Space.full\_name}\verb|Name_Space.full_name: Name_Space.naming -> binding -> string| \\
|
wenzelm@30296
|
1067 |
\end{mldecls}
|
wenzelm@30296
|
1068 |
\begin{mldecls}
|
haftmann@33174
|
1069 |
\indexdef{}{ML type}{Name\_Space.T}\verb|type Name_Space.T| \\
|
haftmann@33174
|
1070 |
\indexdef{}{ML}{Name\_Space.empty}\verb|Name_Space.empty: string -> Name_Space.T| \\
|
haftmann@33174
|
1071 |
\indexdef{}{ML}{Name\_Space.merge}\verb|Name_Space.merge: Name_Space.T * Name_Space.T -> Name_Space.T| \\
|
haftmann@33174
|
1072 |
\indexdef{}{ML}{Name\_Space.declare}\verb|Name_Space.declare: bool -> Name_Space.naming -> binding -> Name_Space.T ->|\isasep\isanewline%
|
haftmann@33174
|
1073 |
\verb| string * Name_Space.T| \\
|
haftmann@33174
|
1074 |
\indexdef{}{ML}{Name\_Space.intern}\verb|Name_Space.intern: Name_Space.T -> string -> string| \\
|
haftmann@33174
|
1075 |
\indexdef{}{ML}{Name\_Space.extern}\verb|Name_Space.extern: Name_Space.T -> string -> string| \\
|
wenzelm@35001
|
1076 |
\indexdef{}{ML}{Name\_Space.is\_concealed}\verb|Name_Space.is_concealed: Name_Space.T -> string -> bool|
|
wenzelm@30296
|
1077 |
\end{mldecls}
|
wenzelm@30296
|
1078 |
|
wenzelm@30296
|
1079 |
\begin{description}
|
wenzelm@30296
|
1080 |
|
wenzelm@35001
|
1081 |
\item \verb|binding| represents the abstract concept of name
|
wenzelm@35001
|
1082 |
bindings.
|
wenzelm@30296
|
1083 |
|
wenzelm@35001
|
1084 |
\item \verb|Binding.empty| is the empty binding.
|
wenzelm@30296
|
1085 |
|
wenzelm@35001
|
1086 |
\item \verb|Binding.name|~\isa{name} produces a binding with base
|
wenzelm@35001
|
1087 |
name \isa{name}.
|
wenzelm@30296
|
1088 |
|
wenzelm@35001
|
1089 |
\item \verb|Binding.qualify|~\isa{mandatory\ name\ binding}
|
wenzelm@35001
|
1090 |
prefixes qualifier \isa{name} to \isa{binding}. The \isa{mandatory} flag tells if this name component always needs to be
|
wenzelm@35001
|
1091 |
given in name space accesses --- this is mostly \isa{false} in
|
wenzelm@35001
|
1092 |
practice. Note that this part of qualification is typically used in
|
wenzelm@35001
|
1093 |
derived specification mechanisms.
|
wenzelm@35001
|
1094 |
|
wenzelm@35001
|
1095 |
\item \verb|Binding.prefix| is similar to \verb|Binding.qualify|, but
|
wenzelm@35001
|
1096 |
affects the system prefix. This part of extra qualification is
|
wenzelm@35001
|
1097 |
typically used in the infrastructure for modular specifications,
|
wenzelm@35001
|
1098 |
notably ``local theory targets'' (see also \chref{ch:local-theory}).
|
wenzelm@35001
|
1099 |
|
wenzelm@35001
|
1100 |
\item \verb|Binding.conceal|~\isa{binding} indicates that the
|
wenzelm@35001
|
1101 |
binding shall refer to an entity that serves foundational purposes
|
wenzelm@35001
|
1102 |
only. This flag helps to mark implementation details of
|
wenzelm@35001
|
1103 |
specification mechanism etc. Other tools should not depend on the
|
wenzelm@35001
|
1104 |
particulars of concealed entities (cf.\ \verb|Name_Space.is_concealed|).
|
wenzelm@35001
|
1105 |
|
wenzelm@35001
|
1106 |
\item \verb|Binding.str_of|~\isa{binding} produces a string
|
wenzelm@35001
|
1107 |
representation for human-readable output, together with some formal
|
wenzelm@35001
|
1108 |
markup that might get used in GUI front-ends, for example.
|
wenzelm@30296
|
1109 |
|
haftmann@33174
|
1110 |
\item \verb|Name_Space.naming| represents the abstract concept of
|
wenzelm@30296
|
1111 |
a naming policy.
|
wenzelm@30296
|
1112 |
|
haftmann@33174
|
1113 |
\item \verb|Name_Space.default_naming| is the default naming policy.
|
wenzelm@30296
|
1114 |
In a theory context, this is usually augmented by a path prefix
|
wenzelm@30296
|
1115 |
consisting of the theory name.
|
wenzelm@30296
|
1116 |
|
haftmann@33174
|
1117 |
\item \verb|Name_Space.add_path|~\isa{path\ naming} augments the
|
wenzelm@30296
|
1118 |
naming policy by extending its path component.
|
wenzelm@30296
|
1119 |
|
haftmann@33174
|
1120 |
\item \verb|Name_Space.full_name|~\isa{naming\ binding} turns a
|
wenzelm@30296
|
1121 |
name binding (usually a basic name) into the fully qualified
|
wenzelm@30296
|
1122 |
internal name, according to the given naming policy.
|
wenzelm@30296
|
1123 |
|
haftmann@33174
|
1124 |
\item \verb|Name_Space.T| represents name spaces.
|
wenzelm@30296
|
1125 |
|
haftmann@33174
|
1126 |
\item \verb|Name_Space.empty|~\isa{kind} and \verb|Name_Space.merge|~\isa{{\isacharparenleft}space\isactrlisub {\isadigit{1}}{\isacharcomma}\ space\isactrlisub {\isadigit{2}}{\isacharparenright}} are the canonical operations for
|
wenzelm@30296
|
1127 |
maintaining name spaces according to theory data management
|
haftmann@33174
|
1128 |
(\secref{sec:context-data}); \isa{kind} is a formal comment
|
haftmann@33174
|
1129 |
to characterize the purpose of a name space.
|
wenzelm@30296
|
1130 |
|
haftmann@33174
|
1131 |
\item \verb|Name_Space.declare|~\isa{strict\ naming\ bindings\ space} enters a name binding as fully qualified internal name into
|
haftmann@33174
|
1132 |
the name space, with external accesses determined by the naming
|
haftmann@33174
|
1133 |
policy.
|
wenzelm@30296
|
1134 |
|
haftmann@33174
|
1135 |
\item \verb|Name_Space.intern|~\isa{space\ name} internalizes a
|
wenzelm@30296
|
1136 |
(partially qualified) external name.
|
wenzelm@30296
|
1137 |
|
wenzelm@30296
|
1138 |
This operation is mostly for parsing! Note that fully qualified
|
haftmann@33174
|
1139 |
names stemming from declarations are produced via \verb|Name_Space.full_name| and \verb|Name_Space.declare|
|
wenzelm@30296
|
1140 |
(or their derivatives for \verb|theory| and
|
wenzelm@30296
|
1141 |
\verb|Proof.context|).
|
wenzelm@30296
|
1142 |
|
haftmann@33174
|
1143 |
\item \verb|Name_Space.extern|~\isa{space\ name} externalizes a
|
wenzelm@30296
|
1144 |
(fully qualified) internal name.
|
wenzelm@30296
|
1145 |
|
wenzelm@30296
|
1146 |
This operation is mostly for printing! User code should not rely on
|
wenzelm@30296
|
1147 |
the precise result too much.
|
wenzelm@30296
|
1148 |
|
wenzelm@35001
|
1149 |
\item \verb|Name_Space.is_concealed|~\isa{space\ name} indicates
|
wenzelm@35001
|
1150 |
whether \isa{name} refers to a strictly private entity that
|
wenzelm@35001
|
1151 |
other tools are supposed to ignore!
|
wenzelm@35001
|
1152 |
|
wenzelm@30296
|
1153 |
\end{description}%
|
wenzelm@30296
|
1154 |
\end{isamarkuptext}%
|
wenzelm@30296
|
1155 |
\isamarkuptrue%
|
wenzelm@30296
|
1156 |
%
|
wenzelm@30296
|
1157 |
\endisatagmlref
|
wenzelm@30296
|
1158 |
{\isafoldmlref}%
|
wenzelm@30296
|
1159 |
%
|
wenzelm@30296
|
1160 |
\isadelimmlref
|
wenzelm@30296
|
1161 |
%
|
wenzelm@30296
|
1162 |
\endisadelimmlref
|
wenzelm@30296
|
1163 |
%
|
wenzelm@30296
|
1164 |
\isadelimtheory
|
wenzelm@30296
|
1165 |
%
|
wenzelm@30296
|
1166 |
\endisadelimtheory
|
wenzelm@30296
|
1167 |
%
|
wenzelm@30296
|
1168 |
\isatagtheory
|
wenzelm@30296
|
1169 |
\isacommand{end}\isamarkupfalse%
|
wenzelm@30296
|
1170 |
%
|
wenzelm@30296
|
1171 |
\endisatagtheory
|
wenzelm@30296
|
1172 |
{\isafoldtheory}%
|
wenzelm@30296
|
1173 |
%
|
wenzelm@30296
|
1174 |
\isadelimtheory
|
wenzelm@30296
|
1175 |
%
|
wenzelm@30296
|
1176 |
\endisadelimtheory
|
wenzelm@30296
|
1177 |
\isanewline
|
wenzelm@30296
|
1178 |
\end{isabellebody}%
|
wenzelm@30296
|
1179 |
%%% Local Variables:
|
wenzelm@30296
|
1180 |
%%% mode: latex
|
wenzelm@30296
|
1181 |
%%% TeX-master: "root"
|
wenzelm@30296
|
1182 |
%%% End:
|