src/HOL/RComplete.thy
author hoelzl
Thu Mar 04 17:28:45 2010 +0100 (2010-03-04)
changeset 35578 384ad08a1d1b
parent 35028 108662d50512
child 36795 e05e1283c550
permissions -rw-r--r--
Added natfloor and floor rules for multiplication and power.
wenzelm@30122
     1
(*  Title:      HOL/RComplete.thy
wenzelm@30122
     2
    Author:     Jacques D. Fleuriot, University of Edinburgh
wenzelm@30122
     3
    Author:     Larry Paulson, University of Cambridge
wenzelm@30122
     4
    Author:     Jeremy Avigad, Carnegie Mellon University
wenzelm@30122
     5
    Author:     Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen
wenzelm@16893
     6
*)
paulson@5078
     7
wenzelm@16893
     8
header {* Completeness of the Reals; Floor and Ceiling Functions *}
paulson@14365
     9
nipkow@15131
    10
theory RComplete
nipkow@15140
    11
imports Lubs RealDef
nipkow@15131
    12
begin
paulson@14365
    13
paulson@14365
    14
lemma real_sum_of_halves: "x/2 + x/2 = (x::real)"
wenzelm@16893
    15
  by simp
paulson@14365
    16
paulson@32707
    17
lemma abs_diff_less_iff:
haftmann@35028
    18
  "(\<bar>x - a\<bar> < (r::'a::linordered_idom)) = (a - r < x \<and> x < a + r)"
paulson@32707
    19
  by auto
paulson@14365
    20
wenzelm@16893
    21
subsection {* Completeness of Positive Reals *}
wenzelm@16893
    22
wenzelm@16893
    23
text {*
wenzelm@16893
    24
  Supremum property for the set of positive reals
wenzelm@16893
    25
wenzelm@16893
    26
  Let @{text "P"} be a non-empty set of positive reals, with an upper
wenzelm@16893
    27
  bound @{text "y"}.  Then @{text "P"} has a least upper bound
wenzelm@16893
    28
  (written @{text "S"}).
paulson@14365
    29
wenzelm@16893
    30
  FIXME: Can the premise be weakened to @{text "\<forall>x \<in> P. x\<le> y"}?
wenzelm@16893
    31
*}
wenzelm@16893
    32
wenzelm@16893
    33
lemma posreal_complete:
wenzelm@16893
    34
  assumes positive_P: "\<forall>x \<in> P. (0::real) < x"
wenzelm@16893
    35
    and not_empty_P: "\<exists>x. x \<in> P"
wenzelm@16893
    36
    and upper_bound_Ex: "\<exists>y. \<forall>x \<in> P. x<y"
wenzelm@16893
    37
  shows "\<exists>S. \<forall>y. (\<exists>x \<in> P. y < x) = (y < S)"
wenzelm@16893
    38
proof (rule exI, rule allI)
wenzelm@16893
    39
  fix y
wenzelm@16893
    40
  let ?pP = "{w. real_of_preal w \<in> P}"
paulson@14365
    41
wenzelm@16893
    42
  show "(\<exists>x\<in>P. y < x) = (y < real_of_preal (psup ?pP))"
wenzelm@16893
    43
  proof (cases "0 < y")
wenzelm@16893
    44
    assume neg_y: "\<not> 0 < y"
wenzelm@16893
    45
    show ?thesis
wenzelm@16893
    46
    proof
wenzelm@16893
    47
      assume "\<exists>x\<in>P. y < x"
wenzelm@16893
    48
      have "\<forall>x. y < real_of_preal x"
wenzelm@16893
    49
        using neg_y by (rule real_less_all_real2)
wenzelm@16893
    50
      thus "y < real_of_preal (psup ?pP)" ..
wenzelm@16893
    51
    next
wenzelm@16893
    52
      assume "y < real_of_preal (psup ?pP)"
wenzelm@16893
    53
      obtain "x" where x_in_P: "x \<in> P" using not_empty_P ..
wenzelm@16893
    54
      hence "0 < x" using positive_P by simp
wenzelm@16893
    55
      hence "y < x" using neg_y by simp
wenzelm@16893
    56
      thus "\<exists>x \<in> P. y < x" using x_in_P ..
wenzelm@16893
    57
    qed
wenzelm@16893
    58
  next
wenzelm@16893
    59
    assume pos_y: "0 < y"
paulson@14365
    60
wenzelm@16893
    61
    then obtain py where y_is_py: "y = real_of_preal py"
wenzelm@16893
    62
      by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@16893
    63
wenzelm@23389
    64
    obtain a where "a \<in> P" using not_empty_P ..
wenzelm@23389
    65
    with positive_P have a_pos: "0 < a" ..
wenzelm@16893
    66
    then obtain pa where "a = real_of_preal pa"
wenzelm@16893
    67
      by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@23389
    68
    hence "pa \<in> ?pP" using `a \<in> P` by auto
wenzelm@16893
    69
    hence pP_not_empty: "?pP \<noteq> {}" by auto
paulson@14365
    70
wenzelm@16893
    71
    obtain sup where sup: "\<forall>x \<in> P. x < sup"
wenzelm@16893
    72
      using upper_bound_Ex ..
wenzelm@23389
    73
    from this and `a \<in> P` have "a < sup" ..
wenzelm@16893
    74
    hence "0 < sup" using a_pos by arith
wenzelm@16893
    75
    then obtain possup where "sup = real_of_preal possup"
wenzelm@16893
    76
      by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@16893
    77
    hence "\<forall>X \<in> ?pP. X \<le> possup"
wenzelm@16893
    78
      using sup by (auto simp add: real_of_preal_lessI)
wenzelm@16893
    79
    with pP_not_empty have psup: "\<And>Z. (\<exists>X \<in> ?pP. Z < X) = (Z < psup ?pP)"
wenzelm@16893
    80
      by (rule preal_complete)
wenzelm@16893
    81
wenzelm@16893
    82
    show ?thesis
wenzelm@16893
    83
    proof
wenzelm@16893
    84
      assume "\<exists>x \<in> P. y < x"
wenzelm@16893
    85
      then obtain x where x_in_P: "x \<in> P" and y_less_x: "y < x" ..
wenzelm@16893
    86
      hence "0 < x" using pos_y by arith
wenzelm@16893
    87
      then obtain px where x_is_px: "x = real_of_preal px"
wenzelm@16893
    88
        by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@16893
    89
wenzelm@16893
    90
      have py_less_X: "\<exists>X \<in> ?pP. py < X"
wenzelm@16893
    91
      proof
wenzelm@16893
    92
        show "py < px" using y_is_py and x_is_px and y_less_x
wenzelm@16893
    93
          by (simp add: real_of_preal_lessI)
wenzelm@16893
    94
        show "px \<in> ?pP" using x_in_P and x_is_px by simp
wenzelm@16893
    95
      qed
paulson@14365
    96
wenzelm@16893
    97
      have "(\<exists>X \<in> ?pP. py < X) ==> (py < psup ?pP)"
wenzelm@16893
    98
        using psup by simp
wenzelm@16893
    99
      hence "py < psup ?pP" using py_less_X by simp
wenzelm@16893
   100
      thus "y < real_of_preal (psup {w. real_of_preal w \<in> P})"
wenzelm@16893
   101
        using y_is_py and pos_y by (simp add: real_of_preal_lessI)
wenzelm@16893
   102
    next
wenzelm@16893
   103
      assume y_less_psup: "y < real_of_preal (psup ?pP)"
paulson@14365
   104
wenzelm@16893
   105
      hence "py < psup ?pP" using y_is_py
wenzelm@16893
   106
        by (simp add: real_of_preal_lessI)
wenzelm@16893
   107
      then obtain "X" where py_less_X: "py < X" and X_in_pP: "X \<in> ?pP"
wenzelm@16893
   108
        using psup by auto
wenzelm@16893
   109
      then obtain x where x_is_X: "x = real_of_preal X"
wenzelm@16893
   110
        by (simp add: real_gt_zero_preal_Ex)
wenzelm@16893
   111
      hence "y < x" using py_less_X and y_is_py
wenzelm@16893
   112
        by (simp add: real_of_preal_lessI)
wenzelm@16893
   113
wenzelm@16893
   114
      moreover have "x \<in> P" using x_is_X and X_in_pP by simp
wenzelm@16893
   115
wenzelm@16893
   116
      ultimately show "\<exists> x \<in> P. y < x" ..
wenzelm@16893
   117
    qed
wenzelm@16893
   118
  qed
wenzelm@16893
   119
qed
wenzelm@16893
   120
wenzelm@16893
   121
text {*
wenzelm@16893
   122
  \medskip Completeness properties using @{text "isUb"}, @{text "isLub"} etc.
wenzelm@16893
   123
*}
paulson@14365
   124
paulson@14365
   125
lemma real_isLub_unique: "[| isLub R S x; isLub R S y |] ==> x = (y::real)"
wenzelm@16893
   126
  apply (frule isLub_isUb)
wenzelm@16893
   127
  apply (frule_tac x = y in isLub_isUb)
wenzelm@16893
   128
  apply (blast intro!: order_antisym dest!: isLub_le_isUb)
wenzelm@16893
   129
  done
paulson@14365
   130
paulson@5078
   131
wenzelm@16893
   132
text {*
wenzelm@16893
   133
  \medskip Completeness theorem for the positive reals (again).
wenzelm@16893
   134
*}
wenzelm@16893
   135
wenzelm@16893
   136
lemma posreals_complete:
wenzelm@16893
   137
  assumes positive_S: "\<forall>x \<in> S. 0 < x"
wenzelm@16893
   138
    and not_empty_S: "\<exists>x. x \<in> S"
