src/HOL/SupInf.thy
author haftmann
Mon Jul 12 08:58:13 2010 +0200 (2010-07-12)
changeset 37765 26bdfb7b680b
parent 36777 be5461582d0f
child 37887 2ae085b07f2f
permissions -rw-r--r--
dropped superfluous [code del]s
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
paulson@33269
     9
instantiation real :: Sup 
paulson@33269
    10
begin
paulson@33269
    11
definition
haftmann@37765
    12
  Sup_real_def: "Sup X == (LEAST z::real. \<forall>x\<in>X. x\<le>z)"
paulson@33269
    13
paulson@33269
    14
instance ..
paulson@33269
    15
end
paulson@33269
    16
paulson@33269
    17
instantiation real :: Inf 
paulson@33269
    18
begin
paulson@33269
    19
definition
haftmann@37765
    20
  Inf_real_def: "Inf (X::real set) == - (Sup (uminus ` X))"
paulson@33269
    21
paulson@33269
    22
instance ..
paulson@33269
    23
end
paulson@33269
    24
paulson@33269
    25
subsection{*Supremum of a set of reals*}
paulson@33269
    26
paulson@33269
    27
lemma Sup_upper [intro]: (*REAL_SUP_UBOUND in HOL4*)
paulson@33269
    28
  fixes x :: real
paulson@33269
    29
  assumes x: "x \<in> X"
paulson@33269
    30
      and z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
paulson@33269
    31
  shows "x \<le> Sup X"
paulson@33269
    32
proof (auto simp add: Sup_real_def) 
paulson@33269
    33
  from reals_complete2
paulson@33269
    34
  obtain s where s: "(\<forall>y\<in>X. y \<le> s) & (\<forall>z. ((\<forall>y\<in>X. y \<le> z) --> s \<le> z))"
paulson@33269
    35
    by (blast intro: x z)
paulson@33269
    36
  hence "x \<le> s"
paulson@33269
    37
    by (blast intro: x z)
paulson@33269
    38
  also with s have "... = (LEAST z. \<forall>x\<in>X. x \<le> z)"
paulson@33269
    39
    by (fast intro: Least_equality [symmetric])  
paulson@33269
    40
  finally show "x \<le> (LEAST z. \<forall>x\<in>X. x \<le> z)" .
paulson@33269
    41
qed
paulson@33269
    42
paulson@33269
    43
lemma Sup_least [intro]: (*REAL_IMP_SUP_LE in HOL4*)
paulson@33269
    44
  fixes z :: real
paulson@33269
    45
  assumes x: "X \<noteq> {}"
paulson@33269
    46
      and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
paulson@33269
    47
  shows "Sup X \<le> z"
paulson@33269
    48
proof (auto simp add: Sup_real_def) 
paulson@33269
    49
  from reals_complete2 x
paulson@33269
    50
  obtain s where s: "(\<forall>y\<in>X. y \<le> s) & (\<forall>z. ((\<forall>y\<in>X. y \<le> z) --> s \<le> z))"
paulson@33269
    51
    by (blast intro: z)
paulson@33269
    52
  hence "(LEAST z. \<forall>x\<in>X. x \<le> z) = s"
paulson@33269
    53
    by (best intro: Least_equality)  
paulson@33269
    54
  also with s z have "... \<le> z"
paulson@33269
    55
    by blast
paulson@33269
    56
  finally show "(LEAST z. \<forall>x\<in>X. x \<le> z) \<le> z" .
paulson@33269
    57
qed
paulson@33269
    58
paulson@33609
    59
lemma less_SupE:
paulson@33609
    60
  fixes y :: real
paulson@33609
    61
  assumes "y < Sup X" "X \<noteq> {}"
paulson@33609
    62
  obtains x where "x\<in>X" "y < x"
paulson@33609
    63
by (metis SupInf.Sup_least assms linorder_not_less that)
paulson@33609
    64
paulson@33269
    65
lemma Sup_singleton [simp]: "Sup {x::real} = x"
paulson@33269
    66
  by (force intro: Least_equality simp add: Sup_real_def)
paulson@33269
    67
 
paulson@33269
    68
