author | bulwahn |
Tue, 08 May 2012 14:31:03 +0200 | |
changeset 47893 | 4cf901b1089a |
parent 41621 | 55b16bd82142 |
permissions | -rw-r--r-- |
18537 | 1 |
% |
2 |
\begin{isabellebody}% |
|
40406 | 3 |
\def\isabellecontext{Local{\isaliteral{5F}{\isacharunderscore}}Theory}% |
18537 | 4 |
% |
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
40406 | 11 |
\ Local{\isaliteral{5F}{\isacharunderscore}}Theory\isanewline |
29756 | 12 |
\isakeyword{imports}\ Base\isanewline |
13 |
\isakeyword{begin}% |
|
18537 | 14 |
\endisatagtheory |
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
35001 | 21 |
\isamarkupchapter{Local theory specifications \label{ch:local-theory}% |
18537 | 22 |
} |
23 |
\isamarkuptrue% |
|
24 |
% |
|
29767 | 25 |
\begin{isamarkuptext}% |
26 |
A \emph{local theory} combines aspects of both theory and proof |
|
27 |
context (cf.\ \secref{sec:context}), such that definitional |
|
28 |
specifications may be given relatively to parameters and |
|
29 |
assumptions. A local theory is represented as a regular proof |
|
30 |
context, augmented by administrative data about the \emph{target |
|
31 |
context}. |
|
32 |
||
33 |
The target is usually derived from the background theory by adding |
|
40406 | 34 |
local \isa{{\isaliteral{5C3C4649583E}{\isasymFIX}}} and \isa{{\isaliteral{5C3C415353554D453E}{\isasymASSUME}}} elements, plus |
29767 | 35 |
suitable modifications of non-logical context data (e.g.\ a special |
36 |
type-checking discipline). Once initialized, the target is ready to |
|
40406 | 37 |
absorb definitional primitives: \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}} for terms and |
38 |
\isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}} for theorems. Such definitions may get |
|
29767 | 39 |
transformed in a target-specific way, but the programming interface |
40 |
hides such details. |
|
41 |
||
42 |
Isabelle/Pure provides target mechanisms for locales, type-classes, |
|
43 |
type-class instantiations, and general overloading. In principle, |
|
44 |
users can implement new targets as well, but this rather arcane |
|
45 |
discipline is beyond the scope of this manual. In contrast, |
|
46 |
implementing derived definitional packages to be used within a local |
|
47 |
theory context is quite easy: the interfaces are even simpler and |
|
48 |
more abstract than the underlying primitives for raw theories. |
|
49 |
||
50 |
Many definitional packages for local theories are available in |
|
51 |
Isabelle. Although a few old packages only work for global |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
52 |
theories, the standard way of implementing definitional packages in |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
53 |
Isabelle is via the local theory interface.% |
29767 | 54 |
\end{isamarkuptext}% |
55 |
\isamarkuptrue% |
|
56 |
% |
|
29762 | 57 |
\isamarkupsection{Definitional elements% |
18537 | 58 |
} |
59 |
\isamarkuptrue% |
|
60 |
% |
|
61 |
\begin{isamarkuptext}% |
|
40406 | 62 |
There are separate elements \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}\ c\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t} for terms, and |
63 |
\isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}\ b\ {\isaliteral{3D}{\isacharequal}}\ thm} for theorems. Types are treated |
|
29767 | 64 |
implicitly, according to Hindley-Milner discipline (cf.\ |
65 |
\secref{sec:variables}). These definitional primitives essentially |
|
66 |
act like \isa{let}-bindings within a local context that may |
|
67 |
already contain earlier \isa{let}-bindings and some initial |
|
40406 | 68 |
\isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}}-bindings. Thus we gain \emph{dependent definitions} |
29767 | 69 |
that are relative to an initial axiomatic context. The following |
70 |
diagram illustrates this idea of axiomatic elements versus |
|
71 |
definitional elements: |
|
72 |
||
73 |
\begin{center} |
|
74 |
\begin{tabular}{|l|l|l|} |
|
75 |
\hline |
|
40406 | 76 |
& \isa{{\isaliteral{5C3C6C616D6264613E}{\isasymlambda}}}-binding & \isa{let}-binding \\ |
29767 | 77 |
\hline |
40406 | 78 |
types & fixed \isa{{\isaliteral{5C3C616C7068613E}{\isasymalpha}}} & arbitrary \isa{{\isaliteral{5C3C626574613E}{\isasymbeta}}} \\ |
79 |
terms & \isa{{\isaliteral{5C3C4649583E}{\isasymFIX}}\ x\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ {\isaliteral{5C3C7461753E}{\isasymtau}}} & \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}\ c\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t} \\ |
|
80 |
theorems & \isa{{\isaliteral{5C3C415353554D453E}{\isasymASSUME}}\ a{\isaliteral{3A}{\isacharcolon}}\ A} & \isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}\ b\ {\isaliteral{3D}{\isacharequal}}\ \isaliteral{5C3C5E42473E}{}\isactrlBG B\isaliteral{5C3C5E454E3E}{}\isactrlEN } \\ |
|
29767 | 81 |
\hline |
82 |
\end{tabular} |
|
83 |
\end{center} |
|
84 |
||
40406 | 85 |
A user package merely needs to produce suitable \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}} |
86 |
and \isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}} elements according to the application. For |
|
87 |
example, a package for inductive definitions might first \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}} a certain predicate as some fixed-point construction, |
|
88 |
then \isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}} a proven result about monotonicity of the |
|
29767 | 89 |
functor involved here, and then produce further derived concepts via |
40406 | 90 |
additional \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}} and \isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}} elements. |
29767 | 91 |
|
40406 | 92 |
The cumulative sequence of \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}} and \isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}} |
29767 | 93 |
produced at package runtime is managed by the local theory |
94 |
infrastructure by means of an \emph{auxiliary context}. Thus the |
|
95 |
system holds up the impression of working within a fully abstract |
|
40406 | 96 |
situation with hypothetical entities: \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}\ c\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t} |
97 |
always results in a literal fact \isa{\isaliteral{5C3C5E42473E}{}\isactrlBG c\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t\isaliteral{5C3C5E454E3E}{}\isactrlEN }, where |
|
29767 | 98 |
\isa{c} is a fixed variable \isa{c}. The details about |
99 |
global constants, name spaces etc. are handled internally. |
|
100 |
||
101 |
So the general structure of a local theory is a sandwich of three |
|
102 |
layers: |
|
103 |
||
104 |
\begin{center} |
|
105 |
\framebox{\quad auxiliary context \quad\framebox{\quad target context \quad\framebox{\quad background theory\quad}}} |
|
106 |
\end{center} |
|
107 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
108 |
When a definitional package is finished, the auxiliary context is |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
109 |
reset to the target context. The target now holds definitions for |
40406 | 110 |
terms and theorems that stem from the hypothetical \isa{{\isaliteral{5C3C444546494E453E}{\isasymDEFINE}}} and \isa{{\isaliteral{5C3C4E4F54453E}{\isasymNOTE}}} elements, transformed by the |
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
111 |
particular target policy (see \cite[\S4--5]{Haftmann-Wenzel:2009} |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
112 |
for details).% |
18537 | 113 |
\end{isamarkuptext}% |
114 |
\isamarkuptrue% |
|
115 |
% |
|
29767 | 116 |
\isadelimmlref |
117 |
% |
|
118 |
\endisadelimmlref |
|
119 |
% |
|
120 |
\isatagmlref |
|
121 |
% |
|
122 |
\begin{isamarkuptext}% |
|
123 |
\begin{mldecls} |
|
30121 | 124 |
\indexdef{}{ML type}{local\_theory}\verb|type local_theory = Proof.context| \\ |
41621 | 125 |
\indexdef{}{ML}{Named\_Target.init}\verb|Named_Target.init: (local_theory -> local_theory) ->|\isasep\isanewline% |
126 |
\verb| string -> theory -> local_theory| \\[1ex] |
|
33834
7c06e19f717c
adapted local theory operations -- eliminated odd kind;
wenzelm
parents:
33672
diff
changeset
|
127 |
\indexdef{}{ML}{Local\_Theory.define}\verb|Local_Theory.define: (binding * mixfix) * (Attrib.binding * term) ->|\isasep\isanewline% |
7c06e19f717c
adapted local theory operations -- eliminated odd kind;
wenzelm
parents:
33672
diff
changeset
|
128 |
\verb| local_theory -> (term * (string * thm)) * local_theory| \\ |
33672 | 129 |
\indexdef{}{ML}{Local\_Theory.note}\verb|Local_Theory.note: Attrib.binding * thm list ->|\isasep\isanewline% |
130 |
\verb| local_theory -> (string * thm list) * local_theory| \\ |
|
29767 | 131 |
\end{mldecls} |
132 |
||
133 |
\begin{description} |
|
134 |
||
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
135 |
\item Type \verb|local_theory| represents local theories. |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
136 |
Although this is merely an alias for \verb|Proof.context|, it is |
29767 | 137 |
semantically a subtype of the same: a \verb|local_theory| holds |
138 |
target information as special context data. Subtyping means that |
|
40406 | 139 |
any value \isa{lthy{\isaliteral{3A}{\isacharcolon}}}~\verb|local_theory| can be also used |
140 |
with operations on expecting a regular \isa{ctxt{\isaliteral{3A}{\isacharcolon}}}~\verb|Proof.context|. |
|
29767 | 141 |
|
41621 | 142 |
\item \verb|Named_Target.init|~\isa{before{\isaliteral{5F}{\isacharunderscore}}exit\ name\ thy} |
143 |
initializes a local theory derived from the given background theory. |
|
144 |
An empty name refers to a \emph{global theory} context, and a |
|
145 |
non-empty name refers to a \hyperlink{command.locale}{\mbox{\isa{\isacommand{locale}}}} or \hyperlink{command.class}{\mbox{\isa{\isacommand{class}}}} |
|
146 |
context (a fully-qualified internal name is expected here). This is |
|
147 |
useful for experimentation --- normally the Isar toplevel already |
|
148 |
takes care to initialize the local theory context. The given \isa{before{\isaliteral{5F}{\isacharunderscore}}exit} function is invoked before leaving the context; in |
|
149 |
most situations plain identity \verb|I| is sufficient. |
|
29767 | 150 |
|
40406 | 151 |
\item \verb|Local_Theory.define|~\isa{{\isaliteral{28}{\isacharparenleft}}{\isaliteral{28}{\isacharparenleft}}b{\isaliteral{2C}{\isacharcomma}}\ mx{\isaliteral{29}{\isacharparenright}}{\isaliteral{2C}{\isacharcomma}}\ {\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ rhs{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ lthy} defines a local entity according to the specification that is |
29767 | 152 |
given relatively to the current \isa{lthy} context. In |
153 |
particular the term of the RHS may refer to earlier local entities |
|
154 |
from the auxiliary context, or hypothetical parameters from the |
|
155 |
target context. The result is the newly defined term (which is |
|
156 |
always a fixed variable with exactly the same name as specified for |
|
157 |
the LHS), together with an equational theorem that states the |
|
158 |
definition as a hypothetical fact. |
|
159 |
||
160 |
Unless an explicit name binding is given for the RHS, the resulting |
|
40406 | 161 |
fact will be called \isa{b{\isaliteral{5F}{\isacharunderscore}}def}. Any given attributes are |
29767 | 162 |
applied to that same fact --- immediately in the auxiliary context |
163 |
\emph{and} in any transformed versions stemming from target-specific |
|
164 |
policies or any later interpretations of results from the target |
|
165 |
context (think of \hyperlink{command.locale}{\mbox{\isa{\isacommand{locale}}}} and \hyperlink{command.interpretation}{\mbox{\isa{\isacommand{interpretation}}}}, |
|
166 |
for example). This means that attributes should be usually plain |
|
167 |
declarations such as \hyperlink{attribute.simp}{\mbox{\isa{simp}}}, while non-trivial rules like |
|
168 |
\hyperlink{attribute.simplified}{\mbox{\isa{simplified}}} are better avoided. |
|
169 |
||
40406 | 170 |
\item \verb|Local_Theory.note|~\isa{{\isaliteral{28}{\isacharparenleft}}a{\isaliteral{2C}{\isacharcomma}}\ ths{\isaliteral{29}{\isacharparenright}}\ lthy} is |
33672 | 171 |
analogous to \verb|Local_Theory.define|, but defines facts instead of |
172 |
terms. There is also a slightly more general variant \verb|Local_Theory.notes| that defines several facts (with attribute |
|
29767 | 173 |
expressions) simultaneously. |
174 |
||
175 |
This is essentially the internal version of the \hyperlink{command.lemmas}{\mbox{\isa{\isacommand{lemmas}}}} |
|
176 |
command, or \hyperlink{command.declare}{\mbox{\isa{\isacommand{declare}}}} if an empty name binding is given. |
|
177 |
||
178 |
\end{description}% |
|
179 |
\end{isamarkuptext}% |
|
180 |
\isamarkuptrue% |
|
181 |
% |
|
182 |
\endisatagmlref |
|
183 |
{\isafoldmlref}% |
|
184 |
% |
|
185 |
\isadelimmlref |
|
186 |
% |
|
187 |
\endisadelimmlref |
|
188 |
% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
189 |
\isamarkupsection{Morphisms and declarations \label{sec:morphisms}% |
18537 | 190 |
} |
191 |
\isamarkuptrue% |
|
192 |
% |
|
193 |
\begin{isamarkuptext}% |
|
39885
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
194 |
FIXME |
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
195 |
|
6a3f7941c3a0
cumulative update of generated files (since bf164c153d10);
wenzelm
parents:
38466
diff
changeset
|
196 |
\medskip See also \cite{Chaieb-Wenzel:2007}.% |
18537 | 197 |
\end{isamarkuptext}% |
198 |
\isamarkuptrue% |
|
199 |
% |
|
200 |
\isadelimtheory |
|
201 |
% |
|
202 |
\endisadelimtheory |
|
203 |
% |
|
204 |
\isatagtheory |
|
205 |
\isacommand{end}\isamarkupfalse% |
|
206 |
% |
|
207 |
\endisatagtheory |
|
208 |
{\isafoldtheory}% |
|
209 |
% |
|
210 |
\isadelimtheory |
|
211 |
% |
|
212 |
\endisadelimtheory |
|
213 |
\isanewline |
|
214 |
\end{isabellebody}% |
|
215 |
%%% Local Variables: |
|
216 |
%%% mode: latex |
|
217 |
%%% TeX-master: "root" |
|
218 |
%%% End: |