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