lemma Sup_eq_maximum: (*REAL_SUP_MAX in HOL4*)
paulson@33269
    69
  fixes z :: real
paulson@33269
    70
  assumes X: "z \<in> X" and z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
paulson@33269
    71
  shows  "Sup X = z"
paulson@33269
    72
  by (force intro: Least_equality X z simp add: Sup_real_def)
paulson@33269
    73
 
paulson@33269
    74
lemma Sup_upper2: (*REAL_IMP_LE_SUP in HOL4*)
paulson@33269
    75
  fixes x :: real
paulson@33269
    76
  shows "x \<in> X \<Longrightarrow> y \<le> x \<Longrightarrow> (!!x. x \<in> X \<Longrightarrow> x \<le> z) \<Longrightarrow> y \<le> Sup X"
huffman@36777
    77
  by (metis Sup_upper order_trans)
paulson@33269
    78
paulson@33269
    79
lemma Sup_real_iff : (*REAL_SUP_LE in HOL4*)
paulson@33269
    80
  fixes z :: real
paulson@33269
    81
  shows "X ~= {} ==> (!!x. x \<in> X ==> x \<le> z) ==> (\<exists>x\<in>X. y<x) <-> y < Sup X"
paulson@33269
    82
  by (metis Sup_least Sup_upper linorder_not_le le_less_trans)
paulson@33269
    83
paulson@33269
    84
lemma Sup_eq:
paulson@33269
    85
  fixes a :: real
paulson@33269
    86
  shows "(!!x. x \<in> X \<Longrightarrow> x \<le> a) 
paulson@33269
    87
        \<Longrightarrow> (!!y. (!!x. x \<in> X \<Longrightarrow> x \<le> y) \<Longrightarrow> a \<le> y) \<Longrightarrow> Sup X = a"
paulson@33269
    88
  by (metis Sup_least Sup_upper add_le_cancel_left diff_add_cancel insert_absorb
huffman@36777
    89
        insert_not_empty order_antisym)
paulson@33269
    90
paulson@33269
    91
lemma Sup_le:
paulson@33269
    92
  fixes S :: "real set"
paulson@33269
    93
  shows "S \<noteq> {} \<Longrightarrow> S *<= b \<Longrightarrow> Sup S \<le> b"
paulson@33269
    94
by (metis SupInf.Sup_least setle_def)
paulson@33269
    95
paulson@33269
    96
lemma Sup_upper_EX: 
paulson@33269
    97
  fixes x :: real
paulson@33269
    98
  shows "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> x \<le> z \<Longrightarrow>  x \<le> Sup X"
paulson@33269
    99
  by blast
paulson@33269
   100
paulson@33269
   101
lemma Sup_insert_nonempty: 
paulson@33269
   102
  fixes x :: real
paulson@33269
   103
  assumes x: "x \<in> X"
paulson@33269
   104
      and z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
paulson@33269
   105
  shows "Sup (insert a X) = max a (Sup X)"
paulson@33269
   106
proof (cases "Sup X \<le> a")
paulson@33269
   107
  case True
paulson@33269
   108
  thus ?thesis
huffman@36007
   109
    apply (simp add: max_def)
paulson@33269
   110
    apply (rule Sup_eq_maximum)
huffman@36007
   111
    apply (rule insertI1)
huffman@36777
   112
    apply (metis Sup_upper [OF _ z] insertE linear order_trans)
paulson@33269
   113
    done
paulson@33269
   114
next
paulson@33269
   115
  case False
paulson@33269
   116
  hence 1:"a < Sup X" by simp
paulson@33269
   117
  have "Sup X \<le> Sup (insert a X)"
paulson@33269
   118
    apply (rule Sup_least)
huffman@36777
   119
    apply (metis ex_in_conv x)
paulson@33269
   120
    apply (rule Sup_upper_EX) 
paulson@33269
   121
    apply blast
huffman@36777
   122
    apply (metis insert_iff linear order_refl order_trans z)
paulson@33269
   123
    done
paulson@33269
   124
  moreover 
paulson@33269
   125
  have "Sup (insert a X) \<le> Sup X"
paulson@33269
   126
    apply (rule Sup_least)
