src/HOL/SupInf.thy
author hoelzl
Fri Mar 22 10:41:43 2013 +0100 (2013-03-22)
changeset 51475 ebf9d4fd00ba
parent 46757 ad878aff9c15
permissions -rw-r--r--
introduct the conditional_complete_lattice type class; generalize theorems about real Sup and Inf to it
paulson@33269
     1
(*  Author: Amine Chaieb and L C Paulson, University of Cambridge *)
paulson@33269
     2
paulson@33269
     3
header {*Sup and Inf Operators on Sets of Reals.*}
paulson@33269
     4
paulson@33269
     5
theory SupInf
paulson@33269
     6
imports RComplete
paulson@33269
     7
begin
paulson@33269
     8
hoelzl@51475
     9
lemma Sup_fin_eq_Max: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup_fin X = Max X"
hoelzl@51475
    10
  by (induct X rule: finite_ne_induct) (simp_all add: sup_max)
hoelzl@51475
    11
hoelzl@51475
    12
lemma Inf_fin_eq_Min: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf_fin X = Min X"
hoelzl@51475
    13
  by (induct X rule: finite_ne_induct) (simp_all add: inf_min)
hoelzl@51475
    14
hoelzl@51475
    15
text {*
hoelzl@51475
    16
hoelzl@51475
    17
To avoid name classes with the @{class complete_lattice}-class we prefix @{const Sup} and
hoelzl@51475
    18
@{const Inf} in theorem names with c.
hoelzl@51475
    19
hoelzl@51475
    20
*}
hoelzl@51475
    21
hoelzl@51475
    22
class conditional_complete_lattice = lattice + Sup + Inf +
hoelzl@51475
    23
  assumes cInf_lower: "x \<in> X \<Longrightarrow> (\<And>a. a \<in> X \<Longrightarrow> z \<le> a) \<Longrightarrow> Inf X \<le> x"
hoelzl@51475
    24
    and cInf_greatest: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> z \<le> Inf X"
hoelzl@51475
    25
  assumes cSup_upper: "x \<in> X \<Longrightarrow> (\<And>a. a \<in> X \<Longrightarrow> a \<le> z) \<Longrightarrow> x \<le> Sup X"
hoelzl@51475
    26
    and cSup_least: "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X \<le> z"
paulson@33269
    27
begin
hoelzl@51475
    28
hoelzl@51475
    29
lemma cSup_eq_maximum: (*REAL_SUP_MAX in HOL4*)
hoelzl@51475
    30
  "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup X = z"
hoelzl@51475
    31
  by (blast intro: antisym cSup_upper cSup_least)
hoelzl@51475
    32
hoelzl@51475
    33
lemma cInf_eq_minimum: (*REAL_INF_MIN in HOL4*)
hoelzl@51475
    34
  "z \<in> X \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X = z"
hoelzl@51475
    35
  by (intro antisym cInf_lower[of z X z] cInf_greatest[of X z]) auto
hoelzl@51475
    36
hoelzl@51475
    37
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)"
hoelzl@51475
    38
  by (metis order_trans cSup_upper cSup_least)
hoelzl@51475
    39
hoelzl@51475
    40
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)"
hoelzl@51475
    41
  by (metis order_trans cInf_lower cInf_greatest)
hoelzl@51475
    42
hoelzl@51475
    43
lemma cSup_singleton [simp]: "Sup {x} = x"
hoelzl@51475
    44
  by (intro cSup_eq_maximum) auto
hoelzl@51475
    45
hoelzl@51475
    46
lemma cInf_singleton [simp]: "Inf {x} = x"
hoelzl@51475
    47
  by (intro cInf_eq_minimum) auto
hoelzl@51475
    48
hoelzl@51475
    49
lemma cSup_upper2: (*REAL_IMP_LE_SUP in HOL4*)
hoelzl@51475
    50
  "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y \<le> Sup X"
hoelzl@51475
    51
  by (metis cSup_upper order_trans)
hoelzl@51475
    52
 
hoelzl@51475
    53
lemma cInf_lower2:
hoelzl@51475
    54
  "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X \<le> y"
hoelzl@51475
    55
  by (metis cInf_lower order_trans)
hoelzl@51475
    56
hoelzl@51475
    57
lemma cSup_upper_EX: "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> x \<le> z \<Longrightarrow> x \<le> Sup X"
hoelzl@51475
    58
  by (blast intro: cSup_upper)
