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