author  haftmann 
Tue, 16 Oct 2007 23:12:45 +0200  
changeset 25062  af5ef0d4d655 
parent 24749  151b3758f576 
child 25102  db3e412c4cb1 
permissions  rwrr 
21249  1 
(* Title: HOL/Lattices.thy 
2 
ID: $Id$ 

3 
Author: Tobias Nipkow 

4 
*) 

5 

22454  6 
header {* Abstract lattices *} 
21249  7 

8 
theory Lattices 

9 
imports Orderings 

10 
begin 

11 

12 
subsection{* Lattices *} 

13 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

14 
class lower_semilattice = order + 
21249  15 
fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70) 
22737  16 
assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x" 
17 
and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y" 

21733  18 
and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z" 
21249  19 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

20 
class upper_semilattice = order + 
21249  21 
fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65) 
22737  22 
assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y" 
23 
and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y" 

21733  24 
and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x" 
21249  25 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

26 
class lattice = lower_semilattice + upper_semilattice 
21249  27 

21733  28 
subsubsection{* Intro and elim rules*} 
29 

30 
context lower_semilattice 

31 
begin 

21249  32 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

33 
lemmas antisym_intro [intro!] = antisym 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

34 
lemmas (in ) [rule del] = antisym_intro 
21249  35 

25062  36 
lemma le_infI1[intro]: 
37 
assumes "a \<sqsubseteq> x" 

38 
shows "a \<sqinter> b \<sqsubseteq> x" 

39 
proof (rule order_trans) 

40 
show "a \<sqinter> b \<sqsubseteq> a" and "a \<sqsubseteq> x" using assms by simp 

41 
qed 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

42 
lemmas (in ) [rule del] = le_infI1 
21249  43 

25062  44 
lemma le_infI2[intro]: 
45 
assumes "b \<sqsubseteq> x" 

46 
shows "a \<sqinter> b \<sqsubseteq> x" 

47 
proof (rule order_trans) 

48 
show "a \<sqinter> b \<sqsubseteq> b" and "b \<sqsubseteq> x" using assms by simp 

49 
qed 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

50 
lemmas (in ) [rule del] = le_infI2 
21733  51 

21734  52 
lemma le_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b" 
21733  53 
by(blast intro: inf_greatest) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

54 
lemmas (in ) [rule del] = le_infI 
21249  55 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

56 
lemma le_infE [elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P" 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

57 
by (blast intro: order_trans) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

58 
lemmas (in ) [rule del] = le_infE 
21249  59 

21734  60 
lemma le_inf_iff [simp]: 
21733  61 
"x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)" 
62 
by blast 

63 

21734  64 
lemma le_iff_inf: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)" 
22168  65 
by(blast dest:eq_iff[THEN iffD1]) 
21249  66 

21733  67 
end 
68 

23878  69 
lemma mono_inf: "mono f \<Longrightarrow> f (inf A B) \<le> inf (f A) (f B)" 
70 
by (auto simp add: mono_def) 

71 

21733  72 

73 
context upper_semilattice 

74 
begin 

21249  75 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

76 
lemmas antisym_intro [intro!] = antisym 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

77 
lemmas (in ) [rule del] = antisym_intro 
21249  78 

21734  79 
lemma le_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b" 
25062  80 
by (rule order_trans) auto 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

81 
lemmas (in ) [rule del] = le_supI1 
21249  82 

21734  83 
lemma le_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b" 
25062  84 
by (rule order_trans) auto 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

85 
lemmas (in ) [rule del] = le_supI2 
21733  86 

21734  87 
lemma le_supI[intro!]: "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x" 
21733  88 
by(blast intro: sup_least) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

89 
lemmas (in ) [rule del] = le_supI 
21249  90 

21734  91 
lemma le_supE[elim!]: "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P" 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

92 
by (blast intro: order_trans) 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

93 
lemmas (in ) [rule del] = le_supE 
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

94 

21249  95 

21734  96 
lemma ge_sup_conv[simp]: 
21733  97 
"x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)" 
98 
by blast 

99 