hoelzl@51475
    59
hoelzl@51475
    60
lemma cInf_lower_EX:  "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> z \<le> x \<Longrightarrow> Inf X \<le> x"
hoelzl@51475
    61
  by (blast intro: cInf_lower)
hoelzl@51475
    62
hoelzl@51475
    63
lemma cSup_eq_non_empty:
hoelzl@51475
    64
  assumes 1: "X \<noteq> {}"
hoelzl@51475
    65
  assumes 2: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
hoelzl@51475
    66
  assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
hoelzl@51475
    67
  shows "Sup X = a"
hoelzl@51475
    68
  by (intro 3 1 antisym cSup_least) (auto intro: 2 1 cSup_upper)
hoelzl@51475
    69
hoelzl@51475
    70
lemma cInf_eq_non_empty:
hoelzl@51475
    71
  assumes 1: "X \<noteq> {}"
hoelzl@51475
    72
  assumes 2: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
hoelzl@51475
    73
  assumes 3: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
hoelzl@51475
    74
  shows "Inf X = a"
hoelzl@51475
    75
  by (intro 3 1 antisym cInf_greatest) (auto intro: 2 1 cInf_lower)
hoelzl@51475
    76
hoelzl@51475
    77
lemma cSup_insert: 
hoelzl@51475
    78
  assumes x: "X \<noteq> {}"
hoelzl@51475
    79
      and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
hoelzl@51475
    80
  shows "Sup (insert a X) = sup a (Sup X)"
hoelzl@51475
    81
proof (intro cSup_eq_non_empty)
hoelzl@51475
    82
  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)
hoelzl@51475
    83
qed (auto intro: le_supI2 z cSup_upper)
paulson@33269
    84
hoelzl@51475
    85
lemma cInf_insert: 
hoelzl@51475
    86
  assumes x: "X \<noteq> {}"
hoelzl@51475
    87
      and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
hoelzl@51475
    88
  shows "Inf (insert a X) = inf a (Inf X)"
hoelzl@51475
    89
proof (intro cInf_eq_non_empty)
hoelzl@51475
    90
  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)
hoelzl@51475
    91
qed (auto intro: le_infI2 z cInf_lower)
hoelzl@51475
    92
hoelzl@51475
    93
lemma cSup_insert_If: 
hoelzl@51475
    94
  "(\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> Sup (insert a X) = (if X = {} then a else sup a (Sup X))"
hoelzl@51475
    95
  using cSup_insert[of X z] by simp
hoelzl@51475
    96
hoelzl@51475
    97
lemma cInf_insert_if: 
hoelzl@51475
    98
  "(\<And>x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf (insert a X) = (if X = {} then a else inf a (Inf X))"
hoelzl@51475
    99
  using cInf_insert[of X z] by simp
hoelzl@51475
   100
hoelzl@51475
   101
lemma le_cSup_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> x \<le> Sup X"
hoelzl@51475
   102
proof (induct X arbitrary: x rule: finite_induct)
hoelzl@51475
   103
  case (insert x X y) then show ?case
hoelzl@51475
   104
    apply (cases "X = {}")
hoelzl@51475
   105
    apply simp
hoelzl@51475
   106
    apply (subst cSup_insert[of _ "Sup X"])
hoelzl@51475
   107
    apply (auto intro: le_supI2)
hoelzl@51475
   108
    done
hoelzl@51475
   109
qed simp
hoelzl@51475
   110
hoelzl@51475
   111
lemma cInf_le_finite: "finite X \<Longrightarrow> x \<in> X \<Longrightarrow> Inf X \<le> x"
hoelzl@51475
   112
proof (induct X arbitrary: x rule: finite_induct)
hoelzl@51475
   113
  case (insert x X y) then show ?case
hoelzl@51475
   114
    apply (cases "X = {}")
hoelzl@51475
   115
    apply simp
hoelzl@51475
   116
    apply (subst cInf_insert[of _ "Inf X"])
hoelzl@51475
   117
    apply (auto intro: le_infI2)
hoelzl@51475
   118
    done
hoelzl@51475
   119
qed simp
hoelzl@51475
   120
hoelzl@51475
   121
lemma cSup_eq_Sup_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Sup_fin X"
hoelzl@51475
   122
proof (induct X rule: finite_ne_induct)
hoelzl@51475
   123
  case (insert x X) then show ?case