paulson@33269
   127
    apply blast
huffman@36777
   128
    apply (metis False Sup_upper insertE linear z)
paulson@33269
   129
    done
paulson@33269
   130
  ultimately have "Sup (insert a X) = Sup X"
paulson@33269
   131
    by (blast intro:  antisym )
paulson@33269
   132
  thus ?thesis
huffman@36777
   133
    by (metis 1 min_max.le_iff_sup less_le)
paulson@33269
   134
qed
paulson@33269
   135
paulson@33269
   136
lemma Sup_insert_if: 
paulson@33269
   137
  fixes X :: "real set"
paulson@33269
   138
  assumes z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
paulson@33269
   139
  shows "Sup (insert a X) = (if X={} then a else max a (Sup X))"
paulson@33269
   140
by auto (metis Sup_insert_nonempty z) 
paulson@33269
   141
paulson@33269
   142
lemma Sup: 
paulson@33269
   143
  fixes S :: "real set"
paulson@33269
   144
  shows "S \<noteq> {} \<Longrightarrow> (\<exists>b. S *<= b) \<Longrightarrow> isLub UNIV S (Sup S)"
paulson@33269
   145
by  (auto simp add: isLub_def setle_def leastP_def isUb_def intro!: setgeI) 
paulson@33269
   146
paulson@33269
   147
lemma Sup_finite_Max: 
paulson@33269
   148
  fixes S :: "real set"
paulson@33269
   149
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   150
  shows "Sup S = Max S"
paulson@33269
   151
using fS Se
paulson@33269
   152
proof-
paulson@33269
   153
  let ?m = "Max S"
paulson@33269
   154
  from Max_ge[OF fS] have Sm: "\<forall> x\<in> S. x \<le> ?m" by metis
paulson@33269
   155
  with Sup[OF Se] have lub: "isLub UNIV S (Sup S)" by (metis setle_def)
paulson@33269
   156
  from Max_in[OF fS Se] lub have mrS: "?m \<le> Sup S"
paulson@33269
   157
    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def)
paulson@33269
   158
  moreover
paulson@33269
   159
  have "Sup S \<le> ?m" using Sm lub
paulson@33269
   160
    by (auto simp add: isLub_def leastP_def isUb_def setle_def setge_def)
paulson@33269
   161
  ultimately  show ?thesis by arith
paulson@33269
   162
qed
paulson@33269
   163
paulson@33269
   164
lemma Sup_finite_in:
paulson@33269
   165
  fixes S :: "real set"
paulson@33269
   166
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   167
  shows "Sup S \<in> S"
paulson@33269
   168
  using Sup_finite_Max[OF fS Se] Max_in[OF fS Se] by metis
paulson@33269
   169
paulson@33269
   170
lemma Sup_finite_ge_iff: 
paulson@33269
   171
  fixes S :: "real set"
paulson@33269
   172
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   173
  shows "a \<le> Sup S \<longleftrightarrow> (\<exists> x \<in> S. a \<le> x)"
paulson@33269
   174
by (metis Max_ge Se Sup_finite_Max Sup_finite_in fS linorder_not_le less_le_trans)
paulson@33269
   175
paulson@33269
   176
lemma Sup_finite_le_iff: 
paulson@33269
   177
  fixes S :: "real set"
paulson@33269
   178
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   179
  shows "a \<ge> Sup S \<longleftrightarrow> (\<forall> x \<in> S. a \<ge> x)"
huffman@36777
   180
by (metis Max_ge Se Sup_finite_Max Sup_finite_in fS order_trans)
paulson@33269
   181
paulson@33269
   182
lemma Sup_finite_gt_iff: 
paulson@33269
   183
  fixes S :: "real set"
paulson@33269
   184
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   185
  shows "a < Sup S \<longleftrightarrow> (\<exists> x \<in> S. a < x)"
paulson@33269
   186
by (metis Se Sup_finite_le_iff fS linorder_not_less)
paulson@33269
   187
paulson@33269
   188
lemma Sup_finite_lt_iff: 
paulson@33269
   189
  fixes S :: "real set"
