src/HOL/RComplete.thy
author bulwahn
Sat Feb 25 09:07:41 2012 +0100 (2012-02-25)
changeset 46671 3a40ea076230
parent 45966 03ce2b2a29a2
child 47108 2a1953f0d20d
permissions -rw-r--r--
removing unnecessary assumptions in RComplete;
simplifying proof in Probability
     1 (*  Title:      HOL/RComplete.thy
     2     Author:     Jacques D. Fleuriot, University of Edinburgh
     3     Author:     Larry Paulson, University of Cambridge
     4     Author:     Jeremy Avigad, Carnegie Mellon University
     5     Author:     Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen
     6 *)
     7 
     8 header {* Completeness of the Reals; Floor and Ceiling Functions *}
     9 
    10 theory RComplete
    11 imports Lubs RealDef
    12 begin
    13 
    14 lemma real_sum_of_halves: "x/2 + x/2 = (x::real)"
    15   by simp
    16 
    17 lemma abs_diff_less_iff:
    18   "(\<bar>x - a\<bar> < (r::'a::linordered_idom)) = (a - r < x \<and> x < a + r)"
    19   by auto
    20 
    21 subsection {* Completeness of Positive Reals *}
    22 
    23 text {*
    24   Supremum property for the set of positive reals
    25 
    26   Let @{text "P"} be a non-empty set of positive reals, with an upper
    27   bound @{text "y"}.  Then @{text "P"} has a least upper bound
    28   (written @{text "S"}).
    29 
    30   FIXME: Can the premise be weakened to @{text "\<forall>x \<in> P. x\<le> y"}?
    31 *}
    32 
    33 text {* Only used in HOL/Import/HOL4Compat.thy; delete? *}
    34 
    35 lemma posreal_complete:
    36   fixes P :: "real set"
    37   assumes not_empty_P: "\<exists>x. x \<in> P"
    38     and upper_bound_Ex: "\<exists>y. \<forall>x \<in> P. x<y"
    39   shows "\<exists>S. \<forall>y. (\<exists>x \<in> P. y < x) = (y < S)"
    40 proof -
    41   from upper_bound_Ex have "\<exists>z. \<forall>x\<in>P. x \<le> z"
    42     by (auto intro: less_imp_le)
    43   from complete_real [OF not_empty_P this] obtain S
    44   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
    45   have "\<forall>y. (\<exists>x \<in> P. y < x) = (y < S)"
    46   proof
    47     fix y show "(\<exists>x\<in>P. y < x) = (y < S)"
    48       apply (cases "\<exists>x\<in>P. y < x", simp_all)
    49       apply (clarify, drule S1, simp)
    50       apply (simp add: not_less S2)
    51       done
    52   qed
    53   thus ?thesis ..
    54 qed
    55 
    56 text {*
    57   \medskip Completeness properties using @{text "isUb"}, @{text "isLub"} etc.
    58 *}
    59 
    60 lemma real_isLub_unique: "[| isLub R S x; isLub R S y |] ==> x = (y::real)"
    61   apply (frule isLub_isUb)
    62   apply (frule_tac x = y in isLub_isUb)
    63   apply (blast intro!: order_antisym dest!: isLub_le_isUb)
    64   done
    65 
    66 
    67 text {*
    68   \medskip reals Completeness (again!)
    69 *}
    70 
    71 lemma reals_complete:
    72   assumes notempty_S: "\<exists>X. X \<in> S"
    73     and exists_Ub: "\<exists>Y. isUb (UNIV::real set) S Y"
    74   shows "\<exists>t. isLub (UNIV :: real set) S t"
    75 proof -
    76   from assms have "\<exists>X. X \<in> S" and "\<exists>Y. \<forall>x\<in>S. x \<le> Y"
    77     unfolding isUb_def setle_def by simp_all
    78   from complete_real [OF this] show ?thesis
    79     by (simp add: isLub_def leastP_def isUb_def setle_def setge_def)
    80 qed
    81 
    82 
    83 subsection {* The Archimedean Property of the Reals *}
    84 
    85 theorem reals_Archimedean:
    86   assumes x_pos: "0 < x"
    87   shows "\<exists>n. inverse (real (Suc n)) < x"
    88   unfolding real_of_nat_def using x_pos
    89   by (rule ex_inverse_of_nat_Suc_less)
    90 
    91 lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)"
    92   unfolding real_of_nat_def by (rule ex_less_of_nat)
    93 
    94 lemma reals_Archimedean3:
    95   assumes x_greater_zero: "0 < x"
    96   shows "\<forall>(y::real). \<exists>(n::nat). y < real n * x"
    97   unfolding real_of_nat_def using `0 < x`
    98   by (auto intro: ex_less_of_nat_mult)
    99 
   100 
   101 subsection{*Density of the Rational Reals in the Reals*}
   102 
   103 text{* This density proof is due to Stefan Richter and was ported by TN.  The
   104 original source is \emph{Real Analysis} by H.L. Royden.
   105 It employs the Archimedean property of the reals. *}
   106 
   107 lemma Rats_dense_in_real:
   108   fixes x :: real
   109   assumes "x < y" shows "\<exists>r\<in>\<rat>. x < r \<and> r < y"
   110 proof -
   111   from `x<y` have "0 < y-x" by simp
   112   with reals_Archimedean obtain q::nat 
   113     where q: "inverse (real q) < y-x" and "0 < q" by auto
   114   def p \<equiv> "ceiling (y * real q) - 1"
   115   def r \<equiv> "of_int p / real q"
   116   from q have "x < y - inverse (real q)" by simp
   117   also have "y - inverse (real q) \<le> r"
   118     unfolding r_def p_def
   119     by (simp add: le_divide_eq left_diff_distrib le_of_int_ceiling `0 < q`)
   120   finally have "x < r" .
   121   moreover have "r < y"
   122     unfolding r_def p_def
   123     by (simp add: divide_less_eq diff_less_eq `0 < q`
   124       less_ceiling_iff [symmetric])
   125   moreover from r_def have "r \<in> \<rat>" by simp
   126   ultimately show ?thesis by fast
   127 qed
   128 
   129 
   130 subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
   131 
   132 lemma number_of_less_real_of_int_iff [simp]:
   133      "((number_of n) < real (m::int)) = (number_of n < m)"
   134 apply auto
   135 apply (rule real_of_int_less_iff [THEN iffD1])
   136 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
   137 done
   138 
   139 lemma number_of_less_real_of_int_iff2 [simp]:
   140      "(real (m::int) < (number_of n)) = (m < number_of n)"
   141 apply auto
   142 apply (rule real_of_int_less_iff [THEN iffD1])
   143 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
   144 done
   145 
   146 lemma number_of_le_real_of_int_iff [simp]:
   147      "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"
   148 by (simp add: linorder_not_less [symmetric])
   149 
   150 lemma number_of_le_real_of_int_iff2 [simp]:
   151      "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"
   152 by (simp add: linorder_not_less [symmetric])
   153 
   154 lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
   155 unfolding real_of_nat_def by simp
   156 
   157 lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
   158 unfolding real_of_nat_def by (simp add: floor_minus)
   159 
   160 lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
   161 unfolding real_of_int_def by simp
   162 
   163 lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
   164 unfolding real_of_int_def by (simp add: floor_minus)
   165 
   166 lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"
   167 unfolding real_of_int_def by (rule floor_exists)
   168 
   169 lemma lemma_floor:
   170   assumes a1: "real m \<le> r" and a2: "r < real n + 1"
   171   shows "m \<le> (n::int)"
   172 proof -
   173   have "real m < real n + 1" using a1 a2 by (rule order_le_less_trans)
   174   also have "... = real (n + 1)" by simp
   175   finally have "m < n + 1" by (simp only: real_of_int_less_iff)
   176   thus ?thesis by arith
   177 qed
   178 
   179 lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
   180 unfolding real_of_int_def by (rule of_int_floor_le)
   181 
   182 lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"
   183 by (auto intro: lemma_floor)
   184 
   185 lemma real_of_int_floor_cancel [simp]:
   186     "(real (floor x) = x) = (\<exists>n::int. x = real n)"
   187   using floor_real_of_int by metis
   188 
   189 lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
   190   unfolding real_of_int_def using floor_unique [of n x] by simp
   191 
   192 lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
   193   unfolding real_of_int_def by (rule floor_unique)
   194 
   195 lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
   196 apply (rule inj_int [THEN injD])
   197 apply (simp add: real_of_nat_Suc)
   198 apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "int n"])
   199 done
   200 
   201 lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
   202 apply (drule order_le_imp_less_or_eq)
   203 apply (auto intro: floor_eq3)
   204 done
   205 
   206 lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
   207   unfolding real_of_int_def using floor_correct [of r] by simp
   208 
   209 lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real(floor r)"
   210   unfolding real_of_int_def using floor_correct [of r] by simp
   211 
   212 lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
   213   unfolding real_of_int_def using floor_correct [of r] by simp
   214 
   215 lemma real_of_int_floor_add_one_gt [simp]: "r < real(floor r) + 1"
   216   unfolding real_of_int_def using floor_correct [of r] by simp
   217 
   218 lemma le_floor: "real a <= x ==> a <= floor x"
   219   unfolding real_of_int_def by (simp add: le_floor_iff)
   220 
   221 lemma real_le_floor: "a <= floor x ==> real a <= x"
   222   unfolding real_of_int_def by (simp add: le_floor_iff)
   223 
   224 lemma le_floor_eq: "(a <= floor x) = (real a <= x)"
   225   unfolding real_of_int_def by (rule le_floor_iff)
   226 
   227 lemma floor_less_eq: "(floor x < a) = (x < real a)"
   228   unfolding real_of_int_def by (rule floor_less_iff)
   229 
   230 lemma less_floor_eq: "(a < floor x) = (real a + 1 <= x)"
   231   unfolding real_of_int_def by (rule less_floor_iff)
   232 
   233 lemma floor_le_eq: "(floor x <= a) = (x < real a + 1)"
   234   unfolding real_of_int_def by (rule floor_le_iff)
   235 
   236 lemma floor_add [simp]: "floor (x + real a) = floor x + a"
   237   unfolding real_of_int_def by (rule floor_add_of_int)
   238 
   239 lemma floor_subtract [simp]: "floor (x - real a) = floor x - a"
   240   unfolding real_of_int_def by (rule floor_diff_of_int)
   241 
   242 lemma le_mult_floor:
   243   assumes "0 \<le> (a :: real)" and "0 \<le> b"
   244   shows "floor a * floor b \<le> floor (a * b)"
   245 proof -
   246   have "real (floor a) \<le> a"
   247     and "real (floor b) \<le> b" by auto
   248   hence "real (floor a * floor b) \<le> a * b"
   249     using assms by (auto intro!: mult_mono)
   250   also have "a * b < real (floor (a * b) + 1)" by auto
   251   finally show ?thesis unfolding real_of_int_less_iff by simp
   252 qed
   253 
   254 lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
   255   unfolding real_of_nat_def by simp
   256 
   257 lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
   258   unfolding real_of_int_def by (rule le_of_int_ceiling)
   259 
   260 lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
   261   unfolding real_of_int_def by simp
   262 
   263 lemma real_of_int_ceiling_cancel [simp]:
   264      "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
   265   using ceiling_real_of_int by metis
   266 
   267 lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
   268   unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp
   269 
   270 lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
   271   unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp
   272 
   273 lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"
   274   unfolding real_of_int_def using ceiling_unique [of n x] by simp
   275 
   276 lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
   277   unfolding real_of_int_def using ceiling_correct [of r] by simp
   278 
   279 lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
   280   unfolding real_of_int_def using ceiling_correct [of r] by simp
   281 
   282 lemma ceiling_le: "x <= real a ==> ceiling x <= a"
   283   unfolding real_of_int_def by (simp add: ceiling_le_iff)
   284 
   285 lemma ceiling_le_real: "ceiling x <= a ==> x <= real a"
   286   unfolding real_of_int_def by (simp add: ceiling_le_iff)
   287 
   288 lemma ceiling_le_eq: "(ceiling x <= a) = (x <= real a)"
   289   unfolding real_of_int_def by (rule ceiling_le_iff)
   290 
   291 lemma less_ceiling_eq: "(a < ceiling x) = (real a < x)"
   292   unfolding real_of_int_def by (rule less_ceiling_iff)
   293 
   294 lemma ceiling_less_eq: "(ceiling x < a) = (x <= real a - 1)"
   295   unfolding real_of_int_def by (rule ceiling_less_iff)
   296 
   297 lemma le_ceiling_eq: "(a <= ceiling x) = (real a - 1 < x)"
   298   unfolding real_of_int_def by (rule le_ceiling_iff)
   299 
   300 lemma ceiling_add [simp]: "ceiling (x + real a) = ceiling x + a"
   301   unfolding real_of_int_def by (rule ceiling_add_of_int)
   302 
   303 lemma ceiling_subtract [simp]: "ceiling (x - real a) = ceiling x - a"
   304   unfolding real_of_int_def by (rule ceiling_diff_of_int)
   305 
   306 
   307 subsection {* Versions for the natural numbers *}
   308 
   309 definition
   310   natfloor :: "real => nat" where
   311   "natfloor x = nat(floor x)"
   312 
   313 definition
   314   natceiling :: "real => nat" where
   315   "natceiling x = nat(ceiling x)"
   316 
   317 lemma natfloor_zero [simp]: "natfloor 0 = 0"
   318   by (unfold natfloor_def, simp)
   319 
   320 lemma natfloor_one [simp]: "natfloor 1 = 1"
   321   by (unfold natfloor_def, simp)
   322 
   323 lemma zero_le_natfloor [simp]: "0 <= natfloor x"
   324   by (unfold natfloor_def, simp)
   325 
   326 lemma natfloor_number_of_eq [simp]: "natfloor (number_of n) = number_of n"
   327   by (unfold natfloor_def, simp)
   328 
   329 lemma natfloor_real_of_nat [simp]: "natfloor(real n) = n"
   330   by (unfold natfloor_def, simp)
   331 
   332 lemma real_natfloor_le: "0 <= x ==> real(natfloor x) <= x"
   333   by (unfold natfloor_def, simp)
   334 
   335 lemma natfloor_neg: "x <= 0 ==> natfloor x = 0"
   336   unfolding natfloor_def by simp
   337 
   338 lemma natfloor_mono: "x <= y ==> natfloor x <= natfloor y"
   339   unfolding natfloor_def by (intro nat_mono floor_mono)
   340 
   341 lemma le_natfloor: "real x <= a ==> x <= natfloor a"
   342   apply (unfold natfloor_def)
   343   apply (subst nat_int [THEN sym])
   344   apply (rule nat_mono)
   345   apply (rule le_floor)
   346   apply simp
   347 done
   348 
   349 lemma natfloor_less_iff: "0 \<le> x \<Longrightarrow> natfloor x < n \<longleftrightarrow> x < real n"
   350   unfolding natfloor_def real_of_nat_def
   351   by (simp add: nat_less_iff floor_less_iff)
   352 
   353 lemma less_natfloor:
   354   assumes "0 \<le> x" and "x < real (n :: nat)"
   355   shows "natfloor x < n"
   356   using assms by (simp add: natfloor_less_iff)
   357 
   358 lemma le_natfloor_eq: "0 <= x ==> (a <= natfloor x) = (real a <= x)"
   359   apply (rule iffI)
   360   apply (rule order_trans)
   361   prefer 2
   362   apply (erule real_natfloor_le)
   363   apply (subst real_of_nat_le_iff)
   364   apply assumption
   365   apply (erule le_natfloor)
   366 done
   367 
   368 lemma le_natfloor_eq_number_of [simp]:
   369     "~ neg((number_of n)::int) ==> 0 <= x ==>
   370       (number_of n <= natfloor x) = (number_of n <= x)"
   371   apply (subst le_natfloor_eq, assumption)
   372   apply simp
   373 done
   374 
   375 lemma le_natfloor_eq_one [simp]: "(1 <= natfloor x) = (1 <= x)"
   376   apply (case_tac "0 <= x")
   377   apply (subst le_natfloor_eq, assumption, simp)
   378   apply (rule iffI)
   379   apply (subgoal_tac "natfloor x <= natfloor 0")
   380   apply simp
   381   apply (rule natfloor_mono)
   382   apply simp
   383   apply simp
   384 done
   385 
   386 lemma natfloor_eq: "real n <= x ==> x < real n + 1 ==> natfloor x = n"
   387   unfolding natfloor_def by (simp add: floor_eq2 [where n="int n"])
   388 
   389 lemma real_natfloor_add_one_gt: "x < real(natfloor x) + 1"
   390   apply (case_tac "0 <= x")
   391   apply (unfold natfloor_def)
   392   apply simp
   393   apply simp_all
   394 done
   395 
   396 lemma real_natfloor_gt_diff_one: "x - 1 < real(natfloor x)"
   397 using real_natfloor_add_one_gt by (simp add: algebra_simps)
   398 
   399 lemma ge_natfloor_plus_one_imp_gt: "natfloor z + 1 <= n ==> z < real n"
   400   apply (subgoal_tac "z < real(natfloor z) + 1")
   401   apply arith
   402   apply (rule real_natfloor_add_one_gt)
   403 done
   404 
   405 lemma natfloor_add [simp]: "0 <= x ==> natfloor (x + real a) = natfloor x + a"
   406   unfolding natfloor_def
   407   unfolding real_of_int_of_nat_eq [symmetric] floor_add
   408   by (simp add: nat_add_distrib)
   409 
   410 lemma natfloor_add_number_of [simp]:
   411     "~neg ((number_of n)::int) ==> 0 <= x ==>
   412       natfloor (x + number_of n) = natfloor x + number_of n"
   413   by (simp add: natfloor_add [symmetric])
   414 
   415 lemma natfloor_add_one: "0 <= x ==> natfloor(x + 1) = natfloor x + 1"
   416   by (simp add: natfloor_add [symmetric] del: One_nat_def)
   417 
   418 lemma natfloor_subtract [simp]:
   419     "natfloor(x - real a) = natfloor x - a"
   420   unfolding natfloor_def real_of_int_of_nat_eq [symmetric] floor_subtract
   421   by simp
   422 
   423 lemma natfloor_div_nat:
   424   assumes "1 <= x" and "y > 0"
   425   shows "natfloor (x / real y) = natfloor x div y"
   426 proof (rule natfloor_eq)
   427   have "(natfloor x) div y * y \<le> natfloor x"
   428     by (rule add_leD1 [where k="natfloor x mod y"], simp)
   429   thus "real (natfloor x div y) \<le> x / real y"
   430     using assms by (simp add: le_divide_eq le_natfloor_eq)
   431   have "natfloor x < (natfloor x) div y * y + y"
   432     apply (subst mod_div_equality [symmetric])
   433     apply (rule add_strict_left_mono)
   434     apply (rule mod_less_divisor)
   435     apply fact
   436     done
   437   thus "x / real y < real (natfloor x div y) + 1"
   438     using assms
   439     by (simp add: divide_less_eq natfloor_less_iff left_distrib)
   440 qed
   441 
   442 lemma le_mult_natfloor:
   443   shows "natfloor a * natfloor b \<le> natfloor (a * b)"
   444   by (cases "0 <= a & 0 <= b")
   445     (auto simp add: le_natfloor_eq mult_nonneg_nonneg mult_mono' real_natfloor_le natfloor_neg)
   446 
   447 lemma natceiling_zero [simp]: "natceiling 0 = 0"
   448   by (unfold natceiling_def, simp)
   449 
   450 lemma natceiling_one [simp]: "natceiling 1 = 1"
   451   by (unfold natceiling_def, simp)
   452 
   453 lemma zero_le_natceiling [simp]: "0 <= natceiling x"
   454   by (unfold natceiling_def, simp)
   455 
   456 lemma natceiling_number_of_eq [simp]: "natceiling (number_of n) = number_of n"
   457   by (unfold natceiling_def, simp)
   458 
   459 lemma natceiling_real_of_nat [simp]: "natceiling(real n) = n"
   460   by (unfold natceiling_def, simp)
   461 
   462 lemma real_natceiling_ge: "x <= real(natceiling x)"
   463   unfolding natceiling_def by (cases "x < 0", simp_all)
   464 
   465 lemma natceiling_neg: "x <= 0 ==> natceiling x = 0"
   466   unfolding natceiling_def by simp
   467 
   468 lemma natceiling_mono: "x <= y ==> natceiling x <= natceiling y"
   469   unfolding natceiling_def by (intro nat_mono ceiling_mono)
   470 
   471 lemma natceiling_le: "x <= real a ==> natceiling x <= a"
   472   unfolding natceiling_def real_of_nat_def
   473   by (simp add: nat_le_iff ceiling_le_iff)
   474 
   475 lemma natceiling_le_eq: "(natceiling x <= a) = (x <= real a)"
   476   unfolding natceiling_def real_of_nat_def
   477   by (simp add: nat_le_iff ceiling_le_iff)
   478 
   479 lemma natceiling_le_eq_number_of [simp]:
   480     "~ neg((number_of n)::int) ==>
   481       (natceiling x <= number_of n) = (x <= number_of n)"
   482   by (simp add: natceiling_le_eq)
   483 
   484 lemma natceiling_le_eq_one: "(natceiling x <= 1) = (x <= 1)"
   485   unfolding natceiling_def
   486   by (simp add: nat_le_iff ceiling_le_iff)
   487 
   488 lemma natceiling_eq: "real n < x ==> x <= real n + 1 ==> natceiling x = n + 1"
   489   unfolding natceiling_def
   490   by (simp add: ceiling_eq2 [where n="int n"])
   491 
   492 lemma natceiling_add [simp]: "0 <= x ==>
   493     natceiling (x + real a) = natceiling x + a"
   494   unfolding natceiling_def
   495   unfolding real_of_int_of_nat_eq [symmetric] ceiling_add
   496   by (simp add: nat_add_distrib)
   497 
   498 lemma natceiling_add_number_of [simp]:
   499     "~ neg ((number_of n)::int) ==> 0 <= x ==>
   500       natceiling (x + number_of n) = natceiling x + number_of n"
   501   by (simp add: natceiling_add [symmetric])
   502 
   503 lemma natceiling_add_one: "0 <= x ==> natceiling(x + 1) = natceiling x + 1"
   504   by (simp add: natceiling_add [symmetric] del: One_nat_def)
   505 
   506 lemma natceiling_subtract [simp]: "natceiling(x - real a) = natceiling x - a"
   507   unfolding natceiling_def real_of_int_of_nat_eq [symmetric] ceiling_subtract
   508   by simp
   509 
   510 subsection {* Exponentiation with floor *}
   511 
   512 lemma floor_power:
   513   assumes "x = real (floor x)"
   514   shows "floor (x ^ n) = floor x ^ n"
   515 proof -
   516   have *: "x ^ n = real (floor x ^ n)"
   517     using assms by (induct n arbitrary: x) simp_all
   518   show ?thesis unfolding real_of_int_inject[symmetric]
   519     unfolding * floor_real_of_int ..
   520 qed
   521 
   522 lemma natfloor_power:
   523   assumes "x = real (natfloor x)"
   524   shows "natfloor (x ^ n) = natfloor x ^ n"
   525 proof -
   526   from assms have "0 \<le> floor x" by auto
   527   note assms[unfolded natfloor_def real_nat_eq_real[OF `0 \<le> floor x`]]
   528   from floor_power[OF this]
   529   show ?thesis unfolding natfloor_def nat_power_eq[OF `0 \<le> floor x`, symmetric]
   530     by simp
   531 qed
   532 
   533 end