src/HOL/Lattices.thy
changeset 21733 131dd2a27137
parent 21619 dea0914773f7
child 21734 283461c15fa7
     1.1 --- a/src/HOL/Lattices.thy	Sat Dec 09 18:06:17 2006 +0100
     1.2 +++ b/src/HOL/Lattices.thy	Sun Dec 10 07:12:26 2006 +0100
     1.3 @@ -3,7 +3,7 @@
     1.4      Author:     Tobias Nipkow
     1.5  *)
     1.6  
     1.7 -header {* Abstract lattices *}
     1.8 +header {* Lattices via Locales *}
     1.9  
    1.10  theory Lattices
    1.11  imports Orderings
    1.12 @@ -19,67 +19,154 @@
    1.13  locale lower_semilattice = partial_order +
    1.14    fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
    1.15    assumes inf_le1[simp]: "x \<sqinter> y \<sqsubseteq> x" and inf_le2[simp]: "x \<sqinter> y \<sqsubseteq> y"
    1.16 -  and inf_least: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
    1.17 +  and inf_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z"
    1.18  
    1.19  locale upper_semilattice = partial_order +
    1.20    fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
    1.21    assumes sup_ge1[simp]: "x \<sqsubseteq> x \<squnion> y" and sup_ge2[simp]: "y \<sqsubseteq> x \<squnion> y"
    1.22 -  and sup_greatest: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    1.23 +  and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
    1.24  
    1.25  locale lattice = lower_semilattice + upper_semilattice
    1.26  
    1.27 -lemma (in lower_semilattice) inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
    1.28 -by(blast intro: antisym inf_le1 inf_le2 inf_least)
    1.29 +subsubsection{* Intro and elim rules*}
    1.30 +
    1.31 +context lower_semilattice
    1.32 +begin
    1.33  
    1.34 -lemma (in upper_semilattice) sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
    1.35 -by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest)
    1.36 +lemmas antisym_intro[intro!] = antisym
    1.37  
    1.38 -lemma (in lower_semilattice) inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
    1.39 -by(blast intro: antisym inf_le1 inf_le2 inf_least trans del:refl)
    1.40 +lemma less_eq_infI1[intro]: "a \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
    1.41 +apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> a")
    1.42 + apply(blast intro:trans)
    1.43 +apply simp
    1.44 +done
    1.45  
    1.46 -lemma (in upper_semilattice) sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
    1.47 -by(blast intro!: antisym sup_ge1 sup_ge2 intro: sup_greatest trans del:refl)
    1.48 +lemma less_eq_infI2[intro]: "b \<sqsubseteq> x \<Longrightarrow> a \<sqinter> b \<sqsubseteq> x"
    1.49 +apply(subgoal_tac "a \<sqinter> b \<sqsubseteq> b")
    1.50 + apply(blast intro:trans)
    1.51 +apply simp
    1.52 +done
    1.53 +
    1.54 +lemma less_eq_infI[intro!]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<sqinter> b"
    1.55 +by(blast intro: inf_greatest)
    1.56  
    1.57 -lemma (in lower_semilattice) inf_idem[simp]: "x \<sqinter> x = x"
    1.58 -by(blast intro: antisym inf_le1 inf_le2 inf_least refl)
    1.59 +lemma less_eq_infE[elim!]: "x \<sqsubseteq> a \<sqinter> b \<Longrightarrow> (x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> b \<Longrightarrow> P) \<Longrightarrow> P"
    1.60 +by(blast intro: trans)
    1.61  
    1.62 -lemma (in upper_semilattice) sup_idem[simp]: "x \<squnion> x = x"
    1.63 -by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl)
    1.64 +lemma less_eq_inf_conv [simp]:
    1.65 + "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
    1.66 +by blast
    1.67 +
    1.68 +lemmas below_inf_conv = less_eq_inf_conv
    1.69 +  -- {* a duplicate for backward compatibility *}
    1.70  
    1.71 -lemma (in lower_semilattice) inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
    1.72 -by (simp add: inf_assoc[symmetric])
    1.73 +end
    1.74 +
    1.75 +
    1.76 +context upper_semilattice
    1.77 +begin
    1.78  
    1.79 -lemma (in upper_semilattice) sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
    1.80 -by (simp add: sup_assoc[symmetric])
    1.81 +lemmas antisym_intro[intro!] = antisym
    1.82  
    1.83 -lemma (in lattice) inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
    1.84 -by(blast intro: antisym inf_le1 inf_least sup_ge1)
    1.85 +lemma less_eq_supI1[intro]: "x \<sqsubseteq> a \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
    1.86 +apply(subgoal_tac "a \<sqsubseteq> a \<squnion> b")
    1.87 + apply(blast intro:trans)
    1.88 +apply simp
    1.89 +done
    1.90  
    1.91 -lemma (in lattice) sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
    1.92 -by(blast intro: antisym sup_ge1 sup_greatest inf_le1)
    1.93 +lemma less_eq_supI2[intro]: "x \<sqsubseteq> b \<Longrightarrow> x \<sqsubseteq> a \<squnion> b"
    1.94 +apply(subgoal_tac "b \<sqsubseteq> a \<squnion> b")
    1.95 + apply(blast intro:trans)
    1.96 +apply simp
    1.97 +done
    1.98 +
    1.99 +lemma less_eq_supI[intro!]: "a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> a \<squnion> b \<sqsubseteq> x"
   1.100 +by(blast intro: sup_least)
   1.101  
   1.102 -lemma (in lower_semilattice) inf_absorb: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
   1.103 -by(blast intro: antisym inf_le1 inf_least refl)
   1.104 +lemma less_eq_supE[elim!]: "a \<squnion> b \<sqsubseteq> x \<Longrightarrow> (a \<sqsubseteq> x \<Longrightarrow> b \<sqsubseteq> x \<Longrightarrow> P) \<Longrightarrow> P"
   1.105 +by(blast intro: trans)
   1.106  
   1.107 -lemma (in upper_semilattice) sup_absorb: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
   1.108 -by(blast intro: antisym sup_ge2 sup_greatest refl)
   1.109 +lemma above_sup_conv[simp]:
   1.110 + "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
   1.111 +by blast
   1.112 +
   1.113 +end
   1.114 +
   1.115 +
   1.116 +subsubsection{* Equational laws *}
   1.117  
   1.118  
   1.119 -lemma (in lower_semilattice) less_eq_inf_conv [simp]:
   1.120 - "x \<sqsubseteq> y \<sqinter> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
   1.121 -by(blast intro: antisym inf_le1 inf_le2 inf_least refl trans)
   1.122 +context lower_semilattice
   1.123 +begin
   1.124 +
   1.125 +lemma inf_commute: "(x \<sqinter> y) = (y \<sqinter> x)"
   1.126 +by blast
   1.127 +
   1.128 +lemma inf_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
   1.129 +by blast
   1.130 +
   1.131 +lemma inf_idem[simp]: "x \<sqinter> x = x"
   1.132 +by blast
   1.133 +
   1.134 +lemma inf_left_idem[simp]: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
   1.135 +by blast
   1.136 +
   1.137 +lemma inf_absorb1: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x"
   1.138 +by blast
   1.139 +
   1.140 +lemma inf_absorb2: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y"
   1.141 +by blast
   1.142 +
   1.143 +lemma inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
   1.144 +by blast
   1.145 +
   1.146 +lemmas inf_ACI = inf_commute inf_assoc inf_left_commute inf_left_idem
   1.147 +
   1.148 +end
   1.149 +
   1.150 +
   1.151 +context upper_semilattice
   1.152 +begin
   1.153  
   1.154 -lemmas (in lower_semilattice) below_inf_conv = less_eq_inf_conv
   1.155 -  -- {* a duplicate for backward compatibility *}
   1.156 +lemma sup_commute: "(x \<squnion> y) = (y \<squnion> x)"
   1.157 +by blast
   1.158 +
   1.159 +lemma sup_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
   1.160 +by blast
   1.161 +
   1.162 +lemma sup_idem[simp]: "x \<squnion> x = x"
   1.163 +by blast
   1.164 +
   1.165 +lemma sup_left_idem[simp]: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
   1.166 +by blast
   1.167 +
   1.168 +lemma sup_absorb1: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x"
   1.169 +by blast
   1.170 +
   1.171 +lemma sup_absorb2: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y"
   1.172 +by blast
   1.173  
   1.174 -lemma (in upper_semilattice) above_sup_conv[simp]:
   1.175 - "x \<squnion> y \<sqsubseteq> z = (x \<sqsubseteq> z \<and> y \<sqsubseteq> z)"
   1.176 -by(blast intro: antisym sup_ge1 sup_ge2 sup_greatest refl trans)
   1.177 +lemma sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
   1.178 +by blast
   1.179 +
   1.180 +lemmas sup_ACI = sup_commute sup_assoc sup_left_commute sup_left_idem
   1.181 +
   1.182 +end
   1.183  
   1.184 +context lattice
   1.185 +begin
   1.186 +
   1.187 +lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
   1.188 +by(blast intro: antisym inf_le1 inf_greatest sup_ge1)
   1.189 +
   1.190 +lemma sup_inf_absorb: "x \<squnion> (x \<sqinter> y) = x"
   1.191 +by(blast intro: antisym sup_ge1 sup_least inf_le1)
   1.192 +
   1.193 +lemmas (in lattice) ACI = inf_ACI sup_ACI
   1.194  
   1.195  text{* Towards distributivity: if you have one of them, you have them all. *}
   1.196  
   1.197 -lemma (in lattice) distrib_imp1:
   1.198 +lemma distrib_imp1:
   1.199  assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   1.200  shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   1.201  proof-
   1.202 @@ -91,7 +178,7 @@
   1.203    finally show ?thesis .
   1.204  qed
   1.205  
   1.206 -lemma (in lattice) distrib_imp2:
   1.207 +lemma distrib_imp2:
   1.208  assumes D: "!!x y z. x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   1.209  shows "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   1.210  proof-
   1.211 @@ -103,46 +190,7 @@
   1.212    finally show ?thesis .
   1.213  qed
   1.214  
   1.215 -text{* A package of rewrite rules for deciding equivalence wrt ACI: *}
   1.216 -
   1.217 -lemma (in lower_semilattice) inf_left_commute: "x \<sqinter> (y \<sqinter> z) = y \<sqinter> (x \<sqinter> z)"
   1.218 -proof -
   1.219 -  have "x \<sqinter> (y \<sqinter> z) = (y \<sqinter> z) \<sqinter> x" by (simp only: inf_commute)
   1.220 -  also have "... = y \<sqinter> (z \<sqinter> x)" by (simp only: inf_assoc)
   1.221 -  also have "z \<sqinter> x = x \<sqinter> z" by (simp only: inf_commute)
   1.222 -  finally(back_subst) show ?thesis .
   1.223 -qed
   1.224 -
   1.225 -lemma (in upper_semilattice) sup_left_commute: "x \<squnion> (y \<squnion> z) = y \<squnion> (x \<squnion> z)"
   1.226 -proof -
   1.227 -  have "x \<squnion> (y \<squnion> z) = (y \<squnion> z) \<squnion> x" by (simp only: sup_commute)
   1.228 -  also have "... = y \<squnion> (z \<squnion> x)" by (simp only: sup_assoc)
   1.229 -  also have "z \<squnion> x = x \<squnion> z" by (simp only: sup_commute)
   1.230 -  finally(back_subst) show ?thesis .
   1.231 -qed
   1.232 -
   1.233 -lemma (in lower_semilattice) inf_left_idem: "x \<sqinter> (x \<sqinter> y) = x \<sqinter> y"
   1.234 -proof -
   1.235 -  have "x \<sqinter> (x \<sqinter> y) = (x \<sqinter> x) \<sqinter> y" by(simp only:inf_assoc)
   1.236 -  also have "\<dots> = x \<sqinter> y" by(simp)
   1.237 -  finally show ?thesis .
   1.238 -qed
   1.239 -
   1.240 -lemma (in upper_semilattice) sup_left_idem: "x \<squnion> (x \<squnion> y) = x \<squnion> y"
   1.241 -proof -
   1.242 -  have "x \<squnion> (x \<squnion> y) = (x \<squnion> x) \<squnion> y" by(simp only:sup_assoc)
   1.243 -  also have "\<dots> = x \<squnion> y" by(simp)
   1.244 -  finally show ?thesis .
   1.245 -qed
   1.246 -
   1.247 -
   1.248 -lemmas (in lower_semilattice) inf_ACI =
   1.249 - inf_commute inf_assoc inf_left_commute inf_left_idem
   1.250 -
   1.251 -lemmas (in upper_semilattice) sup_ACI =
   1.252 - sup_commute sup_assoc sup_left_commute sup_left_idem
   1.253 -
   1.254 -lemmas (in lattice) ACI = inf_ACI sup_ACI
   1.255 +end
   1.256  
   1.257  
   1.258  subsection{* Distributive lattices *}
   1.259 @@ -150,21 +198,26 @@
   1.260  locale distrib_lattice = lattice +
   1.261    assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   1.262  
   1.263 -lemma (in distrib_lattice) sup_inf_distrib2:
   1.264 +context distrib_lattice
   1.265 +begin
   1.266 +
   1.267 +lemma sup_inf_distrib2:
   1.268   "(y \<sqinter> z) \<squnion> x = (y \<squnion> x) \<sqinter> (z \<squnion> x)"
   1.269  by(simp add:ACI sup_inf_distrib1)
   1.270  
   1.271 -lemma (in distrib_lattice) inf_sup_distrib1:
   1.272 +lemma inf_sup_distrib1:
   1.273   "x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   1.274  by(rule distrib_imp2[OF sup_inf_distrib1])
   1.275  
   1.276 -lemma (in distrib_lattice) inf_sup_distrib2:
   1.277 +lemma inf_sup_distrib2:
   1.278   "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
   1.279  by(simp add:ACI inf_sup_distrib1)
   1.280  
   1.281 -lemmas (in distrib_lattice) distrib =
   1.282 +lemmas distrib =
   1.283    sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
   1.284  
   1.285 +end
   1.286 +
   1.287  
   1.288  subsection {* min/max on linear orders as special case of inf/sup *}
   1.289  
   1.290 @@ -178,6 +231,17 @@
   1.291  apply (simp add: max_def linorder_not_le order_less_imp_le)
   1.292  unfolding min_def max_def by auto
   1.293  
   1.294 +text{* Now we have inherited antisymmetry as an intro-rule on all
   1.295 +linear orders. This is a problem because it applies to bool, which is
   1.296 +undesirable. *}
   1.297 +
   1.298 +declare
   1.299 + min_max.antisym_intro[rule del]
   1.300 + min_max.less_eq_infI[rule del] min_max.less_eq_supI[rule del]
   1.301 + min_max.less_eq_supE[rule del] min_max.less_eq_infE[rule del]
   1.302 + min_max.less_eq_supI1[rule del] min_max.less_eq_supI2[rule del]
   1.303 + min_max.less_eq_infI1[rule del] min_max.less_eq_infI2[rule del]
   1.304 +
   1.305  lemmas le_maxI1 = min_max.sup_ge1
   1.306  lemmas le_maxI2 = min_max.sup_ge2
   1.307   
   1.308 @@ -187,4 +251,29 @@
   1.309  lemmas min_ac = min_max.inf_assoc min_max.inf_commute
   1.310                 mk_left_commute[of min,OF min_max.inf_assoc min_max.inf_commute]
   1.311  
   1.312 +text {* ML legacy bindings *}
   1.313 +
   1.314 +ML {*
   1.315 +val Least_def = thm "Least_def";
   1.316 +val Least_equality = thm "Least_equality";
   1.317 +val min_def = thm "min_def";
   1.318 +val min_of_mono = thm "min_of_mono";
   1.319 +val max_def = thm "max_def";
   1.320 +val max_of_mono = thm "max_of_mono";
   1.321 +val min_leastL = thm "min_leastL";
   1.322 +val max_leastL = thm "max_leastL";
   1.323 +val min_leastR = thm "min_leastR";
   1.324 +val max_leastR = thm "max_leastR";
   1.325 +val le_max_iff_disj = thm "le_max_iff_disj";
   1.326 +val le_maxI1 = thm "le_maxI1";
   1.327 +val le_maxI2 = thm "le_maxI2";
   1.328 +val less_max_iff_disj = thm "less_max_iff_disj";
   1.329 +val max_less_iff_conj = thm "max_less_iff_conj";
   1.330 +val min_less_iff_conj = thm "min_less_iff_conj";
   1.331 +val min_le_iff_disj = thm "min_le_iff_disj";
   1.332 +val min_less_iff_disj = thm "min_less_iff_disj";
   1.333 +val split_min = thm "split_min";
   1.334 +val split_max = thm "split_max";
   1.335 +*}
   1.336 +
   1.337  end