| author | berghofe | 
| Sat, 26 Nov 2005 18:41:41 +0100 | |
| changeset 18261 | 1318955d57ac | 
| parent 16893 | 0cc94e6f6ae5 | 
| child 19765 | dfe940911617 | 
| permissions | -rw-r--r-- | 
| 16893 | 1 | (* Title : HOL/Real/RComplete.thy | 
| 7219 | 2 | ID : $Id$ | 
| 16893 | 3 | Author : Jacques D. Fleuriot, University of Edinburgh | 
| 4 | Author : Larry Paulson, University of Cambridge | |
| 5 | Author : Jeremy Avigad, Carnegie Mellon University | |
| 6 | Author : Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen | |
| 7 | *) | |
| 5078 | 8 | |
| 16893 | 9 | header {* Completeness of the Reals; Floor and Ceiling Functions *}
 | 
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 10 | |
| 15131 | 11 | theory RComplete | 
| 15140 | 12 | imports Lubs RealDef | 
| 15131 | 13 | begin | 
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 14 | |
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 15 | lemma real_sum_of_halves: "x/2 + x/2 = (x::real)" | 
| 16893 | 16 | by simp | 
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 17 | |
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 18 | |
| 16893 | 19 | subsection {* Completeness of Positive Reals *}
 | 
| 20 | ||
| 21 | text {*
 | |
| 22 | Supremum property for the set of positive reals | |
| 23 | ||
| 24 |   Let @{text "P"} be a non-empty set of positive reals, with an upper
 | |
| 25 |   bound @{text "y"}.  Then @{text "P"} has a least upper bound
 | |
| 26 |   (written @{text "S"}).
 | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 27 | |
| 16893 | 28 |   FIXME: Can the premise be weakened to @{text "\<forall>x \<in> P. x\<le> y"}?
 | 
| 29 | *} | |
| 30 | ||
| 31 | lemma posreal_complete: | |
| 32 | assumes positive_P: "\<forall>x \<in> P. (0::real) < x" | |
| 33 | and not_empty_P: "\<exists>x. x \<in> P" | |
| 34 | and upper_bound_Ex: "\<exists>y. \<forall>x \<in> P. x<y" | |
| 35 | shows "\<exists>S. \<forall>y. (\<exists>x \<in> P. y < x) = (y < S)" | |
| 36 | proof (rule exI, rule allI) | |
| 37 | fix y | |
| 38 |   let ?pP = "{w. real_of_preal w \<in> P}"
 | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 39 | |
| 16893 | 40 | show "(\<exists>x\<in>P. y < x) = (y < real_of_preal (psup ?pP))" | 
| 41 | proof (cases "0 < y") | |
| 42 | assume neg_y: "\<not> 0 < y" | |
| 43 | show ?thesis | |
| 44 | proof | |
| 45 | assume "\<exists>x\<in>P. y < x" | |
| 46 | have "\<forall>x. y < real_of_preal x" | |
| 47 | using neg_y by (rule real_less_all_real2) | |
| 48 | thus "y < real_of_preal (psup ?pP)" .. | |
| 49 | next | |
| 50 | assume "y < real_of_preal (psup ?pP)" | |
| 51 | obtain "x" where x_in_P: "x \<in> P" using not_empty_P .. | |
| 52 | hence "0 < x" using positive_P by simp | |
| 53 | hence "y < x" using neg_y by simp | |
| 54 | thus "\<exists>x \<in> P. y < x" using x_in_P .. | |
| 55 | qed | |
| 56 | next | |
| 57 | assume pos_y: "0 < y" | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 58 | |
| 16893 | 59 | then obtain py where y_is_py: "y = real_of_preal py" | 
| 60 | by (auto simp add: real_gt_zero_preal_Ex) | |
| 61 | ||
| 62 | obtain a where a_in_P: "a \<in> P" using not_empty_P .. | |
| 63 | have a_pos: "0 < a" using positive_P .. | |
| 64 | then obtain pa where "a = real_of_preal pa" | |
| 65 | by (auto simp add: real_gt_zero_preal_Ex) | |
| 66 | hence "pa \<in> ?pP" using a_in_P by auto | |
| 67 |     hence pP_not_empty: "?pP \<noteq> {}" by auto
 | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 68 | |
| 16893 | 69 | obtain sup where sup: "\<forall>x \<in> P. x < sup" | 
| 70 | using upper_bound_Ex .. | |
| 71 | hence "a < sup" .. | |
| 72 | hence "0 < sup" using a_pos by arith | |
| 73 | then obtain possup where "sup = real_of_preal possup" | |
| 74 | by (auto simp add: real_gt_zero_preal_Ex) | |
| 75 | hence "\<forall>X \<in> ?pP. X \<le> possup" | |
| 76 | using sup by (auto simp add: real_of_preal_lessI) | |
| 77 | with pP_not_empty have psup: "\<And>Z. (\<exists>X \<in> ?pP. Z < X) = (Z < psup ?pP)" | |
| 78 | by (rule preal_complete) | |
| 79 | ||
| 80 | show ?thesis | |
| 81 | proof | |
| 82 | assume "\<exists>x \<in> P. y < x" | |
| 83 | then obtain x where x_in_P: "x \<in> P" and y_less_x: "y < x" .. | |
| 84 | hence "0 < x" using pos_y by arith | |
| 85 | then obtain px where x_is_px: "x = real_of_preal px" | |
| 86 | by (auto simp add: real_gt_zero_preal_Ex) | |
| 87 | ||
| 88 | have py_less_X: "\<exists>X \<in> ?pP. py < X" | |
| 89 | proof | |
| 90 | show "py < px" using y_is_py and x_is_px and y_less_x | |
| 91 | by (simp add: real_of_preal_lessI) | |
| 92 | show "px \<in> ?pP" using x_in_P and x_is_px by simp | |
| 93 | qed | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 94 | |
| 16893 | 95 | have "(\<exists>X \<in> ?pP. py < X) ==> (py < psup ?pP)" | 
| 96 | using psup by simp | |
| 97 | hence "py < psup ?pP" using py_less_X by simp | |
| 98 |       thus "y < real_of_preal (psup {w. real_of_preal w \<in> P})"
 | |
| 99 | using y_is_py and pos_y by (simp add: real_of_preal_lessI) | |
| 100 | next | |
| 101 | assume y_less_psup: "y < real_of_preal (psup ?pP)" | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 102 | |
| 16893 | 103 | hence "py < psup ?pP" using y_is_py | 
| 104 | by (simp add: real_of_preal_lessI) | |
| 105 | then obtain "X" where py_less_X: "py < X" and X_in_pP: "X \<in> ?pP" | |
| 106 | using psup by auto | |
| 107 | then obtain x where x_is_X: "x = real_of_preal X" | |
| 108 | by (simp add: real_gt_zero_preal_Ex) | |
| 109 | hence "y < x" using py_less_X and y_is_py | |
| 110 | by (simp add: real_of_preal_lessI) | |
| 111 | ||
| 112 | moreover have "x \<in> P" using x_is_X and X_in_pP by simp | |
| 113 | ||
| 114 | ultimately show "\<exists> x \<in> P. y < x" .. | |
| 115 | qed | |
| 116 | qed | |
| 117 | qed | |
| 118 | ||
| 119 | text {*
 | |
| 120 |   \medskip Completeness properties using @{text "isUb"}, @{text "isLub"} etc.
 | |
| 121 | *} | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 122 | |
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 123 | lemma real_isLub_unique: "[| isLub R S x; isLub R S y |] ==> x = (y::real)" | 
| 16893 | 124 | apply (frule isLub_isUb) | 
| 125 | apply (frule_tac x = y in isLub_isUb) | |
| 126 | apply (blast intro!: order_antisym dest!: isLub_le_isUb) | |
| 127 | done | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 128 | |
| 5078 | 129 | |
| 16893 | 130 | text {*
 | 
| 131 | \medskip Completeness theorem for the positive reals (again). | |
| 132 | *} | |
| 133 | ||
| 134 | lemma posreals_complete: | |
| 135 | assumes positive_S: "\<forall>x \<in> S. 0 < x" | |
| 136 | and not_empty_S: "\<exists>x. x \<in> S" | |
| 137 | and upper_bound_Ex: "\<exists>u. isUb (UNIV::real set) S u" | |
| 138 | shows "\<exists>t. isLub (UNIV::real set) S t" | |
| 139 | proof | |
| 140 |   let ?pS = "{w. real_of_preal w \<in> S}"
 | |
