src/HOL/SupInf.thy
changeset 36096 abc6a2ea4b88
parent 36007 095b1022e2ae
child 36777 be5461582d0f
equal deleted inserted replaced
36095:059c3568fdc8 36096:abc6a2ea4b88
     3 header {*Sup and Inf Operators on Sets of Reals.*}
     3 header {*Sup and Inf Operators on Sets of Reals.*}
     4 
     4 
     5 theory SupInf
     5 theory SupInf
     6 imports RComplete
     6 imports RComplete
     7 begin
     7 begin
     8 
       
     9 lemma minus_max_eq_min:
       
    10   fixes x :: "'a::{lordered_ab_group_add, linorder}"
       
    11   shows "- (max x y) = min (-x) (-y)"
       
    12 by (metis le_imp_neg_le linorder_linear min_max.inf_absorb2 min_max.le_iff_inf min_max.le_iff_sup min_max.sup_absorb1)
       
    13 
       
    14 lemma minus_min_eq_max:
       
    15   fixes x :: "'a::{lordered_ab_group_add, linorder}"
       
    16   shows "- (min x y) = max (-x) (-y)"
       
    17 by (metis minus_max_eq_min minus_minus)
       
    18 
       
    19 lemma minus_Max_eq_Min [simp]:
       
    20   fixes S :: "'a::{lordered_ab_group_add, linorder} set"
       
    21   shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> - (Max S) = Min (uminus ` S)"
       
    22 proof (induct S rule: finite_ne_induct)
       
    23   case (singleton x)
       
    24   thus ?case by simp
       
    25 next
       
    26   case (insert x S)
       
    27   thus ?case by (simp add: minus_max_eq_min) 
       
    28 qed
       
    29 
       
    30 lemma minus_Min_eq_Max [simp]:
       
    31   fixes S :: "'a::{lordered_ab_group_add, linorder} set"
       
    32   shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> - (Min S) = Max (uminus ` S)"
       
    33 proof (induct S rule: finite_ne_induct)
       
    34   case (singleton x)
       
    35   thus ?case by simp
       
    36 next
       
    37   case (insert x S)
       
    38   thus ?case by (simp add: minus_min_eq_max) 
       
    39 qed
       
    40 
     8 
    41 instantiation real :: Sup 
     9 instantiation real :: Sup 
    42 begin
    10 begin
    43 definition
    11 definition
    44   Sup_real_def [code del]: "Sup X == (LEAST z::real. \<forall>x\<in>X. x\<le>z)"
    12   Sup_real_def [code del]: "Sup X == (LEAST z::real. \<forall>x\<in>X. x\<le>z)"
   136       and z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
   104       and z: "!!x. x \<in> X \<Longrightarrow> x \<le> z"
   137   shows "Sup (insert a X) = max a (Sup X)"
   105   shows "Sup (insert a X) = max a (Sup X)"
   138 proof (cases "Sup X \<le> a")
   106 proof (cases "Sup X \<le> a")
   139   case True
   107   case True
   140   thus ?thesis
   108   thus ?thesis
   141     apply (simp add: max_def) 
   109     apply (simp add: max_def)
   142     apply (rule Sup_eq_maximum)
   110     apply (rule Sup_eq_maximum)
   143     apply (metis insertCI)
   111     apply (rule insertI1)
   144     apply (metis Sup_upper insertE le_iff_sup real_le_linear real_le_trans sup_absorb1 z)     
   112     apply (metis Sup_upper [OF _ z] insertE real_le_linear real_le_trans)
   145     done
   113     done
   146 next
   114 next
   147   case False
   115   case False
   148   hence 1:"a < Sup X" by simp
   116   hence 1:"a < Sup X" by simp
   149   have "Sup X \<le> Sup (insert a X)"
   117   have "Sup X \<le> Sup (insert a X)"
   207 
   175 
   208 lemma Sup_finite_le_iff: 
   176 lemma Sup_finite_le_iff: 
   209   fixes S :: "real set"
   177   fixes S :: "real set"
   210   assumes fS: "finite S" and Se: "S \<noteq> {}"
   178   assumes fS: "finite S" and Se: "S \<noteq> {}"
   211   shows "a \<ge> Sup S \<longleftrightarrow> (\<forall> x \<in> S. a \<ge> x)"
   179   shows "a \<ge> Sup S \<longleftrightarrow> (\<forall> x \<in> S. a \<ge> x)"
   212 by (metis Max_ge Se Sup_finite_Max Sup_finite_in fS le_iff_sup real_le_trans) 
   180 by (metis Max_ge Se Sup_finite_Max Sup_finite_in fS real_le_trans)
   213 
   181 
   214 lemma Sup_finite_gt_iff: 
   182 lemma Sup_finite_gt_iff: 
   215   fixes S :: "real set"
   183   fixes S :: "real set"
   216   assumes fS: "finite S" and Se: "S \<noteq> {}"
   184   assumes fS: "finite S" and Se: "S \<noteq> {}"
   217   shows "a < Sup S \<longleftrightarrow> (\<exists> x \<in> S. a < x)"
   185   shows "a < Sup S \<longleftrightarrow> (\<exists> x \<in> S. a < x)"
   258   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
   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
   259   thus ?thesis using S b Sup_bounds[of S "l - e" "l+e"] unfolding th
   227   thus ?thesis using S b Sup_bounds[of S "l - e" "l+e"] unfolding th
   260     by  (auto simp add: setge_def setle_def)
   228     by  (auto simp add: setge_def setle_def)
   261 qed
   229 qed
   262 
   230 
       
   231 lemma Sup_lessThan[simp]: "Sup {..<x} = (x::real)"
       
   232   by (auto intro!: Sup_eq intro: dense_le)
       
   233 
       
   234 lemma Sup_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Sup {y<..<x} = (x::real)"
       
   235   by (auto intro!: Sup_eq intro: dense_le_bounded)
       
   236 
       
   237 lemma Sup_atLeastLessThan[simp]: "y < x \<Longrightarrow> Sup {y..<x} = (x::real)"
       
   238   by (auto intro!: Sup_eq intro: dense_le_bounded)
       
   239 
       
   240 lemma Sup_atMost[simp]: "Sup {..x} = (x::real)"
       
   241   by (auto intro!: Sup_eq_maximum)
       
   242 
       
   243 lemma Sup_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Sup {y<..x} = (x::real)"
       
   244   by (auto intro!: Sup_eq_maximum)
       
   245 
       
   246 lemma Sup_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Sup {y..x} = (x::real)"
       
   247   by (auto intro!: Sup_eq_maximum)
       
   248 
   263 
   249 
   264 subsection{*Infimum of a set of reals*}
   250 subsection{*Infimum of a set of reals*}
   265 
   251 
   266 lemma Inf_lower [intro]: 
   252 lemma Inf_lower [intro]: 
   267   fixes z :: real
   253   fixes z :: real
   279   fixes z :: real
   265   fixes z :: real
   280   assumes x: "X \<noteq> {}"
   266   assumes x: "X \<noteq> {}"
   281       and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
   267       and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
   282   shows "z \<le> Inf X"
   268   shows "z \<le> Inf X"
   283 proof -
   269 proof -
   284   have "Sup (uminus ` X) \<le> -z" using x z by (force intro: Sup_least)
   270   have "Sup (uminus ` X) \<le> -z" using x z by force
   285   hence "z \<le> - Sup (uminus ` X)"
   271   hence "z \<le> - Sup (uminus ` X)"
   286     by simp
   272     by simp
   287   thus ?thesis 
   273   thus ?thesis 
   288     by (auto simp add: Inf_real_def)
   274     by (auto simp add: Inf_real_def)
   289 qed
   275 qed
   336   shows "Inf (insert a X) = min a (Inf X)"
   322   shows "Inf (insert a X) = min a (Inf X)"
   337 proof (cases "a \<le> Inf X")
   323 proof (cases "a \<le> Inf X")
   338   case True
   324   case True
   339   thus ?thesis
   325   thus ?thesis
   340     by (simp add: min_def)
   326     by (simp add: min_def)
   341        (blast intro: Inf_eq_minimum Inf_lower real_le_refl real_le_trans z) 
   327        (blast intro: Inf_eq_minimum real_le_refl real_le_trans z)
   342 next
   328 next
   343   case False
   329   case False
   344   hence 1:"Inf X < a" by simp
   330   hence 1:"Inf X < a" by simp
   345   have "Inf (insert a X) \<le> Inf X"
   331   have "Inf (insert a X) \<le> Inf X"
   346     apply (rule Inf_greatest)
   332     apply (rule Inf_greatest)
   347     apply (metis empty_psubset_nonempty psubset_eq x)
   333     apply (metis empty_psubset_nonempty psubset_eq x)
   348     apply (rule Inf_lower_EX) 
   334     apply (rule Inf_lower_EX)
   349     apply (blast intro: elim:) 
   335     apply (erule insertI2)
   350     apply (metis insert_iff real_le_linear real_le_refl real_le_trans z)
   336     apply (metis insert_iff real_le_linear real_le_refl real_le_trans z)
   351     done
   337     done
   352   moreover 
   338   moreover 
   353   have "Inf X \<le> Inf (insert a X)"
   339   have "Inf X \<le> Inf (insert a X)"
   354     apply (rule Inf_greatest)
   340     apply (rule Inf_greatest)
   367   shows "Inf (insert a X) = (if X={} then a else min a (Inf X))"
   353   shows "Inf (insert a X) = (if X={} then a else min a (Inf X))"
   368 by auto (metis Inf_insert_nonempty z) 
   354 by auto (metis Inf_insert_nonempty z) 
   369 
   355 
   370 lemma Inf_greater:
   356 lemma Inf_greater:
   371   fixes z :: real
   357   fixes z :: real
   372   shows "X \<noteq> {} \<Longrightarrow>  Inf X < z \<Longrightarrow> \<exists>x \<in> X. x < z"
   358   shows "X \<noteq> {} \<Longrightarrow> Inf X < z \<Longrightarrow> \<exists>x \<in> X. x < z"
   373   by (metis Inf_real_iff mem_def not_leE)
   359   by (metis Inf_real_iff mem_def not_leE)
   374 
   360 
   375 lemma Inf_close:
   361 lemma Inf_close:
   376   fixes e :: real
   362   fixes e :: real
   377   shows "X \<noteq> {} \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>x \<in> X. x < Inf X + e"
   363   shows "X \<noteq> {} \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>x \<in> X. x < Inf X + e"
   378   by (metis add_strict_increasing comm_monoid_add.mult_commute Inf_greater linorder_not_le pos_add_strict)
   364   by (metis add_strict_increasing add_commute Inf_greater linorder_not_le pos_add_strict)
   379 
   365 
   380 lemma Inf_finite_Min:
   366 lemma Inf_finite_Min:
   381   fixes S :: "real set"
   367   fixes S :: "real set"
   382   shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> Inf S = Min S"
   368   shows "finite S \<Longrightarrow> S \<noteq> {} \<Longrightarrow> Inf S = Min S"
   383 by (simp add: Inf_real_def Sup_finite_Max image_image) 
   369 by (simp add: Inf_real_def Sup_finite_Max image_image) 
   429   have "\<bar>- Sup (uminus ` S) - l\<bar> =  \<bar>Sup (uminus ` S) - (-l)\<bar>"
   415   have "\<bar>- Sup (uminus ` S) - l\<bar> =  \<bar>Sup (uminus ` S) - (-l)\<bar>"
   430     by auto
   416     by auto
   431   also have "... \<le> e" 
   417   also have "... \<le> e" 
   432     apply (rule Sup_asclose) 
   418     apply (rule Sup_asclose) 
   433     apply (auto simp add: S)
   419     apply (auto simp add: S)
   434     apply (metis abs_minus_add_cancel b comm_monoid_add.mult_commute real_diff_def) 
   420     apply (metis abs_minus_add_cancel b add_commute real_diff_def) 
   435     done
   421     done
   436   finally have "\<bar>- Sup (uminus ` S) - l\<bar> \<le> e" .
   422   finally have "\<bar>- Sup (uminus ` S) - l\<bar> \<le> e" .
   437   thus ?thesis
   423   thus ?thesis
   438     by (simp add: Inf_real_def)
   424     by (simp add: Inf_real_def)
   439 qed
   425 qed
       
   426 
       
   427 lemma Inf_greaterThanLessThan[simp]: "y < x \<Longrightarrow> Inf {y<..<x} = (y::real)"
       
   428   by (simp add: Inf_real_def)
       
   429 
       
   430 lemma Inf_atLeastLessThan[simp]: "y < x \<Longrightarrow> Inf {y..<x} = (y::real)"
       
   431   by (simp add: Inf_real_def)
       
   432 
       
   433 lemma Inf_atLeast[simp]: "Inf {x..} = (x::real)"
       
   434   by (simp add: Inf_real_def)
       
   435 
       
   436 lemma Inf_greaterThanAtMost[simp]: "y < x \<Longrightarrow> Inf {y<..x} = (y::real)"
       
   437   by (simp add: Inf_real_def)
       
   438 
       
   439 lemma Inf_atLeastAtMost[simp]: "y \<le> x \<Longrightarrow> Inf {y..x} = (y::real)"
       
   440   by (simp add: Inf_real_def)
   440 
   441 
   441 subsection{*Relate max and min to Sup and Inf.*}
   442 subsection{*Relate max and min to Sup and Inf.*}
   442 
   443 
   443 lemma real_max_Sup:
   444 lemma real_max_Sup:
   444   fixes x :: real
   445   fixes x :: real
   471   shows "\<exists>c. a \<le> c & c \<le> b & (\<forall>x. a \<le> x & x < c --> P x) &
   472   shows "\<exists>c. a \<le> c & c \<le> b & (\<forall>x. a \<le> x & x < c --> P x) &
   472              (\<forall>d. (\<forall>x. a \<le> x & x < d --> P x) --> d \<le> c)"
   473              (\<forall>d. (\<forall>x. a \<le> x & x < d --> P x) --> d \<le> c)"
   473 proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
   474 proof (rule exI [where x = "Sup {d. \<forall>x. a \<le> x & x < d --> P x}"], auto)
   474   show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   475   show "a \<le> Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c}"
   475     by (rule SupInf.Sup_upper [where z=b], auto)
   476     by (rule SupInf.Sup_upper [where z=b], auto)
   476        (metis prems real_le_linear real_less_def) 
   477        (metis `a < b` `\<not> P b` real_le_linear real_less_def)
   477 next
   478 next
   478   show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
   479   show "Sup {d. \<forall>c. a \<le> c \<and> c < d \<longrightarrow> P c} \<le> b"
   479     apply (rule SupInf.Sup_least) 
   480     apply (rule SupInf.Sup_least) 
   480     apply (auto simp add: )
   481     apply (auto simp add: )
   481     apply (metis less_le_not_le)
   482     apply (metis less_le_not_le)