src/HOL/Real/RComplete.thy
 author paulson Thu Oct 07 15:42:30 2004 +0200 (2004-10-07) changeset 15234 ec91a90c604e parent 15140 322485b816ac child 15539 333a88244569 permissions -rw-r--r--
simplification tweaks for better arithmetic reasoning
```     1 (*  Title       : RComplete.thy
```
```     2     ID          : \$Id\$
```
```     3     Author      : Jacques D. Fleuriot
```
```     4     Copyright   : 1998  University of Cambridge
```
```     5     Copyright   : 2001,2002  University of Edinburgh
```
```     6 Converted to Isar and polished by lcp
```
```     7 *)
```
```     8
```
```     9 header{*Completeness of the Reals; Floor and Ceiling Functions*}
```
```    10
```
```    11 theory RComplete
```
```    12 imports Lubs RealDef
```
```    13 begin
```
```    14
```
```    15 lemma real_sum_of_halves: "x/2 + x/2 = (x::real)"
```
```    16 by simp
```
```    17
```
```    18
```
```    19 subsection{*Completeness of Reals by Supremum Property of type @{typ preal}*}
```
```    20
```
```    21  (*a few lemmas*)
```
```    22 lemma real_sup_lemma1:
```
```    23      "\<forall>x \<in> P. 0 < x ==>
```
```    24       ((\<exists>x \<in> P. y < x) = (\<exists>X. real_of_preal X \<in> P & y < real_of_preal X))"
```
```    25 by (blast dest!: bspec real_gt_zero_preal_Ex [THEN iffD1])
```
```    26
```
```    27 lemma real_sup_lemma2:
```
```    28      "[| \<forall>x \<in> P. 0 < x;  a \<in> P;   \<forall>x \<in> P. x < y |]
```
```    29       ==> (\<exists>X. X\<in> {w. real_of_preal w \<in> P}) &
```
```    30           (\<exists>Y. \<forall>X\<in> {w. real_of_preal w \<in> P}. X < Y)"
```
```    31 apply (rule conjI)
```
```    32 apply (blast dest: bspec real_gt_zero_preal_Ex [THEN iffD1], auto)
```
```    33 apply (drule bspec, assumption)
```
```    34 apply (frule bspec, assumption)
```
```    35 apply (drule order_less_trans, assumption)
```
```    36 apply (drule real_gt_zero_preal_Ex [THEN iffD1], force)
```
```    37 done
```
```    38
```
```    39 (*-------------------------------------------------------------
```
```    40             Completeness of Positive Reals
```
```    41  -------------------------------------------------------------*)
```
```    42
```
```    43 (**
```
```    44  Supremum property for the set of positive reals
```
```    45  FIXME: long proof - should be improved
```
```    46 **)
```
```    47
```
```    48 (*Let P be a non-empty set of positive reals, with an upper bound y.
```
```    49   Then P has a least upper bound (written S).
```
```    50 FIXME: Can the premise be weakened to \<forall>x \<in> P. x\<le> y ??*)
```
```    51 lemma posreal_complete: "[| \<forall>x \<in> P. (0::real) < x;  \<exists>x. x \<in> P;  \<exists>y. \<forall>x \<in> P. x<y |]
```
```    52       ==> (\<exists>S. \<forall>y. (\<exists>x \<in> P. y < x) = (y < S))"
```
```    53 apply (rule_tac x = "real_of_preal (psup ({w. real_of_preal w \<in> P}))" in exI)
```
```    54 apply clarify
```
```    55 apply (case_tac "0 < ya", auto)
```
```    56 apply (frule real_sup_lemma2, assumption+)
```
```    57 apply (drule real_gt_zero_preal_Ex [THEN iffD1])
```
```    58 apply (drule_tac [3] real_less_all_real2, auto)
```
```    59 apply (rule preal_complete [THEN iffD1])
```
```    60 apply (auto intro: order_less_imp_le)
```
```    61 apply (frule real_gt_preal_preal_Ex, force)
```
```    62 (* second part *)
```
```    63 apply (rule real_sup_lemma1 [THEN iffD2], assumption)
```
```    64 apply (auto dest!: real_less_all_real2 real_gt_zero_preal_Ex [THEN iffD1])
```
```    65 apply (frule_tac [2] real_sup_lemma2)
```
```    66 apply (frule real_sup_lemma2, assumption+, clarify)
```
```    67 apply (rule preal_complete [THEN iffD2, THEN bexE])
```
```    68 prefer 3 apply blast
```
```    69 apply (blast intro!: order_less_imp_le)+
```
```    70 done
```
```    71
```
```    72 (*--------------------------------------------------------
```
```    73    Completeness properties using isUb, isLub etc.
```
```    74  -------------------------------------------------------*)
```
```    75
```
```    76 lemma real_isLub_unique: "[| isLub R S x; isLub R S y |] ==> x = (y::real)"
```
```    77 apply (frule isLub_isUb)
```
```    78 apply (frule_tac x = y in isLub_isUb)
```
```    79 apply (blast intro!: order_antisym dest!: isLub_le_isUb)
```
```    80 done
```
```    81
```
```    82 lemma real_order_restrict: "[| (x::real) <=* S'; S <= S' |] ==> x <=* S"
```
```    83 by (unfold setle_def setge_def, blast)
```
```    84
```
```    85 (*----------------------------------------------------------------
```
```    86            Completeness theorem for the positive reals(again)
```
```    87  ----------------------------------------------------------------*)
```
```    88
```
```    89 lemma posreals_complete:
```
```    90      "[| \<forall>x \<in>S. 0 < x;
```
```    91          \<exists>x. x \<in>S;
```
```    92          \<exists>u. isUb (UNIV::real set) S u
```
```    93       |] ==> \<exists>t. isLub (UNIV::real set) S t"
```
```    94 apply (rule_tac x = "real_of_preal (psup ({w. real_of_preal w \<in> S}))" in exI)
```
```    95 apply (auto simp add: isLub_def leastP_def isUb_def)
```
```    96 apply (auto intro!: setleI setgeI dest!: real_gt_zero_preal_Ex [THEN iffD1])
```
```    97 apply (frule_tac x = y in bspec, assumption)
```
```    98 apply (drule real_gt_zero_preal_Ex [THEN iffD1])
```
```    99 apply (auto simp add: real_of_preal_le_iff)
```
```   100 apply (frule_tac y = "real_of_preal ya" in setleD, assumption)
```
```   101 apply (frule real_ge_preal_preal_Ex, safe)
```
```   102 apply (blast intro!: preal_psup_le dest!: setleD intro: real_of_preal_le_iff [THEN iffD1])
```
```   103 apply (frule_tac x = x in bspec, assumption)
```
```   104 apply (frule isUbD2)
```
```   105 apply (drule real_gt_zero_preal_Ex [THEN iffD1])
```
```   106 apply (auto dest!: isUbD real_ge_preal_preal_Ex simp add: real_of_preal_le_iff)
```
```   107 apply (blast dest!: setleD intro!: psup_le_ub intro: real_of_preal_le_iff [THEN iffD1])
```
```   108 done
```
```   109
```
```   110
```
```   111 (*-------------------------------
```
```   112     Lemmas
```
```   113  -------------------------------*)
```
```   114 lemma real_sup_lemma3: "\<forall>y \<in> {z. \<exists>x \<in> P. z = x + (-xa) + 1} Int {x. 0 < x}. 0 < y"
```
```   115 by auto
```
```   116
```
```   117 lemma lemma_le_swap2: "(xa <= S + X + (-Z)) = (xa + (-X) + Z <= (S::real))"
```
```   118 by auto
```
```   119
```
```   120 lemma lemma_real_complete2b: "[| (x::real) + (-X) + 1 <= S; xa <= x |] ==> xa <= S + X + (- 1)"
```
```   121 by arith
```
```   122
```
```   123 (*----------------------------------------------------------
```
```   124       reals Completeness (again!)
```
```   125  ----------------------------------------------------------*)
```
```   126 lemma reals_complete: "[| \<exists>X. X \<in>S;  \<exists>Y. isUb (UNIV::real set) S Y |]
```
```   127       ==> \<exists>t. isLub (UNIV :: real set) S t"
```
```   128 apply safe
```
```   129 apply (subgoal_tac "\<exists>u. u\<in> {z. \<exists>x \<in>S. z = x + (-X) + 1} Int {x. 0 < x}")
```
```   130 apply (subgoal_tac "isUb (UNIV::real set) ({z. \<exists>x \<in>S. z = x + (-X) + 1} Int {x. 0 < x}) (Y + (-X) + 1) ")
```
```   131 apply (cut_tac P = S and xa = X in real_sup_lemma3)
```
```   132 apply (frule posreals_complete [OF _ _ exI], blast, blast, safe)
```
```   133 apply (rule_tac x = "t + X + (- 1) " in exI)
```
```   134 apply (rule isLubI2)
```
```   135 apply (rule_tac [2] setgeI, safe)
```
```   136 apply (subgoal_tac [2] "isUb (UNIV:: real set) ({z. \<exists>x \<in>S. z = x + (-X) + 1} Int {x. 0 < x}) (y + (-X) + 1) ")
```
```   137 apply (drule_tac [2] y = " (y + (- X) + 1) " in isLub_le_isUb)
```
```   138  prefer 2 apply assumption
```
```   139  prefer 2
```
```   140 apply arith
```
```   141 apply (rule setleI [THEN isUbI], safe)
```
```   142 apply (rule_tac x = x and y = y in linorder_cases)
```
```   143 apply (subst lemma_le_swap2)
```
```   144 apply (frule isLubD2)
```
```   145  prefer 2 apply assumption
```
```   146 apply safe
```
```   147 apply blast
```
```   148 apply arith
```
```   149 apply (subst lemma_le_swap2)
```
```   150 apply (frule isLubD2)
```
```   151  prefer 2 apply assumption
```
```   152 apply blast
```
```   153 apply (rule lemma_real_complete2b)
```
```   154 apply (erule_tac [2] order_less_imp_le)
```
```   155 apply (blast intro!: isLubD2, blast)
```
```   156 apply (simp (no_asm_use) add: add_assoc)
```
```   157 apply (blast dest: isUbD intro!: setleI [THEN isUbI] intro: add_right_mono)
```
```   158 apply (blast dest: isUbD intro!: setleI [THEN isUbI] intro: add_right_mono, auto)
```
```   159 done
```
```   160
```
```   161
```
```   162 subsection{*Corollary: the Archimedean Property of the Reals*}
```
```   163
```
```   164 lemma reals_Archimedean: "0 < x ==> \<exists>n. inverse (real(Suc n)) < x"
```
```   165 apply (rule ccontr)
```
```   166 apply (subgoal_tac "\<forall>n. x * real (Suc n) <= 1")
```
```   167  prefer 2
```
```   168 apply (simp add: linorder_not_less inverse_eq_divide, clarify)
```
```   169 apply (drule_tac x = n in spec)
```
```   170 apply (drule_tac c = "real (Suc n)"  in mult_right_mono)
```
```   171 apply (rule real_of_nat_ge_zero)
```
```   172 apply (simp add: times_divide_eq_right real_of_nat_Suc_gt_zero [THEN real_not_refl2, THEN not_sym] mult_commute)
```
```   173 apply (subgoal_tac "isUb (UNIV::real set) {z. \<exists>n. z = x* (real (Suc n))} 1")
```
```   174 apply (subgoal_tac "\<exists>X. X \<in> {z. \<exists>n. z = x* (real (Suc n))}")
```
```   175 apply (drule reals_complete)
```
```   176 apply (auto intro: isUbI setleI)
```
```   177 apply (subgoal_tac "\<forall>m. x* (real (Suc m)) <= t")
```
```   178 apply (simp add: real_of_nat_Suc right_distrib)
```
```   179 prefer 2 apply (blast intro: isLubD2)
```
```   180 apply (simp add: le_diff_eq [symmetric] real_diff_def)
```
```   181 apply (subgoal_tac "isUb (UNIV::real set) {z. \<exists>n. z = x* (real (Suc n))} (t + (-x))")
```
```   182 prefer 2 apply (blast intro!: isUbI setleI)
```
```   183 apply (drule_tac y = "t+ (-x) " in isLub_le_isUb)
```
```   184 apply (auto simp add: real_of_nat_Suc right_distrib)
```
```   185 done
```
```   186
```
```   187 (*There must be other proofs, e.g. Suc of the largest integer in the
```
```   188   cut representing x*)
```
```   189 lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)"
```
```   190 apply (rule_tac x = x and y = 0 in linorder_cases)
```
```   191 apply (rule_tac x = 0 in exI)
```
```   192 apply (rule_tac [2] x = 1 in exI)
```
```   193 apply (auto elim: order_less_trans simp add: real_of_nat_one)
```
```   194 apply (frule positive_imp_inverse_positive [THEN reals_Archimedean], safe)
```
```   195 apply (rule_tac x = "Suc n" in exI)
```
```   196 apply (frule_tac b = "inverse x" in mult_strict_right_mono, auto)
```
```   197 done
```
```   198
```
```   199 lemma reals_Archimedean3: "0 < x ==> \<forall>y. \<exists>(n::nat). y < real n * x"
```
```   200 apply safe
```
```   201 apply (cut_tac x = "y*inverse (x) " in reals_Archimedean2)
```
```   202 apply safe
```
```   203 apply (frule_tac a = "y * inverse x" in mult_strict_right_mono)
```
```   204 apply (auto simp add: mult_assoc real_of_nat_def)
```
```   205 done
```
```   206
```
```   207 ML
```
```   208 {*
```
```   209 val real_sum_of_halves = thm "real_sum_of_halves";
```
```   210 val posreal_complete = thm "posreal_complete";
```
```   211 val real_isLub_unique = thm "real_isLub_unique";
```
```   212 val real_order_restrict = thm "real_order_restrict";
```
```   213 val posreals_complete = thm "posreals_complete";
```
```   214 val reals_complete = thm "reals_complete";
```
```   215 val reals_Archimedean = thm "reals_Archimedean";
```
```   216 val reals_Archimedean2 = thm "reals_Archimedean2";
```
```   217 val reals_Archimedean3 = thm "reals_Archimedean3";
```
```   218 *}
```
```   219
```
```   220
```
```   221 subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
```
```   222
```
```   223 constdefs
```
```   224
```
```   225   floor :: "real => int"
```
```   226    "floor r == (LEAST n::int. r < real (n+1))"
```
```   227
```
```   228   ceiling :: "real => int"
```
```   229     "ceiling r == - floor (- r)"
```
```   230
```
```   231 syntax (xsymbols)
```
```   232   floor :: "real => int"     ("\<lfloor>_\<rfloor>")
```
```   233   ceiling :: "real => int"   ("\<lceil>_\<rceil>")
```
```   234
```
```   235 syntax (HTML output)
```
```   236   floor :: "real => int"     ("\<lfloor>_\<rfloor>")
```
```   237   ceiling :: "real => int"   ("\<lceil>_\<rceil>")
```
```   238
```
```   239
```
```   240 lemma number_of_less_real_of_int_iff [simp]:
```
```   241      "((number_of n) < real (m::int)) = (number_of n < m)"
```
```   242 apply auto
```
```   243 apply (rule real_of_int_less_iff [THEN iffD1])
```
```   244 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
```
```   245 done
```
```   246
```
```   247 lemma number_of_less_real_of_int_iff2 [simp]:
```
```   248      "(real (m::int) < (number_of n)) = (m < number_of n)"
```
```   249 apply auto
```
```   250 apply (rule real_of_int_less_iff [THEN iffD1])
```
```   251 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
```
```   252 done
```
```   253
```
```   254 lemma number_of_le_real_of_int_iff [simp]:
```
```   255      "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"
```
```   256 by (simp add: linorder_not_less [symmetric])
```
```   257
```
```   258 lemma number_of_le_real_of_int_iff2 [simp]:
```
```   259      "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"
```
```   260 by (simp add: linorder_not_less [symmetric])
```
```   261
```
```   262 lemma floor_zero [simp]: "floor 0 = 0"
```
```   263 apply (simp add: floor_def)
```
```   264 apply (rule Least_equality, auto)
```
```   265 done
```
```   266
```
```   267 lemma floor_real_of_nat_zero [simp]: "floor (real (0::nat)) = 0"
```
```   268 by auto
```
```   269
```
```   270 lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
```
```   271 apply (simp only: floor_def)
```
```   272 apply (rule Least_equality)
```
```   273 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
```
```   274 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
```
```   275 apply (simp_all add: real_of_int_real_of_nat)
```
```   276 done
```
```   277
```
```   278 lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
```
```   279 apply (simp only: floor_def)
```
```   280 apply (rule Least_equality)
```
```   281 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
```
```   282 apply (drule_tac [2] real_of_int_minus [THEN subst])
```
```   283 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
```
```   284 apply (simp_all add: real_of_int_real_of_nat)
```
```   285 done
```
```   286
```
```   287 lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
```
```   288 apply (simp only: floor_def)
```
```   289 apply (rule Least_equality)
```
```   290 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
```
```   291 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
```
```   292 done
```
```   293
```
```   294 lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
```
```   295 apply (simp only: floor_def)
```
```   296 apply (rule Least_equality)
```
```   297 apply (drule_tac [2] real_of_int_minus [THEN subst])
```
```   298 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
```
```   299 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
```
```   300 done
```
```   301
```
```   302 lemma reals_Archimedean6:
```
```   303      "0 \<le> r ==> \<exists>(n::nat). real (n - 1) \<le> r & r < real (n)"
```
```   304 apply (insert reals_Archimedean2 [of r], safe)
```
```   305 apply (frule_tac P = "%k. r < real k" and k = n and m = "%x. x"
```
```   306        in ex_has_least_nat, auto)
```
```   307 apply (rule_tac x = x in exI)
```
```   308 apply (case_tac x, simp)
```
```   309 apply (rename_tac x')
```
```   310 apply (drule_tac x = x' in spec, simp)
```
```   311 done
```
```   312
```
```   313 lemma reals_Archimedean6a: "0 \<le> r ==> \<exists>n. real (n) \<le> r & r < real (Suc n)"
```
```   314 by (drule reals_Archimedean6, auto)
```
```   315
```
```   316 lemma reals_Archimedean_6b_int:
```
```   317      "0 \<le> r ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
```
```   318 apply (drule reals_Archimedean6a, auto)
```
```   319 apply (rule_tac x = "int n" in exI)
```
```   320 apply (simp add: real_of_int_real_of_nat real_of_nat_Suc)
```
```   321 done
```
```   322
```
```   323 lemma reals_Archimedean_6c_int:
```
```   324      "r < 0 ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
```
```   325 apply (rule reals_Archimedean_6b_int [of "-r", THEN exE], simp, auto)
```
```   326 apply (rename_tac n)
```
```   327 apply (drule real_le_imp_less_or_eq, auto)
```
```   328 apply (rule_tac x = "- n - 1" in exI)
```
```   329 apply (rule_tac [2] x = "- n" in exI, auto)
```
```   330 done
```
```   331
```
```   332 lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"
```
```   333 apply (case_tac "r < 0")
```
```   334 apply (blast intro: reals_Archimedean_6c_int)
```
```   335 apply (simp only: linorder_not_less)
```
```   336 apply (blast intro: reals_Archimedean_6b_int reals_Archimedean_6c_int)
```
```   337 done
```
```   338
```
```   339 lemma lemma_floor:
```
```   340   assumes a1: "real m \<le> r" and a2: "r < real n + 1"
```
```   341   shows "m \<le> (n::int)"
```
```   342 proof -
```
```   343   have "real m < real n + 1" by (rule order_le_less_trans)
```
```   344   also have "... = real(n+1)" by simp
```
```   345   finally have "m < n+1" by (simp only: real_of_int_less_iff)
```
```   346   thus ?thesis by arith
```
```   347 qed
```
```   348
```
```   349 lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
```
```   350 apply (simp add: floor_def Least_def)
```
```   351 apply (insert real_lb_ub_int [of r], safe)
```
```   352 apply (rule theI2, auto)
```
```   353 done
```
```   354
```
```   355 lemma floor_le: "x < y ==> floor x \<le> floor y"
```
```   356 apply (simp add: floor_def Least_def)
```
```   357 apply (insert real_lb_ub_int [of x])
```
```   358 apply (insert real_lb_ub_int [of y], safe)
```
```   359 apply (rule theI2)
```
```   360 apply (rule_tac [3] theI2, auto)
```
```   361 done
```
```   362
```
```   363 lemma floor_le2: "x \<le> y ==> floor x \<le> floor y"
```
```   364 by (auto dest: real_le_imp_less_or_eq simp add: floor_le)
```
```   365
```
```   366 lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"
```
```   367 by (auto intro: lemma_floor)
```
```   368
```
```   369 lemma real_of_int_floor_cancel [simp]:
```
```   370     "(real (floor x) = x) = (\<exists>n::int. x = real n)"
```
```   371 apply (simp add: floor_def Least_def)
```
```   372 apply (insert real_lb_ub_int [of x], erule exE)
```
```   373 apply (rule theI2)
```
```   374 apply (auto intro: lemma_floor)
```
```   375 done
```
```   376
```
```   377 lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
```
```   378 apply (simp add: floor_def)
```
```   379 apply (rule Least_equality)
```
```   380 apply (auto intro: lemma_floor)
```
```   381 done
```
```   382
```
```   383 lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
```
```   384 apply (simp add: floor_def)
```
```   385 apply (rule Least_equality)
```
```   386 apply (auto intro: lemma_floor)
```
```   387 done
```
```   388
```
```   389 lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
```
```   390 apply (rule inj_int [THEN injD])
```
```   391 apply (simp add: real_of_nat_Suc)
```
```   392 apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "of_nat n"])
```
```   393 done
```
```   394
```
```   395 lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
```
```   396 apply (drule order_le_imp_less_or_eq)
```
```   397 apply (auto intro: floor_eq3)
```
```   398 done
```
```   399
```
```   400 lemma floor_number_of_eq [simp]:
```
```   401      "floor(number_of n :: real) = (number_of n :: int)"
```
```   402 apply (subst real_number_of [symmetric])
```
```   403 apply (rule floor_real_of_int)
```
```   404 done
```
```   405
```
```   406 lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
```
```   407 apply (simp add: floor_def Least_def)
```
```   408 apply (insert real_lb_ub_int [of r], safe)
```
```   409 apply (rule theI2)
```
```   410 apply (auto intro: lemma_floor)
```
```   411 done
```
```   412
```
```   413 lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
```
```   414 apply (insert real_of_int_floor_ge_diff_one [of r])
```
```   415 apply (auto simp del: real_of_int_floor_ge_diff_one)
```
```   416 done
```
```   417
```
```   418
```
```   419 subsection{*Ceiling Function for Positive Reals*}
```
```   420
```
```   421 lemma ceiling_zero [simp]: "ceiling 0 = 0"
```
```   422 by (simp add: ceiling_def)
```
```   423
```
```   424 lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
```
```   425 by (simp add: ceiling_def)
```
```   426
```
```   427 lemma ceiling_real_of_nat_zero [simp]: "ceiling (real (0::nat)) = 0"
```
```   428 by auto
```
```   429
```
```   430 lemma ceiling_floor [simp]: "ceiling (real (floor r)) = floor r"
```
```   431 by (simp add: ceiling_def)
```
```   432
```
```   433 lemma floor_ceiling [simp]: "floor (real (ceiling r)) = ceiling r"
```
```   434 by (simp add: ceiling_def)
```
```   435
```
```   436 lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
```
```   437 apply (simp add: ceiling_def)
```
```   438 apply (subst le_minus_iff, simp)
```
```   439 done
```
```   440
```
```   441 lemma ceiling_le: "x < y ==> ceiling x \<le> ceiling y"
```
```   442 by (simp add: floor_le ceiling_def)
```
```   443
```
```   444 lemma ceiling_le2: "x \<le> y ==> ceiling x \<le> ceiling y"
```
```   445 by (simp add: floor_le2 ceiling_def)
```
```   446
```
```   447 lemma real_of_int_ceiling_cancel [simp]:
```
```   448      "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
```
```   449 apply (auto simp add: ceiling_def)
```
```   450 apply (drule arg_cong [where f = uminus], auto)
```
```   451 apply (rule_tac x = "-n" in exI, auto)
```
```   452 done
```
```   453
```
```   454 lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
```
```   455 apply (simp add: ceiling_def)
```
```   456 apply (rule minus_equation_iff [THEN iffD1])
```
```   457 apply (simp add: floor_eq [where n = "-(n+1)"])
```
```   458 done
```
```   459
```
```   460 lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
```
```   461 by (simp add: ceiling_def floor_eq2 [where n = "-(n+1)"])
```
```   462
```
```   463 lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"
```
```   464 by (simp add: ceiling_def floor_eq2 [where n = "-n"])
```
```   465
```
```   466 lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
```
```   467 by (simp add: ceiling_def)
```
```   468
```
```   469 lemma ceiling_number_of_eq [simp]:
```
```   470      "ceiling (number_of n :: real) = (number_of n)"
```
```   471 apply (subst real_number_of [symmetric])
```
```   472 apply (rule ceiling_real_of_int)
```
```   473 done
```
```   474
```
```   475 lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
```
```   476 apply (rule neg_le_iff_le [THEN iffD1])
```
```   477 apply (simp add: ceiling_def diff_minus)
```
```   478 done
```
```   479
```
```   480 lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
```
```   481 apply (insert real_of_int_ceiling_diff_one_le [of r])
```
```   482 apply (simp del: real_of_int_ceiling_diff_one_le)
```
```   483 done
```
```   484
```
```   485 ML
```
```   486 {*
```
```   487 val number_of_less_real_of_int_iff = thm "number_of_less_real_of_int_iff";
```
```   488 val number_of_less_real_of_int_iff2 = thm "number_of_less_real_of_int_iff2";
```
```   489 val number_of_le_real_of_int_iff = thm "number_of_le_real_of_int_iff";
```
```   490 val number_of_le_real_of_int_iff2 = thm "number_of_le_real_of_int_iff2";
```
```   491 val floor_zero = thm "floor_zero";
```
```   492 val floor_real_of_nat_zero = thm "floor_real_of_nat_zero";
```
```   493 val floor_real_of_nat = thm "floor_real_of_nat";
```
```   494 val floor_minus_real_of_nat = thm "floor_minus_real_of_nat";
```
```   495 val floor_real_of_int = thm "floor_real_of_int";
```
```   496 val floor_minus_real_of_int = thm "floor_minus_real_of_int";
```
```   497 val reals_Archimedean6 = thm "reals_Archimedean6";
```
```   498 val reals_Archimedean6a = thm "reals_Archimedean6a";
```
```   499 val reals_Archimedean_6b_int = thm "reals_Archimedean_6b_int";
```
```   500 val reals_Archimedean_6c_int = thm "reals_Archimedean_6c_int";
```
```   501 val real_lb_ub_int = thm "real_lb_ub_int";
```
```   502 val lemma_floor = thm "lemma_floor";
```
```   503 val real_of_int_floor_le = thm "real_of_int_floor_le";
```
```   504 val floor_le = thm "floor_le";
```
```   505 val floor_le2 = thm "floor_le2";
```
```   506 val lemma_floor2 = thm "lemma_floor2";
```
```   507 val real_of_int_floor_cancel = thm "real_of_int_floor_cancel";
```
```   508 val floor_eq = thm "floor_eq";
```
```   509 val floor_eq2 = thm "floor_eq2";
```
```   510 val floor_eq3 = thm "floor_eq3";
```
```   511 val floor_eq4 = thm "floor_eq4";
```
```   512 val floor_number_of_eq = thm "floor_number_of_eq";
```
```   513 val real_of_int_floor_ge_diff_one = thm "real_of_int_floor_ge_diff_one";
```
```   514 val real_of_int_floor_add_one_ge = thm "real_of_int_floor_add_one_ge";
```
```   515 val ceiling_zero = thm "ceiling_zero";
```
```   516 val ceiling_real_of_nat = thm "ceiling_real_of_nat";
```
```   517 val ceiling_real_of_nat_zero = thm "ceiling_real_of_nat_zero";
```
```   518 val ceiling_floor = thm "ceiling_floor";
```
```   519 val floor_ceiling = thm "floor_ceiling";
```
```   520 val real_of_int_ceiling_ge = thm "real_of_int_ceiling_ge";
```
```   521 val ceiling_le = thm "ceiling_le";
```
```   522 val ceiling_le2 = thm "ceiling_le2";
```
```   523 val real_of_int_ceiling_cancel = thm "real_of_int_ceiling_cancel";
```
```   524 val ceiling_eq = thm "ceiling_eq";
```
```   525 val ceiling_eq2 = thm "ceiling_eq2";
```
```   526 val ceiling_eq3 = thm "ceiling_eq3";
```
```   527 val ceiling_real_of_int = thm "ceiling_real_of_int";
```
```   528 val ceiling_number_of_eq = thm "ceiling_number_of_eq";
```
```   529 val real_of_int_ceiling_diff_one_le = thm "real_of_int_ceiling_diff_one_le";
```
```   530 val real_of_int_ceiling_le_add_one = thm "real_of_int_ceiling_le_add_one";
```
```   531 *}
```
```   532
```
```   533
```
```   534 end
```
```   535
```
```   536
```
```   537
```
```   538
```