wenzelm@16893
   139
    and upper_bound_Ex: "\<exists>u. isUb (UNIV::real set) S u"
wenzelm@16893
   140
  shows "\<exists>t. isLub (UNIV::real set) S t"
wenzelm@16893
   141
proof
wenzelm@16893
   142
  let ?pS = "{w. real_of_preal w \<in> S}"
wenzelm@16893
   143
wenzelm@16893
   144
  obtain u where "isUb UNIV S u" using upper_bound_Ex ..
wenzelm@16893
   145
  hence sup: "\<forall>x \<in> S. x \<le> u" by (simp add: isUb_def setle_def)
wenzelm@16893
   146
wenzelm@16893
   147
  obtain x where x_in_S: "x \<in> S" using not_empty_S ..
wenzelm@16893
   148
  hence x_gt_zero: "0 < x" using positive_S by simp
wenzelm@16893
   149
  have  "x \<le> u" using sup and x_in_S ..
wenzelm@16893
   150
  hence "0 < u" using x_gt_zero by arith
wenzelm@16893
   151
wenzelm@16893
   152
  then obtain pu where u_is_pu: "u = real_of_preal pu"
wenzelm@16893
   153
    by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@16893
   154
wenzelm@16893
   155
  have pS_less_pu: "\<forall>pa \<in> ?pS. pa \<le> pu"
wenzelm@16893
   156
  proof
wenzelm@16893
   157
    fix pa
wenzelm@16893
   158
    assume "pa \<in> ?pS"
wenzelm@16893
   159
    then obtain a where "a \<in> S" and "a = real_of_preal pa"
wenzelm@16893
   160
      by simp
wenzelm@16893
   161
    moreover hence "a \<le> u" using sup by simp
wenzelm@16893
   162
    ultimately show "pa \<le> pu"
wenzelm@16893
   163
      using sup and u_is_pu by (simp add: real_of_preal_le_iff)
wenzelm@16893
   164
  qed
paulson@14365
   165
wenzelm@16893
   166
  have "\<forall>y \<in> S. y \<le> real_of_preal (psup ?pS)"
wenzelm@16893
   167
  proof
wenzelm@16893
   168
    fix y
wenzelm@16893
   169
    assume y_in_S: "y \<in> S"
wenzelm@16893
   170
    hence "0 < y" using positive_S by simp
wenzelm@16893
   171
    then obtain py where y_is_py: "y = real_of_preal py"
wenzelm@16893
   172
      by (auto simp add: real_gt_zero_preal_Ex)
wenzelm@16893
   173
    hence py_in_pS: "py \<in> ?pS" using y_in_S by simp
wenzelm@16893
   174
    with pS_less_pu have "py \<le> psup ?pS"
wenzelm@16893
   175
      by (rule preal_psup_le)
wenzelm@16893
   176
    thus "y \<le> real_of_preal (psup ?pS)"
wenzelm@16893
   177
      using y_is_py by (simp add: real_of_preal_le_iff)
wenzelm@16893
   178
  qed
wenzelm@16893
   179
wenzelm@16893
   180
  moreover {
wenzelm@16893
   181
    fix x
wenzelm@16893
   182
    assume x_ub_S: "\<forall>y\<in>S. y \<le> x"
wenzelm@16893
   183
    have "real_of_preal (psup ?pS) \<le> x"
wenzelm@16893
   184
    proof -
wenzelm@16893
   185
      obtain "s" where s_in_S: "s \<in> S" using not_empty_S ..
wenzelm@16893
   186
      hence s_pos: "0 < s" using positive_S by simp
wenzelm@16893
   187
wenzelm@16893
   188
      hence "\<exists> ps. s = real_of_preal ps" by (simp add: real_gt_zero_preal_Ex)
wenzelm@16893
   189
      then obtain "ps" where s_is_ps: "s = real_of_preal ps" ..
wenzelm@16893
   190
      hence ps_in_pS: "ps \<in> {w. real_of_preal w \<in> S}" using s_in_S by simp
wenzelm@16893
   191
wenzelm@16893
   192
      from x_ub_S have "s \<le> x" using s_in_S ..
wenzelm@16893
   193
      hence "0 < x" using s_pos by simp
wenzelm@16893
   194
      hence "\<exists> px. x = real_of_preal px" by (simp add: real_gt_zero_preal_Ex)
wenzelm@16893
   195
      then obtain "px" where x_is_px: "x = real_of_preal px" ..
wenzelm@16893
   196
wenzelm@16893
   197
      have "\<forall>pe \<in> ?pS. pe \<le> px"
wenzelm@16893
   198
      proof
wenzelm@32960
   199
        fix pe
wenzelm@32960
   200
        assume "pe \<in> ?pS"
wenzelm@32960
   201
        hence "real_of_preal pe \<in> S" by simp
wenzelm@32960
   202
        hence "real_of_preal pe \<le> x" using x_ub_S by simp
wenzelm@32960
   203
        thus "pe \<le> px" using x_is_px by (simp add: real_of_preal_le_iff)
wenzelm@16893
   204
      qed
wenzelm@16893
   205
wenzelm@16893
   206
      moreover have "?pS \<noteq> {}" using ps_in_pS by auto
wenzelm@16893
   207
      ultimately have "(psup ?pS) \<le> px" by (simp add: psup_le_ub)
wenzelm@16893
   208
      thus "real_of_preal (psup ?pS) \<le> x" using x_is_px by (simp add: real_of_preal_le_iff)
wenzelm@16893
   209
    qed
wenzelm@16893
   210
  }
wenzelm@16893
   211
  ultimately show "isLub UNIV S (real_of_preal (psup ?pS))"
wenzelm@16893
   212
    by (simp add: isLub_def leastP_def isUb_def setle_def setge_def)
wenzelm@16893
   213
qed
wenzelm@16893
   214
wenzelm@16893
   215
text {*
wenzelm@16893
   216
  \medskip reals Completeness (again!)
wenzelm@16893
   217
*}
paulson@14365
   218
wenzelm@16893
   219
lemma reals_complete:
wenzelm@16893
   220
  assumes notempty_S: "\<exists>X. X \<in> S"
wenzelm@16893
   221
    and exists_Ub: "\<exists>Y. isUb (UNIV::real set) S Y"
wenzelm@16893
   222
  shows "\<exists>t. isLub (UNIV :: real set) S t"
wenzelm@16893
   223
proof -
wenzelm@16893
   224
  obtain X where X_in_S: "X \<in> S" using notempty_S ..
wenzelm@16893
   225
  obtain Y where Y_isUb: "isUb (UNIV::real set) S Y"
wenzelm@16893
   226
    using exists_Ub ..
wenzelm@16893
   227
  let ?SHIFT = "{z. \<exists>x \<in>S. z = x + (-X) + 1} \<inter> {x. 0 < x}"
wenzelm@16893
   228
wenzelm@16893
   229
  {
wenzelm@16893
   230
    fix x
wenzelm@16893
   231
    assume "isUb (UNIV::real set) S x"
wenzelm@16893
   232
    hence S_le_x: "\<forall> y \<in> S. y <= x"
wenzelm@16893
   233
      by (simp add: isUb_def setle_def)
wenzelm@16893
   234
    {
wenzelm@16893
   235
      fix s
wenzelm@16893
   236
      assume "s \<in> {z. \<exists>x\<in>S. z = x + - X + 1}"
wenzelm@16893
   237
      hence "\<exists> x \<in> S. s = x + -X + 1" ..
wenzelm@16893
   238
      then obtain x1 where "x1 \<in> S" and "s = x1 + (-X) + 1" ..
wenzelm@16893
   239
      moreover hence "x1 \<le> x" using S_le_x by simp
wenzelm@16893
   240
      ultimately have "s \<le> x + - X + 1" by arith
wenzelm@16893
   241
    }
wenzelm@16893
   242
    then have "isUb (UNIV::real set) ?SHIFT (x + (-X) + 1)"
wenzelm@16893
   243
      by (auto simp add: isUb_def setle_def)
wenzelm@16893
   244
  } note S_Ub_is_SHIFT_Ub = this
wenzelm@16893
   245
wenzelm@16893
   246
  hence "isUb UNIV ?SHIFT (Y + (-X) + 1)" using Y_isUb by simp
wenzelm@16893
   247
  hence "\<exists>Z. isUb UNIV ?SHIFT Z" ..
wenzelm@16893
   248
  moreover have "\<forall>y \<in> ?SHIFT. 0 < y" by auto
wenzelm@16893
   249
  moreover have shifted_not_empty: "\<exists>u. u \<in> ?SHIFT"
wenzelm@16893
   250
    using X_in_S and Y_isUb by auto
wenzelm@16893
   251
  ultimately obtain t where t_is_Lub: "isLub UNIV ?SHIFT t"
wenzelm@16893
   252
    using posreals_complete [of ?SHIFT] by blast
wenzelm@16893
   253
wenzelm@16893
   254
  show ?thesis
wenzelm@16893
   255
  proof
wenzelm@16893
   256
    show "isLub UNIV S (t + X + (-1))"
wenzelm@16893
   257
    proof (rule isLubI2)
wenzelm@16893
   258
      {
wenzelm@16893
   259
        fix x
wenzelm@16893
   260
        assume "isUb (UNIV::real set) S x"
wenzelm@16893
   261
        hence "isUb (UNIV::real set) (?SHIFT) (x + (-X) + 1)"
wenzelm@32960
   262
          using S_Ub_is_SHIFT_Ub by simp
wenzelm@16893
   263
        hence "t \<le> (x + (-X) + 1)"
wenzelm@32960
   264
          using t_is_Lub by (simp add: isLub_le_isUb)
wenzelm@16893
   265
        hence "t + X + -1 \<le> x" by arith
wenzelm@16893
   266
      }