| 141 | ||
| 142 | obtain u where "isUb UNIV S u" using upper_bound_Ex .. | |
| 143 | hence sup: "\<forall>x \<in> S. x \<le> u" by (simp add: isUb_def setle_def) | |
| 144 | ||
| 145 | obtain x where x_in_S: "x \<in> S" using not_empty_S .. | |
| 146 | hence x_gt_zero: "0 < x" using positive_S by simp | |
| 147 | have "x \<le> u" using sup and x_in_S .. | |
| 148 | hence "0 < u" using x_gt_zero by arith | |
| 149 | ||
| 150 | then obtain pu where u_is_pu: "u = real_of_preal pu" | |
| 151 | by (auto simp add: real_gt_zero_preal_Ex) | |
| 152 | ||
| 153 | have pS_less_pu: "\<forall>pa \<in> ?pS. pa \<le> pu" | |
| 154 | proof | |
| 155 | fix pa | |
| 156 | assume "pa \<in> ?pS" | |
| 157 | then obtain a where "a \<in> S" and "a = real_of_preal pa" | |
| 158 | by simp | |
| 159 | moreover hence "a \<le> u" using sup by simp | |
| 160 | ultimately show "pa \<le> pu" | |
| 161 | using sup and u_is_pu by (simp add: real_of_preal_le_iff) | |
| 162 | qed | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 163 | |
| 16893 | 164 | have "\<forall>y \<in> S. y \<le> real_of_preal (psup ?pS)" | 
| 165 | proof | |
| 166 | fix y | |
| 167 | assume y_in_S: "y \<in> S" | |
| 168 | hence "0 < y" using positive_S by simp | |
| 169 | then obtain py where y_is_py: "y = real_of_preal py" | |
| 170 | by (auto simp add: real_gt_zero_preal_Ex) | |
| 171 | hence py_in_pS: "py \<in> ?pS" using y_in_S by simp | |
| 172 | with pS_less_pu have "py \<le> psup ?pS" | |
| 173 | by (rule preal_psup_le) | |
| 174 | thus "y \<le> real_of_preal (psup ?pS)" | |
| 175 | using y_is_py by (simp add: real_of_preal_le_iff) | |
| 176 | qed | |
| 177 | ||
| 178 |   moreover {
 | |
| 179 | fix x | |
| 180 | assume x_ub_S: "\<forall>y\<in>S. y \<le> x" | |
| 181 | have "real_of_preal (psup ?pS) \<le> x" | |
| 182 | proof - | |
| 183 | obtain "s" where s_in_S: "s \<in> S" using not_empty_S .. | |
| 184 | hence s_pos: "0 < s" using positive_S by simp | |
| 185 | ||
| 186 | hence "\<exists> ps. s = real_of_preal ps" by (simp add: real_gt_zero_preal_Ex) | |
| 187 | then obtain "ps" where s_is_ps: "s = real_of_preal ps" .. | |
| 188 |       hence ps_in_pS: "ps \<in> {w. real_of_preal w \<in> S}" using s_in_S by simp
 | |
| 189 | ||
| 190 | from x_ub_S have "s \<le> x" using s_in_S .. | |
| 191 | hence "0 < x" using s_pos by simp | |
| 192 | hence "\<exists> px. x = real_of_preal px" by (simp add: real_gt_zero_preal_Ex) | |
| 193 | then obtain "px" where x_is_px: "x = real_of_preal px" .. | |
| 194 | ||
| 195 | have "\<forall>pe \<in> ?pS. pe \<le> px" | |
| 196 | proof | |
| 197 | fix pe | |
| 198 | assume "pe \<in> ?pS" | |
| 199 | hence "real_of_preal pe \<in> S" by simp | |
| 200 | hence "real_of_preal pe \<le> x" using x_ub_S by simp | |
| 201 | thus "pe \<le> px" using x_is_px by (simp add: real_of_preal_le_iff) | |
| 202 | qed | |
| 203 | ||
| 204 |       moreover have "?pS \<noteq> {}" using ps_in_pS by auto
 | |
| 205 | ultimately have "(psup ?pS) \<le> px" by (simp add: psup_le_ub) | |
| 206 | thus "real_of_preal (psup ?pS) \<le> x" using x_is_px by (simp add: real_of_preal_le_iff) | |
| 207 | qed | |
| 208 | } | |
| 209 | ultimately show "isLub UNIV S (real_of_preal (psup ?pS))" | |
| 210 | by (simp add: isLub_def leastP_def isUb_def setle_def setge_def) | |
| 211 | qed | |
| 212 | ||
| 213 | text {*
 | |
| 214 | \medskip reals Completeness (again!) | |
| 215 | *} | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 216 | |
| 16893 | 217 | lemma reals_complete: | 
| 218 | assumes notempty_S: "\<exists>X. X \<in> S" | |
| 219 | and exists_Ub: "\<exists>Y. isUb (UNIV::real set) S Y" | |
| 220 | shows "\<exists>t. isLub (UNIV :: real set) S t" | |
| 221 | proof - | |
| 222 | obtain X where X_in_S: "X \<in> S" using notempty_S .. | |
| 223 | obtain Y where Y_isUb: "isUb (UNIV::real set) S Y" | |
| 224 | using exists_Ub .. | |
| 225 |   let ?SHIFT = "{z. \<exists>x \<in>S. z = x + (-X) + 1} \<inter> {x. 0 < x}"
 | |
| 226 | ||
| 227 |   {
 | |
| 228 | fix x | |
| 229 | assume "isUb (UNIV::real set) S x" | |
| 230 | hence S_le_x: "\<forall> y \<in> S. y <= x" | |
| 231 | by (simp add: isUb_def setle_def) | |
| 232 |     {
 | |
| 233 | fix s | |
| 234 |       assume "s \<in> {z. \<exists>x\<in>S. z = x + - X + 1}"
 | |
| 235 | hence "\<exists> x \<in> S. s = x + -X + 1" .. | |
| 236 | then obtain x1 where "x1 \<in> S" and "s = x1 + (-X) + 1" .. | |
| 237 | moreover hence "x1 \<le> x" using S_le_x by simp | |
| 238 | ultimately have "s \<le> x + - X + 1" by arith | |
| 239 | } | |
| 240 | then have "isUb (UNIV::real set) ?SHIFT (x + (-X) + 1)" | |
| 241 | by (auto simp add: isUb_def setle_def) | |
| 242 | } note S_Ub_is_SHIFT_Ub = this | |
| 243 | ||
| 244 | hence "isUb UNIV ?SHIFT (Y + (-X) + 1)" using Y_isUb by simp | |
| 245 | hence "\<exists>Z. isUb UNIV ?SHIFT Z" .. | |
| 246 | moreover have "\<forall>y \<in> ?SHIFT. 0 < y" by auto | |
| 247 | moreover have shifted_not_empty: "\<exists>u. u \<in> ?SHIFT" | |
| 248 | using X_in_S and Y_isUb by auto | |
| 249 | ultimately obtain t where t_is_Lub: "isLub UNIV ?SHIFT t" | |
| 250 | using posreals_complete [of ?SHIFT] by blast | |
| 251 | ||
| 252 | show ?thesis | |
| 253 | proof | |
| 254 | show "isLub UNIV S (t + X + (-1))" | |
| 255 | proof (rule isLubI2) | |
| 256 |       {
 | |
| 257 | fix x | |
| 258 | assume "isUb (UNIV::real set) S x" | |
| 259 | hence "isUb (UNIV::real set) (?SHIFT) (x + (-X) + 1)" | |
| 260 | using S_Ub_is_SHIFT_Ub by simp | |
| 261 | hence "t \<le> (x + (-X) + 1)" | |
| 262 | using t_is_Lub by (simp add: isLub_le_isUb) | |
| 263 | hence "t + X + -1 \<le> x" by arith | |
| 264 | } | |
| 265 | then show "(t + X + -1) <=* Collect (isUb UNIV S)" | |
| 266 | by (simp add: setgeI) | |
| 267 | next | |
| 268 | show "isUb UNIV S (t + X + -1)" | |
| 269 | proof - | |
| 270 |         {
 | |
| 271 | fix y | |
| 272 | assume y_in_S: "y \<in> S" | |
| 273 | have "y \<le> t + X + -1" | |
| 274 | proof - | |
| 275 | obtain "u" where u_in_shift: "u \<in> ?SHIFT" using shifted_not_empty .. | |
| 276 | hence "\<exists> x \<in> S. u = x + - X + 1" by simp | |
| 277 | then obtain "x" where x_and_u: "u = x + - X + 1" .. | |
| 278 | have u_le_t: "u \<le> t" using u_in_shift and t_is_Lub by (simp add: isLubD2) | |
| 279 | ||
| 280 | show ?thesis | |
| 281 | proof cases | |
| 282 | assume "y \<le> x" | |
| 283 | moreover have "x = u + X + - 1" using x_and_u by arith | |
| 284 | moreover have "u + X + - 1 \<le> t + X + -1" using u_le_t by arith | |
| 285 | ultimately show "y \<le> t + X + -1" by arith | |
| 286 | next | |
| 287 | assume "~(y \<le> x)" | |
| 288 | hence x_less_y: "x < y" by arith | |
| 289 | ||
| 290 | have "x + (-X) + 1 \<in> ?SHIFT" using x_and_u and u_in_shift by simp | |
| 291 | hence "0 < x + (-X) + 1" by simp | |
| 292 | hence "0 < y + (-X) + 1" using x_less_y by arith | |
| 293 | hence "y + (-X) + 1 \<in> ?SHIFT" using y_in_S by simp | |
| 294 | hence "y + (-X) + 1 \<le> t" using t_is_Lub by (simp add: isLubD2) | |
| 295 | thus ?thesis by simp | |
| 296 | qed | |
| 297 | qed | |
| 298 | } | |
| 299 | then show ?thesis by (simp add: isUb_def setle_def) | |
| 300 | qed | |
| 301 | qed | |
| 302 | qed | |
| 303 | qed | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 304 | |
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 305 | |
| 16893 | 306 | subsection {* The Archimedean Property of the Reals *}
 | 