21734  100 
lemma le_iff_sup: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" 
22168  101 
by(blast dest:eq_iff[THEN iffD1]) 
21734  102 

21733  103 
end 
104 

23878  105 
lemma mono_sup: "mono f \<Longrightarrow> sup (f A) (f B) \<le> f (sup A B)" 
106 
by (auto simp add: mono_def) 

107 

21733  108 

109 
subsubsection{* Equational laws *} 

21249  110 

111 

21733  112 
context lower_semilattice 
113 
begin 

114 

115 
lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)" 

116 
by blast 

117 

118 
lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)" 

119 
by blast 

120 

121 
lemma inf_idem[simp]: "x \<sqinter> x = x" 

122 
by blast 

123 

124 
lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y" 

125 
by blast 

126 

127 
lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x" 

128 
by blast 

129 

130 
lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y" 

131 
by blast 

132 

133 
lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)" 

134 
by blast 

135 

136 
lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem 

137 

138 
end 

139 

140 

141 
context upper_semilattice 

142 
begin 

21249  143 

21733  144 
lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)" 
145 
by blast 

146 

147 
lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)" 

148 
by blast 

149 

150 
lemma sup_idem[simp]: "x \<squnion> x = x" 

151 
by blast 

152 

153 
lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y" 

154 
by blast 

155 

156 
lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x" 

157 
by blast 

158 

159 
lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y" 

160 
by blast 

21249  161 

21733  162 
lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)" 
163 
by blast 

164 

165 
lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem 

166 

167 
end 

21249  168 

21733  169 
context lattice 
170 
begin 

171 

172 
lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x" 

173 
by(blast intro: antisym inf_le1 inf_greatest sup_ge1) 

174 

175 
lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x" 

176 
by(blast intro: antisym sup_ge1 sup_least inf_le1) 

177 

21734  178 
lemmas ACI = inf_ACI sup_ACI 
179 

22454  180 
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2 
181 

21734  182 
text{* Towards distributivity *} 
21249  183 

21734  184 
lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)" 
185 
by blast 

186 

187 
lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)" 

188 
by blast 

189 

190 

191 
text{* If you have one of them, you have them all. *} 

21249  192 

21733  193 
lemma distrib_imp1: 
21249  194 
assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" 
195 
shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)" 

196 
proof 

197 
have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by(simp add:sup_inf_absorb) 

198 
also have "\<dots> = x \<squnion> (z \<sqinter> (x \<squnion> y))" by(simp add:D inf_commute sup_assoc) 

199 
also have "\<dots> = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)" 

200 
by(simp add:inf_sup_absorb inf_commute) 

201 
also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by(simp add:D) 

202 
finally show ?thesis . 

203 
qed 

204 

21733  205 
lemma distrib_imp2: 
21249  206 
assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)" 
207 
shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" 

208 
proof 

209 
have "x \<sqinter> (y \<squnion> z) = (x \<sqinter> (x \<squnion> z)) \<sqinter> (y \<squnion> z)" by(simp add:inf_sup_absorb) 

210 
also have "\<dots> = x \<sqinter> (z \<squnion> (x \<sqinter> y))" by(simp add:D sup_commute inf_assoc) 

211 
also have "\<dots> = ((x \<sqinter> y) \<squnion> x) \<sqinter> ((x \<sqinter> y) \<squnion> z)" 

212 
by(simp add:sup_inf_absorb sup_commute) 

213 
also have "\<dots> = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" by(simp add:D) 

214 
finally show ?thesis . 

215 
qed 

216 

21734  217 
(* seems unused *) 
218 
lemma modular_le: "x \<sqsubseteq> z \<Longrightarrow> x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> z" 

219 
by blast 

220 

21733  221 
end 
21249  222 

223 

24164  224 
subsection {* Distributive lattices *} 
21249  225 

22454  226 
class distrib_lattice = lattice + 
21249  227 
assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)" 
228 

21733  229 
context distrib_lattice 
230 
begin 

231 

232 
lemma sup_inf_distrib2: 