wenzelm@16893
   267
      then show "(t + X + -1) <=* Collect (isUb UNIV S)"
wenzelm@32960
   268
        by (simp add: setgeI)
wenzelm@16893
   269
    next
wenzelm@16893
   270
      show "isUb UNIV S (t + X + -1)"
wenzelm@16893
   271
      proof -
wenzelm@16893
   272
        {
wenzelm@16893
   273
          fix y
wenzelm@16893
   274
          assume y_in_S: "y \<in> S"
wenzelm@16893
   275
          have "y \<le> t + X + -1"
wenzelm@16893
   276
          proof -
wenzelm@16893
   277
            obtain "u" where u_in_shift: "u \<in> ?SHIFT" using shifted_not_empty ..
wenzelm@16893
   278
            hence "\<exists> x \<in> S. u = x + - X + 1" by simp
wenzelm@16893
   279
            then obtain "x" where x_and_u: "u = x + - X + 1" ..
wenzelm@16893
   280
            have u_le_t: "u \<le> t" using u_in_shift and t_is_Lub by (simp add: isLubD2)
wenzelm@16893
   281
wenzelm@16893
   282
            show ?thesis
wenzelm@16893
   283
            proof cases
wenzelm@16893
   284
              assume "y \<le> x"
wenzelm@16893
   285
              moreover have "x = u + X + - 1" using x_and_u by arith
wenzelm@16893
   286
              moreover have "u + X + - 1  \<le> t + X + -1" using u_le_t by arith
wenzelm@16893
   287
              ultimately show "y  \<le> t + X + -1" by arith
wenzelm@16893
   288
            next
wenzelm@16893
   289
              assume "~(y \<le> x)"
wenzelm@16893
   290
              hence x_less_y: "x < y" by arith
wenzelm@16893
   291
wenzelm@16893
   292
              have "x + (-X) + 1 \<in> ?SHIFT" using x_and_u and u_in_shift by simp
wenzelm@16893
   293
              hence "0 < x + (-X) + 1" by simp
wenzelm@16893
   294
              hence "0 < y + (-X) + 1" using x_less_y by arith
wenzelm@16893
   295
              hence "y + (-X) + 1 \<in> ?SHIFT" using y_in_S by simp
wenzelm@16893
   296
              hence "y + (-X) + 1 \<le> t" using t_is_Lub  by (simp add: isLubD2)
wenzelm@16893
   297
              thus ?thesis by simp
wenzelm@16893
   298
            qed
wenzelm@16893
   299
          qed
wenzelm@16893
   300
        }
wenzelm@16893
   301
        then show ?thesis by (simp add: isUb_def setle_def)
wenzelm@16893
   302
      qed
wenzelm@16893
   303
    qed
wenzelm@16893
   304
  qed
wenzelm@16893
   305
qed
paulson@14365
   306
paulson@32707
   307
text{*A version of the same theorem without all those predicates!*}
paulson@32707
   308
lemma reals_complete2:
paulson@32707
   309
  fixes S :: "(real set)"
paulson@32707
   310
  assumes "\<exists>y. y\<in>S" and "\<exists>(x::real). \<forall>y\<in>S. y \<le> x"
paulson@32707
   311
  shows "\<exists>x. (\<forall>y\<in>S. y \<le> x) & 
paulson@32707
   312
               (\<forall>z. ((\<forall>y\<in>S. y \<le> z) --> x \<le> z))"
paulson@32707
   313
proof -
paulson@32707
   314
  have "\<exists>x. isLub UNIV S x" 
paulson@32707
   315
    by (rule reals_complete)
paulson@32707
   316
       (auto simp add: isLub_def isUb_def leastP_def setle_def setge_def prems)
paulson@32707
   317
  thus ?thesis
paulson@32707
   318
    by (metis UNIV_I isLub_isUb isLub_le_isUb isUbD isUb_def setleI)
paulson@32707
   319
qed
paulson@32707
   320
paulson@14365
   321
wenzelm@16893
   322
subsection {* The Archimedean Property of the Reals *}
wenzelm@16893
   323
wenzelm@16893
   324
theorem reals_Archimedean:
wenzelm@16893
   325
  assumes x_pos: "0 < x"
wenzelm@16893
   326
  shows "\<exists>n. inverse (real (Suc n)) < x"
wenzelm@16893
   327
proof (rule ccontr)
wenzelm@16893
   328
  assume contr: "\<not> ?thesis"
wenzelm@16893
   329
  have "\<forall>n. x * real (Suc n) <= 1"
wenzelm@16893
   330
  proof
wenzelm@16893
   331
    fix n
wenzelm@16893
   332
    from contr have "x \<le> inverse (real (Suc n))"
wenzelm@16893
   333
      by (simp add: linorder_not_less)
wenzelm@16893
   334
    hence "x \<le> (1 / (real (Suc n)))"
wenzelm@16893
   335
      by (simp add: inverse_eq_divide)
wenzelm@16893
   336
    moreover have "0 \<le> real (Suc n)"
wenzelm@16893
   337
      by (rule real_of_nat_ge_zero)
wenzelm@16893
   338
    ultimately have "x * real (Suc n) \<le> (1 / real (Suc n)) * real (Suc n)"
wenzelm@16893
   339
      by (rule mult_right_mono)
wenzelm@16893
   340
    thus "x * real (Suc n) \<le> 1" by simp
wenzelm@16893
   341
  qed
wenzelm@16893
   342
  hence "{z. \<exists>n. z = x * (real (Suc n))} *<= 1"
wenzelm@16893
   343
    by (simp add: setle_def, safe, rule spec)
wenzelm@16893
   344
  hence "isUb (UNIV::real set) {z. \<exists>n. z = x * (real (Suc n))} 1"
wenzelm@16893
   345
    by (simp add: isUbI)
wenzelm@16893
   346
  hence "\<exists>Y. isUb (UNIV::real set) {z. \<exists>n. z = x* (real (Suc n))} Y" ..
wenzelm@16893
   347
  moreover have "\<exists>X. X \<in> {z. \<exists>n. z = x* (real (Suc n))}" by auto
wenzelm@16893
   348
  ultimately have "\<exists>t. isLub UNIV {z. \<exists>n. z = x * real (Suc n)} t"
wenzelm@16893
   349
    by (simp add: reals_complete)
wenzelm@16893
   350
  then obtain "t" where
wenzelm@16893
   351
    t_is_Lub: "isLub UNIV {z. \<exists>n. z = x * real (Suc n)} t" ..
wenzelm@16893
   352
wenzelm@16893
   353
  have "\<forall>n::nat. x * real n \<le> t + - x"
wenzelm@16893
   354
  proof
wenzelm@16893
   355
    fix n
wenzelm@16893
   356
    from t_is_Lub have "x * real (Suc n) \<le> t"
wenzelm@16893
   357
      by (simp add: isLubD2)
wenzelm@16893
   358
    hence  "x * (real n) + x \<le> t"
wenzelm@16893
   359
      by (simp add: right_distrib real_of_nat_Suc)
wenzelm@16893
   360
    thus  "x * (real n) \<le> t + - x" by arith
wenzelm@16893
   361
  qed
paulson@14365
   362
wenzelm@16893
   363
  hence "\<forall>m. x * real (Suc m) \<le> t + - x" by simp
wenzelm@16893
   364
  hence "{z. \<exists>n. z = x * (real (Suc n))}  *<= (t + - x)"
wenzelm@16893
   365
    by (auto simp add: setle_def)
wenzelm@16893
   366
  hence "isUb (UNIV::real set) {z. \<exists>n. z = x * (real (Suc n))} (t + (-x))"
wenzelm@16893
   367
    by (simp add: isUbI)
wenzelm@16893
   368
  hence "t \<le> t + - x"
wenzelm@16893
   369
    using t_is_Lub by (simp add: isLub_le_isUb)
wenzelm@16893
   370
  thus False using x_pos by arith
wenzelm@16893
   371
qed
wenzelm@16893
   372
wenzelm@16893
   373
text {*
wenzelm@16893
   374
  There must be other proofs, e.g. @{text "Suc"} of the largest
wenzelm@16893
   375
  integer in the cut representing @{text "x"}.
wenzelm@16893
   376
*}
paulson@14365
   377
paulson@14365
   378
lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)"
wenzelm@16893
   379
proof cases
wenzelm@16893
   380
  assume "x \<le> 0"
wenzelm@16893
   381
  hence "x < real (1::nat)" by simp
wenzelm@16893
   382
  thus ?thesis ..
wenzelm@16893
   383
next
wenzelm@16893
   384
  assume "\<not> x \<le> 0"
wenzelm@16893
   385
  hence x_greater_zero: "0 < x" by simp
wenzelm@16893
   386
  hence "0 < inverse x" by simp
wenzelm@16893
   387
  then obtain n where "inverse (real (Suc n)) < inverse x"
wenzelm@16893
   388
    using reals_Archimedean by blast
wenzelm@16893
   389
  hence "inverse (real (Suc n)) * x < inverse x * x"
wenzelm@16893
   390
    using x_greater_zero by (rule mult_strict_right_mono)
wenzelm@16893
   391
  hence "inverse (real (Suc n)) * x < 1"
huffman@23008
   392
    using x_greater_zero by simp
wenzelm@16893
   393
  hence "real (Suc n) * (inverse (real (Suc n)) * x) < real (Suc n) * 1"
wenzelm@16893
   394
    by (rule mult_strict_left_mono) simp
wenzelm@16893
   395
  hence "x < real (Suc n)"
nipkow@29667
   396
    by (simp add: algebra_simps)
