author | paulson |
Thu, 04 Jan 2001 10:23:01 +0100 | |
changeset 10778 | 2c6605049646 |
parent 10752 | c4f1bf2acf4c |
child 10784 | 27e4d90b35b5 |
permissions | -rw-r--r-- |
10722 | 1 |
(* Title: HOL/Real/RealArith.ML |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1999 University of Cambridge |
|
5 |
||
6 |
Assorted facts that need binary literals and the arithmetic decision procedure |
|
7 |
||
8 |
Also, common factor cancellation |
|
9 |
*) |
|
10 |
||
11 |
(** Division and inverse **) |
|
12 |
||
13 |
Goal "#0/x = (#0::real)"; |
|
14 |
by (simp_tac (simpset() addsimps [real_divide_def]) 1); |
|
15 |
qed "real_0_divide"; |
|
16 |
Addsimps [real_0_divide]; |
|
17 |
||
18 |
Goal "((#0::real) < inverse x) = (#0 < x)"; |
|
19 |
by (case_tac "x=#0" 1); |
|
20 |
by (asm_simp_tac (HOL_ss addsimps [rename_numerals INVERSE_ZERO]) 1); |
|
21 |
by (auto_tac (claset() addDs [rename_numerals real_inverse_less_zero], |
|
22 |
simpset() addsimps [linorder_neq_iff, |
|
23 |
rename_numerals real_inverse_gt_zero])); |
|
24 |
qed "real_0_less_inverse_iff"; |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
25 |
Addsimps [real_0_less_inverse_iff]; |
10722 | 26 |
|
27 |
Goal "(inverse x < (#0::real)) = (x < #0)"; |
|
28 |
by (case_tac "x=#0" 1); |
|
29 |
by (asm_simp_tac (HOL_ss addsimps [rename_numerals INVERSE_ZERO]) 1); |
|
30 |
by (auto_tac (claset() addDs [rename_numerals real_inverse_less_zero], |
|
31 |
simpset() addsimps [linorder_neq_iff, |
|
32 |
rename_numerals real_inverse_gt_zero])); |
|
33 |
qed "real_inverse_less_0_iff"; |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
34 |
Addsimps [real_inverse_less_0_iff]; |
10722 | 35 |
|
36 |
Goal "((#0::real) <= inverse x) = (#0 <= x)"; |
|
37 |
by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1); |
|
38 |
qed "real_0_le_inverse_iff"; |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
39 |
Addsimps [real_0_le_inverse_iff]; |
10722 | 40 |
|
41 |
Goal "(inverse x <= (#0::real)) = (x <= #0)"; |
|
42 |
by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1); |
|
43 |
qed "real_inverse_le_0_iff"; |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
44 |
Addsimps [real_inverse_le_0_iff]; |
10722 | 45 |
|
46 |
Goalw [real_divide_def] "x/(#0::real) = #0"; |
|
47 |
by (stac (rename_numerals INVERSE_ZERO) 1); |
|
48 |
by (Simp_tac 1); |
|
49 |
qed "REAL_DIVIDE_ZERO"; |
|
50 |
||
51 |
Goal "inverse (x::real) = #1/x"; |
|
52 |
by (simp_tac (simpset() addsimps [real_divide_def]) 1); |
|
53 |
qed "real_inverse_eq_divide"; |
|
54 |
||
55 |
Goal "((#0::real) < x/y) = (#0 < x & #0 < y | x < #0 & y < #0)"; |
|
56 |
by (simp_tac (simpset() addsimps [real_divide_def, real_0_less_mult_iff]) 1); |
|
57 |
qed "real_0_less_divide_iff"; |
|
58 |
Addsimps [inst "x" "number_of ?w" real_0_less_divide_iff]; |
|
59 |
||
60 |
Goal "(x/y < (#0::real)) = (#0 < x & y < #0 | x < #0 & #0 < y)"; |
|
61 |
by (simp_tac (simpset() addsimps [real_divide_def, real_mult_less_0_iff]) 1); |
|
62 |
qed "real_divide_less_0_iff"; |
|
63 |
Addsimps [inst "x" "number_of ?w" real_divide_less_0_iff]; |
|
64 |
||
65 |
Goal "((#0::real) <= x/y) = ((x <= #0 | #0 <= y) & (#0 <= x | y <= #0))"; |
|
66 |
by (simp_tac (simpset() addsimps [real_divide_def, real_0_le_mult_iff]) 1); |
|
67 |
by Auto_tac; |
|
68 |
qed "real_0_le_divide_iff"; |
|
69 |
Addsimps [inst "x" "number_of ?w" real_0_le_divide_iff]; |
|
70 |
||
71 |
Goal "(x/y <= (#0::real)) = ((x <= #0 | y <= #0) & (#0 <= x | #0 <= y))"; |
|
72 |
by (simp_tac (simpset() addsimps [real_divide_def, real_mult_le_0_iff]) 1); |
|
73 |
by Auto_tac; |
|
74 |
qed "real_divide_le_0_iff"; |
|
75 |
Addsimps [inst "x" "number_of ?w" real_divide_le_0_iff]; |
|
76 |
||
77 |
Goal "(inverse(x::real) = #0) = (x = #0)"; |
|
78 |
by (auto_tac (claset(), simpset() addsimps [rename_numerals INVERSE_ZERO])); |
|
79 |
by (rtac ccontr 1); |
|
80 |
by (blast_tac (claset() addDs [rename_numerals real_inverse_not_zero]) 1); |
|
81 |
qed "real_inverse_zero_iff"; |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
82 |
Addsimps [real_inverse_zero_iff]; |
10722 | 83 |
|
84 |
Goal "(x/y = #0) = (x=#0 | y=(#0::real))"; |
|
85 |
by (auto_tac (claset(), simpset() addsimps [real_divide_def])); |
|
86 |
qed "real_divide_eq_0_iff"; |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
87 |
Addsimps [real_divide_eq_0_iff]; |
10722 | 88 |
|
10778
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
89 |
Goal "h ~= (#0::real) ==> h/h = #1"; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
90 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_inv_left]) 1); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
91 |
qed "real_divide_self_eq"; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
92 |
Addsimps [real_divide_self_eq]; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
93 |
|
10722 | 94 |
|
95 |
(**** Factor cancellation theorems for "real" ****) |
|
96 |
||
97 |
(** Cancellation laws for k*m < k*n and m*k < n*k, also for <= and =, |
|
98 |
but not (yet?) for k*m < n*k. **) |
|
99 |
||
100 |
bind_thm ("real_mult_minus_right", real_minus_mult_eq2 RS sym); |
|
101 |
||
102 |
Goal "(-y < -x) = ((x::real) < y)"; |
|
103 |
by (arith_tac 1); |
|
104 |
qed "real_minus_less_minus"; |
|
105 |
Addsimps [real_minus_less_minus]; |
|
106 |
||
107 |
Goal "[| i<j; k < (0::real) |] ==> j*k < i*k"; |
|
108 |
by (rtac (real_minus_less_minus RS iffD1) 1); |
|
109 |
by (auto_tac (claset(), |
|
110 |
simpset() delsimps [real_minus_mult_eq2 RS sym] |
|
111 |
addsimps [real_minus_mult_eq2])); |
|
112 |
qed "real_mult_less_mono1_neg"; |
|
113 |
||
114 |
Goal "[| i<j; k < (0::real) |] ==> k*j < k*i"; |
|
115 |
by (rtac (real_minus_less_minus RS iffD1) 1); |
|
116 |
by (auto_tac (claset(), |
|
117 |
simpset() delsimps [real_minus_mult_eq1 RS sym] |
|
118 |
addsimps [real_minus_mult_eq1]));; |
|
119 |
qed "real_mult_less_mono2_neg"; |
|
120 |
||
121 |
Goal "[| i <= j; (0::real) <= k |] ==> i*k <= j*k"; |
|
122 |
by (auto_tac (claset(), |
|
123 |
simpset() addsimps [order_le_less, real_mult_less_mono1])); |
|
124 |
qed "real_mult_le_mono1"; |
|
125 |
||
126 |
Goal "[| i <= j; k <= (0::real) |] ==> j*k <= i*k"; |
|
127 |
by (auto_tac (claset(), |
|
128 |
simpset() addsimps [order_le_less, real_mult_less_mono1_neg])); |
|
129 |
qed "real_mult_le_mono1_neg"; |
|
130 |
||
131 |
Goal "[| i <= j; (0::real) <= k |] ==> k*i <= k*j"; |
|
132 |
by (dtac real_mult_le_mono1 1); |
|
133 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [real_mult_commute]))); |
|
134 |
qed "real_mult_le_mono2"; |
|
135 |
||
136 |
Goal "[| i <= j; k <= (0::real) |] ==> k*j <= k*i"; |
|
137 |
by (dtac real_mult_le_mono1_neg 1); |
|
138 |
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [real_mult_commute]))); |
|
139 |
qed "real_mult_le_mono2_neg"; |
|
140 |
||
141 |
Goal "(m*k < n*k) = (((#0::real) < k & m<n) | (k < #0 & n<m))"; |
|
142 |
by (case_tac "k = (0::real)" 1); |
|
143 |
by (auto_tac (claset(), |
|
144 |
simpset() addsimps [linorder_neq_iff, |
|
145 |
real_mult_less_mono1, real_mult_less_mono1_neg])); |
|
146 |
by (auto_tac (claset(), |
|
147 |
simpset() addsimps [linorder_not_less, |
|
148 |
inst "y1" "m*k" (linorder_not_le RS sym), |
|
149 |
inst "y1" "m" (linorder_not_le RS sym)])); |
|
150 |
by (TRYALL (etac notE)); |
|
151 |
by (auto_tac (claset(), |
|
152 |
simpset() addsimps [order_less_imp_le, real_mult_le_mono1, |
|
153 |
real_mult_le_mono1_neg])); |
|
154 |
qed "real_mult_less_cancel2"; |
|
155 |
||
156 |
Goal "(m*k <= n*k) = (((#0::real) < k --> m<=n) & (k < #0 --> n<=m))"; |
|
157 |
by (simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
158 |
real_mult_less_cancel2]) 1); |
|
159 |
qed "real_mult_le_cancel2"; |
|
160 |
||
161 |
Goal "(k*m < k*n) = (((#0::real) < k & m<n) | (k < #0 & n<m))"; |
|
162 |
by (simp_tac (simpset() addsimps [inst "z" "k" real_mult_commute, |
|
163 |
real_mult_less_cancel2]) 1); |
|
164 |
qed "real_mult_less_cancel1"; |
|
165 |
||
166 |
Goal "!!k::real. (k*m <= k*n) = ((#0 < k --> m<=n) & (k < #0 --> n<=m))"; |
|
167 |
by (simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
168 |
real_mult_less_cancel1]) 1); |
|
169 |
qed "real_mult_le_cancel1"; |
|
170 |
||
171 |
Goal "!!k::real. (k*m = k*n) = (k = #0 | m=n)"; |
|
172 |
by (case_tac "k=0" 1); |
|
173 |
by (auto_tac (claset(), simpset() addsimps [real_mult_left_cancel])); |
|
174 |
qed "real_mult_eq_cancel1"; |
|
175 |
||
176 |
Goal "!!k::real. (m*k = n*k) = (k = #0 | m=n)"; |
|
177 |
by (case_tac "k=0" 1); |
|
178 |
by (auto_tac (claset(), simpset() addsimps [real_mult_right_cancel])); |
|
179 |
qed "real_mult_eq_cancel2"; |
|
180 |
||
181 |
Goal "!!k::real. k~=#0 ==> (k*m) / (k*n) = (m/n)"; |
|
182 |
by (asm_simp_tac |
|
183 |
(simpset() addsimps [real_divide_def, real_inverse_distrib]) 1); |
|
184 |
by (subgoal_tac "k * m * (inverse k * inverse n) = \ |
|
185 |
\ (k * inverse k) * (m * inverse n)" 1); |
|
186 |
by (asm_full_simp_tac (simpset() addsimps []) 1); |
|
187 |
by (asm_full_simp_tac (HOL_ss addsimps real_mult_ac) 1); |
|
188 |
qed "real_mult_div_cancel1"; |
|
189 |
||
190 |
(*For ExtractCommonTerm*) |
|
191 |
Goal "(k*m) / (k*n) = (if k = (#0::real) then #0 else m/n)"; |
|
192 |
by (simp_tac (simpset() addsimps [real_mult_div_cancel1]) 1); |
|
193 |
qed "real_mult_div_cancel_disj"; |
|
194 |
||
195 |
||
196 |
local |
|
197 |
open Real_Numeral_Simprocs |
|
198 |
in |
|
199 |
||
200 |
val rel_real_number_of = [eq_real_number_of, less_real_number_of, |
|
201 |
le_real_number_of_eq_not_less]; |
|
202 |
||
203 |
structure CancelNumeralFactorCommon = |
|
204 |
struct |
|
205 |
val mk_coeff = mk_coeff |
|
206 |
val dest_coeff = dest_coeff 1 |
|
207 |
val trans_tac = trans_tac |
|
208 |
val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_plus_1s)) |
|
209 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps)) |
|
210 |
THEN ALLGOALS |
|
211 |
(simp_tac |
|
212 |
(HOL_ss addsimps [eq_real_number_of, mult_real_number_of, |
|
213 |
real_mult_number_of_left]@ |
|
214 |
real_minus_from_mult_simps @ real_mult_ac)) |
|
215 |
val numeral_simp_tac = |
|
216 |
ALLGOALS (simp_tac (HOL_ss addsimps rel_real_number_of@bin_simps)) |
|
217 |
val simplify_meta_eq = simplify_meta_eq |
|
218 |
end |
|
219 |
||
220 |
structure DivCancelNumeralFactor = CancelNumeralFactorFun |
|
221 |
(open CancelNumeralFactorCommon |
|
222 |
val prove_conv = prove_conv "realdiv_cancel_numeral_factor" |
|
223 |
val mk_bal = HOLogic.mk_binop "HOL.divide" |
|
224 |
val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT |
|
225 |
val cancel = real_mult_div_cancel1 RS trans |
|
226 |
val neg_exchanges = false |
|
227 |
) |
|
228 |
||
229 |
structure EqCancelNumeralFactor = CancelNumeralFactorFun |
|
230 |
(open CancelNumeralFactorCommon |
|
231 |
val prove_conv = prove_conv "realeq_cancel_numeral_factor" |
|
232 |
val mk_bal = HOLogic.mk_eq |
|
233 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
|
234 |
val cancel = real_mult_eq_cancel1 RS trans |
|
235 |
val neg_exchanges = false |
|
236 |
) |
|
237 |
||
238 |
structure LessCancelNumeralFactor = CancelNumeralFactorFun |
|
239 |
(open CancelNumeralFactorCommon |
|
240 |
val prove_conv = prove_conv "realless_cancel_numeral_factor" |
|
241 |
val mk_bal = HOLogic.mk_binrel "op <" |
|
242 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT |
|
243 |
val cancel = real_mult_less_cancel1 RS trans |
|
244 |
val neg_exchanges = true |
|
245 |
) |
|
246 |
||
247 |
structure LeCancelNumeralFactor = CancelNumeralFactorFun |
|
248 |
(open CancelNumeralFactorCommon |
|
249 |
val prove_conv = prove_conv "realle_cancel_numeral_factor" |
|
250 |
val mk_bal = HOLogic.mk_binrel "op <=" |
|
251 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT |
|
252 |
val cancel = real_mult_le_cancel1 RS trans |
|
253 |
val neg_exchanges = true |
|
254 |
) |
|
255 |
||
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
256 |
val real_cancel_numeral_factors_relations = |
10722 | 257 |
map prep_simproc |
258 |
[("realeq_cancel_numeral_factor", |
|
259 |
prep_pats ["(l::real) * m = n", "(l::real) = m * n"], |
|
260 |
EqCancelNumeralFactor.proc), |
|
261 |
("realless_cancel_numeral_factor", |
|
262 |
prep_pats ["(l::real) * m < n", "(l::real) < m * n"], |
|
263 |
LessCancelNumeralFactor.proc), |
|
264 |
("realle_cancel_numeral_factor", |
|
265 |
prep_pats ["(l::real) * m <= n", "(l::real) <= m * n"], |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
266 |
LeCancelNumeralFactor.proc)]; |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
267 |
|
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
268 |
val real_cancel_numeral_factors_divide = prep_simproc |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
269 |
("realdiv_cancel_numeral_factor", |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
270 |
prep_pats ["((l::real) * m) / n", "(l::real) / (m * n)"], |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
271 |
DivCancelNumeralFactor.proc); |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
272 |
|
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
273 |
val real_cancel_numeral_factors = |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
274 |
real_cancel_numeral_factors_relations @ |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
275 |
[real_cancel_numeral_factors_divide]; |
10722 | 276 |
|
277 |
end; |
|
278 |
||
279 |
Addsimprocs real_cancel_numeral_factors; |
|
280 |
||
281 |
||
282 |
(*examples: |
|
283 |
print_depth 22; |
|
284 |
set timing; |
|
285 |
set trace_simp; |
|
286 |
fun test s = (Goal s; by (Simp_tac 1)); |
|
287 |
||
288 |
test "#0 <= (y::real) * #-2"; |
|
289 |
test "#9*x = #12 * (y::real)"; |
|
290 |
test "(#9*x) / (#12 * (y::real)) = z"; |
|
291 |
test "#9*x < #12 * (y::real)"; |
|
292 |
test "#9*x <= #12 * (y::real)"; |
|
293 |
||
294 |
test "#-99*x = #132 * (y::real)"; |
|
295 |
test "(#-99*x) / (#132 * (y::real)) = z"; |
|
296 |
test "#-99*x < #132 * (y::real)"; |
|
297 |
test "#-99*x <= #132 * (y::real)"; |
|
298 |
||
299 |
test "#999*x = #-396 * (y::real)"; |
|
300 |
test "(#999*x) / (#-396 * (y::real)) = z"; |
|
301 |
test "#999*x < #-396 * (y::real)"; |
|
302 |
test "#999*x <= #-396 * (y::real)"; |
|
303 |
||
304 |
test "#-99*x = #-81 * (y::real)"; |
|
305 |
test "(#-99*x) / (#-81 * (y::real)) = z"; |
|
306 |
test "#-99*x <= #-81 * (y::real)"; |
|
307 |
test "#-99*x < #-81 * (y::real)"; |
|
308 |
||
309 |
test "#-2 * x = #-1 * (y::real)"; |
|
310 |
test "#-2 * x = -(y::real)"; |
|
311 |
test "(#-2 * x) / (#-1 * (y::real)) = z"; |
|
312 |
test "#-2 * x < -(y::real)"; |
|
313 |
test "#-2 * x <= #-1 * (y::real)"; |
|
314 |
test "-x < #-23 * (y::real)"; |
|
315 |
test "-x <= #-23 * (y::real)"; |
|
316 |
*) |
|
317 |
||
318 |
||
319 |
(** Declarations for ExtractCommonTerm **) |
|
320 |
||
321 |
local |
|
322 |
open Real_Numeral_Simprocs |
|
323 |
in |
|
324 |
||
325 |
structure CancelFactorCommon = |
|
326 |
struct |
|
327 |
val mk_sum = long_mk_prod |
|
328 |
val dest_sum = dest_prod |
|
329 |
val mk_coeff = mk_coeff |
|
330 |
val dest_coeff = dest_coeff |
|
331 |
val find_first = find_first [] |
|
332 |
val trans_tac = trans_tac |
|
333 |
val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@real_mult_ac)) |
|
334 |
end; |
|
335 |
||
336 |
structure EqCancelFactor = ExtractCommonTermFun |
|
337 |
(open CancelFactorCommon |
|
338 |
val prove_conv = prove_conv "real_eq_cancel_factor" |
|
339 |
val mk_bal = HOLogic.mk_eq |
|
340 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
|
341 |
val simplify_meta_eq = cancel_simplify_meta_eq real_mult_eq_cancel1 |
|
342 |
); |
|
343 |
||
344 |
||
345 |
structure DivideCancelFactor = ExtractCommonTermFun |
|
346 |
(open CancelFactorCommon |
|
347 |
val prove_conv = prove_conv "real_divide_cancel_factor" |
|
348 |
val mk_bal = HOLogic.mk_binop "HOL.divide" |
|
349 |
val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT |
|
350 |
val simplify_meta_eq = cancel_simplify_meta_eq real_mult_div_cancel_disj |
|
351 |
); |
|
352 |
||
353 |
val real_cancel_factor = |
|
354 |
map prep_simproc |
|
355 |
[("real_eq_cancel_factor", |
|
356 |
prep_pats ["(l::real) * m = n", "(l::real) = m * n"], |
|
357 |
EqCancelFactor.proc), |
|
358 |
("real_divide_cancel_factor", |
|
359 |
prep_pats ["((l::real) * m) / n", "(l::real) / (m * n)"], |
|
360 |
DivideCancelFactor.proc)]; |
|
361 |
||
362 |
end; |
|
363 |
||
364 |
Addsimprocs real_cancel_factor; |
|
365 |
||
366 |
||
367 |
(*examples: |
|
368 |
print_depth 22; |
|
369 |
set timing; |
|
370 |
set trace_simp; |
|
371 |
fun test s = (Goal s; by (Asm_simp_tac 1)); |
|
372 |
||
373 |
test "x*k = k*(y::real)"; |
|
374 |
test "k = k*(y::real)"; |
|
375 |
test "a*(b*c) = (b::real)"; |
|
376 |
test "a*(b*c) = d*(b::real)*(x*a)"; |
|
377 |
||
378 |
||
379 |
test "(x*k) / (k*(y::real)) = (uu::real)"; |
|
380 |
test "(k) / (k*(y::real)) = (uu::real)"; |
|
381 |
test "(a*(b*c)) / ((b::real)) = (uu::real)"; |
|
382 |
test "(a*(b*c)) / (d*(b::real)*(x*a)) = (uu::real)"; |
|
383 |
||
384 |
(*FIXME: what do we do about this?*) |
|
385 |
test "a*(b*c)/(y*z) = d*(b::real)*(x*a)/z"; |
|
386 |
*) |
|
387 |
||
388 |
||
389 |
(*** Simplification of inequalities involving literal divisors ***) |
|
390 |
||
391 |
Goal "#0<z ==> ((x::real) <= y/z) = (x*z <= y)"; |
|
392 |
by (subgoal_tac "(x*z <= y) = (x*z <= (y/z)*z)" 1); |
|
393 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
394 |
by (etac ssubst 1); |
|
395 |
by (stac real_mult_le_cancel2 1); |
|
396 |
by (Asm_simp_tac 1); |
|
397 |
qed "pos_real_le_divide_eq"; |
|
398 |
Addsimps [inst "z" "number_of ?w" pos_real_le_divide_eq]; |
|
399 |
||
400 |
Goal "z<#0 ==> ((x::real) <= y/z) = (y <= x*z)"; |
|
401 |
by (subgoal_tac "(y <= x*z) = ((y/z)*z <= x*z)" 1); |
|
402 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
403 |
by (etac ssubst 1); |
|
404 |
by (stac real_mult_le_cancel2 1); |
|
405 |
by (Asm_simp_tac 1); |
|
406 |
qed "neg_real_le_divide_eq"; |
|
407 |
Addsimps [inst "z" "number_of ?w" neg_real_le_divide_eq]; |
|
408 |
||
409 |
Goal "#0<z ==> (y/z <= (x::real)) = (y <= x*z)"; |
|
410 |
by (subgoal_tac "(y <= x*z) = ((y/z)*z <= x*z)" 1); |
|
411 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
412 |
by (etac ssubst 1); |
|
413 |
by (stac real_mult_le_cancel2 1); |
|
414 |
by (Asm_simp_tac 1); |
|
415 |
qed "pos_real_divide_le_eq"; |
|
416 |
Addsimps [inst "z" "number_of ?w" pos_real_divide_le_eq]; |
|
417 |
||
418 |
Goal "z<#0 ==> (y/z <= (x::real)) = (x*z <= y)"; |
|
419 |
by (subgoal_tac "(x*z <= y) = (x*z <= (y/z)*z)" 1); |
|
420 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
421 |
by (etac ssubst 1); |
|
422 |
by (stac real_mult_le_cancel2 1); |
|
423 |
by (Asm_simp_tac 1); |
|
424 |
qed "neg_real_divide_le_eq"; |
|
425 |
Addsimps [inst "z" "number_of ?w" neg_real_divide_le_eq]; |
|
426 |
||
427 |
Goal "#0<z ==> ((x::real) < y/z) = (x*z < y)"; |
|
428 |
by (subgoal_tac "(x*z < y) = (x*z < (y/z)*z)" 1); |
|
429 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
430 |
by (etac ssubst 1); |
|
431 |
by (stac real_mult_less_cancel2 1); |
|
432 |
by (Asm_simp_tac 1); |
|
433 |
qed "pos_real_less_divide_eq"; |
|
434 |
Addsimps [inst "z" "number_of ?w" pos_real_less_divide_eq]; |
|
435 |
||
436 |
Goal "z<#0 ==> ((x::real) < y/z) = (y < x*z)"; |
|
437 |
by (subgoal_tac "(y < x*z) = ((y/z)*z < x*z)" 1); |
|
438 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
439 |
by (etac ssubst 1); |
|
440 |
by (stac real_mult_less_cancel2 1); |
|
441 |
by (Asm_simp_tac 1); |
|
442 |
qed "neg_real_less_divide_eq"; |
|
443 |
Addsimps [inst "z" "number_of ?w" neg_real_less_divide_eq]; |
|
444 |
||
445 |
Goal "#0<z ==> (y/z < (x::real)) = (y < x*z)"; |
|
446 |
by (subgoal_tac "(y < x*z) = ((y/z)*z < x*z)" 1); |
|
447 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
448 |
by (etac ssubst 1); |
|
449 |
by (stac real_mult_less_cancel2 1); |
|
450 |
by (Asm_simp_tac 1); |
|
451 |
qed "pos_real_divide_less_eq"; |
|
452 |
Addsimps [inst "z" "number_of ?w" pos_real_divide_less_eq]; |
|
453 |
||
454 |
Goal "z<#0 ==> (y/z < (x::real)) = (x*z < y)"; |
|
455 |
by (subgoal_tac "(x*z < y) = (x*z < (y/z)*z)" 1); |
|
456 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
457 |
by (etac ssubst 1); |
|
458 |
by (stac real_mult_less_cancel2 1); |
|
459 |
by (Asm_simp_tac 1); |
|
460 |
qed "neg_real_divide_less_eq"; |
|
461 |
Addsimps [inst "z" "number_of ?w" neg_real_divide_less_eq]; |
|
462 |
||
463 |
Goal "z~=#0 ==> ((x::real) = y/z) = (x*z = y)"; |
|
464 |
by (subgoal_tac "(x*z = y) = (x*z = (y/z)*z)" 1); |
|
465 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
466 |
by (etac ssubst 1); |
|
467 |
by (stac real_mult_eq_cancel2 1); |
|
468 |
by (Asm_simp_tac 1); |
|
469 |
qed "real_eq_divide_eq"; |
|
470 |
Addsimps [inst "z" "number_of ?w" real_eq_divide_eq]; |
|
471 |
||
472 |
Goal "z~=#0 ==> (y/z = (x::real)) = (y = x*z)"; |
|
473 |
by (subgoal_tac "(y = x*z) = ((y/z)*z = x*z)" 1); |
|
474 |
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2); |
|
475 |
by (etac ssubst 1); |
|
476 |
by (stac real_mult_eq_cancel2 1); |
|
477 |
by (Asm_simp_tac 1); |
|
478 |
qed "real_divide_eq_eq"; |
|
479 |
Addsimps [inst "z" "number_of ?w" real_divide_eq_eq]; |
|
480 |
||
481 |
Goal "(m/k = n/k) = (k = #0 | m = (n::real))"; |
|
482 |
by (case_tac "k=#0" 1); |
|
483 |
by (asm_simp_tac (simpset() addsimps [REAL_DIVIDE_ZERO]) 1); |
|
484 |
by (asm_simp_tac (simpset() addsimps [real_divide_eq_eq, real_eq_divide_eq, |
|
485 |
real_mult_eq_cancel2]) 1); |
|
486 |
qed "real_divide_eq_cancel2"; |
|
487 |
||
488 |
Goal "(k/m = k/n) = (k = #0 | m = (n::real))"; |
|
489 |
by (case_tac "m=#0 | n = #0" 1); |
|
490 |
by (auto_tac (claset(), |
|
491 |
simpset() addsimps [REAL_DIVIDE_ZERO, real_divide_eq_eq, |
|
492 |
real_eq_divide_eq, real_mult_eq_cancel1])); |
|
493 |
qed "real_divide_eq_cancel1"; |
|
494 |
||
495 |
(*Moved from RealOrd.ML to use #0 *) |
|
496 |
Goal "[| #0 < r; #0 < x|] ==> (inverse x < inverse (r::real)) = (r < x)"; |
|
497 |
by (auto_tac (claset() addIs [real_inverse_less_swap], simpset())); |
|
498 |
by (res_inst_tac [("t","r")] (real_inverse_inverse RS subst) 1); |
|
499 |
by (res_inst_tac [("t","x")] (real_inverse_inverse RS subst) 1); |
|
500 |
by (auto_tac (claset() addIs [real_inverse_less_swap], |
|
501 |
simpset() delsimps [real_inverse_inverse] |
|
502 |
addsimps [real_inverse_gt_zero])); |
|
503 |
qed "real_inverse_less_iff"; |
|
504 |
||
505 |
Goal "[| #0 < r; #0 < x|] ==> (inverse x <= inverse r) = (r <= (x::real))"; |
|
506 |
by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym, |
|
507 |
real_inverse_less_iff]) 1); |
|
508 |
qed "real_inverse_le_iff"; |
|
509 |
||
510 |
(** Division by 1, -1 **) |
|
511 |
||
512 |
Goal "(x::real)/#1 = x"; |
|
513 |
by (simp_tac (simpset() addsimps [real_divide_def]) 1); |
|
514 |
qed "real_divide_1"; |
|
515 |
Addsimps [real_divide_1]; |
|
516 |
||
517 |
Goal "x/#-1 = -(x::real)"; |
|
518 |
by (Simp_tac 1); |
|
519 |
qed "real_divide_minus1"; |
|
520 |
Addsimps [real_divide_minus1]; |
|
521 |
||
522 |
Goal "#-1/(x::real) = - (#1/x)"; |
|
523 |
by (simp_tac (simpset() addsimps [real_divide_def, real_minus_inverse]) 1); |
|
524 |
qed "real_minus1_divide"; |
|
525 |
Addsimps [real_minus1_divide]; |
|
526 |
||
527 |
Goal "[| (#0::real) < d1; #0 < d2 |] ==> EX e. #0 < e & e < d1 & e < d2"; |
|
528 |
by (res_inst_tac [("x","(min d1 d2)/#2")] exI 1); |
|
529 |
by (asm_simp_tac (simpset() addsimps [min_def]) 1); |
|
530 |
qed "real_lbound_gt_zero"; |
|
531 |
||
10778
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
532 |
Goal "(inverse x = inverse y) = (x = (y::real))"; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
533 |
by (case_tac "x=#0 | y=#0" 1); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
534 |
by (auto_tac (claset(), |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
535 |
simpset() addsimps [real_inverse_eq_divide, |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
536 |
rename_numerals DIVISION_BY_ZERO])); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
537 |
by (dres_inst_tac [("f","%u. x*y*u")] arg_cong 1); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
538 |
by (Asm_full_simp_tac 1); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
539 |
qed "real_inverse_eq_iff"; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
540 |
Addsimps [real_inverse_eq_iff]; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
541 |
|
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
542 |
Goal "(z/x = z/y) = (z = #0 | x = (y::real))"; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
543 |
by (case_tac "x=#0 | y=#0" 1); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
544 |
by (auto_tac (claset(), |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
545 |
simpset() addsimps [rename_numerals DIVISION_BY_ZERO])); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
546 |
by (dres_inst_tac [("f","%u. x*y*u")] arg_cong 1); |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
547 |
by Auto_tac; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
548 |
qed "real_divide_eq_iff"; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
549 |
Addsimps [real_divide_eq_iff]; |
2c6605049646
more tidying, especially to remove real_of_posnat
paulson
parents:
10752
diff
changeset
|
550 |
|
10722 | 551 |
|
552 |
(*** General rewrites to improve automation, like those for type "int" ***) |
|
553 |
||
554 |
(** The next several equations can make the simplifier loop! **) |
|
555 |
||
556 |
Goal "(x < - y) = (y < - (x::real))"; |
|
557 |
by Auto_tac; |
|
558 |
qed "real_less_minus"; |
|
559 |
||
560 |
Goal "(- x < y) = (- y < (x::real))"; |
|
561 |
by Auto_tac; |
|
562 |
qed "real_minus_less"; |
|
563 |
||
564 |
Goal "(x <= - y) = (y <= - (x::real))"; |
|
565 |
by Auto_tac; |
|
566 |
qed "real_le_minus"; |
|
567 |
||
568 |
Goal "(- x <= y) = (- y <= (x::real))"; |
|
569 |
by Auto_tac; |
|
570 |
qed "real_minus_le"; |
|
571 |
||
572 |
Goal "(x = - y) = (y = - (x::real))"; |
|
573 |
by Auto_tac; |
|
574 |
qed "real_equation_minus"; |
|
575 |
||
576 |
Goal "(- x = y) = (- (y::real) = x)"; |
|
577 |
by Auto_tac; |
|
578 |
qed "real_minus_equation"; |
|
579 |
||
580 |
||
581 |
Goal "(x + - a = (#0::real)) = (x=a)"; |
|
582 |
by (arith_tac 1); |
|
583 |
qed "real_add_minus_iff"; |
|
584 |
Addsimps [real_add_minus_iff]; |
|
585 |
||
586 |
Goal "(-b = -a) = (b = (a::real))"; |
|
587 |
by (arith_tac 1); |
|
588 |
qed "real_minus_eq_cancel"; |
|
589 |
Addsimps [real_minus_eq_cancel]; |
|
590 |
||
591 |
||
592 |
(*Distributive laws for literals*) |
|
593 |
Addsimps (map (inst "w" "number_of ?v") |
|
594 |
[real_add_mult_distrib, real_add_mult_distrib2, |
|
595 |
real_diff_mult_distrib, real_diff_mult_distrib2]); |
|
596 |
||
597 |
Addsimps (map (inst "x" "number_of ?v") |
|
598 |
[real_less_minus, real_le_minus, real_equation_minus]); |
|
599 |
Addsimps (map (inst "y" "number_of ?v") |
|
600 |
[real_minus_less, real_minus_le, real_minus_equation]); |
|
601 |
||
602 |
||
603 |
(*** Simprules combining x+y and #0 ***) |
|
604 |
||
605 |
Goal "(x+y = (#0::real)) = (y = -x)"; |
|
606 |
by Auto_tac; |
|
607 |
qed "real_add_eq_0_iff"; |
|
608 |
AddIffs [real_add_eq_0_iff]; |
|
609 |
||
610 |
Goal "(x+y < (#0::real)) = (y < -x)"; |
|
611 |
by Auto_tac; |
|
612 |
qed "real_add_less_0_iff"; |
|
613 |
AddIffs [real_add_less_0_iff]; |
|
614 |
||
615 |
Goal "((#0::real) < x+y) = (-x < y)"; |
|
616 |
by Auto_tac; |
|
617 |
qed "real_0_less_add_iff"; |
|
618 |
AddIffs [real_0_less_add_iff]; |
|
619 |
||
620 |
Goal "(x+y <= (#0::real)) = (y <= -x)"; |
|
621 |
by Auto_tac; |
|
622 |
qed "real_add_le_0_iff"; |
|
623 |
AddIffs [real_add_le_0_iff]; |
|
624 |
||
625 |
Goal "((#0::real) <= x+y) = (-x <= y)"; |
|
626 |
by Auto_tac; |
|
627 |
qed "real_0_le_add_iff"; |
|
628 |
AddIffs [real_0_le_add_iff]; |
|
629 |
||
630 |
||
631 |
(** Simprules combining x-y and #0; see also real_less_iff_diff_less_0, etc., |
|
632 |
in RealBin |
|
633 |
**) |
|
634 |
||
635 |
Goal "((#0::real) < x-y) = (y < x)"; |
|
636 |
by Auto_tac; |
|
637 |
qed "real_0_less_diff_iff"; |
|
638 |
AddIffs [real_0_less_diff_iff]; |
|
639 |
||
640 |
Goal "((#0::real) <= x-y) = (y <= x)"; |
|
641 |
by Auto_tac; |
|
642 |
qed "real_0_le_diff_iff"; |
|
643 |
AddIffs [real_0_le_diff_iff]; |
|
644 |
||
645 |
(* |
|
10752
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
646 |
FIXME: we should have this, as for type int, but many proofs would break. |
c4f1bf2acf4c
tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents:
10722
diff
changeset
|
647 |
It replaces x+-y by x-y. |
10722 | 648 |
Addsimps [symmetric real_diff_def]; |
649 |
*) |
|
650 |
||
651 |
Goal "-(x-y) = y - (x::real)"; |
|
652 |
by (arith_tac 1); |
|
653 |
qed "real_minus_diff_eq"; |
|
654 |
Addsimps [real_minus_diff_eq]; |
|
655 |
||
656 |
||
657 |
(*** Density of the Reals ***) |
|
658 |
||
659 |
Goal "x < y ==> x < (x+y) / (#2::real)"; |
|
660 |
by Auto_tac; |
|
661 |
qed "real_less_half_sum"; |
|
662 |
||
663 |
Goal "x < y ==> (x+y)/(#2::real) < y"; |
|
664 |
by Auto_tac; |
|
665 |
qed "real_gt_half_sum"; |
|
666 |
||
667 |
Goal "x < y ==> EX r::real. x < r & r < y"; |
|
668 |
by (blast_tac (claset() addSIs [real_less_half_sum, real_gt_half_sum]) 1); |
|
669 |
qed "real_dense"; |
|
670 |
||
671 |
||
672 |
(*Replaces "inverse #nn" by #1/#nn *) |
|
673 |
Addsimps [inst "x" "number_of ?w" real_inverse_eq_divide]; |
|
674 |
||
675 |