author | wenzelm |
Mon, 18 Apr 2011 15:02:50 +0200 | |
changeset 42395 | 77eedb527068 |
parent 37206 | 7f2a6f3143ad |
child 46855 | f72a2bedd7a9 |
permissions | -rw-r--r-- |
27063 | 1 |
theory Examples |
32981 | 2 |
imports Main |
27063 | 3 |
begin |
4 |
||
27081 | 5 |
pretty_setmargin %invisible 65 |
27063 | 6 |
|
7 |
(* |
|
8 |
text {* The following presentation will use notation of |
|
9 |
Isabelle's meta logic, hence a few sentences to explain this. |
|
10 |
The logical |
|
11 |
primitives are universal quantification (@{text "\<And>"}), entailment |
|
12 |
(@{text "\<Longrightarrow>"}) and equality (@{text "\<equiv>"}). Variables (not bound |
|
13 |
variables) are sometimes preceded by a question mark. The logic is |
|
32983 | 14 |
typed. Type variables are denoted by~@{text "'a"},~@{text "'b"} |
15 |
etc., and~@{text "\<Rightarrow>"} is the function type. Double brackets~@{text |
|
16 |
"\<lbrakk>"} and~@{text "\<rbrakk>"} are used to abbreviate nested entailment. |
|
27063 | 17 |
*} |
18 |
*) |
|
19 |
||
20 |
section {* Introduction *} |
|
21 |
||
22 |
text {* |
|
23 |
Locales are based on contexts. A \emph{context} can be seen as a |
|
24 |
formula schema |
|
25 |
\[ |
|
26 |
@{text "\<And>x\<^sub>1\<dots>x\<^sub>n. \<lbrakk> A\<^sub>1; \<dots> ;A\<^sub>m \<rbrakk> \<Longrightarrow> \<dots>"} |
|
27 |
\] |
|
33838
a3166a169793
Publication details and minor correction of the text.
ballarin
parents:
32984
diff
changeset
|
28 |
where the variables~@{text "x\<^sub>1"}, \ldots,~@{text "x\<^sub>n"} are called |
32983 | 29 |
\emph{parameters} and the premises $@{text "A\<^sub>1"}, \ldots,~@{text |
30 |
"A\<^sub>m"}$ \emph{assumptions}. A formula~@{text "C"} |
|
27063 | 31 |
is a \emph{theorem} in the context if it is a conclusion |
32 |
\[ |
|
33 |
@{text "\<And>x\<^sub>1\<dots>x\<^sub>n. \<lbrakk> A\<^sub>1; \<dots> ;A\<^sub>m \<rbrakk> \<Longrightarrow> C"}. |
|
34 |
\] |
|
35 |
Isabelle/Isar's notion of context goes beyond this logical view. |
|
36 |
Its contexts record, in a consecutive order, proved |
|
32983 | 37 |
conclusions along with \emph{attributes}, which can provide context |
38 |
specific configuration information for proof procedures and concrete |
|
39 |
syntax. From a logical perspective, locales are just contexts that |
|
40 |
have been made persistent. To the user, though, they provide |
|
41 |
powerful means for declaring and combining contexts, and for the |
|
42 |
reuse of theorems proved in these contexts. |
|
27063 | 43 |
*} |
44 |
||
45 |
section {* Simple Locales *} |
|
46 |
||
47 |
text {* |
|
32983 | 48 |
In its simplest form, a |
27063 | 49 |
\emph{locale declaration} consists of a sequence of context elements |
50 |
declaring parameters (keyword \isakeyword{fixes}) and assumptions |
|
51 |
(keyword \isakeyword{assumes}). The following is the specification of |
|
52 |
partial orders, as locale @{text partial_order}. |
|
53 |
*} |
|
54 |
||
55 |
locale partial_order = |
|
56 |
fixes le :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubseteq>" 50) |
|
57 |
assumes refl [intro, simp]: "x \<sqsubseteq> x" |
|
58 |
and anti_sym [intro]: "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> x \<rbrakk> \<Longrightarrow> x = y" |
|
59 |
and trans [trans]: "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z" |
|
60 |
||
32983 | 61 |
text (in partial_order) {* The parameter of this locale is~@{text le}, |
62 |
which is a binary predicate with infix syntax~@{text \<sqsubseteq>}. The |
|
63 |
parameter syntax is available in the subsequent |
|
64 |
assumptions, which are the familiar partial order axioms. |
|
32981 | 65 |
|
32983 | 66 |
Isabelle recognises unbound names as free variables. In locale |
32981 | 67 |
assumptions, these are implicitly universally quantified. That is, |
32983 | 68 |
@{term "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z"} in fact means |
69 |
@{term "\<And>x y z. \<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z"}. |
|
27063 | 70 |
|
32981 | 71 |
Two commands are provided to inspect locales: |
72 |
\isakeyword{print\_locales} lists the names of all locales of the |
|
73 |
current theory; \isakeyword{print\_locale}~$n$ prints the parameters |
|
32983 | 74 |
and assumptions of locale $n$; the variation \isakeyword{print\_locale!}~$n$ |
75 |
additionally outputs the conclusions that are stored in the locale. |
|
76 |
We may inspect the new locale |
|
32981 | 77 |
by issuing \isakeyword{print\_locale!} @{term partial_order}. The output |
78 |
is the following list of context elements. |
|
32983 | 79 |
\begin{small} |
32981 | 80 |
\begin{alltt} |
81 |
\isakeyword{fixes} le :: "'a \(\Rightarrow\) 'a \(\Rightarrow\) bool" (\isakeyword{infixl} "\(\sqsubseteq\)" 50) |
|
82 |
\isakeyword{assumes} "partial_order op \(\sqsubseteq\)" |
|
83 |
\isakeyword{notes} assumption |
|
84 |
refl [intro, simp] = `?x \(\sqsubseteq\) ?x` |
|
85 |
\isakeyword{and} |
|
86 |
anti_sym [intro] = `\(\isasymlbrakk\)?x \(\sqsubseteq\) ?y; ?y \(\sqsubseteq\) ?x\(\isasymrbrakk\) \(\Longrightarrow\) ?x = ?y` |
|
87 |
\isakeyword{and} |
|
88 |
trans [trans] = `\(\isasymlbrakk\)?x \(\sqsubseteq\) ?y; ?y \(\sqsubseteq\) ?z\(\isasymrbrakk\) \(\Longrightarrow\) ?x \(\sqsubseteq\) ?z` |
|
89 |
\end{alltt} |
|
32983 | 90 |
\end{small} |
32981 | 91 |
The keyword \isakeyword{notes} denotes a conclusion element. There |
32983 | 92 |
is one conclusion, which was added automatically. Instead, there is |
93 |
only one assumption, namely @{term "partial_order le"}. The locale |
|
94 |
declaration has introduced the predicate @{term |
|
95 |
partial_order} to the theory. This predicate is the |
|
96 |
\emph{locale predicate}. Its definition may be inspected by |
|
97 |
issuing \isakeyword{thm} @{thm [source] partial_order_def}. |
|
27063 | 98 |
@{thm [display, indent=2] partial_order_def} |
32983 | 99 |
In our example, this is a unary predicate over the parameter of the |
100 |
locale. It is equivalent to the original assumptions, which have |
|
101 |
been turned into conclusions and are |
|
32981 | 102 |
available as theorems in the context of the locale. The names and |
103 |
attributes from the locale declaration are associated to these |
|
104 |
theorems and are effective in the context of the locale. |
|
27063 | 105 |
|
32983 | 106 |
Each conclusion has a \emph{foundational theorem} as counterpart |
107 |
in the theory. Technically, this is simply the theorem composed |
|
108 |
of context and conclusion. For the transitivity theorem, this is |
|
109 |
@{thm [source] partial_order.trans}: |
|
37206 | 110 |
@{thm [display, indent=2] partial_order.trans} |
32981 | 111 |
*} |
112 |
||
32983 | 113 |
subsection {* Targets: Extending Locales *} |
32981 | 114 |
|
115 |
text {* |
|
27063 | 116 |
The specification of a locale is fixed, but its list of conclusions |
117 |
may be extended through Isar commands that take a \emph{target} argument. |
|
118 |
In the following, \isakeyword{definition} and |
|
119 |
\isakeyword{theorem} are illustrated. |
|
120 |
Table~\ref{tab:commands-with-target} lists Isar commands that accept |
|
32983 | 121 |
a target. Isar provides various ways of specifying the target. A |
27063 | 122 |
target for a single command may be indicated with keyword |
123 |
\isakeyword{in} in the following way: |
|
124 |
||
125 |
\begin{table} |
|
126 |
\hrule |
|
127 |
\vspace{2ex} |
|
128 |
\begin{center} |
|
129 |
\begin{tabular}{ll} |
|
130 |
\isakeyword{definition} & definition through an equation \\ |
|
131 |
\isakeyword{inductive} & inductive definition \\ |
|
30826 | 132 |
\isakeyword{primrec} & primitive recursion \\ |
133 |
\isakeyword{fun}, \isakeyword{function} & general recursion \\ |
|
27063 | 134 |
\isakeyword{abbreviation} & syntactic abbreviation \\ |
135 |
\isakeyword{theorem}, etc.\ & theorem statement with proof \\ |
|
30826 | 136 |
\isakeyword{theorems}, etc.\ & redeclaration of theorems \\ |
137 |
\isakeyword{text}, etc.\ & document markup |
|
27063 | 138 |
\end{tabular} |
139 |
\end{center} |
|
140 |
\hrule |
|
141 |
\caption{Isar commands that accept a target.} |
|
142 |
\label{tab:commands-with-target} |
|
143 |
\end{table} |
|
144 |
*} |
|
145 |
||
146 |
definition (in partial_order) |
|
147 |
less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubset>" 50) |
|
148 |
where "(x \<sqsubset> y) = (x \<sqsubseteq> y \<and> x \<noteq> y)" |
|
149 |
||
32981 | 150 |
text (in partial_order) {* The strict order @{text less} with infix |
32983 | 151 |
syntax~@{text \<sqsubset>} is |
152 |
defined in terms of the locale parameter~@{text le} and the general |
|
153 |
equality of the object logic we work in. The definition generates a |
|
154 |
\emph{foundational constant} |
|
32981 | 155 |
@{term partial_order.less} with definition @{thm [source] |
156 |
partial_order.less_def}: |
|
27063 | 157 |
@{thm [display, indent=2] partial_order.less_def} |
30826 | 158 |
At the same time, the locale is extended by syntax transformations |
32983 | 159 |
hiding this construction in the context of the locale. Here, the |
160 |
abbreviation @{text less} is available for |
|
32981 | 161 |
@{text "partial_order.less le"}, and it is printed |
32983 | 162 |
and parsed as infix~@{text \<sqsubset>}. Finally, the conclusion @{thm [source] |
32981 | 163 |
less_def} is added to the locale: |
164 |
@{thm [display, indent=2] less_def} |
|
165 |
*} |
|
30393
aa6f42252bf6
replaced old locale option by proper "text (in locale)";
wenzelm
parents:
29567
diff
changeset
|
166 |
|
32981 | 167 |
text {* The treatment of theorem statements is more straightforward. |
168 |
As an example, here is the derivation of a transitivity law for the |
|
169 |
strict order relation. *} |
|
27063 | 170 |
|
171 |
lemma (in partial_order) less_le_trans [trans]: |
|
172 |
"\<lbrakk> x \<sqsubset> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubset> z" |
|
173 |
unfolding %visible less_def by %visible (blast intro: trans) |
|
174 |
||
32983 | 175 |
text {* In the context of the proof, conclusions of the |
176 |
locale may be used like theorems. Attributes are effective: @{text |
|
177 |
anti_sym} was |
|
27063 | 178 |
declared as introduction rule, hence it is in the context's set of |
179 |
rules used by the classical reasoner by default. *} |
|
180 |
||
32981 | 181 |
subsection {* Context Blocks *} |
182 |
||
27063 | 183 |
text {* When working with locales, sequences of commands with the same |
184 |
target are frequent. A block of commands, delimited by |
|
185 |
\isakeyword{begin} and \isakeyword{end}, makes a theory-like style |
|
186 |
of working possible. All commands inside the block refer to the |
|
187 |
same target. A block may immediately follow a locale |
|
188 |
declaration, which makes that locale the target. Alternatively the |
|
189 |
target for a block may be given with the \isakeyword{context} |
|
190 |
command. |
|
191 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
192 |
This style of working is illustrated in the block below, where |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
193 |
notions of infimum and supremum for partial orders are introduced, |
32981 | 194 |
together with theorems about their uniqueness. *} |
27063 | 195 |
|
196 |
context partial_order begin |
|
197 |
||
198 |
definition |
|
199 |
is_inf where "is_inf x y i = |
|
200 |
(i \<sqsubseteq> x \<and> i \<sqsubseteq> y \<and> (\<forall>z. z \<sqsubseteq> x \<and> z \<sqsubseteq> y \<longrightarrow> z \<sqsubseteq> i))" |
|
201 |
||
202 |
definition |
|
203 |
is_sup where "is_sup x y s = |
|
204 |
(x \<sqsubseteq> s \<and> y \<sqsubseteq> s \<and> (\<forall>z. x \<sqsubseteq> z \<and> y \<sqsubseteq> z \<longrightarrow> s \<sqsubseteq> z))" |
|
205 |
||
206 |
lemma %invisible is_infI [intro?]: "i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> |
|
207 |
(\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> is_inf x y i" |
|
208 |
by (unfold is_inf_def) blast |
|
209 |
||
210 |
lemma %invisible is_inf_lower [elim?]: |
|
211 |
"is_inf x y i \<Longrightarrow> (i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> C) \<Longrightarrow> C" |
|
212 |
by (unfold is_inf_def) blast |
|
213 |
||
214 |
lemma %invisible is_inf_greatest [elim?]: |
|
215 |
"is_inf x y i \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i" |
|
216 |
by (unfold is_inf_def) blast |
|
217 |
||
218 |
theorem is_inf_uniq: "\<lbrakk>is_inf x y i; is_inf x y i'\<rbrakk> \<Longrightarrow> i = i'" |
|
32983 | 219 |
proof - |
27063 | 220 |
assume inf: "is_inf x y i" |
221 |
assume inf': "is_inf x y i'" |
|
222 |
show ?thesis |
|
223 |
proof (rule anti_sym) |
|
224 |
from inf' show "i \<sqsubseteq> i'" |
|
225 |
proof (rule is_inf_greatest) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
226 |
from inf show "i \<sqsubseteq> x" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
227 |
from inf show "i \<sqsubseteq> y" .. |
27063 | 228 |
qed |
229 |
from inf show "i' \<sqsubseteq> i" |
|
230 |
proof (rule is_inf_greatest) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
231 |
from inf' show "i' \<sqsubseteq> x" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
232 |
from inf' show "i' \<sqsubseteq> y" .. |
27063 | 233 |
qed |
234 |
qed |
|
235 |
qed |
|
236 |
||
237 |
theorem %invisible is_inf_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_inf x y x" |
|
238 |
proof - |
|
239 |
assume "x \<sqsubseteq> y" |
|
240 |
show ?thesis |
|
241 |
proof |
|
242 |
show "x \<sqsubseteq> x" .. |
|
243 |
show "x \<sqsubseteq> y" by fact |
|
244 |
fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" show "z \<sqsubseteq> x" by fact |
|
245 |
qed |
|
246 |
qed |
|
247 |
||
248 |
lemma %invisible is_supI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> |
|
249 |
(\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> is_sup x y s" |
|
250 |
by (unfold is_sup_def) blast |
|
251 |
||
252 |
lemma %invisible is_sup_least [elim?]: |
|
253 |
"is_sup x y s \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z" |
|
254 |
by (unfold is_sup_def) blast |
|
255 |
||
256 |
lemma %invisible is_sup_upper [elim?]: |
|
257 |
"is_sup x y s \<Longrightarrow> (x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> C) \<Longrightarrow> C" |
|
258 |
by (unfold is_sup_def) blast |
|
259 |
||
260 |
theorem is_sup_uniq: "\<lbrakk>is_sup x y s; is_sup x y s'\<rbrakk> \<Longrightarrow> s = s'" |
|
32983 | 261 |
proof - |
27063 | 262 |
assume sup: "is_sup x y s" |
263 |
assume sup': "is_sup x y s'" |
|
264 |
show ?thesis |
|
265 |
proof (rule anti_sym) |
|
266 |
from sup show "s \<sqsubseteq> s'" |
|
267 |
proof (rule is_sup_least) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
268 |
from sup' show "x \<sqsubseteq> s'" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
269 |
from sup' show "y \<sqsubseteq> s'" .. |
27063 | 270 |
qed |
271 |
from sup' show "s' \<sqsubseteq> s" |
|
272 |
proof (rule is_sup_least) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
273 |
from sup show "x \<sqsubseteq> s" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
274 |
from sup show "y \<sqsubseteq> s" .. |
27063 | 275 |
qed |
276 |
qed |
|
277 |
qed |
|
278 |
||
279 |
theorem %invisible is_sup_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_sup x y y" |
|
280 |
proof - |
|
281 |
assume "x \<sqsubseteq> y" |
|
282 |
show ?thesis |
|
283 |
proof |
|
284 |
show "x \<sqsubseteq> y" by fact |
|
285 |
show "y \<sqsubseteq> y" .. |
|
286 |
fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z" |
|
287 |
show "y \<sqsubseteq> z" by fact |
|
288 |
qed |
|
289 |
qed |
|
290 |
||
291 |
end |
|
292 |
||
32981 | 293 |
text {* The syntax of the locale commands discussed in this tutorial is |
32983 | 294 |
shown in Table~\ref{tab:commands}. The grammar is complete with the |
295 |
exception of the context elements \isakeyword{constrains} and |
|
296 |
\isakeyword{defines}, which are provided for backward |
|
297 |
compatibility. See the Isabelle/Isar Reference |
|
298 |
Manual~\cite{IsarRef} for full documentation. *} |
|
27063 | 299 |
|
300 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
301 |
section {* Import \label{sec:import} *} |
27063 | 302 |
|
303 |
text {* |
|
304 |
Algebraic structures are commonly defined by adding operations and |
|
305 |
properties to existing structures. For example, partial orders |
|
306 |
are extended to lattices and total orders. Lattices are extended to |
|
32981 | 307 |
distributive lattices. *} |
27063 | 308 |
|
32981 | 309 |
text {* |
310 |
With locales, this kind of inheritance is achieved through |
|
311 |
\emph{import} of locales. The import part of a locale declaration, |
|
312 |
if present, precedes the context elements. Here is an example, |
|
313 |
where partial orders are extended to lattices. |
|
27063 | 314 |
*} |
315 |
||
316 |
locale lattice = partial_order + |
|
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
317 |
assumes ex_inf: "\<exists>inf. is_inf x y inf" |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
318 |
and ex_sup: "\<exists>sup. is_sup x y sup" |
27063 | 319 |
begin |
320 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
321 |
text {* These assumptions refer to the predicates for infimum |
32981 | 322 |
and supremum defined for @{text partial_order} in the previous |
323 |
section. We now introduce the notions of meet and join. *} |
|
27063 | 324 |
|
325 |
definition |
|
326 |
meet (infixl "\<sqinter>" 70) where "x \<sqinter> y = (THE inf. is_inf x y inf)" |
|
327 |
definition |
|
328 |
join (infixl "\<squnion>" 65) where "x \<squnion> y = (THE sup. is_sup x y sup)" |
|
329 |
||
330 |
lemma %invisible meet_equality [elim?]: "is_inf x y i \<Longrightarrow> x \<sqinter> y = i" |
|
331 |
proof (unfold meet_def) |
|
332 |
assume "is_inf x y i" |
|
333 |
then show "(THE i. is_inf x y i) = i" |
|
334 |
by (rule the_equality) (rule is_inf_uniq [OF _ `is_inf x y i`]) |
|
335 |
qed |
|
336 |
||
337 |
lemma %invisible meetI [intro?]: |
|
338 |
"i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> (\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> x \<sqinter> y = i" |
|
339 |
by (rule meet_equality, rule is_infI) blast+ |
|
340 |
||
341 |
lemma %invisible is_inf_meet [intro?]: "is_inf x y (x \<sqinter> y)" |
|
342 |
proof (unfold meet_def) |
|
343 |
from ex_inf obtain i where "is_inf x y i" .. |
|
344 |
then show "is_inf x y (THE i. is_inf x y i)" |
|
345 |
by (rule theI) (rule is_inf_uniq [OF _ `is_inf x y i`]) |
|
346 |
qed |
|
347 |
||
348 |
lemma %invisible meet_left [intro?]: |
|
349 |
"x \<sqinter> y \<sqsubseteq> x" |
|
350 |
by (rule is_inf_lower) (rule is_inf_meet) |
|
351 |
||
352 |
lemma %invisible meet_right [intro?]: |
|
353 |
"x \<sqinter> y \<sqsubseteq> y" |
|
354 |
by (rule is_inf_lower) (rule is_inf_meet) |
|
355 |
||
356 |
lemma %invisible meet_le [intro?]: |
|
357 |
"\<lbrakk> z \<sqsubseteq> x; z \<sqsubseteq> y \<rbrakk> \<Longrightarrow> z \<sqsubseteq> x \<sqinter> y" |
|
358 |
by (rule is_inf_greatest) (rule is_inf_meet) |
|
359 |
||
360 |
lemma %invisible join_equality [elim?]: "is_sup x y s \<Longrightarrow> x \<squnion> y = s" |
|
361 |
proof (unfold join_def) |
|
362 |
assume "is_sup x y s" |
|
363 |
then show "(THE s. is_sup x y s) = s" |
|
364 |
by (rule the_equality) (rule is_sup_uniq [OF _ `is_sup x y s`]) |
|
365 |
qed |
|
366 |
||
367 |
lemma %invisible joinI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> |
|
368 |
(\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> x \<squnion> y = s" |
|
369 |
by (rule join_equality, rule is_supI) blast+ |
|
370 |
||
371 |
lemma %invisible is_sup_join [intro?]: "is_sup x y (x \<squnion> y)" |
|
372 |
proof (unfold join_def) |
|
373 |
from ex_sup obtain s where "is_sup x y s" .. |
|
374 |
then show "is_sup x y (THE s. is_sup x y s)" |
|
375 |
by (rule theI) (rule is_sup_uniq [OF _ `is_sup x y s`]) |
|
376 |
qed |
|
377 |
||
378 |
lemma %invisible join_left [intro?]: |
|
379 |
"x \<sqsubseteq> x \<squnion> y" |
|
380 |
by (rule is_sup_upper) (rule is_sup_join) |
|
381 |
||
382 |
lemma %invisible join_right [intro?]: |
|
383 |
"y \<sqsubseteq> x \<squnion> y" |
|
384 |
by (rule is_sup_upper) (rule is_sup_join) |
|
385 |
||
386 |
lemma %invisible join_le [intro?]: |
|
387 |
"\<lbrakk> x \<sqsubseteq> z; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<squnion> y \<sqsubseteq> z" |
|
388 |
by (rule is_sup_least) (rule is_sup_join) |
|
389 |
||
390 |
theorem %invisible meet_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)" |
|
391 |
proof (rule meetI) |
|
392 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x \<sqinter> y" |
|
393 |
proof |
|
394 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x" .. |
|
395 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y" |
|
396 |
proof - |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
397 |
have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
398 |
also have "\<dots> \<sqsubseteq> y" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
399 |
finally show ?thesis . |
27063 | 400 |
qed |
401 |
qed |
|
402 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> z" |
|
403 |
proof - |
|
404 |
have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" .. |
|
405 |
also have "\<dots> \<sqsubseteq> z" .. |
|
406 |
finally show ?thesis . |
|
407 |
qed |
|
408 |
fix w assume "w \<sqsubseteq> x \<sqinter> y" and "w \<sqsubseteq> z" |
|
409 |
show "w \<sqsubseteq> x \<sqinter> (y \<sqinter> z)" |
|
410 |
proof |
|
411 |
show "w \<sqsubseteq> x" |
|
412 |
proof - |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
413 |
have "w \<sqsubseteq> x \<sqinter> y" by fact |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
414 |
also have "\<dots> \<sqsubseteq> x" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
415 |
finally show ?thesis . |
27063 | 416 |
qed |
417 |
show "w \<sqsubseteq> y \<sqinter> z" |
|
418 |
proof |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
419 |
show "w \<sqsubseteq> y" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
420 |
proof - |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
421 |
have "w \<sqsubseteq> x \<sqinter> y" by fact |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
422 |
also have "\<dots> \<sqsubseteq> y" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
423 |
finally show ?thesis . |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
424 |
qed |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
425 |
show "w \<sqsubseteq> z" by fact |
27063 | 426 |
qed |
427 |
qed |
|
428 |
qed |
|
429 |
||
430 |
theorem %invisible meet_commute: "x \<sqinter> y = y \<sqinter> x" |
|
431 |
proof (rule meetI) |
|
432 |
show "y \<sqinter> x \<sqsubseteq> x" .. |
|
433 |
show "y \<sqinter> x \<sqsubseteq> y" .. |
|
434 |
fix z assume "z \<sqsubseteq> y" and "z \<sqsubseteq> x" |
|
435 |
then show "z \<sqsubseteq> y \<sqinter> x" .. |
|
436 |
qed |
|
437 |
||
438 |
theorem %invisible meet_join_absorb: "x \<sqinter> (x \<squnion> y) = x" |
|
439 |
proof (rule meetI) |
|
440 |
show "x \<sqsubseteq> x" .. |
|
441 |
show "x \<sqsubseteq> x \<squnion> y" .. |
|
442 |
fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> x \<squnion> y" |
|
443 |
show "z \<sqsubseteq> x" by fact |
|
444 |
qed |
|
445 |
||
446 |
theorem %invisible join_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)" |
|
447 |
proof (rule joinI) |
|
448 |
show "x \<squnion> y \<sqsubseteq> x \<squnion> (y \<squnion> z)" |
|
449 |
proof |
|
450 |
show "x \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. |
|
451 |
show "y \<sqsubseteq> x \<squnion> (y \<squnion> z)" |
|
452 |
proof - |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
453 |
have "y \<sqsubseteq> y \<squnion> z" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
454 |
also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
455 |
finally show ?thesis . |
27063 | 456 |
qed |
457 |
qed |
|
458 |
show "z \<sqsubseteq> x \<squnion> (y \<squnion> z)" |
|
459 |
proof - |
|
460 |
have "z \<sqsubseteq> y \<squnion> z" .. |
|
461 |
also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. |
|
462 |
finally show ?thesis . |
|
463 |
qed |
|
464 |
fix w assume "x \<squnion> y \<sqsubseteq> w" and "z \<sqsubseteq> w" |
|
465 |
show "x \<squnion> (y \<squnion> z) \<sqsubseteq> w" |
|
466 |
proof |
|
467 |
show "x \<sqsubseteq> w" |
|
468 |
proof - |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
469 |
have "x \<sqsubseteq> x \<squnion> y" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
470 |
also have "\<dots> \<sqsubseteq> w" by fact |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
471 |
finally show ?thesis . |
27063 | 472 |
qed |
473 |
show "y \<squnion> z \<sqsubseteq> w" |
|
474 |
proof |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
475 |
show "y \<sqsubseteq> w" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
476 |
proof - |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
477 |
have "y \<sqsubseteq> x \<squnion> y" .. |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
478 |
also have "... \<sqsubseteq> w" by fact |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
479 |
finally show ?thesis . |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
480 |
qed |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
481 |
show "z \<sqsubseteq> w" by fact |
27063 | 482 |
qed |
483 |
qed |
|
484 |
qed |
|
485 |
||
486 |
theorem %invisible join_commute: "x \<squnion> y = y \<squnion> x" |
|
487 |
proof (rule joinI) |
|
488 |
show "x \<sqsubseteq> y \<squnion> x" .. |
|
489 |
show "y \<sqsubseteq> y \<squnion> x" .. |
|
490 |
fix z assume "y \<sqsubseteq> z" and "x \<sqsubseteq> z" |
|
491 |
then show "y \<squnion> x \<sqsubseteq> z" .. |
|
492 |
qed |
|
493 |
||
494 |
theorem %invisible join_meet_absorb: "x \<squnion> (x \<sqinter> y) = x" |
|
495 |
proof (rule joinI) |
|
496 |
show "x \<sqsubseteq> x" .. |
|
497 |
show "x \<sqinter> y \<sqsubseteq> x" .. |
|
498 |
fix z assume "x \<sqsubseteq> z" and "x \<sqinter> y \<sqsubseteq> z" |
|
499 |
show "x \<sqsubseteq> z" by fact |
|
500 |
qed |
|
501 |
||
502 |
theorem %invisible meet_idem: "x \<sqinter> x = x" |
|
503 |
proof - |
|
504 |
have "x \<sqinter> (x \<squnion> (x \<sqinter> x)) = x" by (rule meet_join_absorb) |
|
505 |
also have "x \<squnion> (x \<sqinter> x) = x" by (rule join_meet_absorb) |
|
506 |
finally show ?thesis . |
|
507 |
qed |
|
508 |
||
509 |
theorem %invisible meet_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x" |
|
510 |
proof (rule meetI) |
|
511 |
assume "x \<sqsubseteq> y" |
|
512 |
show "x \<sqsubseteq> x" .. |
|
513 |
show "x \<sqsubseteq> y" by fact |
|
514 |
fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" |
|
515 |
show "z \<sqsubseteq> x" by fact |
|
516 |
qed |
|
517 |
||
518 |
theorem %invisible meet_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y" |
|
519 |
by (drule meet_related) (simp add: meet_commute) |
|
520 |
||
521 |
theorem %invisible join_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y" |
|
522 |
proof (rule joinI) |
|
523 |
assume "x \<sqsubseteq> y" |
|
524 |
show "y \<sqsubseteq> y" .. |
|
525 |
show "x \<sqsubseteq> y" by fact |
|
526 |
fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z" |
|
527 |
show "y \<sqsubseteq> z" by fact |
|
528 |
qed |
|
529 |
||
530 |
theorem %invisible join_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x" |
|
531 |
by (drule join_related) (simp add: join_commute) |
|
532 |
||
533 |
theorem %invisible meet_connection: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)" |
|
534 |
proof |
|
535 |
assume "x \<sqsubseteq> y" |
|
536 |
then have "is_inf x y x" .. |
|
537 |
then show "x \<sqinter> y = x" .. |
|
538 |
next |
|
539 |
have "x \<sqinter> y \<sqsubseteq> y" .. |
|
540 |
also assume "x \<sqinter> y = x" |
|
541 |
finally show "x \<sqsubseteq> y" . |
|
542 |
qed |
|
543 |
||
544 |
theorem %invisible join_connection: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" |
|
545 |
proof |
|
546 |
assume "x \<sqsubseteq> y" |
|
547 |
then have "is_sup x y y" .. |
|
548 |
then show "x \<squnion> y = y" .. |
|
549 |
next |
|
550 |
have "x \<sqsubseteq> x \<squnion> y" .. |
|
551 |
also assume "x \<squnion> y = y" |
|
552 |
finally show "x \<sqsubseteq> y" . |
|
553 |
qed |
|
554 |
||
555 |
theorem %invisible meet_connection2: "(x \<sqsubseteq> y) = (y \<sqinter> x = x)" |
|
556 |
using meet_commute meet_connection by simp |
|
557 |
||
558 |
theorem %invisible join_connection2: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" |
|
559 |
using join_commute join_connection by simp |
|
560 |
||
561 |
text %invisible {* Naming according to Jacobson I, p.\ 459. *} |
|
562 |
lemmas %invisible L1 = join_commute meet_commute |
|
563 |
lemmas %invisible L2 = join_assoc meet_assoc |
|
564 |
(* lemmas L3 = join_idem meet_idem *) |
|
565 |
lemmas %invisible L4 = join_meet_absorb meet_join_absorb |
|
566 |
||
567 |
end |
|
568 |
||
32983 | 569 |
text {* Locales for total orders and distributive lattices follow to |
570 |
establish a sufficiently rich landscape of locales for |
|
32981 | 571 |
further examples in this tutorial. Each comes with an example |
572 |
theorem. *} |
|
27063 | 573 |
|
574 |
locale total_order = partial_order + |
|
575 |
assumes total: "x \<sqsubseteq> y \<or> y \<sqsubseteq> x" |
|
576 |
||
577 |
lemma (in total_order) less_total: "x \<sqsubset> y \<or> x = y \<or> y \<sqsubset> x" |
|
578 |
using total |
|
579 |
by (unfold less_def) blast |
|
580 |
||
581 |
locale distrib_lattice = lattice + |
|
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
582 |
assumes meet_distr: "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" |
27063 | 583 |
|
584 |
lemma (in distrib_lattice) join_distr: |
|
585 |
"x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)" (* txt {* Jacobson I, p.\ 462 *} *) |
|
586 |
proof - |
|
587 |
have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by (simp add: L4) |
|
588 |
also have "... = x \<squnion> ((x \<sqinter> z) \<squnion> (y \<sqinter> z))" by (simp add: L2) |
|
589 |
also have "... = x \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 meet_distr) |
|
590 |
also have "... = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 L4) |
|
591 |
also have "... = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by (simp add: meet_distr) |
|
592 |
finally show ?thesis . |
|
593 |
qed |
|
594 |
||
595 |
text {* |
|
32983 | 596 |
The locale hierarchy obtained through these declarations is shown in |
32981 | 597 |
Figure~\ref{fig:lattices}(a). |
27063 | 598 |
|
599 |
\begin{figure} |
|
600 |
\hrule \vspace{2ex} |
|
601 |
\begin{center} |
|
32983 | 602 |
\subfigure[Declared hierarchy]{ |
27063 | 603 |
\begin{tikzpicture} |
604 |
\node (po) at (0,0) {@{text partial_order}}; |
|
605 |
\node (lat) at (-1.5,-1) {@{text lattice}}; |
|
606 |
\node (dlat) at (-1.5,-2) {@{text distrib_lattice}}; |
|
607 |
\node (to) at (1.5,-1) {@{text total_order}}; |
|
608 |
\draw (po) -- (lat); |
|
609 |
\draw (lat) -- (dlat); |
|
610 |
\draw (po) -- (to); |
|
611 |
% \draw[->, dashed] (lat) -- (to); |
|
612 |
\end{tikzpicture} |
|
613 |
} \\ |
|
614 |
\subfigure[Total orders are lattices]{ |
|
615 |
\begin{tikzpicture} |
|
616 |
\node (po) at (0,0) {@{text partial_order}}; |
|
617 |
\node (lat) at (0,-1) {@{text lattice}}; |
|
618 |
\node (dlat) at (-1.5,-2) {@{text distrib_lattice}}; |
|
619 |
\node (to) at (1.5,-2) {@{text total_order}}; |
|
620 |
\draw (po) -- (lat); |
|
621 |
\draw (lat) -- (dlat); |
|
622 |
\draw (lat) -- (to); |
|
623 |
% \draw[->, dashed] (dlat) -- (to); |
|
624 |
\end{tikzpicture} |
|
625 |
} \quad |
|
626 |
\subfigure[Total orders are distributive lattices]{ |
|
627 |
\begin{tikzpicture} |
|
628 |
\node (po) at (0,0) {@{text partial_order}}; |
|
629 |
\node (lat) at (0,-1) {@{text lattice}}; |
|
630 |
\node (dlat) at (0,-2) {@{text distrib_lattice}}; |
|
631 |
\node (to) at (0,-3) {@{text total_order}}; |
|
632 |
\draw (po) -- (lat); |
|
633 |
\draw (lat) -- (dlat); |
|
634 |
\draw (dlat) -- (to); |
|
635 |
\end{tikzpicture} |
|
636 |
} |
|
637 |
\end{center} |
|
638 |
\hrule |
|
639 |
\caption{Hierarchy of Lattice Locales.} |
|
640 |
\label{fig:lattices} |
|
641 |
\end{figure} |
|
642 |
*} |
|
643 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
644 |
section {* Changing the Locale Hierarchy |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
645 |
\label{sec:changing-the-hierarchy} *} |
27063 | 646 |
|
647 |
text {* |
|
32981 | 648 |
Locales enable to prove theorems abstractly, relative to |
649 |
sets of assumptions. These theorems can then be used in other |
|
650 |
contexts where the assumptions themselves, or |
|
651 |
instances of the assumptions, are theorems. This form of theorem |
|
652 |
reuse is called \emph{interpretation}. Locales generalise |
|
653 |
interpretation from theorems to conclusions, enabling the reuse of |
|
654 |
definitions and other constructs that are not part of the |
|
655 |
specifications of the locales. |
|
656 |
||
37094 | 657 |
The first form of interpretation we will consider in this tutorial |
32983 | 658 |
is provided by the \isakeyword{sublocale} command. It enables to |
32981 | 659 |
modify the import hierarchy to reflect the \emph{logical} relation |
660 |
between locales. |
|
661 |
||
662 |
Consider the locale hierarchy from Figure~\ref{fig:lattices}(a). |
|
32983 | 663 |
Total orders are lattices, although this is not reflected here, and |
664 |
definitions, theorems and other conclusions |
|
32981 | 665 |
from @{term lattice} are not available in @{term total_order}. To |
666 |
obtain the situation in Figure~\ref{fig:lattices}(b), it is |
|
667 |
sufficient to add the conclusions of the latter locale to the former. |
|
668 |
The \isakeyword{sublocale} command does exactly this. |
|
669 |
The declaration \isakeyword{sublocale} $l_1 |
|
670 |
\subseteq l_2$ causes locale $l_2$ to be \emph{interpreted} in the |
|
32983 | 671 |
context of $l_1$. This means that all conclusions of $l_2$ are made |
32981 | 672 |
available in $l_1$. |
673 |
||
674 |
Of course, the change of hierarchy must be supported by a theorem |
|
675 |
that reflects, in our example, that total orders are indeed |
|
676 |
lattices. Therefore the \isakeyword{sublocale} command generates a |
|
677 |
goal, which must be discharged by the user. This is illustrated in |
|
678 |
the following paragraphs. First the sublocale relation is stated. |
|
679 |
*} |
|
27063 | 680 |
|
29566
937baa077df2
Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents:
27375
diff
changeset
|
681 |
sublocale %visible total_order \<subseteq> lattice |
27063 | 682 |
|
32981 | 683 |
txt {* \normalsize |
684 |
This enters the context of locale @{text total_order}, in |
|
685 |
which the goal @{subgoals [display]} must be shown. |
|
686 |
Now the |
|
687 |
locale predicate needs to be unfolded --- for example, using its |
|
27063 | 688 |
definition or by introduction rules |
32983 | 689 |
provided by the locale package. For automation, the locale package |
690 |
provides the methods @{text intro_locales} and @{text |
|
691 |
unfold_locales}. They are aware of the |
|
27063 | 692 |
current context and dependencies between locales and automatically |
693 |
discharge goals implied by these. While @{text unfold_locales} |
|
694 |
always unfolds locale predicates to assumptions, @{text |
|
695 |
intro_locales} only unfolds definitions along the locale |
|
696 |
hierarchy, leaving a goal consisting of predicates defined by the |
|
697 |
locale package. Occasionally the latter is of advantage since the goal |
|
698 |
is smaller. |
|
699 |
||
700 |
For the current goal, we would like to get hold of |
|
32981 | 701 |
the assumptions of @{text lattice}, which need to be shown, hence |
702 |
@{text unfold_locales} is appropriate. *} |
|
27063 | 703 |
|
704 |
proof unfold_locales |
|
705 |
||
32981 | 706 |
txt {* \normalsize |
707 |
Since the fact that both lattices and total orders are partial |
|
708 |
orders is already reflected in the locale hierarchy, the assumptions |
|
709 |
of @{text partial_order} are discharged automatically, and only the |
|
710 |
assumptions introduced in @{text lattice} remain as subgoals |
|
711 |
@{subgoals [display]} |
|
712 |
The proof for the first subgoal is obtained by constructing an |
|
713 |
infimum, whose existence is implied by totality. *} |
|
27063 | 714 |
|
715 |
fix x y |
|
716 |
from total have "is_inf x y (if x \<sqsubseteq> y then x else y)" |
|
717 |
by (auto simp: is_inf_def) |
|
718 |
then show "\<exists>inf. is_inf x y inf" .. |
|
32981 | 719 |
txt {* \normalsize |
720 |
The proof for the second subgoal is analogous and not |
|
27063 | 721 |
reproduced here. *} |
722 |
next %invisible |
|
723 |
fix x y |
|
724 |
from total have "is_sup x y (if x \<sqsubseteq> y then y else x)" |
|
725 |
by (auto simp: is_sup_def) |
|
726 |
then show "\<exists>sup. is_sup x y sup" .. qed %visible |
|
727 |
||
32983 | 728 |
text {* Similarly, we may establish that total orders are distributive |
32981 | 729 |
lattices with a second \isakeyword{sublocale} statement. *} |
27063 | 730 |
|
29566
937baa077df2
Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents:
27375
diff
changeset
|
731 |
sublocale total_order \<subseteq> distrib_lattice |
32983 | 732 |
proof unfold_locales |
27063 | 733 |
fix %"proof" x y z |
734 |
show "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" (is "?l = ?r") |
|
735 |
txt {* Jacobson I, p.\ 462 *} |
|
736 |
proof - |
|
737 |
{ assume c: "y \<sqsubseteq> x" "z \<sqsubseteq> x" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
738 |
from c have "?l = y \<squnion> z" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
739 |
by (metis c join_connection2 join_related2 meet_related2 total) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
740 |
also from c have "... = ?r" by (metis meet_related2) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
741 |
finally have "?l = ?r" . } |
27063 | 742 |
moreover |
743 |
{ assume c: "x \<sqsubseteq> y \<or> x \<sqsubseteq> z" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
744 |
from c have "?l = x" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
745 |
by (metis join_connection2 join_related2 meet_connection total trans) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
746 |
also from c have "... = ?r" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
747 |
by (metis join_commute join_related2 meet_connection meet_related2 total) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
30826
diff
changeset
|
748 |
finally have "?l = ?r" . } |
27063 | 749 |
moreover note total |
750 |
ultimately show ?thesis by blast |
|
751 |
qed |
|
752 |
qed |
|
753 |
||
32981 | 754 |
text {* The locale hierarchy is now as shown in |
755 |
Figure~\ref{fig:lattices}(c). *} |
|
756 |
||
757 |
text {* |
|
758 |
Locale interpretation is \emph{dynamic}. The statement |
|
759 |
\isakeyword{sublocale} $l_1 \subseteq l_2$ will not just add the |
|
760 |
current conclusions of $l_2$ to $l_1$. Rather the dependency is |
|
761 |
stored, and conclusions that will be |
|
762 |
added to $l_2$ in future are automatically propagated to $l_1$. |
|
763 |
The sublocale relation is transitive --- that is, propagation takes |
|
764 |
effect along chains of sublocales. Even cycles in the sublocale relation are |
|
765 |
supported, as long as these cycles do not lead to infinite chains. |
|
32983 | 766 |
Details are discussed in the technical report \cite{Ballarin2006a}. |
767 |
See also Section~\ref{sec:infinite-chains} of this tutorial. *} |
|
27063 | 768 |
|
769 |
end |