paulson@33269
   190
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   191
  shows "a > Sup S \<longleftrightarrow> (\<forall> x \<in> S. a > x)"
paulson@33269
   192
by (metis Se Sup_finite_ge_iff fS linorder_not_less)
paulson@33269
   193
paulson@33269
   194
lemma Sup_unique:
paulson@33269
   195
  fixes S :: "real set"
paulson@33269
   196
  shows "S *<= b \<Longrightarrow> (\<forall>b' < b. \<exists>x \<in> S. b' < x) \<Longrightarrow> Sup S = b"
paulson@33269
   197
unfolding setle_def
paulson@33269
   198
apply (rule Sup_eq, auto) 
paulson@33269
   199
apply (metis linorder_not_less) 
paulson@33269
   200
done
paulson@33269
   201
paulson@33269
   202
lemma Sup_abs_le:
paulson@33269
   203
  fixes S :: "real set"
paulson@33269
   204
  shows "S \<noteq> {} \<Longrightarrow> (\<forall>x\<in>S. \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>Sup S\<bar> \<le> a"
paulson@33269
   205
by (auto simp add: abs_le_interval_iff) (metis Sup_upper2) 
paulson@33269
   206
paulson@33269
   207
lemma Sup_bounds:
paulson@33269
   208
  fixes S :: "real set"
paulson@33269
   209
  assumes Se: "S \<noteq> {}" and l: "a <=* S" and u: "S *<= b"
paulson@33269
   210
  shows "a \<le> Sup S \<and> Sup S \<le> b"
paulson@33269
   211
proof-
paulson@33269
   212
  from Sup[OF Se] u have lub: "isLub UNIV S (Sup S)" by blast
paulson@33269
   213
  hence b: "Sup S \<le> b" using u 
paulson@33269
   214
    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def) 
paulson@33269
   215
  from Se obtain y where y: "y \<in> S" by blast
paulson@33269
   216
  from lub l have "a \<le> Sup S"
paulson@33269
   217
    by (auto simp add: isLub_def leastP_def setle_def setge_def isUb_def)
paulson@33269
   218
       (metis le_iff_sup le_sup_iff y)
paulson@33269
   219
  with b show ?thesis by blast
paulson@33269
   220
qed
paulson@33269
   221
paulson@33269
   222
lemma Sup_asclose: 
paulson@33269
   223
  fixes S :: "real set"
paulson@33269
   224
  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
   225
proof-
paulson@33269
   226
  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
paulson@33269
   227
  thus ?thesis using S b Sup_bounds[of S "l - e" "l+e"] unfolding th
paulson@33269
   228
    by  (auto simp add: setge_def setle_def)
paulson@33269
   229
qed
paulson@33269
   230
hoelzl@35581
   231
lemma Sup_lessThan[simp]: "Sup {..<x} = (x::real)"
hoelzl@35581
   232
  by (auto intro!: Sup_eq intro: dense_le)
hoelzl@35581
   233
hoelzl@35581
   234
lemma Sup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x} = (x::real)"
hoelzl@35581
   235
  by (auto intro!: Sup_eq intro: dense_le_bounded)
hoelzl@35581
   236
hoelzl@35581
   237
lemma Sup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x} = (x::real)"
hoelzl@35581
   238
  by (auto intro!: Sup_eq intro: dense_le_bounded)
hoelzl@35581
   239
hoelzl@35581
   240
lemma Sup_atMost[simp]: "Sup {..x} = (x::real)"
hoelzl@35581
   241
  by (auto intro!: Sup_eq_maximum)
hoelzl@35581
   242
hoelzl@35581
   243
lemma Sup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = (x::real)"
hoelzl@35581
   244
  by (auto intro!: Sup_eq_maximum)
hoelzl@35581
   245
hoelzl@35581
   246
lemma Sup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = (x::real)"
hoelzl@35581
   247
  by (auto intro!: Sup_eq_maximum)
hoelzl@35581
   248
paulson@33269
   249
paulson@33269
   250
subsection{*Infimum of a set of reals*}
paulson@33269
   251
paulson@33269
   252
lemma Inf_lower [intro]: 
paulson@33269
   253
  fixes z :: real