hoelzl@51475
   124
    using cSup_insert[of X "Sup_fin X" x] le_cSup_finite[of X] by simp
hoelzl@51475
   125
qed simp
hoelzl@51475
   126
hoelzl@51475
   127
lemma cInf_eq_Inf_fin: "finite X \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Inf_fin X"
hoelzl@51475
   128
proof (induct X rule: finite_ne_induct)
hoelzl@51475
   129
  case (insert x X) then show ?case
hoelzl@51475
   130
    using cInf_insert[of X "Inf_fin X" x] cInf_le_finite[of X] by simp
hoelzl@51475
   131
qed simp
hoelzl@51475
   132
hoelzl@51475
   133
lemma cSup_atMost[simp]: "Sup {..x} = x"
hoelzl@51475
   134
  by (auto intro!: cSup_eq_maximum)
hoelzl@51475
   135
hoelzl@51475
   136
lemma cSup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = x"
hoelzl@51475
   137
  by (auto intro!: cSup_eq_maximum)
hoelzl@51475
   138
hoelzl@51475
   139
lemma cSup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = x"
hoelzl@51475
   140
  by (auto intro!: cSup_eq_maximum)
hoelzl@51475
   141
hoelzl@51475
   142
lemma cInf_atLeast[simp]: "Inf {x..} = x"
hoelzl@51475
   143
  by (auto intro!: cInf_eq_minimum)
hoelzl@51475
   144
hoelzl@51475
   145
lemma cInf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = y"
hoelzl@51475
   146
  by (auto intro!: cInf_eq_minimum)
hoelzl@51475
   147
hoelzl@51475
   148
lemma cInf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = y"
hoelzl@51475
   149
  by (auto intro!: cInf_eq_minimum)
hoelzl@51475
   150
paulson@33269
   151
end
paulson@33269
   152
hoelzl@51475
   153
instance complete_lattice \<subseteq> conditional_complete_lattice
hoelzl@51475
   154
  by default (auto intro: Sup_upper Sup_least Inf_lower Inf_greatest)
hoelzl@51475
   155
hoelzl@51475
   156
lemma isLub_cSup: 
hoelzl@51475
   157
  "(S::'a :: conditional_complete_lattice set) \<noteq> {} \<Longrightarrow> (\<exists>b. S *<= b) \<Longrightarrow> isLub UNIV S (Sup S)"
hoelzl@51475
   158
  by  (auto simp add: isLub_def setle_def leastP_def isUb_def
hoelzl@51475
   159
            intro!: setgeI intro: cSup_upper cSup_least)
hoelzl@51475
   160
hoelzl@51475
   161
lemma cSup_eq:
hoelzl@51475
   162
  fixes a :: "'a :: {conditional_complete_lattice, no_bot}"
hoelzl@51475
   163
  assumes upper: "\<And>x. x \<in> X \<Longrightarrow> x \<le> a"
hoelzl@51475
   164
  assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y"
hoelzl@51475
   165
  shows "Sup X = a"
hoelzl@51475
   166
proof cases
hoelzl@51475
   167
  assume "X = {}" with lt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
hoelzl@51475
   168
qed (intro cSup_eq_non_empty assms)
hoelzl@51475
   169
hoelzl@51475
   170
lemma cInf_eq:
hoelzl@51475
   171
  fixes a :: "'a :: {conditional_complete_lattice, no_top}"
hoelzl@51475
   172
  assumes upper: "\<And>x. x \<in> X \<Longrightarrow> a \<le> x"
hoelzl@51475
   173
  assumes least: "\<And>y. (\<And>x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a"
hoelzl@51475
   174
  shows "Inf X = a"
hoelzl@51475
   175
proof cases
hoelzl@51475
   176
  assume "X = {}" with gt_ex[of a] least show ?thesis by (auto simp: less_le_not_le)
hoelzl@51475
   177
qed (intro cInf_eq_non_empty assms)
hoelzl@51475
   178
hoelzl@51475
   179
lemma cSup_le: "(S::'a::conditional_complete_lattice set) \<noteq> {} \<Longrightarrow> S *<= b \<Longrightarrow> Sup S \<le> b"
hoelzl@51475
   180
  by (metis cSup_least setle_def)
hoelzl@51475
   181
hoelzl@51475
   182
lemma cInf_ge: "(S::'a :: conditional_complete_lattice set) \<noteq> {} \<Longrightarrow> b <=* S \<Longrightarrow> Inf S \<ge> b"
hoelzl@51475
   183
  by (metis cInf_greatest setge_def)
