author | wenzelm |
Thu, 22 Oct 2015 23:01:49 +0200 | |
changeset 61506 | 436b7fe89cdc |
parent 61493 | 0debd22f0c0e |
child 61656 | cfabbc083977 |
permissions | -rw-r--r-- |
29755 | 1 |
theory Local_Theory |
2 |
imports Base |
|
3 |
begin |
|
18537 | 4 |
|
58618 | 5 |
chapter \<open>Local theory specifications \label{ch:local-theory}\<close> |
29759 | 6 |
|
58618 | 7 |
text \<open> |
61477 | 8 |
A \<^emph>\<open>local theory\<close> combines aspects of both theory and proof |
29764 | 9 |
context (cf.\ \secref{sec:context}), such that definitional |
10 |
specifications may be given relatively to parameters and |
|
11 |
assumptions. A local theory is represented as a regular proof |
|
61477 | 12 |
context, augmented by administrative data about the \<^emph>\<open>target |
13 |
context\<close>. |
|
29764 | 14 |
|
15 |
The target is usually derived from the background theory by adding |
|
61493 | 16 |
local \<open>\<FIX>\<close> and \<open>\<ASSUME>\<close> elements, plus |
29764 | 17 |
suitable modifications of non-logical context data (e.g.\ a special |
18 |
type-checking discipline). Once initialized, the target is ready to |
|
61493 | 19 |
absorb definitional primitives: \<open>\<DEFINE>\<close> for terms and |
20 |
\<open>\<NOTE>\<close> for theorems. Such definitions may get |
|
29764 | 21 |
transformed in a target-specific way, but the programming interface |
22 |
hides such details. |
|
23 |
||
24 |
Isabelle/Pure provides target mechanisms for locales, type-classes, |
|
25 |
type-class instantiations, and general overloading. In principle, |
|
26 |
users can implement new targets as well, but this rather arcane |
|
27 |
discipline is beyond the scope of this manual. In contrast, |
|
28 |
implementing derived definitional packages to be used within a local |
|
29765 | 29 |
theory context is quite easy: the interfaces are even simpler and |
30 |
more abstract than the underlying primitives for raw theories. |
|
29764 | 31 |
|
32 |
Many definitional packages for local theories are available in |
|
29765 | 33 |
Isabelle. Although a few old packages only work for global |
39839 | 34 |
theories, the standard way of implementing definitional packages in |
35 |
Isabelle is via the local theory interface. |
|
58618 | 36 |
\<close> |
29764 | 37 |
|
38 |
||
58618 | 39 |
section \<open>Definitional elements\<close> |
18537 | 40 |
|
58618 | 41 |
text \<open> |
61493 | 42 |
There are separate elements \<open>\<DEFINE> c \<equiv> t\<close> for terms, and |
43 |
\<open>\<NOTE> b = thm\<close> for theorems. Types are treated |
|
29765 | 44 |
implicitly, according to Hindley-Milner discipline (cf.\ |
29764 | 45 |
\secref{sec:variables}). These definitional primitives essentially |
61493 | 46 |
act like \<open>let\<close>-bindings within a local context that may |
47 |
already contain earlier \<open>let\<close>-bindings and some initial |
|
48 |
\<open>\<lambda>\<close>-bindings. Thus we gain \<^emph>\<open>dependent definitions\<close> |
|
29765 | 49 |
that are relative to an initial axiomatic context. The following |
50 |
diagram illustrates this idea of axiomatic elements versus |
|
51 |
definitional elements: |
|
29764 | 52 |
|
53 |
\begin{center} |
|
54 |
\begin{tabular}{|l|l|l|} |
|
55 |
\hline |
|
61493 | 56 |
& \<open>\<lambda>\<close>-binding & \<open>let\<close>-binding \\ |
29764 | 57 |
\hline |
61493 | 58 |
types & fixed \<open>\<alpha>\<close> & arbitrary \<open>\<beta>\<close> \\ |
59 |
terms & \<open>\<FIX> x :: \<tau>\<close> & \<open>\<DEFINE> c \<equiv> t\<close> \\ |
|
60 |
theorems & \<open>\<ASSUME> a: A\<close> & \<open>\<NOTE> b = \<^BG>B\<^EN>\<close> \\ |
|
29764 | 61 |
\hline |
62 |
\end{tabular} |
|
63 |
\end{center} |
|
64 |
||
61493 | 65 |
A user package merely needs to produce suitable \<open>\<DEFINE>\<close> |
66 |
and \<open>\<NOTE>\<close> elements according to the application. For |
|
67 |
example, a package for inductive definitions might first \<open>\<DEFINE>\<close> a certain predicate as some fixed-point construction, |
|
68 |
then \<open>\<NOTE>\<close> a proven result about monotonicity of the |
|
29765 | 69 |
functor involved here, and then produce further derived concepts via |
61493 | 70 |
additional \<open>\<DEFINE>\<close> and \<open>\<NOTE>\<close> elements. |
29764 | 71 |
|
61493 | 72 |
The cumulative sequence of \<open>\<DEFINE>\<close> and \<open>\<NOTE>\<close> |
29764 | 73 |
produced at package runtime is managed by the local theory |
61477 | 74 |
infrastructure by means of an \<^emph>\<open>auxiliary context\<close>. Thus the |
29764 | 75 |
system holds up the impression of working within a fully abstract |
61493 | 76 |
situation with hypothetical entities: \<open>\<DEFINE> c \<equiv> t\<close> |
77 |
always results in a literal fact \<open>\<^BG>c \<equiv> t\<^EN>\<close>, where |
|
78 |
\<open>c\<close> is a fixed variable \<open>c\<close>. The details about |
|
29764 | 79 |
global constants, name spaces etc. are handled internally. |
80 |
||
81 |
So the general structure of a local theory is a sandwich of three |
|
82 |
layers: |
|
83 |
||
84 |
\begin{center} |
|
85 |
\framebox{\quad auxiliary context \quad\framebox{\quad target context \quad\framebox{\quad background theory\quad}}} |
|
86 |
\end{center} |
|
87 |
||
39861
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents:
39849
diff
changeset
|
88 |
When a definitional package is finished, the auxiliary context is |
b8d89db3e238
use continental paragraph style, which works better with mixture of (in)formal text;
wenzelm
parents:
39849
diff
changeset
|
89 |
reset to the target context. The target now holds definitions for |
61493 | 90 |
terms and theorems that stem from the hypothetical \<open>\<DEFINE>\<close> and \<open>\<NOTE>\<close> elements, transformed by the |
58555 | 91 |
particular target policy (see @{cite \<open>\S4--5\<close> "Haftmann-Wenzel:2009"} |
58618 | 92 |
for details).\<close> |
29764 | 93 |
|
58618 | 94 |
text %mlref \<open> |
29764 | 95 |
\begin{mldecls} |
29765 | 96 |
@{index_ML_type local_theory: Proof.context} \\ |
57181
2d13bf9ea77b
dropped obscure and unused ad-hoc before_exit hook for named targets
haftmann
parents:
56420
diff
changeset
|
97 |
@{index_ML Named_Target.init: "string -> theory -> local_theory"} \\[1ex] |
33834
7c06e19f717c
adapted local theory operations -- eliminated odd kind;
wenzelm
parents:
33672
diff
changeset
|
98 |
@{index_ML Local_Theory.define: "(binding * mixfix) * (Attrib.binding * term) -> |
7c06e19f717c
adapted local theory operations -- eliminated odd kind;
wenzelm
parents:
33672
diff
changeset
|
99 |
local_theory -> (term * (string * thm)) * local_theory"} \\ |
33672 | 100 |
@{index_ML Local_Theory.note: "Attrib.binding * thm list -> |
101 |
local_theory -> (string * thm list) * local_theory"} \\ |
|
29764 | 102 |
\end{mldecls} |
103 |
||
61439 | 104 |
\<^descr> Type @{ML_type local_theory} represents local theories. |
39864 | 105 |
Although this is merely an alias for @{ML_type Proof.context}, it is |
29765 | 106 |
semantically a subtype of the same: a @{ML_type local_theory} holds |
107 |
target information as special context data. Subtyping means that |
|
61493 | 108 |
any value \<open>lthy:\<close>~@{ML_type local_theory} can be also used |
109 |
with operations on expecting a regular \<open>ctxt:\<close>~@{ML_type |
|
29765 | 110 |
Proof.context}. |
111 |
||
61493 | 112 |
\<^descr> @{ML Named_Target.init}~\<open>before_exit name thy\<close> |
41621 | 113 |
initializes a local theory derived from the given background theory. |
61477 | 114 |
An empty name refers to a \<^emph>\<open>global theory\<close> context, and a |
41621 | 115 |
non-empty name refers to a @{command locale} or @{command class} |
116 |
context (a fully-qualified internal name is expected here). This is |
|
117 |
useful for experimentation --- normally the Isar toplevel already |
|
57181
2d13bf9ea77b
dropped obscure and unused ad-hoc before_exit hook for named targets
haftmann
parents:
56420
diff
changeset
|
118 |
takes care to initialize the local theory context. |
29764 | 119 |
|
61493 | 120 |
\<^descr> @{ML Local_Theory.define}~\<open>((b, mx), (a, rhs)) |
121 |
lthy\<close> defines a local entity according to the specification that is |
|
122 |
given relatively to the current \<open>lthy\<close> context. In |
|
29765 | 123 |
particular the term of the RHS may refer to earlier local entities |
29766 | 124 |
from the auxiliary context, or hypothetical parameters from the |
29765 | 125 |
target context. The result is the newly defined term (which is |
126 |
always a fixed variable with exactly the same name as specified for |
|
127 |
the LHS), together with an equational theorem that states the |
|
128 |
definition as a hypothetical fact. |
|
129 |
||
130 |
Unless an explicit name binding is given for the RHS, the resulting |
|
61493 | 131 |
fact will be called \<open>b_def\<close>. Any given attributes are |
29765 | 132 |
applied to that same fact --- immediately in the auxiliary context |
61477 | 133 |
\<^emph>\<open>and\<close> in any transformed versions stemming from target-specific |
29765 | 134 |
policies or any later interpretations of results from the target |
135 |
context (think of @{command locale} and @{command interpretation}, |
|
136 |
for example). This means that attributes should be usually plain |
|
137 |
declarations such as @{attribute simp}, while non-trivial rules like |
|
138 |
@{attribute simplified} are better avoided. |
|
139 |
||
61493 | 140 |
\<^descr> @{ML Local_Theory.note}~\<open>(a, ths) lthy\<close> is |
33672 | 141 |
analogous to @{ML Local_Theory.define}, but defines facts instead of |
29765 | 142 |
terms. There is also a slightly more general variant @{ML |
33672 | 143 |
Local_Theory.notes} that defines several facts (with attribute |
29765 | 144 |
expressions) simultaneously. |
145 |
||
146 |
This is essentially the internal version of the @{command lemmas} |
|
147 |
command, or @{command declare} if an empty name binding is given. |
|
58618 | 148 |
\<close> |
18537 | 149 |
|
20451 | 150 |
|
58618 | 151 |
section \<open>Morphisms and declarations \label{sec:morphisms}\<close> |
18537 | 152 |
|
58618 | 153 |
text \<open> |
52422 | 154 |
%FIXME |
39877 | 155 |
|
58555 | 156 |
See also @{cite "Chaieb-Wenzel:2007"}. |
58618 | 157 |
\<close> |
30272 | 158 |
|
18537 | 159 |
end |