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