hoelzl@51475
   184
hoelzl@51475
   185
class conditional_complete_linorder = conditional_complete_lattice + linorder
paulson@33269
   186
begin
hoelzl@51475
   187
hoelzl@51475
   188
lemma less_cSup_iff : (*REAL_SUP_LE in HOL4*)
hoelzl@51475
   189
  "X \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y < Sup X \<longleftrightarrow> (\<exists>x\<in>X. y < x)"
hoelzl@51475
   190
  by (rule iffI) (metis cSup_least not_less, metis cSup_upper less_le_trans)
hoelzl@51475
   191
hoelzl@51475
   192
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)"
hoelzl@51475
   193
  by (rule iffI) (metis cInf_greatest not_less, metis cInf_lower le_less_trans)
hoelzl@51475
   194
hoelzl@51475
   195
lemma less_cSupE:
hoelzl@51475
   196
  assumes "y < Sup X" "X \<noteq> {}" obtains x where "x \<in> X" "y < x"
hoelzl@51475
   197
  by (metis cSup_least assms not_le that)
hoelzl@51475
   198
hoelzl@51475
   199
lemma complete_interval:
hoelzl@51475
   200
  assumes "a < b" and "P a" and "\<not> P b"
hoelzl@51475
   201
  shows "\<exists>c. a \<le> c \<and> c \<le> b \<and> (\<forall>x. a \<le> x \<and> x < c \<longrightarrow> P x) \<and>
hoelzl@51475
   202
             (\<forall>d. (\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x) \<longrightarrow> d \<le> c)"
hoelzl@51475
   203
proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
hoelzl@51475
   204
  show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
hoelzl@51475
   205
    by (rule cSup_upper [where z=b], auto)
hoelzl@51475
   206
       (metis `a < b` `\<not> P b` linear less_le)
hoelzl@51475
   207
next
hoelzl@51475
   208
  show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
hoelzl@51475
   209
    apply (rule cSup_least) 
hoelzl@51475
   210
    apply auto
hoelzl@51475
   211
    apply (metis less_le_not_le)
hoelzl@51475
   212
    apply (metis `a<b` `~ P b` linear less_le)
hoelzl@51475
   213
    done
hoelzl@51475
   214
next
hoelzl@51475
   215
  fix x
hoelzl@51475
   216
  assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
hoelzl@51475
   217
  show "P x"
hoelzl@51475
   218
    apply (rule less_cSupE [OF lt], auto)
hoelzl@51475
   219
    apply (metis less_le_not_le)
hoelzl@51475
   220
    apply (metis x) 
hoelzl@51475
   221
    done
hoelzl@51475
   222
next
hoelzl@51475
   223
  fix d
hoelzl@51475
   224
    assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
hoelzl@51475
   225
    thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
hoelzl@51475
   226
      by (rule_tac z="b" in cSup_upper, auto) 
hoelzl@51475
   227
         (metis `a<b` `~ P b` linear less_le)
hoelzl@51475
   228
qed
hoelzl@51475
   229
hoelzl@51475
   230
end
hoelzl@51475
   231
hoelzl@51475
   232
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"
hoelzl@51475
   233
  by (rule cSup_eq) (auto simp: not_le[symmetric] setle_def)
hoelzl@51475
   234
hoelzl@51475
   235
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"
hoelzl@51475
   236
  by (rule cInf_eq) (auto simp: not_le[symmetric] setge_def)
hoelzl@51475
   237
hoelzl@51475
   238
lemma cSup_eq_Max: "finite (X::'a::conditional_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Sup X = Max X"
hoelzl@51475
   239
  using cSup_eq_Sup_fin[of X] Sup_fin_eq_Max[of X] by simp
hoelzl@51475
   240
hoelzl@51475
   241
lemma cInf_eq_Min: "finite (X::'a::conditional_complete_linorder set) \<Longrightarrow> X \<noteq> {} \<Longrightarrow> Inf X = Min X"
hoelzl@51475
   242
  using cInf_eq_Inf_fin[of X] Inf_fin_eq_Min[of X] by simp
hoelzl@51475
   243
hoelzl@51475
   244
lemma cSup_lessThan[simp]: "Sup {..<x::'a::{conditional_complete_linorder, dense_linorder}} = x"
hoelzl@51475
   245
  by (auto intro!: cSup_eq_non_empty intro: dense_le)
