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