src/HOL/RComplete.thy
 author huffman Fri Sep 02 20:58:31 2011 -0700 (2011-09-02) changeset 44678 21eb31192850 parent 44669 8e6cdb9c00a7 child 44679 a89d0ad8ed20 permissions -rw-r--r--
remove redundant simp rules ceiling_floor and floor_ceiling
     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   assumes positive_P: "\<forall>x \<in> P. (0::real) < x"

    37     and 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     unfolding isLub_def leastP_def setle_def setge_def Ball_def

    80       Collect_def mem_def isUb_def UNIV_def by simp

    81 qed

    82

    83

    84 subsection {* The Archimedean Property of the Reals *}

    85

    86 theorem reals_Archimedean:

    87   assumes x_pos: "0 < x"

    88   shows "\<exists>n. inverse (real (Suc n)) < x"

    89   unfolding real_of_nat_def using x_pos

    90   by (rule ex_inverse_of_nat_Suc_less)

    91

    92 lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)"

    93   unfolding real_of_nat_def by (rule ex_less_of_nat)

    94

    95 lemma reals_Archimedean3:

    96   assumes x_greater_zero: "0 < x"

    97   shows "\<forall>(y::real). \<exists>(n::nat). y < real n * x"

    98   unfolding real_of_nat_def using 0 < x

    99   by (auto intro: ex_less_of_nat_mult)

   100

   101

   102 subsection{*Density of the Rational Reals in the Reals*}

   103

   104 text{* This density proof is due to Stefan Richter and was ported by TN.  The

   105 original source is \emph{Real Analysis} by H.L. Royden.

   106 It employs the Archimedean property of the reals. *}

   107

   108 lemma Rats_dense_in_real:

   109   fixes x :: real

   110   assumes "x < y" shows "\<exists>r\<in>\<rat>. x < r \<and> r < y"

   111 proof -

   112   from x<y have "0 < y-x" by simp

   113   with reals_Archimedean obtain q::nat

   114     where q: "inverse (real q) < y-x" and "0 < q" by auto

   115   def p \<equiv> "ceiling (y * real q) - 1"

   116   def r \<equiv> "of_int p / real q"

   117   from q have "x < y - inverse (real q)" by simp

   118   also have "y - inverse (real q) \<le> r"

   119     unfolding r_def p_def

   120     by (simp add: le_divide_eq left_diff_distrib le_of_int_ceiling 0 < q)

   121   finally have "x < r" .

   122   moreover have "r < y"

   123     unfolding r_def p_def

   124     by (simp add: divide_less_eq diff_less_eq 0 < q

   125       less_ceiling_iff [symmetric])

   126   moreover from r_def have "r \<in> \<rat>" by simp

   127   ultimately show ?thesis by fast

   128 qed

   129

   130

   131 subsection{*Floor and Ceiling Functions from the Reals to the Integers*}

   132

   133 lemma number_of_less_real_of_int_iff [simp]:

   134      "((number_of n) < real (m::int)) = (number_of n < m)"

   135 apply auto

   136 apply (rule real_of_int_less_iff [THEN iffD1])

   137 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)

   138 done

   139

   140 lemma number_of_less_real_of_int_iff2 [simp]:

   141      "(real (m::int) < (number_of n)) = (m < number_of n)"

   142 apply auto

   143 apply (rule real_of_int_less_iff [THEN iffD1])

   144 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)

   145 done

   146

   147 lemma number_of_le_real_of_int_iff [simp]:

   148      "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"

   149 by (simp add: linorder_not_less [symmetric])

   150

   151 lemma number_of_le_real_of_int_iff2 [simp]:

   152      "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"

   153 by (simp add: linorder_not_less [symmetric])

   154

   155 lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"

   156 unfolding real_of_nat_def by simp

   157

   158 lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"

   159 unfolding real_of_nat_def by (simp add: floor_minus)

   160

   161 lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"

   162 unfolding real_of_int_def by simp

   163

   164 lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"

   165 unfolding real_of_int_def by (simp add: floor_minus)

   166

   167 lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"

   168 unfolding real_of_int_def by (rule floor_exists)

   169

   170 lemma lemma_floor:

   171   assumes a1: "real m \<le> r" and a2: "r < real n + 1"

   172   shows "m \<le> (n::int)"

   173 proof -

   174   have "real m < real n + 1" using a1 a2 by (rule order_le_less_trans)

   175   also have "... = real (n + 1)" by simp

   176   finally have "m < n + 1" by (simp only: real_of_int_less_iff)

   177   thus ?thesis by arith

   178 qed

   179

   180 lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"

   181 unfolding real_of_int_def by (rule of_int_floor_le)

   182

   183 lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"

   184 by (auto intro: lemma_floor)

   185

   186 lemma real_of_int_floor_cancel [simp]:

   187     "(real (floor x) = x) = (\<exists>n::int. x = real n)"

   188   using floor_real_of_int by metis

   189

   190 lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"

   191   unfolding real_of_int_def using floor_unique [of n x] by simp

   192

   193 lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"

   194   unfolding real_of_int_def by (rule floor_unique)

   195

   196 lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"

   197 apply (rule inj_int [THEN injD])

   198 apply (simp add: real_of_nat_Suc)

   199 apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "int n"])

   200 done

   201

   202 lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"

   203 apply (drule order_le_imp_less_or_eq)

   204 apply (auto intro: floor_eq3)

   205 done

   206

   207 lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"

   208   unfolding real_of_int_def using floor_correct [of r] by simp

   209

   210 lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real(floor r)"

   211   unfolding real_of_int_def using floor_correct [of r] by simp

   212

   213 lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"

   214   unfolding real_of_int_def using floor_correct [of r] by simp

   215

   216 lemma real_of_int_floor_add_one_gt [simp]: "r < real(floor r) + 1"

   217   unfolding real_of_int_def using floor_correct [of r] by simp

   218

   219 lemma le_floor: "real a <= x ==> a <= floor x"

   220   unfolding real_of_int_def by (simp add: le_floor_iff)

   221

   222 lemma real_le_floor: "a <= floor x ==> real a <= x"

   223   unfolding real_of_int_def by (simp add: le_floor_iff)

   224

   225 lemma le_floor_eq: "(a <= floor x) = (real a <= x)"

   226   unfolding real_of_int_def by (rule le_floor_iff)

   227

   228 lemma floor_less_eq: "(floor x < a) = (x < real a)"

   229   unfolding real_of_int_def by (rule floor_less_iff)

   230

   231 lemma less_floor_eq: "(a < floor x) = (real a + 1 <= x)"

   232   unfolding real_of_int_def by (rule less_floor_iff)

   233

   234 lemma floor_le_eq: "(floor x <= a) = (x < real a + 1)"

   235   unfolding real_of_int_def by (rule floor_le_iff)

   236

   237 lemma floor_add [simp]: "floor (x + real a) = floor x + a"

   238   unfolding real_of_int_def by (rule floor_add_of_int)

   239

   240 lemma floor_subtract [simp]: "floor (x - real a) = floor x - a"

   241   unfolding real_of_int_def by (rule floor_diff_of_int)

   242

   243 lemma le_mult_floor:

   244   assumes "0 \<le> (a :: real)" and "0 \<le> b"

   245   shows "floor a * floor b \<le> floor (a * b)"

   246 proof -

   247   have "real (floor a) \<le> a"

   248     and "real (floor b) \<le> b" by auto

   249   hence "real (floor a * floor b) \<le> a * b"

   250     using assms by (auto intro!: mult_mono)

   251   also have "a * b < real (floor (a * b) + 1)" by auto

   252   finally show ?thesis unfolding real_of_int_less_iff by simp

   253 qed

   254

   255 lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"

   256   unfolding real_of_nat_def by simp

   257

   258 lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"

   259   unfolding real_of_int_def by (rule le_of_int_ceiling)

   260

   261 lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"

   262   unfolding real_of_int_def by simp

   263

   264 lemma real_of_int_ceiling_cancel [simp]:

   265      "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"

   266   using ceiling_real_of_int by metis

   267

   268 lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"

   269   unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp

   270

   271 lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"

   272   unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp

   273

   274 lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"

   275   unfolding real_of_int_def using ceiling_unique [of n x] by simp

   276

   277 lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"

   278   unfolding real_of_int_def using ceiling_correct [of r] by simp

   279

   280 lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"

   281   unfolding real_of_int_def using ceiling_correct [of r] by simp

   282

   283 lemma ceiling_le: "x <= real a ==> ceiling x <= a"

   284   unfolding real_of_int_def by (simp add: ceiling_le_iff)

   285

   286 lemma ceiling_le_real: "ceiling x <= a ==> x <= real a"

   287   unfolding real_of_int_def by (simp add: ceiling_le_iff)

   288

   289 lemma ceiling_le_eq: "(ceiling x <= a) = (x <= real a)"

   290   unfolding real_of_int_def by (rule ceiling_le_iff)

   291

   292 lemma less_ceiling_eq: "(a < ceiling x) = (real a < x)"

   293   unfolding real_of_int_def by (rule less_ceiling_iff)

   294

   295 lemma ceiling_less_eq: "(ceiling x < a) = (x <= real a - 1)"

   296   unfolding real_of_int_def by (rule ceiling_less_iff)

   297

   298 lemma le_ceiling_eq: "(a <= ceiling x) = (real a - 1 < x)"

   299   unfolding real_of_int_def by (rule le_ceiling_iff)

   300

   301 lemma ceiling_add [simp]: "ceiling (x + real a) = ceiling x + a"

   302   unfolding real_of_int_def by (rule ceiling_add_of_int)

   303

   304 lemma ceiling_subtract [simp]: "ceiling (x - real a) = ceiling x - a"

   305   unfolding real_of_int_def by (rule ceiling_diff_of_int)

   306

   307

   308 subsection {* Versions for the natural numbers *}

   309

   310 definition

   311   natfloor :: "real => nat" where

   312   "natfloor x = nat(floor x)"

   313

   314 definition

   315   natceiling :: "real => nat" where

   316   "natceiling x = nat(ceiling x)"

   317

   318 lemma natfloor_zero [simp]: "natfloor 0 = 0"

   319   by (unfold natfloor_def, simp)

   320

   321 lemma natfloor_one [simp]: "natfloor 1 = 1"

   322   by (unfold natfloor_def, simp)

   323

   324 lemma zero_le_natfloor [simp]: "0 <= natfloor x"

   325   by (unfold natfloor_def, simp)

   326

   327 lemma natfloor_number_of_eq [simp]: "natfloor (number_of n) = number_of n"

   328   by (unfold natfloor_def, simp)

   329

   330 lemma natfloor_real_of_nat [simp]: "natfloor(real n) = n"

   331   by (unfold natfloor_def, simp)

   332

   333 lemma real_natfloor_le: "0 <= x ==> real(natfloor x) <= x"

   334   by (unfold natfloor_def, simp)

   335

   336 lemma natfloor_neg: "x <= 0 ==> natfloor x = 0"

   337   apply (unfold natfloor_def)

   338   apply (subgoal_tac "floor x <= floor 0")

   339   apply simp

   340   apply (erule floor_mono)

   341 done

   342

   343 lemma natfloor_mono: "x <= y ==> natfloor x <= natfloor y"

   344   apply (case_tac "0 <= x")

   345   apply (subst natfloor_def)+

   346   apply (subst nat_le_eq_zle)

   347   apply force

   348   apply (erule floor_mono)

   349   apply (subst natfloor_neg)

   350   apply simp

   351   apply simp

   352 done

   353

   354 lemma le_natfloor: "real x <= a ==> x <= natfloor a"

   355   apply (unfold natfloor_def)

   356   apply (subst nat_int [THEN sym])

   357   apply (subst nat_le_eq_zle)

   358   apply simp

   359   apply (rule le_floor)

   360   apply simp

   361 done

   362

   363 lemma less_natfloor:

   364   assumes "0 \<le> x" and "x < real (n :: nat)"

   365   shows "natfloor x < n"

   366 proof (rule ccontr)

   367   assume "\<not> ?thesis" hence *: "n \<le> natfloor x" by simp

   368   note assms(2)

   369   also have "real n \<le> real (natfloor x)"

   370     using * unfolding real_of_nat_le_iff .

   371   finally have "x < real (natfloor x)" .

   372   with real_natfloor_le[OF assms(1)]

   373   show False by auto

   374 qed

   375

   376 lemma le_natfloor_eq: "0 <= x ==> (a <= natfloor x) = (real a <= x)"

   377   apply (rule iffI)

   378   apply (rule order_trans)

   379   prefer 2

   380   apply (erule real_natfloor_le)

   381   apply (subst real_of_nat_le_iff)

   382   apply assumption

   383   apply (erule le_natfloor)

   384 done

   385

   386 lemma le_natfloor_eq_number_of [simp]:

   387     "~ neg((number_of n)::int) ==> 0 <= x ==>

   388       (number_of n <= natfloor x) = (number_of n <= x)"

   389   apply (subst le_natfloor_eq, assumption)

   390   apply simp

   391 done

   392

   393 lemma le_natfloor_eq_one [simp]: "(1 <= natfloor x) = (1 <= x)"

   394   apply (case_tac "0 <= x")

   395   apply (subst le_natfloor_eq, assumption, simp)

   396   apply (rule iffI)

   397   apply (subgoal_tac "natfloor x <= natfloor 0")

   398   apply simp

   399   apply (rule natfloor_mono)

   400   apply simp

   401   apply simp

   402 done

   403

   404 lemma natfloor_eq: "real n <= x ==> x < real n + 1 ==> natfloor x = n"

   405   apply (unfold natfloor_def)

   406   apply (subst (2) nat_int [THEN sym])

   407   apply (subst eq_nat_nat_iff)

   408   apply simp

   409   apply simp

   410   apply (rule floor_eq2)

   411   apply auto

   412 done

   413

   414 lemma real_natfloor_add_one_gt: "x < real(natfloor x) + 1"

   415   apply (case_tac "0 <= x")

   416   apply (unfold natfloor_def)

   417   apply simp

   418   apply simp_all

   419 done

   420

   421 lemma real_natfloor_gt_diff_one: "x - 1 < real(natfloor x)"

   422 using real_natfloor_add_one_gt by (simp add: algebra_simps)

   423

   424 lemma ge_natfloor_plus_one_imp_gt: "natfloor z + 1 <= n ==> z < real n"

   425   apply (subgoal_tac "z < real(natfloor z) + 1")

   426   apply arith

   427   apply (rule real_natfloor_add_one_gt)

   428 done

   429

   430 lemma natfloor_add [simp]: "0 <= x ==> natfloor (x + real a) = natfloor x + a"

   431   apply (unfold natfloor_def)

   432   apply (subgoal_tac "real a = real (int a)")

   433   apply (erule ssubst)

   434   apply (simp add: nat_add_distrib del: real_of_int_of_nat_eq)

   435   apply simp

   436 done

   437

   438 lemma natfloor_add_number_of [simp]:

   439     "~neg ((number_of n)::int) ==> 0 <= x ==>

   440       natfloor (x + number_of n) = natfloor x + number_of n"

   441   apply (subst natfloor_add [THEN sym])

   442   apply simp_all

   443 done

   444

   445 lemma natfloor_add_one: "0 <= x ==> natfloor(x + 1) = natfloor x + 1"

   446   apply (subst natfloor_add [THEN sym])

   447   apply assumption

   448   apply simp

   449 done

   450

   451 lemma natfloor_subtract [simp]: "real a <= x ==>

   452     natfloor(x - real a) = natfloor x - a"

   453   apply (unfold natfloor_def)

   454   apply (subgoal_tac "real a = real (int a)")

   455   apply (erule ssubst)

   456   apply (simp del: real_of_int_of_nat_eq)

   457   apply simp

   458 done

   459

   460 lemma natfloor_div_nat:

   461   assumes "1 <= x" and "y > 0"

   462   shows "natfloor (x / real y) = natfloor x div y"

   463 proof -

   464   have "natfloor x = (natfloor x) div y * y + (natfloor x) mod y"

   465     by simp

   466   then have a: "real(natfloor x) = real ((natfloor x) div y) * real y +

   467     real((natfloor x) mod y)"

   468     by (simp only: real_of_nat_add [THEN sym] real_of_nat_mult [THEN sym])

   469   have "x = real(natfloor x) + (x - real(natfloor x))"

   470     by simp

   471   then have "x = real ((natfloor x) div y) * real y +

   472       real((natfloor x) mod y) + (x - real(natfloor x))"

   473     by (simp add: a)

   474   then have "x / real y = ... / real y"

   475     by simp

   476   also have "... = real((natfloor x) div y) + real((natfloor x) mod y) /

   477     real y + (x - real(natfloor x)) / real y"

   478     by (auto simp add: algebra_simps add_divide_distrib diff_divide_distrib)

   479   finally have "natfloor (x / real y) = natfloor(...)" by simp

   480   also have "... = natfloor(real((natfloor x) mod y) /

   481     real y + (x - real(natfloor x)) / real y + real((natfloor x) div y))"

   482     by (simp add: add_ac)

   483   also have "... = natfloor(real((natfloor x) mod y) /

   484     real y + (x - real(natfloor x)) / real y) + (natfloor x) div y"

   485     apply (rule natfloor_add)

   486     apply (rule add_nonneg_nonneg)

   487     apply (rule divide_nonneg_pos)

   488     apply simp

   489     apply (simp add: assms)

   490     apply (rule divide_nonneg_pos)

   491     apply (simp add: algebra_simps)

   492     apply (rule real_natfloor_le)

   493     using assms apply auto

   494     done

   495   also have "natfloor(real((natfloor x) mod y) /

   496     real y + (x - real(natfloor x)) / real y) = 0"

   497     apply (rule natfloor_eq)

   498     apply simp

   499     apply (rule add_nonneg_nonneg)

   500     apply (rule divide_nonneg_pos)

   501     apply force

   502     apply (force simp add: assms)

   503     apply (rule divide_nonneg_pos)

   504     apply (simp add: algebra_simps)

   505     apply (rule real_natfloor_le)

   506     apply (auto simp add: assms)

   507     using assms apply arith

   508     using assms apply (simp add: add_divide_distrib [THEN sym])

   509     apply (subgoal_tac "real y = real y - 1 + 1")

   510     apply (erule ssubst)

   511     apply (rule add_le_less_mono)

   512     apply (simp add: algebra_simps)

   513     apply (subgoal_tac "1 + real(natfloor x mod y) =

   514       real(natfloor x mod y + 1)")

   515     apply (erule ssubst)

   516     apply (subst real_of_nat_le_iff)

   517     apply (subgoal_tac "natfloor x mod y < y")

   518     apply arith

   519     apply (rule mod_less_divisor)

   520     apply auto

   521     using real_natfloor_add_one_gt

   522     apply (simp add: algebra_simps)

   523     done

   524   finally show ?thesis by simp

   525 qed

   526

   527 lemma le_mult_natfloor:

   528   assumes "0 \<le> (a :: real)" and "0 \<le> b"

   529   shows "natfloor a * natfloor b \<le> natfloor (a * b)"

   530   unfolding natfloor_def

   531   apply (subst nat_mult_distrib[symmetric])

   532   using assms apply simp

   533   apply (subst nat_le_eq_zle)

   534   using assms le_mult_floor by (auto intro!: mult_nonneg_nonneg)

   535

   536 lemma natceiling_zero [simp]: "natceiling 0 = 0"

   537   by (unfold natceiling_def, simp)

   538

   539 lemma natceiling_one [simp]: "natceiling 1 = 1"

   540   by (unfold natceiling_def, simp)

   541

   542 lemma zero_le_natceiling [simp]: "0 <= natceiling x"

   543   by (unfold natceiling_def, simp)

   544

   545 lemma natceiling_number_of_eq [simp]: "natceiling (number_of n) = number_of n"

   546   by (unfold natceiling_def, simp)

   547

   548 lemma natceiling_real_of_nat [simp]: "natceiling(real n) = n"

   549   by (unfold natceiling_def, simp)

   550

   551 lemma real_natceiling_ge: "x <= real(natceiling x)"

   552   apply (unfold natceiling_def)

   553   apply (case_tac "x < 0")

   554   apply simp

   555   apply (subst real_nat_eq_real)

   556   apply (subgoal_tac "ceiling 0 <= ceiling x")

   557   apply simp

   558   apply (rule ceiling_mono)

   559   apply simp

   560   apply simp

   561 done

   562

   563 lemma natceiling_neg: "x <= 0 ==> natceiling x = 0"

   564   apply (unfold natceiling_def)

   565   apply simp

   566 done

   567

   568 lemma natceiling_mono: "x <= y ==> natceiling x <= natceiling y"

   569   apply (case_tac "0 <= x")

   570   apply (subst natceiling_def)+

   571   apply (subst nat_le_eq_zle)

   572   apply (rule disjI2)

   573   apply (subgoal_tac "real (0::int) <= real(ceiling y)")

   574   apply simp

   575   apply (rule order_trans)

   576   apply simp

   577   apply (erule order_trans)

   578   apply simp

   579   apply (erule ceiling_mono)

   580   apply (subst natceiling_neg)

   581   apply simp_all

   582 done

   583

   584 lemma natceiling_le: "x <= real a ==> natceiling x <= a"

   585   apply (unfold natceiling_def)

   586   apply (case_tac "x < 0")

   587   apply simp

   588   apply (subst (2) nat_int [THEN sym])

   589   apply (subst nat_le_eq_zle)

   590   apply simp

   591   apply (rule ceiling_le)

   592   apply simp

   593 done

   594

   595 lemma natceiling_le_eq: "0 <= x ==> (natceiling x <= a) = (x <= real a)"

   596   apply (rule iffI)

   597   apply (rule order_trans)

   598   apply (rule real_natceiling_ge)

   599   apply (subst real_of_nat_le_iff)

   600   apply assumption

   601   apply (erule natceiling_le)

   602 done

   603

   604 lemma natceiling_le_eq_number_of [simp]:

   605     "~ neg((number_of n)::int) ==> 0 <= x ==>

   606       (natceiling x <= number_of n) = (x <= number_of n)"

   607   apply (subst natceiling_le_eq, assumption)

   608   apply simp

   609 done

   610

   611 lemma natceiling_le_eq_one: "(natceiling x <= 1) = (x <= 1)"

   612   apply (case_tac "0 <= x")

   613   apply (subst natceiling_le_eq)

   614   apply assumption

   615   apply simp

   616   apply (subst natceiling_neg)

   617   apply simp

   618   apply simp

   619 done

   620

   621 lemma natceiling_eq: "real n < x ==> x <= real n + 1 ==> natceiling x = n + 1"

   622   apply (unfold natceiling_def)

   623   apply (simplesubst nat_int [THEN sym]) back back

   624   apply (subgoal_tac "nat(int n) + 1 = nat(int n + 1)")

   625   apply (erule ssubst)

   626   apply (subst eq_nat_nat_iff)

   627   apply (subgoal_tac "ceiling 0 <= ceiling x")

   628   apply simp

   629   apply (rule ceiling_mono)

   630   apply force

   631   apply force

   632   apply (rule ceiling_eq2)

   633   apply (simp, simp)

   634   apply (subst nat_add_distrib)

   635   apply auto

   636 done

   637

   638 lemma natceiling_add [simp]: "0 <= x ==>

   639     natceiling (x + real a) = natceiling x + a"

   640   apply (unfold natceiling_def)

   641   apply (subgoal_tac "real a = real (int a)")

   642   apply (erule ssubst)

   643   apply (simp del: real_of_int_of_nat_eq)

   644   apply (subst nat_add_distrib)

   645   apply (subgoal_tac "0 = ceiling 0")

   646   apply (erule ssubst)

   647   apply (erule ceiling_mono)

   648   apply simp_all

   649 done

   650

   651 lemma natceiling_add_number_of [simp]:

   652     "~ neg ((number_of n)::int) ==> 0 <= x ==>

   653       natceiling (x + number_of n) = natceiling x + number_of n"

   654   apply (subst natceiling_add [THEN sym])

   655   apply simp_all

   656 done

   657

   658 lemma natceiling_add_one: "0 <= x ==> natceiling(x + 1) = natceiling x + 1"

   659   apply (subst natceiling_add [THEN sym])

   660   apply assumption

   661   apply simp

   662 done

   663

   664 lemma natceiling_subtract [simp]: "real a <= x ==>

   665     natceiling(x - real a) = natceiling x - a"

   666   apply (unfold natceiling_def)

   667   apply (subgoal_tac "real a = real (int a)")

   668   apply (erule ssubst)

   669   apply (simp del: real_of_int_of_nat_eq)

   670   apply simp

   671 done

   672

   673 subsection {* Exponentiation with floor *}

   674

   675 lemma floor_power:

   676   assumes "x = real (floor x)"

   677   shows "floor (x ^ n) = floor x ^ n"

   678 proof -

   679   have *: "x ^ n = real (floor x ^ n)"

   680     using assms by (induct n arbitrary: x) simp_all

   681   show ?thesis unfolding real_of_int_inject[symmetric]

   682     unfolding * floor_real_of_int ..

   683 qed

   684

   685 lemma natfloor_power:

   686   assumes "x = real (natfloor x)"

   687   shows "natfloor (x ^ n) = natfloor x ^ n"

   688 proof -

   689   from assms have "0 \<le> floor x" by auto

   690   note assms[unfolded natfloor_def real_nat_eq_real[OF 0 \<le> floor x]]

   691   from floor_power[OF this]

   692   show ?thesis unfolding natfloor_def nat_power_eq[OF 0 \<le> floor x, symmetric]

   693     by simp

   694 qed

   695

   696 end