| 307 | ||
| 308 | theorem reals_Archimedean: | |
| 309 | assumes x_pos: "0 < x" | |
| 310 | shows "\<exists>n. inverse (real (Suc n)) < x" | |
| 311 | proof (rule ccontr) | |
| 312 | assume contr: "\<not> ?thesis" | |
| 313 | have "\<forall>n. x * real (Suc n) <= 1" | |
| 314 | proof | |
| 315 | fix n | |
| 316 | from contr have "x \<le> inverse (real (Suc n))" | |
| 317 | by (simp add: linorder_not_less) | |
| 318 | hence "x \<le> (1 / (real (Suc n)))" | |
| 319 | by (simp add: inverse_eq_divide) | |
| 320 | moreover have "0 \<le> real (Suc n)" | |
| 321 | by (rule real_of_nat_ge_zero) | |
| 322 | ultimately have "x * real (Suc n) \<le> (1 / real (Suc n)) * real (Suc n)" | |
| 323 | by (rule mult_right_mono) | |
| 324 | thus "x * real (Suc n) \<le> 1" by simp | |
| 325 | qed | |
| 326 |   hence "{z. \<exists>n. z = x * (real (Suc n))} *<= 1"
 | |
| 327 | by (simp add: setle_def, safe, rule spec) | |
| 328 |   hence "isUb (UNIV::real set) {z. \<exists>n. z = x * (real (Suc n))} 1"
 | |
| 329 | by (simp add: isUbI) | |
| 330 |   hence "\<exists>Y. isUb (UNIV::real set) {z. \<exists>n. z = x* (real (Suc n))} Y" ..
 | |
| 331 |   moreover have "\<exists>X. X \<in> {z. \<exists>n. z = x* (real (Suc n))}" by auto
 | |
| 332 |   ultimately have "\<exists>t. isLub UNIV {z. \<exists>n. z = x * real (Suc n)} t"
 | |
| 333 | by (simp add: reals_complete) | |
| 334 | then obtain "t" where | |
| 335 |     t_is_Lub: "isLub UNIV {z. \<exists>n. z = x * real (Suc n)} t" ..
 | |
| 336 | ||
| 337 | have "\<forall>n::nat. x * real n \<le> t + - x" | |
| 338 | proof | |
| 339 | fix n | |
| 340 | from t_is_Lub have "x * real (Suc n) \<le> t" | |
| 341 | by (simp add: isLubD2) | |
| 342 | hence "x * (real n) + x \<le> t" | |
| 343 | by (simp add: right_distrib real_of_nat_Suc) | |
| 344 | thus "x * (real n) \<le> t + - x" by arith | |
| 345 | qed | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 346 | |
| 16893 | 347 | hence "\<forall>m. x * real (Suc m) \<le> t + - x" by simp | 
| 348 |   hence "{z. \<exists>n. z = x * (real (Suc n))}  *<= (t + - x)"
 | |
| 349 | by (auto simp add: setle_def) | |
| 350 |   hence "isUb (UNIV::real set) {z. \<exists>n. z = x * (real (Suc n))} (t + (-x))"
 | |
