src/HOL/Lattices.thy
changeset 31991 37390299214a
parent 30729 461ee3e49ad3
child 32063 2aab4f2af536
     1.1 --- a/src/HOL/Lattices.thy	Fri Jul 10 09:24:50 2009 +0200
     1.2 +++ b/src/HOL/Lattices.thy	Sat Jul 11 21:33:01 2009 +0200
     1.3 @@ -29,7 +29,7 @@
     1.4  
     1.5  text {* Dual lattice *}
     1.6  
     1.7 -lemma dual_lattice:
     1.8 +lemma dual_semilattice:
     1.9    "lower_semilattice (op \<ge>) (op >) sup"
    1.10  by (rule lower_semilattice.intro, rule dual_order)
    1.11    (unfold_locales, simp_all add: sup_least)
    1.12 @@ -180,6 +180,11 @@
    1.13  context lattice
    1.14  begin
    1.15  
    1.16 +lemma dual_lattice:
    1.17 +  "lattice (op \<ge>) (op >) sup inf"
    1.18 +  by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
    1.19 +    (unfold_locales, auto)
    1.20 +
    1.21  lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
    1.22    by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
    1.23  
    1.24 @@ -252,12 +257,148 @@
    1.25   "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
    1.26  by(simp add:ACI inf_sup_distrib1)
    1.27  
    1.28 +lemma dual_distrib_lattice:
    1.29 +  "distrib_lattice (op \<ge>) (op >) sup inf"
    1.30 +  by (rule distrib_lattice.intro, rule dual_lattice)
    1.31 +    (unfold_locales, fact inf_sup_distrib1)
    1.32 +
    1.33  lemmas distrib =
    1.34    sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
    1.35  
    1.36  end
    1.37  
    1.38  
    1.39 +subsection {* Boolean algebras *}
    1.40 +
    1.41 +class boolean_algebra = distrib_lattice + top + bot + minus + uminus +
    1.42 +  assumes inf_compl_bot: "x \<sqinter> - x = bot"
    1.43 +    and sup_compl_top: "x \<squnion> - x = top"
    1.44 +  assumes diff_eq: "x - y = x \<sqinter> - y"
    1.45 +begin
    1.46 +
    1.47 +lemma dual_boolean_algebra:
    1.48 +  "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) top bot"
    1.49 +  by (rule boolean_algebra.intro, rule dual_distrib_lattice)
    1.50 +    (unfold_locales,
    1.51 +      auto simp add: inf_compl_bot sup_compl_top diff_eq less_le_not_le)
    1.52 +
    1.53 +lemma compl_inf_bot:
    1.54 +  "- x \<sqinter> x = bot"
    1.55 +  by (simp add: inf_commute inf_compl_bot)
    1.56 +
    1.57 +lemma compl_sup_top:
    1.58 +  "- x \<squnion> x = top"
    1.59 +  by (simp add: sup_commute sup_compl_top)
    1.60 +
    1.61 +lemma inf_bot_left [simp]:
    1.62 +  "bot \<sqinter> x = bot"
    1.63 +  by (rule inf_absorb1) simp
    1.64 +
    1.65 +lemma inf_bot_right [simp]:
    1.66 +  "x \<sqinter> bot = bot"
    1.67 +  by (rule inf_absorb2) simp
    1.68 +
    1.69 +lemma sup_top_left [simp]:
    1.70 +  "top \<squnion> x = top"
    1.71 +  by (rule sup_absorb1) simp
    1.72 +
    1.73 +lemma sup_top_right [simp]:
    1.74 +  "x \<squnion> top = top"
    1.75 +  by (rule sup_absorb2) simp
    1.76 +
    1.77 +lemma inf_top_left [simp]:
    1.78 +  "top \<sqinter> x = x"
    1.79 +  by (rule inf_absorb2) simp
    1.80 +
    1.81 +lemma inf_top_right [simp]:
    1.82 +  "x \<sqinter> top = x"
    1.83 +  by (rule inf_absorb1) simp
    1.84 +
    1.85 +lemma sup_bot_left [simp]:
    1.86 +  "bot \<squnion> x = x"
    1.87 +  by (rule sup_absorb2) simp
    1.88 +
    1.89 +lemma sup_bot_right [simp]:
    1.90 +  "x \<squnion> bot = x"
    1.91 +  by (rule sup_absorb1) simp
    1.92 +
    1.93 +lemma compl_unique:
    1.94 +  assumes "x \<sqinter> y = bot"
    1.95 +    and "x \<squnion> y = top"
    1.96 +  shows "- x = y"
    1.97 +proof -
    1.98 +  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
    1.99 +    using inf_compl_bot assms(1) by simp
   1.100 +  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
   1.101 +    by (simp add: inf_commute)
   1.102 +  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
   1.103 +    by (simp add: inf_sup_distrib1)
   1.104 +  then have "- x \<sqinter> top = y \<sqinter> top"
   1.105 +    using sup_compl_top assms(2) by simp
   1.106 +  then show "- x = y" by (simp add: inf_top_right)
   1.107 +qed
   1.108 +
   1.109 +lemma double_compl [simp]:
   1.110 +  "- (- x) = x"
   1.111 +  using compl_inf_bot compl_sup_top by (rule compl_unique)
   1.112 +
   1.113 +lemma compl_eq_compl_iff [simp]:
   1.114 +  "- x = - y \<longleftrightarrow> x = y"
   1.115 +proof
   1.116 +  assume "- x = - y"
   1.117 +  then have "- x \<sqinter> y = bot"
   1.118 +    and "- x \<squnion> y = top"
   1.119 +    by (simp_all add: compl_inf_bot compl_sup_top)
   1.120 +  then have "- (- x) = y" by (rule compl_unique)
   1.121 +  then show "x = y" by simp
   1.122 +next
   1.123 +  assume "x = y"
   1.124 +  then show "- x = - y" by simp
   1.125 +qed
   1.126 +
   1.127 +lemma compl_bot_eq [simp]:
   1.128 +  "- bot = top"
   1.129 +proof -
   1.130 +  from sup_compl_top have "bot \<squnion> - bot = top" .
   1.131 +  then show ?thesis by simp
   1.132 +qed
   1.133 +
   1.134 +lemma compl_top_eq [simp]:
   1.135 +  "- top = bot"
   1.136 +proof -
   1.137 +  from inf_compl_bot have "top \<sqinter> - top = bot" .
   1.138 +  then show ?thesis by simp
   1.139 +qed
   1.140 +
   1.141 +lemma compl_inf [simp]:
   1.142 +  "- (x \<sqinter> y) = - x \<squnion> - y"
   1.143 +proof (rule compl_unique)
   1.144 +  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
   1.145 +    by (rule inf_sup_distrib1)
   1.146 +  also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
   1.147 +    by (simp only: inf_commute inf_assoc inf_left_commute)
   1.148 +  finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = bot"
   1.149 +    by (simp add: inf_compl_bot)
   1.150 +next
   1.151 +  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
   1.152 +    by (rule sup_inf_distrib2)
   1.153 +  also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
   1.154 +    by (simp only: sup_commute sup_assoc sup_left_commute)
   1.155 +  finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = top"
   1.156 +    by (simp add: sup_compl_top)
   1.157 +qed
   1.158 +
   1.159 +lemma compl_sup [simp]:
   1.160 +  "- (x \<squnion> y) = - x \<sqinter> - y"
   1.161 +proof -
   1.162 +  interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" top bot
   1.163 +    by (rule dual_boolean_algebra)
   1.164 +  then show ?thesis by simp
   1.165 +qed
   1.166 +
   1.167 +end
   1.168 +
   1.169 +
   1.170  subsection {* Uniqueness of inf and sup *}
   1.171  
   1.172  lemma (in lower_semilattice) inf_unique:
   1.173 @@ -330,17 +471,24 @@
   1.174  
   1.175  subsection {* Bool as lattice *}
   1.176  
   1.177 -instantiation bool :: distrib_lattice
   1.178 +instantiation bool :: boolean_algebra
   1.179  begin
   1.180  
   1.181  definition
   1.182 +  bool_Compl_def: "uminus = Not"
   1.183 +
   1.184 +definition
   1.185 +  bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
   1.186 +
   1.187 +definition
   1.188    inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
   1.189  
   1.190  definition
   1.191    sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
   1.192  
   1.193 -instance
   1.194 -  by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
   1.195 +instance proof
   1.196 +qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
   1.197 +  bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
   1.198  
   1.199  end
   1.200  
   1.201 @@ -369,7 +517,33 @@
   1.202  end
   1.203  
   1.204  instance "fun" :: (type, distrib_lattice) distrib_lattice
   1.205 -  by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   1.206 +proof
   1.207 +qed (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   1.208 +
   1.209 +instantiation "fun" :: (type, uminus) uminus
   1.210 +begin
   1.211 +
   1.212 +definition
   1.213 +  fun_Compl_def: "- A = (\<lambda>x. - A x)"
   1.214 +
   1.215 +instance ..
   1.216 +
   1.217 +end
   1.218 +
   1.219 +instantiation "fun" :: (type, minus) minus
   1.220 +begin
   1.221 +
   1.222 +definition
   1.223 +  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
   1.224 +
   1.225 +instance ..
   1.226 +
   1.227 +end
   1.228 +
   1.229 +instance "fun" :: (type, boolean_algebra) boolean_algebra
   1.230 +proof
   1.231 +qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
   1.232 +  inf_compl_bot sup_compl_top diff_eq)
   1.233  
   1.234  
   1.235  text {* redundant bindings *}