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