hoelzl@51475
   246
hoelzl@51475
   247
lemma cSup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x::'a::{conditional_complete_linorder, dense_linorder}} = x"
hoelzl@51475
   248
  by (auto intro!: cSup_eq intro: dense_le_bounded)
hoelzl@51475
   249
hoelzl@51475
   250
lemma cSup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x::'a::{conditional_complete_linorder, dense_linorder}} = x"
hoelzl@51475
   251
  by (auto intro!: cSup_eq intro: dense_le_bounded)
hoelzl@51475
   252
hoelzl@51475
   253
lemma cInf_greaterThan[simp]: "Inf {x::'a::{conditional_complete_linorder, dense_linorder} <..} = x"
hoelzl@51475
   254
  by (auto intro!: cInf_eq intro: dense_ge)
hoelzl@51475
   255
hoelzl@51475
   256
lemma cInf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x::'a::{conditional_complete_linorder, dense_linorder}} = y"
hoelzl@51475
   257
  by (auto intro!: cInf_eq intro: dense_ge_bounded)
hoelzl@51475
   258
hoelzl@51475
   259
lemma cInf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x::'a::{conditional_complete_linorder, dense_linorder}} = y"
hoelzl@51475
   260
  by (auto intro!: cInf_eq intro: dense_ge_bounded)
hoelzl@51475
   261
hoelzl@51475
   262
instantiation real :: conditional_complete_linorder
hoelzl@51475
   263
begin
hoelzl@51475
   264
hoelzl@51475
   265
subsection{*Supremum of a set of reals*}
hoelzl@51475
   266
paulson@33269
   267
definition
hoelzl@51475
   268
  Sup_real_def: "Sup X \<equiv> LEAST z::real. \<forall>x\<in>X. x\<le>z"
hoelzl@51475
   269
hoelzl@51475
   270
definition
hoelzl@51475
   271
  Inf_real_def: "Inf (X::real set) \<equiv> - Sup (uminus ` X)"
hoelzl@51475
   272
hoelzl@51475
   273
instance
hoelzl@51475
   274
proof
hoelzl@51475
   275
  { fix z x :: real and X :: "real set"
hoelzl@51475
   276
    assume x: "x \<in> X" and z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
hoelzl@51475
   277
    show "x \<le> Sup X"
hoelzl@51475
   278
    proof (auto simp add: Sup_real_def) 
hoelzl@51475
   279
      from complete_real[of X]
hoelzl@51475
   280
      obtain s where s: "(\<forall>y\<in>X. y \<le> s) & (\<forall>z. ((\<forall>y\<in>X. y \<le> z) --> s \<le> z))"
hoelzl@51475
   281
        by (blast intro: x z)
hoelzl@51475
   282
      hence "x \<le> s"
hoelzl@51475
   283
        by (blast intro: x z)
hoelzl@51475
   284
      also with s have "... = (LEAST z. \<forall>x\<in>X. x \<le> z)"
hoelzl@51475
   285
        by (fast intro: Least_equality [symmetric])  
hoelzl@51475
   286
      finally show "x \<le> (LEAST z. \<forall>x\<in>X. x \<le> z)" .
hoelzl@51475
   287
    qed }
hoelzl@51475
   288
  note Sup_upper = this
paulson@33269
   289
hoelzl@51475
   290
  { fix z :: real and X :: "real set"
hoelzl@51475
   291
    assume x: "X \<noteq> {}"
hoelzl@51475
   292
        and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
hoelzl@51475
   293
    show "Sup X \<le> z"
hoelzl@51475
   294
    proof (auto simp add: Sup_real_def) 
hoelzl@51475
   295
      from complete_real x
hoelzl@51475
   296
      obtain s where s: "(\<forall>y\<in>X. y \<le> s) & (\<forall>z. ((\<forall>y\<in>X. y \<le> z) --> s \<le> z))"
hoelzl@51475
   297
        by (blast intro: z)
hoelzl@51475
   298
      hence "(LEAST z. \<forall>x\<in>X. x \<le> z) = s"
hoelzl@51475
   299
        by (best intro: Least_equality)  
hoelzl@51475
   300
      also with s z have "... \<le> z"
hoelzl@51475
   301
        by blast
hoelzl@51475
   302
      finally show "(LEAST z. \<forall>x\<in>X. x \<le> z) \<le> z" .
hoelzl@51475
   303
    qed }