wenzelm@16893
   397
  thus "\<exists>(n::nat). x < real n" ..
wenzelm@16893
   398
qed
paulson@14365
   399
huffman@30097
   400
instance real :: archimedean_field
huffman@30097
   401
proof
huffman@30097
   402
  fix r :: real
huffman@30097
   403
  obtain n :: nat where "r < real n"
huffman@30097
   404
    using reals_Archimedean2 ..
huffman@30097
   405
  then have "r \<le> of_int (int n)"
huffman@30097
   406
    unfolding real_eq_of_nat by simp
huffman@30097
   407
  then show "\<exists>z. r \<le> of_int z" ..
huffman@30097
   408
qed
huffman@30097
   409
wenzelm@16893
   410
lemma reals_Archimedean3:
wenzelm@16893
   411
  assumes x_greater_zero: "0 < x"
wenzelm@16893
   412
  shows "\<forall>(y::real). \<exists>(n::nat). y < real n * x"
huffman@30097
   413
  unfolding real_of_nat_def using `0 < x`
huffman@30097
   414
  by (auto intro: ex_less_of_nat_mult)
paulson@14365
   415
avigad@16819
   416
lemma reals_Archimedean6:
avigad@16819
   417
     "0 \<le> r ==> \<exists>(n::nat). real (n - 1) \<le> r & r < real (n)"
huffman@30097
   418
unfolding real_of_nat_def
huffman@30097
   419
apply (rule exI [where x="nat (floor r + 1)"])
huffman@30097
   420
apply (insert floor_correct [of r])
huffman@30097
   421
apply (simp add: nat_add_distrib of_nat_nat)
avigad@16819
   422
done
avigad@16819
   423
avigad@16819
   424
lemma reals_Archimedean6a: "0 \<le> r ==> \<exists>n. real (n) \<le> r & r < real (Suc n)"
wenzelm@16893
   425
  by (drule reals_Archimedean6) auto
avigad@16819
   426
avigad@16819
   427
lemma reals_Archimedean_6b_int:
avigad@16819
   428
     "0 \<le> r ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
huffman@30097
   429
  unfolding real_of_int_def by (rule floor_exists)
avigad@16819
   430
avigad@16819
   431
lemma reals_Archimedean_6c_int:
avigad@16819
   432
     "r < 0 ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
huffman@30097
   433
  unfolding real_of_int_def by (rule floor_exists)
avigad@16819
   434
avigad@16819
   435
nipkow@28091
   436
subsection{*Density of the Rational Reals in the Reals*}
nipkow@28091
   437
nipkow@28091
   438
text{* This density proof is due to Stefan Richter and was ported by TN.  The
nipkow@28091
   439
original source is \emph{Real Analysis} by H.L. Royden.
nipkow@28091
   440
It employs the Archimedean property of the reals. *}
nipkow@28091
   441
nipkow@28091
   442
lemma Rats_dense_in_nn_real: fixes x::real
nipkow@28091
   443
assumes "0\<le>x" and "x<y" shows "\<exists>r \<in> \<rat>.  x<r \<and> r<y"
nipkow@28091
   444
proof -
nipkow@28091
   445
  from `x<y` have "0 < y-x" by simp
nipkow@28091
   446
  with reals_Archimedean obtain q::nat 
nipkow@28091
   447
    where q: "inverse (real q) < y-x" and "0 < real q" by auto  
nipkow@28091
   448
  def p \<equiv> "LEAST n.  y \<le> real (Suc n)/real q"  
nipkow@28091
   449
  from reals_Archimedean2 obtain n::nat where "y * real q < real n" by auto
nipkow@28091
   450
  with `0 < real q` have ex: "y \<le> real n/real q" (is "?P n")
nipkow@28091
   451
    by (simp add: pos_less_divide_eq[THEN sym])
nipkow@28091
   452
  also from assms have "\<not> y \<le> real (0::nat) / real q" by simp
nipkow@28091
   453
  ultimately have main: "(LEAST n. y \<le> real n/real q) = Suc p"
nipkow@28091
   454
    by (unfold p_def) (rule Least_Suc)
nipkow@28091
   455
  also from ex have "?P (LEAST x. ?P x)" by (rule LeastI)
nipkow@28091
   456
  ultimately have suc: "y \<le> real (Suc p) / real q" by simp
nipkow@28091
   457
  def r \<equiv> "real p/real q"
nipkow@28091
   458
  have "x = y-(y-x)" by simp
nipkow@28091
   459
  also from suc q have "\<dots> < real (Suc p)/real q - inverse (real q)" by arith
nipkow@28091
   460
  also have "\<dots> = real p / real q"
nipkow@28091
   461
    by (simp only: inverse_eq_divide real_diff_def real_of_nat_Suc 
nipkow@28091
   462
    minus_divide_left add_divide_distrib[THEN sym]) simp
nipkow@28091
   463
  finally have "x<r" by (unfold r_def)
nipkow@28091
   464
  have "p<Suc p" .. also note main[THEN sym]
nipkow@28091
   465
  finally have "\<not> ?P p"  by (rule not_less_Least)
nipkow@28091
   466
  hence "r<y" by (simp add: r_def)
nipkow@28091
   467
  from r_def have "r \<in> \<rat>" by simp
nipkow@28091
   468
  with `x<r` `r<y` show ?thesis by fast
nipkow@28091
   469
qed
nipkow@28091
   470
nipkow@28091
   471
theorem Rats_dense_in_real: fixes x y :: real
nipkow@28091
   472
assumes "x<y" shows "\<exists>r \<in> \<rat>.  x<r \<and> r<y"
nipkow@28091
   473
proof -
nipkow@28091
   474
  from reals_Archimedean2 obtain n::nat where "-x < real n" by auto
nipkow@28091
   475
  hence "0 \<le> x + real n" by arith
nipkow@28091
   476
  also from `x<y` have "x + real n < y + real n" by arith
nipkow@28091
   477
  ultimately have "\<exists>r \<in> \<rat>. x + real n < r \<and> r < y + real n"
nipkow@28091
   478
    by(rule Rats_dense_in_nn_real)
nipkow@28091
   479
  then obtain r where "r \<in> \<rat>" and r2: "x + real n < r" 
nipkow@28091
   480
    and r3: "r < y + real n"
nipkow@28091
   481
    by blast
nipkow@28091
   482
  have "r - real n = r + real (int n)/real (-1::int)" by simp
nipkow@28091
   483
  also from `r\<in>\<rat>` have "r + real (int n)/real (-1::int) \<in> \<rat>" by simp
nipkow@28091
   484
  also from r2 have "x < r - real n" by arith
nipkow@28091
   485
  moreover from r3 have "r - real n < y" by arith
nipkow@28091
   486
  ultimately show ?thesis by fast
nipkow@28091
   487
qed
nipkow@28091
   488
nipkow@28091
   489
paulson@14641
   490
subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
paulson@14641
   491
paulson@14641
   492
lemma number_of_less_real_of_int_iff [simp]:
paulson@14641
   493
     "((number_of n) < real (m::int)) = (number_of n < m)"
paulson@14641
   494
apply auto
paulson@14641
   495
apply (rule real_of_int_less_iff [THEN iffD1])
paulson@14641
   496
apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
paulson@14641
   497
done
paulson@14641
   498
paulson@14641
   499
lemma number_of_less_real_of_int_iff2 [simp]:
paulson@14641
   500
     "(real (m::int) < (number_of n)) = (m < number_of n)"
paulson@14641
   501
apply auto
paulson@14641
   502
apply (rule real_of_int_less_iff [THEN iffD1])
paulson@14641
   503
apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
paulson@14641
   504
done
paulson@14641
   505
paulson@14641
   506
lemma number_of_le_real_of_int_iff [simp]:
paulson@14641
   507
     "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"
paulson@14641
   508
by (simp add: linorder_not_less [symmetric])
paulson@14641
   509
paulson@14641
   510
lemma number_of_le_real_of_int_iff2 [simp]:
paulson@14641
   511
     "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"
paulson@14641
   512
by (simp add: linorder_not_less [symmetric])
paulson@14641
   513
huffman@30097
   514
lemma floor_real_of_nat_zero: "floor (real (0::nat)) = 0"
huffman@30097
   515
by auto (* delete? *)
paulson@14641
   516
huffman@24355
   517
lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
huffman@30097
   518
unfolding real_of_nat_def by simp
paulson@14641
   519
huffman@24355
   520
lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
huffman@30102
   521
unfolding real_of_nat_def by (simp add: floor_minus)
paulson@14641
   522
paulson@14641
   523
lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
huffman@30097
   524
unfolding real_of_int_def by simp
paulson@14641
   525
paulson@14641
   526
lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
huffman@30102
   527
unfolding real_of_int_def by (simp add: floor_minus)
paulson@14641
   528
paulson@14641
   529
lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"
huffman@30097
   530
unfolding real_of_int_def by (rule floor_exists)
paulson@14641
   531
paulson@14641
   532
lemma lemma_floor:
paulson@14641
   533
  assumes a1: "real m \<le> r" and a2: "r < real n + 1"
paulson@14641
   534
  shows "m \<le> (n::int)"
paulson@14641
   535
proof -
wenzelm@23389
   536
  have "real m < real n + 1" using a1 a2 by (rule order_le_less_trans)
wenzelm@23389
   537
  also have "... = real (n + 1)" by simp
wenzelm@23389
   538
  finally have "m < n + 1" by (simp only: real_of_int_less_iff)
paulson@14641
   539
  thus ?thesis by arith
paulson@14641
   540
qed
paulson@14641
   541
paulson@14641
   542
lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
huffman@30097
   543