21249  233 
"(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)" 
234 
by(simp add:ACI sup_inf_distrib1) 

235 

21733  236 
lemma inf_sup_distrib1: 
21249  237 
"x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)" 
238 
by(rule distrib_imp2[OF sup_inf_distrib1]) 

239 

21733  240 
lemma inf_sup_distrib2: 
21249  241 
"(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)" 
242 
by(simp add:ACI inf_sup_distrib1) 

243 

21733  244 
lemmas distrib = 
21249  245 
sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2 
246 

21733  247 
end 
248 

21249  249 

22454  250 
subsection {* Uniqueness of inf and sup *} 
251 

22737  252 
lemma (in lower_semilattice) inf_unique: 
22454  253 
fixes f (infixl "\<triangle>" 70) 
25062  254 
assumes le1: "\<And>x y. x \<triangle> y \<le> x" and le2: "\<And>x y. x \<triangle> y \<le> y" 
255 
and greatest: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z" 

22737  256 
shows "x \<sqinter> y = x \<triangle> y" 
22454  257 
proof (rule antisym) 
25062  258 
show "x \<triangle> y \<le> x \<sqinter> y" by (rule le_infI) (rule le1, rule le2) 
22454  259 
next 
25062  260 
have leI: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z" by (blast intro: greatest) 
261 
show "x \<sqinter> y \<le> x \<triangle> y" by (rule leI) simp_all 

22454  262 
qed 
263 

22737  264 
lemma (in upper_semilattice) sup_unique: 
22454  265 
fixes f (infixl "\<nabla>" 70) 
25062  266 
assumes ge1 [simp]: "\<And>x y. x \<le> x \<nabla> y" and ge2: "\<And>x y. y \<le> x \<nabla> y" 
267 
and least: "\<And>x y z. y \<le> x \<Longrightarrow> z \<le> x \<Longrightarrow> y \<nabla> z \<le> x" 

22737  268 
shows "x \<squnion> y = x \<nabla> y" 
22454  269 
proof (rule antisym) 
25062  270 
show "x \<squnion> y \<le> x \<nabla> y" by (rule le_supI) (rule ge1, rule ge2) 
22454  271 
next 
25062  272 
have leI: "\<And>x y z. x \<le> z \<Longrightarrow> y \<le> z \<Longrightarrow> x \<nabla> y \<le> z" by (blast intro: least) 
273 
show "x \<nabla> y \<le> x \<squnion> y" by (rule leI) simp_all 

22454  274 
qed 
275 

276 

22916  277 
subsection {* @{const min}/@{const max} on linear orders as 
278 
special case of @{const inf}/@{const sup} *} 

279 

280 
lemma (in linorder) distrib_lattice_min_max: 

25062  281 
"distrib_lattice (op \<le>) (op <) min max" 
22916  282 
proof unfold_locales 
25062  283 
have aux: "\<And>x y \<Colon> 'a. x < y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y" 
22916  284 
by (auto simp add: less_le antisym) 
285 
fix x y z 

286 
show "max x (min y z) = min (max x y) (max x z)" 

287 
unfolding min_def max_def 

24640
85a6c200ecd3
Simplified proofs due to transitivity reasoner setup.
ballarin
parents:
24514
diff
changeset

288 
by auto 
22916  289 
qed (auto simp add: min_def max_def not_le less_imp_le) 
21249  290 

291 
interpretation min_max: 

22454  292 
distrib_lattice ["op \<le> \<Colon> 'a\<Colon>linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max] 
23948  293 
by (rule distrib_lattice_min_max) 
21249  294 

22454  295 
lemma inf_min: "inf = (min \<Colon> 'a\<Colon>{lower_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)" 
296 
by (rule ext)+ auto 

21733  297 

22454  298 
lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{upper_semilattice, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)" 
299 
by (rule ext)+ auto 

21733  300 

21249  301 
lemmas le_maxI1 = min_max.sup_ge1 
302 
lemmas le_maxI2 = min_max.sup_ge2 

21381  303 

21249  304 
lemmas max_ac = min_max.sup_assoc min_max.sup_commute 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

305 
mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute] 
21249  306 

