13958
|
1 |
(* Title: IntFloor.thy
|
|
2 |
Author: Jacques D. Fleuriot
|
|
3 |
Copyright: 2001,2002 University of Edinburgh
|
14425
|
4 |
Converted to Isar and polished by lcp
|
13958
|
5 |
*)
|
|
6 |
|
14425
|
7 |
header{*Floor and Ceiling Functions from the Reals to the Integers*}
|
|
8 |
|
|
9 |
theory IntFloor = Integration:
|
13958
|
10 |
|
|
11 |
constdefs
|
14425
|
12 |
|
|
13 |
floor :: "real => int"
|
13958
|
14 |
"floor r == (LEAST n. r < real (n + (1::int)))"
|
|
15 |
|
14425
|
16 |
ceiling :: "real => int"
|
13958
|
17 |
"ceiling r == - floor (- r)"
|
14425
|
18 |
|
|
19 |
syntax (xsymbols)
|
|
20 |
floor :: "real => int" ("\<lfloor>_\<rfloor>")
|
|
21 |
ceiling :: "real => int" ("\<lceil>_\<rceil>")
|
|
22 |
|
14565
|
23 |
syntax (HTML output)
|
|
24 |
floor :: "real => int" ("\<lfloor>_\<rfloor>")
|
|
25 |
ceiling :: "real => int" ("\<lceil>_\<rceil>")
|
14425
|
26 |
|
|
27 |
|
|
28 |
lemma number_of_less_real_of_int_iff [simp]:
|
|
29 |
"((number_of n) < real (m::int)) = (number_of n < m)"
|
|
30 |
apply auto
|
|
31 |
apply (rule real_of_int_less_iff [THEN iffD1])
|
|
32 |
apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
|
|
33 |
done
|
|
34 |
|
|
35 |
lemma number_of_less_real_of_int_iff2 [simp]:
|
|
36 |
"(real (m::int) < (number_of n)) = (m < number_of n)"
|
|
37 |
apply auto
|
|
38 |
apply (rule real_of_int_less_iff [THEN iffD1])
|
|
39 |
apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
|
|
40 |
done
|
|
41 |
|
|
42 |
lemma number_of_le_real_of_int_iff [simp]:
|
|
43 |
"((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"
|
|
44 |
by (simp add: linorder_not_less [symmetric])
|
|
45 |
|
|
46 |
lemma number_of_le_real_of_int_iff2 [simp]:
|
|
47 |
"(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"
|
|
48 |
by (simp add: linorder_not_less [symmetric])
|
|
49 |
|
|
50 |
lemma floor_zero [simp]: "floor 0 = 0"
|
|
51 |
apply (simp add: floor_def)
|
|
52 |
apply (rule Least_equality, auto)
|
|
53 |
done
|
|
54 |
|
|
55 |
lemma floor_real_of_nat_zero [simp]: "floor (real (0::nat)) = 0"
|
|
56 |
by auto
|
|
57 |
|
|
58 |
lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
|
|
59 |
apply (simp only: floor_def)
|
|
60 |
apply (rule Least_equality)
|
|
61 |
apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
|
|
62 |
apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
|
|
63 |
apply (simp_all add: real_of_int_real_of_nat)
|
|
64 |
done
|
|
65 |
|
|
66 |
lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
|
|
67 |
apply (simp only: floor_def)
|
|
68 |
apply (rule Least_equality)
|
|
69 |
apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
|
|
70 |
apply (drule_tac [2] real_of_int_minus [THEN subst])
|
|
71 |
apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
|
|
72 |
apply (simp_all add: real_of_int_real_of_nat)
|
|
73 |
done
|
|
74 |
|
|
75 |
lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
|
|
76 |
apply (simp only: floor_def)
|
|
77 |
apply (rule Least_equality)
|
|
78 |
apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
|
|
79 |
apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
|
|
80 |
done
|
|
81 |
|
|
82 |
lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
|
|
83 |
apply (simp only: floor_def)
|
|
84 |
apply (rule Least_equality)
|
|
85 |
apply (drule_tac [2] real_of_int_minus [THEN subst])
|
|
86 |
apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
|
|
87 |
apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
|
|
88 |
done
|
|
89 |
|
|
90 |
lemma reals_Archimedean6:
|
|
91 |
"0 \<le> r ==> \<exists>(n::nat). real (n - 1) \<le> r & r < real (n)"
|
|
92 |
apply (insert reals_Archimedean2 [of r], safe)
|
|
93 |
apply (frule_tac P = "%k. r < real k" and k = n and m = "%x. x"
|
|
94 |
in ex_has_least_nat, auto)
|
|
95 |
apply (rule_tac x = x in exI)
|
|
96 |
apply (case_tac x, simp)
|
|
97 |
apply (rename_tac x')
|
|
98 |
apply (drule_tac x = x' in spec, simp)
|
|
99 |
done
|
|
100 |
|
|
101 |
lemma reals_Archimedean6a: "0 \<le> r ==> \<exists>n. real (n) \<le> r & r < real (Suc n)"
|
|
102 |
by (drule reals_Archimedean6, auto)
|
|
103 |
|
|
104 |
lemma reals_Archimedean_6b_int:
|
|
105 |
"0 \<le> r ==> \<exists>n. real n \<le> r & r < real ((n::int) + 1)"
|
|
106 |
apply (drule reals_Archimedean6a, auto)
|
|
107 |
apply (rule_tac x = "int n" in exI)
|
|
108 |
apply (simp add: real_of_int_real_of_nat real_of_nat_Suc)
|
|
109 |
done
|
|
110 |
|
|
111 |
lemma reals_Archimedean_6c_int:
|
|
112 |
"r < 0 ==> \<exists>n. real n \<le> r & r < real ((n::int) + 1)"
|
|
113 |
apply (rule reals_Archimedean_6b_int [of "-r", THEN exE], simp, auto)
|
|
114 |
apply (rename_tac n)
|
|
115 |
apply (drule real_le_imp_less_or_eq, auto)
|
|
116 |
apply (rule_tac x = "- n - 1" in exI)
|
|
117 |
apply (rule_tac [2] x = "- n" in exI, auto)
|
|
118 |
done
|
|
119 |
|
|
120 |
lemma real_lb_ub_int: " \<exists>(n::int). real n \<le> r & r < real ((n::int) + 1)"
|
|
121 |
apply (case_tac "r < 0")
|
|
122 |
apply (blast intro: reals_Archimedean_6c_int)
|
|
123 |
apply (simp only: linorder_not_less)
|
|
124 |
apply (blast intro: reals_Archimedean_6b_int reals_Archimedean_6c_int)
|
|
125 |
done
|
|
126 |
|
|
127 |
lemma lemma_floor:
|
|
128 |
assumes a1: "real m \<le> r" and a2: "r < real n + 1"
|
|
129 |
shows "m \<le> (n::int)"
|
|
130 |
proof -
|
|
131 |
have "real m < real n + 1" by (rule order_le_less_trans)
|
|
132 |
also have "... = real(n+1)" by simp
|
|
133 |
finally have "m < n+1" by (simp only: real_of_int_less_iff)
|
|
134 |
thus ?thesis by arith
|
|
135 |
qed
|
|
136 |
|
|
137 |
lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
|
|
138 |
apply (simp add: floor_def Least_def)
|
|
139 |
apply (insert real_lb_ub_int [of r], safe)
|
|
140 |
apply (rule theI2, auto)
|
|
141 |
done
|
|
142 |
|
|
143 |
lemma floor_le: "x < y ==> floor x \<le> floor y"
|
|
144 |
apply (simp add: floor_def Least_def)
|
|
145 |
apply (insert real_lb_ub_int [of x])
|
|
146 |
apply (insert real_lb_ub_int [of y], safe)
|
|
147 |
apply (rule theI2)
|
|
148 |
apply (rule_tac [3] theI2, auto)
|
|
149 |
done
|
|
150 |
|
|
151 |
lemma floor_le2: "x \<le> y ==> floor x \<le> floor y"
|
|
152 |
by (auto dest: real_le_imp_less_or_eq simp add: floor_le)
|
|
153 |
|
|
154 |
lemma lemma_floor2: "real na < real (x::int) + 1 ==> na \<le> x"
|
|
155 |
by (auto intro: lemma_floor)
|
|
156 |
|
|
157 |
lemma real_of_int_floor_cancel [simp]:
|
|
158 |
"(real (floor x) = x) = (\<exists>n::int. x = real n)"
|
|
159 |
apply (simp add: floor_def Least_def)
|
|
160 |
apply (insert real_lb_ub_int [of x], erule exE)
|
|
161 |
apply (rule theI2)
|
|
162 |
apply (auto intro: lemma_floor)
|
|
163 |
done
|
|
164 |
|
|
165 |
lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
|
|
166 |
apply (simp add: floor_def)
|
|
167 |
apply (rule Least_equality)
|
|
168 |
apply (auto intro: lemma_floor)
|
|
169 |
done
|
|
170 |
|
|
171 |
lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
|
|
172 |
apply (simp add: floor_def)
|
|
173 |
apply (rule Least_equality)
|
|
174 |
apply (auto intro: lemma_floor)
|
|
175 |
done
|
|
176 |
|
|
177 |
lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
|
|
178 |
apply (rule inj_int [THEN injD])
|
|
179 |
apply (simp add: real_of_nat_Suc)
|
|
180 |
apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "of_nat n"])
|
|
181 |
done
|
|
182 |
|
|
183 |
lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
|
|
184 |
apply (drule order_le_imp_less_or_eq)
|
|
185 |
apply (auto intro: floor_eq3)
|
|
186 |
done
|
|
187 |
|
|
188 |
lemma floor_number_of_eq [simp]:
|
|
189 |
"floor(number_of n :: real) = (number_of n :: int)"
|
|
190 |
apply (subst real_number_of [symmetric])
|
|
191 |
apply (rule floor_real_of_int)
|
|
192 |
done
|
|
193 |
|
|
194 |
lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
|
|
195 |
apply (simp add: floor_def Least_def)
|
|
196 |
apply (insert real_lb_ub_int [of r], safe)
|
|
197 |
apply (rule theI2)
|
|
198 |
apply (auto intro: lemma_floor)
|
|
199 |
done
|
|
200 |
|
|
201 |
lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
|
|
202 |
apply (insert real_of_int_floor_ge_diff_one [of r])
|
|
203 |
apply (auto simp del: real_of_int_floor_ge_diff_one)
|
|
204 |
done
|
|
205 |
|
|
206 |
|
|
207 |
subsection{*Ceiling Function for Positive Reals*}
|
|
208 |
|
|
209 |
lemma ceiling_zero [simp]: "ceiling 0 = 0"
|
|
210 |
by (simp add: ceiling_def)
|
|
211 |
|
|
212 |
lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
|
|
213 |
by (simp add: ceiling_def)
|
|
214 |
|
|
215 |
lemma ceiling_real_of_nat_zero [simp]: "ceiling (real (0::nat)) = 0"
|
|
216 |
by auto
|
|
217 |
|
|
218 |
lemma ceiling_floor [simp]: "ceiling (real (floor r)) = floor r"
|
|
219 |
by (simp add: ceiling_def)
|
|
220 |
|
|
221 |
lemma floor_ceiling [simp]: "floor (real (ceiling r)) = ceiling r"
|
|
222 |
by (simp add: ceiling_def)
|
|
223 |
|
|
224 |
lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
|
|
225 |
apply (simp add: ceiling_def)
|
|
226 |
apply (subst le_minus_iff, simp)
|
|
227 |
done
|
|
228 |
|
|
229 |
lemma ceiling_le: "x < y ==> ceiling x \<le> ceiling y"
|
|
230 |
by (simp add: floor_le ceiling_def)
|
|
231 |
|
|
232 |
lemma ceiling_le2: "x \<le> y ==> ceiling x \<le> ceiling y"
|
|
233 |
by (simp add: floor_le2 ceiling_def)
|
|
234 |
|
|
235 |
lemma real_of_int_ceiling_cancel [simp]:
|
|
236 |
"(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
|
|
237 |
apply (auto simp add: ceiling_def)
|
|
238 |
apply (drule arg_cong [where f = uminus], auto)
|
|
239 |
apply (rule_tac x = "-n" in exI, auto)
|
|
240 |
done
|
|
241 |
|
|
242 |
lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
|
|
243 |
apply (simp add: ceiling_def)
|
|
244 |
apply (rule minus_equation_iff [THEN iffD1])
|
|
245 |
apply (simp add: floor_eq [where n = "-(n+1)"])
|
|
246 |
done
|
|
247 |
|
|
248 |
lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
|
|
249 |
by (simp add: ceiling_def floor_eq2 [where n = "-(n+1)"])
|
|
250 |
|
|
251 |
lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n |] ==> ceiling x = n"
|
|
252 |
by (simp add: ceiling_def floor_eq2 [where n = "-n"])
|
|
253 |
|
|
254 |
lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
|
|
255 |
by (simp add: ceiling_def)
|
|
256 |
|
|
257 |
lemma ceiling_number_of_eq [simp]:
|
|
258 |
"ceiling (number_of n :: real) = (number_of n)"
|
|
259 |
apply (subst real_number_of [symmetric])
|
|
260 |
apply (rule ceiling_real_of_int)
|
|
261 |
done
|
|
262 |
|
|
263 |
lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
|
|
264 |
apply (rule neg_le_iff_le [THEN iffD1])
|
|
265 |
apply (simp add: ceiling_def diff_minus)
|
|
266 |
done
|
|
267 |
|
|
268 |
lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
|
|
269 |
apply (insert real_of_int_ceiling_diff_one_le [of r])
|
|
270 |
apply (simp del: real_of_int_ceiling_diff_one_le)
|
|
271 |
done
|
|
272 |
|
|
273 |
ML
|
|
274 |
{*
|
|
275 |
val number_of_less_real_of_int_iff = thm "number_of_less_real_of_int_iff";
|
|
276 |
val number_of_less_real_of_int_iff2 = thm "number_of_less_real_of_int_iff2";
|
|
277 |
val number_of_le_real_of_int_iff = thm "number_of_le_real_of_int_iff";
|
|
278 |
val number_of_le_real_of_int_iff2 = thm "number_of_le_real_of_int_iff2";
|
|
279 |
val floor_zero = thm "floor_zero";
|
|
280 |
val floor_real_of_nat_zero = thm "floor_real_of_nat_zero";
|
|
281 |
val floor_real_of_nat = thm "floor_real_of_nat";
|
|
282 |
val floor_minus_real_of_nat = thm "floor_minus_real_of_nat";
|
|
283 |
val floor_real_of_int = thm "floor_real_of_int";
|
|
284 |
val floor_minus_real_of_int = thm "floor_minus_real_of_int";
|
|
285 |
val reals_Archimedean6 = thm "reals_Archimedean6";
|
|
286 |
val reals_Archimedean6a = thm "reals_Archimedean6a";
|
|
287 |
val reals_Archimedean_6b_int = thm "reals_Archimedean_6b_int";
|
|
288 |
val reals_Archimedean_6c_int = thm "reals_Archimedean_6c_int";
|
|
289 |
val real_lb_ub_int = thm "real_lb_ub_int";
|
|
290 |
val lemma_floor = thm "lemma_floor";
|
|
291 |
val real_of_int_floor_le = thm "real_of_int_floor_le";
|
|
292 |
val floor_le = thm "floor_le";
|
|
293 |
val floor_le2 = thm "floor_le2";
|
|
294 |
val lemma_floor2 = thm "lemma_floor2";
|
|
295 |
val real_of_int_floor_cancel = thm "real_of_int_floor_cancel";
|
|
296 |
val floor_eq = thm "floor_eq";
|
|
297 |
val floor_eq2 = thm "floor_eq2";
|
|
298 |
val floor_eq3 = thm "floor_eq3";
|
|
299 |
val floor_eq4 = thm "floor_eq4";
|
|
300 |
val floor_number_of_eq = thm "floor_number_of_eq";
|
|
301 |
val real_of_int_floor_ge_diff_one = thm "real_of_int_floor_ge_diff_one";
|
|
302 |
val real_of_int_floor_add_one_ge = thm "real_of_int_floor_add_one_ge";
|
|
303 |
val ceiling_zero = thm "ceiling_zero";
|
|
304 |
val ceiling_real_of_nat = thm "ceiling_real_of_nat";
|
|
305 |
val ceiling_real_of_nat_zero = thm "ceiling_real_of_nat_zero";
|
|
306 |
val ceiling_floor = thm "ceiling_floor";
|
|
307 |
val floor_ceiling = thm "floor_ceiling";
|
|
308 |
val real_of_int_ceiling_ge = thm "real_of_int_ceiling_ge";
|
|
309 |
val ceiling_le = thm "ceiling_le";
|
|
310 |
val ceiling_le2 = thm "ceiling_le2";
|
|
311 |
val real_of_int_ceiling_cancel = thm "real_of_int_ceiling_cancel";
|
|
312 |
val ceiling_eq = thm "ceiling_eq";
|
|
313 |
val ceiling_eq2 = thm "ceiling_eq2";
|
|
314 |
val ceiling_eq3 = thm "ceiling_eq3";
|
|
315 |
val ceiling_real_of_int = thm "ceiling_real_of_int";
|
|
316 |
val ceiling_number_of_eq = thm "ceiling_number_of_eq";
|
|
317 |
val real_of_int_ceiling_diff_one_le = thm "real_of_int_ceiling_diff_one_le";
|
|
318 |
val real_of_int_ceiling_le_add_one = thm "real_of_int_ceiling_le_add_one";
|
|
319 |
*}
|
|
320 |
|
|
321 |
|
13958
|
322 |
end
|