unfolding real_of_int_def by (rule of_int_floor_le)
paulson@14641
   544
paulson@14641
   545
lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"
paulson@14641
   546
by (auto intro: lemma_floor)
paulson@14641
   547
paulson@14641
   548
lemma real_of_int_floor_cancel [simp]:
paulson@14641
   549
    "(real (floor x) = x) = (\<exists>n::int. x = real n)"
huffman@30097
   550
  using floor_real_of_int by metis
paulson@14641
   551
paulson@14641
   552
lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
huffman@30097
   553
  unfolding real_of_int_def using floor_unique [of n x] by simp
paulson@14641
   554
paulson@14641
   555
lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
huffman@30097
   556
  unfolding real_of_int_def by (rule floor_unique)
paulson@14641
   557
paulson@14641
   558
lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
paulson@14641
   559
apply (rule inj_int [THEN injD])
paulson@14641
   560
apply (simp add: real_of_nat_Suc)
nipkow@15539
   561
apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "int n"])
paulson@14641
   562
done
paulson@14641
   563
paulson@14641
   564
lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
paulson@14641
   565
apply (drule order_le_imp_less_or_eq)
paulson@14641
   566
apply (auto intro: floor_eq3)
paulson@14641
   567
done
paulson@14641
   568
huffman@30097
   569
lemma floor_number_of_eq:
paulson@14641
   570
     "floor(number_of n :: real) = (number_of n :: int)"
huffman@30097
   571
  by (rule floor_number_of) (* already declared [simp] *)
avigad@16819
   572
paulson@14641
   573
lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
huffman@30097
   574
  unfolding real_of_int_def using floor_correct [of r] by simp
avigad@16819
   575
avigad@16819
   576
lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real(floor r)"
huffman@30097
   577
  unfolding real_of_int_def using floor_correct [of r] by simp
paulson@14641
   578
paulson@14641
   579
lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
huffman@30097
   580
  unfolding real_of_int_def using floor_correct [of r] by simp
paulson@14641
   581
avigad@16819
   582
lemma real_of_int_floor_add_one_gt [simp]: "r < real(floor r) + 1"
huffman@30097
   583
  unfolding real_of_int_def using floor_correct [of r] by simp
paulson@14641
   584
avigad@16819
   585
lemma le_floor: "real a <= x ==> a <= floor x"
huffman@30097
   586
  unfolding real_of_int_def by (simp add: le_floor_iff)
avigad@16819
   587
avigad@16819
   588
lemma real_le_floor: "a <= floor x ==> real a <= x"
huffman@30097
   589
  unfolding real_of_int_def by (simp add: le_floor_iff)
avigad@16819
   590
avigad@16819
   591
lemma le_floor_eq: "(a <= floor x) = (real a <= x)"
huffman@30097
   592
  unfolding real_of_int_def by (rule le_floor_iff)
avigad@16819
   593
huffman@30097
   594
lemma le_floor_eq_number_of:
avigad@16819
   595
    "(number_of n <= floor x) = (number_of n <= x)"
huffman@30097
   596
  by (rule number_of_le_floor) (* already declared [simp] *)
avigad@16819
   597
huffman@30097
   598
lemma le_floor_eq_zero: "(0 <= floor x) = (0 <= x)"
huffman@30097
   599
  by (rule zero_le_floor) (* already declared [simp] *)
avigad@16819
   600
huffman@30097
   601
lemma le_floor_eq_one: "(1 <= floor x) = (1 <= x)"
huffman@30097
   602
  by (rule one_le_floor) (* already declared [simp] *)
avigad@16819
   603
avigad@16819
   604
lemma floor_less_eq: "(floor x < a) = (x < real a)"
huffman@30097
   605
  unfolding real_of_int_def by (rule floor_less_iff)
avigad@16819
   606
huffman@30097
   607
lemma floor_less_eq_number_of:
avigad@16819
   608
    "(floor x < number_of n) = (x < number_of n)"
huffman@30097
   609
  by (rule floor_less_number_of) (* already declared [simp] *)
avigad@16819
   610
huffman@30097
   611
lemma floor_less_eq_zero: "(floor x < 0) = (x < 0)"
huffman@30097
   612
  by (rule floor_less_zero) (* already declared [simp] *)
avigad@16819
   613
huffman@30097
   614
lemma floor_less_eq_one: "(floor x < 1) = (x < 1)"
huffman@30097
   615
  by (rule floor_less_one) (* already declared [simp] *)
avigad@16819
   616
avigad@16819
   617
lemma less_floor_eq: "(a < floor x) = (real a + 1 <= x)"
huffman@30097
   618
  unfolding real_of_int_def by (rule less_floor_iff)
avigad@16819
   619
huffman@30097
   620
lemma less_floor_eq_number_of:
avigad@16819
   621
    "(number_of n < floor x) = (number_of n + 1 <= x)"
huffman@30097
   622
  by (rule number_of_less_floor) (* already declared [simp] *)
avigad@16819
   623
huffman@30097
   624
lemma less_floor_eq_zero: "(0 < floor x) = (1 <= x)"
huffman@30097
   625
  by (rule zero_less_floor) (* already declared [simp] *)
avigad@16819
   626
huffman@30097
   627
lemma less_floor_eq_one: "(1 < floor x) = (2 <= x)"
huffman@30097
   628
  by (rule one_less_floor) (* already declared [simp] *)
avigad@16819
   629
avigad@16819
   630
lemma floor_le_eq: "(floor x <= a) = (x < real a + 1)"
huffman@30097
   631
  unfolding real_of_int_def by (rule floor_le_iff)
avigad@16819
   632
huffman@30097
   633
lemma floor_le_eq_number_of:
avigad@16819
   634
    "(floor x <= number_of n) = (x < number_of n + 1)"
huffman@30097
   635
  by (rule floor_le_number_of) (* already declared [simp] *)
avigad@16819
   636
huffman@30097
   637
lemma floor_le_eq_zero: "(floor x <= 0) = (x < 1)"
huffman@30097
   638
  by (rule floor_le_zero) (* already declared [simp] *)
avigad@16819
   639
huffman@30097
   640
lemma floor_le_eq_one: "(floor x <= 1) = (x < 2)"
huffman@30097
   641
  by (rule floor_le_one) (* already declared [simp] *)
avigad@16819
   642
avigad@16819
   643
lemma floor_add [simp]: "floor (x + real a) = floor x + a"
huffman@30097
   644
  unfolding real_of_int_def by (rule floor_add_of_int)
avigad@16819
   645
avigad@16819
   646
lemma floor_subtract [simp]: "floor (x - real a) = floor x - a"
huffman@30097
   647
  unfolding real_of_int_def by (rule floor_diff_of_int)
avigad@16819
   648
huffman@30097
   649
lemma floor_subtract_number_of: "floor (x - number_of n) =
avigad@16819
   650
    floor x - number_of n"
huffman@30097
   651
  by (rule floor_diff_number_of) (* already declared [simp] *)
avigad@16819
   652
huffman@30097
   653
lemma floor_subtract_one: "floor (x - 1) = floor x - 1"
huffman@30097
   654
  by (rule floor_diff_one) (* already declared [simp] *)
paulson@14641
   655
hoelzl@35578
   656
lemma le_mult_floor:
hoelzl@35578
   657
  assumes "0 \<le> (a :: real)" and "0 \<le> b"
hoelzl@35578
   658
  shows "floor a * floor b \<le> floor (a * b)"
hoelzl@35578
   659
proof -
hoelzl@35578
   660
  have "real (floor a) \<le> a"
hoelzl@35578
   661
    and "real (floor b) \<le> b" by auto
hoelzl@35578
   662
  hence "real (floor a * floor b) \<le> a * b"
hoelzl@35578
   663
    using assms by (auto intro!: mult_mono)
hoelzl@35578
   664
  also have "a * b < real (floor (a * b) + 1)" by auto
hoelzl@35578
   665
  finally show ?thesis unfolding real_of_int_less_iff by simp
hoelzl@35578
   666
qed
hoelzl@35578
   667
huffman@24355
   668
lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
huffman@30097
   669
  unfolding real_of_nat_def by simp
paulson@14641
   670
huffman@30097
   671
lemma ceiling_real_of_nat_zero: "ceiling (real (0::nat)) = 0"
huffman@30097
   672
by auto (* delete? *)
paulson@14641
   673
paulson@14641
   674
lemma ceiling_floor [simp]: "ceiling (real (floor r)) = floor r"
huffman@30097
   675
  unfolding real_of_int_def by simp
paulson@14641
   676
paulson@14641
   677
lemma floor_ceiling [simp]: "floor (real (ceiling r)) = ceiling r"
huffman@30097
   678
  unfolding real_of_int_def by simp
paulson@14641
   679
paulson@14641
   680
lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
huffman@30097
   681
  unfolding real_of_int_def by (rule le_of_int_ceiling)
paulson@14641
   682
huffman@30097
   683
lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
huffman@30097
   684
  unfolding real_of_int_def by simp
paulson@14641
   685
paulson@14641
   686
lemma real_of_int_ceiling_cancel [simp]:
paulson@14641
   687
     "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
huffman@30097
   688
  using ceiling_real_of_int by metis
paulson@14641
   689
paulson@14641
   690
lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
huffman@30097
   691
  unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp
paulson@14641
   692
paulson@14641
   693
lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
huffman@30097
   694
  unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp
paulson@14641
   695
paulson@14641
   696
lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"
huffman@30097
   697
  unfolding real_of_int_def using ceiling_unique [of n x] by simp
paulson@14641
   698
huffman@30097
   699
lemma ceiling_number_of_eq:
paulson@14641
   700
     "ceiling (number_of n :: real) = (number_of n)"
