author | paulson |
Tue, 17 Feb 2004 10:41:59 +0100 | |
changeset 14390 | 55fe71faadda |
parent 14387 | e96d5c42c4b0 |
permissions | -rw-r--r-- |
13958 | 1 |
(* Title: IntFloor.ML |
2 |
Author: Jacques D. Fleuriot |
|
3 |
Copyright: 2001,2002 University of Edinburgh |
|
4 |
Description: Floor and ceiling operations over reals |
|
5 |
*) |
|
6 |
||
7 |
Goal "((number_of n) < real (m::int)) = (number_of n < m)"; |
|
8 |
by Auto_tac; |
|
9 |
by (rtac (real_of_int_less_iff RS iffD1) 1); |
|
10 |
by (dtac (real_of_int_less_iff RS iffD2) 2); |
|
11 |
by Auto_tac; |
|
12 |
qed "number_of_less_real_of_int_iff"; |
|
13 |
Addsimps [number_of_less_real_of_int_iff]; |
|
14 |
||
15 |
Goal "(real (m::int) < (number_of n)) = (m < number_of n)"; |
|
16 |
by Auto_tac; |
|
17 |
by (rtac (real_of_int_less_iff RS iffD1) 1); |
|
18 |
by (dtac (real_of_int_less_iff RS iffD2) 2); |
|
19 |
by Auto_tac; |
|
20 |
qed "number_of_less_real_of_int_iff2"; |
|
21 |
Addsimps [number_of_less_real_of_int_iff2]; |
|
22 |
||
14365
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14355
diff
changeset
|
23 |
Goal "((number_of n) <= real (m::int)) = (number_of n <= m)"; |
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14355
diff
changeset
|
24 |
by (auto_tac (claset(), simpset() addsimps [linorder_not_less RS sym])); |
13958 | 25 |
qed "number_of_le_real_of_int_iff"; |
26 |
Addsimps [number_of_le_real_of_int_iff]; |
|
27 |
||
14365
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14355
diff
changeset
|
28 |
Goal "(real (m::int) <= (number_of n)) = (m <= number_of n)"; |
3d4df8c166ae
replacing HOL/Real/PRat, PNat by the rational number development
paulson
parents:
14355
diff
changeset
|
29 |
by (auto_tac (claset(), simpset() addsimps [linorder_not_less RS sym])); |
13958 | 30 |
qed "number_of_le_real_of_int_iff2"; |
31 |
Addsimps [number_of_le_real_of_int_iff2]; |
|
32 |
||
33 |
Goalw [floor_def] "floor 0 = 0"; |
|
34 |
by (rtac Least_equality 1); |
|
35 |
by Auto_tac; |
|
36 |
qed "floor_zero"; |
|
37 |
Addsimps [floor_zero]; |
|
38 |
||
39 |
Goal "floor (real (0::nat)) = 0"; |
|
40 |
by Auto_tac; |
|
41 |
qed "floor_real_of_nat_zero"; |
|
42 |
Addsimps [floor_real_of_nat_zero]; |
|
43 |
||
44 |
Goalw [floor_def] "floor (real (n::nat)) = int n"; |
|
45 |
by (rtac Least_equality 1); |
|
46 |
by (dtac (real_of_int_real_of_nat RS ssubst) 2); |
|
47 |
by (dtac (real_of_int_less_iff RS iffD1) 2); |
|
48 |
by (auto_tac (claset(),simpset() addsimps [real_of_int_real_of_nat])); |
|
49 |
qed "floor_real_of_nat"; |
|
50 |
Addsimps [floor_real_of_nat]; |
|
51 |
||
52 |
Goalw [floor_def] "floor (- real (n::nat)) = - int n"; |
|
53 |
by (rtac Least_equality 1); |
|
54 |
by (dtac (real_of_int_real_of_nat RS ssubst) 2); |
|
55 |
by (dtac (real_of_int_minus RS subst) 2); |
|
56 |
by (dtac (real_of_int_less_iff RS iffD1) 2); |
|
57 |
by (auto_tac (claset(),simpset() addsimps [real_of_int_real_of_nat])); |
|
58 |
qed "floor_minus_real_of_nat"; |
|
59 |
Addsimps [floor_minus_real_of_nat]; |
|
60 |
||
61 |
Goalw [floor_def] "floor (real (n::int)) = n"; |
|
62 |
by (rtac Least_equality 1); |
|
63 |
by (dtac (real_of_int_real_of_nat RS ssubst) 2); |
|
64 |
by (dtac (real_of_int_less_iff RS iffD1) 2); |
|
65 |
by Auto_tac; |
|
66 |
qed "floor_real_of_int"; |
|
67 |
Addsimps [floor_real_of_int]; |
|
68 |
||
69 |
Goalw [floor_def] "floor (- real (n::int)) = - n"; |
|
70 |
by (rtac Least_equality 1); |
|
71 |
by (dtac (real_of_int_minus RS subst) 2); |
|
72 |
by (dtac (real_of_int_real_of_nat RS ssubst) 2); |
|
73 |
by (dtac (real_of_int_less_iff RS iffD1) 2); |
|
74 |
by Auto_tac; |
|
75 |
qed "floor_minus_real_of_int"; |
|
76 |
Addsimps [floor_minus_real_of_int]; |
|
77 |
||
78 |
Goal "0 <= r ==> EX (n::nat). real (n - 1) <= r & r < real (n)"; |
|
79 |
by (cut_inst_tac [("x","r")] reals_Archimedean2 1); |
|
80 |
by (Step_tac 1); |
|
81 |
by (forw_inst_tac [("P","%k. r < real k"),("k","n"),("m","%x. x")] |
|
82 |
(thm "ex_has_least_nat") 1); |
|
83 |
by Auto_tac; |
|
84 |
by (res_inst_tac [("x","x")] exI 1); |
|
85 |
by (dres_inst_tac [("x","x - 1")] spec 1); |
|
86 |
by (auto_tac (claset() addDs [ARITH_PROVE "x <= x - Suc 0 ==> x = (0::nat)"], |
|
87 |
simpset())); |
|
88 |
qed "reals_Archimedean6"; |
|
89 |
||
90 |
Goal "0 <= r ==> EX n. real (n) <= r & r < real (Suc n)"; |
|
91 |
by (dtac reals_Archimedean6 1); |
|
92 |
by Auto_tac; |
|
93 |
qed "reals_Archimedean6a"; |
|
94 |
||
95 |
Goal "0 <= r ==> EX n. real n <= r & r < real ((n::int) + 1)"; |
|
96 |
by (dtac reals_Archimedean6a 1); |
|
97 |
by Auto_tac; |
|
98 |
by (res_inst_tac [("x","int n")] exI 1); |
|
99 |
by (auto_tac (claset(),simpset() addsimps [real_of_int_real_of_nat, |
|
100 |
real_of_nat_Suc])); |
|
101 |
qed "reals_Archimedean_6b_int"; |
|
102 |
||
103 |
Goal "r < 0 ==> EX n. real n <= r & r < real ((n::int) + 1)"; |
|
104 |
by (dtac (CLAIM "r < (0::real) ==> 0 <= -r") 1); |
|
105 |
by (dtac reals_Archimedean_6b_int 1); |
|
106 |
by Auto_tac; |
|
107 |
by (dtac real_le_imp_less_or_eq 1 THEN Auto_tac); |
|
108 |
by (res_inst_tac [("x","- n - 1")] exI 1); |
|
109 |
by (res_inst_tac [("x","- n")] exI 2); |
|
110 |
by Auto_tac; |
|
111 |
qed "reals_Archimedean_6c_int"; |
|
112 |
||
113 |
Goal " EX (n::int). real n <= r & r < real ((n::int) + 1)"; |
|
114 |
by (cut_inst_tac [("r","r")] (CLAIM "0 <= r | r < (0::real)") 1); |
|
115 |
by (blast_tac (claset() addIs [reals_Archimedean_6b_int, |
|
116 |
reals_Archimedean_6c_int]) 1); |
|
117 |
qed "real_lb_ub_int"; |
|
118 |
||
119 |
Goal "[| real n <= r; r < real y + 1 |] ==> n <= (y::int)"; |
|
120 |
by (dres_inst_tac [("x","real n"),("z","real y + 1")] order_le_less_trans 1); |
|
121 |
by (rotate_tac 1 2); |
|
122 |
by (dtac ((CLAIM "real (1::int) = 1") RS ssubst) 2); |
|
123 |
by (rotate_tac 1 2); |
|
124 |
by (dres_inst_tac [("x1","y")] (real_of_int_add RS subst) 2); |
|
125 |
by (dtac (real_of_int_less_iff RS iffD1) 2); |
|
126 |
by Auto_tac; |
|
127 |
val lemma_floor = result(); |
|
128 |
||
129 |
Goalw [floor_def,Least_def] "real (floor r) <= r"; |
|
130 |
by (cut_inst_tac [("r","r")] real_lb_ub_int 1 THEN Step_tac 1); |
|
131 |
by (rtac theI2 1); |
|
132 |
by Auto_tac; |
|
133 |
qed "real_of_int_floor_le"; |
|
134 |
Addsimps [real_of_int_floor_le]; |
|
135 |
||
136 |
Goalw [floor_def,Least_def] |
|
137 |
"x < y ==> floor x <= floor y"; |
|
138 |
by (cut_inst_tac [("r","x")] real_lb_ub_int 1 THEN Step_tac 1); |
|
139 |
by (cut_inst_tac [("r","y")] real_lb_ub_int 1 THEN Step_tac 1); |
|
140 |
by (rtac theI2 1); |
|
141 |
by (rtac theI2 3); |
|
142 |
by Auto_tac; |
|
143 |
by (auto_tac (claset() addIs [lemma_floor],simpset())); |
|
144 |
by (ALLGOALS(force_tac (claset() addDs [lemma_floor],simpset()))); |
|
145 |
qed "floor_le"; |
|
146 |
||
147 |
Goal "x <= y ==> floor x <= floor y"; |
|
148 |
by (auto_tac (claset() addDs [real_le_imp_less_or_eq],simpset() |
|
149 |
addsimps [floor_le])); |
|
150 |
qed "floor_le2"; |
|
151 |
||
152 |
Goal "real na < real (x::int) + 1 ==> na <= x"; |
|
153 |
by (auto_tac (claset() addIs [lemma_floor],simpset())); |
|
154 |
val lemma_floor2 = result(); |
|
155 |
||
156 |
Goalw [floor_def,Least_def] |
|
157 |
"(real (floor x) = x) = (EX (n::int). x = real n)"; |
|
158 |
by (cut_inst_tac [("r","x")] real_lb_ub_int 1 THEN etac exE 1); |
|
159 |
by (rtac theI2 1); |
|
160 |
by (auto_tac (claset() addIs [lemma_floor],simpset())); |
|
161 |
qed "real_of_int_floor_cancel"; |
|
162 |
Addsimps [real_of_int_floor_cancel]; |
|
163 |
||
164 |
Goalw [floor_def] |
|
165 |
"[| real n < x; x < real n + 1 |] ==> floor x = n"; |
|
166 |
by (rtac Least_equality 1); |
|
167 |
by (auto_tac (claset() addIs [lemma_floor],simpset())); |
|
168 |
qed "floor_eq"; |
|
169 |
||
170 |
Goalw [floor_def] |
|
171 |
"[| real n <= x; x < real n + 1 |] ==> floor x = n"; |
|
172 |
by (rtac Least_equality 1); |
|
173 |
by (auto_tac (claset() addIs [lemma_floor],simpset())); |
|
174 |
qed "floor_eq2"; |
|
175 |
||
176 |
Goal "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"; |
|
177 |
by (rtac (inj_int RS injD) 1); |
|
178 |
by (rtac (CLAIM "0 <= x ==> int (nat x) = x" RS ssubst) 1); |
|
179 |
by (rtac floor_eq 2); |
|
180 |
by (auto_tac (claset(),simpset() addsimps [real_of_nat_Suc, |
|
181 |
real_of_int_real_of_nat])); |
|
182 |
by (rtac (floor_le RSN (2,zle_trans)) 1 THEN Auto_tac); |
|
183 |
qed "floor_eq3"; |
|
184 |
||
185 |
Goal "[| real n <= x; x < real (Suc n) |] ==> nat(floor x) = n"; |
|
186 |
by (dtac order_le_imp_less_or_eq 1); |
|
187 |
by (auto_tac (claset() addIs [floor_eq3],simpset())); |
|
188 |
qed "floor_eq4"; |
|
189 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14365
diff
changeset
|
190 |
Goal "floor(number_of n :: real) = (number_of n :: int)"; |
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14365
diff
changeset
|
191 |
by (stac (real_number_of RS sym) 1); |
13958 | 192 |
by (rtac floor_eq2 1); |
193 |
by (rtac (CLAIM "x < x + (1::real)") 2); |
|
194 |
by (rtac real_le_refl 1); |
|
195 |
qed "floor_number_of_eq"; |
|
196 |
Addsimps [floor_number_of_eq]; |
|
197 |
||
198 |
Goalw [floor_def,Least_def] "r - 1 <= real(floor r)"; |
|
199 |
by (cut_inst_tac [("r","r")] real_lb_ub_int 1 THEN Step_tac 1); |
|
200 |
by (rtac theI2 1); |
|
201 |
by (auto_tac (claset() addIs [lemma_floor],simpset())); |
|
202 |
qed "real_of_int_floor_ge_diff_one"; |
|
203 |
Addsimps [real_of_int_floor_ge_diff_one]; |
|
204 |
||
205 |
Goal "r <= real(floor r) + 1"; |
|
206 |
by (cut_inst_tac [("r","r")] real_of_int_floor_ge_diff_one 1); |
|
207 |
by (auto_tac (claset(),simpset() delsimps [real_of_int_floor_ge_diff_one])); |
|
208 |
qed "real_of_int_floor_add_one_ge"; |
|
209 |
Addsimps [real_of_int_floor_add_one_ge]; |
|
210 |
||
211 |
||
212 |
(*--------------------------------------------------------------------------------*) |
|
213 |
(* ceiling function for positive reals *) |
|
214 |
(*--------------------------------------------------------------------------------*) |
|
215 |
||
216 |
Goalw [ceiling_def] "ceiling 0 = 0"; |
|
217 |
by Auto_tac; |
|
218 |
qed "ceiling_zero"; |
|
219 |
Addsimps [ceiling_zero]; |
|
220 |
||
221 |
Goalw [ceiling_def] "ceiling (real (n::nat)) = int n"; |
|
222 |
by Auto_tac; |
|
223 |
qed "ceiling_real_of_nat"; |
|
224 |
Addsimps [ceiling_real_of_nat]; |
|
225 |
||
226 |
Goal "ceiling (real (0::nat)) = 0"; |
|
227 |
by Auto_tac; |
|
228 |
qed "ceiling_real_of_nat_zero"; |
|
229 |
Addsimps [ceiling_real_of_nat_zero]; |
|
230 |
||
231 |
Goalw [ceiling_def] "ceiling (real (floor r)) = floor r"; |
|
232 |
by Auto_tac; |
|
233 |
qed "ceiling_floor"; |
|
234 |
Addsimps [ceiling_floor]; |
|
235 |
||
236 |
Goalw [ceiling_def] "floor (real (ceiling r)) = ceiling r"; |
|
237 |
by Auto_tac; |
|
238 |
qed "floor_ceiling"; |
|
239 |
Addsimps [floor_ceiling]; |
|
240 |
||
241 |
Goalw [ceiling_def] "r <= real (ceiling r)"; |
|
242 |
by Auto_tac; |
|
243 |
by (rtac (CLAIM "x <= -y ==> (y::real) <= - x") 1); |
|
244 |
by Auto_tac; |
|
245 |
qed "real_of_int_ceiling_ge"; |
|
246 |
Addsimps [real_of_int_ceiling_ge]; |
|
247 |
||
248 |
Goalw [ceiling_def] "x < y ==> ceiling x <= ceiling y"; |
|
249 |
by (auto_tac (claset() addIs [floor_le],simpset())); |
|
250 |
qed "ceiling_le"; |
|
251 |
||
252 |
Goalw [ceiling_def] "x <= y ==> ceiling x <= ceiling y"; |
|
253 |
by (auto_tac (claset() addIs [floor_le2],simpset())); |
|
254 |
qed "ceiling_le2"; |
|
255 |
||
256 |
Goalw [ceiling_def] "(real (ceiling x) = x) = (EX (n::int). x = real n)"; |
|
257 |
by Auto_tac; |
|
258 |
by (dtac (CLAIM "- x = y ==> (x::real) = -y") 1); |
|
259 |
by Auto_tac; |
|
260 |
by (res_inst_tac [("x","-n")] exI 1); |
|
261 |
by Auto_tac; |
|
262 |
qed "real_of_int_ceiling_cancel"; |
|
263 |
Addsimps [real_of_int_ceiling_cancel]; |
|
264 |
||
265 |
Goalw [ceiling_def] |
|
266 |
"[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"; |
|
267 |
by (rtac (CLAIM "x = - y ==> - (x::int) = y") 1); |
|
268 |
by (auto_tac (claset() addIs [floor_eq],simpset())); |
|
269 |
qed "ceiling_eq"; |
|
270 |
||
271 |
Goalw [ceiling_def] |
|
272 |
"[| real n < x; x <= real n + 1 |] ==> ceiling x = n + 1"; |
|
273 |
by (rtac (CLAIM "x = - y ==> - (x::int) = y") 1); |
|
274 |
by (auto_tac (claset() addIs [floor_eq2],simpset())); |
|
275 |
qed "ceiling_eq2"; |
|
276 |
||
277 |
Goalw [ceiling_def] "[| real n - 1 < x; x <= real n |] ==> ceiling x = n"; |
|
278 |
by (rtac (CLAIM "x = -(y::int) ==> - x = y") 1); |
|
279 |
by (auto_tac (claset() addIs [floor_eq2],simpset())); |
|
280 |
qed "ceiling_eq3"; |
|
281 |
||
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14365
diff
changeset
|
282 |
Goalw [ceiling_def] |
13958 | 283 |
"ceiling (number_of n :: real) = (number_of n :: int)"; |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14365
diff
changeset
|
284 |
by (stac (real_number_of RS sym) 1); |
13958 | 285 |
by (rtac (CLAIM "x = - y ==> - (x::int) = y") 1); |
286 |
by (rtac (floor_minus_real_of_int RS ssubst) 1); |
|
287 |
by Auto_tac; |
|
288 |
qed "ceiling_number_of_eq"; |
|
289 |
Addsimps [ceiling_number_of_eq]; |
|
290 |
||
291 |
Goalw [ceiling_def] "real (ceiling r) - 1 <= r"; |
|
292 |
by (rtac (CLAIM "-x <= -y ==> (y::real) <= x") 1); |
|
293 |
by (auto_tac (claset(),simpset() addsimps [real_diff_def])); |
|
294 |
qed "real_of_int_ceiling_diff_one_le"; |
|
295 |
Addsimps [real_of_int_ceiling_diff_one_le]; |
|
296 |
||
297 |
Goal "real (ceiling r) <= r + 1"; |
|
298 |
by (cut_inst_tac [("r","r")] real_of_int_ceiling_diff_one_le 1); |
|
299 |
by (auto_tac (claset(),simpset() delsimps [real_of_int_ceiling_diff_one_le])); |
|
300 |
qed "real_of_int_ceiling_le_add_one"; |
|
301 |
Addsimps [real_of_int_ceiling_le_add_one]; |
|
302 |