src/HOL/Lattices.thy
changeset 23878 bd651ecd4b8a
parent 23389 aaca6a8e5414
child 23948 261bd4678076
     1.1 --- a/src/HOL/Lattices.thy	Fri Jul 20 00:01:40 2007 +0200
     1.2 +++ b/src/HOL/Lattices.thy	Fri Jul 20 14:27:56 2007 +0200
     1.3 @@ -11,12 +11,6 @@
     1.4  
     1.5  subsection{* Lattices *}
     1.6  
     1.7 -text{*
     1.8 -  This theory of lattices only defines binary sup and inf
     1.9 -  operations. The extension to complete lattices is done in theory
    1.10 -  @{text FixedPoint}.
    1.11 -*}
    1.12 -
    1.13  class lower_semilattice = order +
    1.14    fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
    1.15    assumes inf_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x"
    1.16 @@ -70,6 +64,9 @@
    1.17  
    1.18  end
    1.19  
    1.20 +lemma mono_inf: "mono f \<Longrightarrow> f (inf A B) \<le> inf (f A) (f B)"
    1.21 +  by (auto simp add: mono_def)
    1.22 +
    1.23  
    1.24  context upper_semilattice
    1.25  begin
    1.26 @@ -109,6 +106,9 @@
    1.27  
    1.28  end
    1.29  
    1.30 +lemma mono_sup: "mono f \<Longrightarrow> sup (f A) (f B) \<le> f (sup A B)"
    1.31 +  by (auto simp add: mono_def)
    1.32 +
    1.33  
    1.34  subsubsection{* Equational laws *}
    1.35  
    1.36 @@ -323,6 +323,174 @@
    1.37    min_max.le_infI1 min_max.le_infI2
    1.38  
    1.39  
    1.40 +subsection {* Complete lattices *}
    1.41 +
    1.42 +class complete_lattice = lattice +
    1.43 +  fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)
    1.44 +  assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"
    1.45 +  assumes Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"
    1.46 +begin
    1.47 +
    1.48 +definition
    1.49 +  Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)
    1.50 +where
    1.51 +  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<^loc>\<le> b}"
    1.52 +
    1.53 +lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<^loc>\<le> a}"
    1.54 +  unfolding Sup_def by (auto intro: Inf_greatest Inf_lower)
    1.55 +
    1.56 +lemma Sup_upper: "x \<in> A \<Longrightarrow> x \<^loc>\<le> \<Squnion>A"
    1.57 +  by (auto simp: Sup_def intro: Inf_greatest)
    1.58 +
    1.59 +lemma Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<^loc>\<le> z) \<Longrightarrow> \<Squnion>A \<^loc>\<le> z"
    1.60 +  by (auto simp: Sup_def intro: Inf_lower)
    1.61 +
    1.62 +lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
    1.63 +  unfolding Sup_def by auto
    1.64 +
    1.65 +lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
    1.66 +  unfolding Inf_Sup by auto
    1.67 +
    1.68 +lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
    1.69 +  apply (rule antisym)
    1.70 +  apply (rule le_infI)
    1.71 +  apply (rule Inf_lower)
    1.72 +  apply simp
    1.73 +  apply (rule Inf_greatest)
    1.74 +  apply (rule Inf_lower)
    1.75 +  apply simp
    1.76 +  apply (rule Inf_greatest)
    1.77 +  apply (erule insertE)
    1.78 +  apply (rule le_infI1)
    1.79 +  apply simp
    1.80 +  apply (rule le_infI2)
    1.81 +  apply (erule Inf_lower)
    1.82 +  done
    1.83 +
    1.84 +lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
    1.85 +  apply (rule antisym)
    1.86 +  apply (rule Sup_least)
    1.87 +  apply (erule insertE)
    1.88 +  apply (rule le_supI1)
    1.89 +  apply simp
    1.90 +  apply (rule le_supI2)
    1.91 +  apply (erule Sup_upper)
    1.92 +  apply (rule le_supI)
    1.93 +  apply (rule Sup_upper)
    1.94 +  apply simp
    1.95 +  apply (rule Sup_least)
    1.96 +  apply (rule Sup_upper)
    1.97 +  apply simp
    1.98 +  done
    1.99 +
   1.100 +lemma Inf_singleton [simp]:
   1.101 +  "\<Sqinter>{a} = a"
   1.102 +  by (auto intro: antisym Inf_lower Inf_greatest)
   1.103 +
   1.104 +lemma Sup_singleton [simp]:
   1.105 +  "\<Squnion>{a} = a"
   1.106 +  by (auto intro: antisym Sup_upper Sup_least)
   1.107 +
   1.108 +lemma Inf_insert_simp:
   1.109 +  "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
   1.110 +  by (cases "A = {}") (simp_all, simp add: Inf_insert)
   1.111 +
   1.112 +lemma Sup_insert_simp:
   1.113 +  "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
   1.114 +  by (cases "A = {}") (simp_all, simp add: Sup_insert)
   1.115 +
   1.116 +lemma Inf_binary:
   1.117 +  "\<Sqinter>{a, b} = a \<sqinter> b"
   1.118 +  by (simp add: Inf_insert_simp)
   1.119 +
   1.120 +lemma Sup_binary:
   1.121 +  "\<Squnion>{a, b} = a \<squnion> b"
   1.122 +  by (simp add: Sup_insert_simp)
   1.123 +
   1.124 +end
   1.125 +
   1.126 +lemmas Sup_def = Sup_def [folded complete_lattice_class.Sup]
   1.127 +lemmas Sup_upper = Sup_upper [folded complete_lattice_class.Sup]
   1.128 +lemmas Sup_least = Sup_least [folded complete_lattice_class.Sup]
   1.129 +
   1.130 +lemmas Sup_insert [code func] = Sup_insert [folded complete_lattice_class.Sup]
   1.131 +lemmas Sup_singleton [simp, code func] = Sup_singleton [folded complete_lattice_class.Sup]
   1.132 +lemmas Sup_insert_simp = Sup_insert_simp [folded complete_lattice_class.Sup]
   1.133 +lemmas Sup_binary = Sup_binary [folded complete_lattice_class.Sup]
   1.134 +
   1.135 +definition
   1.136 +  top :: "'a::complete_lattice"
   1.137 +where
   1.138 +  "top = Inf {}"
   1.139 +
   1.140 +definition
   1.141 +  bot :: "'a::complete_lattice"
   1.142 +where
   1.143 +  "bot = Sup {}"
   1.144 +
   1.145 +lemma top_greatest [simp]: "x \<le> top"
   1.146 +  by (unfold top_def, rule Inf_greatest, simp)
   1.147 +
   1.148 +lemma bot_least [simp]: "bot \<le> x"
   1.149 +  by (unfold bot_def, rule Sup_least, simp)
   1.150 +
   1.151 +definition
   1.152 +  SUPR :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::complete_lattice) \<Rightarrow> 'b"
   1.153 +where
   1.154 +  "SUPR A f == Sup (f ` A)"
   1.155 +
   1.156 +definition
   1.157 +  INFI :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b::complete_lattice) \<Rightarrow> 'b"
   1.158 +where
   1.159 +  "INFI A f == Inf (f ` A)"
   1.160 +
   1.161 +syntax
   1.162 +  "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
   1.163 +  "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
   1.164 +  "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
   1.165 +  "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
   1.166 +
   1.167 +translations
   1.168 +  "SUP x y. B"   == "SUP x. SUP y. B"
   1.169 +  "SUP x. B"     == "CONST SUPR UNIV (%x. B)"
   1.170 +  "SUP x. B"     == "SUP x:UNIV. B"
   1.171 +  "SUP x:A. B"   == "CONST SUPR A (%x. B)"
   1.172 +  "INF x y. B"   == "INF x. INF y. B"
   1.173 +  "INF x. B"     == "CONST INFI UNIV (%x. B)"
   1.174 +  "INF x. B"     == "INF x:UNIV. B"
   1.175 +  "INF x:A. B"   == "CONST INFI A (%x. B)"
   1.176 +
   1.177 +(* To avoid eta-contraction of body: *)
   1.178 +print_translation {*
   1.179 +let
   1.180 +  fun btr' syn (A :: Abs abs :: ts) =
   1.181 +    let val (x,t) = atomic_abs_tr' abs
   1.182 +    in list_comb (Syntax.const syn $ x $ A $ t, ts) end
   1.183 +  val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const
   1.184 +in
   1.185 +[(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]
   1.186 +end
   1.187 +*}
   1.188 +
   1.189 +lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
   1.190 +  by (auto simp add: SUPR_def intro: Sup_upper)
   1.191 +
   1.192 +lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
   1.193 +  by (auto simp add: SUPR_def intro: Sup_least)
   1.194 +
   1.195 +lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
   1.196 +  by (auto simp add: INFI_def intro: Inf_lower)
   1.197 +
   1.198 +lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
   1.199 +  by (auto simp add: INFI_def intro: Inf_greatest)
   1.200 +
   1.201 +lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
   1.202 +  by (auto intro: order_antisym SUP_leI le_SUPI)
   1.203 +
   1.204 +lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
   1.205 +  by (auto intro: order_antisym INF_leI le_INFI)
   1.206 +
   1.207 +
   1.208  subsection {* Bool as lattice *}
   1.209  
   1.210  instance bool :: distrib_lattice
   1.211 @@ -330,10 +498,156 @@
   1.212    sup_bool_eq: "sup P Q \<equiv> P \<or> Q"
   1.213    by intro_classes (auto simp add: inf_bool_eq sup_bool_eq le_bool_def)
   1.214  
   1.215 +instance bool :: complete_lattice
   1.216 +  Inf_bool_def: "Inf A \<equiv> \<forall>x\<in>A. x"
   1.217 +  apply intro_classes
   1.218 +  apply (unfold Inf_bool_def)
   1.219 +  apply (iprover intro!: le_boolI elim: ballE)
   1.220 +  apply (iprover intro!: ballI le_boolI elim: ballE le_boolE)
   1.221 +  done
   1.222  
   1.223 -text {* duplicates *}
   1.224 +theorem Sup_bool_eq: "Sup A \<longleftrightarrow> (\<exists>x\<in>A. x)"
   1.225 +  apply (rule order_antisym)
   1.226 +  apply (rule Sup_least)
   1.227 +  apply (rule le_boolI)
   1.228 +  apply (erule bexI, assumption)
   1.229 +  apply (rule le_boolI)
   1.230 +  apply (erule bexE)
   1.231 +  apply (rule le_boolE)
   1.232 +  apply (rule Sup_upper)
   1.233 +  apply assumption+
   1.234 +  done
   1.235 +
   1.236 +lemma Inf_empty_bool [simp]:
   1.237 +  "Inf {}"
   1.238 +  unfolding Inf_bool_def by auto
   1.239 +
   1.240 +lemma not_Sup_empty_bool [simp]:
   1.241 +  "\<not> Sup {}"
   1.242 +  unfolding Sup_def Inf_bool_def by auto
   1.243 +
   1.244 +lemma top_bool_eq: "top = True"
   1.245 +  by (iprover intro!: order_antisym le_boolI top_greatest)
   1.246 +
   1.247 +lemma bot_bool_eq: "bot = False"
   1.248 +  by (iprover intro!: order_antisym le_boolI bot_least)
   1.249 +
   1.250 +
   1.251 +subsection {* Set as lattice *}
   1.252 +
   1.253 +instance set :: (type) distrib_lattice
   1.254 +  inf_set_eq: "inf A B \<equiv> A \<inter> B"
   1.255 +  sup_set_eq: "sup A B \<equiv> A \<union> B"
   1.256 +  by intro_classes (auto simp add: inf_set_eq sup_set_eq)
   1.257 +
   1.258 +lemmas [code func del] = inf_set_eq sup_set_eq
   1.259 +
   1.260 +lemmas mono_Int = mono_inf
   1.261 +  [where ?'a="?'a set", where ?'b="?'b set", unfolded inf_set_eq sup_set_eq]
   1.262 +
   1.263 +lemmas mono_Un = mono_sup
   1.264 +  [where ?'a="?'a set", where ?'b="?'b set", unfolded inf_set_eq sup_set_eq]
   1.265 +
   1.266 +instance set :: (type) complete_lattice
   1.267 +  Inf_set_def: "Inf S \<equiv> \<Inter>S"
   1.268 +  by intro_classes (auto simp add: Inf_set_def)
   1.269 +
   1.270 +lemmas [code func del] = Inf_set_def
   1.271 +
   1.272 +theorem Sup_set_eq: "Sup S = \<Union>S"
   1.273 +  apply (rule subset_antisym)
   1.274 +  apply (rule Sup_least)
   1.275 +  apply (erule Union_upper)
   1.276 +  apply (rule Union_least)
   1.277 +  apply (erule Sup_upper)
   1.278 +  done
   1.279 +
   1.280 +lemma top_set_eq: "top = UNIV"
   1.281 +  by (iprover intro!: subset_antisym subset_UNIV top_greatest)
   1.282 +
   1.283 +lemma bot_set_eq: "bot = {}"
   1.284 +  by (iprover intro!: subset_antisym empty_subsetI bot_least)
   1.285 +
   1.286 +
   1.287 +subsection {* Fun as lattice *}
   1.288 +
   1.289 +instance "fun" :: (type, lattice) lattice
   1.290 +  inf_fun_eq: "inf f g \<equiv> (\<lambda>x. inf (f x) (g x))"
   1.291 +  sup_fun_eq: "sup f g \<equiv> (\<lambda>x. sup (f x) (g x))"
   1.292 +apply intro_classes
   1.293 +unfolding inf_fun_eq sup_fun_eq
   1.294 +apply (auto intro: le_funI)
   1.295 +apply (rule le_funI)
   1.296 +apply (auto dest: le_funD)
   1.297 +apply (rule le_funI)
   1.298 +apply (auto dest: le_funD)
   1.299 +done
   1.300 +
   1.301 +lemmas [code func del] = inf_fun_eq sup_fun_eq
   1.302 +
   1.303 +instance "fun" :: (type, distrib_lattice) distrib_lattice
   1.304 +  by default (auto simp add: inf_fun_eq sup_fun_eq sup_inf_distrib1)
   1.305 +
   1.306 +instance "fun" :: (type, complete_lattice) complete_lattice
   1.307 +  Inf_fun_def: "Inf A \<equiv> (\<lambda>x. Inf {y. \<exists>f\<in>A. y = f x})"
   1.308 +  apply intro_classes
   1.309 +  apply (unfold Inf_fun_def)
   1.310 +  apply (rule le_funI)
   1.311 +  apply (rule Inf_lower)
   1.312 +  apply (rule CollectI)
   1.313 +  apply (rule bexI)
   1.314 +  apply (rule refl)
   1.315 +  apply assumption
   1.316 +  apply (rule le_funI)
   1.317 +  apply (rule Inf_greatest)
   1.318 +  apply (erule CollectE)
   1.319 +  apply (erule bexE)
   1.320 +  apply (iprover elim: le_funE)
   1.321 +  done
   1.322 +
   1.323 +lemmas [code func del] = Inf_fun_def
   1.324 +
   1.325 +theorem Sup_fun_eq: "Sup A = (\<lambda>x. Sup {y. \<exists>f\<in>A. y = f x})"
   1.326 +  apply (rule order_antisym)
   1.327 +  apply (rule Sup_least)
   1.328 +  apply (rule le_funI)
   1.329 +  apply (rule Sup_upper)
   1.330 +  apply fast
   1.331 +  apply (rule le_funI)
   1.332 +  apply (rule Sup_least)
   1.333 +  apply (erule CollectE)
   1.334 +  apply (erule bexE)
   1.335 +  apply (drule le_funD [OF Sup_upper])
   1.336 +  apply simp
   1.337 +  done
   1.338 +
   1.339 +lemma Inf_empty_fun:
   1.340 +  "Inf {} = (\<lambda>_. Inf {})"
   1.341 +  by rule (auto simp add: Inf_fun_def)
   1.342 +
   1.343 +lemma Sup_empty_fun:
   1.344 +  "Sup {} = (\<lambda>_. Sup {})"
   1.345 +proof -
   1.346 +  have aux: "\<And>x. {y. \<exists>f. y = f x} = UNIV" by auto
   1.347 +  show ?thesis
   1.348 +  by (auto simp add: Sup_def Inf_fun_def Inf_binary inf_bool_eq aux)
   1.349 +qed
   1.350 +
   1.351 +lemma top_fun_eq: "top = (\<lambda>x. top)"
   1.352 +  by (iprover intro!: order_antisym le_funI top_greatest)
   1.353 +
   1.354 +lemma bot_fun_eq: "bot = (\<lambda>x. bot)"
   1.355 +  by (iprover intro!: order_antisym le_funI bot_least)
   1.356 +
   1.357 +
   1.358 +text {* redundant bindings *}
   1.359  
   1.360  lemmas inf_aci = inf_ACI
   1.361  lemmas sup_aci = sup_ACI
   1.362  
   1.363 +ML {*
   1.364 +val sup_fun_eq = @{thm sup_fun_eq}
   1.365 +val sup_bool_eq = @{thm sup_bool_eq}
   1.366 +*}
   1.367 +
   1.368  end