paulson@33269
   254
  assumes x: "x \<in> X"
paulson@33269
   255
      and z: "!!x. x \<in> X \<Longrightarrow> z \<le> x"
paulson@33269
   256
  shows "Inf X \<le> x"
paulson@33269
   257
proof -
paulson@33269
   258
  have "-x \<le> Sup (uminus ` X)"
paulson@33269
   259
    by (rule Sup_upper [where z = "-z"]) (auto simp add: image_iff x z)
paulson@33269
   260
  thus ?thesis 
paulson@33269
   261
    by (auto simp add: Inf_real_def)
paulson@33269
   262
qed
paulson@33269
   263
paulson@33269
   264
lemma Inf_greatest [intro]: 
paulson@33269
   265
  fixes z :: real
paulson@33269
   266
  assumes x: "X \<noteq> {}"
paulson@33269
   267
      and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
paulson@33269
   268
  shows "z \<le> Inf X"
paulson@33269
   269
proof -
huffman@35216
   270
  have "Sup (uminus ` X) \<le> -z" using x z by force
paulson@33269
   271
  hence "z \<le> - Sup (uminus ` X)"
paulson@33269
   272
    by simp
paulson@33269
   273
  thus ?thesis 
paulson@33269
   274
    by (auto simp add: Inf_real_def)
paulson@33269
   275
qed
paulson@33269
   276
paulson@33269
   277
lemma Inf_singleton [simp]: "Inf {x::real} = x"
paulson@33269
   278
  by (simp add: Inf_real_def) 
paulson@33269
   279
 
paulson@33269
   280
lemma Inf_eq_minimum: (*REAL_INF_MIN in HOL4*)
paulson@33269
   281
  fixes z :: real
paulson@33269
   282
  assumes x: "z \<in> X" and z: "!!x. x \<in> X \<Longrightarrow> z \<le> x"
paulson@33269
   283
  shows  "Inf X = z"
paulson@33269
   284
proof -
paulson@33269
   285
  have "Sup (uminus ` X) = -z" using x z
paulson@33269
   286
    by (force intro: Sup_eq_maximum x z)
paulson@33269
   287
  thus ?thesis
paulson@33269
   288
    by (simp add: Inf_real_def) 
paulson@33269
   289
qed
paulson@33269
   290
 
paulson@33269
   291
lemma Inf_lower2:
paulson@33269
   292
  fixes x :: real
paulson@33269
   293
  shows "x \<in> X \<Longrightarrow> x \<le> y \<Longrightarrow> (!!x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> Inf X \<le> y"
huffman@36777
   294
  by (metis Inf_lower order_trans)
paulson@33269
   295
paulson@33269
   296
lemma Inf_real_iff:
paulson@33269
   297
  fixes z :: real
paulson@33269
   298
  shows "X \<noteq> {} \<Longrightarrow> (!!x. x \<in> X \<Longrightarrow> z \<le> x) \<Longrightarrow> (\<exists>x\<in>X. x<y) \<longleftrightarrow> Inf X < y"
huffman@36777
   299
  by (metis Inf_greatest Inf_lower less_le_not_le linear
paulson@33269
   300
            order_less_le_trans)
paulson@33269
   301
paulson@33269
   302
lemma Inf_eq:
paulson@33269
   303
  fixes a :: real
paulson@33269
   304
  shows "(!!x. x \<in> X \<Longrightarrow> a \<le> x) \<Longrightarrow> (!!y. (!!x. x \<in> X \<Longrightarrow> y \<le> x) \<Longrightarrow> y \<le> a) \<Longrightarrow> Inf X = a"
paulson@33269
   305
  by (metis Inf_greatest Inf_lower add_le_cancel_left diff_add_cancel
huffman@36777
   306
        insert_absorb insert_not_empty order_antisym)
paulson@33269
   307
paulson@33269
   308
lemma Inf_ge: 
paulson@33269
   309
  fixes S :: "real set"
paulson@33269
   310
  shows "S \<noteq> {} \<Longrightarrow> b <=* S \<Longrightarrow> Inf S \<ge> b"
paulson@33269
   311
by (metis SupInf.Inf_greatest setge_def)
paulson@33269
   312
