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