hoelzl@51475
   304
  note Sup_least = this
hoelzl@51475
   305
hoelzl@51475
   306
  { fix x z :: real and X :: "real set"
hoelzl@51475
   307
    assume x: "x \<in> X" and z: "!!x. x \<in> X \<Longrightarrow> z \<le> x"
hoelzl@51475
   308
    show "Inf X \<le> x"
hoelzl@51475
   309
    proof -
hoelzl@51475
   310
      have "-x \<le> Sup (uminus ` X)"
hoelzl@51475
   311
        by (rule Sup_upper[of _ _ "- z"]) (auto simp add: image_iff x z)
hoelzl@51475
   312
      thus ?thesis 
hoelzl@51475
   313
        by (auto simp add: Inf_real_def)
hoelzl@51475
   314
    qed }
hoelzl@51475
   315
hoelzl@51475
   316
  { fix z :: real and X :: "real set"
hoelzl@51475
   317
    assume x: "X \<noteq> {}"
hoelzl@51475
   318
      and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
hoelzl@51475
   319
    show "z \<le> Inf X"
hoelzl@51475
   320
    proof -
hoelzl@51475
   321
      have "Sup (uminus ` X) \<le> -z"
hoelzl@51475
   322
        using x z by (force intro: Sup_least)
hoelzl@51475
   323
      hence "z \<le> - Sup (uminus ` X)"
hoelzl@51475
   324
        by simp
hoelzl@51475
   325
      thus ?thesis 
hoelzl@51475
   326
        by (auto simp add: Inf_real_def)
hoelzl@51475
   327
    qed }
hoelzl@51475
   328
qed
paulson@33269
   329
end
paulson@33269
   330
paulson@33269
   331
subsection{*Supremum of a set of reals*}
paulson@33269
   332
hoelzl@51475
   333
lemma cSup_abs_le:
paulson@33269
   334
  fixes S :: "real set"
paulson@33269
   335
  shows "S \<noteq> {} \<Longrightarrow> (\<forall>x\<in>S. \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>Sup S\<bar> \<le> a"
hoelzl@51475
   336
by (auto simp add: abs_le_interval_iff intro: cSup_least) (metis cSup_upper2) 
paulson@33269
   337
hoelzl@51475
   338
lemma cSup_bounds:
paulson@33269
   339
  fixes S :: "real set"
paulson@33269
   340
  assumes Se: "S \<noteq> {}" and l: "a <=* S" and u: "S *<= b"
paulson@33269
   341
  shows "a \<le> Sup S \<and> Sup S \<le> b"
paulson@33269
   342
proof-
hoelzl@51475
   343
  from isLub_cSup[OF Se] u have lub: "isLub UNIV S (Sup S)" by blast
paulson@33269
   344
  hence b: "Sup S \<le> b" using u 
paulson@33269
   345
    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def) 
paulson@33269
   346
  from Se obtain y where y: "y \<in> S" by blast
paulson@33269
   347
  from lub l have "a \<le> Sup S"
paulson@33269
   348
    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def)
paulson@33269
   349
       (metis le_iff_sup le_sup_iff y)
paulson@33269
   350
  with b show ?thesis by blast
paulson@33269
   351
qed
paulson@33269
   352
hoelzl@51475
   353
lemma cSup_asclose: 
paulson@33269
   354
  fixes S :: "real set"
paulson@33269
   355
  assumes S:"S \<noteq> {}" and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" shows "\<bar>Sup S - l\<bar> \<le> e"
paulson@33269
   356
proof-
paulson@33269
   357
  have th: "\<And>(x::real) l e. \<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" by arith
hoelzl@51475
   358
  thus ?thesis using S b cSup_bounds[of S "l - e" "l+e"] unfolding th
paulson@33269
   359
    by  (auto simp add: setge_def setle_def)
paulson@33269
   360
qed
paulson@33269
   361
paulson@33269
   362
subsection{*Infimum of a set of reals*}
paulson@33269
   363
hoelzl@51475
   364
lemma cInf_greater:
paulson@33269
   365
  fixes z :: real
hoelzl@51475
   366
  shows "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x\<in>X. x < z"
hoelzl@51475
   367
  by (metis cInf_less_iff not_leE)
paulson@33269
   368
hoelzl@51475
   369
lemma cInf_close:
paulson@33269
   370
  fixes e :: real
