author  haftmann 
Fri, 16 Mar 2007 21:32:10 +0100  
changeset 22454  c3654ba76a09 
parent 22422  ee19cdb07528 
child 22548  6ce4bddf3bcb 
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 

22454  14 
text{* 
15 
This theory of lattices only defines binary sup and inf 

16 
operations. The extension to (finite) sets is done in theories @{text FixedPoint} 

17 
and @{text Finite_Set}. 

18 
*} 

21249  19 

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

20 
class lower_semilattice = order + 
21249  21 
fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

22 
assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x" and inf_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y" 
21733  23 
and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z" 
21249  24 

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

25 
class upper_semilattice = order + 
21249  26 
fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65) 
22422
ee19cdb07528
stepping towards uniform lattice theory development in HOL
haftmann
parents:
22384
diff
changeset

27 
assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y" and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y" 
21733  28 
and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x" 
21249  29 

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

30 
class lattice = lower_semilattice + upper_semilattice 
21249  31 

21733  32 
subsubsection{* Intro and elim rules*} 
33 

34 
context lower_semilattice 

35 
begin 

21249  36 

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

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

38 
lemmas (in ) [rule del] = antisym_intro 
21249  39 

21734  40 
lemma le_infI1[intro]: "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x" 
21733  41 
apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> a") 
22384
33a46e6c7f04
prefix of class interpretation not mandatory any longer
haftmann
parents:
22168
diff
changeset

42 
apply(blast intro: order_trans) 
21733  43 
apply simp 
44 
done 

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

45 
lemmas (in ) [rule del] = le_infI1 
21249  46 

21734  47 
lemma le_infI2[intro]: "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x" 
21733  48 
apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> b") 
22384
33a46e6c7f04
prefix of class interpretation not mandatory any longer
haftmann
parents:
22168
diff
changeset

49 
apply(blast intro: order_trans) 
21733  50 
apply simp 
51 
done 

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

52 
lemmas (in ) [rule del] = le_infI2 
21733  53 

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

56 
lemmas (in ) [rule del] = le_infI 
21249  57 

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

58 
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

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

60 
lemmas (in ) [rule del] = le_infE 
21249  61 

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

65 

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

21733  69 
end 
70 

71 

72 
context upper_semilattice 

73 
begin 

21249  74 

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

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

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

21734  78 
lemma le_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b" 
21733  79 
apply(subgoal_tac "a \<sqsubseteq> a \<squnion> b") 
22384
33a46e6c7f04
prefix of class interpretation not mandatory any longer
haftmann
parents:
22168
diff
changeset

80 
apply(blast intro: order_trans) 
21733  81 
apply simp 
82 
done 

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

83 
lemmas (in ) [rule del] = le_supI1 
21249  84 

21734  85 
lemma le_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b" 
21733  86 
apply(subgoal_tac "b \<sqsubseteq> a \<squnion> b") 
22384
33a46e6c7f04
prefix of class interpretation not mandatory any longer
haftmann
parents:
22168
diff
changeset

87 
apply(blast intro: order_trans) 
21733  88 
apply simp 
89 
done 

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

90 
lemmas (in ) [rule del] = le_supI2 
21733  91 

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

94 
lemmas (in ) [rule del] = le_supI 
21249  95 

21734  96 
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

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

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

99 

21249  100 

21734  101 
lemma ge_sup_conv[simp]: 
21733  102 
"x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)" 
103 
by blast 

104 

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

21733  108 
end 
109 

110 

111 
subsubsection{* Equational laws *} 

21249  112 

113 

21733  114 
context lower_semilattice 
115 
begin 

116 

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

118 
by blast 

119 

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

121 
by blast 

122 

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

124 
by blast 

125 

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

127 
by blast 

128 

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

130 
by blast 

131 

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

133 
by blast 

134 

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

136 
by blast 

137 

138 
lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem 

139 

140 
end 

141 

142 

143 
context upper_semilattice 

144 
begin 

21249  145 

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

148 

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

150 
by blast 

151 

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

153 
by blast 

154 

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

156 
by blast 

157 

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

159 
by blast 

160 

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

162 
by blast 

21249  163 

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

166 

167 
lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem 

168 

169 
end 

21249  170 

21733  171 
context lattice 
172 
begin 

173 

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

175 
by(blast intro: antisym inf_le1 inf_greatest sup_ge1) 

176 

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

178 
by(blast intro: antisym sup_ge1 sup_least inf_le1) 

179 

21734  180 
lemmas ACI = inf_ACI sup_ACI 
181 

22454  182 
lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2 
183 

21734  184 
text{* Towards distributivity *} 
21249  185 

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

188 

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

190 
by blast 

191 

192 

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

21249  194 

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

198 
proof 

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

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

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

202 
by(simp add:inf_sup_absorb inf_commute) 

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

204 
finally show ?thesis . 

205 
qed 

206 

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

210 
proof 

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

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

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

214 
by(simp add:sup_inf_absorb sup_commute) 

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

216 
finally show ?thesis . 

217 
qed 

218 

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

221 
by blast 

222 

21733  223 
end 
21249  224 

225 

226 
subsection{* Distributive lattices *} 

227 

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

21733  231 
context distrib_lattice 
232 
begin 