paulson@33269
   313
lemma Inf_lower_EX: 
paulson@33269
   314
  fixes x :: real
paulson@33269
   315
  shows "x \<in> X \<Longrightarrow> \<exists>z. \<forall>x. x \<in> X \<longrightarrow> z \<le> x \<Longrightarrow> Inf X \<le> x"
paulson@33269
   316
  by blast
paulson@33269
   317
paulson@33269
   318
lemma Inf_insert_nonempty: 
paulson@33269
   319
  fixes x :: real
paulson@33269
   320
  assumes x: "x \<in> X"
paulson@33269
   321
      and z: "!!x. x \<in> X \<Longrightarrow> z \<le> x"
paulson@33269
   322
  shows "Inf (insert a X) = min a (Inf X)"
paulson@33269
   323
proof (cases "a \<le> Inf X")
paulson@33269
   324
  case True
paulson@33269
   325
  thus ?thesis
paulson@33269
   326
    by (simp add: min_def)
huffman@36777
   327
       (blast intro: Inf_eq_minimum order_trans z)
paulson@33269
   328
next
paulson@33269
   329
  case False
paulson@33269
   330
  hence 1:"Inf X < a" by simp
paulson@33269
   331
  have "Inf (insert a X) \<le> Inf X"
paulson@33269
   332
    apply (rule Inf_greatest)
huffman@36777
   333
    apply (metis ex_in_conv x)
huffman@36007
   334
    apply (rule Inf_lower_EX)
huffman@36007
   335
    apply (erule insertI2)
huffman@36777
   336
    apply (metis insert_iff linear order_refl order_trans z)
paulson@33269
   337
    done
paulson@33269
   338
  moreover 
paulson@33269
   339
  have "Inf X \<le> Inf (insert a X)"
paulson@33269
   340
    apply (rule Inf_greatest)
paulson@33269
   341
    apply blast
huffman@36777
   342
    apply (metis False Inf_lower insertE linear z) 
paulson@33269
   343
    done
paulson@33269
   344
  ultimately have "Inf (insert a X) = Inf X"
paulson@33269
   345
    by (blast intro:  antisym )
paulson@33269
   346
  thus ?thesis
huffman@36777
   347
    by (metis False min_max.inf_absorb2 linear)
paulson@33269
   348
qed
paulson@33269
   349
paulson@33269
   350
lemma Inf_insert_if: 
paulson@33269
   351
  fixes X :: "real set"
paulson@33269
   352
  assumes z:  "!!x. x \<in> X \<Longrightarrow> z \<le> x"
paulson@33269
   353
  shows "Inf (insert a X) = (if X={} then a else min a (Inf X))"
paulson@33269
   354
by auto (metis Inf_insert_nonempty z) 
paulson@33269
   355
paulson@33269
   356
lemma Inf_greater:
paulson@33269
   357
  fixes z :: real
haftmann@35823
   358
  shows "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x \<in> X. x < z"
paulson@33269
   359
  by (metis Inf_real_iff mem_def not_leE)
paulson@33269
   360
paulson@33269
   361
lemma Inf_close:
paulson@33269
   362
  fixes e :: real
paulson@33269
   363
  shows "X \<noteq> {} \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>x \<in> X. x < Inf X + e"
haftmann@35823
   364
  by (metis add_strict_increasing add_commute Inf_greater linorder_not_le pos_add_strict)
paulson@33269
   365
paulson@33269
   366
lemma Inf_finite_Min:
paulson@33269
   367
  fixes S :: "real set"
paulson@33269
   368
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> Inf S = Min S"
paulson@33269
   369
by (simp add: Inf_real_def Sup_finite_Max image_image) 
paulson@33269
   370
paulson@33269
   371
lemma Inf_finite_in: 
paulson@33269
   372
  fixes S :: "real set"
paulson@33269
   373
  assumes fS: "finite S" and Se: "S \<noteq> {}"
paulson@33269
   374
  shows "Inf S \<in> S"
paulson@33269
   375
  using Inf_finite_Min[OF fS Se] Min_in[OF fS Se] by metis
paulson@33269
   376
