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