paulson@33269
   371
  shows "X \<noteq> {} \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>x \<in> X. x < Inf X + e"
hoelzl@51475
   372
  by (metis add_strict_increasing add_commute cInf_greater linorder_not_le pos_add_strict)
paulson@33269
   373
hoelzl@51475
   374
lemma cInf_finite_in: 
paulson@33269
   375
  fixes S :: "real set"
paulson@33269
   376
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   377
  shows "Inf S \<in> S"
hoelzl@51475
   378
  using cInf_eq_Min[OF fS Se] Min_in[OF fS Se] by metis
paulson@33269
   379
hoelzl@51475
   380
lemma cInf_finite_ge_iff: 
paulson@33269
   381
  fixes S :: "real set"
paulson@33269
   382
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall> x \<in> S. a \<le> x)"
hoelzl@51475
   383
by (metis cInf_eq_Min cInf_finite_in Min_le order_trans)
paulson@33269
   384
hoelzl@51475
   385
lemma cInf_finite_le_iff:
paulson@33269
   386
  fixes S :: "real set"
paulson@33269
   387
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a \<ge> Inf S \<longleftrightarrow> (\<exists> x \<in> S. a \<ge> x)"
hoelzl@51475
   388
by (metis cInf_eq_Min cInf_finite_ge_iff cInf_finite_in Min_le order_antisym linear)
paulson@33269
   389
hoelzl@51475
   390
lemma cInf_finite_gt_iff: 
paulson@33269
   391
  fixes S :: "real set"
paulson@33269
   392
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a < Inf S \<longleftrightarrow> (\<forall> x \<in> S. a < x)"
hoelzl@51475
   393
by (metis cInf_finite_le_iff linorder_not_less)
paulson@33269
   394
hoelzl@51475
   395
lemma cInf_finite_lt_iff: 
paulson@33269
   396
  fixes S :: "real set"
paulson@33269
   397
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a > Inf S \<longleftrightarrow> (\<exists> x \<in> S. a > x)"
hoelzl@51475
   398
by (metis cInf_finite_ge_iff linorder_not_less)
paulson@33269
   399
hoelzl@51475
   400
lemma cInf_abs_ge:
paulson@33269
   401
  fixes S :: "real set"
paulson@33269
   402
  shows "S \<noteq> {} \<Longrightarrow> (\<forall>x\<in>S. \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>Inf S\<bar> \<le> a"
hoelzl@51475
   403
by (simp add: Inf_real_def) (rule cSup_abs_le, auto) 
paulson@33269
   404
hoelzl@51475
   405
lemma cInf_asclose:
paulson@33269
   406
  fixes S :: "real set"
paulson@33269
   407
  assumes S:"S \<noteq> {}" and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" shows "\<bar>Inf S - l\<bar> \<le> e"
paulson@33269
   408
proof -
paulson@33269
   409
  have "\<bar>- Sup (uminus ` S) - l\<bar> =  \<bar>Sup (uminus ` S) - (-l)\<bar>"
paulson@33269
   410
    by auto
paulson@33269
   411
  also have "... \<le> e" 
hoelzl@51475
   412
    apply (rule cSup_asclose) 
paulson@33269
   413
    apply (auto simp add: S)
haftmann@37887
   414
    apply (metis abs_minus_add_cancel b add_commute diff_minus)
paulson@33269
   415
    done
paulson@33269
   416
  finally have "\<bar>- Sup (uminus ` S) - l\<bar> \<le> e" .
paulson@33269
   417
  thus ?thesis
paulson@33269
   418
    by (simp add: Inf_real_def)
paulson@33269
   419
qed
paulson@33269
   420
paulson@33271
   421
subsection{*Relate max and min to Sup and Inf.*}
paulson@33269
   422
hoelzl@51475
   423
lemma real_max_cSup:
paulson@33269
   424
  fixes x :: real
paulson@33269
   425
  shows "max x y = Sup {x,y}"
hoelzl@51475
   426
  by (subst cSup_insert[of _ y]) (simp_all add: sup_max)
paulson@33269
   427
hoelzl@51475
   428
lemma real_min_cInf: 
paulson@33269
   429
  fixes x :: real
paulson@33269
   430
  shows "min x y = Inf {x,y}"
hoelzl@51475
   431
  by (subst cInf_insert[of _ y]) (simp_all add: inf_min)
paulson@33609
   432
paulson@33269
   433
end