89 (\S\ref{sec:syn-trans}). Type declaration and internal syntactic |
86 (\S\ref{sec:syn-trans}). Type declaration and internal syntactic |
90 representation of the given entity is retrieved from the context. |
87 representation of the given entity is retrieved from the context. |
91 |
88 |
92 \end{descr} |
89 \end{descr} |
93 |
90 |
94 Any of these specifications support an optional target locale context |
91 All of these specifications support local theory targets (cf.\ |
95 (cf.\ \S\ref{sec:locale}). In the latter case, constants being |
92 \S\ref{sec:target}). |
96 introduced depend on certain fixed parameters of the locale context; |
93 |
97 the constant name is qualified by the locale base name. A syntactic |
94 |
98 abbreviation takes care for convenient input and output of such terms, |
95 \subsection{Local theory targets}\label{sec:target} |
99 making the parameters implicit and using the original short name. |
96 |
100 Outside the locale context, the specified entities are available in |
97 A local theory target is a context managed separately within the |
101 generalized form, with the parameters being open to explicit |
98 enclosing theory. Contexts may introduce parameters (fixed variables) |
102 instantiation. |
99 and assumptions (hypotheses). Definitions and theorems depending on |
103 |
100 the context may be added incrementally later on. Named contexts refer |
104 |
101 to locales (cf.\ \S\ref{sec:locale}) or type classes (cf.\ |
105 \subsection{Locales and local contexts}\label{sec:locale} |
102 \S\ref{sec:class}); the name ``$-$'' signifies the global theory |
|
103 context. |
|
104 |
|
105 \indexisarcmd{context}\indexisarcmd{end} |
|
106 \begin{matharray}{rcll} |
|
107 \isarcmd{context} & : & \isartrans{theory}{local{\dsh}theory} \\ |
|
108 \isarcmd{end} & : & \isartrans{local{\dsh}theory}{theory} \\ |
|
109 \end{matharray} |
|
110 |
|
111 \indexouternonterm{target} |
|
112 \begin{rail} |
|
113 'context' name 'begin' |
|
114 ; |
|
115 |
|
116 target: '(' 'in' name ')' |
|
117 ; |
|
118 \end{rail} |
|
119 |
|
120 \begin{descr} |
|
121 |
|
122 \item $\isarkeyword{context}~c~\isarkeyword{begin}$ recommences an |
|
123 existing locale or class context $c$. Note that locale and class |
|
124 definitions allow to include the $\isarkeyword{begin}$ keyword as |
|
125 well, in order to continue the local theory immediately after the |
|
126 initial specification. |
|
127 |
|
128 \item $\END$ concludes the current local theory and continues the |
|
129 enclosing global theory. Note that a non-local $\END$ has a |
|
130 different meaning: it concludes the theory itself |
|
131 (\S\ref{sec:begin-thy}). |
|
132 |
|
133 \item $(\IN~loc)$ given after any local theory command specifies an |
|
134 immediate target, e.g.\ |
|
135 ``$\isarkeyword{definition}~(\IN~loc)~\dots$'' or |
|
136 ``$\THEOREMNAME~(\IN~loc)~\dots$''. This works both in a local or |
|
137 global theory context; the current target context will be suspended |
|
138 for this command only. Note that $(\IN~-)$ will always produce a |
|
139 global result independently of the current target context. |
|
140 |
|
141 \end{descr} |
|
142 |
|
143 The exact meaning of results produced within a local theory context |
|
144 depends on the underlying target infrastructure (locale, type class |
|
145 etc.). The general idea is as follows, considering a context named |
|
146 $c$ with parameter $x$ and assumption $A[x]$. |
|
147 |
|
148 Definitions are exported by introducing a global version with |
|
149 additional arguments; a syntactic abbreviation links the long form |
|
150 with the abstract version of the target context. For example, $a |
|
151 \equiv t[x]$ becomes $c\dtt a \; ?x \equiv t[?x]$ at the theory level |
|
152 (for arbitrary $?x$), together with a local abbreviation $c \equiv |
|
153 c\dtt a\; x$ in the target context (for fixed $x$). |
|
154 |
|
155 Theorems are exported by discharging the assumptions and generalizing |
|
156 the parameters of the context. For example, $a: B[x]$ becomes $c\dtt |
|
157 a: A[?x] \Imp B[?x]$ (for arbitrary $?x$). |
|
158 |
|
159 |
|
160 \subsection{Locales}\label{sec:locale} |
106 |
161 |
107 Locales are named local contexts, consisting of a list of declaration elements |
162 Locales are named local contexts, consisting of a list of declaration elements |
108 that are modeled after the Isar proof context commands (cf.\ |
163 that are modeled after the Isar proof context commands (cf.\ |
109 \S\ref{sec:proof-context}). |
164 \S\ref{sec:proof-context}). |
110 |
|
111 |
|
112 \subsubsection{Localized commands} |
|
113 |
|
114 Existing locales may be augmented later on by adding new facts. Note that the |
|
115 actual context definition may not be changed! Several theory commands that |
|
116 produce facts in some way are available in ``localized'' versions, referring |
|
117 to a named locale instead of the global theory context. |
|
118 |
|
119 \indexouternonterm{locale} |
|
120 \begin{rail} |
|
121 locale: '(' 'in' name ')' |
|
122 ; |
|
123 \end{rail} |
|
124 |
|
125 Emerging facts of localized commands are stored in two versions, both in the |
|
126 target locale and the theory (after export). The latter view produces a |
|
127 qualified binding, using the locale name as a name space prefix. |
|
128 |
|
129 For example, ``$\LEMMAS~(\IN~loc)~a = \vec b$'' retrieves facts $\vec b$ from |
|
130 the locale context of $loc$ and augments its body by an appropriate |
|
131 ``$\isarkeyword{notes}$'' element (see below). The exported view of $a$, |
|
132 after discharging the locale context, is stored as $loc{.}a$ within the global |
|
133 theory. A localized goal ``$\LEMMANAME~(\IN~loc)~a:~\phi$'' works similarly, |
|
134 only that the fact emerges through the subsequent proof, which may refer to |
|
135 the full infrastructure of the locale context (covering local parameters with |
|
136 typing and concrete syntax, assumptions, definitions etc.). Most notably, |
|
137 fact declarations of the locale are active during the proof as well (e.g.\ |
|
138 local $simp$ rules). |
|
139 |
|
140 As a general principle, results exported from a locale context acquire |
|
141 additional premises according to the specification. Usually this is only a |
|
142 single predicate according to the standard ``closed'' view of locale |
|
143 specifications. |
|
144 |
165 |
145 |
166 |
146 \subsubsection{Locale specifications} |
167 \subsubsection{Locale specifications} |
147 |
168 |
148 \indexisarcmd{locale}\indexisarcmd{print-locale}\indexisarcmd{print-locales} |
169 \indexisarcmd{locale}\indexisarcmd{print-locale}\indexisarcmd{print-locales} |
295 |
316 |
296 Locale expressions (more precisely, \emph{context expressions}) may be |
317 Locale expressions (more precisely, \emph{context expressions}) may be |
297 instantiated, and the instantiated facts added to the current context. |
318 instantiated, and the instantiated facts added to the current context. |
298 This requires a proof of the instantiated specification and is called |
319 This requires a proof of the instantiated specification and is called |
299 \emph{locale interpretation}. Interpretation is possible in theories |
320 \emph{locale interpretation}. Interpretation is possible in theories |
300 and locales |
321 and locales (command $\isarcmd{interpretation}$) and also in proof |
301 (command $\isarcmd{interpretation}$) and also in proof contexts |
322 contexts ($\isarcmd{interpret}$). |
302 ($\isarcmd{interpret}$). |
|
303 |
323 |
304 \indexisarcmd{interpretation}\indexisarcmd{interpret} |
324 \indexisarcmd{interpretation}\indexisarcmd{interpret} |
305 \indexisarcmd{print-interps} |
325 \indexisarcmd{print-interps} |
306 \begin{matharray}{rcl} |
326 \begin{matharray}{rcl} |
307 \isarcmd{interpretation} & : & \isartrans{theory}{proof(prove)} \\ |
327 \isarcmd{interpretation} & : & \isartrans{theory}{proof(prove)} \\ |
409 |
429 |
410 \end{descr} |
430 \end{descr} |
411 |
431 |
412 \begin{warn} |
432 \begin{warn} |
413 Since attributes are applied to interpreted theorems, interpretation |
433 Since attributes are applied to interpreted theorems, interpretation |
414 may modify the current simpset and claset. Take this into |
434 may modify the context of common proof tools, e.g.\ the Simplifier |
415 account when choosing attributes for local theorems. |
435 or Classical Reasoner. Since the behavior of such automated |
|
436 reasoning tools is \emph{not} stable under interpretation morphisms, |
|
437 manual declarations might have to be issued. |
416 \end{warn} |
438 \end{warn} |
417 |
439 |
418 \begin{warn} |
440 \begin{warn} |
419 An interpretation in a theory may subsume previous interpretations. |
441 An interpretation in a theory may subsume previous interpretations. |
420 This happens if the same specification fragment is interpreted twice |
442 This happens if the same specification fragment is interpreted twice |
421 and the instantiation of the second interpretation is more general |
443 and the instantiation of the second interpretation is more general |
422 than the interpretation of the first. A warning |
444 than the interpretation of the first. A warning is issued, since it |
423 is issued, since it is likely that these could have been generalized |
445 is likely that these could have been generalized in the first place. |
424 in the first place. The locale package does not attempt to remove |
446 The locale package does not attempt to remove subsumed |
425 subsumed interpretations. This situation is normally harmless, but |
447 interpretations. |
426 note that $blast$ gets confused by the presence of multiple axclass |
|
427 instances of a rule. |
|
428 \end{warn} |
448 \end{warn} |
429 |
449 |
430 |
450 |
431 \subsection{Type classes} |
451 \subsection{Type classes}\label{sec:class} |
432 |
452 |
433 A special case of locales are type classes. |
453 A type class is a special case of a locale, with some additional |
434 Type classes |
454 infrastructure (notably a link to type-inference). Type classes |
435 consist of a locale with \emph{exactly one} type variable |
455 consist of a locale with \emph{exactly one} type variable and an |
436 and an corresponding axclass. \cite{isabelle-classes} gives a substantial |
456 corresponding axclass. \cite{isabelle-classes} gives a substantial |
437 introduction on type classes. |
457 introduction on type classes. |
438 |
458 |
439 \indexisarcmd{instance}\indexisarcmd{class}\indexisarcmd{print-classes} |
459 \indexisarcmd{instance}\indexisarcmd{class}\indexisarcmd{print-classes} |
440 \begin{matharray}{rcl} |
460 \begin{matharray}{rcl} |
441 \isarcmd{class} & : & \isartrans{theory}{local{\dsh}theory} \\ |
461 \isarcmd{class} & : & \isartrans{theory}{local{\dsh}theory} \\ |
442 \isarcmd{instance} & : & \isartrans{theory}{proof(prove)} \\ |
462 \isarcmd{instance} & : & \isartrans{theory}{proof(prove)} \\ |
443 \isarcmd{print_classes}^* & : & \isarkeep{theory~|~proof} \\ |
463 \isarcmd{print_classes}^* & : & \isarkeep{theory~|~proof} \\ |
444 \end{matharray} |
464 \end{matharray} |
445 |
465 |
446 \begin{rail} |
466 \begin{rail} |
447 'class' name '=' classexpr |
467 'class' name '=' classexpr 'begin'? |
448 ; |
468 ; |
449 'instance' (instarity | instsubsort) |
469 'instance' (instarity | instsubsort) |
450 ; |
470 ; |
451 'print\_classes' |
471 'print\_classes' |
452 ; |
472 ; |