paulson@33269
   377
lemma Inf_finite_ge_iff: 
paulson@33269
   378
  fixes S :: "real set"
paulson@33269
   379
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a \<le> Inf S \<longleftrightarrow> (\<forall> x \<in> S. a \<le> x)"
huffman@36777
   380
by (metis Inf_finite_Min Inf_finite_in Min_le order_trans)
paulson@33269
   381
paulson@33269
   382
lemma Inf_finite_le_iff:
paulson@33269
   383
  fixes S :: "real set"
paulson@33269
   384
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a \<ge> Inf S \<longleftrightarrow> (\<exists> x \<in> S. a \<ge> x)"
paulson@33269
   385
by (metis Inf_finite_Min Inf_finite_ge_iff Inf_finite_in Min_le
huffman@36777
   386
          order_antisym linear)
paulson@33269
   387
paulson@33269
   388
lemma Inf_finite_gt_iff: 
paulson@33269
   389
  fixes S :: "real set"
paulson@33269
   390
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a < Inf S \<longleftrightarrow> (\<forall> x \<in> S. a < x)"
paulson@33269
   391
by (metis Inf_finite_le_iff linorder_not_less)
paulson@33269
   392
paulson@33269
   393
lemma Inf_finite_lt_iff: 
paulson@33269
   394
  fixes S :: "real set"
paulson@33269
   395
  shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> a > Inf S \<longleftrightarrow> (\<exists> x \<in> S. a > x)"
paulson@33269
   396
by (metis Inf_finite_ge_iff linorder_not_less)
paulson@33269
   397
paulson@33269
   398
lemma Inf_unique:
paulson@33269
   399
  fixes S :: "real set"
paulson@33269
   400
  shows "b <=* S \<Longrightarrow> (\<forall>b' > b. \<exists>x \<in> S. b' > x) \<Longrightarrow> Inf S = b"
paulson@33269
   401
unfolding setge_def
paulson@33269
   402
apply (rule Inf_eq, auto) 
paulson@33269
   403
apply (metis less_le_not_le linorder_not_less) 
paulson@33269
   404
done
paulson@33269
   405
paulson@33269
   406
lemma Inf_abs_ge:
paulson@33269
   407
  fixes S :: "real set"
paulson@33269
   408
  shows "S \<noteq> {} \<Longrightarrow> (\<forall>x\<in>S. \<bar>x\<bar> \<le> a) \<Longrightarrow> \<bar>Inf S\<bar> \<le> a"
paulson@33269
   409
by (simp add: Inf_real_def) (rule Sup_abs_le, auto) 
paulson@33269
   410
paulson@33269
   411
lemma Inf_asclose:
paulson@33269
   412
  fixes S :: "real set"
paulson@33269
   413
  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
   414
proof -
paulson@33269
   415
  have "\<bar>- Sup (uminus ` S) - l\<bar> =  \<bar>Sup (uminus ` S) - (-l)\<bar>"
paulson@33269
   416
    by auto
paulson@33269
   417
  also have "... \<le> e" 
paulson@33269
   418
    apply (rule Sup_asclose) 
paulson@33269
   419
    apply (auto simp add: S)
huffman@36777
   420
    apply (metis abs_minus_add_cancel b add_commute diff_def)
paulson@33269
   421
    done
paulson@33269
   422
  finally have "\<bar>- Sup (uminus ` S) - l\<bar> \<le> e" .
paulson@33269
   423
  thus ?thesis
paulson@33269
   424
    by (simp add: Inf_real_def)
paulson@33269
   425
qed
paulson@33269
   426
hoelzl@35581
   427
lemma Inf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x} = (y::real)"
hoelzl@35581
   428
  by (simp add: Inf_real_def)
hoelzl@35581
   429
hoelzl@35581
   430
lemma Inf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = (y::real)"
hoelzl@35581
   431
  by (simp add: Inf_real_def)
hoelzl@35581
   432
hoelzl@35581
   433
lemma Inf_atLeast[simp]: "Inf {x..} = (x::real)"
hoelzl@35581
   434
  by (simp add: Inf_real_def)
hoelzl@35581
   435
hoelzl@35581
   436
