author | ballarin |
Tue, 31 Mar 2009 21:25:08 +0200 | |
changeset 30826 | a53f4872400e |
parent 30780 | c3f1e8a9e0b5 |
child 32960 | 69916a850301 |
child 32981 | 0114e04a0d64 |
permissions | -rw-r--r-- |
27063 | 1 |
theory Examples |
27375 | 2 |
imports Main GCD |
27063 | 3 |
begin |
4 |
||
27081 | 5 |
hide %invisible const Lattices.lattice |
6 |
pretty_setmargin %invisible 65 |
|
27063 | 7 |
|
8 |
(* |
|
9 |
text {* The following presentation will use notation of |
|
10 |
Isabelle's meta logic, hence a few sentences to explain this. |
|
11 |
The logical |
|
12 |
primitives are universal quantification (@{text "\<And>"}), entailment |
|
13 |
(@{text "\<Longrightarrow>"}) and equality (@{text "\<equiv>"}). Variables (not bound |
|
14 |
variables) are sometimes preceded by a question mark. The logic is |
|
15 |
typed. Type variables are denoted by @{text "'a"}, @{text "'b"} |
|
16 |
etc., and @{text "\<Rightarrow>"} is the function type. Double brackets @{text |
|
17 |
"\<lbrakk>"} and @{text "\<rbrakk>"} are used to abbreviate nested entailment. |
|
18 |
*} |
|
19 |
*) |
|
20 |
||
21 |
section {* Introduction *} |
|
22 |
||
23 |
text {* |
|
24 |
Locales are based on contexts. A \emph{context} can be seen as a |
|
25 |
formula schema |
|
26 |
\[ |
|
27 |
@{text "\<And>x\<^sub>1\<dots>x\<^sub>n. \<lbrakk> A\<^sub>1; \<dots> ;A\<^sub>m \<rbrakk> \<Longrightarrow> \<dots>"} |
|
28 |
\] |
|
29 |
where variables @{text "x\<^sub>1"}, \ldots, @{text "x\<^sub>n"} are called |
|
30 |
\emph{parameters} and the premises $@{text "A\<^sub>1"}, \ldots, |
|
31 |
@{text "A\<^sub>m"}$ \emph{assumptions}. A formula @{text "C"} |
|
32 |
is a \emph{theorem} in the context if it is a conclusion |
|
33 |
\[ |
|
34 |
%\label{eq-fact-in-context} |
|
35 |
@{text "\<And>x\<^sub>1\<dots>x\<^sub>n. \<lbrakk> A\<^sub>1; \<dots> ;A\<^sub>m \<rbrakk> \<Longrightarrow> C"}. |
|
36 |
\] |
|
37 |
Isabelle/Isar's notion of context goes beyond this logical view. |
|
38 |
Its contexts record, in a consecutive order, proved |
|
39 |
conclusions along with attributes, which |
|
40 |
may control proof procedures. Contexts also contain syntax information |
|
41 |
for parameters and for terms depending on them. |
|
42 |
*} |
|
43 |
||
44 |
section {* Simple Locales *} |
|
45 |
||
46 |
text {* |
|
47 |
Locales can be seen as persistent contexts. In its simplest form, a |
|
48 |
\emph{locale declaration} consists of a sequence of context elements |
|
49 |
declaring parameters (keyword \isakeyword{fixes}) and assumptions |
|
50 |
(keyword \isakeyword{assumes}). The following is the specification of |
|
51 |
partial orders, as locale @{text partial_order}. |
|
52 |
*} |
|
53 |
||
54 |
locale partial_order = |
|
55 |
fixes le :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubseteq>" 50) |
|
56 |
assumes refl [intro, simp]: "x \<sqsubseteq> x" |
|
57 |
and anti_sym [intro]: "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> x \<rbrakk> \<Longrightarrow> x = y" |
|
58 |
and trans [trans]: "\<lbrakk> x \<sqsubseteq> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z" |
|
59 |
||
60 |
text {* The parameter of this locale is @{term le}, with infix syntax |
|
61 |
@{text \<sqsubseteq>}. There is an implicit type parameter @{typ "'a"}. It |
|
62 |
is not necessary to declare parameter types: most general types will |
|
63 |
be inferred from the context elements for all parameters. |
|
64 |
||
65 |
The above declaration not only introduces the locale, it also |
|
66 |
defines the \emph{locale predicate} @{term partial_order} with |
|
67 |
definition @{thm [source] partial_order_def}: |
|
68 |
@{thm [display, indent=2] partial_order_def} |
|
69 |
||
70 |
The specification of a locale is fixed, but its list of conclusions |
|
71 |
may be extended through Isar commands that take a \emph{target} argument. |
|
72 |
In the following, \isakeyword{definition} and |
|
73 |
\isakeyword{theorem} are illustrated. |
|
74 |
Table~\ref{tab:commands-with-target} lists Isar commands that accept |
|
75 |
a target. There are various ways of specifying the target. A |
|
76 |
target for a single command may be indicated with keyword |
|
77 |
\isakeyword{in} in the following way: |
|
78 |
||
79 |
\begin{table} |
|
80 |
\hrule |
|
81 |
\vspace{2ex} |
|
82 |
\begin{center} |
|
83 |
\begin{tabular}{ll} |
|
84 |
\isakeyword{definition} & definition through an equation \\ |
|
85 |
\isakeyword{inductive} & inductive definition \\ |
|
30826 | 86 |
\isakeyword{primrec} & primitive recursion \\ |
87 |
\isakeyword{fun}, \isakeyword{function} & general recursion \\ |
|
27063 | 88 |
\isakeyword{abbreviation} & syntactic abbreviation \\ |
89 |
\isakeyword{theorem}, etc.\ & theorem statement with proof \\ |
|
30826 | 90 |
\isakeyword{theorems}, etc.\ & redeclaration of theorems \\ |
91 |
\isakeyword{text}, etc.\ & document markup |
|
27063 | 92 |
\end{tabular} |
93 |
\end{center} |
|
94 |
\hrule |
|
95 |
\caption{Isar commands that accept a target.} |
|
96 |
\label{tab:commands-with-target} |
|
97 |
\end{table} |
|
98 |
*} |
|
99 |
||
100 |
definition (in partial_order) |
|
101 |
less :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl "\<sqsubset>" 50) |
|
102 |
where "(x \<sqsubset> y) = (x \<sqsubseteq> y \<and> x \<noteq> y)" |
|
103 |
||
104 |
text {* A definition in a locale depends on the locale parameters. |
|
105 |
Here, a global constant @{term partial_order.less} is declared, which is lifted over the |
|
106 |
locale parameter @{term le}. Its definition is the global theorem |
|
107 |
@{thm [source] partial_order.less_def}: |
|
108 |
@{thm [display, indent=2] partial_order.less_def} |
|
30826 | 109 |
At the same time, the locale is extended by syntax transformations |
27063 | 110 |
hiding this construction in the context of the locale. That is, |
111 |
@{term "partial_order.less le"} is printed and parsed as infix |
|
30393
aa6f42252bf6
replaced old locale option by proper "text (in locale)";
wenzelm
parents:
29567
diff
changeset
|
112 |
@{text \<sqsubset>}. *} |
aa6f42252bf6
replaced old locale option by proper "text (in locale)";
wenzelm
parents:
29567
diff
changeset
|
113 |
|
aa6f42252bf6
replaced old locale option by proper "text (in locale)";
wenzelm
parents:
29567
diff
changeset
|
114 |
text (in partial_order) {* Finally, the conclusion of the definition |
aa6f42252bf6
replaced old locale option by proper "text (in locale)";
wenzelm
parents:
29567
diff
changeset
|
115 |
is added to the locale, @{thm [source] less_def}: |
aa6f42252bf6
replaced old locale option by proper "text (in locale)";
wenzelm
parents:
29567
diff
changeset
|
116 |
@{thm [display, indent=2] less_def} |
27063 | 117 |
*} |
118 |
||
119 |
text {* As an example of a theorem statement in the locale, here is the |
|
120 |
derivation of a transitivity law. *} |
|
121 |
||
122 |
lemma (in partial_order) less_le_trans [trans]: |
|
123 |
"\<lbrakk> x \<sqsubset> y; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<sqsubset> z" |
|
124 |
unfolding %visible less_def by %visible (blast intro: trans) |
|
125 |
||
126 |
text {* In the context of the proof, assumptions and theorems of the |
|
127 |
locale may be used. Attributes are effective: @{text anti_sym} was |
|
128 |
declared as introduction rule, hence it is in the context's set of |
|
129 |
rules used by the classical reasoner by default. *} |
|
130 |
||
131 |
text {* When working with locales, sequences of commands with the same |
|
132 |
target are frequent. A block of commands, delimited by |
|
133 |
\isakeyword{begin} and \isakeyword{end}, makes a theory-like style |
|
134 |
of working possible. All commands inside the block refer to the |
|
135 |
same target. A block may immediately follow a locale |
|
136 |
declaration, which makes that locale the target. Alternatively the |
|
137 |
target for a block may be given with the \isakeyword{context} |
|
138 |
command. |
|
139 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
140 |
This style of working is illustrated in the block below, where |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
141 |
notions of infimum and supremum for partial orders are introduced, |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
142 |
together with theorems. *} |
27063 | 143 |
|
144 |
context partial_order begin |
|
145 |
||
146 |
definition |
|
147 |
is_inf where "is_inf x y i = |
|
148 |
(i \<sqsubseteq> x \<and> i \<sqsubseteq> y \<and> (\<forall>z. z \<sqsubseteq> x \<and> z \<sqsubseteq> y \<longrightarrow> z \<sqsubseteq> i))" |
|
149 |
||
150 |
definition |
|
151 |
is_sup where "is_sup x y s = |
|
152 |
(x \<sqsubseteq> s \<and> y \<sqsubseteq> s \<and> (\<forall>z. x \<sqsubseteq> z \<and> y \<sqsubseteq> z \<longrightarrow> s \<sqsubseteq> z))" |
|
153 |
||
154 |
lemma %invisible is_infI [intro?]: "i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> |
|
155 |
(\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> is_inf x y i" |
|
156 |
by (unfold is_inf_def) blast |
|
157 |
||
158 |
lemma %invisible is_inf_lower [elim?]: |
|
159 |
"is_inf x y i \<Longrightarrow> (i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> C) \<Longrightarrow> C" |
|
160 |
by (unfold is_inf_def) blast |
|
161 |
||
162 |
lemma %invisible is_inf_greatest [elim?]: |
|
163 |
"is_inf x y i \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i" |
|
164 |
by (unfold is_inf_def) blast |
|
165 |
||
166 |
theorem is_inf_uniq: "\<lbrakk>is_inf x y i; is_inf x y i'\<rbrakk> \<Longrightarrow> i = i'" |
|
167 |
proof - |
|
168 |
assume inf: "is_inf x y i" |
|
169 |
assume inf': "is_inf x y i'" |
|
170 |
show ?thesis |
|
171 |
proof (rule anti_sym) |
|
172 |
from inf' show "i \<sqsubseteq> i'" |
|
173 |
proof (rule is_inf_greatest) |
|
174 |
from inf show "i \<sqsubseteq> x" .. |
|
175 |
from inf show "i \<sqsubseteq> y" .. |
|
176 |
qed |
|
177 |
from inf show "i' \<sqsubseteq> i" |
|
178 |
proof (rule is_inf_greatest) |
|
179 |
from inf' show "i' \<sqsubseteq> x" .. |
|
180 |
from inf' show "i' \<sqsubseteq> y" .. |
|
181 |
qed |
|
182 |
qed |
|
183 |
qed |
|
184 |
||
185 |
theorem %invisible is_inf_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_inf x y x" |
|
186 |
proof - |
|
187 |
assume "x \<sqsubseteq> y" |
|
188 |
show ?thesis |
|
189 |
proof |
|
190 |
show "x \<sqsubseteq> x" .. |
|
191 |
show "x \<sqsubseteq> y" by fact |
|
192 |
fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" show "z \<sqsubseteq> x" by fact |
|
193 |
qed |
|
194 |
qed |
|
195 |
||
196 |
lemma %invisible is_supI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> |
|
197 |
(\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> is_sup x y s" |
|
198 |
by (unfold is_sup_def) blast |
|
199 |
||
200 |
lemma %invisible is_sup_least [elim?]: |
|
201 |
"is_sup x y s \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z" |
|
202 |
by (unfold is_sup_def) blast |
|
203 |
||
204 |
lemma %invisible is_sup_upper [elim?]: |
|
205 |
"is_sup x y s \<Longrightarrow> (x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> C) \<Longrightarrow> C" |
|
206 |
by (unfold is_sup_def) blast |
|
207 |
||
208 |
theorem is_sup_uniq: "\<lbrakk>is_sup x y s; is_sup x y s'\<rbrakk> \<Longrightarrow> s = s'" |
|
209 |
proof - |
|
210 |
assume sup: "is_sup x y s" |
|
211 |
assume sup': "is_sup x y s'" |
|
212 |
show ?thesis |
|
213 |
proof (rule anti_sym) |
|
214 |
from sup show "s \<sqsubseteq> s'" |
|
215 |
proof (rule is_sup_least) |
|
216 |
from sup' show "x \<sqsubseteq> s'" .. |
|
217 |
from sup' show "y \<sqsubseteq> s'" .. |
|
218 |
qed |
|
219 |
from sup' show "s' \<sqsubseteq> s" |
|
220 |
proof (rule is_sup_least) |
|
221 |
from sup show "x \<sqsubseteq> s" .. |
|
222 |
from sup show "y \<sqsubseteq> s" .. |
|
223 |
qed |
|
224 |
qed |
|
225 |
qed |
|
226 |
||
227 |
theorem %invisible is_sup_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_sup x y y" |
|
228 |
proof - |
|
229 |
assume "x \<sqsubseteq> y" |
|
230 |
show ?thesis |
|
231 |
proof |
|
232 |
show "x \<sqsubseteq> y" by fact |
|
233 |
show "y \<sqsubseteq> y" .. |
|
234 |
fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z" |
|
235 |
show "y \<sqsubseteq> z" by fact |
|
236 |
qed |
|
237 |
qed |
|
238 |
||
239 |
end |
|
240 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
241 |
text {* Two commands are provided to inspect locales: |
27063 | 242 |
\isakeyword{print\_locales} lists the names of all locales of the |
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
243 |
current theory; \isakeyword{print\_locale}~$n$ prints the parameters |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
244 |
and assumptions of locale $n$; \isakeyword{print\_locale!}~$n$ |
27063 | 245 |
additionally outputs the conclusions. |
246 |
||
247 |
The syntax of the locale commands discussed in this tutorial is |
|
30780 | 248 |
shown in Table~\ref{tab:commands}. The grammer is complete with the |
249 |
exception of additional context elements not discussed here. See the |
|
27063 | 250 |
Isabelle/Isar Reference Manual~\cite{IsarRef} |
251 |
for full documentation. *} |
|
252 |
||
253 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
254 |
section {* Import \label{sec:import} *} |
27063 | 255 |
|
256 |
text {* |
|
257 |
Algebraic structures are commonly defined by adding operations and |
|
258 |
properties to existing structures. For example, partial orders |
|
259 |
are extended to lattices and total orders. Lattices are extended to |
|
260 |
distributive lattices. |
|
261 |
||
262 |
With locales, this inheritance is achieved through \emph{import} of a |
|
30826 | 263 |
locale. Import is a separate entity in the locale declaration. If |
264 |
present, it precedes the context elements. |
|
27063 | 265 |
*} |
266 |
||
267 |
locale lattice = partial_order + |
|
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
268 |
assumes ex_inf: "\<exists>inf. is_inf x y inf" |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
269 |
and ex_sup: "\<exists>sup. is_sup x y sup" |
27063 | 270 |
begin |
271 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
272 |
text {* These assumptions refer to the predicates for infimum |
30826 | 273 |
and supremum defined in @{text partial_order}. We may now introduce |
274 |
the notions of meet and join. *} |
|
27063 | 275 |
|
276 |
definition |
|
277 |
meet (infixl "\<sqinter>" 70) where "x \<sqinter> y = (THE inf. is_inf x y inf)" |
|
278 |
||
279 |
definition |
|
280 |
join (infixl "\<squnion>" 65) where "x \<squnion> y = (THE sup. is_sup x y sup)" |
|
281 |
||
282 |
lemma %invisible meet_equality [elim?]: "is_inf x y i \<Longrightarrow> x \<sqinter> y = i" |
|
283 |
proof (unfold meet_def) |
|
284 |
assume "is_inf x y i" |
|
285 |
then show "(THE i. is_inf x y i) = i" |
|
286 |
by (rule the_equality) (rule is_inf_uniq [OF _ `is_inf x y i`]) |
|
287 |
qed |
|
288 |
||
289 |
lemma %invisible meetI [intro?]: |
|
290 |
"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" |
|
291 |
by (rule meet_equality, rule is_infI) blast+ |
|
292 |
||
293 |
lemma %invisible is_inf_meet [intro?]: "is_inf x y (x \<sqinter> y)" |
|
294 |
proof (unfold meet_def) |
|
295 |
from ex_inf obtain i where "is_inf x y i" .. |
|
296 |
then show "is_inf x y (THE i. is_inf x y i)" |
|
297 |
by (rule theI) (rule is_inf_uniq [OF _ `is_inf x y i`]) |
|
298 |
qed |
|
299 |
||
300 |
lemma %invisible meet_left [intro?]: |
|
301 |
"x \<sqinter> y \<sqsubseteq> x" |
|
302 |
by (rule is_inf_lower) (rule is_inf_meet) |
|
303 |
||
304 |
lemma %invisible meet_right [intro?]: |
|
305 |
"x \<sqinter> y \<sqsubseteq> y" |
|
306 |
by (rule is_inf_lower) (rule is_inf_meet) |
|
307 |
||
308 |
lemma %invisible meet_le [intro?]: |
|
309 |
"\<lbrakk> z \<sqsubseteq> x; z \<sqsubseteq> y \<rbrakk> \<Longrightarrow> z \<sqsubseteq> x \<sqinter> y" |
|
310 |
by (rule is_inf_greatest) (rule is_inf_meet) |
|
311 |
||
312 |
lemma %invisible join_equality [elim?]: "is_sup x y s \<Longrightarrow> x \<squnion> y = s" |
|
313 |
proof (unfold join_def) |
|
314 |
assume "is_sup x y s" |
|
315 |
then show "(THE s. is_sup x y s) = s" |
|
316 |
by (rule the_equality) (rule is_sup_uniq [OF _ `is_sup x y s`]) |
|
317 |
qed |
|
318 |
||
319 |
lemma %invisible joinI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> |
|
320 |
(\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> x \<squnion> y = s" |
|
321 |
by (rule join_equality, rule is_supI) blast+ |
|
322 |
||
323 |
lemma %invisible is_sup_join [intro?]: "is_sup x y (x \<squnion> y)" |
|
324 |
proof (unfold join_def) |
|
325 |
from ex_sup obtain s where "is_sup x y s" .. |
|
326 |
then show "is_sup x y (THE s. is_sup x y s)" |
|
327 |
by (rule theI) (rule is_sup_uniq [OF _ `is_sup x y s`]) |
|
328 |
qed |
|
329 |
||
330 |
lemma %invisible join_left [intro?]: |
|
331 |
"x \<sqsubseteq> x \<squnion> y" |
|
332 |
by (rule is_sup_upper) (rule is_sup_join) |
|
333 |
||
334 |
lemma %invisible join_right [intro?]: |
|
335 |
"y \<sqsubseteq> x \<squnion> y" |
|
336 |
by (rule is_sup_upper) (rule is_sup_join) |
|
337 |
||
338 |
lemma %invisible join_le [intro?]: |
|
339 |
"\<lbrakk> x \<sqsubseteq> z; y \<sqsubseteq> z \<rbrakk> \<Longrightarrow> x \<squnion> y \<sqsubseteq> z" |
|
340 |
by (rule is_sup_least) (rule is_sup_join) |
|
341 |
||
342 |
theorem %invisible meet_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)" |
|
343 |
proof (rule meetI) |
|
344 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x \<sqinter> y" |
|
345 |
proof |
|
346 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x" .. |
|
347 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y" |
|
348 |
proof - |
|
349 |
have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" .. |
|
350 |
also have "\<dots> \<sqsubseteq> y" .. |
|
351 |
finally show ?thesis . |
|
352 |
qed |
|
353 |
qed |
|
354 |
show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> z" |
|
355 |
proof - |
|
356 |
have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" .. |
|
357 |
also have "\<dots> \<sqsubseteq> z" .. |
|
358 |
finally show ?thesis . |
|
359 |
qed |
|
360 |
fix w assume "w \<sqsubseteq> x \<sqinter> y" and "w \<sqsubseteq> z" |
|
361 |
show "w \<sqsubseteq> x \<sqinter> (y \<sqinter> z)" |
|
362 |
proof |
|
363 |
show "w \<sqsubseteq> x" |
|
364 |
proof - |
|
365 |
have "w \<sqsubseteq> x \<sqinter> y" by fact |
|
366 |
also have "\<dots> \<sqsubseteq> x" .. |
|
367 |
finally show ?thesis . |
|
368 |
qed |
|
369 |
show "w \<sqsubseteq> y \<sqinter> z" |
|
370 |
proof |
|
371 |
show "w \<sqsubseteq> y" |
|
372 |
proof - |
|
373 |
have "w \<sqsubseteq> x \<sqinter> y" by fact |
|
374 |
also have "\<dots> \<sqsubseteq> y" .. |
|
375 |
finally show ?thesis . |
|
376 |
qed |
|
377 |
show "w \<sqsubseteq> z" by fact |
|
378 |
qed |
|
379 |
qed |
|
380 |
qed |
|
381 |
||
382 |
theorem %invisible meet_commute: "x \<sqinter> y = y \<sqinter> x" |
|
383 |
proof (rule meetI) |
|
384 |
show "y \<sqinter> x \<sqsubseteq> x" .. |
|
385 |
show "y \<sqinter> x \<sqsubseteq> y" .. |
|
386 |
fix z assume "z \<sqsubseteq> y" and "z \<sqsubseteq> x" |
|
387 |
then show "z \<sqsubseteq> y \<sqinter> x" .. |
|
388 |
qed |
|
389 |
||
390 |
theorem %invisible meet_join_absorb: "x \<sqinter> (x \<squnion> y) = x" |
|
391 |
proof (rule meetI) |
|
392 |
show "x \<sqsubseteq> x" .. |
|
393 |
show "x \<sqsubseteq> x \<squnion> y" .. |
|
394 |
fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> x \<squnion> y" |
|
395 |
show "z \<sqsubseteq> x" by fact |
|
396 |
qed |
|
397 |
||
398 |
theorem %invisible join_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)" |
|
399 |
proof (rule joinI) |
|
400 |
show "x \<squnion> y \<sqsubseteq> x \<squnion> (y \<squnion> z)" |
|
401 |
proof |
|
402 |
show "x \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. |
|
403 |
show "y \<sqsubseteq> x \<squnion> (y \<squnion> z)" |
|
404 |
proof - |
|
405 |
have "y \<sqsubseteq> y \<squnion> z" .. |
|
406 |
also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. |
|
407 |
finally show ?thesis . |
|
408 |
qed |
|
409 |
qed |
|
410 |
show "z \<sqsubseteq> x \<squnion> (y \<squnion> z)" |
|
411 |
proof - |
|
412 |
have "z \<sqsubseteq> y \<squnion> z" .. |
|
413 |
also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. |
|
414 |
finally show ?thesis . |
|
415 |
qed |
|
416 |
fix w assume "x \<squnion> y \<sqsubseteq> w" and "z \<sqsubseteq> w" |
|
417 |
show "x \<squnion> (y \<squnion> z) \<sqsubseteq> w" |
|
418 |
proof |
|
419 |
show "x \<sqsubseteq> w" |
|
420 |
proof - |
|
421 |
have "x \<sqsubseteq> x \<squnion> y" .. |
|
422 |
also have "\<dots> \<sqsubseteq> w" by fact |
|
423 |
finally show ?thesis . |
|
424 |
qed |
|
425 |
show "y \<squnion> z \<sqsubseteq> w" |
|
426 |
proof |
|
427 |
show "y \<sqsubseteq> w" |
|
428 |
proof - |
|
429 |
have "y \<sqsubseteq> x \<squnion> y" .. |
|
430 |
also have "... \<sqsubseteq> w" by fact |
|
431 |
finally show ?thesis . |
|
432 |
qed |
|
433 |
show "z \<sqsubseteq> w" by fact |
|
434 |
qed |
|
435 |
qed |
|
436 |
qed |
|
437 |
||
438 |
theorem %invisible join_commute: "x \<squnion> y = y \<squnion> x" |
|
439 |
proof (rule joinI) |
|
440 |
show "x \<sqsubseteq> y \<squnion> x" .. |
|
441 |
show "y \<sqsubseteq> y \<squnion> x" .. |
|
442 |
fix z assume "y \<sqsubseteq> z" and "x \<sqsubseteq> z" |
|
443 |
then show "y \<squnion> x \<sqsubseteq> z" .. |
|
444 |
qed |
|
445 |
||
446 |
theorem %invisible join_meet_absorb: "x \<squnion> (x \<sqinter> y) = x" |
|
447 |
proof (rule joinI) |
|
448 |
show "x \<sqsubseteq> x" .. |
|
449 |
show "x \<sqinter> y \<sqsubseteq> x" .. |
|
450 |
fix z assume "x \<sqsubseteq> z" and "x \<sqinter> y \<sqsubseteq> z" |
|
451 |
show "x \<sqsubseteq> z" by fact |
|
452 |
qed |
|
453 |
||
454 |
theorem %invisible meet_idem: "x \<sqinter> x = x" |
|
455 |
proof - |
|
456 |
have "x \<sqinter> (x \<squnion> (x \<sqinter> x)) = x" by (rule meet_join_absorb) |
|
457 |
also have "x \<squnion> (x \<sqinter> x) = x" by (rule join_meet_absorb) |
|
458 |
finally show ?thesis . |
|
459 |
qed |
|
460 |
||
461 |
theorem %invisible meet_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x" |
|
462 |
proof (rule meetI) |
|
463 |
assume "x \<sqsubseteq> y" |
|
464 |
show "x \<sqsubseteq> x" .. |
|
465 |
show "x \<sqsubseteq> y" by fact |
|
466 |
fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" |
|
467 |
show "z \<sqsubseteq> x" by fact |
|
468 |
qed |
|
469 |
||
470 |
theorem %invisible meet_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y" |
|
471 |
by (drule meet_related) (simp add: meet_commute) |
|
472 |
||
473 |
theorem %invisible join_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y" |
|
474 |
proof (rule joinI) |
|
475 |
assume "x \<sqsubseteq> y" |
|
476 |
show "y \<sqsubseteq> y" .. |
|
477 |
show "x \<sqsubseteq> y" by fact |
|
478 |
fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z" |
|
479 |
show "y \<sqsubseteq> z" by fact |
|
480 |
qed |
|
481 |
||
482 |
theorem %invisible join_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x" |
|
483 |
by (drule join_related) (simp add: join_commute) |
|
484 |
||
485 |
theorem %invisible meet_connection: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)" |
|
486 |
proof |
|
487 |
assume "x \<sqsubseteq> y" |
|
488 |
then have "is_inf x y x" .. |
|
489 |
then show "x \<sqinter> y = x" .. |
|
490 |
next |
|
491 |
have "x \<sqinter> y \<sqsubseteq> y" .. |
|
492 |
also assume "x \<sqinter> y = x" |
|
493 |
finally show "x \<sqsubseteq> y" . |
|
494 |
qed |
|
495 |
||
496 |
theorem %invisible join_connection: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" |
|
497 |
proof |
|
498 |
assume "x \<sqsubseteq> y" |
|
499 |
then have "is_sup x y y" .. |
|
500 |
then show "x \<squnion> y = y" .. |
|
501 |
next |
|
502 |
have "x \<sqsubseteq> x \<squnion> y" .. |
|
503 |
also assume "x \<squnion> y = y" |
|
504 |
finally show "x \<sqsubseteq> y" . |
|
505 |
qed |
|
506 |
||
507 |
theorem %invisible meet_connection2: "(x \<sqsubseteq> y) = (y \<sqinter> x = x)" |
|
508 |
using meet_commute meet_connection by simp |
|
509 |
||
510 |
theorem %invisible join_connection2: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" |
|
511 |
using join_commute join_connection by simp |
|
512 |
||
513 |
text %invisible {* Naming according to Jacobson I, p.\ 459. *} |
|
514 |
lemmas %invisible L1 = join_commute meet_commute |
|
515 |
lemmas %invisible L2 = join_assoc meet_assoc |
|
516 |
(* lemmas L3 = join_idem meet_idem *) |
|
517 |
lemmas %invisible L4 = join_meet_absorb meet_join_absorb |
|
518 |
||
519 |
end |
|
520 |
||
521 |
text {* Locales for total orders and distributive lattices follow. |
|
522 |
Each comes with an example theorem. *} |
|
523 |
||
524 |
locale total_order = partial_order + |
|
525 |
assumes total: "x \<sqsubseteq> y \<or> y \<sqsubseteq> x" |
|
526 |
||
527 |
lemma (in total_order) less_total: "x \<sqsubset> y \<or> x = y \<or> y \<sqsubset> x" |
|
528 |
using total |
|
529 |
by (unfold less_def) blast |
|
530 |
||
531 |
locale distrib_lattice = lattice + |
|
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
532 |
assumes meet_distr: "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" |
27063 | 533 |
|
534 |
lemma (in distrib_lattice) join_distr: |
|
535 |
"x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)" (* txt {* Jacobson I, p.\ 462 *} *) |
|
536 |
proof - |
|
537 |
have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by (simp add: L4) |
|
538 |
also have "... = x \<squnion> ((x \<sqinter> z) \<squnion> (y \<sqinter> z))" by (simp add: L2) |
|
539 |
also have "... = x \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 meet_distr) |
|
540 |
also have "... = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 L4) |
|
541 |
also have "... = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by (simp add: meet_distr) |
|
542 |
finally show ?thesis . |
|
543 |
qed |
|
544 |
||
545 |
text {* |
|
546 |
The locale hierachy obtained through these declarations is shown in Figure~\ref{fig:lattices}(a). |
|
547 |
||
548 |
\begin{figure} |
|
549 |
\hrule \vspace{2ex} |
|
550 |
\begin{center} |
|
551 |
\subfigure[Declared hierachy]{ |
|
552 |
\begin{tikzpicture} |
|
553 |
\node (po) at (0,0) {@{text partial_order}}; |
|
554 |
\node (lat) at (-1.5,-1) {@{text lattice}}; |
|
555 |
\node (dlat) at (-1.5,-2) {@{text distrib_lattice}}; |
|
556 |
\node (to) at (1.5,-1) {@{text total_order}}; |
|
557 |
\draw (po) -- (lat); |
|
558 |
\draw (lat) -- (dlat); |
|
559 |
\draw (po) -- (to); |
|
560 |
% \draw[->, dashed] (lat) -- (to); |
|
561 |
\end{tikzpicture} |
|
562 |
} \\ |
|
563 |
\subfigure[Total orders are lattices]{ |
|
564 |
\begin{tikzpicture} |
|
565 |
\node (po) at (0,0) {@{text partial_order}}; |
|
566 |
\node (lat) at (0,-1) {@{text lattice}}; |
|
567 |
\node (dlat) at (-1.5,-2) {@{text distrib_lattice}}; |
|
568 |
\node (to) at (1.5,-2) {@{text total_order}}; |
|
569 |
\draw (po) -- (lat); |
|
570 |
\draw (lat) -- (dlat); |
|
571 |
\draw (lat) -- (to); |
|
572 |
% \draw[->, dashed] (dlat) -- (to); |
|
573 |
\end{tikzpicture} |
|
574 |
} \quad |
|
575 |
\subfigure[Total orders are distributive lattices]{ |
|
576 |
\begin{tikzpicture} |
|
577 |
\node (po) at (0,0) {@{text partial_order}}; |
|
578 |
\node (lat) at (0,-1) {@{text lattice}}; |
|
579 |
\node (dlat) at (0,-2) {@{text distrib_lattice}}; |
|
580 |
\node (to) at (0,-3) {@{text total_order}}; |
|
581 |
\draw (po) -- (lat); |
|
582 |
\draw (lat) -- (dlat); |
|
583 |
\draw (dlat) -- (to); |
|
584 |
\end{tikzpicture} |
|
585 |
} |
|
586 |
\end{center} |
|
587 |
\hrule |
|
588 |
\caption{Hierarchy of Lattice Locales.} |
|
589 |
\label{fig:lattices} |
|
590 |
\end{figure} |
|
591 |
*} |
|
592 |
||
30580
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
593 |
section {* Changing the Locale Hierarchy |
cc5a55d7a5be
Updated chapters 1-5 to locale reimplementation.
ballarin
parents:
30393
diff
changeset
|
594 |
\label{sec:changing-the-hierarchy} *} |
27063 | 595 |
|
596 |
text {* |
|
597 |
Total orders are lattices. Hence, by deriving the lattice |
|
598 |
axioms for total orders, the hierarchy may be changed |
|
599 |
and @{text lattice} be placed between @{text partial_order} |
|
600 |
and @{text total_order}, as shown in Figure~\ref{fig:lattices}(b). |
|
601 |
Changes to the locale hierarchy may be declared |
|
29566
937baa077df2
Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents:
27375
diff
changeset
|
602 |
with the \isakeyword{sublocale} command. *} |
27063 | 603 |
|
29566
937baa077df2
Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents:
27375
diff
changeset
|
604 |
sublocale %visible total_order \<subseteq> lattice |
27063 | 605 |
|
606 |
txt {* This enters the context of locale @{text total_order}, in |
|
607 |
which the goal @{subgoals [display]} must be shown. First, the |
|
608 |
locale predicate needs to be unfolded --- for example using its |
|
609 |
definition or by introduction rules |
|
610 |
provided by the locale package. The methods @{text intro_locales} |
|
611 |
and @{text unfold_locales} automate this. They are aware of the |
|
612 |
current context and dependencies between locales and automatically |
|
613 |
discharge goals implied by these. While @{text unfold_locales} |
|
614 |
always unfolds locale predicates to assumptions, @{text |
|
615 |
intro_locales} only unfolds definitions along the locale |
|
616 |
hierarchy, leaving a goal consisting of predicates defined by the |
|
617 |
locale package. Occasionally the latter is of advantage since the goal |
|
618 |
is smaller. |
|
619 |
||
620 |
For the current goal, we would like to get hold of |
|
621 |
the assumptions of @{text lattice}, hence @{text unfold_locales} |
|
622 |
is appropriate. *} |
|
623 |
||
624 |
proof unfold_locales |
|
625 |
||
626 |
txt {* Since both @{text lattice} and @{text total_order} |
|
627 |
inherit @{text partial_order}, the assumptions of the latter are |
|
628 |
discharged, and the only subgoals that remain are the assumptions |
|
629 |
introduced in @{text lattice} @{subgoals [display]} |
|
630 |
The proof for the first subgoal is *} |
|
631 |
||
632 |
fix x y |
|
633 |
from total have "is_inf x y (if x \<sqsubseteq> y then x else y)" |
|
634 |
by (auto simp: is_inf_def) |
|
635 |
then show "\<exists>inf. is_inf x y inf" .. |
|
636 |
txt {* The proof for the second subgoal is analogous and not |
|
637 |
reproduced here. *} |
|
638 |
next %invisible |
|
639 |
fix x y |
|
640 |
from total have "is_sup x y (if x \<sqsubseteq> y then y else x)" |
|
641 |
by (auto simp: is_sup_def) |
|
642 |
then show "\<exists>sup. is_sup x y sup" .. qed %visible |
|
643 |
||
644 |
text {* Similarly, total orders are distributive lattices. *} |
|
645 |
||
29566
937baa077df2
Fixed tutorial to compile with new locales; grammar of new locale commands.
ballarin
parents:
27375
diff
changeset
|
646 |
sublocale total_order \<subseteq> distrib_lattice |
27063 | 647 |
proof unfold_locales |
648 |
fix %"proof" x y z |
|
649 |
show "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" (is "?l = ?r") |
|
650 |
txt {* Jacobson I, p.\ 462 *} |
|
651 |
proof - |
|
652 |
{ assume c: "y \<sqsubseteq> x" "z \<sqsubseteq> x" |
|
653 |
from c have "?l = y \<squnion> z" |
|
654 |
by (metis c join_connection2 join_related2 meet_related2 total) |
|
655 |
also from c have "... = ?r" by (metis meet_related2) |
|
656 |
finally have "?l = ?r" . } |
|
657 |
moreover |
|
658 |
{ assume c: "x \<sqsubseteq> y \<or> x \<sqsubseteq> z" |
|
659 |
from c have "?l = x" |
|
660 |
by (metis join_connection2 join_related2 meet_connection total trans) |
|
661 |
also from c have "... = ?r" |
|
662 |
by (metis join_commute join_related2 meet_connection meet_related2 total) |
|
663 |
finally have "?l = ?r" . } |
|
664 |
moreover note total |
|
665 |
ultimately show ?thesis by blast |
|
666 |
qed |
|
667 |
qed |
|
668 |
||
669 |
text {* The locale hierarchy is now as shown in Figure~\ref{fig:lattices}(c). *} |
|
670 |
||
671 |
end |