added boolean_algebra type class; tuned lattice duals
authorhaftmann
Sat Jul 11 21:33:01 2009 +0200 (2009-07-11)
changeset 3199137390299214a
parent 31990 1d4d0b305f16
child 31993 2ce88db62a84
added boolean_algebra type class; tuned lattice duals
src/HOL/Finite_Set.thy
src/HOL/Lattices.thy
src/HOL/Set.thy
     1.1 --- a/src/HOL/Finite_Set.thy	Fri Jul 10 09:24:50 2009 +0200
     1.2 +++ b/src/HOL/Finite_Set.thy	Sat Jul 11 21:33:01 2009 +0200
     1.3 @@ -2719,7 +2719,7 @@
     1.4  lemma (in upper_semilattice) ab_semigroup_idem_mult_sup:
     1.5    "ab_semigroup_idem_mult sup"
     1.6    by (rule lower_semilattice.ab_semigroup_idem_mult_inf)
     1.7 -    (rule dual_lattice)
     1.8 +    (rule dual_semilattice)
     1.9  
    1.10  context lattice
    1.11  begin
    1.12 @@ -2741,7 +2741,7 @@
    1.13  apply(erule exE)
    1.14  apply(rule order_trans)
    1.15  apply(erule (1) fold1_belowI)
    1.16 -apply(erule (1) lower_semilattice.fold1_belowI [OF dual_lattice])
    1.17 +apply(erule (1) lower_semilattice.fold1_belowI [OF dual_semilattice])
    1.18  done
    1.19  
    1.20  lemma sup_Inf_absorb [simp]:
    1.21 @@ -2753,7 +2753,7 @@
    1.22  lemma inf_Sup_absorb [simp]:
    1.23    "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> inf a (\<Squnion>\<^bsub>fin\<^esub>A) = a"
    1.24  by (simp add: Sup_fin_def inf_absorb1
    1.25 -  lower_semilattice.fold1_belowI [OF dual_lattice])
    1.26 +  lower_semilattice.fold1_belowI [OF dual_semilattice])
    1.27  
    1.28  end
    1.29  
     2.1 --- a/src/HOL/Lattices.thy	Fri Jul 10 09:24:50 2009 +0200
     2.2 +++ b/src/HOL/Lattices.thy	Sat Jul 11 21:33:01 2009 +0200
     2.3 @@ -29,7 +29,7 @@
     2.4  
     2.5  text {* Dual lattice *}
     2.6  
     2.7 -lemma dual_lattice:
     2.8 +lemma dual_semilattice:
     2.9    "lower_semilattice (op \<ge>) (op >) sup"
    2.10  by (rule lower_semilattice.intro, rule dual_order)
    2.11    (unfold_locales, simp_all add: sup_least)
    2.12 @@ -180,6 +180,11 @@
    2.13  context lattice
    2.14  begin
    2.15  
    2.16 +lemma dual_lattice:
    2.17 +  "lattice (op \<ge>) (op >) sup inf"
    2.18 +  by (rule lattice.intro, rule dual_semilattice, rule upper_semilattice.intro, rule dual_order)
    2.19 +    (unfold_locales, auto)
    2.20 +
    2.21  lemma inf_sup_absorb: "x \<sqinter> (x \<squnion> y) = x"
    2.22    by (blast intro: antisym inf_le1 inf_greatest sup_ge1)
    2.23  
    2.24 @@ -252,12 +257,148 @@
    2.25   "(y \<squnion> z) \<sqinter> x = (y \<sqinter> x) \<squnion> (z \<sqinter> x)"
    2.26  by(simp add:ACI inf_sup_distrib1)
    2.27  
    2.28 +lemma dual_distrib_lattice:
    2.29 +  "distrib_lattice (op \<ge>) (op >) sup inf"
    2.30 +  by (rule distrib_lattice.intro, rule dual_lattice)
    2.31 +    (unfold_locales, fact inf_sup_distrib1)
    2.32 +
    2.33  lemmas distrib =
    2.34    sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
    2.35  
    2.36  end
    2.37  
    2.38  
    2.39 +subsection {* Boolean algebras *}
    2.40 +
    2.41 +class boolean_algebra = distrib_lattice + top + bot + minus + uminus +
    2.42 +  assumes inf_compl_bot: "x \<sqinter> - x = bot"
    2.43 +    and sup_compl_top: "x \<squnion> - x = top"
    2.44 +  assumes diff_eq: "x - y = x \<sqinter> - y"
    2.45 +begin
    2.46 +
    2.47 +lemma dual_boolean_algebra:
    2.48 +  "boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) top bot"
    2.49 +  by (rule boolean_algebra.intro, rule dual_distrib_lattice)
    2.50 +    (unfold_locales,
    2.51 +      auto simp add: inf_compl_bot sup_compl_top diff_eq less_le_not_le)
    2.52 +
    2.53 +lemma compl_inf_bot:
    2.54 +  "- x \<sqinter> x = bot"
    2.55 +  by (simp add: inf_commute inf_compl_bot)
    2.56 +
    2.57 +lemma compl_sup_top:
    2.58 +  "- x \<squnion> x = top"
    2.59 +  by (simp add: sup_commute sup_compl_top)
    2.60 +
    2.61 +lemma inf_bot_left [simp]:
    2.62 +  "bot \<sqinter> x = bot"
    2.63 +  by (rule inf_absorb1) simp
    2.64 +
    2.65 +lemma inf_bot_right [simp]:
    2.66 +  "x \<sqinter> bot = bot"
    2.67 +  by (rule inf_absorb2) simp
    2.68 +
    2.69 +lemma sup_top_left [simp]:
    2.70 +  "top \<squnion> x = top"
    2.71 +  by (rule sup_absorb1) simp
    2.72 +
    2.73 +lemma sup_top_right [simp]:
    2.74 +  "x \<squnion> top = top"
    2.75 +  by (rule sup_absorb2) simp
    2.76 +
    2.77 +lemma inf_top_left [simp]:
    2.78 +  "top \<sqinter> x = x"
    2.79 +  by (rule inf_absorb2) simp
    2.80 +
    2.81 +lemma inf_top_right [simp]:
    2.82 +  "x \<sqinter> top = x"
    2.83 +  by (rule inf_absorb1) simp
    2.84 +
    2.85 +lemma sup_bot_left [simp]:
    2.86 +  "bot \<squnion> x = x"
    2.87 +  by (rule sup_absorb2) simp
    2.88 +
    2.89 +lemma sup_bot_right [simp]:
    2.90 +  "x \<squnion> bot = x"
    2.91 +  by (rule sup_absorb1) simp
    2.92 +
    2.93 +lemma compl_unique:
    2.94 +  assumes "x \<sqinter> y = bot"
    2.95 +    and "x \<squnion> y = top"
    2.96 +  shows "- x = y"
    2.97 +proof -
    2.98 +  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
    2.99 +    using inf_compl_bot assms(1) by simp
   2.100 +  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
   2.101 +    by (simp add: inf_commute)
   2.102 +  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
   2.103 +    by (simp add: inf_sup_distrib1)
   2.104 +  then have "- x \<sqinter> top = y \<sqinter> top"
   2.105 +    using sup_compl_top assms(2) by simp
   2.106 +  then show "- x = y" by (simp add: inf_top_right)
   2.107 +qed
   2.108 +
   2.109 +lemma double_compl [simp]:
   2.110 +  "- (- x) = x"
   2.111 +  using compl_inf_bot compl_sup_top by (rule compl_unique)
   2.112 +
   2.113 +lemma compl_eq_compl_iff [simp]:
   2.114 +  "- x = - y \<longleftrightarrow> x = y"
   2.115 +proof
   2.116 +  assume "- x = - y"
   2.117 +  then have "- x \<sqinter> y = bot"
   2.118 +    and "- x \<squnion> y = top"
   2.119 +    by (simp_all add: compl_inf_bot compl_sup_top)
   2.120 +  then have "- (- x) = y" by (rule compl_unique)
   2.121 +  then show "x = y" by simp
   2.122 +next
   2.123 +  assume "x = y"
   2.124 +  then show "- x = - y" by simp
   2.125 +qed
   2.126 +
   2.127 +lemma compl_bot_eq [simp]:
   2.128 +  "- bot = top"
   2.129 +proof -
   2.130 +  from sup_compl_top have "bot \<squnion> - bot = top" .
   2.131 +  then show ?thesis by simp
   2.132 +qed
   2.133 +
   2.134 +lemma compl_top_eq [simp]:
   2.135 +  "- top = bot"
   2.136 +proof -
   2.137 +  from inf_compl_bot have "top \<sqinter> - top = bot" .
   2.138 +  then show ?thesis by simp
   2.139 +qed
   2.140 +
   2.141 +lemma compl_inf [simp]:
   2.142 +  "- (x \<sqinter> y) = - x \<squnion> - y"
   2.143 +proof (rule compl_unique)
   2.144 +  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = ((x \<sqinter> y) \<sqinter> - x) \<squnion> ((x \<sqinter> y) \<sqinter> - y)"
   2.145 +    by (rule inf_sup_distrib1)
   2.146 +  also have "... = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
   2.147 +    by (simp only: inf_commute inf_assoc inf_left_commute)
   2.148 +  finally show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = bot"
   2.149 +    by (simp add: inf_compl_bot)
   2.150 +next
   2.151 +  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (x \<squnion> (- x \<squnion> - y)) \<sqinter> (y \<squnion> (- x \<squnion> - y))"
   2.152 +    by (rule sup_inf_distrib2)
   2.153 +  also have "... = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
   2.154 +    by (simp only: sup_commute sup_assoc sup_left_commute)
   2.155 +  finally show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = top"
   2.156 +    by (simp add: sup_compl_top)
   2.157 +qed
   2.158 +
   2.159 +lemma compl_sup [simp]:
   2.160 +  "- (x \<squnion> y) = - x \<sqinter> - y"
   2.161 +proof -
   2.162 +  interpret boolean_algebra "\<lambda>x y. x \<squnion> - y" uminus "op \<ge>" "op >" "op \<squnion>" "op \<sqinter>" top bot
   2.163 +    by (rule dual_boolean_algebra)
   2.164 +  then show ?thesis by simp
   2.165 +qed
   2.166 +
   2.167 +end
   2.168 +
   2.169 +
   2.170  subsection {* Uniqueness of inf and sup *}
   2.171  
   2.172  lemma (in lower_semilattice) inf_unique:
   2.173 @@ -330,17 +471,24 @@
   2.174  
   2.175  subsection {* Bool as lattice *}
   2.176  
   2.177 -instantiation bool :: distrib_lattice
   2.178 +instantiation bool :: boolean_algebra
   2.179  begin
   2.180  
   2.181  definition
   2.182 +  bool_Compl_def: "uminus = Not"
   2.183 +
   2.184 +definition
   2.185 +  bool_diff_def: "A - B \<longleftrightarrow> A \<and> \<not> B"
   2.186 +
   2.187 +definition
   2.188    inf_bool_eq: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
   2.189  
   2.190  definition
   2.191    sup_bool_eq: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
   2.192  
   2.193 -instance
   2.194 -  by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
   2.195 +instance proof
   2.196 +qed (simp_all add: inf_bool_eq sup_bool_eq le_bool_def
   2.197 +  bot_bool_eq top_bool_eq bool_Compl_def bool_diff_def, auto)
   2.198  
   2.199  end
   2.200  
   2.201 @@ -369,7 +517,33 @@
   2.202  end
   2.203  
   2.204  instance "fun" :: (type, distrib_lattice) distrib_lattice
   2.205 -  by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   2.206 +proof
   2.207 +qed (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   2.208 +
   2.209 +instantiation "fun" :: (type, uminus) uminus
   2.210 +begin
   2.211 +
   2.212 +definition
   2.213 +  fun_Compl_def: "- A = (\<lambda>x. - A x)"
   2.214 +
   2.215 +instance ..
   2.216 +
   2.217 +end
   2.218 +
   2.219 +instantiation "fun" :: (type, minus) minus
   2.220 +begin
   2.221 +
   2.222 +definition
   2.223 +  fun_diff_def: "A - B = (\<lambda>x. A x - B x)"
   2.224 +
   2.225 +instance ..
   2.226 +
   2.227 +end
   2.228 +
   2.229 +instance "fun" :: (type, boolean_algebra) boolean_algebra
   2.230 +proof
   2.231 +qed (simp_all add: inf_fun_eq sup_fun_eq bot_fun_eq top_fun_eq fun_Compl_def fun_diff_def
   2.232 +  inf_compl_bot sup_compl_top diff_eq)
   2.233  
   2.234  
   2.235  text {* redundant bindings *}
     3.1 --- a/src/HOL/Set.thy	Fri Jul 10 09:24:50 2009 +0200
     3.2 +++ b/src/HOL/Set.thy	Sat Jul 11 21:33:01 2009 +0200
     3.3 @@ -10,7 +10,6 @@
     3.4  
     3.5  text {* A set in HOL is simply a predicate. *}
     3.6  
     3.7 -
     3.8  subsection {* Basic syntax *}
     3.9  
    3.10  global
    3.11 @@ -363,46 +362,6 @@
    3.12    Bex_def:      "Bex A P        == EX x. x:A & P(x)"
    3.13    Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"
    3.14  
    3.15 -instantiation "fun" :: (type, minus) minus
    3.16 -begin
    3.17 -
    3.18 -definition
    3.19 -  fun_diff_def: "A - B = (%x. A x - B x)"
    3.20 -
    3.21 -instance ..
    3.22 -
    3.23 -end
    3.24 -
    3.25 -instantiation bool :: minus
    3.26 -begin
    3.27 -
    3.28 -definition
    3.29 -  bool_diff_def: "A - B = (A & ~ B)"
    3.30 -
    3.31 -instance ..
    3.32 -
    3.33 -end
    3.34 -
    3.35 -instantiation "fun" :: (type, uminus) uminus
    3.36 -begin
    3.37 -
    3.38 -definition
    3.39 -  fun_Compl_def: "- A = (%x. - A x)"
    3.40 -
    3.41 -instance ..
    3.42 -
    3.43 -end
    3.44 -
    3.45 -instantiation bool :: uminus
    3.46 -begin
    3.47 -
    3.48 -definition
    3.49 -  bool_Compl_def: "- A = (~ A)"
    3.50 -
    3.51 -instance ..
    3.52 -
    3.53 -end
    3.54 -
    3.55  definition Pow :: "'a set => 'a set set" where
    3.56    Pow_def: "Pow A = {B. B \<le> A}"
    3.57