| 351 | by (simp add: isUbI) | |
| 352 | hence "t \<le> t + - x" | |
| 353 | using t_is_Lub by (simp add: isLub_le_isUb) | |
| 354 | thus False using x_pos by arith | |
| 355 | qed | |
| 356 | ||
| 357 | text {*
 | |
| 358 |   There must be other proofs, e.g. @{text "Suc"} of the largest
 | |
| 359 |   integer in the cut representing @{text "x"}.
 | |
| 360 | *} | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 361 | |
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 362 | lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)" | 
| 16893 | 363 | proof cases | 
| 364 | assume "x \<le> 0" | |
| 365 | hence "x < real (1::nat)" by simp | |
| 366 | thus ?thesis .. | |
| 367 | next | |
| 368 | assume "\<not> x \<le> 0" | |
| 369 | hence x_greater_zero: "0 < x" by simp | |
| 370 | hence "0 < inverse x" by simp | |
| 371 | then obtain n where "inverse (real (Suc n)) < inverse x" | |
| 372 | using reals_Archimedean by blast | |
| 373 | hence "inverse (real (Suc n)) * x < inverse x * x" | |
| 374 | using x_greater_zero by (rule mult_strict_right_mono) | |
| 375 | hence "inverse (real (Suc n)) * x < 1" | |
| 376 | using x_greater_zero by (simp add: real_mult_inverse_left mult_commute) | |
| 377 | hence "real (Suc n) * (inverse (real (Suc n)) * x) < real (Suc n) * 1" | |
| 378 | by (rule mult_strict_left_mono) simp | |
| 379 | hence "x < real (Suc n)" | |
| 380 | by (simp add: mult_commute ring_eq_simps real_mult_inverse_left) | |
| 381 | thus "\<exists>(n::nat). x < real n" .. | |
| 382 | qed | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 383 | |
| 16893 | 384 | lemma reals_Archimedean3: | 
| 385 | assumes x_greater_zero: "0 < x" | |
| 386 | shows "\<forall>(y::real). \<exists>(n::nat). y < real n * x" | |
| 387 | proof | |
| 388 | fix y | |
| 389 | have x_not_zero: "x \<noteq> 0" using x_greater_zero by simp | |
| 390 | obtain n where "y * inverse x < real (n::nat)" | |
| 391 | using reals_Archimedean2 .. | |
| 392 | hence "y * inverse x * x < real n * x" | |
| 393 | using x_greater_zero by (simp add: mult_strict_right_mono) | |
| 394 | hence "x * inverse x * y < x * real n" | |
| 395 | by (simp add: mult_commute ring_eq_simps) | |
| 396 | hence "y < real (n::nat) * x" | |
| 397 | using x_not_zero by (simp add: real_mult_inverse_left ring_eq_simps) | |
| 398 | thus "\<exists>(n::nat). y < real n * x" .. | |
| 399 | qed | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 400 | |
| 16819 | 401 | lemma reals_Archimedean6: | 
| 402 | "0 \<le> r ==> \<exists>(n::nat). real (n - 1) \<le> r & r < real (n)" | |
| 403 | apply (insert reals_Archimedean2 [of r], safe) | |
| 404 | apply (frule_tac P = "%k. r < real k" and k = n and m = "%x. x" | |
| 405 | in ex_has_least_nat, auto) | |
| 406 | apply (rule_tac x = x in exI) | |
| 407 | apply (case_tac x, simp) | |
| 408 | apply (rename_tac x') | |
| 409 | apply (drule_tac x = x' in spec, simp) | |
| 410 | done | |
| 411 | ||
| 412 | lemma reals_Archimedean6a: "0 \<le> r ==> \<exists>n. real (n) \<le> r & r < real (Suc n)" | |
| 16893 | 413 | by (drule reals_Archimedean6) auto | 
| 16819 | 414 | |
| 415 | lemma reals_Archimedean_6b_int: | |
| 416 | "0 \<le> r ==> \<exists>n::int. real n \<le> r & r < real (n+1)" | |
| 417 | apply (drule reals_Archimedean6a, auto) | |
| 418 | apply (rule_tac x = "int n" in exI) | |
| 419 | apply (simp add: real_of_int_real_of_nat real_of_nat_Suc) | |
| 420 | done | |
| 421 | ||
| 422 | lemma reals_Archimedean_6c_int: | |
| 423 | "r < 0 ==> \<exists>n::int. real n \<le> r & r < real (n+1)" | |
| 424 | apply (rule reals_Archimedean_6b_int [of "-r", THEN exE], simp, auto) | |
| 425 | apply (rename_tac n) | |
| 426 | apply (drule real_le_imp_less_or_eq, auto) | |
| 427 | apply (rule_tac x = "- n - 1" in exI) | |
| 428 | apply (rule_tac [2] x = "- n" in exI, auto) | |
| 429 | done | |
| 430 | ||
| 431 | ||
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 432 | ML | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 433 | {*
 | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 434 | val real_sum_of_halves = thm "real_sum_of_halves"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 435 | val posreal_complete = thm "posreal_complete"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 436 | val real_isLub_unique = thm "real_isLub_unique"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 437 | val posreals_complete = thm "posreals_complete"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 438 | val reals_complete = thm "reals_complete"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 439 | val reals_Archimedean = thm "reals_Archimedean"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 440 | val reals_Archimedean2 = thm "reals_Archimedean2"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 441 | val reals_Archimedean3 = thm "reals_Archimedean3"; | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 442 | *} | 
| 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 443 | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 444 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 445 | subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
 | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 446 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 447 | constdefs | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 448 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 449 | floor :: "real => int" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 450 | "floor r == (LEAST n::int. r < real (n+1))" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 451 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 452 | ceiling :: "real => int" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 453 | "ceiling r == - floor (- r)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 454 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 455 | syntax (xsymbols) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 456 |   floor :: "real => int"     ("\<lfloor>_\<rfloor>")
 | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 457 |   ceiling :: "real => int"   ("\<lceil>_\<rceil>")
 | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 458 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 459 | syntax (HTML output) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 460 |   floor :: "real => int"     ("\<lfloor>_\<rfloor>")
 | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 461 |   ceiling :: "real => int"   ("\<lceil>_\<rceil>")
 | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 462 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 463 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 464 | lemma number_of_less_real_of_int_iff [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 465 | "((number_of n) < real (m::int)) = (number_of n < m)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 466 | apply auto | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 467 | apply (rule real_of_int_less_iff [THEN iffD1]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 468 | apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 469 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 470 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 471 | lemma number_of_less_real_of_int_iff2 [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 472 | "(real (m::int) < (number_of n)) = (m < number_of n)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 473 | apply auto | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 474 | apply (rule real_of_int_less_iff [THEN iffD1]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 475 | apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 476 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 477 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 478 | lemma number_of_le_real_of_int_iff [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 479 | "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 480 | by (simp add: linorder_not_less [symmetric]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 481 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 482 | lemma number_of_le_real_of_int_iff2 [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 483 | "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 484 | by (simp add: linorder_not_less [symmetric]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 485 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 486 | lemma floor_zero [simp]: "floor 0 = 0" | 
| 16819 | 487 | apply (simp add: floor_def del: real_of_int_add) | 
| 488 | apply (rule Least_equality) | |
| 489 | apply simp_all | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 490 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 491 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 492 | lemma floor_real_of_nat_zero [simp]: "floor (real (0::nat)) = 0" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 493 | by auto | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 494 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 495 | lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 496 | apply (simp only: floor_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 497 | apply (rule Least_equality) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 498 | apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 499 | apply (drule_tac [2] real_of_int_less_iff [THEN iffD1]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 500 | apply (simp_all add: real_of_int_real_of_nat) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 501 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 502 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 503 | lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 504 | apply (simp only: floor_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 505 | apply (rule Least_equality) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 506 | apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst]) | 
| 16819 | 507 | apply (drule_tac [2] real_of_int_minus [THEN sym, THEN subst]) | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 508 | apply (drule_tac [2] real_of_int_less_iff [THEN iffD1]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 509 | apply (simp_all add: real_of_int_real_of_nat) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 510 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 511 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 512 | lemma floor_real_of_int [simp]: "floor (real (n::int)) = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 513 | apply (simp only: floor_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 514 | apply (rule Least_equality) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 515 | apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 516 | apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 517 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 518 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 519 | lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 520 | apply (simp only: floor_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 521 | apply (rule Least_equality) | 
| 16819 | 522 | apply (drule_tac [2] real_of_int_minus [THEN sym, THEN subst]) | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 523 | apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 524 | apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 525 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 526 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 527 | lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 528 | apply (case_tac "r < 0") | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 529 | apply (blast intro: reals_Archimedean_6c_int) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 530 | apply (simp only: linorder_not_less) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 531 | apply (blast intro: reals_Archimedean_6b_int reals_Archimedean_6c_int) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 532 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 533 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 534 | lemma lemma_floor: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 535 | assumes a1: "real m \<le> r" and a2: "r < real n + 1" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 536 | shows "m \<le> (n::int)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 537 | proof - | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 538 | have "real m < real n + 1" by (rule order_le_less_trans) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 539 | also have "... = real(n+1)" by simp | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 540 | finally have "m < n+1" by (simp only: real_of_int_less_iff) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 541 | thus ?thesis by arith | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 542 | qed | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 543 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 544 | lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 545 | apply (simp add: floor_def Least_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 546 | apply (insert real_lb_ub_int [of r], safe) | 
| 16819 | 547 | apply (rule theI2) | 
| 548 | apply auto | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 549 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 550 | |
| 16819 | 551 | lemma floor_mono: "x < y ==> floor x \<le> floor y" | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 552 | apply (simp add: floor_def Least_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 553 | apply (insert real_lb_ub_int [of x]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 554 | apply (insert real_lb_ub_int [of y], safe) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 555 | apply (rule theI2) | 
| 16819 | 556 | apply (rule_tac [3] theI2) | 
| 557 | apply simp | |
| 558 | apply (erule conjI) | |
| 559 | apply (auto simp add: order_eq_iff int_le_real_less) | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 560 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 561 | |
| 16819 | 562 | lemma floor_mono2: "x \<le> y ==> floor x \<le> floor y" | 
| 563 | by (auto dest: real_le_imp_less_or_eq simp add: floor_mono) | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 564 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 565 | lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 566 | by (auto intro: lemma_floor) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 567 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 568 | lemma real_of_int_floor_cancel [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 569 | "(real (floor x) = x) = (\<exists>n::int. x = real n)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 570 | apply (simp add: floor_def Least_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 571 | apply (insert real_lb_ub_int [of x], erule exE) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 572 | apply (rule theI2) | 
| 16893 | 573 | apply (auto intro: lemma_floor) | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 574 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 575 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 576 | lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 577 | apply (simp add: floor_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 578 | apply (rule Least_equality) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 579 | apply (auto intro: lemma_floor) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 580 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 581 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 582 | lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 583 | apply (simp add: floor_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 584 | apply (rule Least_equality) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 585 | apply (auto intro: lemma_floor) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 586 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 587 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 588 | lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 589 | apply (rule inj_int [THEN injD]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 590 | apply (simp add: real_of_nat_Suc) | 
| 15539 | 591 | apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "int n"]) | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 592 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 593 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 594 | lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 595 | apply (drule order_le_imp_less_or_eq) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 596 | apply (auto intro: floor_eq3) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 597 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 598 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 599 | lemma floor_number_of_eq [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 600 | "floor(number_of n :: real) = (number_of n :: int)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 601 | apply (subst real_number_of [symmetric]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 602 | apply (rule floor_real_of_int) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 603 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 604 | |
| 16819 | 605 | lemma floor_one [simp]: "floor 1 = 1" | 
| 606 | apply (rule trans) | |
| 607 | prefer 2 | |
| 608 | apply (rule floor_real_of_int) | |
| 609 | apply simp | |
| 610 | done | |
| 611 | ||
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 612 | lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 613 | apply (simp add: floor_def Least_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 614 | apply (insert real_lb_ub_int [of r], safe) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 615 | apply (rule theI2) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 616 | apply (auto intro: lemma_floor) | 
| 16819 | 617 | done | 
| 618 | ||
| 619 | lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real(floor r)" | |
| 620 | apply (simp add: floor_def Least_def) | |
| 621 | apply (insert real_lb_ub_int [of r], safe) | |
| 622 | apply (rule theI2) | |
| 623 | apply (auto intro: lemma_floor) | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 624 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 625 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 626 | lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 627 | apply (insert real_of_int_floor_ge_diff_one [of r]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 628 | apply (auto simp del: real_of_int_floor_ge_diff_one) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 629 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 630 | |
| 16819 | 631 | lemma real_of_int_floor_add_one_gt [simp]: "r < real(floor r) + 1" | 
| 632 | apply (insert real_of_int_floor_gt_diff_one [of r]) | |
| 633 | apply (auto simp del: real_of_int_floor_gt_diff_one) | |
| 634 | done | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 635 | |
| 16819 | 636 | lemma le_floor: "real a <= x ==> a <= floor x" | 
| 637 | apply (subgoal_tac "a < floor x + 1") | |
| 638 | apply arith | |
| 639 | apply (subst real_of_int_less_iff [THEN sym]) | |
| 640 | apply simp | |
| 16893 | 641 | apply (insert real_of_int_floor_add_one_gt [of x]) | 
| 16819 | 642 | apply arith | 
| 643 | done | |
| 644 | ||
| 645 | lemma real_le_floor: "a <= floor x ==> real a <= x" | |
| 646 | apply (rule order_trans) | |
| 647 | prefer 2 | |
| 648 | apply (rule real_of_int_floor_le) | |
| 649 | apply (subst real_of_int_le_iff) | |
| 650 | apply assumption | |
| 651 | done | |
| 652 | ||
| 653 | lemma le_floor_eq: "(a <= floor x) = (real a <= x)" | |
| 654 | apply (rule iffI) | |
| 655 | apply (erule real_le_floor) | |
| 656 | apply (erule le_floor) | |
| 657 | done | |
| 658 | ||
| 16893 | 659 | lemma le_floor_eq_number_of [simp]: | 
| 16819 | 660 | "(number_of n <= floor x) = (number_of n <= x)" | 
| 661 | by (simp add: le_floor_eq) | |
| 662 | ||
| 663 | lemma le_floor_eq_zero [simp]: "(0 <= floor x) = (0 <= x)" | |
| 664 | by (simp add: le_floor_eq) | |
| 665 | ||
| 666 | lemma le_floor_eq_one [simp]: "(1 <= floor x) = (1 <= x)" | |
| 667 | by (simp add: le_floor_eq) | |
| 668 | ||
| 669 | lemma floor_less_eq: "(floor x < a) = (x < real a)" | |
| 670 | apply (subst linorder_not_le [THEN sym])+ | |
| 671 | apply simp | |
| 672 | apply (rule le_floor_eq) | |
| 673 | done | |
| 674 | ||
| 16893 | 675 | lemma floor_less_eq_number_of [simp]: | 
| 16819 | 676 | "(floor x < number_of n) = (x < number_of n)" | 
| 677 | by (simp add: floor_less_eq) | |
| 678 | ||
| 679 | lemma floor_less_eq_zero [simp]: "(floor x < 0) = (x < 0)" | |
| 680 | by (simp add: floor_less_eq) | |
| 681 | ||
| 682 | lemma floor_less_eq_one [simp]: "(floor x < 1) = (x < 1)" | |
| 683 | by (simp add: floor_less_eq) | |
| 684 | ||
| 685 | lemma less_floor_eq: "(a < floor x) = (real a + 1 <= x)" | |
| 686 | apply (insert le_floor_eq [of "a + 1" x]) | |
| 687 | apply auto | |
| 688 | done | |
| 689 | ||
| 16893 | 690 | lemma less_floor_eq_number_of [simp]: | 
| 16819 | 691 | "(number_of n < floor x) = (number_of n + 1 <= x)" | 
| 692 | by (simp add: less_floor_eq) | |
| 693 | ||
| 694 | lemma less_floor_eq_zero [simp]: "(0 < floor x) = (1 <= x)" | |
| 695 | by (simp add: less_floor_eq) | |
| 696 | ||
| 697 | lemma less_floor_eq_one [simp]: "(1 < floor x) = (2 <= x)" | |
| 698 | by (simp add: less_floor_eq) | |
| 699 | ||
| 700 | lemma floor_le_eq: "(floor x <= a) = (x < real a + 1)" | |
| 701 | apply (insert floor_less_eq [of x "a + 1"]) | |
| 702 | apply auto | |
| 703 | done | |
| 704 | ||
| 16893 | 705 | lemma floor_le_eq_number_of [simp]: | 
| 16819 | 706 | "(floor x <= number_of n) = (x < number_of n + 1)" | 
| 707 | by (simp add: floor_le_eq) | |
| 708 | ||
| 709 | lemma floor_le_eq_zero [simp]: "(floor x <= 0) = (x < 1)" | |
| 710 | by (simp add: floor_le_eq) | |
| 711 | ||
| 712 | lemma floor_le_eq_one [simp]: "(floor x <= 1) = (x < 2)" | |
| 713 | by (simp add: floor_le_eq) | |
| 714 | ||
| 715 | lemma floor_add [simp]: "floor (x + real a) = floor x + a" | |
| 716 | apply (subst order_eq_iff) | |
| 717 | apply (rule conjI) | |
| 718 | prefer 2 | |
| 719 | apply (subgoal_tac "floor x + a < floor (x + real a) + 1") | |
| 720 | apply arith | |
| 721 | apply (subst real_of_int_less_iff [THEN sym]) | |
| 722 | apply simp | |
| 723 | apply (subgoal_tac "x + real a < real(floor(x + real a)) + 1") | |
| 724 | apply (subgoal_tac "real (floor x) <= x") | |
| 725 | apply arith | |
| 726 | apply (rule real_of_int_floor_le) | |
| 727 | apply (rule real_of_int_floor_add_one_gt) | |
| 728 | apply (subgoal_tac "floor (x + real a) < floor x + a + 1") | |
| 729 | apply arith | |
| 16893 | 730 | apply (subst real_of_int_less_iff [THEN sym]) | 
| 16819 | 731 | apply simp | 
| 16893 | 732 | apply (subgoal_tac "real(floor(x + real a)) <= x + real a") | 
| 16819 | 733 | apply (subgoal_tac "x < real(floor x) + 1") | 
| 734 | apply arith | |
| 735 | apply (rule real_of_int_floor_add_one_gt) | |
| 736 | apply (rule real_of_int_floor_le) | |
| 737 | done | |
| 738 | ||
| 16893 | 739 | lemma floor_add_number_of [simp]: | 
| 16819 | 740 | "floor (x + number_of n) = floor x + number_of n" | 
| 741 | apply (subst floor_add [THEN sym]) | |
| 742 | apply simp | |
| 743 | done | |
| 744 | ||
| 745 | lemma floor_add_one [simp]: "floor (x + 1) = floor x + 1" | |
| 746 | apply (subst floor_add [THEN sym]) | |
| 747 | apply simp | |
| 748 | done | |
| 749 | ||
| 750 | lemma floor_subtract [simp]: "floor (x - real a) = floor x - a" | |
| 751 | apply (subst diff_minus)+ | |
| 752 | apply (subst real_of_int_minus [THEN sym]) | |
| 753 | apply (rule floor_add) | |
| 754 | done | |
| 755 | ||
| 16893 | 756 | lemma floor_subtract_number_of [simp]: "floor (x - number_of n) = | 
| 16819 | 757 | floor x - number_of n" | 
| 758 | apply (subst floor_subtract [THEN sym]) | |
| 759 | apply simp | |
| 760 | done | |
| 761 | ||
| 762 | lemma floor_subtract_one [simp]: "floor (x - 1) = floor x - 1" | |
| 763 | apply (subst floor_subtract [THEN sym]) | |
| 764 | apply simp | |
| 765 | done | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 766 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 767 | lemma ceiling_zero [simp]: "ceiling 0 = 0" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 768 | by (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 769 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 770 | lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 771 | by (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 772 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 773 | lemma ceiling_real_of_nat_zero [simp]: "ceiling (real (0::nat)) = 0" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 774 | by auto | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 775 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 776 | lemma ceiling_floor [simp]: "ceiling (real (floor r)) = floor r" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 777 | by (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 778 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 779 | lemma floor_ceiling [simp]: "floor (real (ceiling r)) = ceiling r" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 780 | by (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 781 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 782 | lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 783 | apply (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 784 | apply (subst le_minus_iff, simp) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 785 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 786 | |
| 16819 | 787 | lemma ceiling_mono: "x < y ==> ceiling x \<le> ceiling y" | 
| 788 | by (simp add: floor_mono ceiling_def) | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 789 | |
| 16819 | 790 | lemma ceiling_mono2: "x \<le> y ==> ceiling x \<le> ceiling y" | 
| 791 | by (simp add: floor_mono2 ceiling_def) | |
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 792 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 793 | lemma real_of_int_ceiling_cancel [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 794 | "(real (ceiling x) = x) = (\<exists>n::int. x = real n)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 795 | apply (auto simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 796 | apply (drule arg_cong [where f = uminus], auto) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 797 | apply (rule_tac x = "-n" in exI, auto) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 798 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 799 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 800 | lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 801 | apply (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 802 | apply (rule minus_equation_iff [THEN iffD1]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 803 | apply (simp add: floor_eq [where n = "-(n+1)"]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 804 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 805 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 806 | lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 807 | by (simp add: ceiling_def floor_eq2 [where n = "-(n+1)"]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 808 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 809 | lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n |] ==> ceiling x = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 810 | by (simp add: ceiling_def floor_eq2 [where n = "-n"]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 811 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 812 | lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 813 | by (simp add: ceiling_def) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 814 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 815 | lemma ceiling_number_of_eq [simp]: | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 816 | "ceiling (number_of n :: real) = (number_of n)" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 817 | apply (subst real_number_of [symmetric]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 818 | apply (rule ceiling_real_of_int) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 819 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 820 | |
| 16819 | 821 | lemma ceiling_one [simp]: "ceiling 1 = 1" | 
| 822 | by (unfold ceiling_def, simp) | |
| 823 | ||
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 824 | lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 825 | apply (rule neg_le_iff_le [THEN iffD1]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 826 | apply (simp add: ceiling_def diff_minus) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 827 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 828 | |
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 829 | lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1" | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 830 | apply (insert real_of_int_ceiling_diff_one_le [of r]) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 831 | apply (simp del: real_of_int_ceiling_diff_one_le) | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 832 | done | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 833 | |
| 16819 | 834 | lemma ceiling_le: "x <= real a ==> ceiling x <= a" | 
| 835 | apply (unfold ceiling_def) | |
| 836 | apply (subgoal_tac "-a <= floor(- x)") | |
| 837 | apply simp | |
| 838 | apply (rule le_floor) | |
| 839 | apply simp | |
| 840 | done | |
| 841 | ||
| 842 | lemma ceiling_le_real: "ceiling x <= a ==> x <= real a" | |
| 843 | apply (unfold ceiling_def) | |
| 844 | apply (subgoal_tac "real(- a) <= - x") | |
| 845 | apply simp | |
| 846 | apply (rule real_le_floor) | |
| 847 | apply simp | |
| 848 | done | |
| 849 | ||
| 850 | lemma ceiling_le_eq: "(ceiling x <= a) = (x <= real a)" | |
| 851 | apply (rule iffI) | |
| 852 | apply (erule ceiling_le_real) | |
| 853 | apply (erule ceiling_le) | |
| 854 | done | |
| 855 | ||
| 16893 | 856 | lemma ceiling_le_eq_number_of [simp]: | 
| 16819 | 857 | "(ceiling x <= number_of n) = (x <= number_of n)" | 
| 858 | by (simp add: ceiling_le_eq) | |
| 859 | ||
| 16893 | 860 | lemma ceiling_le_zero_eq [simp]: "(ceiling x <= 0) = (x <= 0)" | 
| 16819 | 861 | by (simp add: ceiling_le_eq) | 
| 862 | ||
| 16893 | 863 | lemma ceiling_le_eq_one [simp]: "(ceiling x <= 1) = (x <= 1)" | 
| 16819 | 864 | by (simp add: ceiling_le_eq) | 
| 865 | ||
| 866 | lemma less_ceiling_eq: "(a < ceiling x) = (real a < x)" | |
| 867 | apply (subst linorder_not_le [THEN sym])+ | |
| 868 | apply simp | |
| 869 | apply (rule ceiling_le_eq) | |
| 870 | done | |
| 871 | ||
| 16893 | 872 | lemma less_ceiling_eq_number_of [simp]: | 
| 16819 | 873 | "(number_of n < ceiling x) = (number_of n < x)" | 
| 874 | by (simp add: less_ceiling_eq) | |
| 875 | ||
| 876 | lemma less_ceiling_eq_zero [simp]: "(0 < ceiling x) = (0 < x)" | |
| 877 | by (simp add: less_ceiling_eq) | |
| 878 | ||
| 879 | lemma less_ceiling_eq_one [simp]: "(1 < ceiling x) = (1 < x)" | |
| 880 | by (simp add: less_ceiling_eq) | |
| 881 | ||
| 882 | lemma ceiling_less_eq: "(ceiling x < a) = (x <= real a - 1)" | |
| 883 | apply (insert ceiling_le_eq [of x "a - 1"]) | |
| 884 | apply auto | |
| 885 | done | |
| 886 | ||
| 16893 | 887 | lemma ceiling_less_eq_number_of [simp]: | 
| 16819 | 888 | "(ceiling x < number_of n) = (x <= number_of n - 1)" | 
| 889 | by (simp add: ceiling_less_eq) | |
| 890 | ||
| 891 | lemma ceiling_less_eq_zero [simp]: "(ceiling x < 0) = (x <= -1)" | |
| 892 | by (simp add: ceiling_less_eq) | |
| 893 | ||
| 894 | lemma ceiling_less_eq_one [simp]: "(ceiling x < 1) = (x <= 0)" | |
| 895 | by (simp add: ceiling_less_eq) | |
| 896 | ||
| 897 | lemma le_ceiling_eq: "(a <= ceiling x) = (real a - 1 < x)" | |
| 898 | apply (insert less_ceiling_eq [of "a - 1" x]) | |
| 899 | apply auto | |
| 900 | done | |
| 901 | ||
| 16893 | 902 | lemma le_ceiling_eq_number_of [simp]: | 
| 16819 | 903 | "(number_of n <= ceiling x) = (number_of n - 1 < x)" | 
| 904 | by (simp add: le_ceiling_eq) | |
| 905 | ||
| 906 | lemma le_ceiling_eq_zero [simp]: "(0 <= ceiling x) = (-1 < x)" | |
| 907 | by (simp add: le_ceiling_eq) | |
| 908 | ||
| 909 | lemma le_ceiling_eq_one [simp]: "(1 <= ceiling x) = (0 < x)" | |
| 910 | by (simp add: le_ceiling_eq) | |
| 911 | ||
| 912 | lemma ceiling_add [simp]: "ceiling (x + real a) = ceiling x + a" | |
| 913 | apply (unfold ceiling_def, simp) | |
| 914 | apply (subst real_of_int_minus [THEN sym]) | |
| 915 | apply (subst floor_add) | |
| 916 | apply simp | |
| 917 | done | |
| 918 | ||
| 16893 | 919 | lemma ceiling_add_number_of [simp]: "ceiling (x + number_of n) = | 
| 16819 | 920 | ceiling x + number_of n" | 
| 921 | apply (subst ceiling_add [THEN sym]) | |
| 922 | apply simp | |
| 923 | done | |
| 924 | ||
| 925 | lemma ceiling_add_one [simp]: "ceiling (x + 1) = ceiling x + 1" | |
| 926 | apply (subst ceiling_add [THEN sym]) | |
| 927 | apply simp | |
| 928 | done | |
| 929 | ||
| 930 | lemma ceiling_subtract [simp]: "ceiling (x - real a) = ceiling x - a" | |
| 931 | apply (subst diff_minus)+ | |
| 932 | apply (subst real_of_int_minus [THEN sym]) | |
| 933 | apply (rule ceiling_add) | |
| 934 | done | |
| 935 | ||
| 16893 | 936 | lemma ceiling_subtract_number_of [simp]: "ceiling (x - number_of n) = | 
| 16819 | 937 | ceiling x - number_of n" | 
| 938 | apply (subst ceiling_subtract [THEN sym]) | |
| 939 | apply simp | |
| 940 | done | |
| 941 | ||
| 942 | lemma ceiling_subtract_one [simp]: "ceiling (x - 1) = ceiling x - 1" | |
| 943 | apply (subst ceiling_subtract [THEN sym]) | |
| 944 | apply simp | |
| 945 | done | |
| 946 | ||
| 947 | subsection {* Versions for the natural numbers *}
 | |
| 948 | ||
| 949 | constdefs | |
| 950 | natfloor :: "real => nat" | |
| 951 | "natfloor x == nat(floor x)" | |
| 952 | natceiling :: "real => nat" | |
| 953 | "natceiling x == nat(ceiling x)" | |
| 954 | ||
| 955 | lemma natfloor_zero [simp]: "natfloor 0 = 0" | |
| 956 | by (unfold natfloor_def, simp) | |
| 957 | ||
| 958 | lemma natfloor_one [simp]: "natfloor 1 = 1" | |
| 959 | by (unfold natfloor_def, simp) | |
| 960 | ||
| 961 | lemma zero_le_natfloor [simp]: "0 <= natfloor x" | |
| 962 | by (unfold natfloor_def, simp) | |
| 963 | ||
| 964 | lemma natfloor_number_of_eq [simp]: "natfloor (number_of n) = number_of n" | |
| 965 | by (unfold natfloor_def, simp) | |
| 966 | ||
| 967 | lemma natfloor_real_of_nat [simp]: "natfloor(real n) = n" | |
| 968 | by (unfold natfloor_def, simp) | |
| 969 | ||
| 970 | lemma real_natfloor_le: "0 <= x ==> real(natfloor x) <= x" | |
| 971 | by (unfold natfloor_def, simp) | |
| 972 | ||
| 973 | lemma natfloor_neg: "x <= 0 ==> natfloor x = 0" | |
| 974 | apply (unfold natfloor_def) | |
| 975 | apply (subgoal_tac "floor x <= floor 0") | |
| 976 | apply simp | |
| 977 | apply (erule floor_mono2) | |
| 978 | done | |
| 979 | ||
| 980 | lemma natfloor_mono: "x <= y ==> natfloor x <= natfloor y" | |
| 981 | apply (case_tac "0 <= x") | |
| 982 | apply (subst natfloor_def)+ | |
| 983 | apply (subst nat_le_eq_zle) | |
| 984 | apply force | |
| 16893 | 985 | apply (erule floor_mono2) | 
| 16819 | 986 | apply (subst natfloor_neg) | 
| 987 | apply simp | |
| 988 | apply simp | |
| 989 | done | |
| 990 | ||
| 991 | lemma le_natfloor: "real x <= a ==> x <= natfloor a" | |
| 992 | apply (unfold natfloor_def) | |
| 993 | apply (subst nat_int [THEN sym]) | |
| 994 | apply (subst nat_le_eq_zle) | |
| 995 | apply simp | |
| 996 | apply (rule le_floor) | |
| 997 | apply simp | |
| 998 | done | |
| 999 | ||
| 1000 | lemma le_natfloor_eq: "0 <= x ==> (a <= natfloor x) = (real a <= x)" | |
| 1001 | apply (rule iffI) | |
| 1002 | apply (rule order_trans) | |
| 1003 | prefer 2 | |
| 1004 | apply (erule real_natfloor_le) | |
| 1005 | apply (subst real_of_nat_le_iff) | |
| 1006 | apply assumption | |
| 1007 | apply (erule le_natfloor) | |
| 1008 | done | |
| 1009 | ||
| 16893 | 1010 | lemma le_natfloor_eq_number_of [simp]: | 
| 16819 | 1011 | "~ neg((number_of n)::int) ==> 0 <= x ==> | 
| 1012 | (number_of n <= natfloor x) = (number_of n <= x)" | |
| 1013 | apply (subst le_natfloor_eq, assumption) | |
| 1014 | apply simp | |
| 1015 | done | |
| 1016 | ||
| 16820 | 1017 | lemma le_natfloor_eq_one [simp]: "(1 <= natfloor x) = (1 <= x)" | 
| 16819 | 1018 | apply (case_tac "0 <= x") | 
| 1019 | apply (subst le_natfloor_eq, assumption, simp) | |
| 1020 | apply (rule iffI) | |
| 16893 | 1021 | apply (subgoal_tac "natfloor x <= natfloor 0") | 
| 16819 | 1022 | apply simp | 
| 1023 | apply (rule natfloor_mono) | |
| 1024 | apply simp | |
| 1025 | apply simp | |
| 1026 | done | |
| 1027 | ||
| 1028 | lemma natfloor_eq: "real n <= x ==> x < real n + 1 ==> natfloor x = n" | |
| 1029 | apply (unfold natfloor_def) | |
| 1030 | apply (subst nat_int [THEN sym]);back; | |
| 1031 | apply (subst eq_nat_nat_iff) | |
| 1032 | apply simp | |
| 1033 | apply simp | |
| 1034 | apply (rule floor_eq2) | |
| 1035 | apply auto | |
| 1036 | done | |
| 1037 | ||
| 1038 | lemma real_natfloor_add_one_gt: "x < real(natfloor x) + 1" | |
| 1039 | apply (case_tac "0 <= x") | |
| 1040 | apply (unfold natfloor_def) | |
| 1041 | apply simp | |
| 1042 | apply simp_all | |
| 1043 | done | |
| 1044 | ||
| 1045 | lemma real_natfloor_gt_diff_one: "x - 1 < real(natfloor x)" | |
| 1046 | apply (simp add: compare_rls) | |
| 1047 | apply (rule real_natfloor_add_one_gt) | |
| 1048 | done | |
| 1049 | ||
| 1050 | lemma ge_natfloor_plus_one_imp_gt: "natfloor z + 1 <= n ==> z < real n" | |
| 1051 | apply (subgoal_tac "z < real(natfloor z) + 1") | |
| 1052 | apply arith | |
| 1053 | apply (rule real_natfloor_add_one_gt) | |
| 1054 | done | |
| 1055 | ||
| 1056 | lemma natfloor_add [simp]: "0 <= x ==> natfloor (x + real a) = natfloor x + a" | |
| 1057 | apply (unfold natfloor_def) | |
| 1058 | apply (subgoal_tac "real a = real (int a)") | |
| 1059 | apply (erule ssubst) | |
| 1060 | apply (simp add: nat_add_distrib) | |
| 1061 | apply simp | |
| 1062 | done | |
| 1063 | ||
| 16893 | 1064 | lemma natfloor_add_number_of [simp]: | 
| 1065 | "~neg ((number_of n)::int) ==> 0 <= x ==> | |
| 16819 | 1066 | natfloor (x + number_of n) = natfloor x + number_of n" | 
| 1067 | apply (subst natfloor_add [THEN sym]) | |
| 1068 | apply simp_all | |
| 1069 | done | |
| 1070 | ||
| 1071 | lemma natfloor_add_one: "0 <= x ==> natfloor(x + 1) = natfloor x + 1" | |
| 1072 | apply (subst natfloor_add [THEN sym]) | |
| 1073 | apply assumption | |
| 1074 | apply simp | |
| 1075 | done | |
| 1076 | ||
| 16893 | 1077 | lemma natfloor_subtract [simp]: "real a <= x ==> | 
| 16819 | 1078 | natfloor(x - real a) = natfloor x - a" | 
| 1079 | apply (unfold natfloor_def) | |
| 1080 | apply (subgoal_tac "real a = real (int a)") | |
| 1081 | apply (erule ssubst) | |
| 1082 | apply simp | |
| 1083 | apply (subst nat_diff_distrib) | |
| 1084 | apply simp | |
| 1085 | apply (rule le_floor) | |
| 1086 | apply simp_all | |
| 1087 | done | |
| 1088 | ||
| 1089 | lemma natceiling_zero [simp]: "natceiling 0 = 0" | |
| 1090 | by (unfold natceiling_def, simp) | |
| 1091 | ||
| 1092 | lemma natceiling_one [simp]: "natceiling 1 = 1" | |
| 1093 | by (unfold natceiling_def, simp) | |
| 1094 | ||
| 1095 | lemma zero_le_natceiling [simp]: "0 <= natceiling x" | |
| 1096 | by (unfold natceiling_def, simp) | |
| 1097 | ||
| 1098 | lemma natceiling_number_of_eq [simp]: "natceiling (number_of n) = number_of n" | |
| 1099 | by (unfold natceiling_def, simp) | |
| 1100 | ||
| 1101 | lemma natceiling_real_of_nat [simp]: "natceiling(real n) = n" | |
| 1102 | by (unfold natceiling_def, simp) | |
| 1103 | ||
| 1104 | lemma real_natceiling_ge: "x <= real(natceiling x)" | |
| 1105 | apply (unfold natceiling_def) | |
| 1106 | apply (case_tac "x < 0") | |
| 1107 | apply simp | |
| 1108 | apply (subst real_nat_eq_real) | |
| 1109 | apply (subgoal_tac "ceiling 0 <= ceiling x") | |
| 1110 | apply simp | |
| 1111 | apply (rule ceiling_mono2) | |
| 1112 | apply simp | |
| 1113 | apply simp | |
| 1114 | done | |
| 1115 | ||
| 1116 | lemma natceiling_neg: "x <= 0 ==> natceiling x = 0" | |
| 1117 | apply (unfold natceiling_def) | |
| 1118 | apply simp | |
| 1119 | done | |
| 1120 | ||
| 1121 | lemma natceiling_mono: "x <= y ==> natceiling x <= natceiling y" | |
| 1122 | apply (case_tac "0 <= x") | |
| 1123 | apply (subst natceiling_def)+ | |
| 1124 | apply (subst nat_le_eq_zle) | |
| 1125 | apply (rule disjI2) | |
| 1126 | apply (subgoal_tac "real (0::int) <= real(ceiling y)") | |
| 1127 | apply simp | |
| 1128 | apply (rule order_trans) | |
| 1129 | apply simp | |
| 1130 | apply (erule order_trans) | |
| 1131 | apply simp | |
| 1132 | apply (erule ceiling_mono2) | |
| 1133 | apply (subst natceiling_neg) | |
| 1134 | apply simp_all | |
| 1135 | done | |
| 1136 | ||
| 1137 | lemma natceiling_le: "x <= real a ==> natceiling x <= a" | |
| 1138 | apply (unfold natceiling_def) | |
| 1139 | apply (case_tac "x < 0") | |
| 1140 | apply simp | |
| 1141 | apply (subst nat_int [THEN sym]);back; | |
| 1142 | apply (subst nat_le_eq_zle) | |
| 1143 | apply simp | |
| 1144 | apply (rule ceiling_le) | |
| 1145 | apply simp | |
| 1146 | done | |
| 1147 | ||
| 1148 | lemma natceiling_le_eq: "0 <= x ==> (natceiling x <= a) = (x <= real a)" | |
| 1149 | apply (rule iffI) | |
| 1150 | apply (rule order_trans) | |
| 1151 | apply (rule real_natceiling_ge) | |
| 1152 | apply (subst real_of_nat_le_iff) | |
| 1153 | apply assumption | |
| 1154 | apply (erule natceiling_le) | |
| 1155 | done | |
| 1156 | ||
| 16893 | 1157 | lemma natceiling_le_eq_number_of [simp]: | 
| 16820 | 1158 | "~ neg((number_of n)::int) ==> 0 <= x ==> | 
| 1159 | (natceiling x <= number_of n) = (x <= number_of n)" | |
| 16819 | 1160 | apply (subst natceiling_le_eq, assumption) | 
| 1161 | apply simp | |
| 1162 | done | |
| 1163 | ||
| 16820 | 1164 | lemma natceiling_le_eq_one: "(natceiling x <= 1) = (x <= 1)" | 
| 16819 | 1165 | apply (case_tac "0 <= x") | 
| 1166 | apply (subst natceiling_le_eq) | |
| 1167 | apply assumption | |
| 1168 | apply simp | |
| 1169 | apply (subst natceiling_neg) | |
| 1170 | apply simp | |
| 1171 | apply simp | |
| 1172 | done | |
| 1173 | ||
| 1174 | lemma natceiling_eq: "real n < x ==> x <= real n + 1 ==> natceiling x = n + 1" | |
| 1175 | apply (unfold natceiling_def) | |
| 1176 | apply (subst nat_int [THEN sym]);back; | |
| 1177 | apply (subgoal_tac "nat(int n) + 1 = nat(int n + 1)") | |
| 1178 | apply (erule ssubst) | |
| 1179 | apply (subst eq_nat_nat_iff) | |
| 1180 | apply (subgoal_tac "ceiling 0 <= ceiling x") | |
| 1181 | apply simp | |
| 1182 | apply (rule ceiling_mono2) | |
| 1183 | apply force | |
| 1184 | apply force | |
| 1185 | apply (rule ceiling_eq2) | |
| 1186 | apply (simp, simp) | |
| 1187 | apply (subst nat_add_distrib) | |
| 1188 | apply auto | |
| 1189 | done | |
| 1190 | ||
| 16893 | 1191 | lemma natceiling_add [simp]: "0 <= x ==> | 
| 16819 | 1192 | natceiling (x + real a) = natceiling x + a" | 
| 1193 | apply (unfold natceiling_def) | |
| 1194 | apply (subgoal_tac "real a = real (int a)") | |
| 1195 | apply (erule ssubst) | |
| 1196 | apply simp | |
| 1197 | apply (subst nat_add_distrib) | |
| 1198 | apply (subgoal_tac "0 = ceiling 0") | |
| 1199 | apply (erule ssubst) | |
| 1200 | apply (erule ceiling_mono2) | |
| 1201 | apply simp_all | |
| 1202 | done | |
| 1203 | ||
| 16893 | 1204 | lemma natceiling_add_number_of [simp]: | 
| 1205 | "~ neg ((number_of n)::int) ==> 0 <= x ==> | |
| 16820 | 1206 | natceiling (x + number_of n) = natceiling x + number_of n" | 
| 16819 | 1207 | apply (subst natceiling_add [THEN sym]) | 
| 1208 | apply simp_all | |
| 1209 | done | |
| 1210 | ||
| 1211 | lemma natceiling_add_one: "0 <= x ==> natceiling(x + 1) = natceiling x + 1" | |
| 1212 | apply (subst natceiling_add [THEN sym]) | |
| 1213 | apply assumption | |
| 1214 | apply simp | |
| 1215 | done | |
| 1216 | ||
| 16893 | 1217 | lemma natceiling_subtract [simp]: "real a <= x ==> | 
| 16819 | 1218 | natceiling(x - real a) = natceiling x - a" | 
| 1219 | apply (unfold natceiling_def) | |
| 1220 | apply (subgoal_tac "real a = real (int a)") | |
| 1221 | apply (erule ssubst) | |
| 1222 | apply simp | |
| 1223 | apply (subst nat_diff_distrib) | |
| 1224 | apply simp | |
| 1225 | apply (rule order_trans) | |
| 1226 | prefer 2 | |
| 1227 | apply (rule ceiling_mono2) | |
| 1228 | apply assumption | |
| 1229 | apply simp_all | |
| 1230 | done | |
| 1231 | ||
| 16893 | 1232 | lemma natfloor_div_nat: "1 <= x ==> 0 < y ==> | 
| 16819 | 1233 | natfloor (x / real y) = natfloor x div y" | 
| 1234 | proof - | |
| 1235 | assume "1 <= (x::real)" and "0 < (y::nat)" | |
| 1236 | have "natfloor x = (natfloor x) div y * y + (natfloor x) mod y" | |
| 1237 | by simp | |
| 16893 | 1238 | then have a: "real(natfloor x) = real ((natfloor x) div y) * real y + | 
| 16819 | 1239 | real((natfloor x) mod y)" | 
| 1240 | by (simp only: real_of_nat_add [THEN sym] real_of_nat_mult [THEN sym]) | |
| 1241 | have "x = real(natfloor x) + (x - real(natfloor x))" | |
| 1242 | by simp | |
| 16893 | 1243 | then have "x = real ((natfloor x) div y) * real y + | 
| 16819 | 1244 | real((natfloor x) mod y) + (x - real(natfloor x))" | 
| 1245 | by (simp add: a) | |
| 1246 | then have "x / real y = ... / real y" | |
| 1247 | by simp | |
| 16893 | 1248 | also have "... = real((natfloor x) div y) + real((natfloor x) mod y) / | 
| 16819 | 1249 | real y + (x - real(natfloor x)) / real y" | 
| 1250 | by (auto simp add: ring_distrib ring_eq_simps add_divide_distrib | |
| 1251 | diff_divide_distrib prems) | |
| 1252 | finally have "natfloor (x / real y) = natfloor(...)" by simp | |
| 16893 | 1253 | also have "... = natfloor(real((natfloor x) mod y) / | 
| 16819 | 1254 | real y + (x - real(natfloor x)) / real y + real((natfloor x) div y))" | 
| 1255 | by (simp add: add_ac) | |
| 16893 | 1256 | also have "... = natfloor(real((natfloor x) mod y) / | 
| 16819 | 1257 | real y + (x - real(natfloor x)) / real y) + (natfloor x) div y" | 
| 1258 | apply (rule natfloor_add) | |
| 1259 | apply (rule add_nonneg_nonneg) | |
| 1260 | apply (rule divide_nonneg_pos) | |
| 1261 | apply simp | |
| 1262 | apply (simp add: prems) | |
| 1263 | apply (rule divide_nonneg_pos) | |
| 1264 | apply (simp add: compare_rls) | |
| 1265 | apply (rule real_natfloor_le) | |
| 1266 | apply (insert prems, auto) | |
| 1267 | done | |
| 16893 | 1268 | also have "natfloor(real((natfloor x) mod y) / | 
| 16819 | 1269 | real y + (x - real(natfloor x)) / real y) = 0" | 
| 1270 | apply (rule natfloor_eq) | |
| 1271 | apply simp | |
| 1272 | apply (rule add_nonneg_nonneg) | |
| 1273 | apply (rule divide_nonneg_pos) | |
| 1274 | apply force | |
| 1275 | apply (force simp add: prems) | |
| 1276 | apply (rule divide_nonneg_pos) | |
| 1277 | apply (simp add: compare_rls) | |
| 1278 | apply (rule real_natfloor_le) | |
| 1279 | apply (auto simp add: prems) | |
| 1280 | apply (insert prems, arith) | |
| 1281 | apply (simp add: add_divide_distrib [THEN sym]) | |
| 1282 | apply (subgoal_tac "real y = real y - 1 + 1") | |
| 1283 | apply (erule ssubst) | |
| 1284 | apply (rule add_le_less_mono) | |
| 1285 | apply (simp add: compare_rls) | |
| 16893 | 1286 | apply (subgoal_tac "real(natfloor x mod y) + 1 = | 
| 16819 | 1287 | real(natfloor x mod y + 1)") | 
| 1288 | apply (erule ssubst) | |
| 1289 | apply (subst real_of_nat_le_iff) | |
| 1290 | apply (subgoal_tac "natfloor x mod y < y") | |
| 1291 | apply arith | |
| 1292 | apply (rule mod_less_divisor) | |
| 1293 | apply assumption | |
| 1294 | apply auto | |
| 1295 | apply (simp add: compare_rls) | |
| 1296 | apply (subst add_commute) | |
| 1297 | apply (rule real_natfloor_add_one_gt) | |
| 1298 | done | |
| 1299 | finally show ?thesis | |
| 1300 | by simp | |
| 1301 | qed | |
| 1302 | ||
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1303 | ML | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1304 | {*
 | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1305 | val number_of_less_real_of_int_iff = thm "number_of_less_real_of_int_iff"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1306 | val number_of_less_real_of_int_iff2 = thm "number_of_less_real_of_int_iff2"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1307 | val number_of_le_real_of_int_iff = thm "number_of_le_real_of_int_iff"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1308 | val number_of_le_real_of_int_iff2 = thm "number_of_le_real_of_int_iff2"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1309 | val floor_zero = thm "floor_zero"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1310 | val floor_real_of_nat_zero = thm "floor_real_of_nat_zero"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1311 | val floor_real_of_nat = thm "floor_real_of_nat"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1312 | val floor_minus_real_of_nat = thm "floor_minus_real_of_nat"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1313 | val floor_real_of_int = thm "floor_real_of_int"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1314 | val floor_minus_real_of_int = thm "floor_minus_real_of_int"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1315 | val reals_Archimedean6 = thm "reals_Archimedean6"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1316 | val reals_Archimedean6a = thm "reals_Archimedean6a"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1317 | val reals_Archimedean_6b_int = thm "reals_Archimedean_6b_int"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1318 | val reals_Archimedean_6c_int = thm "reals_Archimedean_6c_int"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1319 | val real_lb_ub_int = thm "real_lb_ub_int"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1320 | val lemma_floor = thm "lemma_floor"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1321 | val real_of_int_floor_le = thm "real_of_int_floor_le"; | 
| 16819 | 1322 | (*val floor_le = thm "floor_le"; | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1323 | val floor_le2 = thm "floor_le2"; | 
| 16819 | 1324 | *) | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1325 | val lemma_floor2 = thm "lemma_floor2"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1326 | val real_of_int_floor_cancel = thm "real_of_int_floor_cancel"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1327 | val floor_eq = thm "floor_eq"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1328 | val floor_eq2 = thm "floor_eq2"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1329 | val floor_eq3 = thm "floor_eq3"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1330 | val floor_eq4 = thm "floor_eq4"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1331 | val floor_number_of_eq = thm "floor_number_of_eq"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1332 | val real_of_int_floor_ge_diff_one = thm "real_of_int_floor_ge_diff_one"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1333 | val real_of_int_floor_add_one_ge = thm "real_of_int_floor_add_one_ge"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1334 | val ceiling_zero = thm "ceiling_zero"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1335 | val ceiling_real_of_nat = thm "ceiling_real_of_nat"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1336 | val ceiling_real_of_nat_zero = thm "ceiling_real_of_nat_zero"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1337 | val ceiling_floor = thm "ceiling_floor"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1338 | val floor_ceiling = thm "floor_ceiling"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1339 | val real_of_int_ceiling_ge = thm "real_of_int_ceiling_ge"; | 
| 16819 | 1340 | (* | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1341 | val ceiling_le = thm "ceiling_le"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1342 | val ceiling_le2 = thm "ceiling_le2"; | 
| 16819 | 1343 | *) | 
| 14641 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1344 | val real_of_int_ceiling_cancel = thm "real_of_int_ceiling_cancel"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1345 | val ceiling_eq = thm "ceiling_eq"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1346 | val ceiling_eq2 = thm "ceiling_eq2"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1347 | val ceiling_eq3 = thm "ceiling_eq3"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1348 | val ceiling_real_of_int = thm "ceiling_real_of_int"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1349 | val ceiling_number_of_eq = thm "ceiling_number_of_eq"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1350 | val real_of_int_ceiling_diff_one_le = thm "real_of_int_ceiling_diff_one_le"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1351 | val real_of_int_ceiling_le_add_one = thm "real_of_int_ceiling_le_add_one"; | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1352 | *} | 
| 
79b7bd936264
moved Complex/NSInduct and Hyperreal/IntFloor to more appropriate
 paulson parents: 
14476diff
changeset | 1353 | |
| 14365 
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
 paulson parents: 
9429diff
changeset | 1354 | end |