src/HOL/Real.thy
changeset 63040 eb4ddd18d635
parent 62626 de25474ce728
child 63331 247eac9758dd
equal deleted inserted replaced
63039:1a20fd9cf281 63040:eb4ddd18d635
   773   shows "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
   773   shows "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
   774 proof -
   774 proof -
   775   obtain x where x: "x \<in> S" using assms(1) ..
   775   obtain x where x: "x \<in> S" using assms(1) ..
   776   obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) ..
   776   obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) ..
   777 
   777 
   778   def P \<equiv> "\<lambda>x. \<forall>y\<in>S. y \<le> of_rat x"
   778   define P where "P x \<longleftrightarrow> (\<forall>y\<in>S. y \<le> of_rat x)" for x
   779   obtain a where a: "\<not> P a"
   779   obtain a where a: "\<not> P a"
   780   proof
   780   proof
   781     have "of_int \<lfloor>x - 1\<rfloor> \<le> x - 1" by (rule of_int_floor_le)
   781     have "of_int \<lfloor>x - 1\<rfloor> \<le> x - 1" by (rule of_int_floor_le)
   782     also have "x - 1 < x" by simp
   782     also have "x - 1 < x" by simp
   783     finally have "of_int \<lfloor>x - 1\<rfloor> < x" .
   783     finally have "of_int \<lfloor>x - 1\<rfloor> < x" .
   795       also have "z \<le> of_int \<lceil>z\<rceil>" by (rule le_of_int_ceiling)
   795       also have "z \<le> of_int \<lceil>z\<rceil>" by (rule le_of_int_ceiling)
   796       finally show "y \<le> of_int \<lceil>z\<rceil>" .
   796       finally show "y \<le> of_int \<lceil>z\<rceil>" .
   797     qed
   797     qed
   798   qed
   798   qed
   799 
   799 
   800   def avg \<equiv> "\<lambda>x y :: rat. x/2 + y/2"
   800   define avg where "avg x y = x/2 + y/2" for x y :: rat
   801   def bisect \<equiv> "\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y)"
   801   define bisect where "bisect = (\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y))"
   802   def A \<equiv> "\<lambda>n. fst ((bisect ^^ n) (a, b))"
   802   define A where "A n = fst ((bisect ^^ n) (a, b))" for n
   803   def B \<equiv> "\<lambda>n. snd ((bisect ^^ n) (a, b))"
   803   define B where "B n = snd ((bisect ^^ n) (a, b))" for n
   804   def C \<equiv> "\<lambda>n. avg (A n) (B n)"
   804   define C where "C n = avg (A n) (B n)" for n
   805   have A_0 [simp]: "A 0 = a" unfolding A_def by simp
   805   have A_0 [simp]: "A 0 = a" unfolding A_def by simp
   806   have B_0 [simp]: "B 0 = b" unfolding B_def by simp
   806   have B_0 [simp]: "B 0 = b" unfolding B_def by simp
   807   have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)"
   807   have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)"
   808     unfolding A_def B_def C_def bisect_def split_def by simp
   808     unfolding A_def B_def C_def bisect_def split_def by simp
   809   have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)"
   809   have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)"
  1249   assumes "x < y" shows "\<exists>r\<in>\<rat>. x < r \<and> r < y"
  1249   assumes "x < y" shows "\<exists>r\<in>\<rat>. x < r \<and> r < y"
  1250 proof -
  1250 proof -
  1251   from \<open>x<y\<close> have "0 < y-x" by simp
  1251   from \<open>x<y\<close> have "0 < y-x" by simp
  1252   with reals_Archimedean obtain q::nat
  1252   with reals_Archimedean obtain q::nat
  1253     where q: "inverse (real q) < y-x" and "0 < q" by blast
  1253     where q: "inverse (real q) < y-x" and "0 < q" by blast
  1254   def p \<equiv> "\<lceil>y * real q\<rceil> - 1"
  1254   define p where "p = \<lceil>y * real q\<rceil> - 1"
  1255   def r \<equiv> "of_int p / real q"
  1255   define r where "r = of_int p / real q"
  1256   from q have "x < y - inverse (real q)" by simp
  1256   from q have "x < y - inverse (real q)" by simp
  1257   also have "y - inverse (real q) \<le> r"
  1257   also have "y - inverse (real q) \<le> r"
  1258     unfolding r_def p_def
  1258     unfolding r_def p_def
  1259     by (simp add: le_divide_eq left_diff_distrib le_of_int_ceiling \<open>0 < q\<close>)
  1259     by (simp add: le_divide_eq left_diff_distrib le_of_int_ceiling \<open>0 < q\<close>)
  1260   finally have "x < r" .
  1260   finally have "x < r" .