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 {*
|
|
11 |
A logical context represents the background that is taken for
|
|
12 |
granted when formulating statements and composing proofs. It acts
|
|
13 |
as a medium to produce formal content, depending on earlier material
|
|
14 |
(declarations, results etc.).
|
18537
|
15 |
|
20429
|
16 |
In particular, derivations within the primitive Pure logic can be
|
|
17 |
described as a judgment @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}, meaning that a
|
|
18 |
proposition @{text "\<phi>"} is derivable from hypotheses @{text "\<Gamma>"}
|
|
19 |
within the theory @{text "\<Theta>"}. There are logical reasons for
|
|
20 |
keeping @{text "\<Theta>"} and @{text "\<Gamma>"} separate: theories support type
|
|
21 |
constructors and schematic polymorphism of constants and axioms,
|
|
22 |
while the inner calculus of @{text "\<Gamma> \<turnstile> \<phi>"} is limited to Simple
|
|
23 |
Type Theory (with fixed type variables in the assumptions).
|
18537
|
24 |
|
20429
|
25 |
\medskip Contexts and derivations are linked by the following key
|
|
26 |
principles:
|
|
27 |
|
|
28 |
\begin{itemize}
|
|
29 |
|
|
30 |
\item Transfer: monotonicity of derivations admits results to be
|
|
31 |
transferred into a larger context, i.e.\ @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}
|
|
32 |
implies @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta>\<^sub>' \<phi>"} for contexts @{text "\<Theta>' \<supseteq>
|
|
33 |
\<Theta>"} and @{text "\<Gamma>' \<supseteq> \<Gamma>"}.
|
18537
|
34 |
|
20429
|
35 |
\item Export: discharge of hypotheses admits results to be exported
|
|
36 |
into a smaller context, i.e.\ @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta> \<phi>"} implies
|
|
37 |
@{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<Delta> \<Longrightarrow> \<phi>"} where @{text "\<Gamma>' \<supseteq> \<Gamma>"} and @{text "\<Delta> =
|
|
38 |
\<Gamma>' - \<Gamma>"}. Note that @{text "\<Theta>"} remains unchanged here, only the
|
|
39 |
@{text "\<Gamma>"} part is affected.
|
|
40 |
|
|
41 |
\end{itemize}
|
18537
|
42 |
|
20429
|
43 |
\medskip Isabelle/Isar provides two different notions of abstract
|
|
44 |
containers called \emph{theory context} and \emph{proof context},
|
|
45 |
respectively. These model the main characteristics of the primitive
|
|
46 |
@{text "\<Theta>"} and @{text "\<Gamma>"} above, without subscribing to any
|
|
47 |
particular kind of content yet. Instead, contexts merely impose a
|
|
48 |
certain policy of managing arbitrary \emph{context data}. The
|
|
49 |
system provides strongly typed mechanisms to declare new kinds of
|
|
50 |
data at compile time.
|
18537
|
51 |
|
20429
|
52 |
Thus the internal bootstrap process of Isabelle/Pure eventually
|
|
53 |
reaches a stage where certain data slots provide the logical content
|
|
54 |
of @{text "\<Theta>"} and @{text "\<Gamma>"} sketched above, but this does not
|
|
55 |
stop there! Various additional data slots support all kinds of
|
|
56 |
mechanisms that 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
|
|
61 |
standard proof steps implicitly (cf.\ the @{text "rule"} method).
|
18537
|
62 |
|
20429
|
63 |
Isabelle is able to bring forth more and more concepts successively.
|
|
64 |
In particular, an object-logic like Isabelle/HOL continues the
|
|
65 |
Isabelle/Pure setup by adding specific components for automated
|
|
66 |
reasoning (classical reasoner, tableau prover, structured induction
|
|
67 |
etc.) and derived specification mechanisms (inductive predicates,
|
|
68 |
recursive functions etc.). All of this is based on the generic data
|
|
69 |
management by theory and proof contexts.
|
18537
|
70 |
*}
|
|
71 |
|
|
72 |
|
|
73 |
subsection {* Theory context \label{sec:context-theory} *}
|
|
74 |
|
20429
|
75 |
text {*
|
|
76 |
Each theory is explicitly named and holds a unique identifier.
|
|
77 |
There is a separate \emph{theory reference} for pointing backwards
|
|
78 |
to the enclosing theory context of derived entities. Theories are
|
|
79 |
related by a (nominal) sub-theory relation, which corresponds to the
|
|
80 |
canonical dependency graph: each theory is derived from a certain
|
|
81 |
sub-graph of ancestor theories. The @{text "merge"} of two theories
|
|
82 |
refers to the least upper bound, which actually degenerates into
|
|
83 |
absorption of one theory into the other, due to the nominal
|
|
84 |
sub-theory relation this.
|
18537
|
85 |
|
20429
|
86 |
The @{text "begin"} operation starts a new theory by importing
|
|
87 |
several parent theories and entering a special @{text "draft"} mode,
|
|
88 |
which is sustained until the final @{text "end"} operation. A draft
|
|
89 |
mode theory acts like a linear type, where updates invalidate
|
|
90 |
earlier drafts, but theory reference values will be propagated
|
|
91 |
automatically. Thus derived entities that ``belong'' to a draft
|
|
92 |
might be transferred spontaneously to a larger context. An
|
|
93 |
invalidated draft is called ``stale''. The @{text "copy"} operation
|
|
94 |
produces an auxiliary version with the same data content, but is
|
|
95 |
unrelated to the original: updates of the copy do not affect the
|
|
96 |
original, neither does the sub-theory relation hold.
|
|
97 |
|
|
98 |
The example below shows a theory graph derived from @{text "Pure"}.
|
|
99 |
Theory @{text "Length"} imports @{text "Nat"} and @{text "List"}.
|
|
100 |
The linear draft mode is enabled during the ``@{text "\<dots>"}'' stage of
|
|
101 |
the theory body.
|
|
102 |
|
|
103 |
\bigskip
|
|
104 |
\begin{tabular}{rcccl}
|
18537
|
105 |
& & $Pure$ \\
|
|
106 |
& & $\downarrow$ \\
|
|
107 |
& & $FOL$ \\
|
|
108 |
& $\swarrow$ & & $\searrow$ & \\
|
|
109 |
$Nat$ & & & & $List$ \\
|
|
110 |
& $\searrow$ & & $\swarrow$ \\
|
|
111 |
& & $Length$ \\
|
|
112 |
& & \multicolumn{3}{l}{~~$\isarkeyword{imports}$} \\
|
|
113 |
& & \multicolumn{3}{l}{~~$\isarkeyword{begin}$} \\
|
|
114 |
& & $\vdots$~~ \\
|
|
115 |
& & \multicolumn{3}{l}{~~$\isarkeyword{end}$} \\
|
20429
|
116 |
\end{tabular}
|
|
117 |
|
|
118 |
\medskip In practice, derived theory operations mostly operate
|
|
119 |
drafts, namely the body of the current portion of theory that the
|
|
120 |
user happens to be composing.
|
18537
|
121 |
|
20429
|
122 |
\medskip There is also a builtin theory history mechanism that amends for
|
|
123 |
the destructive behaviour of theory drafts. The @{text
|
|
124 |
"checkpoint"} operation produces an intermediate stepping stone that
|
|
125 |
survives the next update unscathed: both the original and the
|
|
126 |
changed theory remain valid and are related by the sub-theory
|
|
127 |
relation. This recovering of pure theory values comes at the cost
|
|
128 |
of extra internal bookeeping. The cumulative effect of
|
|
129 |
checkpointing is purged by the @{text "finish"} operation.
|
18537
|
130 |
|
20429
|
131 |
History operations are usually managed by the system, e.g.\ notably
|
|
132 |
in the Isar transaction loop.
|
18537
|
133 |
|
20429
|
134 |
\medskip
|
|
135 |
FIXME theory data
|
18537
|
136 |
*}
|
|
137 |
|
20430
|
138 |
text %mlref {*
|
|
139 |
*}
|
|
140 |
|
18537
|
141 |
|
|
142 |
subsection {* Proof context \label{sec:context-proof} *}
|
|
143 |
|
|
144 |
text {*
|
20429
|
145 |
A proof context is an arbitrary container that is initialized from a
|
|
146 |
given theory. The result contains a back-reference to the theory it
|
|
147 |
belongs to, together with pure data. No further bookkeeping is
|
|
148 |
required here, thanks to the lack of destructive features.
|
|
149 |
|
|
150 |
There is no restriction on producing proof contexts, although the
|
|
151 |
usual discipline is to follow block structure as a mental model: a
|
|
152 |
given context is extended consecutively, results are exported back
|
|
153 |
into the original context. In particular, the concept of Isar proof
|
|
154 |
state models block-structured reasoning explicitly, using a stack of
|
|
155 |
proof contexts.
|
|
156 |
|
|
157 |
Due to the lack of identification and back-referencing, entities
|
|
158 |
derived in a proof context need to record inherent logical
|
|
159 |
requirements explicitly. For example, hypotheses used in a
|
|
160 |
derivation will be recorded separately within the sequent @{text "\<Gamma>
|
|
161 |
\<turnstile> \<phi>"}, just to make double sure. Results could leak into an alien
|
|
162 |
proof context do to programming errors, but Isabelle/Isar
|
|
163 |
occasionally includes extra validity checks at the end of a
|
|
164 |
sub-proof.
|
|
165 |
|
|
166 |
\medskip
|
|
167 |
FIXME proof data
|
18537
|
168 |
|
|
169 |
\glossary{Proof context}{The static context of a structured proof,
|
|
170 |
acts like a local ``theory'' of the current portion of Isar proof
|
|
171 |
text, generalizes the idea of local hypotheses @{text "\<Gamma>"} in
|
|
172 |
judgments @{text "\<Gamma> \<turnstile> \<phi>"} of natural deduction calculi. There is a
|
|
173 |
generic notion of introducing and discharging hypotheses. Arbritrary
|
|
174 |
auxiliary context data may be adjoined.}
|
|
175 |
|
|
176 |
*}
|
|
177 |
|
20430
|
178 |
text %mlref {* FIXME *}
|
|
179 |
|
20429
|
180 |
|
|
181 |
subsection {* Generic contexts *}
|
|
182 |
|
20430
|
183 |
text FIXME
|
|
184 |
|
|
185 |
text %mlref {* FIXME *}
|
|
186 |
|
20437
|
187 |
|
|
188 |
section {* Named entities *}
|
|
189 |
|
|
190 |
text {* Named entities of different kinds (logical constant, type,
|
|
191 |
type class, theorem, method etc.) live in separate name spaces. It is
|
|
192 |
usually clear from the occurrence of a name which kind of entity it
|
|
193 |
refers to. For example, proof method @{text "foo"} vs.\ theorem
|
|
194 |
@{text "foo"} vs.\ logical constant @{text "foo"} are easily
|
|
195 |
distinguished by means of the syntactic context. A notable exception
|
|
196 |
are logical identifiers within a term (\secref{sec:terms}): constants,
|
|
197 |
fixed variables, and bound variables all share the same identifier
|
|
198 |
syntax, but are distinguished by their scope.
|
|
199 |
|
|
200 |
Each name space is organized as a collection of \emph{qualified
|
|
201 |
names}, which consist of a sequence of basic name components separated
|
|
202 |
by dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"}
|
|
203 |
are examples for valid qualified names. Name components are
|
|
204 |
subdivided into \emph{symbols}, which constitute the smallest textual
|
|
205 |
unit in Isabelle --- raw characters are normally not encountered
|
|
206 |
directly. *}
|
|
207 |
|
|
208 |
|
|
209 |
subsection {* Strings of symbols *}
|
|
210 |
|
|
211 |
text {* Isabelle strings consist of a sequence of
|
|
212 |
symbols\glossary{Symbol}{The smalles unit of text in Isabelle,
|
|
213 |
subsumes plain ASCII characters as well as an infinite collection of
|
|
214 |
named symbols (for greek, math etc.).}, which are either packed as an
|
|
215 |
actual @{text "string"}, or represented as a list. Each symbol is in
|
|
216 |
itself a small string of the following form:
|
|
217 |
|
|
218 |
\begin{enumerate}
|
|
219 |
|
|
220 |
\item either a singleton ASCII character ``@{text "c"}'' (with
|
|
221 |
character code 0--127), for example ``\verb,a,'',
|
|
222 |
|
|
223 |
\item or a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'',
|
|
224 |
for example ``\verb,\,\verb,<alpha>,'',
|
|
225 |
|
|
226 |
\item or a control symbol ``\verb,\,\verb,<^,@{text
|
|
227 |
"ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'',
|
|
228 |
|
|
229 |
\item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text
|
|
230 |
"\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any
|
|
231 |
printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or
|
|
232 |
non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'',
|
|
233 |
|
|
234 |
\item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text
|
|
235 |
"nnn"}\verb,>, where @{text "nnn"} are digits, for example
|
|
236 |
``\verb,\,\verb,<^raw42>,''.
|
|
237 |
|
|
238 |
\end{enumerate}
|
|
239 |
|
|
240 |
The @{text "ident"} syntax for symbol names is @{text "letter (letter
|
|
241 |
| digit)\<^sup>*"}, where @{text "letter = A..Za..Z"} and @{text
|
|
242 |
"digit = 0..9"}. There are infinitely many regular symbols and
|
|
243 |
control symbols available, but a certain collection of standard
|
|
244 |
symbols is treated specifically. For example,
|
|
245 |
``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter,
|
|
246 |
which means it may occur within regular Isabelle identifier syntax.
|
|
247 |
|
|
248 |
Output of symbols depends on the print mode (\secref{sec:print-mode}).
|
|
249 |
For example, the standard {\LaTeX} setup of the Isabelle document
|
|
250 |
preparation system would present ``\verb,\,\verb,<alpha>,'' as @{text
|
|
251 |
"\<alpha>"}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text
|
|
252 |
"\<^bold>\<alpha>"}.
|
|
253 |
|
|
254 |
\medskip It is important to note that the character set underlying
|
|
255 |
Isabelle symbols is plain 7-bit ASCII. Since 8-bit characters are
|
|
256 |
passed through transparently, Isabelle may easily process actual
|
|
257 |
Unicode/UCS data (using the well-known UTF-8 encoding, for example).
|
|
258 |
Unicode provides its own collection of mathematical symbols, but there
|
|
259 |
is presently no link to Isabelle's named ones; both kinds of symbols
|
|
260 |
coexist independently. *}
|
|
261 |
|
|
262 |
text %mlref {*
|
|
263 |
\begin{mldecls}
|
|
264 |
@{index_ML_type "Symbol.symbol"} \\
|
|
265 |
@{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\
|
|
266 |
@{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\
|
|
267 |
@{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\
|
|
268 |
@{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\
|
|
269 |
@{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\
|
|
270 |
@{index_ML_type "Symbol.sym"} \\
|
|
271 |
@{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\
|
|
272 |
\end{mldecls}
|
|
273 |
|
|
274 |
\begin{description}
|
|
275 |
|
|
276 |
\item @{ML_type "Symbol.symbol"} represents Isabelle symbols; this type
|
|
277 |
is merely an alias for @{ML_type "string"}, but emphasizes the
|
|
278 |
specific format encountered here.
|
|
279 |
|
|
280 |
\item @{ML "Symbol.explode"}~@{text "s"} produces an actual symbol
|
|
281 |
list from the packed form usually encountered as user input. This
|
|
282 |
function replaces @{ML "String.explode"} for virtually all purposes
|
|
283 |
of manipulating text in Isabelle! Plain @{text "implode"} may be
|
|
284 |
used for the reverse operation.
|
|
285 |
|
|
286 |
\item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML
|
|
287 |
"Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols
|
|
288 |
(both ASCII and several named ones) according to fixed syntactic
|
|
289 |
convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}.
|
|
290 |
|
|
291 |
\item @{ML_type "Symbol.sym"} is a concrete datatype that represents
|
|
292 |
the different kinds of symbols explicitly as @{ML "Symbol.Char"},
|
|
293 |
@{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML "Symbol.Raw"}.
|
|
294 |
|
|
295 |
\item @{ML "Symbol.decode"} converts the string representation of a
|
|
296 |
symbol into the explicit datatype version.
|
|
297 |
|
|
298 |
\end{description}
|
|
299 |
*}
|
|
300 |
|
|
301 |
|
|
302 |
subsection {* Qualified names and name spaces *}
|
|
303 |
|
|
304 |
text %FIXME {* Qualified names are constructed according to implicit naming
|
|
305 |
principles of the present context.
|
|
306 |
|
|
307 |
|
|
308 |
The last component is called \emph{base name}; the remaining prefix of
|
|
309 |
qualification may be empty.
|
|
310 |
|
|
311 |
Some practical conventions help to organize named entities more
|
|
312 |
systematically:
|
|
313 |
|
|
314 |
\begin{itemize}
|
|
315 |
|
|
316 |
\item Names are qualified first by the theory name, second by an
|
|
317 |
optional ``structure''. For example, a constant @{text "c"} declared
|
|
318 |
as part of a certain structure @{text "b"} (say a type definition) in
|
|
319 |
theory @{text "A"} will be named @{text "A.b.c"} internally.
|
|
320 |
|
|
321 |
\item
|
|
322 |
|
|
323 |
\item
|
|
324 |
|
|
325 |
\item
|
|
326 |
|
|
327 |
\item
|
|
328 |
|
|
329 |
\end{itemize}
|
|
330 |
|
|
331 |
Names of different kinds of entities are basically independent, but
|
|
332 |
some practical naming conventions relate them to each other. For
|
|
333 |
example, a constant @{text "foo"} may be accompanied with theorems
|
|
334 |
@{text "foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc. The
|
|
335 |
same may happen for a type @{text "foo"}, which is then apt to cause
|
|
336 |
clashes in the theorem name space! To avoid this, we occasionally
|
|
337 |
follow an additional convention of suffixes that determine the
|
|
338 |
original kind of entity that a name has been derived. For example,
|
|
339 |
constant @{text "foo"} is associated with theorem @{text "foo.intro"},
|
|
340 |
type @{text "foo"} with theorem @{text "foo_type.intro"}, and type
|
|
341 |
class @{text "foo"} with @{text "foo_class.intro"}.
|
|
342 |
|
|
343 |
*}
|
|
344 |
|
|
345 |
|
|
346 |
section {* Structured output *}
|
|
347 |
|
|
348 |
subsection {* Pretty printing *}
|
|
349 |
|
|
350 |
text FIXME
|
|
351 |
|
|
352 |
subsection {* Output channels *}
|
|
353 |
|
|
354 |
text FIXME
|
|
355 |
|
|
356 |
subsection {* Print modes *}
|
|
357 |
|
|
358 |
text FIXME
|
|
359 |
|
|
360 |
|
18537
|
361 |
end
|