307 
lemmas min_ac = min_max.inf_assoc min_max.inf_commute 

22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

308 
mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute] 
21249  309 

22454  310 
text {* 
311 
Now we have inherited antisymmetry as an introrule on all 

312 
linear orders. This is a problem because it applies to bool, which is 

313 
undesirable. 

314 
*} 

315 

316 
lemmas [rule del] = min_max.antisym_intro min_max.le_infI min_max.le_supI 

317 
min_max.le_supE min_max.le_infE min_max.le_supI1 min_max.le_supI2 

318 
min_max.le_infI1 min_max.le_infI2 

319 

320 

23878  321 
subsection {* Complete lattices *} 
322 

323 
class complete_lattice = lattice + 

324 
fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900) 

24345  325 
and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900) 
23878  326 
assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x" 
24345  327 
and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A" 
328 
assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A" 

329 
and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z" 

23878  330 
begin 
331 

25062  332 
lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}" 
24345  333 
by (auto intro: Inf_lower Inf_greatest Sup_upper Sup_least) 
23878  334 

25062  335 
lemma Sup_Inf: "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}" 
24345  336 
by (auto intro: Inf_lower Inf_greatest Sup_upper Sup_least) 
23878  337 

338 
lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}" 

24345  339 
unfolding Sup_Inf by auto 
23878  340 

341 
lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}" 

342 
unfolding Inf_Sup by auto 

343 

344 
lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A" 

345 
apply (rule antisym) 

346 
apply (rule le_infI) 

347 
apply (rule Inf_lower) 

348 
apply simp 

349 
apply (rule Inf_greatest) 

350 
apply (rule Inf_lower) 

351 
apply simp 

352 
apply (rule Inf_greatest) 

353 
apply (erule insertE) 

354 
apply (rule le_infI1) 

355 
apply simp 

356 
apply (rule le_infI2) 

357 
apply (erule Inf_lower) 

358 
done 

359 

24345  360 
lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A" 
23878  361 
apply (rule antisym) 
362 
apply (rule Sup_least) 

363 
apply (erule insertE) 

364 
apply (rule le_supI1) 

365 
apply simp 

366 
apply (rule le_supI2) 

367 
apply (erule Sup_upper) 

368 
apply (rule le_supI) 

369 
apply (rule Sup_upper) 

370 
apply simp 

371 
apply (rule Sup_least) 

372 
apply (rule Sup_upper) 

373 
apply simp 

374 
done 

375 

376 
lemma Inf_singleton [simp]: 

377 
"\<Sqinter>{a} = a" 

378 
by (auto intro: antisym Inf_lower Inf_greatest) 

379 

24345  380 
lemma Sup_singleton [simp]: 
23878  381 
"\<Squnion>{a} = a" 
382 
by (auto intro: antisym Sup_upper Sup_least) 

383 

384 
lemma Inf_insert_simp: 

385 
"\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)" 

386 
by (cases "A = {}") (simp_all, simp add: Inf_insert) 

387 

388 
lemma Sup_insert_simp: 

389 
"\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)" 

390 
by (cases "A = {}") (simp_all, simp add: Sup_insert) 

391 

392 
lemma Inf_binary: 

393 
"\<Sqinter>{a, b} = a \<sqinter> b" 

394 
by (simp add: Inf_insert_simp) 

395 

396 
lemma Sup_binary: 

397 
"\<Squnion>{a, b} = a \<squnion> b" 

398 
by (simp add: Sup_insert_simp) 

399 

400 
definition 

24749  401 
top :: 'a 
23878  402 
where 
403 
"top = Inf {}" 

404 

405 
definition 

24749  406 
bot :: 'a 
23878  407 
where 
408 
"bot = Sup {}" 

409 

25062  410 
lemma top_greatest [simp]: "x \<le> top" 
23878  411 
by (unfold top_def, rule Inf_greatest, simp) 
412 

25062  413 
lemma bot_least [simp]: "bot \<le> x" 
23878  414 
by (unfold bot_def, rule Sup_least, simp) 
415 