lemma Inf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x} = (y::real)"
hoelzl@35581
   437
  by (simp add: Inf_real_def)
hoelzl@35581
   438
hoelzl@35581
   439
lemma Inf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = (y::real)"
hoelzl@35581
   440
  by (simp add: Inf_real_def)
hoelzl@35581
   441
paulson@33271
   442
subsection{*Relate max and min to Sup and Inf.*}
paulson@33269
   443
paulson@33269
   444
lemma real_max_Sup:
paulson@33269
   445
  fixes x :: real
paulson@33269
   446
  shows "max x y = Sup {x,y}"
paulson@33269
   447
proof-
paulson@33269
   448
  have f: "finite {x, y}" "{x,y} \<noteq> {}"  by simp_all
paulson@33269
   449
  from Sup_finite_le_iff[OF f, of "max x y"] have "Sup {x,y} \<le> max x y" by simp
paulson@33269
   450
  moreover
paulson@33269
   451
  have "max x y \<le> Sup {x,y}" using Sup_finite_ge_iff[OF f, of "max x y"]
paulson@33269
   452
    by (simp add: linorder_linear)
paulson@33269
   453
  ultimately show ?thesis by arith
paulson@33269
   454
qed
paulson@33269
   455
paulson@33269
   456
lemma real_min_Inf: 
paulson@33269
   457
  fixes x :: real
paulson@33269
   458
  shows "min x y = Inf {x,y}"
paulson@33269
   459
proof-
paulson@33269
   460
  have f: "finite {x, y}" "{x,y} \<noteq> {}"  by simp_all
paulson@33269
   461
  from Inf_finite_le_iff[OF f, of "min x y"] have "Inf {x,y} \<le> min x y"
paulson@33269
   462
    by (simp add: linorder_linear)
paulson@33269
   463
  moreover
paulson@33269
   464
  have "min x y \<le> Inf {x,y}" using Inf_finite_ge_iff[OF f, of "min x y"]
paulson@33269
   465
    by simp
paulson@33269
   466
  ultimately show ?thesis by arith
paulson@33269
   467
qed
paulson@33269
   468
paulson@33609
   469
lemma reals_complete_interval:
paulson@33609
   470
  fixes a::real and b::real
paulson@33609
   471
  assumes "a < b" and "P a" and "~P b"
paulson@33609
   472
  shows "\<exists>c. a \<le> c & c \<le> b & (\<forall>x. a \<le> x & x < c --> P x) &
paulson@33609
   473
             (\<forall>d. (\<forall>x. a \<le> x & x < d --> P x) --> d \<le> c)"
paulson@33609
   474
proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
paulson@33609
   475
  show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
paulson@33609
   476
    by (rule SupInf.Sup_upper [where z=b], auto)
huffman@36777
   477
       (metis `a < b` `\<not> P b` linear less_le)
paulson@33609
   478
next
paulson@33609
   479
  show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
paulson@33609
   480
    apply (rule SupInf.Sup_least) 
paulson@33609
   481
    apply (auto simp add: )
paulson@33609
   482
    apply (metis less_le_not_le)
huffman@36777
   483
    apply (metis `a<b` `~ P b` linear less_le)
paulson@33609
   484
    done
paulson@33609
   485
next
paulson@33609
   486
  fix x
paulson@33609
   487
  assume x: "a \<le> x" and lt: "x < Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
paulson@33609
   488
  show "P x"
paulson@33609
   489
    apply (rule less_SupE [OF lt], auto)
paulson@33609
   490
    apply (metis less_le_not_le)
paulson@33609
   491
    apply (metis x) 
paulson@33609
   492
    done
paulson@33609
   493
next
paulson@33609
   494
  fix d
paulson@33609
   495
    assume 0: "\<forall>x. a \<le> x \<and> x < d \<longrightarrow> P x"
paulson@33609
   496
    thus "d \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
paulson@33609
   497
      by (rule_tac z="b" in SupInf.Sup_upper, auto) 
huffman@36777
   498
         (metis `a<b` `~ P b` linear less_le)
paulson@33609
   499
qed
paulson@33609
   500
paulson@33269
   501
end