233 

234 
lemma sup_inf_distrib2: 

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

237 

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

241 

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

245 

21733  246 
lemmas distrib = 
21249  247 
sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2 
248 

21733  249 
end 
250 

21249  251 

22454  252 
subsection {* Uniqueness of inf and sup *} 
253 

254 
lemma inf_unique: 

255 
fixes f (infixl "\<triangle>" 70) 

256 
assumes le1: "\<And>x y. x \<triangle> y \<le> x" and le2: "\<And>x y. x \<triangle> y \<le> y" 

257 
and greatest: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z" 

258 
shows "inf x y = f x y" 

259 
proof (rule antisym) 

260 
show "x \<triangle> y \<le> inf x y" by (rule le_infI) (rule le1 le2) 

261 
next 

262 
have leI: "\<And>x y z. x \<le> y \<Longrightarrow> x \<le> z \<Longrightarrow> x \<le> y \<triangle> z" by (blast intro: greatest) 

263 
show "inf x y \<le> x \<triangle> y" by (rule leI) simp_all 

264 
qed 

265 

266 
lemma sup_unique: 

267 
fixes f (infixl "\<nabla>" 70) 

268 
assumes ge1 [simp]: "\<And>x y. x \<le> x \<nabla> y" and ge2: "\<And>x y. y \<le> x \<nabla> y" 

269 
and least: "\<And>x y z. y \<le> x \<Longrightarrow> z \<le> x \<Longrightarrow> y \<nabla> z \<le> x" 

270 
shows "sup x y = f x y" 

271 
proof (rule antisym) 

272 
show "sup x y \<le> x \<nabla> y" by (rule le_supI) (rule ge1 ge2) 

273 
next 

274 
have leI: "\<And>x y z. x \<le> z \<Longrightarrow> y \<le> z \<Longrightarrow> x \<nabla> y \<le> z" by (blast intro: least) 

275 
show "x \<nabla> y \<le> sup x y" by (rule leI) simp_all 

276 
qed 

277 

278 

21381  279 
subsection {* min/max on linear orders as special case of inf/sup *} 
21249  280 

281 
interpretation min_max: 

22454  282 
distrib_lattice ["op \<le> \<Colon> 'a\<Colon>linorder \<Rightarrow> 'a \<Rightarrow> bool" "op <" min max] 
21249  283 
apply unfold_locales 
21381  284 
apply (simp add: min_def linorder_not_le order_less_imp_le) 
285 
apply (simp add: min_def linorder_not_le order_less_imp_le) 

286 
apply (simp add: min_def linorder_not_le order_less_imp_le) 

287 
apply (simp add: max_def linorder_not_le order_less_imp_le) 

288 
apply (simp add: max_def linorder_not_le order_less_imp_le) 

289 
unfolding min_def max_def by auto 

21249  290 

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

21733  293 

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

21733  296 

21249  297 
lemmas le_maxI1 = min_max.sup_ge1 
298 
lemmas le_maxI2 = min_max.sup_ge2 

21381  299 

21249  300 
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

301 
mk_left_commute [of max, OF min_max.sup_assoc min_max.sup_commute] 
21249  302 

303 
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

304 
mk_left_commute [of min, OF min_max.inf_assoc min_max.inf_commute] 
21249  305 

22454  306 
text {* 
307 
Now we have inherited antisymmetry as an introrule on all 

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

309 
undesirable. 

310 
*} 

311 

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

313 
min_max.le_supE min_max.le_infE min_max.le_supI1 min_max.le_supI2 

314 
min_max.le_infI1 min_max.le_infI2 

315 

316 

317 
subsection {* Bool as lattice *} 

318 

319 
instance bool :: distrib_lattice 

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

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

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

323 

324 

325 
text {* duplicates *} 

326 

327 
lemmas inf_aci = inf_ACI 

328 
lemmas sup_aci = sup_ACI 

329 

330 

21733  331 
text {* ML legacy bindings *} 
332 

333 
ML {* 

22139  334 
val Least_def = @{thm Least_def} 
335 
val Least_equality = @{thm Least_equality} 

336 
val min_def = @{thm min_def} 

337 
val min_of_mono = @{thm min_of_mono} 

338 
val max_def = @{thm max_def} 

339 
val max_of_mono = @{thm max_of_mono} 

340 
val min_leastL = @{thm min_leastL} 

341 
val max_leastL = @{thm max_leastL} 

342 
val min_leastR = @{thm min_leastR} 

343 
val max_leastR = @{thm max_leastR} 

344 
val le_max_iff_disj = @{thm le_max_iff_disj} 

345 
val le_maxI1 = @{thm le_maxI1} 

346 
val le_maxI2 = @{thm le_maxI2} 

347 
val less_max_iff_disj = @{thm less_max_iff_disj} 

348 
val max_less_iff_conj = @{thm max_less_iff_conj} 

349 
val min_less_iff_conj = @{thm min_less_iff_conj} 

350 
val min_le_iff_disj = @{thm min_le_iff_disj} 

351 
val min_less_iff_disj = @{thm min_less_iff_disj} 

352 
val split_min = @{thm split_min} 

353 
val split_max = @{thm split_max} 

21733  354 
*} 
355 

21249  356 
end 