416 
definition 

24749  417 
SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" 
23878  418 
where 
419 
"SUPR A f == Sup (f ` A)" 

420 

421 
definition 

24749  422 
INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" 
23878  423 
where 
424 
"INFI A f == Inf (f ` A)" 

425 

24749  426 
end 
427 

23878  428 
syntax 
429 
"_SUP1" :: "pttrns => 'b => 'b" ("(3SUP _./ _)" [0, 10] 10) 

430 
"_SUP" :: "pttrn => 'a set => 'b => 'b" ("(3SUP _:_./ _)" [0, 10] 10) 

431 
"_INF1" :: "pttrns => 'b => 'b" ("(3INF _./ _)" [0, 10] 10) 

432 
"_INF" :: "pttrn => 'a set => 'b => 'b" ("(3INF _:_./ _)" [0, 10] 10) 

433 

434 
translations 

435 
"SUP x y. B" == "SUP x. SUP y. B" 

436 
"SUP x. B" == "CONST SUPR UNIV (%x. B)" 

437 
"SUP x. B" == "SUP x:UNIV. B" 

438 
"SUP x:A. B" == "CONST SUPR A (%x. B)" 

439 
"INF x y. B" == "INF x. INF y. B" 

440 
"INF x. B" == "CONST INFI UNIV (%x. B)" 

441 
"INF x. B" == "INF x:UNIV. B" 

442 
"INF x:A. B" == "CONST INFI A (%x. B)" 

443 

444 
(* To avoid etacontraction of body: *) 

445 
print_translation {* 

446 
let 

447 
fun btr' syn (A :: Abs abs :: ts) = 

448 
let val (x,t) = atomic_abs_tr' abs 

449 
in list_comb (Syntax.const syn $ x $ A $ t, ts) end 

450 
val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const 

451 
in 

452 
[(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")] 

453 
end 

454 
*} 

455 

456 
lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)" 

457 
by (auto simp add: SUPR_def intro: Sup_upper) 

458 

459 
lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u" 

460 
by (auto simp add: SUPR_def intro: Sup_least) 

461 

462 
lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i" 

463 
by (auto simp add: INFI_def intro: Inf_lower) 

464 

465 
lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)" 

466 
by (auto simp add: INFI_def intro: Inf_greatest) 

467 

468 
lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M" 

469 
by (auto intro: order_antisym SUP_leI le_SUPI) 

470 

471 
lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M" 

472 
by (auto intro: order_antisym INF_leI le_INFI) 

473 

474 

22454  475 
subsection {* Bool as lattice *} 
476 

477 
instance bool :: distrib_lattice 

478 
inf_bool_eq: "inf P Q \<equiv> P \<and> Q" 

479 
sup_bool_eq: "sup P Q \<equiv> P \<or> Q" 

480 
by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def) 

481 

23878  482 
instance bool :: complete_lattice 
483 
Inf_bool_def: "Inf A \<equiv> \<forall>x\<in>A. x" 

24345  484 
Sup_bool_def: "Sup A \<equiv> \<exists>x\<in>A. x" 
485 
by intro_classes (auto simp add: Inf_bool_def Sup_bool_def le_bool_def) 

23878  486 

487 
lemma Inf_empty_bool [simp]: 

488 
"Inf {}" 

489 
unfolding Inf_bool_def by auto 

490 

491 
lemma not_Sup_empty_bool [simp]: 

492 
"\<not> Sup {}" 

24345  493 
unfolding Sup_bool_def by auto 
23878  494 

495 
lemma top_bool_eq: "top = True" 

496 
by (iprover intro!: order_antisym le_boolI top_greatest) 

497 

498 
lemma bot_bool_eq: "bot = False" 

499 
by (iprover intro!: order_antisym le_boolI bot_least) 

500 

501 

502 
subsection {* Set as lattice *} 

503 

504 
instance set :: (type) distrib_lattice 

505 
inf_set_eq: "inf A B \<equiv> A \<inter> B" 

506 
sup_set_eq: "sup A B \<equiv> A \<union> B" 