huffman@30097
   701
  by (rule ceiling_number_of) (* already declared [simp] *)
avigad@16819
   702
paulson@14641
   703
lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
huffman@30097
   704
  unfolding real_of_int_def using ceiling_correct [of r] by simp
paulson@14641
   705
paulson@14641
   706
lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
huffman@30097
   707
  unfolding real_of_int_def using ceiling_correct [of r] by simp
paulson@14641
   708
avigad@16819
   709
lemma ceiling_le: "x <= real a ==> ceiling x <= a"
huffman@30097
   710
  unfolding real_of_int_def by (simp add: ceiling_le_iff)
avigad@16819
   711
avigad@16819
   712
lemma ceiling_le_real: "ceiling x <= a ==> x <= real a"
huffman@30097
   713
  unfolding real_of_int_def by (simp add: ceiling_le_iff)
avigad@16819
   714
avigad@16819
   715
lemma ceiling_le_eq: "(ceiling x <= a) = (x <= real a)"
huffman@30097
   716
  unfolding real_of_int_def by (rule ceiling_le_iff)
avigad@16819
   717
huffman@30097
   718
lemma ceiling_le_eq_number_of:
avigad@16819
   719
    "(ceiling x <= number_of n) = (x <= number_of n)"
huffman@30097
   720
  by (rule ceiling_le_number_of) (* already declared [simp] *)
avigad@16819
   721
huffman@30097
   722
lemma ceiling_le_zero_eq: "(ceiling x <= 0) = (x <= 0)"
huffman@30097
   723
  by (rule ceiling_le_zero) (* already declared [simp] *)
avigad@16819
   724
huffman@30097
   725
lemma ceiling_le_eq_one: "(ceiling x <= 1) = (x <= 1)"
huffman@30097
   726
  by (rule ceiling_le_one) (* already declared [simp] *)
avigad@16819
   727
avigad@16819
   728
lemma less_ceiling_eq: "(a < ceiling x) = (real a < x)"
huffman@30097
   729
  unfolding real_of_int_def by (rule less_ceiling_iff)
avigad@16819
   730
huffman@30097
   731
lemma less_ceiling_eq_number_of:
avigad@16819
   732
    "(number_of n < ceiling x) = (number_of n < x)"
huffman@30097
   733
  by (rule number_of_less_ceiling) (* already declared [simp] *)
avigad@16819
   734
huffman@30097
   735
lemma less_ceiling_eq_zero: "(0 < ceiling x) = (0 < x)"
huffman@30097
   736
  by (rule zero_less_ceiling) (* already declared [simp] *)
avigad@16819
   737
huffman@30097
   738
lemma less_ceiling_eq_one: "(1 < ceiling x) = (1 < x)"
huffman@30097
   739
  by (rule one_less_ceiling) (* already declared [simp] *)
avigad@16819
   740
avigad@16819
   741
lemma ceiling_less_eq: "(ceiling x < a) = (x <= real a - 1)"
huffman@30097
   742
  unfolding real_of_int_def by (rule ceiling_less_iff)
avigad@16819
   743
huffman@30097
   744
lemma ceiling_less_eq_number_of:
avigad@16819
   745
    "(ceiling x < number_of n) = (x <= number_of n - 1)"
huffman@30097
   746
  by (rule ceiling_less_number_of) (* already declared [simp] *)
avigad@16819
   747
huffman@30097
   748
lemma ceiling_less_eq_zero: "(ceiling x < 0) = (x <= -1)"
huffman@30097
   749
  by (rule ceiling_less_zero) (* already declared [simp] *)
avigad@16819
   750
huffman@30097
   751
lemma ceiling_less_eq_one: "(ceiling x < 1) = (x <= 0)"
huffman@30097
   752
  by (rule ceiling_less_one) (* already declared [simp] *)
avigad@16819
   753
avigad@16819
   754
lemma le_ceiling_eq: "(a <= ceiling x) = (real a - 1 < x)"
huffman@30097
   755
  unfolding real_of_int_def by (rule le_ceiling_iff)
avigad@16819
   756
huffman@30097
   757
lemma le_ceiling_eq_number_of:
avigad@16819
   758
    "(number_of n <= ceiling x) = (number_of n - 1 < x)"
huffman@30097
   759
  by (rule number_of_le_ceiling) (* already declared [simp] *)
avigad@16819
   760
huffman@30097
   761
lemma le_ceiling_eq_zero: "(0 <= ceiling x) = (-1 < x)"
huffman@30097
   762
  by (rule zero_le_ceiling) (* already declared [simp] *)
avigad@16819
   763
huffman@30097
   764
lemma le_ceiling_eq_one: "(1 <= ceiling x) = (0 < x)"
huffman@30097
   765
  by (rule one_le_ceiling) (* already declared [simp] *)
avigad@16819
   766
avigad@16819
   767
lemma ceiling_add [simp]: "ceiling (x + real a) = ceiling x + a"
huffman@30097
   768
  unfolding real_of_int_def by (rule ceiling_add_of_int)
avigad@16819
   769
avigad@16819
   770
lemma ceiling_subtract [simp]: "ceiling (x - real a) = ceiling x - a"
huffman@30097
   771
  unfolding real_of_int_def by (rule ceiling_diff_of_int)
avigad@16819
   772
huffman@30097
   773
lemma ceiling_subtract_number_of: "ceiling (x - number_of n) =
avigad@16819
   774
    ceiling x - number_of n"
huffman@30097
   775
  by (rule ceiling_diff_number_of) (* already declared [simp] *)
avigad@16819
   776
huffman@30097
   777
lemma ceiling_subtract_one: "ceiling (x - 1) = ceiling x - 1"
huffman@30097
   778
  by (rule ceiling_diff_one) (* already declared [simp] *)
huffman@30097
   779
avigad@16819
   780
avigad@16819
   781
subsection {* Versions for the natural numbers *}
avigad@16819
   782
wenzelm@19765
   783
definition
wenzelm@21404
   784
  natfloor :: "real => nat" where
wenzelm@19765
   785
  "natfloor x = nat(floor x)"
wenzelm@21404
   786
wenzelm@21404
   787
definition
wenzelm@21404
   788
  natceiling :: "real => nat" where
wenzelm@19765
   789
  "natceiling x = nat(ceiling x)"
avigad@16819
   790
avigad@16819
   791
lemma natfloor_zero [simp]: "natfloor 0 = 0"
avigad@16819
   792
  by (unfold natfloor_def, simp)
avigad@16819
   793
avigad@16819
   794
lemma natfloor_one [simp]: "natfloor 1 = 1"
avigad@16819
   795
  by (unfold natfloor_def, simp)
avigad@16819
   796
avigad@16819
   797
lemma zero_le_natfloor [simp]: "0 <= natfloor x"
avigad@16819
   798
  by (unfold natfloor_def, simp)
avigad@16819
   799
avigad@16819
   800
lemma natfloor_number_of_eq [simp]: "natfloor (number_of n) = number_of n"
avigad@16819
   801
  by (unfold natfloor_def, simp)
avigad@16819
   802
avigad@16819
   803
lemma natfloor_real_of_nat [simp]: "natfloor(real n) = n"
avigad@16819
   804
  by (unfold natfloor_def, simp)
avigad@16819
   805
avigad@16819
   806
lemma real_natfloor_le: "0 <= x ==> real(natfloor x) <= x"
avigad@16819
   807
  by (unfold natfloor_def, simp)
avigad@16819
   808
avigad@16819
   809
lemma natfloor_neg: "x <= 0 ==> natfloor x = 0"
avigad@16819
   810
  apply (unfold natfloor_def)
avigad@16819
   811
  apply (subgoal_tac "floor x <= floor 0")
avigad@16819
   812
  apply simp
huffman@30097
   813
  apply (erule floor_mono)
avigad@16819
   814
done
avigad@16819
   815
avigad@16819
   816
lemma natfloor_mono: "x <= y ==> natfloor x <= natfloor y"
avigad@16819
   817
  apply (case_tac "0 <= x")
avigad@16819
   818
  apply (subst natfloor_def)+
avigad@16819
   819
  apply (subst nat_le_eq_zle)
avigad@16819
   820
  apply force
huffman@30097
   821
  apply (erule floor_mono)
avigad@16819
   822
  apply (subst natfloor_neg)
avigad@16819
   823
  apply simp
avigad@16819
   824
  apply simp
avigad@16819
   825
done
avigad@16819
   826
avigad@16819
   827
lemma le_natfloor: "real x <= a ==> x <= natfloor a"
avigad@16819
   828
  apply (unfold natfloor_def)
avigad@16819
   829
  apply (subst nat_int [THEN sym])
avigad@16819
   830
  apply (subst nat_le_eq_zle)
avigad@16819
   831
  apply simp
avigad@16819
   832
  apply (rule le_floor)
avigad@16819
   833
  apply simp
avigad@16819
   834
done
avigad@16819
   835
hoelzl@35578
   836
lemma less_natfloor:
hoelzl@35578
   837
  assumes "0 \<le> x" and "x < real (n :: nat)"
hoelzl@35578
   838
  shows "natfloor x < n"
hoelzl@35578
   839
proof (rule ccontr)
hoelzl@35578
   840
  assume "\<not> ?thesis" hence *: "n \<le> natfloor x" by simp
hoelzl@35578
   841
  note assms(2)
hoelzl@35578
   842
  also have "real n \<le> real (natfloor x)"
hoelzl@35578
   843
    using * unfolding real_of_nat_le_iff .
hoelzl@35578
   844
  finally have "x < real (natfloor x)" .
hoelzl@35578
   845
  with real_natfloor_le[OF assms(1)]
