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 |
|
20447
|
304 |
subsection {* Context data *}
|
|
305 |
|
|
306 |
text {*
|
20451
|
307 |
The main purpose of theory and proof contexts is to manage arbitrary
|
|
308 |
data. New data types can be declared incrementally at compile time.
|
|
309 |
There are separate declaration mechanisms for any of the three kinds
|
|
310 |
of contexts: theory, proof, generic.
|
20449
|
311 |
|
|
312 |
\paragraph{Theory data} may refer to destructive entities, which are
|
20451
|
313 |
maintained in direct correspondence to the linear evolution of
|
|
314 |
theory values, including explicit copies.\footnote{Most existing
|
|
315 |
instances of destructive theory data are merely historical relics
|
|
316 |
(e.g.\ the destructive theorem storage, and destructive hints for
|
|
317 |
the Simplifier and Classical rules).} A theory data declaration
|
|
318 |
needs to implement the following specification (depending on type
|
|
319 |
@{text "T"}):
|
20449
|
320 |
|
|
321 |
\medskip
|
|
322 |
\begin{tabular}{ll}
|
|
323 |
@{text "name: string"} \\
|
|
324 |
@{text "empty: T"} & initial value \\
|
|
325 |
@{text "copy: T \<rightarrow> T"} & refresh impure data \\
|
|
326 |
@{text "extend: T \<rightarrow> T"} & re-initialize on import \\
|
|
327 |
@{text "merge: T \<times> T \<rightarrow> T"} & join on import \\
|
|
328 |
@{text "print: T \<rightarrow> unit"} & diagnostic output \\
|
|
329 |
\end{tabular}
|
|
330 |
\medskip
|
|
331 |
|
|
332 |
\noindent The @{text "name"} acts as a comment for diagnostic
|
|
333 |
messages; @{text "copy"} is just the identity for pure data; @{text
|
|
334 |
"extend"} is acts like a unitary version of @{text "merge"}, both
|
|
335 |
should also include the functionality of @{text "copy"} for impure
|
|
336 |
data.
|
|
337 |
|
20451
|
338 |
\paragraph{Proof context data} is purely functional. A declaration
|
|
339 |
needs to implement the following specification:
|
20449
|
340 |
|
|
341 |
\medskip
|
|
342 |
\begin{tabular}{ll}
|
|
343 |
@{text "name: string"} \\
|
|
344 |
@{text "init: theory \<rightarrow> T"} & produce initial value \\
|
|
345 |
@{text "print: T \<rightarrow> unit"} & diagnostic output \\
|
|
346 |
\end{tabular}
|
|
347 |
\medskip
|
|
348 |
|
|
349 |
\noindent The @{text "init"} operation is supposed to produce a pure
|
20451
|
350 |
value from the given background theory. The remainder is analogous
|
|
351 |
to theory data.
|
20449
|
352 |
|
20451
|
353 |
\paragraph{Generic data} provides a hybrid interface for both theory
|
|
354 |
and proof data. The declaration is essentially the same as for
|
|
355 |
(pure) theory data, without @{text "copy"}, though. The @{text
|
|
356 |
"init"} operation for proof contexts merely selects the current data
|
|
357 |
value from the background theory.
|
20449
|
358 |
|
|
359 |
\bigskip In any case, a data declaration of type @{text "T"} results
|
|
360 |
in the following interface:
|
|
361 |
|
|
362 |
\medskip
|
|
363 |
\begin{tabular}{ll}
|
|
364 |
@{text "init: theory \<rightarrow> theory"} \\
|
|
365 |
@{text "get: context \<rightarrow> T"} \\
|
|
366 |
@{text "put: T \<rightarrow> context \<rightarrow> context"} \\
|
|
367 |
@{text "map: (T \<rightarrow> T) \<rightarrow> context \<rightarrow> context"} \\
|
|
368 |
@{text "print: context \<rightarrow> unit"}
|
|
369 |
\end{tabular}
|
|
370 |
\medskip
|
|
371 |
|
|
372 |
\noindent Here @{text "init"} needs to be applied to the current
|
|
373 |
theory context once, in order to register the initial setup. The
|
|
374 |
other operations provide access for the particular kind of context
|
|
375 |
(theory, proof, or generic context). Note that this is a safe
|
|
376 |
interface: there is no other way to access the corresponding data
|
20451
|
377 |
slot of a context. By keeping these operations private, a component
|
|
378 |
may maintain abstract values authentically, without other components
|
|
379 |
interfering.
|
20447
|
380 |
*}
|
|
381 |
|
20450
|
382 |
text %mlref {*
|
|
383 |
\begin{mldecls}
|
|
384 |
@{index_ML_functor TheoryDataFun} \\
|
|
385 |
@{index_ML_functor ProofDataFun} \\
|
|
386 |
@{index_ML_functor GenericDataFun} \\
|
|
387 |
\end{mldecls}
|
|
388 |
|
|
389 |
\begin{description}
|
|
390 |
|
|
391 |
\item @{ML_functor TheoryDataFun}@{text "(spec)"} declares data for
|
|
392 |
type @{ML_type theory} according to the specification provided as
|
20451
|
393 |
argument structure. The resulting structure provides data init and
|
|
394 |
access operations as described above.
|
20450
|
395 |
|
|
396 |
\item @{ML_functor ProofDataFun}@{text "(spec)"} is analogous for
|
|
397 |
type @{ML_type Proof.context}.
|
|
398 |
|
|
399 |
\item @{ML_functor GenericDataFun}@{text "(spec)"} is analogous for
|
|
400 |
type @{ML_type Context.generic}.
|
|
401 |
|
|
402 |
\end{description}
|
|
403 |
*}
|
|
404 |
|
20447
|
405 |
|
20452
|
406 |
section {* Name spaces *}
|
20437
|
407 |
|
20451
|
408 |
text {*
|
|
409 |
By general convention, each kind of formal entities (logical
|
|
410 |
constant, type, type class, theorem, method etc.) lives in a
|
|
411 |
separate name space. It is usually clear from the syntactic context
|
|
412 |
of a name, which kind of entity it refers to. For example, proof
|
|
413 |
method @{text "foo"} vs.\ theorem @{text "foo"} vs.\ logical
|
|
414 |
constant @{text "foo"} are easily distinguished thanks to the design
|
|
415 |
of the concrete outer syntax. A notable exception are logical
|
|
416 |
identifiers within a term (\secref{sec:terms}): constants, fixed
|
|
417 |
variables, and bound variables all share the same identifier syntax,
|
|
418 |
but are distinguished by their scope.
|
|
419 |
|
|
420 |
Name spaces are organized uniformly, as a collection of qualified
|
|
421 |
names consisting of a sequence of basic name components separated by
|
|
422 |
dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"}
|
|
423 |
are examples for qualified names.
|
20437
|
424 |
|
20451
|
425 |
Despite the independence of names of different kinds, certain naming
|
|
426 |
conventions may relate them to each other. For example, a constant
|
|
427 |
@{text "foo"} could be accompanied with theorems @{text
|
|
428 |
"foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc. The same
|
|
429 |
could happen for a type @{text "foo"}, but this is apt to cause
|
|
430 |
clashes in the theorem name space! To avoid this, there is an
|
|
431 |
additional convention to add a suffix that determines the original
|
|
432 |
kind. For example, constant @{text "foo"} could associated with
|
|
433 |
theorem @{text "foo.intro"}, type @{text "foo"} with theorem @{text
|
|
434 |
"foo_type.intro"}, and type class @{text "foo"} with @{text
|
|
435 |
"foo_class.intro"}.
|
|
436 |
|
|
437 |
\medskip Name components are subdivided into \emph{symbols}, which
|
|
438 |
constitute the smallest textual unit in Isabelle --- raw characters
|
|
439 |
are normally not encountered.
|
|
440 |
*}
|
20437
|
441 |
|
|
442 |
|
|
443 |
subsection {* Strings of symbols *}
|
|
444 |
|
20451
|
445 |
text {*
|
|
446 |
Isabelle strings consist of a sequence of
|
|
447 |
symbols\glossary{Symbol}{The smallest unit of text in Isabelle,
|
|
448 |
subsumes plain ASCII characters as well as an infinite collection of
|
|
449 |
named symbols (for greek, math etc.).}, which are either packed as
|
|
450 |
an actual @{text "string"}, or represented as a list. Each symbol
|
|
451 |
is in itself a small string of the following form:
|
20437
|
452 |
|
20451
|
453 |
\begin{enumerate}
|
20437
|
454 |
|
20451
|
455 |
\item either a singleton ASCII character ``@{text "c"}'' (with
|
|
456 |
character code 0--127), for example ``\verb,a,'',
|
20437
|
457 |
|
20451
|
458 |
\item or a regular symbol ``\verb,\,\verb,<,@{text
|
|
459 |
"ident"}\verb,>,'', for example ``\verb,\,\verb,<alpha>,'',
|
20437
|
460 |
|
20451
|
461 |
\item or a control symbol ``\verb,\,\verb,<^,@{text
|
|
462 |
"ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'',
|
20437
|
463 |
|
20451
|
464 |
\item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text
|
|
465 |
"\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any printable ASCII
|
|
466 |
character (excluding ``\verb,.,'' and ``\verb,>,'') or non-ASCII
|
|
467 |
character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
|
20437
|
468 |
|
20451
|
469 |
\item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
|
|
470 |
"nnn"}\verb,>, where @{text "nnn"} are digits, for example
|
|
471 |
``\verb,\,\verb,<^raw42>,''.
|
20437
|
472 |
|
20451
|
473 |
\end{enumerate}
|
20437
|
474 |
|
20451
|
475 |
The @{text "ident"} syntax for symbol names is @{text "letter
|
|
476 |
(letter | digit)\<^sup>*"}, where @{text "letter = A..Za..z"} and
|
|
477 |
@{text "digit = 0..9"}. There are infinitely many regular symbols
|
|
478 |
and control symbols available, but a certain collection of standard
|
|
479 |
symbols is treated specifically. For example,
|
|
480 |
``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter,
|
|
481 |
which means it may occur within regular Isabelle identifier syntax.
|
20437
|
482 |
|
20451
|
483 |
Output of symbols depends on the print mode
|
|
484 |
(\secref{sec:print-mode}). For example, the standard {\LaTeX} setup
|
|
485 |
of the Isabelle document preparation system would present
|
|
486 |
``\verb,\,\verb,<alpha>,'' as @{text "\<alpha>"}, and
|
|
487 |
``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
|
|
488 |
"\<^bold>\<alpha>"}.
|
20437
|
489 |
|
20451
|
490 |
\medskip It is important to note that the character set underlying
|
|
491 |
Isabelle symbols is plain 7-bit ASCII. Since 8-bit characters are
|
|
492 |
passed through transparently, Isabelle may easily process
|
|
493 |
Unicode/UCS data as well (using UTF-8 encoding). Unicode provides
|
|
494 |
its own collection of mathematical symbols, but there is no built-in
|
|
495 |
link to the ones of Isabelle.
|
|
496 |
*}
|
20437
|
497 |
|
|
498 |
text %mlref {*
|
|
499 |
\begin{mldecls}
|
|
500 |
@{index_ML_type "Symbol.symbol"} \\
|
|
501 |
@{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
|
|
502 |
@{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
|
|
503 |
@{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
|
|
504 |
@{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
|
20451
|
505 |
@{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\[1ex]
|
20437
|
506 |
@{index_ML_type "Symbol.sym"} \\
|
|
507 |
@{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
|
|
508 |
\end{mldecls}
|
|
509 |
|
|
510 |
\begin{description}
|
|
511 |
|
20451
|
512 |
\item @{ML_type "Symbol.symbol"} represents Isabelle symbols. This
|
|
513 |
type is an alias for @{ML_type "string"}, but emphasizes the
|
20437
|
514 |
specific format encountered here.
|
|
515 |
|
20447
|
516 |
\item @{ML "Symbol.explode"}~@{text "s"} produces a symbol list from
|
20451
|
517 |
the packed form that is encountered in most practical situations.
|
|
518 |
This function supercedes @{ML "String.explode"} for virtually all
|
|
519 |
purposes of manipulating text in Isabelle! Plain @{ML "implode"}
|
|
520 |
may still be used for the reverse operation.
|
20437
|
521 |
|
|
522 |
\item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
|
|
523 |
"Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols
|
|
524 |
(both ASCII and several named ones) according to fixed syntactic
|
20451
|
525 |
conventions of Isabelle, cf.\ \cite{isabelle-isar-ref}.
|
20437
|
526 |
|
|
527 |
\item @{ML_type "Symbol.sym"} is a concrete datatype that represents
|
20451
|
528 |
the different kinds of symbols explicitly with constructors @{ML
|
|
529 |
"Symbol.Char"}, @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML
|
|
530 |
"Symbol.Raw"}.
|
20437
|
531 |
|
|
532 |
\item @{ML "Symbol.decode"} converts the string representation of a
|
20451
|
533 |
symbol into the datatype version.
|
20437
|
534 |
|
|
535 |
\end{description}
|
|
536 |
*}
|
|
537 |
|
|
538 |
|
20452
|
539 |
subsection {* Qualified names *}
|
20437
|
540 |
|
20450
|
541 |
text {*
|
20451
|
542 |
A \emph{qualified name} essentially consists of a non-empty list of
|
|
543 |
basic name components. The packad notation uses a dot as separator,
|
|
544 |
as in @{text "A.b"}, for example. The very last component is called
|
|
545 |
\emph{base} name, the remaining prefix \emph{qualifier} (which may
|
|
546 |
be empty).
|
20437
|
547 |
|
20451
|
548 |
A @{text "naming"} policy tells how to produce fully qualified names
|
|
549 |
from a given specification. The @{text "full"} operation applies
|
|
550 |
performs naming of a name; the policy is usually taken from the
|
|
551 |
context. For example, a common policy is to attach an implicit
|
|
552 |
prefix.
|
20437
|
553 |
|
20451
|
554 |
A @{text "name space"} manages declarations of fully qualified
|
|
555 |
names. There are separate operations to @{text "declare"}, @{text
|
|
556 |
"intern"}, and @{text "extern"} names.
|
|
557 |
|
|
558 |
FIXME
|
20437
|
559 |
*}
|
|
560 |
|
20451
|
561 |
text %mlref FIXME
|
|
562 |
|
20437
|
563 |
|
|
564 |
section {* Structured output *}
|
|
565 |
|
|
566 |
subsection {* Pretty printing *}
|
|
567 |
|
|
568 |
text FIXME
|
|
569 |
|
|
570 |
subsection {* Output channels *}
|
|
571 |
|
|
572 |
text FIXME
|
|
573 |
|
20451
|
574 |
subsection {* Print modes \label{sec:print-mode} *}
|
20437
|
575 |
|
|
576 |
text FIXME
|
|
577 |
|
|
578 |
|
18537
|
579 |
end
|