src/HOL/RComplete.thy
changeset 36795 e05e1283c550
parent 35578 384ad08a1d1b
child 36826 4d4462d644ae
     1.1 --- a/src/HOL/RComplete.thy	Mon May 10 11:47:56 2010 -0700
     1.2 +++ b/src/HOL/RComplete.thy	Mon May 10 12:12:58 2010 -0700
     1.3 @@ -30,92 +30,27 @@
     1.4    FIXME: Can the premise be weakened to @{text "\<forall>x \<in> P. x\<le> y"}?
     1.5  *}
     1.6  
     1.7 +text {* Only used in HOL/Import/HOL4Compat.thy; delete? *}
     1.8 +
     1.9  lemma posreal_complete:
    1.10    assumes positive_P: "\<forall>x \<in> P. (0::real) < x"
    1.11      and not_empty_P: "\<exists>x. x \<in> P"
    1.12      and upper_bound_Ex: "\<exists>y. \<forall>x \<in> P. x<y"
    1.13    shows "\<exists>S. \<forall>y. (\<exists>x \<in> P. y < x) = (y < S)"
    1.14 -proof (rule exI, rule allI)
    1.15 -  fix y
    1.16 -  let ?pP = "{w. real_of_preal w \<in> P}"
    1.17 -
    1.18 -  show "(\<exists>x\<in>P. y < x) = (y < real_of_preal (psup ?pP))"
    1.19 -  proof (cases "0 < y")
    1.20 -    assume neg_y: "\<not> 0 < y"
    1.21 -    show ?thesis
    1.22 -    proof
    1.23 -      assume "\<exists>x\<in>P. y < x"
    1.24 -      have "\<forall>x. y < real_of_preal x"
    1.25 -        using neg_y by (rule real_less_all_real2)
    1.26 -      thus "y < real_of_preal (psup ?pP)" ..
    1.27 -    next
    1.28 -      assume "y < real_of_preal (psup ?pP)"
    1.29 -      obtain "x" where x_in_P: "x \<in> P" using not_empty_P ..
    1.30 -      hence "0 < x" using positive_P by simp
    1.31 -      hence "y < x" using neg_y by simp
    1.32 -      thus "\<exists>x \<in> P. y < x" using x_in_P ..
    1.33 -    qed
    1.34 -  next
    1.35 -    assume pos_y: "0 < y"
    1.36 -
    1.37 -    then obtain py where y_is_py: "y = real_of_preal py"
    1.38 -      by (auto simp add: real_gt_zero_preal_Ex)
    1.39 -
    1.40 -    obtain a where "a \<in> P" using not_empty_P ..
    1.41 -    with positive_P have a_pos: "0 < a" ..
    1.42 -    then obtain pa where "a = real_of_preal pa"
    1.43 -      by (auto simp add: real_gt_zero_preal_Ex)
    1.44 -    hence "pa \<in> ?pP" using `a \<in> P` by auto
    1.45 -    hence pP_not_empty: "?pP \<noteq> {}" by auto
    1.46 -
    1.47 -    obtain sup where sup: "\<forall>x \<in> P. x < sup"
    1.48 -      using upper_bound_Ex ..
    1.49 -    from this and `a \<in> P` have "a < sup" ..
    1.50 -    hence "0 < sup" using a_pos by arith
    1.51 -    then obtain possup where "sup = real_of_preal possup"
    1.52 -      by (auto simp add: real_gt_zero_preal_Ex)
    1.53 -    hence "\<forall>X \<in> ?pP. X \<le> possup"
    1.54 -      using sup by (auto simp add: real_of_preal_lessI)
    1.55 -    with pP_not_empty have psup: "\<And>Z. (\<exists>X \<in> ?pP. Z < X) = (Z < psup ?pP)"
    1.56 -      by (rule preal_complete)
    1.57 -
    1.58 -    show ?thesis
    1.59 -    proof
    1.60 -      assume "\<exists>x \<in> P. y < x"
    1.61 -      then obtain x where x_in_P: "x \<in> P" and y_less_x: "y < x" ..
    1.62 -      hence "0 < x" using pos_y by arith
    1.63 -      then obtain px where x_is_px: "x = real_of_preal px"
    1.64 -        by (auto simp add: real_gt_zero_preal_Ex)
    1.65 -
    1.66 -      have py_less_X: "\<exists>X \<in> ?pP. py < X"
    1.67 -      proof
    1.68 -        show "py < px" using y_is_py and x_is_px and y_less_x
    1.69 -          by (simp add: real_of_preal_lessI)
    1.70 -        show "px \<in> ?pP" using x_in_P and x_is_px by simp
    1.71 -      qed
    1.72 -
    1.73 -      have "(\<exists>X \<in> ?pP. py < X) ==> (py < psup ?pP)"
    1.74 -        using psup by simp
    1.75 -      hence "py < psup ?pP" using py_less_X by simp
    1.76 -      thus "y < real_of_preal (psup {w. real_of_preal w \<in> P})"
    1.77 -        using y_is_py and pos_y by (simp add: real_of_preal_lessI)
    1.78 -    next
    1.79 -      assume y_less_psup: "y < real_of_preal (psup ?pP)"
    1.80 -
    1.81 -      hence "py < psup ?pP" using y_is_py
    1.82 -        by (simp add: real_of_preal_lessI)
    1.83 -      then obtain "X" where py_less_X: "py < X" and X_in_pP: "X \<in> ?pP"
    1.84 -        using psup by auto
    1.85 -      then obtain x where x_is_X: "x = real_of_preal X"
    1.86 -        by (simp add: real_gt_zero_preal_Ex)
    1.87 -      hence "y < x" using py_less_X and y_is_py
    1.88 -        by (simp add: real_of_preal_lessI)
    1.89 -
    1.90 -      moreover have "x \<in> P" using x_is_X and X_in_pP by simp
    1.91 -
    1.92 -      ultimately show "\<exists> x \<in> P. y < x" ..
    1.93 -    qed
    1.94 +proof -
    1.95 +  from upper_bound_Ex have "\<exists>z. \<forall>x\<in>P. x \<le> z"
    1.96 +    by (auto intro: less_imp_le)
    1.97 +  from complete_real [OF not_empty_P this] obtain S
    1.98 +  where S1: "\<And>x. x \<in> P \<Longrightarrow> x \<le> S" and S2: "\<And>z. \<forall>x\<in>P. x \<le> z \<Longrightarrow> S \<le> z" by fast
    1.99 +  have "\<forall>y. (\<exists>x \<in> P. y < x) = (y < S)"
   1.100 +  proof
   1.101 +    fix y show "(\<exists>x\<in>P. y < x) = (y < S)"
   1.102 +      apply (cases "\<exists>x\<in>P. y < x", simp_all)
   1.103 +      apply (clarify, drule S1, simp)
   1.104 +      apply (simp add: not_less S2)
   1.105 +      done
   1.106    qed
   1.107 +  thus ?thesis ..
   1.108  qed
   1.109  
   1.110  text {*
   1.111 @@ -130,89 +65,6 @@
   1.112  
   1.113  
   1.114  text {*
   1.115 -  \medskip Completeness theorem for the positive reals (again).
   1.116 -*}
   1.117 -
   1.118 -lemma posreals_complete:
   1.119 -  assumes positive_S: "\<forall>x \<in> S. 0 < x"
   1.120 -    and not_empty_S: "\<exists>x. x \<in> S"
   1.121 -    and upper_bound_Ex: "\<exists>u. isUb (UNIV::real set) S u"
   1.122 -  shows "\<exists>t. isLub (UNIV::real set) S t"
   1.123 -proof
   1.124 -  let ?pS = "{w. real_of_preal w \<in> S}"
   1.125 -
   1.126 -  obtain u where "isUb UNIV S u" using upper_bound_Ex ..
   1.127 -  hence sup: "\<forall>x \<in> S. x \<le> u" by (simp add: isUb_def setle_def)
   1.128 -
   1.129 -  obtain x where x_in_S: "x \<in> S" using not_empty_S ..
   1.130 -  hence x_gt_zero: "0 < x" using positive_S by simp
   1.131 -  have  "x \<le> u" using sup and x_in_S ..
   1.132 -  hence "0 < u" using x_gt_zero by arith
   1.133 -
   1.134 -  then obtain pu where u_is_pu: "u = real_of_preal pu"
   1.135 -    by (auto simp add: real_gt_zero_preal_Ex)
   1.136 -
   1.137 -  have pS_less_pu: "\<forall>pa \<in> ?pS. pa \<le> pu"
   1.138 -  proof
   1.139 -    fix pa
   1.140 -    assume "pa \<in> ?pS"
   1.141 -    then obtain a where "a \<in> S" and "a = real_of_preal pa"
   1.142 -      by simp
   1.143 -    moreover hence "a \<le> u" using sup by simp
   1.144 -    ultimately show "pa \<le> pu"
   1.145 -      using sup and u_is_pu by (simp add: real_of_preal_le_iff)
   1.146 -  qed
   1.147 -
   1.148 -  have "\<forall>y \<in> S. y \<le> real_of_preal (psup ?pS)"
   1.149 -  proof
   1.150 -    fix y
   1.151 -    assume y_in_S: "y \<in> S"
   1.152 -    hence "0 < y" using positive_S by simp
   1.153 -    then obtain py where y_is_py: "y = real_of_preal py"
   1.154 -      by (auto simp add: real_gt_zero_preal_Ex)
   1.155 -    hence py_in_pS: "py \<in> ?pS" using y_in_S by simp
   1.156 -    with pS_less_pu have "py \<le> psup ?pS"
   1.157 -      by (rule preal_psup_le)
   1.158 -    thus "y \<le> real_of_preal (psup ?pS)"
   1.159 -      using y_is_py by (simp add: real_of_preal_le_iff)
   1.160 -  qed
   1.161 -
   1.162 -  moreover {
   1.163 -    fix x
   1.164 -    assume x_ub_S: "\<forall>y\<in>S. y \<le> x"
   1.165 -    have "real_of_preal (psup ?pS) \<le> x"
   1.166 -    proof -
   1.167 -      obtain "s" where s_in_S: "s \<in> S" using not_empty_S ..
   1.168 -      hence s_pos: "0 < s" using positive_S by simp
   1.169 -
   1.170 -      hence "\<exists> ps. s = real_of_preal ps" by (simp add: real_gt_zero_preal_Ex)
   1.171 -      then obtain "ps" where s_is_ps: "s = real_of_preal ps" ..
   1.172 -      hence ps_in_pS: "ps \<in> {w. real_of_preal w \<in> S}" using s_in_S by simp
   1.173 -
   1.174 -      from x_ub_S have "s \<le> x" using s_in_S ..
   1.175 -      hence "0 < x" using s_pos by simp
   1.176 -      hence "\<exists> px. x = real_of_preal px" by (simp add: real_gt_zero_preal_Ex)
   1.177 -      then obtain "px" where x_is_px: "x = real_of_preal px" ..
   1.178 -
   1.179 -      have "\<forall>pe \<in> ?pS. pe \<le> px"
   1.180 -      proof
   1.181 -        fix pe
   1.182 -        assume "pe \<in> ?pS"
   1.183 -        hence "real_of_preal pe \<in> S" by simp
   1.184 -        hence "real_of_preal pe \<le> x" using x_ub_S by simp
   1.185 -        thus "pe \<le> px" using x_is_px by (simp add: real_of_preal_le_iff)
   1.186 -      qed
   1.187 -
   1.188 -      moreover have "?pS \<noteq> {}" using ps_in_pS by auto
   1.189 -      ultimately have "(psup ?pS) \<le> px" by (simp add: psup_le_ub)
   1.190 -      thus "real_of_preal (psup ?pS) \<le> x" using x_is_px by (simp add: real_of_preal_le_iff)
   1.191 -    qed
   1.192 -  }
   1.193 -  ultimately show "isLub UNIV S (real_of_preal (psup ?pS))"
   1.194 -    by (simp add: isLub_def leastP_def isUb_def setle_def setge_def)
   1.195 -qed
   1.196 -
   1.197 -text {*
   1.198    \medskip reals Completeness (again!)
   1.199  *}
   1.200  
   1.201 @@ -221,87 +73,11 @@
   1.202      and exists_Ub: "\<exists>Y. isUb (UNIV::real set) S Y"
   1.203    shows "\<exists>t. isLub (UNIV :: real set) S t"
   1.204  proof -
   1.205 -  obtain X where X_in_S: "X \<in> S" using notempty_S ..
   1.206 -  obtain Y where Y_isUb: "isUb (UNIV::real set) S Y"
   1.207 -    using exists_Ub ..
   1.208 -  let ?SHIFT = "{z. \<exists>x \<in>S. z = x + (-X) + 1} \<inter> {x. 0 < x}"
   1.209 -
   1.210 -  {
   1.211 -    fix x
   1.212 -    assume "isUb (UNIV::real set) S x"
   1.213 -    hence S_le_x: "\<forall> y \<in> S. y <= x"
   1.214 -      by (simp add: isUb_def setle_def)
   1.215 -    {
   1.216 -      fix s
   1.217 -      assume "s \<in> {z. \<exists>x\<in>S. z = x + - X + 1}"
   1.218 -      hence "\<exists> x \<in> S. s = x + -X + 1" ..
   1.219 -      then obtain x1 where "x1 \<in> S" and "s = x1 + (-X) + 1" ..
   1.220 -      moreover hence "x1 \<le> x" using S_le_x by simp
   1.221 -      ultimately have "s \<le> x + - X + 1" by arith
   1.222 -    }
   1.223 -    then have "isUb (UNIV::real set) ?SHIFT (x + (-X) + 1)"
   1.224 -      by (auto simp add: isUb_def setle_def)
   1.225 -  } note S_Ub_is_SHIFT_Ub = this
   1.226 -
   1.227 -  hence "isUb UNIV ?SHIFT (Y + (-X) + 1)" using Y_isUb by simp
   1.228 -  hence "\<exists>Z. isUb UNIV ?SHIFT Z" ..
   1.229 -  moreover have "\<forall>y \<in> ?SHIFT. 0 < y" by auto
   1.230 -  moreover have shifted_not_empty: "\<exists>u. u \<in> ?SHIFT"
   1.231 -    using X_in_S and Y_isUb by auto
   1.232 -  ultimately obtain t where t_is_Lub: "isLub UNIV ?SHIFT t"
   1.233 -    using posreals_complete [of ?SHIFT] by blast
   1.234 -
   1.235 -  show ?thesis
   1.236 -  proof
   1.237 -    show "isLub UNIV S (t + X + (-1))"
   1.238 -    proof (rule isLubI2)
   1.239 -      {
   1.240 -        fix x
   1.241 -        assume "isUb (UNIV::real set) S x"
   1.242 -        hence "isUb (UNIV::real set) (?SHIFT) (x + (-X) + 1)"
   1.243 -          using S_Ub_is_SHIFT_Ub by simp
   1.244 -        hence "t \<le> (x + (-X) + 1)"
   1.245 -          using t_is_Lub by (simp add: isLub_le_isUb)
   1.246 -        hence "t + X + -1 \<le> x" by arith
   1.247 -      }
   1.248 -      then show "(t + X + -1) <=* Collect (isUb UNIV S)"
   1.249 -        by (simp add: setgeI)
   1.250 -    next
   1.251 -      show "isUb UNIV S (t + X + -1)"
   1.252 -      proof -
   1.253 -        {
   1.254 -          fix y
   1.255 -          assume y_in_S: "y \<in> S"
   1.256 -          have "y \<le> t + X + -1"
   1.257 -          proof -
   1.258 -            obtain "u" where u_in_shift: "u \<in> ?SHIFT" using shifted_not_empty ..
   1.259 -            hence "\<exists> x \<in> S. u = x + - X + 1" by simp
   1.260 -            then obtain "x" where x_and_u: "u = x + - X + 1" ..
   1.261 -            have u_le_t: "u \<le> t" using u_in_shift and t_is_Lub by (simp add: isLubD2)
   1.262 -
   1.263 -            show ?thesis
   1.264 -            proof cases
   1.265 -              assume "y \<le> x"
   1.266 -              moreover have "x = u + X + - 1" using x_and_u by arith
   1.267 -              moreover have "u + X + - 1  \<le> t + X + -1" using u_le_t by arith
   1.268 -              ultimately show "y  \<le> t + X + -1" by arith
   1.269 -            next
   1.270 -              assume "~(y \<le> x)"
   1.271 -              hence x_less_y: "x < y" by arith
   1.272 -
   1.273 -              have "x + (-X) + 1 \<in> ?SHIFT" using x_and_u and u_in_shift by simp
   1.274 -              hence "0 < x + (-X) + 1" by simp
   1.275 -              hence "0 < y + (-X) + 1" using x_less_y by arith
   1.276 -              hence "y + (-X) + 1 \<in> ?SHIFT" using y_in_S by simp
   1.277 -              hence "y + (-X) + 1 \<le> t" using t_is_Lub  by (simp add: isLubD2)
   1.278 -              thus ?thesis by simp
   1.279 -            qed
   1.280 -          qed
   1.281 -        }
   1.282 -        then show ?thesis by (simp add: isUb_def setle_def)
   1.283 -      qed
   1.284 -    qed
   1.285 -  qed
   1.286 +  from assms have "\<exists>X. X \<in> S" and "\<exists>Y. \<forall>x\<in>S. x \<le> Y"
   1.287 +    unfolding isUb_def setle_def by simp_all
   1.288 +  from complete_real [OF this] show ?thesis
   1.289 +    unfolding isLub_def leastP_def setle_def setge_def Ball_def
   1.290 +      Collect_def mem_def isUb_def UNIV_def by simp
   1.291  qed
   1.292  
   1.293  text{*A version of the same theorem without all those predicates!*}
   1.294 @@ -310,13 +86,7 @@
   1.295    assumes "\<exists>y. y\<in>S" and "\<exists>(x::real). \<forall>y\<in>S. y \<le> x"
   1.296    shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) & 
   1.297                 (\<forall>z. ((\<forall>y\<in>S. y \<le> z) --> x \<le> z))"
   1.298 -proof -
   1.299 -  have "\<exists>x. isLub UNIV S x" 
   1.300 -    by (rule reals_complete)
   1.301 -       (auto simp add: isLub_def isUb_def leastP_def setle_def setge_def prems)
   1.302 -  thus ?thesis
   1.303 -    by (metis UNIV_I isLub_isUb isLub_le_isUb isUbD isUb_def setleI)
   1.304 -qed
   1.305 +using assms by (rule complete_real)
   1.306  
   1.307  
   1.308  subsection {* The Archimedean Property of the Reals *}
   1.309 @@ -324,88 +94,11 @@
   1.310  theorem reals_Archimedean:
   1.311    assumes x_pos: "0 < x"
   1.312    shows "\<exists>n. inverse (real (Suc n)) < x"
   1.313 -proof (rule ccontr)
   1.314 -  assume contr: "\<not> ?thesis"
   1.315 -  have "\<forall>n. x * real (Suc n) <= 1"
   1.316 -  proof
   1.317 -    fix n
   1.318 -    from contr have "x \<le> inverse (real (Suc n))"
   1.319 -      by (simp add: linorder_not_less)
   1.320 -    hence "x \<le> (1 / (real (Suc n)))"
   1.321 -      by (simp add: inverse_eq_divide)
   1.322 -    moreover have "0 \<le> real (Suc n)"
   1.323 -      by (rule real_of_nat_ge_zero)
   1.324 -    ultimately have "x * real (Suc n) \<le> (1 / real (Suc n)) * real (Suc n)"
   1.325 -      by (rule mult_right_mono)
   1.326 -    thus "x * real (Suc n) \<le> 1" by simp
   1.327 -  qed
   1.328 -  hence "{z. \<exists>n. z = x * (real (Suc n))} *<= 1"
   1.329 -    by (simp add: setle_def, safe, rule spec)
   1.330 -  hence "isUb (UNIV::real set) {z. \<exists>n. z = x * (real (Suc n))} 1"
   1.331 -    by (simp add: isUbI)
   1.332 -  hence "\<exists>Y. isUb (UNIV::real set) {z. \<exists>n. z = x* (real (Suc n))} Y" ..
   1.333 -  moreover have "\<exists>X. X \<in> {z. \<exists>n. z = x* (real (Suc n))}" by auto
   1.334 -  ultimately have "\<exists>t. isLub UNIV {z. \<exists>n. z = x * real (Suc n)} t"
   1.335 -    by (simp add: reals_complete)
   1.336 -  then obtain "t" where
   1.337 -    t_is_Lub: "isLub UNIV {z. \<exists>n. z = x * real (Suc n)} t" ..
   1.338 -
   1.339 -  have "\<forall>n::nat. x * real n \<le> t + - x"
   1.340 -  proof
   1.341 -    fix n
   1.342 -    from t_is_Lub have "x * real (Suc n) \<le> t"
   1.343 -      by (simp add: isLubD2)
   1.344 -    hence  "x * (real n) + x \<le> t"
   1.345 -      by (simp add: right_distrib real_of_nat_Suc)
   1.346 -    thus  "x * (real n) \<le> t + - x" by arith
   1.347 -  qed
   1.348 -
   1.349 -  hence "\<forall>m. x * real (Suc m) \<le> t + - x" by simp
   1.350 -  hence "{z. \<exists>n. z = x * (real (Suc n))}  *<= (t + - x)"
   1.351 -    by (auto simp add: setle_def)
   1.352 -  hence "isUb (UNIV::real set) {z. \<exists>n. z = x * (real (Suc n))} (t + (-x))"
   1.353 -    by (simp add: isUbI)
   1.354 -  hence "t \<le> t + - x"
   1.355 -    using t_is_Lub by (simp add: isLub_le_isUb)
   1.356 -  thus False using x_pos by arith
   1.357 -qed
   1.358 -
   1.359 -text {*
   1.360 -  There must be other proofs, e.g. @{text "Suc"} of the largest
   1.361 -  integer in the cut representing @{text "x"}.
   1.362 -*}
   1.363 +  unfolding real_of_nat_def using x_pos
   1.364 +  by (rule ex_inverse_of_nat_Suc_less)
   1.365  
   1.366  lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)"
   1.367 -proof cases
   1.368 -  assume "x \<le> 0"
   1.369 -  hence "x < real (1::nat)" by simp
   1.370 -  thus ?thesis ..
   1.371 -next
   1.372 -  assume "\<not> x \<le> 0"
   1.373 -  hence x_greater_zero: "0 < x" by simp
   1.374 -  hence "0 < inverse x" by simp
   1.375 -  then obtain n where "inverse (real (Suc n)) < inverse x"
   1.376 -    using reals_Archimedean by blast
   1.377 -  hence "inverse (real (Suc n)) * x < inverse x * x"
   1.378 -    using x_greater_zero by (rule mult_strict_right_mono)
   1.379 -  hence "inverse (real (Suc n)) * x < 1"
   1.380 -    using x_greater_zero by simp
   1.381 -  hence "real (Suc n) * (inverse (real (Suc n)) * x) < real (Suc n) * 1"
   1.382 -    by (rule mult_strict_left_mono) simp
   1.383 -  hence "x < real (Suc n)"
   1.384 -    by (simp add: algebra_simps)
   1.385 -  thus "\<exists>(n::nat). x < real n" ..
   1.386 -qed
   1.387 -
   1.388 -instance real :: archimedean_field
   1.389 -proof
   1.390 -  fix r :: real
   1.391 -  obtain n :: nat where "r < real n"
   1.392 -    using reals_Archimedean2 ..
   1.393 -  then have "r \<le> of_int (int n)"
   1.394 -    unfolding real_eq_of_nat by simp
   1.395 -  then show "\<exists>z. r \<le> of_int z" ..
   1.396 -qed
   1.397 +  unfolding real_of_nat_def by (rule ex_less_of_nat)
   1.398  
   1.399  lemma reals_Archimedean3:
   1.400    assumes x_greater_zero: "0 < x"
   1.401 @@ -458,7 +151,7 @@
   1.402    have "x = y-(y-x)" by simp
   1.403    also from suc q have "\<dots> < real (Suc p)/real q - inverse (real q)" by arith
   1.404    also have "\<dots> = real p / real q"
   1.405 -    by (simp only: inverse_eq_divide real_diff_def real_of_nat_Suc 
   1.406 +    by (simp only: inverse_eq_divide diff_def real_of_nat_Suc 
   1.407      minus_divide_left add_divide_distrib[THEN sym]) simp
   1.408    finally have "x<r" by (unfold r_def)
   1.409    have "p<Suc p" .. also note main[THEN sym]