hoelzl@35578
   846
  show False by auto
hoelzl@35578
   847
qed
hoelzl@35578
   848
avigad@16819
   849
lemma le_natfloor_eq: "0 <= x ==> (a <= natfloor x) = (real a <= x)"
avigad@16819
   850
  apply (rule iffI)
avigad@16819
   851
  apply (rule order_trans)
avigad@16819
   852
  prefer 2
avigad@16819
   853
  apply (erule real_natfloor_le)
avigad@16819
   854
  apply (subst real_of_nat_le_iff)
avigad@16819
   855
  apply assumption
avigad@16819
   856
  apply (erule le_natfloor)
avigad@16819
   857
done
avigad@16819
   858
wenzelm@16893
   859
lemma le_natfloor_eq_number_of [simp]:
avigad@16819
   860
    "~ neg((number_of n)::int) ==> 0 <= x ==>
avigad@16819
   861
      (number_of n <= natfloor x) = (number_of n <= x)"
avigad@16819
   862
  apply (subst le_natfloor_eq, assumption)
avigad@16819
   863
  apply simp
avigad@16819
   864
done
avigad@16819
   865
avigad@16820
   866
lemma le_natfloor_eq_one [simp]: "(1 <= natfloor x) = (1 <= x)"
avigad@16819
   867
  apply (case_tac "0 <= x")
avigad@16819
   868
  apply (subst le_natfloor_eq, assumption, simp)
avigad@16819
   869
  apply (rule iffI)
wenzelm@16893
   870
  apply (subgoal_tac "natfloor x <= natfloor 0")
avigad@16819
   871
  apply simp
avigad@16819
   872
  apply (rule natfloor_mono)
avigad@16819
   873
  apply simp
avigad@16819
   874
  apply simp
avigad@16819
   875
done
avigad@16819
   876
avigad@16819
   877
lemma natfloor_eq: "real n <= x ==> x < real n + 1 ==> natfloor x = n"
avigad@16819
   878
  apply (unfold natfloor_def)
hoelzl@35578
   879
  apply (subst (2) nat_int [THEN sym])
avigad@16819
   880
  apply (subst eq_nat_nat_iff)
avigad@16819
   881
  apply simp
avigad@16819
   882
  apply simp
avigad@16819
   883
  apply (rule floor_eq2)
avigad@16819
   884
  apply auto
avigad@16819
   885
done
avigad@16819
   886
avigad@16819
   887
lemma real_natfloor_add_one_gt: "x < real(natfloor x) + 1"
avigad@16819
   888
  apply (case_tac "0 <= x")
avigad@16819
   889
  apply (unfold natfloor_def)
avigad@16819
   890
  apply simp
avigad@16819
   891
  apply simp_all
avigad@16819
   892
done
avigad@16819
   893
avigad@16819
   894
lemma real_natfloor_gt_diff_one: "x - 1 < real(natfloor x)"
nipkow@29667
   895
using real_natfloor_add_one_gt by (simp add: algebra_simps)
avigad@16819
   896
avigad@16819
   897
lemma ge_natfloor_plus_one_imp_gt: "natfloor z + 1 <= n ==> z < real n"
avigad@16819
   898
  apply (subgoal_tac "z < real(natfloor z) + 1")
avigad@16819
   899
  apply arith
avigad@16819
   900
  apply (rule real_natfloor_add_one_gt)
avigad@16819
   901
done
avigad@16819
   902
avigad@16819
   903
lemma natfloor_add [simp]: "0 <= x ==> natfloor (x + real a) = natfloor x + a"
avigad@16819
   904
  apply (unfold natfloor_def)
huffman@24355
   905
  apply (subgoal_tac "real a = real (int a)")
avigad@16819
   906
  apply (erule ssubst)
huffman@23309
   907
  apply (simp add: nat_add_distrib del: real_of_int_of_nat_eq)
avigad@16819
   908
  apply simp
avigad@16819
   909
done
avigad@16819
   910
wenzelm@16893
   911
lemma natfloor_add_number_of [simp]:
wenzelm@16893
   912
    "~neg ((number_of n)::int) ==> 0 <= x ==>
avigad@16819
   913
      natfloor (x + number_of n) = natfloor x + number_of n"
avigad@16819
   914
  apply (subst natfloor_add [THEN sym])
avigad@16819
   915
  apply simp_all
avigad@16819
   916
done
avigad@16819
   917
avigad@16819
   918
lemma natfloor_add_one: "0 <= x ==> natfloor(x + 1) = natfloor x + 1"
avigad@16819
   919
  apply (subst natfloor_add [THEN sym])
avigad@16819
   920
  apply assumption
avigad@16819
   921
  apply simp
avigad@16819
   922
done
avigad@16819
   923
wenzelm@16893
   924
lemma natfloor_subtract [simp]: "real a <= x ==>
avigad@16819
   925
    natfloor(x - real a) = natfloor x - a"
avigad@16819
   926
  apply (unfold natfloor_def)
huffman@24355
   927
  apply (subgoal_tac "real a = real (int a)")
avigad@16819
   928
  apply (erule ssubst)
huffman@23309
   929
  apply (simp del: real_of_int_of_nat_eq)
avigad@16819
   930
  apply simp
avigad@16819
   931
done
avigad@16819
   932
hoelzl@35578
   933
lemma natfloor_div_nat: "1 <= x ==> y > 0 ==>
hoelzl@35578
   934
  natfloor (x / real y) = natfloor x div y"
hoelzl@35578
   935
proof -
hoelzl@35578
   936
  assume "1 <= (x::real)" and "(y::nat) > 0"
hoelzl@35578
   937
  have "natfloor x = (natfloor x) div y * y + (natfloor x) mod y"
hoelzl@35578
   938
    by simp
hoelzl@35578
   939
  then have a: "real(natfloor x) = real ((natfloor x) div y) * real y +
hoelzl@35578
   940
    real((natfloor x) mod y)"
hoelzl@35578
   941
    by (simp only: real_of_nat_add [THEN sym] real_of_nat_mult [THEN sym])
hoelzl@35578
   942
  have "x = real(natfloor x) + (x - real(natfloor x))"
hoelzl@35578
   943
    by simp
hoelzl@35578
   944
  then have "x = real ((natfloor x) div y) * real y +
hoelzl@35578
   945
      real((natfloor x) mod y) + (x - real(natfloor x))"
hoelzl@35578
   946
    by (simp add: a)
hoelzl@35578
   947
  then have "x / real y = ... / real y"
hoelzl@35578
   948
    by simp
hoelzl@35578
   949
  also have "... = real((natfloor x) div y) + real((natfloor x) mod y) /
hoelzl@35578
   950
    real y + (x - real(natfloor x)) / real y"
hoelzl@35578
   951
    by (auto simp add: algebra_simps add_divide_distrib
hoelzl@35578
   952
      diff_divide_distrib prems)
hoelzl@35578
   953
  finally have "natfloor (x / real y) = natfloor(...)" by simp
hoelzl@35578
   954
  also have "... = natfloor(real((natfloor x) mod y) /
hoelzl@35578
   955
    real y + (x - real(natfloor x)) / real y + real((natfloor x) div y))"
hoelzl@35578
   956
    by (simp add: add_ac)
hoelzl@35578
   957
  also have "... = natfloor(real((natfloor x) mod y) /
hoelzl@35578
   958
    real y + (x - real(natfloor x)) / real y) + (natfloor x) div y"
hoelzl@35578
   959
    apply (rule natfloor_add)
hoelzl@35578
   960
    apply (rule add_nonneg_nonneg)
hoelzl@35578
   961
    apply (rule divide_nonneg_pos)
hoelzl@35578
   962
    apply simp
hoelzl@35578
   963
    apply (simp add: prems)
hoelzl@35578
   964
    apply (rule divide_nonneg_pos)
hoelzl@35578
   965
    apply (simp add: algebra_simps)
hoelzl@35578
   966
    apply (rule real_natfloor_le)
hoelzl@35578
   967
    apply (insert prems, auto)
hoelzl@35578
   968
    done
hoelzl@35578
   969
  also have "natfloor(real((natfloor x) mod y) /
hoelzl@35578
   970
    real y + (x - real(natfloor x)) / real y) = 0"
hoelzl@35578
   971
    apply (rule natfloor_eq)
hoelzl@35578
   972
    apply simp
hoelzl@35578
   973
    apply (rule add_nonneg_nonneg)
hoelzl@35578
   974
    apply (rule divide_nonneg_pos)
hoelzl@35578
   975
    apply force
hoelzl@35578
   976
    apply (force simp add: prems)
hoelzl@35578
   977
    apply (rule divide_nonneg_pos)
hoelzl@35578
   978
    apply (simp add: algebra_simps)
hoelzl@35578
   979
    apply (rule real_natfloor_le)
hoelzl@35578
   980
    apply (auto simp add: prems)
hoelzl@35578
   981
    apply (insert prems, arith)
hoelzl@35578
   982
    apply (simp add: add_divide_distrib [THEN sym])
hoelzl@35578
   983
    apply (subgoal_tac "real y = real y - 1 + 1")
hoelzl@35578
   984
    apply (erule ssubst)
hoelzl@35578
   985
    apply (rule add_le_less_mono)
hoelzl@35578
   986
    apply (simp add: algebra_simps)
