src/HOL/Conditionally_Complete_Lattices.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 62343 24106dc44def
child 62379 340738057c8c
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
     1 (*  Title:      HOL/Conditionally_Complete_Lattices.thy
     2     Author:     Amine Chaieb and L C Paulson, University of Cambridge
     3     Author:     Johannes Hölzl, TU München
     4     Author:     Luke S. Serafin, Carnegie Mellon University
     5 *)
     6 
     7 section \<open>Conditionally-complete Lattices\<close>
     8 
     9 theory Conditionally_Complete_Lattices
    10 imports Main
    11 begin
    12 
    13 lemma (in linorder) Sup_fin_eq_Max: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup_fin X = Max X"
    14   by (induct X rule: finite_ne_induct) (simp_all add: sup_max)
    15 
    16 lemma (in linorder) Inf_fin_eq_Min: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf_fin X = Min X"
    17   by (induct X rule: finite_ne_induct) (simp_all add: inf_min)
    18 
    19 context preorder
    20 begin
    21 
    22 definition "bdd_above A \<longleftrightarrow> (\<exists>M. \<forall>x \<in> A. x \<le> M)"
    23 definition "bdd_below A \<longleftrightarrow> (\<exists>m. \<forall>x \<in> A. m \<le> x)"
    24 
    25 lemma bdd_aboveI[intro]: "(\<And>x. x \<in> A \<Longrightarrow> x \<le> M) \<Longrightarrow> bdd_above A"
    26   by (auto simp: bdd_above_def)
    27 
    28 lemma bdd_belowI[intro]: "(\<And>x. x \<in> A \<Longrightarrow> m \<le> x) \<Longrightarrow> bdd_below A"
    29   by (auto simp: bdd_below_def)
    30 
    31 lemma bdd_aboveI2: "(\<And>x. x \<in> A \<Longrightarrow> f x \<le> M) \<Longrightarrow> bdd_above (f`A)"
    32   by force
    33 
    34 lemma bdd_belowI2: "(\<And>x. x \<in> A \<Longrightarrow> m \<le> f x) \<Longrightarrow> bdd_below (f`A)"
    35   by force
    36 
    37 lemma bdd_above_empty [simp, intro]: "bdd_above {}"
    38   unfolding bdd_above_def by auto
    39 
    40 lemma bdd_below_empty [simp, intro]: "bdd_below {}"
    41   unfolding bdd_below_def by auto
    42 
    43 lemma bdd_above_mono: "bdd_above B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> bdd_above A"
    44   by (metis (full_types) bdd_above_def order_class.le_neq_trans psubsetD)
    45 
    46 lemma bdd_below_mono: "bdd_below B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> bdd_below A"
    47   by (metis bdd_below_def order_class.le_neq_trans psubsetD)
    48 
    49 lemma bdd_above_Int1 [simp]: "bdd_above A \<Longrightarrow> bdd_above (A \<inter> B)"
    50   using bdd_above_mono by auto
    51 
    52 lemma bdd_above_Int2 [simp]: "bdd_above B \<Longrightarrow> bdd_above (A \<inter> B)"
    53   using bdd_above_mono by auto
    54 
    55 lemma bdd_below_Int1 [simp]: "bdd_below A \<Longrightarrow> bdd_below (A \<inter> B)"
    56   using bdd_below_mono by auto
    57 
    58 lemma bdd_below_Int2 [simp]: "bdd_below B \<Longrightarrow> bdd_below (A \<inter> B)"
    59   using bdd_below_mono by auto
    60 
    61 lemma bdd_above_Ioo [simp, intro]: "bdd_above {a <..< b}"
    62   by (auto simp add: bdd_above_def intro!: exI[of _ b] less_imp_le)
    63 
    64 lemma bdd_above_Ico [simp, intro]: "bdd_above {a ..< b}"
    65   by (auto simp add: bdd_above_def intro!: exI[of _ b] less_imp_le)
    66 
    67 lemma bdd_above_Iio [simp, intro]: "bdd_above {..< b}"
    68   by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
    69 
    70 lemma bdd_above_Ioc [simp, intro]: "bdd_above {a <.. b}"
    71   by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
    72 
    73 lemma bdd_above_Icc [simp, intro]: "bdd_above {a .. b}"
    74   by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
    75 
    76 lemma bdd_above_Iic [simp, intro]: "bdd_above {.. b}"
    77   by (auto simp add: bdd_above_def intro: exI[of _ b] less_imp_le)
    78 
    79 lemma bdd_below_Ioo [simp, intro]: "bdd_below {a <..< b}"
    80   by (auto simp add: bdd_below_def intro!: exI[of _ a] less_imp_le)
    81 
    82 lemma bdd_below_Ioc [simp, intro]: "bdd_below {a <.. b}"
    83   by (auto simp add: bdd_below_def intro!: exI[of _ a] less_imp_le)
    84 
    85 lemma bdd_below_Ioi [simp, intro]: "bdd_below {a <..}"
    86   by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
    87 
    88 lemma bdd_below_Ico [simp, intro]: "bdd_below {a ..< b}"
    89   by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
    90 
    91 lemma bdd_below_Icc [simp, intro]: "bdd_below {a .. b}"
    92   by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
    93 
    94 lemma bdd_below_Ici [simp, intro]: "bdd_below {a ..}"
    95   by (auto simp add: bdd_below_def intro: exI[of _ a] less_imp_le)
    96 
    97 end
    98 
    99 lemma (in order_top) bdd_above_top[simp, intro!]: "bdd_above A"
   100   by (rule bdd_aboveI[of _ top]) simp
   101 
   102 lemma (in order_bot) bdd_above_bot[simp, intro!]: "bdd_below A"
   103   by (rule bdd_belowI[of _ bot]) simp
   104 
   105 lemma bdd_above_image_mono: "mono f \<Longrightarrow> bdd_above A \<Longrightarrow> bdd_above (f`A)"
   106   by (auto simp: bdd_above_def mono_def)
   107 
   108 lemma bdd_below_image_mono: "mono f \<Longrightarrow> bdd_below A \<Longrightarrow> bdd_below (f`A)"
   109   by (auto simp: bdd_below_def mono_def)
   110   
   111 lemma bdd_above_image_antimono: "antimono f \<Longrightarrow> bdd_below A \<Longrightarrow> bdd_above (f`A)"
   112   by (auto simp: bdd_above_def bdd_below_def antimono_def)
   113 
   114 lemma bdd_below_image_antimono: "antimono f \<Longrightarrow> bdd_above A \<Longrightarrow> bdd_below (f`A)"
   115   by (auto simp: bdd_above_def bdd_below_def antimono_def)
   116 
   117 lemma
   118   fixes X :: "'a::ordered_ab_group_add set"
   119   shows bdd_above_uminus[simp]: "bdd_above (uminus ` X) \<longleftrightarrow> bdd_below X"
   120     and bdd_below_uminus[simp]: "bdd_below (uminus ` X) \<longleftrightarrow> bdd_above X"
   121   using bdd_above_image_antimono[of uminus X] bdd_below_image_antimono[of uminus "uminus`X"]
   122   using bdd_below_image_antimono[of uminus X] bdd_above_image_antimono[of uminus "uminus`X"]
   123   by (auto simp: antimono_def image_image)
   124 
   125 context lattice
   126 begin
   127 
   128 lemma bdd_above_insert [simp]: "bdd_above (insert a A) = bdd_above A"
   129   by (auto simp: bdd_above_def intro: le_supI2 sup_ge1)
   130 
   131 lemma bdd_below_insert [simp]: "bdd_below (insert a A) = bdd_below A"
   132   by (auto simp: bdd_below_def intro: le_infI2 inf_le1)
   133 
   134 lemma bdd_finite [simp]:
   135   assumes "finite A" shows bdd_above_finite: "bdd_above A" and bdd_below_finite: "bdd_below A"
   136   using assms by (induct rule: finite_induct, auto)
   137 
   138 lemma bdd_above_Un [simp]: "bdd_above (A \<union> B) = (bdd_above A \<and> bdd_above B)"
   139 proof
   140   assume "bdd_above (A \<union> B)"
   141   thus "bdd_above A \<and> bdd_above B" unfolding bdd_above_def by auto
   142 next
   143   assume "bdd_above A \<and> bdd_above B"
   144   then obtain a b where "\<forall>x\<in>A. x \<le> a" "\<forall>x\<in>B. x \<le> b" unfolding bdd_above_def by auto
   145   hence "\<forall>x \<in> A \<union> B. x \<le> sup a b" by (auto intro: Un_iff le_supI1 le_supI2)
   146   thus "bdd_above (A \<union> B)" unfolding bdd_above_def ..
   147 qed
   148 
   149 lemma bdd_below_Un [simp]: "bdd_below (A \<union> B) = (bdd_below A \<and> bdd_below B)"
   150 proof
   151   assume "bdd_below (A \<union> B)"
   152   thus "bdd_below A \<and> bdd_below B" unfolding bdd_below_def by auto
   153 next
   154   assume "bdd_below A \<and> bdd_below B"
   155   then obtain a b where "\<forall>x\<in>A. a \<le> x" "\<forall>x\<in>B. b \<le> x" unfolding bdd_below_def by auto
   156   hence "\<forall>x \<in> A \<union> B. inf a b \<le> x" by (auto intro: Un_iff le_infI1 le_infI2)
   157   thus "bdd_below (A \<union> B)" unfolding bdd_below_def ..
   158 qed
   159 
   160 lemma bdd_above_sup[simp]: "bdd_above ((\<lambda>x. sup (f x) (g x)) ` A) \<longleftrightarrow> bdd_above (f`A) \<and> bdd_above (g`A)"
   161   by (auto simp: bdd_above_def intro: le_supI1 le_supI2)
   162 
   163 lemma bdd_below_inf[simp]: "bdd_below ((\<lambda>x. inf (f x) (g x)) ` A) \<longleftrightarrow> bdd_below (f`A) \<and> bdd_below (g`A)"
   164   by (auto simp: bdd_below_def intro: le_infI1 le_infI2)
   165 
   166 end
   167 
   168 
   169 text \<open>
   170 
   171 To avoid name classes with the @{class complete_lattice}-class we prefix @{const Sup} and
   172 @{const Inf} in theorem names with c.
   173 
   174 \<close>
   175 
   176 class conditionally_complete_lattice = lattice + Sup + Inf +
   177   assumes cInf_lower: "x \<in> X \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X \<le> x"
   178     and cInf_greatest: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> z \<le> Inf X"
   179   assumes cSup_upper: "x \<in> X \<Longrightarrow> bdd_above X \<Longrightarrow> x \<le> Sup X"
   180     and cSup_least: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X \<le> z"
   181 begin
   182 
   183 lemma cSup_upper2: "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> bdd_above X \<Longrightarrow> y \<le> Sup X"
   184   by (metis cSup_upper order_trans)
   185 
   186 lemma cInf_lower2: "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X \<le> y"
   187   by (metis cInf_lower order_trans)
   188 
   189 lemma cSup_mono: "B \<noteq> {} \<Longrightarrow> bdd_above A \<Longrightarrow> (\<And>b. b \<in> B \<Longrightarrow> \<exists>a\<in>A. b \<le> a) \<Longrightarrow> Sup B \<le> Sup A"
   190   by (metis cSup_least cSup_upper2)
   191 
   192 lemma cInf_mono: "B \<noteq> {} \<Longrightarrow> bdd_below A \<Longrightarrow> (\<And>b. b \<in> B \<Longrightarrow> \<exists>a\<in>A. a \<le> b) \<Longrightarrow> Inf A \<le> Inf B"
   193   by (metis cInf_greatest cInf_lower2)
   194 
   195 lemma cSup_subset_mono: "A \<noteq> {} \<Longrightarrow> bdd_above B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Sup A \<le> Sup B"
   196   by (metis cSup_least cSup_upper subsetD)
   197 
   198 lemma cInf_superset_mono: "A \<noteq> {} \<Longrightarrow> bdd_below B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Inf B \<le> Inf A"
   199   by (metis cInf_greatest cInf_lower subsetD)
   200 
   201 lemma cSup_eq_maximum: "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X = z"
   202   by (intro antisym cSup_upper[of z X] cSup_least[of X z]) auto
   203 
   204 lemma cInf_eq_minimum: "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X = z"
   205   by (intro antisym cInf_lower[of z X] cInf_greatest[of X z]) auto
   206 
   207 lemma cSup_le_iff: "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> Sup S \<le> a \<longleftrightarrow> (\<forall>x\<in>S. x \<le> a)"
   208   by (metis order_trans cSup_upper cSup_least)
   209 
   210 lemma le_cInf_iff: "S \<noteq> {} \<Longrightarrow> bdd_below S \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall>x\<in>S. a \<le> x)"
   211   by (metis order_trans cInf_lower cInf_greatest)
   212 
   213 lemma cSup_eq_non_empty:
   214   assumes 1: "X \<noteq> {}"
   215   assumes 2: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
   216   assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
   217   shows "Sup X = a"
   218   by (intro 3 1 antisym cSup_least) (auto intro: 2 1 cSup_upper)
   219 
   220 lemma cInf_eq_non_empty:
   221   assumes 1: "X \<noteq> {}"
   222   assumes 2: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
   223   assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
   224   shows "Inf X = a"
   225   by (intro 3 1 antisym cInf_greatest) (auto intro: 2 1 cInf_lower)
   226 
   227 lemma cInf_cSup: "S \<noteq> {} \<Longrightarrow> bdd_below S \<Longrightarrow> Inf S = Sup {x. \<forall>s\<in>S. x \<le> s}"
   228   by (rule cInf_eq_non_empty) (auto intro!: cSup_upper cSup_least simp: bdd_below_def)
   229 
   230 lemma cSup_cInf: "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> Sup S = Inf {x. \<forall>s\<in>S. s \<le> x}"
   231   by (rule cSup_eq_non_empty) (auto intro!: cInf_lower cInf_greatest simp: bdd_above_def)
   232 
   233 lemma cSup_insert: "X \<noteq> {} \<Longrightarrow> bdd_above X \<Longrightarrow> Sup (insert a X) = sup a (Sup X)"
   234   by (intro cSup_eq_non_empty) (auto intro: le_supI2 cSup_upper cSup_least)
   235 
   236 lemma cInf_insert: "X \<noteq> {} \<Longrightarrow> bdd_below X \<Longrightarrow> Inf (insert a X) = inf a (Inf X)"
   237   by (intro cInf_eq_non_empty) (auto intro: le_infI2 cInf_lower cInf_greatest)
   238 
   239 lemma cSup_singleton [simp]: "Sup {x} = x"
   240   by (intro cSup_eq_maximum) auto
   241 
   242 lemma cInf_singleton [simp]: "Inf {x} = x"
   243   by (intro cInf_eq_minimum) auto
   244 
   245 lemma cSup_insert_If:  "bdd_above X \<Longrightarrow> Sup (insert a X) = (if X = {} then a else sup a (Sup X))"
   246   using cSup_insert[of X] by simp
   247 
   248 lemma cInf_insert_If: "bdd_below X \<Longrightarrow> Inf (insert a X) = (if X = {} then a else inf a (Inf X))"
   249   using cInf_insert[of X] by simp
   250 
   251 lemma le_cSup_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> x \<le> Sup X"
   252 proof (induct X arbitrary: x rule: finite_induct)
   253   case (insert x X y) then show ?case
   254     by (cases "X = {}") (auto simp: cSup_insert intro: le_supI2)
   255 qed simp
   256 
   257 lemma cInf_le_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> Inf X \<le> x"
   258 proof (induct X arbitrary: x rule: finite_induct)
   259   case (insert x X y) then show ?case
   260     by (cases "X = {}") (auto simp: cInf_insert intro: le_infI2)
   261 qed simp
   262 
   263 lemma cSup_eq_Sup_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Sup_fin X"
   264   by (induct X rule: finite_ne_induct) (simp_all add: cSup_insert)
   265 
   266 lemma cInf_eq_Inf_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Inf_fin X"
   267   by (induct X rule: finite_ne_induct) (simp_all add: cInf_insert)
   268 
   269 lemma cSup_atMost[simp]: "Sup {..x} = x"
   270   by (auto intro!: cSup_eq_maximum)
   271 
   272 lemma cSup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = x"
   273   by (auto intro!: cSup_eq_maximum)
   274 
   275 lemma cSup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = x"
   276   by (auto intro!: cSup_eq_maximum)
   277 
   278 lemma cInf_atLeast[simp]: "Inf {x..} = x"
   279   by (auto intro!: cInf_eq_minimum)
   280 
   281 lemma cInf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = y"
   282   by (auto intro!: cInf_eq_minimum)
   283 
   284 lemma cInf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = y"
   285   by (auto intro!: cInf_eq_minimum)
   286 
   287 lemma cINF_lower: "bdd_below (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> INFIMUM A f \<le> f x"
   288   using cInf_lower [of _ "f ` A"] by simp
   289 
   290 lemma cINF_greatest: "A \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> m \<le> f x) \<Longrightarrow> m \<le> INFIMUM A f"
   291   using cInf_greatest [of "f ` A"] by auto
   292 
   293 lemma cSUP_upper: "x \<in> A \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> f x \<le> SUPREMUM A f"
   294   using cSup_upper [of _ "f ` A"] by simp
   295 
   296 lemma cSUP_least: "A \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<le> M) \<Longrightarrow> SUPREMUM A f \<le> M"
   297   using cSup_least [of "f ` A"] by auto
   298 
   299 lemma cINF_lower2: "bdd_below (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> f x \<le> u \<Longrightarrow> INFIMUM A f \<le> u"
   300   by (auto intro: cINF_lower assms order_trans)
   301 
   302 lemma cSUP_upper2: "bdd_above (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> u \<le> f x \<Longrightarrow> u \<le> SUPREMUM A f"
   303   by (auto intro: cSUP_upper assms order_trans)
   304 
   305 lemma cSUP_const [simp]: "A \<noteq> {} \<Longrightarrow> (SUP x:A. c) = c"
   306   by (intro antisym cSUP_least) (auto intro: cSUP_upper)
   307 
   308 lemma cINF_const [simp]: "A \<noteq> {} \<Longrightarrow> (INF x:A. c) = c"
   309   by (intro antisym cINF_greatest) (auto intro: cINF_lower)
   310 
   311 lemma le_cINF_iff: "A \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> u \<le> INFIMUM A f \<longleftrightarrow> (\<forall>x\<in>A. u \<le> f x)"
   312   by (metis cINF_greatest cINF_lower assms order_trans)
   313 
   314 lemma cSUP_le_iff: "A \<noteq> {} \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> SUPREMUM A f \<le> u \<longleftrightarrow> (\<forall>x\<in>A. f x \<le> u)"
   315   by (metis cSUP_least cSUP_upper assms order_trans)
   316 
   317 lemma less_cINF_D: "bdd_below (f`A) \<Longrightarrow> y < (INF i:A. f i) \<Longrightarrow> i \<in> A \<Longrightarrow> y < f i"
   318   by (metis cINF_lower less_le_trans)
   319 
   320 lemma cSUP_lessD: "bdd_above (f`A) \<Longrightarrow> (SUP i:A. f i) < y \<Longrightarrow> i \<in> A \<Longrightarrow> f i < y"
   321   by (metis cSUP_upper le_less_trans)
   322 
   323 lemma cINF_insert: "A \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> INFIMUM (insert a A) f = inf (f a) (INFIMUM A f)"
   324   by (metis cInf_insert image_insert image_is_empty)
   325 
   326 lemma cSUP_insert: "A \<noteq> {} \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> SUPREMUM (insert a A) f = sup (f a) (SUPREMUM A f)"
   327   by (metis cSup_insert image_insert image_is_empty)
   328 
   329 lemma cINF_mono: "B \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> (\<And>m. m \<in> B \<Longrightarrow> \<exists>n\<in>A. f n \<le> g m) \<Longrightarrow> INFIMUM A f \<le> INFIMUM B g"
   330   using cInf_mono [of "g ` B" "f ` A"] by auto
   331 
   332 lemma cSUP_mono: "A \<noteq> {} \<Longrightarrow> bdd_above (g ` B) \<Longrightarrow> (\<And>n. n \<in> A \<Longrightarrow> \<exists>m\<in>B. f n \<le> g m) \<Longrightarrow> SUPREMUM A f \<le> SUPREMUM B g"
   333   using cSup_mono [of "f ` A" "g ` B"] by auto
   334 
   335 lemma cINF_superset_mono: "A \<noteq> {} \<Longrightarrow> bdd_below (g ` B) \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> g x \<le> f x) \<Longrightarrow> INFIMUM B g \<le> INFIMUM A f"
   336   by (rule cINF_mono) auto
   337 
   338 lemma cSUP_subset_mono: "A \<noteq> {} \<Longrightarrow> bdd_above (g ` B) \<Longrightarrow> A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> f x \<le> g x) \<Longrightarrow> SUPREMUM A f \<le> SUPREMUM B g"
   339   by (rule cSUP_mono) auto
   340 
   341 lemma less_eq_cInf_inter: "bdd_below A \<Longrightarrow> bdd_below B \<Longrightarrow> A \<inter> B \<noteq> {} \<Longrightarrow> inf (Inf A) (Inf B) \<le> Inf (A \<inter> B)"
   342   by (metis cInf_superset_mono lattice_class.inf_sup_ord(1) le_infI1)
   343 
   344 lemma cSup_inter_less_eq: "bdd_above A \<Longrightarrow> bdd_above B \<Longrightarrow> A \<inter> B \<noteq> {} \<Longrightarrow> Sup (A \<inter> B) \<le> sup (Sup A) (Sup B) "
   345   by (metis cSup_subset_mono lattice_class.inf_sup_ord(1) le_supI1)
   346 
   347 lemma cInf_union_distrib: "A \<noteq> {} \<Longrightarrow> bdd_below A \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_below B \<Longrightarrow> Inf (A \<union> B) = inf (Inf A) (Inf B)"
   348   by (intro antisym le_infI cInf_greatest cInf_lower) (auto intro: le_infI1 le_infI2 cInf_lower)
   349 
   350 lemma cINF_union: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_below (f`B) \<Longrightarrow> INFIMUM (A \<union> B) f = inf (INFIMUM A f) (INFIMUM B f)"
   351   using cInf_union_distrib [of "f ` A" "f ` B"] by (simp add: image_Un [symmetric])
   352 
   353 lemma cSup_union_distrib: "A \<noteq> {} \<Longrightarrow> bdd_above A \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_above B \<Longrightarrow> Sup (A \<union> B) = sup (Sup A) (Sup B)"
   354   by (intro antisym le_supI cSup_least cSup_upper) (auto intro: le_supI1 le_supI2 cSup_upper)
   355 
   356 lemma cSUP_union: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_above (f`B) \<Longrightarrow> SUPREMUM (A \<union> B) f = sup (SUPREMUM A f) (SUPREMUM B f)"
   357   using cSup_union_distrib [of "f ` A" "f ` B"] by (simp add: image_Un [symmetric])
   358 
   359 lemma cINF_inf_distrib: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> bdd_below (g`A) \<Longrightarrow> inf (INFIMUM A f) (INFIMUM A g) = (INF a:A. inf (f a) (g a))"
   360   by (intro antisym le_infI cINF_greatest cINF_lower2)
   361      (auto intro: le_infI1 le_infI2 cINF_greatest cINF_lower le_infI)
   362 
   363 lemma SUP_sup_distrib: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> bdd_above (g`A) \<Longrightarrow> sup (SUPREMUM A f) (SUPREMUM A g) = (SUP a:A. sup (f a) (g a))"
   364   by (intro antisym le_supI cSUP_least cSUP_upper2)
   365      (auto intro: le_supI1 le_supI2 cSUP_least cSUP_upper le_supI)
   366 
   367 lemma cInf_le_cSup:
   368   "A \<noteq> {} \<Longrightarrow> bdd_above A \<Longrightarrow> bdd_below A \<Longrightarrow> Inf A \<le> Sup A"
   369   by (auto intro!: cSup_upper2[of "SOME a. a \<in> A"] intro: someI cInf_lower)
   370 
   371 end
   372 
   373 instance complete_lattice \<subseteq> conditionally_complete_lattice
   374   by standard (auto intro: Sup_upper Sup_least Inf_lower Inf_greatest)
   375 
   376 lemma cSup_eq:
   377   fixes a :: "'a :: {conditionally_complete_lattice, no_bot}"
   378   assumes upper: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
   379   assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
   380   shows "Sup X = a"
   381 proof cases
   382   assume "X = {}" with lt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   383 qed (intro cSup_eq_non_empty assms)
   384 
   385 lemma cInf_eq:
   386   fixes a :: "'a :: {conditionally_complete_lattice, no_top}"
   387   assumes upper: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
   388   assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
   389   shows "Inf X = a"
   390 proof cases
   391   assume "X = {}" with gt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   392 qed (intro cInf_eq_non_empty assms)
   393 
   394 class conditionally_complete_linorder = conditionally_complete_lattice + linorder
   395 begin
   396 
   397 lemma less_cSup_iff : (*REAL_SUP_LE in HOL4*)
   398   "X \<noteq> {} \<Longrightarrow> bdd_above X \<Longrightarrow> y < Sup X \<longleftrightarrow> (\<exists>x\<in>X. y < x)"
   399   by (rule iffI) (metis cSup_least not_less, metis cSup_upper less_le_trans)
   400 
   401 lemma cInf_less_iff: "X \<noteq> {} \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X < y \<longleftrightarrow> (\<exists>x\<in>X. x < y)"
   402   by (rule iffI) (metis cInf_greatest not_less, metis cInf_lower le_less_trans)
   403 
   404 lemma cINF_less_iff: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> (INF i:A. f i) < a \<longleftrightarrow> (\<exists>x\<in>A. f x < a)"
   405   using cInf_less_iff[of "f`A"] by auto
   406 
   407 lemma less_cSUP_iff: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> a < (SUP i:A. f i) \<longleftrightarrow> (\<exists>x\<in>A. a < f x)"
   408   using less_cSup_iff[of "f`A"] by auto
   409 
   410 lemma less_cSupE:
   411   assumes "y < Sup X" "X \<noteq> {}" obtains x where "x \<in> X" "y < x"
   412   by (metis cSup_least assms not_le that)
   413 
   414 lemma less_cSupD:
   415   "X \<noteq> {} \<Longrightarrow> z < Sup X \<Longrightarrow> \<exists>x\<in>X. z < x"
   416   by (metis less_cSup_iff not_le_imp_less bdd_above_def)
   417 
   418 lemma cInf_lessD:
   419   "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x\<in>X. x < z"
   420   by (metis cInf_less_iff not_le_imp_less bdd_below_def)
   421 
   422 lemma complete_interval:
   423   assumes "a < b" and "P a" and "\<not> P b"
   424   shows "\<exists>c. a \<le> c \<and> c \<le> b \<and> (\<forall>x. a \<le> x \<and> x < c \<longrightarrow> P x) \<and>
   425              (\<forall>d. (\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x) \<longrightarrow> d \<le> c)"
   426 proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
   427   show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   428     by (rule cSup_upper, auto simp: bdd_above_def)
   429        (metis \<open>a < b\<close> \<open>\<not> P b\<close> linear less_le)
   430 next
   431   show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
   432     apply (rule cSup_least) 
   433     apply auto
   434     apply (metis less_le_not_le)
   435     apply (metis \<open>a<b\<close> \<open>~ P b\<close> linear less_le)
   436     done
   437 next
   438   fix x
   439   assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   440   show "P x"
   441     apply (rule less_cSupE [OF lt], auto)
   442     apply (metis less_le_not_le)
   443     apply (metis x) 
   444     done
   445 next
   446   fix d
   447     assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
   448     thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   449       by (rule_tac cSup_upper, auto simp: bdd_above_def)
   450          (metis \<open>a<b\<close> \<open>~ P b\<close> linear less_le)
   451 qed
   452 
   453 end
   454 
   455 instance complete_linorder < conditionally_complete_linorder
   456   ..
   457 
   458 lemma cSup_eq_Max: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Max X"
   459   using cSup_eq_Sup_fin[of X] Sup_fin_eq_Max[of X] by simp
   460 
   461 lemma cInf_eq_Min: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Min X"
   462   using cInf_eq_Inf_fin[of X] Inf_fin_eq_Min[of X] by simp
   463 
   464 lemma cSup_lessThan[simp]: "Sup {..<x::'a::{conditionally_complete_linorder, no_bot, dense_linorder}} = x"
   465   by (auto intro!: cSup_eq_non_empty intro: dense_le)
   466 
   467 lemma cSup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
   468   by (auto intro!: cSup_eq_non_empty intro: dense_le_bounded)
   469 
   470 lemma cSup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x::'a::{conditionally_complete_linorder, dense_linorder}} = x"
   471   by (auto intro!: cSup_eq_non_empty intro: dense_le_bounded)
   472 
   473 lemma cInf_greaterThan[simp]: "Inf {x::'a::{conditionally_complete_linorder, no_top, dense_linorder} <..} = x"
   474   by (auto intro!: cInf_eq_non_empty intro: dense_ge)
   475 
   476 lemma cInf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x::'a::{conditionally_complete_linorder, dense_linorder}} = y"
   477   by (auto intro!: cInf_eq_non_empty intro: dense_ge_bounded)
   478 
   479 lemma cInf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x::'a::{conditionally_complete_linorder, dense_linorder}} = y"
   480   by (auto intro!: cInf_eq_non_empty intro: dense_ge_bounded)
   481 
   482 class linear_continuum = conditionally_complete_linorder + dense_linorder +
   483   assumes UNIV_not_singleton: "\<exists>a b::'a. a \<noteq> b"
   484 begin
   485 
   486 lemma ex_gt_or_lt: "\<exists>b. a < b \<or> b < a"
   487   by (metis UNIV_not_singleton neq_iff)
   488 
   489 end
   490 
   491 instantiation nat :: conditionally_complete_linorder
   492 begin
   493 
   494 definition "Sup (X::nat set) = Max X"
   495 definition "Inf (X::nat set) = (LEAST n. n \<in> X)"
   496 
   497 lemma bdd_above_nat: "bdd_above X \<longleftrightarrow> finite (X::nat set)"
   498 proof
   499   assume "bdd_above X"
   500   then obtain z where "X \<subseteq> {.. z}"
   501     by (auto simp: bdd_above_def)
   502   then show "finite X"
   503     by (rule finite_subset) simp
   504 qed simp
   505 
   506 instance
   507 proof
   508   fix x :: nat and X :: "nat set"
   509   { assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
   510       by (simp add: Inf_nat_def Least_le) }
   511   { assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y" then show "x \<le> Inf X"
   512       unfolding Inf_nat_def ex_in_conv[symmetric] by (rule LeastI2_ex) }
   513   { assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
   514       by (simp add: Sup_nat_def bdd_above_nat) }
   515   { assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x" 
   516     moreover then have "bdd_above X"
   517       by (auto simp: bdd_above_def)
   518     ultimately show "Sup X \<le> x"
   519       by (simp add: Sup_nat_def bdd_above_nat) }
   520 qed
   521 end
   522 
   523 instantiation int :: conditionally_complete_linorder
   524 begin
   525 
   526 definition "Sup (X::int set) = (THE x. x \<in> X \<and> (\<forall>y\<in>X. y \<le> x))"
   527 definition "Inf (X::int set) = - (Sup (uminus ` X))"
   528 
   529 instance
   530 proof
   531   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "bdd_above X"
   532     then obtain x y where "X \<subseteq> {..y}" "x \<in> X"
   533       by (auto simp: bdd_above_def)
   534     then have *: "finite (X \<inter> {x..y})" "X \<inter> {x..y} \<noteq> {}" and "x \<le> y"
   535       by (auto simp: subset_eq)
   536     have "\<exists>!x\<in>X. (\<forall>y\<in>X. y \<le> x)"
   537     proof
   538       { fix z assume "z \<in> X"
   539         have "z \<le> Max (X \<inter> {x..y})"
   540         proof cases
   541           assume "x \<le> z" with \<open>z \<in> X\<close> \<open>X \<subseteq> {..y}\<close> *(1) show ?thesis
   542             by (auto intro!: Max_ge)
   543         next
   544           assume "\<not> x \<le> z"
   545           then have "z < x" by simp
   546           also have "x \<le> Max (X \<inter> {x..y})"
   547             using \<open>x \<in> X\<close> *(1) \<open>x \<le> y\<close> by (intro Max_ge) auto
   548           finally show ?thesis by simp
   549         qed }
   550       note le = this
   551       with Max_in[OF *] show ex: "Max (X \<inter> {x..y}) \<in> X \<and> (\<forall>z\<in>X. z \<le> Max (X \<inter> {x..y}))" by auto
   552 
   553       fix z assume *: "z \<in> X \<and> (\<forall>y\<in>X. y \<le> z)"
   554       with le have "z \<le> Max (X \<inter> {x..y})"
   555         by auto
   556       moreover have "Max (X \<inter> {x..y}) \<le> z"
   557         using * ex by auto
   558       ultimately show "z = Max (X \<inter> {x..y})"
   559         by auto
   560     qed
   561     then have "Sup X \<in> X \<and> (\<forall>y\<in>X. y \<le> Sup X)"
   562       unfolding Sup_int_def by (rule theI') }
   563   note Sup_int = this
   564 
   565   { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
   566       using Sup_int[of X] by auto }
   567   note le_Sup = this
   568   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x" then show "Sup X \<le> x"
   569       using Sup_int[of X] by (auto simp: bdd_above_def) }
   570   note Sup_le = this
   571 
   572   { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
   573       using le_Sup[of "-x" "uminus ` X"] by (auto simp: Inf_int_def) }
   574   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y" then show "x \<le> Inf X"
   575       using Sup_le[of "uminus ` X" "-x"] by (force simp: Inf_int_def) }
   576 qed
   577 end
   578 
   579 lemma interval_cases:
   580   fixes S :: "'a :: conditionally_complete_linorder set"
   581   assumes ivl: "\<And>a b x. a \<in> S \<Longrightarrow> b \<in> S \<Longrightarrow> a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> x \<in> S"
   582   shows "\<exists>a b. S = {} \<or>
   583     S = UNIV \<or>
   584     S = {..<b} \<or>
   585     S = {..b} \<or>
   586     S = {a<..} \<or>
   587     S = {a..} \<or>
   588     S = {a<..<b} \<or>
   589     S = {a<..b} \<or>
   590     S = {a..<b} \<or>
   591     S = {a..b}"
   592 proof -
   593   def lower \<equiv> "{x. \<exists>s\<in>S. s \<le> x}" and upper \<equiv> "{x. \<exists>s\<in>S. x \<le> s}"
   594   with ivl have "S = lower \<inter> upper"
   595     by auto
   596   moreover 
   597   have "\<exists>a. upper = UNIV \<or> upper = {} \<or> upper = {.. a} \<or> upper = {..< a}"
   598   proof cases
   599     assume *: "bdd_above S \<and> S \<noteq> {}"
   600     from * have "upper \<subseteq> {.. Sup S}"
   601       by (auto simp: upper_def intro: cSup_upper2)
   602     moreover from * have "{..< Sup S} \<subseteq> upper"
   603       by (force simp add: less_cSup_iff upper_def subset_eq Ball_def)
   604     ultimately have "upper = {.. Sup S} \<or> upper = {..< Sup S}"
   605       unfolding ivl_disj_un(2)[symmetric] by auto
   606     then show ?thesis by auto
   607   next
   608     assume "\<not> (bdd_above S \<and> S \<noteq> {})"
   609     then have "upper = UNIV \<or> upper = {}"
   610       by (auto simp: upper_def bdd_above_def not_le dest: less_imp_le)
   611     then show ?thesis
   612       by auto
   613   qed
   614   moreover
   615   have "\<exists>b. lower = UNIV \<or> lower = {} \<or> lower = {b ..} \<or> lower = {b <..}"
   616   proof cases
   617     assume *: "bdd_below S \<and> S \<noteq> {}"
   618     from * have "lower \<subseteq> {Inf S ..}"
   619       by (auto simp: lower_def intro: cInf_lower2)
   620     moreover from * have "{Inf S <..} \<subseteq> lower"
   621       by (force simp add: cInf_less_iff lower_def subset_eq Ball_def)
   622     ultimately have "lower = {Inf S ..} \<or> lower = {Inf S <..}"
   623       unfolding ivl_disj_un(1)[symmetric] by auto
   624     then show ?thesis by auto
   625   next
   626     assume "\<not> (bdd_below S \<and> S \<noteq> {})"
   627     then have "lower = UNIV \<or> lower = {}"
   628       by (auto simp: lower_def bdd_below_def not_le dest: less_imp_le)
   629     then show ?thesis
   630       by auto
   631   qed
   632   ultimately show ?thesis
   633     unfolding greaterThanAtMost_def greaterThanLessThan_def atLeastAtMost_def atLeastLessThan_def
   634     by (elim exE disjE) auto
   635 qed
   636 
   637 lemma cSUP_eq_cINF_D:
   638   fixes f :: "_ \<Rightarrow> 'b::conditionally_complete_lattice"
   639   assumes eq: "(SUP x:A. f x) = (INF x:A. f x)"
   640      and bdd: "bdd_above (f ` A)" "bdd_below (f ` A)"
   641      and a: "a \<in> A"
   642   shows "f a = (INF x:A. f x)"
   643 apply (rule antisym)
   644 using a bdd
   645 apply (auto simp: cINF_lower)
   646 apply (metis eq cSUP_upper)
   647 done 
   648 
   649 end