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