src/HOL/Conditionally_Complete_Lattices.thy
changeset 51773 9328c6681f3c
parent 51643 b6675f4549d8
child 51775 408d937c9486
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Conditionally_Complete_Lattices.thy	Wed Apr 24 13:28:30 2013 +0200
     1.3 @@ -0,0 +1,295 @@
     1.4 +(*  Title:      HOL/Conditional_Complete_Lattices.thy
     1.5 +    Author:     Amine Chaieb and L C Paulson, University of Cambridge
     1.6 +    Author:     Johannes Hölzl, TU München
     1.7 +*)
     1.8 +
     1.9 +header {* Conditionally-complete Lattices *}
    1.10 +
    1.11 +theory Conditionally_Complete_Lattices
    1.12 +imports Main Lubs
    1.13 +begin
    1.14 +
    1.15 +lemma Sup_fin_eq_Max: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup_fin X = Max X"
    1.16 +  by (induct X rule: finite_ne_induct) (simp_all add: sup_max)
    1.17 +
    1.18 +lemma Inf_fin_eq_Min: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf_fin X = Min X"
    1.19 +  by (induct X rule: finite_ne_induct) (simp_all add: inf_min)
    1.20 +
    1.21 +text {*
    1.22 +
    1.23 +To avoid name classes with the @{class complete_lattice}-class we prefix @{const Sup} and
    1.24 +@{const Inf} in theorem names with c.
    1.25 +
    1.26 +*}
    1.27 +
    1.28 +class conditionally_complete_lattice = lattice + Sup + Inf +
    1.29 +  assumes cInf_lower: "x \<in> X \<Longrightarrow> (\<And>a. a \<in> X \<Longrightarrow> z \<le> a) \<Longrightarrow> Inf X \<le> x"
    1.30 +    and cInf_greatest: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> z \<le> Inf X"
    1.31 +  assumes cSup_upper: "x \<in> X \<Longrightarrow> (\<And>a. a \<in> X \<Longrightarrow> a \<le> z) \<Longrightarrow> x \<le> Sup X"
    1.32 +    and cSup_least: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X \<le> z"
    1.33 +begin
    1.34 +
    1.35 +lemma cSup_eq_maximum: (*REAL_SUP_MAX in HOL4*)
    1.36 +  "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X = z"
    1.37 +  by (blast intro: antisym cSup_upper cSup_least)
    1.38 +
    1.39 +lemma cInf_eq_minimum: (*REAL_INF_MIN in HOL4*)
    1.40 +  "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X = z"
    1.41 +  by (intro antisym cInf_lower[of z X z] cInf_greatest[of X z]) auto
    1.42 +
    1.43 +lemma cSup_le_iff: "S \<noteq> {} \<Longrightarrow> (\<And>a. a \<in> S \<Longrightarrow> a \<le> z) \<Longrightarrow> Sup S \<le> a \<longleftrightarrow> (\<forall>x\<in>S. x \<le> a)"
    1.44 +  by (metis order_trans cSup_upper cSup_least)
    1.45 +
    1.46 +lemma le_cInf_iff: "S \<noteq> {} \<Longrightarrow> (\<And>a. a \<in> S \<Longrightarrow> z \<le> a) \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall>x\<in>S. a \<le> x)"
    1.47 +  by (metis order_trans cInf_lower cInf_greatest)
    1.48 +
    1.49 +lemma cSup_singleton [simp]: "Sup {x} = x"
    1.50 +  by (intro cSup_eq_maximum) auto
    1.51 +
    1.52 +lemma cInf_singleton [simp]: "Inf {x} = x"
    1.53 +  by (intro cInf_eq_minimum) auto
    1.54 +
    1.55 +lemma cSup_upper2: (*REAL_IMP_LE_SUP in HOL4*)
    1.56 +  "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y \<le> Sup X"
    1.57 +  by (metis cSup_upper order_trans)
    1.58 + 
    1.59 +lemma cInf_lower2:
    1.60 +  "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X \<le> y"
    1.61 +  by (metis cInf_lower order_trans)
    1.62 +
    1.63 +lemma cSup_upper_EX: "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> x \<le> z \<Longrightarrow> x \<le> Sup X"
    1.64 +  by (blast intro: cSup_upper)
    1.65 +
    1.66 +lemma cInf_lower_EX:  "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> z \<le> x \<Longrightarrow> Inf X \<le> x"
    1.67 +  by (blast intro: cInf_lower)
    1.68 +
    1.69 +lemma cSup_eq_non_empty:
    1.70 +  assumes 1: "X \<noteq> {}"
    1.71 +  assumes 2: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
    1.72 +  assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
    1.73 +  shows "Sup X = a"
    1.74 +  by (intro 3 1 antisym cSup_least) (auto intro: 2 1 cSup_upper)
    1.75 +
    1.76 +lemma cInf_eq_non_empty:
    1.77 +  assumes 1: "X \<noteq> {}"
    1.78 +  assumes 2: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
    1.79 +  assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
    1.80 +  shows "Inf X = a"
    1.81 +  by (intro 3 1 antisym cInf_greatest) (auto intro: 2 1 cInf_lower)
    1.82 +
    1.83 +lemma cInf_cSup: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf S = Sup {x. \<forall>s\<in>S. x \<le> s}"
    1.84 +  by (rule cInf_eq_non_empty) (auto intro: cSup_upper cSup_least)
    1.85 +
    1.86 +lemma cSup_cInf: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup S = Inf {x. \<forall>s\<in>S. s \<le> x}"
    1.87 +  by (rule cSup_eq_non_empty) (auto intro: cInf_lower cInf_greatest)
    1.88 +
    1.89 +lemma cSup_insert: 
    1.90 +  assumes x: "X \<noteq> {}"
    1.91 +      and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
    1.92 +  shows "Sup (insert a X) = sup a (Sup X)"
    1.93 +proof (intro cSup_eq_non_empty)
    1.94 +  fix y assume "\<And>x. x \<in> insert a X \<Longrightarrow> x \<le> y" with x show "sup a (Sup X) \<le> y" by (auto intro: cSup_least)
    1.95 +qed (auto intro: le_supI2 z cSup_upper)
    1.96 +
    1.97 +lemma cInf_insert: 
    1.98 +  assumes x: "X \<noteq> {}"
    1.99 +      and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
   1.100 +  shows "Inf (insert a X) = inf a (Inf X)"
   1.101 +proof (intro cInf_eq_non_empty)
   1.102 +  fix y assume "\<And>x. x \<in> insert a X \<Longrightarrow> y \<le> x" with x show "y \<le> inf a (Inf X)" by (auto intro: cInf_greatest)
   1.103 +qed (auto intro: le_infI2 z cInf_lower)
   1.104 +
   1.105 +lemma cSup_insert_If: 
   1.106 +  "(\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup (insert a X) = (if X = {} then a else sup a (Sup X))"
   1.107 +  using cSup_insert[of X z] by simp
   1.108 +
   1.109 +lemma cInf_insert_if: 
   1.110 +  "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf (insert a X) = (if X = {} then a else inf a (Inf X))"
   1.111 +  using cInf_insert[of X z] by simp
   1.112 +
   1.113 +lemma le_cSup_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> x \<le> Sup X"
   1.114 +proof (induct X arbitrary: x rule: finite_induct)
   1.115 +  case (insert x X y) then show ?case
   1.116 +    apply (cases "X = {}")
   1.117 +    apply simp
   1.118 +    apply (subst cSup_insert[of _ "Sup X"])
   1.119 +    apply (auto intro: le_supI2)
   1.120 +    done
   1.121 +qed simp
   1.122 +
   1.123 +lemma cInf_le_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> Inf X \<le> x"
   1.124 +proof (induct X arbitrary: x rule: finite_induct)
   1.125 +  case (insert x X y) then show ?case
   1.126 +    apply (cases "X = {}")
   1.127 +    apply simp
   1.128 +    apply (subst cInf_insert[of _ "Inf X"])
   1.129 +    apply (auto intro: le_infI2)
   1.130 +    done
   1.131 +qed simp
   1.132 +
   1.133 +lemma cSup_eq_Sup_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Sup_fin X"
   1.134 +proof (induct X rule: finite_ne_induct)
   1.135 +  case (insert x X) then show ?case
   1.136 +    using cSup_insert[of X "Sup_fin X" x] le_cSup_finite[of X] by simp
   1.137 +qed simp
   1.138 +
   1.139 +lemma cInf_eq_Inf_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Inf_fin X"
   1.140 +proof (induct X rule: finite_ne_induct)
   1.141 +  case (insert x X) then show ?case
   1.142 +    using cInf_insert[of X "Inf_fin X" x] cInf_le_finite[of X] by simp
   1.143 +qed simp
   1.144 +
   1.145 +lemma cSup_atMost[simp]: "Sup {..x} = x"
   1.146 +  by (auto intro!: cSup_eq_maximum)
   1.147 +
   1.148 +lemma cSup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = x"
   1.149 +  by (auto intro!: cSup_eq_maximum)
   1.150 +
   1.151 +lemma cSup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = x"
   1.152 +  by (auto intro!: cSup_eq_maximum)
   1.153 +
   1.154 +lemma cInf_atLeast[simp]: "Inf {x..} = x"
   1.155 +  by (auto intro!: cInf_eq_minimum)
   1.156 +
   1.157 +lemma cInf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = y"
   1.158 +  by (auto intro!: cInf_eq_minimum)
   1.159 +
   1.160 +lemma cInf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = y"
   1.161 +  by (auto intro!: cInf_eq_minimum)
   1.162 +
   1.163 +end
   1.164 +
   1.165 +instance complete_lattice \<subseteq> conditionally_complete_lattice
   1.166 +  by default (auto intro: Sup_upper Sup_least Inf_lower Inf_greatest)
   1.167 +
   1.168 +lemma isLub_cSup: 
   1.169 +  "(S::'a :: conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> (\<exists>b. S *<= b) \<Longrightarrow> isLub UNIV S (Sup S)"
   1.170 +  by  (auto simp add: isLub_def setle_def leastP_def isUb_def
   1.171 +            intro!: setgeI intro: cSup_upper cSup_least)
   1.172 +
   1.173 +lemma cSup_eq:
   1.174 +  fixes a :: "'a :: {conditionally_complete_lattice, no_bot}"
   1.175 +  assumes upper: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
   1.176 +  assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
   1.177 +  shows "Sup X = a"
   1.178 +proof cases
   1.179 +  assume "X = {}" with lt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   1.180 +qed (intro cSup_eq_non_empty assms)
   1.181 +
   1.182 +lemma cInf_eq:
   1.183 +  fixes a :: "'a :: {conditionally_complete_lattice, no_top}"
   1.184 +  assumes upper: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
   1.185 +  assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
   1.186 +  shows "Inf X = a"
   1.187 +proof cases
   1.188 +  assume "X = {}" with gt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   1.189 +qed (intro cInf_eq_non_empty assms)
   1.190 +
   1.191 +lemma cSup_le: "(S::'a::conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> S *<= b \<Longrightarrow> Sup S \<le> b"
   1.192 +  by (metis cSup_least setle_def)
   1.193 +
   1.194 +lemma cInf_ge: "(S::'a :: conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> b <=* S \<Longrightarrow> Inf S \<ge> b"
   1.195 +  by (metis cInf_greatest setge_def)
   1.196 +
   1.197 +class conditionally_complete_linorder = conditionally_complete_lattice + linorder
   1.198 +begin
   1.199 +
   1.200 +lemma less_cSup_iff : (*REAL_SUP_LE in HOL4*)
   1.201 +  "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y < Sup X \<longleftrightarrow> (\<exists>x\<in>X. y < x)"
   1.202 +  by (rule iffI) (metis cSup_least not_less, metis cSup_upper less_le_trans)
   1.203 +
   1.204 +lemma cInf_less_iff: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X < y \<longleftrightarrow> (\<exists>x\<in>X. x < y)"
   1.205 +  by (rule iffI) (metis cInf_greatest not_less, metis cInf_lower le_less_trans)
   1.206 +
   1.207 +lemma less_cSupE:
   1.208 +  assumes "y < Sup X" "X \<noteq> {}" obtains x where "x \<in> X" "y < x"
   1.209 +  by (metis cSup_least assms not_le that)
   1.210 +
   1.211 +lemma less_cSupD:
   1.212 +  "X \<noteq> {} \<Longrightarrow> z < Sup X \<Longrightarrow> \<exists>x\<in>X. z < x"
   1.213 +  by (metis less_cSup_iff not_leE)
   1.214 +
   1.215 +lemma cInf_lessD:
   1.216 +  "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x\<in>X. x < z"
   1.217 +  by (metis cInf_less_iff not_leE)
   1.218 +
   1.219 +lemma complete_interval:
   1.220 +  assumes "a < b" and "P a" and "\<not> P b"
   1.221 +  shows "\<exists>c. a \<le> c \<and> c \<le> b \<and> (\<forall>x. a \<le> x \<and> x < c \<longrightarrow> P x) \<and>
   1.222 +             (\<forall>d. (\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x) \<longrightarrow> d \<le> c)"
   1.223 +proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
   1.224 +  show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   1.225 +    by (rule cSup_upper [where z=b], auto)
   1.226 +       (metis `a < b` `\<not> P b` linear less_le)
   1.227 +next
   1.228 +  show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
   1.229 +    apply (rule cSup_least) 
   1.230 +    apply auto
   1.231 +    apply (metis less_le_not_le)
   1.232 +    apply (metis `a<b` `~ P b` linear less_le)
   1.233 +    done
   1.234 +next
   1.235 +  fix x
   1.236 +  assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   1.237 +  show "P x"
   1.238 +    apply (rule less_cSupE [OF lt], auto)
   1.239 +    apply (metis less_le_not_le)
   1.240 +    apply (metis x) 
   1.241 +    done
   1.242 +next
   1.243 +  fix d
   1.244 +    assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
   1.245 +    thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   1.246 +      by (rule_tac z="b" in cSup_upper, auto) 
   1.247 +         (metis `a<b` `~ P b` linear less_le)
   1.248 +qed
   1.249 +
   1.250 +end
   1.251 +
   1.252 +lemma cSup_bounds:
   1.253 +  fixes S :: "'a :: conditionally_complete_lattice set"
   1.254 +  assumes Se: "S \<noteq> {}" and l: "a <=* S" and u: "S *<= b"
   1.255 +  shows "a \<le> Sup S \<and> Sup S \<le> b"
   1.256 +proof-
   1.257 +  from isLub_cSup[OF Se] u have lub: "isLub UNIV S (Sup S)" by blast
   1.258 +  hence b: "Sup S \<le> b" using u 
   1.259 +    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def) 
   1.260 +  from Se obtain y where y: "y \<in> S" by blast
   1.261 +  from lub l have "a \<le> Sup S"
   1.262 +    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def)
   1.263 +       (metis le_iff_sup le_sup_iff y)
   1.264 +  with b show ?thesis by blast
   1.265 +qed
   1.266 +
   1.267 +
   1.268 +lemma cSup_unique: "(S::'a :: {conditionally_complete_linorder, no_bot} set) *<= b \<Longrightarrow> (\<forall>b'<b. \<exists>x\<in>S. b' < x) \<Longrightarrow> Sup S = b"
   1.269 +  by (rule cSup_eq) (auto simp: not_le[symmetric] setle_def)
   1.270 +
   1.271 +lemma cInf_unique: "b <=* (S::'a :: {conditionally_complete_linorder, no_top} set) \<Longrightarrow> (\<forall>b'>b. \<exists>x\<in>S. b' > x) \<Longrightarrow> Inf S = b"
   1.272 +  by (rule cInf_eq) (auto simp: not_le[symmetric] setge_def)
   1.273 +
   1.274 +lemma cSup_eq_Max: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Max X"
   1.275 +  using cSup_eq_Sup_fin[of X] Sup_fin_eq_Max[of X] by simp
   1.276 +
   1.277 +lemma cInf_eq_Min: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Min X"
   1.278 +  using cInf_eq_Inf_fin[of X] Inf_fin_eq_Min[of X] by simp
   1.279 +
   1.280 +lemma cSup_lessThan[simp]: "Sup {..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
   1.281 +  by (auto intro!: cSup_eq_non_empty intro: dense_le)
   1.282 +
   1.283 +lemma cSup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
   1.284 +  by (auto intro!: cSup_eq intro: dense_le_bounded)
   1.285 +
   1.286 +lemma cSup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
   1.287 +  by (auto intro!: cSup_eq intro: dense_le_bounded)
   1.288 +
   1.289 +lemma cInf_greaterThan[simp]: "Inf {x::'a::{conditionally_complete_linorder, dense_linorder} <..} = x"
   1.290 +  by (auto intro!: cInf_eq intro: dense_ge)
   1.291 +
   1.292 +lemma cInf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x::'a::{conditionally_complete_linorder, dense_linorder}} = y"
   1.293 +  by (auto intro!: cInf_eq intro: dense_ge_bounded)
   1.294 +
   1.295 +lemma cInf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x::'a::{conditionally_complete_linorder, dense_linorder}} = y"
   1.296 +  by (auto intro!: cInf_eq intro: dense_ge_bounded)
   1.297 +
   1.298 +end