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