src/HOL/Conditional_Complete_Lattices.thy
author hoelzl
Tue Mar 26 12:20:58 2013 +0100 (2013-03-26)
changeset 51526 155263089e7b
parent 51518 6a56b7088a6a
child 51643 b6675f4549d8
permissions -rw-r--r--
move SEQ.thy and Lim.thy to Limits.thy
     1 (*  Title:      HOL/Conditional_Complete_Lattices.thy
     2     Author:     Amine Chaieb and L C Paulson, University of Cambridge
     3     Author:     Johanens Hölzl, TU München
     4 *)
     5 
     6 header {* Conditional Complete Lattices *}
     7 
     8 theory Conditional_Complete_Lattices
     9 imports Main Lubs
    10 begin
    11 
    12 lemma Sup_fin_eq_Max: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup_fin X = Max X"
    13   by (induct X rule: finite_ne_induct) (simp_all add: sup_max)
    14 
    15 lemma Inf_fin_eq_Min: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf_fin X = Min X"
    16   by (induct X rule: finite_ne_induct) (simp_all add: inf_min)
    17 
    18 text {*
    19 
    20 To avoid name classes with the @{class complete_lattice}-class we prefix @{const Sup} and
    21 @{const Inf} in theorem names with c.
    22 
    23 *}
    24 
    25 class conditional_complete_lattice = lattice + Sup + Inf +
    26   assumes cInf_lower: "x \<in> X \<Longrightarrow> (\<And>a. a \<in> X \<Longrightarrow> z \<le> a) \<Longrightarrow> Inf X \<le> x"
    27     and cInf_greatest: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> z \<le> Inf X"
    28   assumes cSup_upper: "x \<in> X \<Longrightarrow> (\<And>a. a \<in> X \<Longrightarrow> a \<le> z) \<Longrightarrow> x \<le> Sup X"
    29     and cSup_least: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X \<le> z"
    30 begin
    31 
    32 lemma cSup_eq_maximum: (*REAL_SUP_MAX in HOL4*)
    33   "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X = z"
    34   by (blast intro: antisym cSup_upper cSup_least)
    35 
    36 lemma cInf_eq_minimum: (*REAL_INF_MIN in HOL4*)
    37   "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X = z"
    38   by (intro antisym cInf_lower[of z X z] cInf_greatest[of X z]) auto
    39 
    40 lemma cSup_le_iff: "S \<noteq> {} \<Longrightarrow> (\<And>a. a \<in> S \<Longrightarrow> a \<le> z) \<Longrightarrow> Sup S \<le> a \<longleftrightarrow> (\<forall>x\<in>S. x \<le> a)"
    41   by (metis order_trans cSup_upper cSup_least)
    42 
    43 lemma le_cInf_iff: "S \<noteq> {} \<Longrightarrow> (\<And>a. a \<in> S \<Longrightarrow> z \<le> a) \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall>x\<in>S. a \<le> x)"
    44   by (metis order_trans cInf_lower cInf_greatest)
    45 
    46 lemma cSup_singleton [simp]: "Sup {x} = x"
    47   by (intro cSup_eq_maximum) auto
    48 
    49 lemma cInf_singleton [simp]: "Inf {x} = x"
    50   by (intro cInf_eq_minimum) auto
    51 
    52 lemma cSup_upper2: (*REAL_IMP_LE_SUP in HOL4*)
    53   "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y \<le> Sup X"
    54   by (metis cSup_upper order_trans)
    55  
    56 lemma cInf_lower2:
    57   "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X \<le> y"
    58   by (metis cInf_lower order_trans)
    59 
    60 lemma cSup_upper_EX: "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> x \<le> z \<Longrightarrow> x \<le> Sup X"
    61   by (blast intro: cSup_upper)
    62 
    63 lemma cInf_lower_EX:  "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> z \<le> x \<Longrightarrow> Inf X \<le> x"
    64   by (blast intro: cInf_lower)
    65 
    66 lemma cSup_eq_non_empty:
    67   assumes 1: "X \<noteq> {}"
    68   assumes 2: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
    69   assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
    70   shows "Sup X = a"
    71   by (intro 3 1 antisym cSup_least) (auto intro: 2 1 cSup_upper)
    72 
    73 lemma cInf_eq_non_empty:
    74   assumes 1: "X \<noteq> {}"
    75   assumes 2: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
    76   assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
    77   shows "Inf X = a"
    78   by (intro 3 1 antisym cInf_greatest) (auto intro: 2 1 cInf_lower)
    79 
    80 lemma cInf_cSup: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf S = Sup {x. \<forall>s\<in>S. x \<le> s}"
    81   by (rule cInf_eq_non_empty) (auto intro: cSup_upper cSup_least)
    82 
    83 lemma cSup_cInf: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup S = Inf {x. \<forall>s\<in>S. s \<le> x}"
    84   by (rule cSup_eq_non_empty) (auto intro: cInf_lower cInf_greatest)
    85 
    86 lemma cSup_insert: 
    87   assumes x: "X \<noteq> {}"
    88       and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
    89   shows "Sup (insert a X) = sup a (Sup X)"
    90 proof (intro cSup_eq_non_empty)
    91   fix y assume "\<And>x. x \<in> insert a X \<Longrightarrow> x \<le> y" with x show "sup a (Sup X) \<le> y" by (auto intro: cSup_least)
    92 qed (auto intro: le_supI2 z cSup_upper)
    93 
    94 lemma cInf_insert: 
    95   assumes x: "X \<noteq> {}"
    96       and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
    97   shows "Inf (insert a X) = inf a (Inf X)"
    98 proof (intro cInf_eq_non_empty)
    99   fix y assume "\<And>x. x \<in> insert a X \<Longrightarrow> y \<le> x" with x show "y \<le> inf a (Inf X)" by (auto intro: cInf_greatest)
   100 qed (auto intro: le_infI2 z cInf_lower)
   101 
   102 lemma cSup_insert_If: 
   103   "(\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup (insert a X) = (if X = {} then a else sup a (Sup X))"
   104   using cSup_insert[of X z] by simp
   105 
   106 lemma cInf_insert_if: 
   107   "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf (insert a X) = (if X = {} then a else inf a (Inf X))"
   108   using cInf_insert[of X z] by simp
   109 
   110 lemma le_cSup_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> x \<le> Sup X"
   111 proof (induct X arbitrary: x rule: finite_induct)
   112   case (insert x X y) then show ?case
   113     apply (cases "X = {}")
   114     apply simp
   115     apply (subst cSup_insert[of _ "Sup X"])
   116     apply (auto intro: le_supI2)
   117     done
   118 qed simp
   119 
   120 lemma cInf_le_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> Inf X \<le> x"
   121 proof (induct X arbitrary: x rule: finite_induct)
   122   case (insert x X y) then show ?case
   123     apply (cases "X = {}")
   124     apply simp
   125     apply (subst cInf_insert[of _ "Inf X"])
   126     apply (auto intro: le_infI2)
   127     done
   128 qed simp
   129 
   130 lemma cSup_eq_Sup_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Sup_fin X"
   131 proof (induct X rule: finite_ne_induct)
   132   case (insert x X) then show ?case
   133     using cSup_insert[of X "Sup_fin X" x] le_cSup_finite[of X] by simp
   134 qed simp
   135 
   136 lemma cInf_eq_Inf_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Inf_fin X"
   137 proof (induct X rule: finite_ne_induct)
   138   case (insert x X) then show ?case
   139     using cInf_insert[of X "Inf_fin X" x] cInf_le_finite[of X] by simp
   140 qed simp
   141 
   142 lemma cSup_atMost[simp]: "Sup {..x} = x"
   143   by (auto intro!: cSup_eq_maximum)
   144 
   145 lemma cSup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = x"
   146   by (auto intro!: cSup_eq_maximum)
   147 
   148 lemma cSup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = x"
   149   by (auto intro!: cSup_eq_maximum)
   150 
   151 lemma cInf_atLeast[simp]: "Inf {x..} = x"
   152   by (auto intro!: cInf_eq_minimum)
   153 
   154 lemma cInf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = y"
   155   by (auto intro!: cInf_eq_minimum)
   156 
   157 lemma cInf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = y"
   158   by (auto intro!: cInf_eq_minimum)
   159 
   160 end
   161 
   162 instance complete_lattice \<subseteq> conditional_complete_lattice
   163   by default (auto intro: Sup_upper Sup_least Inf_lower Inf_greatest)
   164 
   165 lemma isLub_cSup: 
   166   "(S::'a :: conditional_complete_lattice set) \<noteq> {} \<Longrightarrow> (\<exists>b. S *<= b) \<Longrightarrow> isLub UNIV S (Sup S)"
   167   by  (auto simp add: isLub_def setle_def leastP_def isUb_def
   168             intro!: setgeI intro: cSup_upper cSup_least)
   169 
   170 lemma cSup_eq:
   171   fixes a :: "'a :: {conditional_complete_lattice, no_bot}"
   172   assumes upper: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
   173   assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
   174   shows "Sup X = a"
   175 proof cases
   176   assume "X = {}" with lt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   177 qed (intro cSup_eq_non_empty assms)
   178 
   179 lemma cInf_eq:
   180   fixes a :: "'a :: {conditional_complete_lattice, no_top}"
   181   assumes upper: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
   182   assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
   183   shows "Inf X = a"
   184 proof cases
   185   assume "X = {}" with gt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
   186 qed (intro cInf_eq_non_empty assms)
   187 
   188 lemma cSup_le: "(S::'a::conditional_complete_lattice set) \<noteq> {} \<Longrightarrow> S *<= b \<Longrightarrow> Sup S \<le> b"
   189   by (metis cSup_least setle_def)
   190 
   191 lemma cInf_ge: "(S::'a :: conditional_complete_lattice set) \<noteq> {} \<Longrightarrow> b <=* S \<Longrightarrow> Inf S \<ge> b"
   192   by (metis cInf_greatest setge_def)
   193 
   194 class conditional_complete_linorder = conditional_complete_lattice + linorder
   195 begin
   196 
   197 lemma less_cSup_iff : (*REAL_SUP_LE in HOL4*)
   198   "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y < Sup X \<longleftrightarrow> (\<exists>x\<in>X. y < x)"
   199   by (rule iffI) (metis cSup_least not_less, metis cSup_upper less_le_trans)
   200 
   201 lemma cInf_less_iff: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X < y \<longleftrightarrow> (\<exists>x\<in>X. x < y)"
   202   by (rule iffI) (metis cInf_greatest not_less, metis cInf_lower le_less_trans)
   203 
   204 lemma less_cSupE:
   205   assumes "y < Sup X" "X \<noteq> {}" obtains x where "x \<in> X" "y < x"
   206   by (metis cSup_least assms not_le that)
   207 
   208 lemma less_cSupD:
   209   "X \<noteq> {} \<Longrightarrow> z < Sup X \<Longrightarrow> \<exists>x\<in>X. z < x"
   210   by (metis less_cSup_iff not_leE)
   211 
   212 lemma cInf_lessD:
   213   "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x\<in>X. x < z"
   214   by (metis cInf_less_iff not_leE)
   215 
   216 lemma complete_interval:
   217   assumes "a < b" and "P a" and "\<not> P b"
   218   shows "\<exists>c. a \<le> c \<and> c \<le> b \<and> (\<forall>x. a \<le> x \<and> x < c \<longrightarrow> P x) \<and>
   219              (\<forall>d. (\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x) \<longrightarrow> d \<le> c)"
   220 proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
   221   show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   222     by (rule cSup_upper [where z=b], auto)
   223        (metis `a < b` `\<not> P b` linear less_le)
   224 next
   225   show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
   226     apply (rule cSup_least) 
   227     apply auto
   228     apply (metis less_le_not_le)
   229     apply (metis `a<b` `~ P b` linear less_le)
   230     done
   231 next
   232   fix x
   233   assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   234   show "P x"
   235     apply (rule less_cSupE [OF lt], auto)
   236     apply (metis less_le_not_le)
   237     apply (metis x) 
   238     done
   239 next
   240   fix d
   241     assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
   242     thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   243       by (rule_tac z="b" in cSup_upper, auto) 
   244          (metis `a<b` `~ P b` linear less_le)
   245 qed
   246 
   247 end
   248 
   249 lemma cSup_bounds:
   250   fixes S :: "'a :: conditional_complete_lattice set"
   251   assumes Se: "S \<noteq> {}" and l: "a <=* S" and u: "S *<= b"
   252   shows "a \<le> Sup S \<and> Sup S \<le> b"
   253 proof-
   254   from isLub_cSup[OF Se] u have lub: "isLub UNIV S (Sup S)" by blast
   255   hence b: "Sup S \<le> b" using u 
   256     by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def) 
   257   from Se obtain y where y: "y \<in> S" by blast
   258   from lub l have "a \<le> Sup S"
   259     by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def)
   260        (metis le_iff_sup le_sup_iff y)
   261   with b show ?thesis by blast
   262 qed
   263 
   264 
   265 lemma cSup_unique: "(S::'a :: {conditional_complete_linorder, no_bot} set) *<= b \<Longrightarrow> (\<forall>b'<b. \<exists>x\<in>S. b' < x) \<Longrightarrow> Sup S = b"
   266   by (rule cSup_eq) (auto simp: not_le[symmetric] setle_def)
   267 
   268 lemma cInf_unique: "b <=* (S::'a :: {conditional_complete_linorder, no_top} set) \<Longrightarrow> (\<forall>b'>b. \<exists>x\<in>S. b' > x) \<Longrightarrow> Inf S = b"
   269   by (rule cInf_eq) (auto simp: not_le[symmetric] setge_def)
   270 
   271 lemma cSup_eq_Max: "finite (X::'a::conditional_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Max X"
   272   using cSup_eq_Sup_fin[of X] Sup_fin_eq_Max[of X] by simp
   273 
   274 lemma cInf_eq_Min: "finite (X::'a::conditional_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Min X"
   275   using cInf_eq_Inf_fin[of X] Inf_fin_eq_Min[of X] by simp
   276 
   277 lemma cSup_lessThan[simp]: "Sup {..<x::'a::{conditional_complete_linorder, dense_linorder}} = x"
   278   by (auto intro!: cSup_eq_non_empty intro: dense_le)
   279 
   280 lemma cSup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x::'a::{conditional_complete_linorder, dense_linorder}} = x"
   281   by (auto intro!: cSup_eq intro: dense_le_bounded)
   282 
   283 lemma cSup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x::'a::{conditional_complete_linorder, dense_linorder}} = x"
   284   by (auto intro!: cSup_eq intro: dense_le_bounded)
   285 
   286 lemma cInf_greaterThan[simp]: "Inf {x::'a::{conditional_complete_linorder, dense_linorder} <..} = x"
   287   by (auto intro!: cInf_eq intro: dense_ge)
   288 
   289 lemma cInf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x::'a::{conditional_complete_linorder, dense_linorder}} = y"
   290   by (auto intro!: cInf_eq intro: dense_ge_bounded)
   291 
   292 lemma cInf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x::'a::{conditional_complete_linorder, dense_linorder}} = y"
   293   by (auto intro!: cInf_eq intro: dense_ge_bounded)
   294 
   295 end