6 chapter {* Preliminaries *} |
6 chapter {* Preliminaries *} |
7 |
7 |
8 section {* Contexts \label{sec:context} *} |
8 section {* Contexts \label{sec:context} *} |
9 |
9 |
10 text {* |
10 text {* |
11 A logical context represents the background that is taken for |
11 A logical context represents the background that is required for |
12 granted when formulating statements and composing proofs. It acts |
12 formulating statements and composing proofs. It acts as a medium to |
13 as a medium to produce formal content, depending on earlier material |
13 produce formal content, depending on earlier material (declarations, |
14 (declarations, results etc.). |
14 results etc.). |
15 |
15 |
16 In particular, derivations within the primitive Pure logic can be |
16 For example, derivations within the Isabelle/Pure logic can be |
17 described as a judgment @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}, meaning that a |
17 described as a judgment @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"}, which means that a |
18 proposition @{text "\<phi>"} is derivable from hypotheses @{text "\<Gamma>"} |
18 proposition @{text "\<phi>"} is derivable from hypotheses @{text "\<Gamma>"} |
19 within the theory @{text "\<Theta>"}. There are logical reasons for |
19 within the theory @{text "\<Theta>"}. There are logical reasons for |
20 keeping @{text "\<Theta>"} and @{text "\<Gamma>"} separate: theories support type |
20 keeping @{text "\<Theta>"} and @{text "\<Gamma>"} separate: theories can be |
21 constructors and schematic polymorphism of constants and axioms, |
21 liberal about supporting type constructors and schematic |
22 while the inner calculus of @{text "\<Gamma> \<turnstile> \<phi>"} is limited to Simple |
22 polymorphism of constants and axioms, while the inner calculus of |
23 Type Theory (with fixed type variables in the assumptions). |
23 @{text "\<Gamma> \<turnstile> \<phi>"} is strictly limited to Simple Type Theory (with |
|
24 fixed type variables in the assumptions). |
24 |
25 |
25 \medskip Contexts and derivations are linked by the following key |
26 \medskip Contexts and derivations are linked by the following key |
26 principles: |
27 principles: |
27 |
28 |
28 \begin{itemize} |
29 \begin{itemize} |
29 |
30 |
30 \item Transfer: monotonicity of derivations admits results to be |
31 \item Transfer: monotonicity of derivations admits results to be |
31 transferred into a larger context, i.e.\ @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<phi>"} |
32 transferred into a \emph{larger} context, i.e.\ @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> |
32 implies @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta>\<^sub>' \<phi>"} for contexts @{text "\<Theta>' \<supseteq> |
33 \<phi>"} implies @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta>\<^sub>' \<phi>"} for contexts @{text "\<Theta>' |
33 \<Theta>"} and @{text "\<Gamma>' \<supseteq> \<Gamma>"}. |
34 \<supseteq> \<Theta>"} and @{text "\<Gamma>' \<supseteq> \<Gamma>"}. |
34 |
35 |
35 \item Export: discharge of hypotheses admits results to be exported |
36 \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 into a \emph{smaller} context, i.e.\ @{text "\<Gamma>' \<turnstile>\<^sub>\<Theta> \<phi>"} |
37 @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<Delta> \<Longrightarrow> \<phi>"} where @{text "\<Gamma>' \<supseteq> \<Gamma>"} and @{text "\<Delta> = |
38 implies @{text "\<Gamma> \<turnstile>\<^sub>\<Theta> \<Delta> \<Longrightarrow> \<phi>"} where @{text "\<Gamma>' \<supseteq> \<Gamma>"} and |
38 \<Gamma>' - \<Gamma>"}. Note that @{text "\<Theta>"} remains unchanged here, only the |
39 @{text "\<Delta> = \<Gamma>' - \<Gamma>"}. Note that @{text "\<Theta>"} remains unchanged here, |
39 @{text "\<Gamma>"} part is affected. |
40 only the @{text "\<Gamma>"} part is affected. |
40 |
41 |
41 \end{itemize} |
42 \end{itemize} |
42 |
43 |
43 \medskip Isabelle/Isar provides two different notions of abstract |
44 \medskip By modeling the main characteristics of the primitive |
44 containers called \emph{theory context} and \emph{proof context}, |
45 @{text "\<Theta>"} and @{text "\<Gamma>"} above, and abstracting over any |
45 respectively. These model the main characteristics of the primitive |
46 particular logical content, we arrive at the fundamental notions of |
46 @{text "\<Theta>"} and @{text "\<Gamma>"} above, without subscribing to any |
47 \emph{theory context} and \emph{proof context} in Isabelle/Isar. |
47 particular kind of content yet. Instead, contexts merely impose a |
48 These implement a certain policy to manage arbitrary \emph{context |
48 certain policy of managing arbitrary \emph{context data}. The |
49 data}. There is a strongly-typed mechanism to declare new kinds of |
49 system provides strongly typed mechanisms to declare new kinds of |
|
50 data at compile time. |
50 data at compile time. |
51 |
51 |
52 Thus the internal bootstrap process of Isabelle/Pure eventually |
52 The internal bootstrap process of Isabelle/Pure eventually reaches a |
53 reaches a stage where certain data slots provide the logical content |
53 stage where certain data slots provide the logical content of @{text |
54 of @{text "\<Theta>"} and @{text "\<Gamma>"} sketched above, but this does not |
54 "\<Theta>"} and @{text "\<Gamma>"} sketched above, but this does not stop there! |
55 stop there! Various additional data slots support all kinds of |
55 Various additional data slots support all kinds of mechanisms that |
56 mechanisms that are not necessarily part of the core logic. |
56 are not necessarily part of the core logic. |
57 |
57 |
58 For example, there would be data for canonical introduction and |
58 For example, there would be data for canonical introduction and |
59 elimination rules for arbitrary operators (depending on the |
59 elimination rules for arbitrary operators (depending on the |
60 object-logic and application), which enables users to perform |
60 object-logic and application), which enables users to perform |
61 standard proof steps implicitly (cf.\ the @{text "rule"} method). |
61 standard proof steps implicitly (cf.\ the @{text "rule"} method |
62 |
62 \cite{isabelle-isar-ref}). |
63 Isabelle is able to bring forth more and more concepts successively. |
63 |
64 In particular, an object-logic like Isabelle/HOL continues the |
64 \medskip Thus Isabelle/Isar is able to bring forth more and more |
65 Isabelle/Pure setup by adding specific components for automated |
65 concepts successively. In particular, an object-logic like |
66 reasoning (classical reasoner, tableau prover, structured induction |
66 Isabelle/HOL continues the Isabelle/Pure setup by adding specific |
67 etc.) and derived specification mechanisms (inductive predicates, |
67 components for automated reasoning (classical reasoner, tableau |
68 recursive functions etc.). All of this is based on the generic data |
68 prover, structured induction etc.) and derived specification |
69 management by theory and proof contexts. |
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. |
70 *} |
72 *} |
71 |
73 |
72 |
74 |
73 subsection {* Theory context \label{sec:context-theory} *} |
75 subsection {* Theory context \label{sec:context-theory} *} |
74 |
76 |
75 text {* |
77 text {* |
76 \glossary{Theory}{FIXME} |
78 \glossary{Theory}{FIXME} |
77 |
79 |
78 Each theory is explicitly named and holds a unique identifier. |
80 A \emph{theory} is a data container with explicit named and unique |
79 There is a separate \emph{theory reference} for pointing backwards |
81 identifier. Theories are related by a (nominal) sub-theory |
80 to the enclosing theory context of derived entities. Theories are |
82 relation, which corresponds to the dependency graph of the original |
81 related by a (nominal) sub-theory relation, which corresponds to the |
83 construction; each theory is derived from a certain sub-graph of |
82 canonical dependency graph: each theory is derived from a certain |
84 ancestor theories. |
83 sub-graph of ancestor theories. The @{text "merge"} of two theories |
85 |
84 refers to the least upper bound, which actually degenerates into |
86 The @{text "merge"} operation produces the least upper bound of two |
85 absorption of one theory into the other, due to the nominal |
87 theories, which actually degenerates into absorption of one theory |
86 sub-theory relation this. |
88 into the other (due to the nominal sub-theory relation). |
87 |
89 |
88 The @{text "begin"} operation starts a new theory by importing |
90 The @{text "begin"} operation starts a new theory by importing |
89 several parent theories and entering a special @{text "draft"} mode, |
91 several parent theories and entering a special @{text "draft"} mode, |
90 which is sustained until the final @{text "end"} operation. A draft |
92 which is sustained until the final @{text "end"} operation. A draft |
91 mode theory acts like a linear type, where updates invalidate |
93 theory acts like a linear type, where updates invalidate earlier |
92 earlier drafts, but theory reference values will be propagated |
94 versions. An invalidated draft is called ``stale''. |
93 automatically. Thus derived entities that ``belong'' to a draft |
|
94 might be transferred spontaneously to a larger context. An |
|
95 invalidated draft is called ``stale''. |
|
96 |
95 |
97 The @{text "checkpoint"} operation produces an intermediate stepping |
96 The @{text "checkpoint"} operation produces an intermediate stepping |
98 stone that will survive the next update unscathed: both the original |
97 stone that will survive the next update: both the original and the |
99 and the changed theory remain valid and are related by the |
98 changed theory remain valid and are related by the sub-theory |
100 sub-theory relation. Checkpointing essentially recovers purely |
99 relation. Checkpointing essentially recovers purely functional |
101 functional theory values, at the expense of some extra internal |
100 theory values, at the expense of some extra internal bookkeeping. |
102 bookkeeping. |
|
103 |
101 |
104 The @{text "copy"} operation produces an auxiliary version that has |
102 The @{text "copy"} operation produces an auxiliary version that has |
105 the same data content, but is unrelated to the original: updates of |
103 the same data content, but is unrelated to the original: updates of |
106 the copy do not affect the original, neither does the sub-theory |
104 the copy do not affect the original, neither does the sub-theory |
107 relation hold. |
105 relation hold. |
108 |
106 |
109 \medskip The example in \figref{fig:ex-theory} below shows a theory |
107 \medskip The example in \figref{fig:ex-theory} below shows a theory |
110 graph derived from @{text "Pure"}. Theory @{text "Length"} imports |
108 graph derived from @{text "Pure"}, with theory @{text "Length"} |
111 @{text "Nat"} and @{text "List"}. The theory body consists of a |
109 importing @{text "Nat"} and @{text "List"}. The body of @{text |
112 sequence of updates, working mostly on drafts. Intermediate |
110 "Length"} consists of a sequence of updates, working mostly on |
113 checkpoints may occur as well, due to the history mechanism provided |
111 drafts. Intermediate checkpoints may occur as well, due to the |
114 by the Isar top-level, cf.\ \secref{sec:isar-toplevel}. |
112 history mechanism provided by the Isar top-level, cf.\ |
|
113 \secref{sec:isar-toplevel}. |
115 |
114 |
116 \begin{figure}[htb] |
115 \begin{figure}[htb] |
117 \begin{center} |
116 \begin{center} |
118 \begin{tabular}{rcccl} |
117 \begin{tabular}{rcccl} |
119 & & @{text "Pure"} \\ |
118 & & @{text "Pure"} \\ |
196 generic notion of introducing and discharging hypotheses. |
205 generic notion of introducing and discharging hypotheses. |
197 Arbritrary auxiliary context data may be adjoined.} |
206 Arbritrary auxiliary context data may be adjoined.} |
198 |
207 |
199 A proof context is a container for pure data with a back-reference |
208 A proof context is a container for pure data with a back-reference |
200 to the theory it belongs to. The @{text "init"} operation creates a |
209 to the theory it belongs to. The @{text "init"} operation creates a |
201 proof context derived from a given theory. Modifications to draft |
210 proof context from a given theory. Modifications to draft theories |
202 theories are propagated to the proof context as usual, but there is |
211 are propagated to the proof context as usual, but there is also an |
203 also an explicit @{text "transfer"} operation to force |
212 explicit @{text "transfer"} operation to force resynchronization |
204 resynchronization with more substantial updates to the underlying |
213 with more substantial updates to the underlying theory. The actual |
205 theory. The actual context data does not require any special |
214 context data does not require any special bookkeeping, thanks to the |
206 bookkeeping, thanks to the lack of destructive features. |
215 lack of destructive features. |
207 |
216 |
208 Entities derived in a proof context need to record inherent logical |
217 Entities derived in a proof context need to record inherent logical |
209 requirements explicitly, since there is no separate context |
218 requirements explicitly, since there is no separate context |
210 identification as for theories. For example, hypotheses used in |
219 identification as for theories. For example, hypotheses used in |
211 primitive derivations (cf.\ \secref{sec:thm}) are recorded |
220 primitive derivations (cf.\ \secref{sec:thms}) are recorded |
212 separately within the sequent @{text "\<Gamma> \<turnstile> \<phi>"}, just to make double |
221 separately within the sequent @{text "\<Gamma> \<turnstile> \<phi>"}, just to make double |
213 sure. Results could still leak into an alien proof context do to |
222 sure. Results could still leak into an alien proof context do to |
214 programming errors, but Isabelle/Isar includes some extra validity |
223 programming errors, but Isabelle/Isar includes some extra validity |
215 checks in critical positions, notably at the end of sub-proof. |
224 checks in critical positions, notably at the end of sub-proof. |
216 |
225 |
217 Proof contexts may be produced in arbitrary ways, although the |
226 Proof contexts may be manipulated arbitrarily, although the common |
218 common discipline is to follow block structure as a mental model: a |
227 discipline is to follow block structure as a mental model: a given |
219 given context is extended consecutively, and results are exported |
228 context is extended consecutively, and results are exported back |
220 back into the original context. Note that the Isar proof states |
229 into the original context. Note that the Isar proof states model |
221 model block-structured reasoning explicitly, using a stack of proof |
230 block-structured reasoning explicitly, using a stack of proof |
222 contexts, cf.\ \secref{isar-proof-state}. |
231 contexts internally, cf.\ \secref{sec:isar-proof-state}. |
223 *} |
232 *} |
224 |
233 |
225 text %mlref {* |
234 text %mlref {* |
226 \begin{mldecls} |
235 \begin{mldecls} |
227 @{index_ML_type Proof.context} \\ |
236 @{index_ML_type Proof.context} \\ |
275 \end{mldecls} |
284 \end{mldecls} |
276 |
285 |
277 \begin{description} |
286 \begin{description} |
278 |
287 |
279 \item @{ML_type Context.generic} is the direct sum of @{ML_type |
288 \item @{ML_type Context.generic} is the direct sum of @{ML_type |
280 "theory"} and @{ML_type "Proof.context"}, with datatype constructors |
289 "theory"} and @{ML_type "Proof.context"}, with the datatype |
281 @{ML "Context.Theory"} and @{ML "Context.Proof"}. |
290 constructors @{ML "Context.Theory"} and @{ML "Context.Proof"}. |
282 |
291 |
283 \item @{ML Context.theory_of}~@{text "context"} always produces a |
292 \item @{ML Context.theory_of}~@{text "context"} always produces a |
284 theory from the generic @{text "context"}, using @{ML |
293 theory from the generic @{text "context"}, using @{ML |
285 "ProofContext.theory_of"} as required. |
294 "ProofContext.theory_of"} as required. |
286 |
295 |
287 \item @{ML Context.proof_of}~@{text "context"} always produces a |
296 \item @{ML Context.proof_of}~@{text "context"} always produces a |
288 proof context from the generic @{text "context"}, using @{ML |
297 proof context from the generic @{text "context"}, using @{ML |
289 "ProofContext.init"} as required. Note that this re-initializes the |
298 "ProofContext.init"} as required (note that this re-initializes the |
290 context data with each invocation. |
299 context data with each invocation). |
291 |
300 |
292 \end{description} |
301 \end{description} |
293 *} |
302 *} |
294 |
303 |
295 subsection {* Context data *} |
304 subsection {* Context data *} |
296 |
305 |
297 text {* |
306 text {* |
298 Both theory and proof contexts manage arbitrary data, which is the |
307 The main purpose of theory and proof contexts is to manage arbitrary |
299 main purpose of contexts in the first place. Data can be declared |
308 data. New data types can be declared incrementally at compile time. |
300 incrementally at compile --- Isabelle/Pure and major object-logics |
309 There are separate declaration mechanisms for any of the three kinds |
301 are bootstrapped that way. |
310 of contexts: theory, proof, generic. |
302 |
311 |
303 \paragraph{Theory data} may refer to destructive entities, which are |
312 \paragraph{Theory data} may refer to destructive entities, which are |
304 maintained in correspondence to the linear evolution of theory |
313 maintained in direct correspondence to the linear evolution of |
305 values, or explicit copies.\footnote{Most existing instances of |
314 theory values, including explicit copies.\footnote{Most existing |
306 destructive theory data are merely historical relics (e.g.\ the |
315 instances of destructive theory data are merely historical relics |
307 destructive theorem storage, and destructive hints for the |
316 (e.g.\ the destructive theorem storage, and destructive hints for |
308 Simplifier and Classical rules).} A theory data declaration needs |
317 the Simplifier and Classical rules).} A theory data declaration |
309 to implement the following specification: |
318 needs to implement the following specification (depending on type |
|
319 @{text "T"}): |
310 |
320 |
311 \medskip |
321 \medskip |
312 \begin{tabular}{ll} |
322 \begin{tabular}{ll} |
313 @{text "name: string"} \\ |
323 @{text "name: string"} \\ |
314 @{text "T"} & the ML type \\ |
|
315 @{text "empty: T"} & initial value \\ |
324 @{text "empty: T"} & initial value \\ |
316 @{text "copy: T \<rightarrow> T"} & refresh impure data \\ |
325 @{text "copy: T \<rightarrow> T"} & refresh impure data \\ |
317 @{text "extend: T \<rightarrow> T"} & re-initialize on import \\ |
326 @{text "extend: T \<rightarrow> T"} & re-initialize on import \\ |
318 @{text "merge: T \<times> T \<rightarrow> T"} & join on import \\ |
327 @{text "merge: T \<times> T \<rightarrow> T"} & join on import \\ |
319 @{text "print: T \<rightarrow> unit"} & diagnostic output \\ |
328 @{text "print: T \<rightarrow> unit"} & diagnostic output \\ |
395 *} |
403 *} |
396 |
404 |
397 |
405 |
398 section {* Named entities *} |
406 section {* Named entities *} |
399 |
407 |
400 text {* Named entities of different kinds (logical constant, type, |
408 text {* |
401 type class, theorem, method etc.) live in separate name spaces. It is |
409 By general convention, each kind of formal entities (logical |
402 usually clear from the occurrence of a name which kind of entity it |
410 constant, type, type class, theorem, method etc.) lives in a |
403 refers to. For example, proof method @{text "foo"} vs.\ theorem |
411 separate name space. It is usually clear from the syntactic context |
404 @{text "foo"} vs.\ logical constant @{text "foo"} are easily |
412 of a name, which kind of entity it refers to. For example, proof |
405 distinguished by means of the syntactic context. A notable exception |
413 method @{text "foo"} vs.\ theorem @{text "foo"} vs.\ logical |
406 are logical identifiers within a term (\secref{sec:terms}): constants, |
414 constant @{text "foo"} are easily distinguished thanks to the design |
407 fixed variables, and bound variables all share the same identifier |
415 of the concrete outer syntax. A notable exception are logical |
408 syntax, but are distinguished by their scope. |
416 identifiers within a term (\secref{sec:terms}): constants, fixed |
409 |
417 variables, and bound variables all share the same identifier syntax, |
410 Each name space is organized as a collection of \emph{qualified |
418 but are distinguished by their scope. |
411 names}, which consist of a sequence of basic name components separated |
419 |
412 by dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"} |
420 Name spaces are organized uniformly, as a collection of qualified |
413 are examples for valid qualified names. Name components are |
421 names consisting of a sequence of basic name components separated by |
414 subdivided into \emph{symbols}, which constitute the smallest textual |
422 dots: @{text "Bar.bar.foo"}, @{text "Bar.foo"}, and @{text "foo"} |
415 unit in Isabelle --- raw characters are normally not encountered |
423 are examples for qualified names. |
416 directly. *} |
424 |
|
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 *} |
417 |
441 |
418 |
442 |
419 subsection {* Strings of symbols *} |
443 subsection {* Strings of symbols *} |
420 |
444 |
421 text {* Isabelle strings consist of a sequence of |
445 text {* |
422 symbols\glossary{Symbol}{The smallest unit of text in Isabelle, |
446 Isabelle strings consist of a sequence of |
423 subsumes plain ASCII characters as well as an infinite collection of |
447 symbols\glossary{Symbol}{The smallest unit of text in Isabelle, |
424 named symbols (for greek, math etc.).}, which are either packed as an |
448 subsumes plain ASCII characters as well as an infinite collection of |
425 actual @{text "string"}, or represented as a list. Each symbol is in |
449 named symbols (for greek, math etc.).}, which are either packed as |
426 itself a small string of the following form: |
450 an actual @{text "string"}, or represented as a list. Each symbol |
427 |
451 is in itself a small string of the following form: |
428 \begin{enumerate} |
452 |
429 |
453 \begin{enumerate} |
430 \item either a singleton ASCII character ``@{text "c"}'' (with |
454 |
431 character code 0--127), for example ``\verb,a,'', |
455 \item either a singleton ASCII character ``@{text "c"}'' (with |
432 |
456 character code 0--127), for example ``\verb,a,'', |
433 \item or a regular symbol ``\verb,\,\verb,<,@{text "ident"}\verb,>,'', |
457 |
434 for example ``\verb,\,\verb,<alpha>,'', |
458 \item or a regular symbol ``\verb,\,\verb,<,@{text |
435 |
459 "ident"}\verb,>,'', for example ``\verb,\,\verb,<alpha>,'', |
436 \item or a control symbol ``\verb,\,\verb,<^,@{text |
460 |
437 "ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'', |
461 \item or a control symbol ``\verb,\,\verb,<^,@{text |
438 |
462 "ident"}\verb,>,'', for example ``\verb,\,\verb,<^bold>,'', |
439 \item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text |
463 |
440 "\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any |
464 \item or a raw control symbol ``\verb,\,\verb,<^raw:,@{text |
441 printable ASCII character (excluding ``\verb,.,'' and ``\verb,>,'') or |
465 "\<dots>"}\verb,>,'' where ``@{text "\<dots>"}'' refers to any printable ASCII |
442 non-ASCII character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'', |
466 character (excluding ``\verb,.,'' and ``\verb,>,'') or non-ASCII |
443 |
467 character, for example ``\verb,\,\verb,<^raw:$\sum_{i = 1}^n$>,'', |
444 \item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text |
468 |
445 "nnn"}\verb,>, where @{text "nnn"} are digits, for example |
469 \item or a numbered raw control symbol ``\verb,\,\verb,<^raw,@{text |
446 ``\verb,\,\verb,<^raw42>,''. |
470 "nnn"}\verb,>, where @{text "nnn"} are digits, for example |
447 |
471 ``\verb,\,\verb,<^raw42>,''. |
448 \end{enumerate} |
472 |
449 |
473 \end{enumerate} |
450 The @{text "ident"} syntax for symbol names is @{text "letter (letter |
474 |
451 | digit)\<^sup>*"}, where @{text "letter = A..Za..Z"} and @{text |
475 The @{text "ident"} syntax for symbol names is @{text "letter |
452 "digit = 0..9"}. There are infinitely many regular symbols and |
476 (letter | digit)\<^sup>*"}, where @{text "letter = A..Za..z"} and |
453 control symbols available, but a certain collection of standard |
477 @{text "digit = 0..9"}. There are infinitely many regular symbols |
454 symbols is treated specifically. For example, |
478 and control symbols available, but a certain collection of standard |
455 ``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter, |
479 symbols is treated specifically. For example, |
456 which means it may occur within regular Isabelle identifier syntax. |
480 ``\verb,\,\verb,<alpha>,'' is classified as a (non-ASCII) letter, |
457 |
481 which means it may occur within regular Isabelle identifier syntax. |
458 Output of symbols depends on the print mode (\secref{sec:print-mode}). |
482 |
459 For example, the standard {\LaTeX} setup of the Isabelle document |
483 Output of symbols depends on the print mode |
460 preparation system would present ``\verb,\,\verb,<alpha>,'' as @{text |
484 (\secref{sec:print-mode}). For example, the standard {\LaTeX} setup |
461 "\<alpha>"}, and ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text |
485 of the Isabelle document preparation system would present |
462 "\<^bold>\<alpha>"}. |
486 ``\verb,\,\verb,<alpha>,'' as @{text "\<alpha>"}, and |
463 |
487 ``\verb,\,\verb,<^bold>,\verb,\,\verb,<alpha>,'' as @{text |
464 \medskip It is important to note that the character set underlying |
488 "\<^bold>\<alpha>"}. |
465 Isabelle symbols is plain 7-bit ASCII. Since 8-bit characters are |
489 |
466 passed through transparently, Isabelle may easily process actual |
490 \medskip It is important to note that the character set underlying |
467 Unicode/UCS data (using the well-known UTF-8 encoding, for example). |
491 Isabelle symbols is plain 7-bit ASCII. Since 8-bit characters are |
468 Unicode provides its own collection of mathematical symbols, but there |
492 passed through transparently, Isabelle may easily process |
469 is presently no link to Isabelle's named ones; both kinds of symbols |
493 Unicode/UCS data as well (using UTF-8 encoding). Unicode provides |
470 coexist independently. *} |
494 its own collection of mathematical symbols, but there is no built-in |
|
495 link to the ones of Isabelle. |
|
496 *} |
471 |
497 |
472 text %mlref {* |
498 text %mlref {* |
473 \begin{mldecls} |
499 \begin{mldecls} |
474 @{index_ML_type "Symbol.symbol"} \\ |
500 @{index_ML_type "Symbol.symbol"} \\ |
475 @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\ |
501 @{index_ML Symbol.explode: "string -> Symbol.symbol list"} \\ |
476 @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\ |
502 @{index_ML Symbol.is_letter: "Symbol.symbol -> bool"} \\ |
477 @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\ |
503 @{index_ML Symbol.is_digit: "Symbol.symbol -> bool"} \\ |
478 @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\ |
504 @{index_ML Symbol.is_quasi: "Symbol.symbol -> bool"} \\ |
479 @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\ |
505 @{index_ML Symbol.is_blank: "Symbol.symbol -> bool"} \\[1ex] |
480 @{index_ML_type "Symbol.sym"} \\ |
506 @{index_ML_type "Symbol.sym"} \\ |
481 @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\ |
507 @{index_ML Symbol.decode: "Symbol.symbol -> Symbol.sym"} \\ |
482 \end{mldecls} |
508 \end{mldecls} |
483 |
509 |
484 \begin{description} |
510 \begin{description} |
485 |
511 |
486 \item @{ML_type "Symbol.symbol"} represents Isabelle symbols; this type |
512 \item @{ML_type "Symbol.symbol"} represents Isabelle symbols. This |
487 is merely an alias for @{ML_type "string"}, but emphasizes the |
513 type is an alias for @{ML_type "string"}, but emphasizes the |
488 specific format encountered here. |
514 specific format encountered here. |
489 |
515 |
490 \item @{ML "Symbol.explode"}~@{text "s"} produces a symbol list from |
516 \item @{ML "Symbol.explode"}~@{text "s"} produces a symbol list from |
491 the packed form usually encountered as user input. This function |
517 the packed form that is encountered in most practical situations. |
492 replaces @{ML "String.explode"} for virtually all purposes of |
518 This function supercedes @{ML "String.explode"} for virtually all |
493 manipulating text in Isabelle! Plain @{ML "implode"} may be used |
519 purposes of manipulating text in Isabelle! Plain @{ML "implode"} |
494 for the reverse operation. |
520 may still be used for the reverse operation. |
495 |
521 |
496 \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML |
522 \item @{ML "Symbol.is_letter"}, @{ML "Symbol.is_digit"}, @{ML |
497 "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols |
523 "Symbol.is_quasi"}, @{ML "Symbol.is_blank"} classify certain symbols |
498 (both ASCII and several named ones) according to fixed syntactic |
524 (both ASCII and several named ones) according to fixed syntactic |
499 convections of Isabelle, e.g.\ see \cite{isabelle-isar-ref}. |
525 conventions of Isabelle, cf.\ \cite{isabelle-isar-ref}. |
500 |
526 |
501 \item @{ML_type "Symbol.sym"} is a concrete datatype that represents |
527 \item @{ML_type "Symbol.sym"} is a concrete datatype that represents |
502 the different kinds of symbols explicitly as @{ML "Symbol.Char"}, |
528 the different kinds of symbols explicitly with constructors @{ML |
503 @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML "Symbol.Raw"}. |
529 "Symbol.Char"}, @{ML "Symbol.Sym"}, @{ML "Symbol.Ctrl"}, or @{ML |
|
530 "Symbol.Raw"}. |
504 |
531 |
505 \item @{ML "Symbol.decode"} converts the string representation of a |
532 \item @{ML "Symbol.decode"} converts the string representation of a |
506 symbol into the explicit datatype version. |
533 symbol into the datatype version. |
507 |
534 |
508 \end{description} |
535 \end{description} |
509 *} |
536 *} |
510 |
537 |
511 |
538 |
512 subsection {* Qualified names and name spaces *} |
539 subsection {* Qualified names and name spaces *} |
513 |
540 |
514 text {* |
541 text {* |
|
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). |
|
547 |
|
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. |
|
553 |
|
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 |
515 FIXME |
558 FIXME |
516 |
559 *} |
517 Qualified names are constructed according to implicit naming |
560 |
518 principles of the present context. |
561 text %mlref FIXME |
519 |
|
520 |
|
521 The last component is called \emph{base name}; the remaining prefix |
|
522 of qualification may be empty. |
|
523 |
|
524 Some practical conventions help to organize named entities more |
|
525 systematically: |
|
526 |
|
527 \begin{itemize} |
|
528 |
|
529 \item Names are qualified first by the theory name, second by an |
|
530 optional ``structure''. For example, a constant @{text "c"} |
|
531 declared as part of a certain structure @{text "b"} (say a type |
|
532 definition) in theory @{text "A"} will be named @{text "A.b.c"} |
|
533 internally. |
|
534 |
|
535 \item |
|
536 |
|
537 \item |
|
538 |
|
539 \item |
|
540 |
|
541 \item |
|
542 |
|
543 \end{itemize} |
|
544 |
|
545 Names of different kinds of entities are basically independent, but |
|
546 some practical naming conventions relate them to each other. For |
|
547 example, a constant @{text "foo"} may be accompanied with theorems |
|
548 @{text "foo.intro"}, @{text "foo.elim"}, @{text "foo.simps"} etc. |
|
549 The same may happen for a type @{text "foo"}, which is then apt to |
|
550 cause clashes in the theorem name space! To avoid this, we |
|
551 occasionally follow an additional convention of suffixes that |
|
552 determine the original kind of entity that a name has been derived. |
|
553 For example, constant @{text "foo"} is associated with theorem |
|
554 @{text "foo.intro"}, type @{text "foo"} with theorem @{text |
|
555 "foo_type.intro"}, and type class @{text "foo"} with @{text |
|
556 "foo_class.intro"}. |
|
557 *} |
|
558 |
562 |
559 |
563 |
560 section {* Structured output *} |
564 section {* Structured output *} |
561 |
565 |
562 subsection {* Pretty printing *} |
566 subsection {* Pretty printing *} |