507 
by intro_classes (auto simp add: inf_set_eq sup_set_eq) 

508 

509 
lemmas [code func del] = inf_set_eq sup_set_eq 

510 

24514
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

511 
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B" 
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

512 
apply (fold inf_set_eq sup_set_eq) 
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

513 
apply (erule mono_inf) 
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

514 
done 
23878  515 

24514
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

516 
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)" 
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

517 
apply (fold inf_set_eq sup_set_eq) 
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

518 
apply (erule mono_sup) 
540eaf87e42d
mono_Int/Un: proper proof, avoid illegal schematic type vars;
wenzelm
parents:
24345
diff
changeset

519 
done 
23878  520 

521 
instance set :: (type) complete_lattice 

522 
Inf_set_def: "Inf S \<equiv> \<Inter>S" 

24345  523 
Sup_set_def: "Sup S \<equiv> \<Union>S" 
524 
by intro_classes (auto simp add: Inf_set_def Sup_set_def) 

23878  525 

24345  526 
lemmas [code func del] = Inf_set_def Sup_set_def 
23878  527 

528 
lemma top_set_eq: "top = UNIV" 

529 
by (iprover intro!: subset_antisym subset_UNIV top_greatest) 

530 

531 
lemma bot_set_eq: "bot = {}" 

532 
by (iprover intro!: subset_antisym empty_subsetI bot_least) 

533 

534 

535 
subsection {* Fun as lattice *} 

536 

537 
instance "fun" :: (type, lattice) lattice 

538 
inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))" 

539 
sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))" 

540 
apply intro_classes 

541 
unfolding inf_fun_eq sup_fun_eq 

542 
apply (auto intro: le_funI) 

543 
apply (rule le_funI) 

544 
apply (auto dest: le_funD) 

545 
apply (rule le_funI) 

546 
apply (auto dest: le_funD) 

547 
done 

548 

549 
lemmas [code func del] = inf_fun_eq sup_fun_eq 

550 

551 
instance "fun" :: (type, distrib_lattice) distrib_lattice 

552 
by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1) 

553 

554 
instance "fun" :: (type, complete_lattice) complete_lattice 

555 
Inf_fun_def: "Inf A \<equiv> (\<lambda>x. Inf {y. \<exists>f\<in>A. y = f x})" 

24345  556 
Sup_fun_def: "Sup A \<equiv> (\<lambda>x. Sup {y. \<exists>f\<in>A. y = f x})" 
557 
by intro_classes 

558 
(auto simp add: Inf_fun_def Sup_fun_def le_fun_def 

559 
intro: Inf_lower Sup_upper Inf_greatest Sup_least) 

23878  560 

24345  561 
lemmas [code func del] = Inf_fun_def Sup_fun_def 
23878  562 

563 
lemma Inf_empty_fun: 

564 
"Inf {} = (\<lambda>_. Inf {})" 

565 
by rule (auto simp add: Inf_fun_def) 

566 

567 
lemma Sup_empty_fun: 

568 
"Sup {} = (\<lambda>_. Sup {})" 

24345  569 
by rule (auto simp add: Sup_fun_def) 
23878  570 

571 
lemma top_fun_eq: "top = (\<lambda>x. top)" 

572 
by (iprover intro!: order_antisym le_funI top_greatest) 

573 

574 
lemma bot_fun_eq: "bot = (\<lambda>x. bot)" 

575 
by (iprover intro!: order_antisym le_funI bot_least) 

576 

577 

578 
text {* redundant bindings *} 

22454  579 

580 
lemmas inf_aci = inf_ACI 

581 
lemmas sup_aci = sup_ACI 

582 

25062  583 
no_notation 
584 
inf (infixl "\<sqinter>" 70) 

585 

586 
no_notation 

587 
sup (infixl "\<squnion>" 65) 

588 

589 
no_notation 

590 
Inf ("\<Sqinter>_" [900] 900) 

591 

592 
no_notation 

593 
Sup ("\<Squnion>_" [900] 900) 

594 

21249  595 
end 