src/HOL/Conditionally_Complete_Lattices.thy
author haftmann
Sun Mar 16 18:09:04 2014 +0100 (2014-03-16)
changeset 56166 9a241bc276cd
parent 54281 b01057e72233
child 56218 1c3f1f2431f9
permissions -rw-r--r--
normalising simp rules for compound operators
     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 header {* Conditionally-complete Lattices *}
     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_uminus[simp]:
   106   fixes X :: "'a::ordered_ab_group_add set"
   107   shows "bdd_above (uminus ` X) \<longleftrightarrow> bdd_below X"
   108   by (auto simp: bdd_above_def bdd_below_def intro: le_imp_neg_le) (metis le_imp_neg_le minus_minus)
   109 
   110 lemma bdd_below_uminus[simp]:
   111   fixes X :: "'a::ordered_ab_group_add set"
   112   shows"bdd_below (uminus ` X) \<longleftrightarrow> bdd_above X"
   113   by (auto simp: bdd_above_def bdd_below_def intro: le_imp_neg_le) (metis le_imp_neg_le minus_minus)
   114 
   115 context lattice
   116 begin
   117 
   118 lemma bdd_above_insert [simp]: "bdd_above (insert a A) = bdd_above A"
   119   by (auto simp: bdd_above_def intro: le_supI2 sup_ge1)
   120 
   121 lemma bdd_below_insert [simp]: "bdd_below (insert a A) = bdd_below A"
   122   by (auto simp: bdd_below_def intro: le_infI2 inf_le1)
   123 
   124 lemma bdd_finite [simp]:
   125   assumes "finite A" shows bdd_above_finite: "bdd_above A" and bdd_below_finite: "bdd_below A"
   126   using assms by (induct rule: finite_induct, auto)
   127 
   128 lemma bdd_above_Un [simp]: "bdd_above (A \<union> B) = (bdd_above A \<and> bdd_above B)"
   129 proof
   130   assume "bdd_above (A \<union> B)"
   131   thus "bdd_above A \<and> bdd_above B" unfolding bdd_above_def by auto
   132 next
   133   assume "bdd_above A \<and> bdd_above B"
   134   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
   135   hence "\<forall>x \<in> A \<union> B. x \<le> sup a b" by (auto intro: Un_iff le_supI1 le_supI2)
   136   thus "bdd_above (A \<union> B)" unfolding bdd_above_def ..
   137 qed
   138 
   139 lemma bdd_below_Un [simp]: "bdd_below (A \<union> B) = (bdd_below A \<and> bdd_below B)"
   140 proof
   141   assume "bdd_below (A \<union> B)"
   142   thus "bdd_below A \<and> bdd_below B" unfolding bdd_below_def by auto
   143 next
   144   assume "bdd_below A \<and> bdd_below B"
   145   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
   146   hence "\<forall>x \<in> A \<union> B. inf a b \<le> x" by (auto intro: Un_iff le_infI1 le_infI2)
   147   thus "bdd_below (A \<union> B)" unfolding bdd_below_def ..
   148 qed
   149 
   150 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)"
   151   by (auto simp: bdd_above_def intro: le_supI1 le_supI2)
   152 
   153 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)"
   154   by (auto simp: bdd_below_def intro: le_infI1 le_infI2)
   155 
   156 end
   157 
   158 
   159 text {*
   160 
   161 To avoid name classes with the @{class complete_lattice}-class we prefix @{const Sup} and
   162 @{const Inf} in theorem names with c.
   163 
   164 *}
   165 
   166 class conditionally_complete_lattice = lattice + Sup + Inf +
   167   assumes cInf_lower: "x \<in> X \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X \<le> x"
   168     and cInf_greatest: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> z \<le> Inf X"
   169   assumes cSup_upper: "x \<in> X \<Longrightarrow> bdd_above X \<Longrightarrow> x \<le> Sup X"
   170     and cSup_least: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X \<le> z"
   171 begin
   172 
   173 lemma cSup_upper2: "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> bdd_above X \<Longrightarrow> y \<le> Sup X"
   174   by (metis cSup_upper order_trans)
   175 
   176 lemma cInf_lower2: "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X \<le> y"
   177   by (metis cInf_lower order_trans)
   178 
   179 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"
   180   by (metis cSup_least cSup_upper2)
   181 
   182 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"
   183   by (metis cInf_greatest cInf_lower2)
   184 
   185 lemma cSup_subset_mono: "A \<noteq> {} \<Longrightarrow> bdd_above B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Sup A \<le> Sup B"
   186   by (metis cSup_least cSup_upper subsetD)
   187 
   188 lemma cInf_superset_mono: "A \<noteq> {} \<Longrightarrow> bdd_below B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> Inf B \<le> Inf A"
   189   by (metis cInf_greatest cInf_lower subsetD)
   190 
   191 lemma cSup_eq_maximum: "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X = z"
   192   by (intro antisym cSup_upper[of z X] cSup_least[of X z]) auto
   193 
   194 lemma cInf_eq_minimum: "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X = z"
   195   by (intro antisym cInf_lower[of z X] cInf_greatest[of X z]) auto
   196 
   197 lemma cSup_le_iff: "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> Sup S \<le> a \<longleftrightarrow> (\<forall>x\<in>S. x \<le> a)"
   198   by (metis order_trans cSup_upper cSup_least)
   199 
   200 lemma le_cInf_iff: "S \<noteq> {} \<Longrightarrow> bdd_below S \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall>x\<in>S. a \<le> x)"
   201   by (metis order_trans cInf_lower cInf_greatest)
   202 
   203 lemma cSup_eq_non_empty:
   204   assumes 1: "X \<noteq> {}"
   205   assumes 2: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
   206   assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
   207   shows "Sup X = a"
   208   by (intro 3 1 antisym cSup_least) (auto intro: 2 1 cSup_upper)
   209 
   210 lemma cInf_eq_non_empty:
   211   assumes 1: "X \<noteq> {}"
   212   assumes 2: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
   213   assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
   214   shows "Inf X = a"
   215   by (intro 3 1 antisym cInf_greatest) (auto intro: 2 1 cInf_lower)
   216 
   217 lemma cInf_cSup: "S \<noteq> {} \<Longrightarrow> bdd_below S \<Longrightarrow> Inf S = Sup {x. \<forall>s\<in>S. x \<le> s}"
   218   by (rule cInf_eq_non_empty) (auto intro!: cSup_upper cSup_least simp: bdd_below_def)
   219 
   220 lemma cSup_cInf: "S \<noteq> {} \<Longrightarrow> bdd_above S \<Longrightarrow> Sup S = Inf {x. \<forall>s\<in>S. s \<le> x}"
   221   by (rule cSup_eq_non_empty) (auto intro!: cInf_lower cInf_greatest simp: bdd_above_def)
   222 
   223 lemma cSup_insert: "X \<noteq> {} \<Longrightarrow> bdd_above X \<Longrightarrow> Sup (insert a X) = sup a (Sup X)"
   224   by (intro cSup_eq_non_empty) (auto intro: le_supI2 cSup_upper cSup_least)
   225 
   226 lemma cInf_insert: "X \<noteq> {} \<Longrightarrow> bdd_below X \<Longrightarrow> Inf (insert a X) = inf a (Inf X)"
   227   by (intro cInf_eq_non_empty) (auto intro: le_infI2 cInf_lower cInf_greatest)
   228 
   229 lemma cSup_singleton [simp]: "Sup {x} = x"
   230   by (intro cSup_eq_maximum) auto
   231 
   232 lemma cInf_singleton [simp]: "Inf {x} = x"
   233   by (intro cInf_eq_minimum) auto
   234 
   235 lemma cSup_insert_If:  "bdd_above X \<Longrightarrow> Sup (insert a X) = (if X = {} then a else sup a (Sup X))"
   236   using cSup_insert[of X] by simp
   237 
   238 lemma cInf_insert_If: "bdd_below X \<Longrightarrow> Inf (insert a X) = (if X = {} then a else inf a (Inf X))"
   239   using cInf_insert[of X] by simp
   240 
   241 lemma le_cSup_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> x \<le> Sup X"
   242 proof (induct X arbitrary: x rule: finite_induct)
   243   case (insert x X y) then show ?case
   244     by (cases "X = {}") (auto simp: cSup_insert intro: le_supI2)
   245 qed simp
   246 
   247 lemma cInf_le_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> Inf X \<le> x"
   248 proof (induct X arbitrary: x rule: finite_induct)
   249   case (insert x X y) then show ?case
   250     by (cases "X = {}") (auto simp: cInf_insert intro: le_infI2)
   251 qed simp
   252 
   253 lemma cSup_eq_Sup_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Sup_fin X"
   254   by (induct X rule: finite_ne_induct) (simp_all add: cSup_insert)
   255 
   256 lemma cInf_eq_Inf_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Inf_fin X"
   257   by (induct X rule: finite_ne_induct) (simp_all add: cInf_insert)
   258 
   259 lemma cSup_atMost[simp]: "Sup {..x} = x"
   260   by (auto intro!: cSup_eq_maximum)
   261 
   262 lemma cSup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = x"
   263   by (auto intro!: cSup_eq_maximum)
   264 
   265 lemma cSup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = x"
   266   by (auto intro!: cSup_eq_maximum)
   267 
   268 lemma cInf_atLeast[simp]: "Inf {x..} = x"
   269   by (auto intro!: cInf_eq_minimum)
   270 
   271 lemma cInf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = y"
   272   by (auto intro!: cInf_eq_minimum)
   273 
   274 lemma cInf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = y"
   275   by (auto intro!: cInf_eq_minimum)
   276 
   277 lemma cINF_lower: "bdd_below (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> INFI A f \<le> f x"
   278   using cInf_lower [of _ "f ` A"] by simp
   279 
   280 lemma cINF_greatest: "A \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> m \<le> f x) \<Longrightarrow> m \<le> INFI A f"
   281   using cInf_greatest [of "f ` A"] by auto
   282 
   283 lemma cSUP_upper: "x \<in> A \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> f x \<le> SUPR A f"
   284   using cSup_upper [of _ "f ` A"] by simp
   285 
   286 lemma cSUP_least: "A \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<le> M) \<Longrightarrow> SUPR A f \<le> M"
   287   using cSup_least [of "f ` A"] by auto
   288 
   289 lemma cINF_lower2: "bdd_below (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> f x \<le> u \<Longrightarrow> INFI A f \<le> u"
   290   by (auto intro: cINF_lower assms order_trans)
   291 
   292 lemma cSUP_upper2: "bdd_above (f ` A) \<Longrightarrow> x \<in> A \<Longrightarrow> u \<le> f x \<Longrightarrow> u \<le> SUPR A f"
   293   by (auto intro: cSUP_upper assms order_trans)
   294 
   295 lemma cSUP_const: "A \<noteq> {} \<Longrightarrow> (SUP x:A. c) = c"
   296   by (intro antisym cSUP_least) (auto intro: cSUP_upper)
   297 
   298 lemma cINF_const: "A \<noteq> {} \<Longrightarrow> (INF x:A. c) = c"
   299   by (intro antisym cINF_greatest) (auto intro: cINF_lower)
   300 
   301 lemma le_cINF_iff: "A \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> u \<le> INFI A f \<longleftrightarrow> (\<forall>x\<in>A. u \<le> f x)"
   302   by (metis cINF_greatest cINF_lower assms order_trans)
   303 
   304 lemma cSUP_le_iff: "A \<noteq> {} \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> SUPR A f \<le> u \<longleftrightarrow> (\<forall>x\<in>A. f x \<le> u)"
   305   by (metis cSUP_least cSUP_upper assms order_trans)
   306 
   307 lemma less_cINF_D: "bdd_below (f`A) \<Longrightarrow> y < (INF i:A. f i) \<Longrightarrow> i \<in> A \<Longrightarrow> y < f i"
   308   by (metis cINF_lower less_le_trans)
   309 
   310 lemma cSUP_lessD: "bdd_above (f`A) \<Longrightarrow> (SUP i:A. f i) < y \<Longrightarrow> i \<in> A \<Longrightarrow> f i < y"
   311   by (metis cSUP_upper le_less_trans)
   312 
   313 lemma cINF_insert: "A \<noteq> {} \<Longrightarrow> bdd_below (f ` A) \<Longrightarrow> INFI (insert a A) f = inf (f a) (INFI A f)"
   314   by (metis cInf_insert Inf_image_eq image_insert image_is_empty)
   315 
   316 lemma cSUP_insert: "A \<noteq> {} \<Longrightarrow> bdd_above (f ` A) \<Longrightarrow> SUPR (insert a A) f = sup (f a) (SUPR A f)"
   317   by (metis cSup_insert Sup_image_eq image_insert image_is_empty)
   318 
   319 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> INFI A f \<le> INFI B g"
   320   using cInf_mono [of "g ` B" "f ` A"] by auto
   321 
   322 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> SUPR A f \<le> SUPR B g"
   323   using cSup_mono [of "f ` A" "g ` B"] by auto
   324 
   325 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> INFI B g \<le> INFI A f"
   326   by (rule cINF_mono) auto
   327 
   328 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> SUPR A f \<le> SUPR B g"
   329   by (rule cSUP_mono) auto
   330 
   331 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)"
   332   by (metis cInf_superset_mono lattice_class.inf_sup_ord(1) le_infI1)
   333 
   334 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) "
   335   by (metis cSup_subset_mono lattice_class.inf_sup_ord(1) le_supI1)
   336 
   337 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)"
   338   by (intro antisym le_infI cInf_greatest cInf_lower) (auto intro: le_infI1 le_infI2 cInf_lower)
   339 
   340 lemma cINF_union: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_below (f`B) \<Longrightarrow> INFI (A \<union> B) f = inf (INFI A f) (INFI B f)"
   341   using cInf_union_distrib [of "f ` A" "f ` B"] by (simp add: image_Un [symmetric])
   342 
   343 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)"
   344   by (intro antisym le_supI cSup_least cSup_upper) (auto intro: le_supI1 le_supI2 cSup_upper)
   345 
   346 lemma cSUP_union: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> B \<noteq> {} \<Longrightarrow> bdd_above (f`B) \<Longrightarrow> SUPR (A \<union> B) f = sup (SUPR A f) (SUPR B f)"
   347   using cSup_union_distrib [of "f ` A" "f ` B"] by (simp add: image_Un [symmetric])
   348 
   349 lemma cINF_inf_distrib: "A \<noteq> {} \<Longrightarrow> bdd_below (f`A) \<Longrightarrow> bdd_below (g`A) \<Longrightarrow> inf (INFI A f) (INFI A g) = (INF a:A. inf (f a) (g a))"
   350   by (intro antisym le_infI cINF_greatest cINF_lower2)
   351      (auto intro: le_infI1 le_infI2 cINF_greatest cINF_lower le_infI)
   352 
   353 lemma SUP_sup_distrib: "A \<noteq> {} \<Longrightarrow> bdd_above (f`A) \<Longrightarrow> bdd_above (g`A) \<Longrightarrow> sup (SUPR A f) (SUPR A g) = (SUP a:A. sup (f a) (g a))"
   354   by (intro antisym le_supI cSUP_least cSUP_upper2)
   355      (auto intro: le_supI1 le_supI2 cSUP_least cSUP_upper le_supI)
   356 
   357 end
   358 
   359 instance complete_lattice \<subseteq> conditionally_complete_lattice
   360   by default (auto intro: Sup_upper Sup_least Inf_lower Inf_greatest)
   361 
   362 lemma cSup_eq:
   363   fixes a :: "'a :: {conditionally_complete_lattice, no_bot}"
   364   assumes upper: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
   365   assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
   366   shows "Sup X = a"
   367 proof cases
   368   assume "X = {}" with lt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   369 qed (intro cSup_eq_non_empty assms)
   370 
   371 lemma cInf_eq:
   372   fixes a :: "'a :: {conditionally_complete_lattice, no_top}"
   373   assumes upper: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
   374   assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
   375   shows "Inf X = a"
   376 proof cases
   377   assume "X = {}" with gt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   378 qed (intro cInf_eq_non_empty assms)
   379 
   380 class conditionally_complete_linorder = conditionally_complete_lattice + linorder
   381 begin
   382 
   383 lemma less_cSup_iff : (*REAL_SUP_LE in HOL4*)
   384   "X \<noteq> {} \<Longrightarrow> bdd_above X \<Longrightarrow> y < Sup X \<longleftrightarrow> (\<exists>x\<in>X. y < x)"
   385   by (rule iffI) (metis cSup_least not_less, metis cSup_upper less_le_trans)
   386 
   387 lemma cInf_less_iff: "X \<noteq> {} \<Longrightarrow> bdd_below X \<Longrightarrow> Inf X < y \<longleftrightarrow> (\<exists>x\<in>X. x < y)"
   388   by (rule iffI) (metis cInf_greatest not_less, metis cInf_lower le_less_trans)
   389 
   390 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)"
   391   using cInf_less_iff[of "f`A"] by auto
   392 
   393 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)"
   394   using less_cSup_iff[of "f`A"] by auto
   395 
   396 lemma less_cSupE:
   397   assumes "y < Sup X" "X \<noteq> {}" obtains x where "x \<in> X" "y < x"
   398   by (metis cSup_least assms not_le that)
   399 
   400 lemma less_cSupD:
   401   "X \<noteq> {} \<Longrightarrow> z < Sup X \<Longrightarrow> \<exists>x\<in>X. z < x"
   402   by (metis less_cSup_iff not_leE bdd_above_def)
   403 
   404 lemma cInf_lessD:
   405   "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x\<in>X. x < z"
   406   by (metis cInf_less_iff not_leE bdd_below_def)
   407 
   408 lemma complete_interval:
   409   assumes "a < b" and "P a" and "\<not> P b"
   410   shows "\<exists>c. a \<le> c \<and> c \<le> b \<and> (\<forall>x. a \<le> x \<and> x < c \<longrightarrow> P x) \<and>
   411              (\<forall>d. (\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x) \<longrightarrow> d \<le> c)"
   412 proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
   413   show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   414     by (rule cSup_upper, auto simp: bdd_above_def)
   415        (metis `a < b` `\<not> P b` linear less_le)
   416 next
   417   show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
   418     apply (rule cSup_least) 
   419     apply auto
   420     apply (metis less_le_not_le)
   421     apply (metis `a<b` `~ P b` linear less_le)
   422     done
   423 next
   424   fix x
   425   assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   426   show "P x"
   427     apply (rule less_cSupE [OF lt], auto)
   428     apply (metis less_le_not_le)
   429     apply (metis x) 
   430     done
   431 next
   432   fix d
   433     assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
   434     thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   435       by (rule_tac cSup_upper, auto simp: bdd_above_def)
   436          (metis `a<b` `~ P b` linear less_le)
   437 qed
   438 
   439 end
   440 
   441 lemma cSup_eq_Max: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Max X"
   442   using cSup_eq_Sup_fin[of X] Sup_fin_eq_Max[of X] by simp
   443 
   444 lemma cInf_eq_Min: "finite (X::'a::conditionally_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Min X"
   445   using cInf_eq_Inf_fin[of X] Inf_fin_eq_Min[of X] by simp
   446 
   447 lemma cSup_lessThan[simp]: "Sup {..<x::'a::{conditionally_complete_linorder, no_bot, dense_linorder}} = x"
   448   by (auto intro!: cSup_eq_non_empty intro: dense_le)
   449 
   450 lemma cSup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x::'a::{conditionally_complete_linorder, no_bot, dense_linorder}} = x"
   451   by (auto intro!: cSup_eq intro: dense_le_bounded)
   452 
   453 lemma cSup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x::'a::{conditionally_complete_linorder, no_bot, dense_linorder}} = x"
   454   by (auto intro!: cSup_eq intro: dense_le_bounded)
   455 
   456 lemma cInf_greaterThan[simp]: "Inf {x::'a::{conditionally_complete_linorder, no_top, dense_linorder} <..} = x"
   457   by (auto intro!: cInf_eq intro: dense_ge)
   458 
   459 lemma cInf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x::'a::{conditionally_complete_linorder, no_top, dense_linorder}} = y"
   460   by (auto intro!: cInf_eq intro: dense_ge_bounded)
   461 
   462 lemma cInf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x::'a::{conditionally_complete_linorder, no_top, dense_linorder}} = y"
   463   by (auto intro!: cInf_eq intro: dense_ge_bounded)
   464 
   465 class linear_continuum = conditionally_complete_linorder + dense_linorder +
   466   assumes UNIV_not_singleton: "\<exists>a b::'a. a \<noteq> b"
   467 begin
   468 
   469 lemma ex_gt_or_lt: "\<exists>b. a < b \<or> b < a"
   470   by (metis UNIV_not_singleton neq_iff)
   471 
   472 end
   473 
   474 instantiation nat :: conditionally_complete_linorder
   475 begin
   476 
   477 definition "Sup (X::nat set) = Max X"
   478 definition "Inf (X::nat set) = (LEAST n. n \<in> X)"
   479 
   480 lemma bdd_above_nat: "bdd_above X \<longleftrightarrow> finite (X::nat set)"
   481 proof
   482   assume "bdd_above X"
   483   then obtain z where "X \<subseteq> {.. z}"
   484     by (auto simp: bdd_above_def)
   485   then show "finite X"
   486     by (rule finite_subset) simp
   487 qed simp
   488 
   489 instance
   490 proof
   491   fix x :: nat and X :: "nat set"
   492   { assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
   493       by (simp add: Inf_nat_def Least_le) }
   494   { assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> x \<le> y" then show "x \<le> Inf X"
   495       unfolding Inf_nat_def ex_in_conv[symmetric] by (rule LeastI2_ex) }
   496   { assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
   497       by (simp add: Sup_nat_def bdd_above_nat) }
   498   { assume "X \<noteq> {}" "\<And>y. y \<in> X \<Longrightarrow> y \<le> x" 
   499     moreover then have "bdd_above X"
   500       by (auto simp: bdd_above_def)
   501     ultimately show "Sup X \<le> x"
   502       by (simp add: Sup_nat_def bdd_above_nat) }
   503 qed
   504 end
   505 
   506 instantiation int :: conditionally_complete_linorder
   507 begin
   508 
   509 definition "Sup (X::int set) = (THE x. x \<in> X \<and> (\<forall>y\<in>X. y \<le> x))"
   510 definition "Inf (X::int set) = - (Sup (uminus ` X))"
   511 
   512 instance
   513 proof
   514   { fix x :: int and X :: "int set" assume "X \<noteq> {}" "bdd_above X"
   515     then obtain x y where "X \<subseteq> {..y}" "x \<in> X"
   516       by (auto simp: bdd_above_def)
   517     then have *: "finite (X \<inter> {x..y})" "X \<inter> {x..y} \<noteq> {}" and "x \<le> y"
   518       by (auto simp: subset_eq)
   519     have "\<exists>!x\<in>X. (\<forall>y\<in>X. y \<le> x)"
   520     proof
   521       { fix z assume "z \<in> X"
   522         have "z \<le> Max (X \<inter> {x..y})"
   523         proof cases
   524           assume "x \<le> z" with `z \<in> X` `X \<subseteq> {..y}` *(1) show ?thesis
   525             by (auto intro!: Max_ge)
   526         next
   527           assume "\<not> x \<le> z"
   528           then have "z < x" by simp
   529           also have "x \<le> Max (X \<inter> {x..y})"
   530             using `x \<in> X` *(1) `x \<le> y` by (intro Max_ge) auto
   531           finally show ?thesis by simp
   532         qed }
   533       note le = this
   534       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
   535 
   536       fix z assume *: "z \<in> X \<and> (\<forall>y\<in>X. y \<le> z)"
   537       with le have "z \<le> Max (X \<inter> {x..y})"
   538         by auto
   539       moreover have "Max (X \<inter> {x..y}) \<le> z"
   540         using * ex by auto
   541       ultimately show "z = Max (X \<inter> {x..y})"
   542         by auto
   543     qed
   544     then have "Sup X \<in> X \<and> (\<forall>y\<in>X. y \<le> Sup X)"
   545       unfolding Sup_int_def by (rule theI') }
   546   note Sup_int = this
   547 
   548   { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_above X" then show "x \<le> Sup X"
   549       using Sup_int[of X] by auto }
   550   note le_Sup = this
   551   { 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"
   552       using Sup_int[of X] by (auto simp: bdd_above_def) }
   553   note Sup_le = this
   554 
   555   { fix x :: int and X :: "int set" assume "x \<in> X" "bdd_below X" then show "Inf X \<le> x"
   556       using le_Sup[of "-x" "uminus ` X"] by (auto simp: Inf_int_def) }
   557   { 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"
   558       using Sup_le[of "uminus ` X" "-x"] by (force simp: Inf_int_def) }
   559 qed
   560 end
   561 
   562 end