hoelzl@35578
   987
    apply (subgoal_tac "1 + real(natfloor x mod y) =
hoelzl@35578
   988
      real(natfloor x mod y + 1)")
hoelzl@35578
   989
    apply (erule ssubst)
hoelzl@35578
   990
    apply (subst real_of_nat_le_iff)
hoelzl@35578
   991
    apply (subgoal_tac "natfloor x mod y < y")
hoelzl@35578
   992
    apply arith
hoelzl@35578
   993
    apply (rule mod_less_divisor)
hoelzl@35578
   994
    apply auto
hoelzl@35578
   995
    using real_natfloor_add_one_gt
hoelzl@35578
   996
    apply (simp add: algebra_simps)
hoelzl@35578
   997
    done
hoelzl@35578
   998
  finally show ?thesis by simp
hoelzl@35578
   999
qed
hoelzl@35578
  1000
hoelzl@35578
  1001
lemma le_mult_natfloor:
hoelzl@35578
  1002
  assumes "0 \<le> (a :: real)" and "0 \<le> b"
hoelzl@35578
  1003
  shows "natfloor a * natfloor b \<le> natfloor (a * b)"
hoelzl@35578
  1004
  unfolding natfloor_def
hoelzl@35578
  1005
  apply (subst nat_mult_distrib[symmetric])
hoelzl@35578
  1006
  using assms apply simp
hoelzl@35578
  1007
  apply (subst nat_le_eq_zle)
hoelzl@35578
  1008
  using assms le_mult_floor by (auto intro!: mult_nonneg_nonneg)
hoelzl@35578
  1009
avigad@16819
  1010
lemma natceiling_zero [simp]: "natceiling 0 = 0"
avigad@16819
  1011
  by (unfold natceiling_def, simp)
avigad@16819
  1012
avigad@16819
  1013
lemma natceiling_one [simp]: "natceiling 1 = 1"
avigad@16819
  1014
  by (unfold natceiling_def, simp)
avigad@16819
  1015
avigad@16819
  1016
lemma zero_le_natceiling [simp]: "0 <= natceiling x"
avigad@16819
  1017
  by (unfold natceiling_def, simp)
avigad@16819
  1018
avigad@16819
  1019
lemma natceiling_number_of_eq [simp]: "natceiling (number_of n) = number_of n"
avigad@16819
  1020
  by (unfold natceiling_def, simp)
avigad@16819
  1021
avigad@16819
  1022
lemma natceiling_real_of_nat [simp]: "natceiling(real n) = n"
avigad@16819
  1023
  by (unfold natceiling_def, simp)
avigad@16819
  1024
avigad@16819
  1025
lemma real_natceiling_ge: "x <= real(natceiling x)"
avigad@16819
  1026
  apply (unfold natceiling_def)
avigad@16819
  1027
  apply (case_tac "x < 0")
avigad@16819
  1028
  apply simp
avigad@16819
  1029
  apply (subst real_nat_eq_real)
avigad@16819
  1030
  apply (subgoal_tac "ceiling 0 <= ceiling x")
avigad@16819
  1031
  apply simp
huffman@30097
  1032
  apply (rule ceiling_mono)
avigad@16819
  1033
  apply simp
avigad@16819
  1034
  apply simp
avigad@16819
  1035
done
avigad@16819
  1036
avigad@16819
  1037
lemma natceiling_neg: "x <= 0 ==> natceiling x = 0"
avigad@16819
  1038
  apply (unfold natceiling_def)
avigad@16819
  1039
  apply simp
avigad@16819
  1040
done
avigad@16819
  1041
avigad@16819
  1042
lemma natceiling_mono: "x <= y ==> natceiling x <= natceiling y"
avigad@16819
  1043
  apply (case_tac "0 <= x")
avigad@16819
  1044
  apply (subst natceiling_def)+
avigad@16819
  1045
  apply (subst nat_le_eq_zle)
avigad@16819
  1046
  apply (rule disjI2)
avigad@16819
  1047
  apply (subgoal_tac "real (0::int) <= real(ceiling y)")
avigad@16819
  1048
  apply simp
avigad@16819
  1049
  apply (rule order_trans)
avigad@16819
  1050
  apply simp
avigad@16819
  1051
  apply (erule order_trans)
avigad@16819
  1052
  apply simp
huffman@30097
  1053
  apply (erule ceiling_mono)
avigad@16819
  1054
  apply (subst natceiling_neg)
avigad@16819
  1055
  apply simp_all
avigad@16819
  1056
done
avigad@16819
  1057
avigad@16819
  1058
lemma natceiling_le: "x <= real a ==> natceiling x <= a"
avigad@16819
  1059
  apply (unfold natceiling_def)
avigad@16819
  1060
  apply (case_tac "x < 0")
avigad@16819
  1061
  apply simp
hoelzl@35578
  1062
  apply (subst (2) nat_int [THEN sym])
avigad@16819
  1063
  apply (subst nat_le_eq_zle)
avigad@16819
  1064
  apply simp
avigad@16819
  1065
  apply (rule ceiling_le)
avigad@16819
  1066
  apply simp
avigad@16819
  1067
done
avigad@16819
  1068
avigad@16819
  1069
lemma natceiling_le_eq: "0 <= x ==> (natceiling x <= a) = (x <= real a)"
avigad@16819
  1070
  apply (rule iffI)
avigad@16819
  1071
  apply (rule order_trans)
avigad@16819
  1072
  apply (rule real_natceiling_ge)
avigad@16819
  1073
  apply (subst real_of_nat_le_iff)
avigad@16819
  1074
  apply assumption
avigad@16819
  1075
  apply (erule natceiling_le)
avigad@16819
  1076
done
avigad@16819
  1077
wenzelm@16893
  1078
lemma natceiling_le_eq_number_of [simp]:
avigad@16820
  1079
    "~ neg((number_of n)::int) ==> 0 <= x ==>
avigad@16820
  1080
      (natceiling x <= number_of n) = (x <= number_of n)"
avigad@16819
  1081
  apply (subst natceiling_le_eq, assumption)
avigad@16819
  1082
  apply simp
avigad@16819
  1083
done
avigad@16819
  1084
avigad@16820
  1085
lemma natceiling_le_eq_one: "(natceiling x <= 1) = (x <= 1)"
avigad@16819
  1086
  apply (case_tac "0 <= x")
avigad@16819
  1087
  apply (subst natceiling_le_eq)
avigad@16819
  1088
  apply assumption
avigad@16819
  1089
  apply simp
avigad@16819
  1090
  apply (subst natceiling_neg)
avigad@16819
  1091
  apply simp
avigad@16819
  1092
  apply simp
avigad@16819
  1093
done
avigad@16819
  1094
avigad@16819
  1095
lemma natceiling_eq: "real n < x ==> x <= real n + 1 ==> natceiling x = n + 1"
avigad@16819
  1096
  apply (unfold natceiling_def)
wenzelm@19850
  1097
  apply (simplesubst nat_int [THEN sym]) back back
avigad@16819
  1098
  apply (subgoal_tac "nat(int n) + 1 = nat(int n + 1)")
avigad@16819
  1099
  apply (erule ssubst)
avigad@16819
  1100
  apply (subst eq_nat_nat_iff)
avigad@16819
  1101
  apply (subgoal_tac "ceiling 0 <= ceiling x")
avigad@16819
  1102
  apply simp
huffman@30097
  1103
  apply (rule ceiling_mono)
avigad@16819
  1104
  apply force
avigad@16819
  1105
  apply force
avigad@16819
  1106
  apply (rule ceiling_eq2)
avigad@16819
  1107
  apply (simp, simp)
avigad@16819
  1108
  apply (subst nat_add_distrib)
avigad@16819
  1109
  apply auto
avigad@16819
  1110
done
avigad@16819
  1111
wenzelm@16893
  1112
lemma natceiling_add [simp]: "0 <= x ==>
avigad@16819
  1113
    natceiling (x + real a) = natceiling x + a"
avigad@16819
  1114
  apply (unfold natceiling_def)
huffman@24355
  1115
  apply (subgoal_tac "real a = real (int a)")
avigad@16819
  1116
  apply (erule ssubst)
huffman@23309
  1117
  apply (simp del: real_of_int_of_nat_eq)
avigad@16819
  1118
  apply (subst nat_add_distrib)
avigad@16819
  1119
  apply (subgoal_tac "0 = ceiling 0")
avigad@16819
  1120
  apply (erule ssubst)
huffman@30097
  1121
  apply (erule ceiling_mono)
avigad@16819
  1122
  apply simp_all
avigad@16819
  1123
done
avigad@16819
  1124
wenzelm@16893
  1125
lemma natceiling_add_number_of [simp]:
wenzelm@16893
  1126
    "~ neg ((number_of n)::int) ==> 0 <= x ==>
avigad@16820
  1127
      natceiling (x + number_of n) = natceiling x + number_of n"
avigad@16819
  1128
  apply (subst natceiling_add [THEN sym])
avigad@16819
  1129
  apply simp_all
avigad@16819
  1130
done
avigad@16819
  1131
avigad@16819
  1132
lemma natceiling_add_one: "0 <= x ==> natceiling(x + 1) = natceiling x + 1"
avigad@16819
  1133
  apply (subst natceiling_add [THEN sym])
avigad@16819
  1134
  apply assumption
avigad@16819
  1135
  apply simp
avigad@16819
  1136
done
avigad@16819
  1137
wenzelm@16893
  1138
lemma natceiling_subtract [simp]: "real a <= x ==>
avigad@16819
  1139
    natceiling(x - real a) = natceiling x - a"
avigad@16819
  1140
  apply (unfold natceiling_def)
huffman@24355
  1141
  apply (subgoal_tac "real a = real (int a)")
avigad@16819
  1142
  apply (erule ssubst)
huffman@23309
  1143
  apply (simp del: real_of_int_of_nat_eq)
avigad@16819
  1144
  apply simp
avigad@16819
  1145
done
avigad@16819
  1146
avigad@16819
  1147
paulson@14365
  1148
end