author | paulson |
Fri, 12 Dec 2003 15:05:18 +0100 | |
changeset 14293 | 22542982bffd |
parent 14289 | deb8e1e62002 |
child 14305 | f17ca9f6dc8c |
permissions | -rw-r--r-- |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: HOL/Real/real_arith.ML |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
2 |
ID: $Id$ |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
3 |
Author: Tobias Nipkow, TU Muenchen |
14289 | 4 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
5 |
|
14289 | 6 |
Simprocs: Common factor cancellation & Rational coefficient handling |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
7 |
*) |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
8 |
|
14289 | 9 |
|
10 |
(** Misc ML bindings **) |
|
11 |
||
12 |
val real_inverse_less_iff = thm"real_inverse_less_iff"; |
|
13 |
val real_inverse_le_iff = thm"real_inverse_le_iff"; |
|
14 |
||
15 |
val pos_real_less_divide_eq = thm"pos_less_divide_eq"; |
|
16 |
val pos_real_divide_less_eq = thm"pos_divide_less_eq"; |
|
17 |
val pos_real_le_divide_eq = thm"pos_le_divide_eq"; |
|
18 |
val pos_real_divide_le_eq = thm"pos_divide_le_eq"; |
|
19 |
||
20 |
||
21 |
(****Common factor cancellation****) |
|
22 |
||
14293 | 23 |
(*To quote from Provers/Arith/cancel_numeral_factor.ML: |
24 |
||
25 |
This simproc Cancels common coefficients in balanced expressions: |
|
26 |
||
27 |
u*#m ~~ u'*#m' == #n*u ~~ #n'*u' |
|
28 |
||
29 |
where ~~ is an appropriate balancing operation (e.g. =, <=, <, div, /) |
|
30 |
and d = gcd(m,m') and n=m/d and n'=m'/d. |
|
31 |
*) |
|
32 |
||
14289 | 33 |
val real_inverse_eq_divide = thm"real_inverse_eq_divide"; |
34 |
val real_mult_less_cancel2 = thm"real_mult_less_cancel2"; |
|
35 |
val real_mult_le_cancel2 = thm"real_mult_le_cancel2"; |
|
36 |
val real_mult_less_cancel1 = thm"real_mult_less_cancel1"; |
|
37 |
val real_mult_le_cancel1 = thm"real_mult_le_cancel1"; |
|
38 |
val real_mult_eq_cancel1 = thm"real_mult_eq_cancel1"; |
|
39 |
val real_mult_eq_cancel2 = thm"real_mult_eq_cancel2"; |
|
40 |
val real_mult_div_cancel1 = thm"real_mult_div_cancel1"; |
|
41 |
val real_mult_div_cancel_disj = thm"real_mult_div_cancel_disj"; |
|
42 |
||
14288 | 43 |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
44 |
local |
14289 | 45 |
open Real_Numeral_Simprocs |
46 |
in |
|
47 |
||
48 |
val rel_real_number_of = [eq_real_number_of, less_real_number_of, |
|
49 |
le_real_number_of_eq_not_less] |
|
50 |
||
51 |
structure CancelNumeralFactorCommon = |
|
52 |
struct |
|
53 |
val mk_coeff = mk_coeff |
|
54 |
val dest_coeff = dest_coeff 1 |
|
55 |
val trans_tac = trans_tac |
|
56 |
val norm_tac = |
|
57 |
ALLGOALS (simp_tac (HOL_ss addsimps real_minus_from_mult_simps @ mult_1s)) |
|
58 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps)) |
|
59 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps real_mult_ac)) |
|
60 |
val numeral_simp_tac = |
|
61 |
ALLGOALS (simp_tac (HOL_ss addsimps rel_real_number_of@bin_simps)) |
|
62 |
val simplify_meta_eq = simplify_meta_eq |
|
63 |
end |
|
64 |
||
65 |
structure DivCancelNumeralFactor = CancelNumeralFactorFun |
|
66 |
(open CancelNumeralFactorCommon |
|
67 |
val prove_conv = Bin_Simprocs.prove_conv |
|
68 |
val mk_bal = HOLogic.mk_binop "HOL.divide" |
|
69 |
val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT |
|
70 |
val cancel = real_mult_div_cancel1 RS trans |
|
71 |
val neg_exchanges = false |
|
72 |
) |
|
73 |
||
74 |
structure EqCancelNumeralFactor = CancelNumeralFactorFun |
|
75 |
(open CancelNumeralFactorCommon |
|
76 |
val prove_conv = Bin_Simprocs.prove_conv |
|
77 |
val mk_bal = HOLogic.mk_eq |
|
78 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
|
79 |
val cancel = real_mult_eq_cancel1 RS trans |
|
80 |
val neg_exchanges = false |
|
81 |
) |
|
82 |
||
83 |
structure LessCancelNumeralFactor = CancelNumeralFactorFun |
|
84 |
(open CancelNumeralFactorCommon |
|
85 |
val prove_conv = Bin_Simprocs.prove_conv |
|
86 |
val mk_bal = HOLogic.mk_binrel "op <" |
|
87 |
val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT |
|
88 |
val cancel = real_mult_less_cancel1 RS trans |
|
89 |
val neg_exchanges = true |
|
90 |
) |
|
91 |
||
92 |
structure LeCancelNumeralFactor = CancelNumeralFactorFun |
|
93 |
(open CancelNumeralFactorCommon |
|
94 |
val prove_conv = Bin_Simprocs.prove_conv |
|
95 |
val mk_bal = HOLogic.mk_binrel "op <=" |
|
96 |
val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT |
|
97 |
val cancel = real_mult_le_cancel1 RS trans |
|
98 |
val neg_exchanges = true |
|
99 |
) |
|
100 |
||
101 |
val real_cancel_numeral_factors_relations = |
|
102 |
map prep_simproc |
|
103 |
[("realeq_cancel_numeral_factor", |
|
104 |
["(l::real) * m = n", "(l::real) = m * n"], |
|
105 |
EqCancelNumeralFactor.proc), |
|
106 |
("realless_cancel_numeral_factor", |
|
107 |
["(l::real) * m < n", "(l::real) < m * n"], |
|
108 |
LessCancelNumeralFactor.proc), |
|
109 |
("realle_cancel_numeral_factor", |
|
110 |
["(l::real) * m <= n", "(l::real) <= m * n"], |
|
111 |
LeCancelNumeralFactor.proc)] |
|
112 |
||
113 |
val real_cancel_numeral_factors_divide = prep_simproc |
|
114 |
("realdiv_cancel_numeral_factor", |
|
115 |
["((l::real) * m) / n", "(l::real) / (m * n)", |
|
116 |
"((number_of v)::real) / (number_of w)"], |
|
117 |
DivCancelNumeralFactor.proc) |
|
118 |
||
119 |
val real_cancel_numeral_factors = |
|
120 |
real_cancel_numeral_factors_relations @ |
|
121 |
[real_cancel_numeral_factors_divide] |
|
122 |
||
123 |
end; |
|
124 |
||
125 |
Addsimprocs real_cancel_numeral_factors; |
|
126 |
||
127 |
||
128 |
(*examples: |
|
129 |
print_depth 22; |
|
130 |
set timing; |
|
131 |
set trace_simp; |
|
132 |
fun test s = (Goal s; by (Simp_tac 1)); |
|
133 |
||
134 |
test "0 <= (y::real) * -2"; |
|
135 |
test "9*x = 12 * (y::real)"; |
|
136 |
test "(9*x) / (12 * (y::real)) = z"; |
|
137 |
test "9*x < 12 * (y::real)"; |
|
138 |
test "9*x <= 12 * (y::real)"; |
|
139 |
||
140 |
test "-99*x = 132 * (y::real)"; |
|
141 |
test "(-99*x) / (132 * (y::real)) = z"; |
|
142 |
test "-99*x < 132 * (y::real)"; |
|
143 |
test "-99*x <= 132 * (y::real)"; |
|
144 |
||
145 |
test "999*x = -396 * (y::real)"; |
|
146 |
test "(999*x) / (-396 * (y::real)) = z"; |
|
147 |
test "999*x < -396 * (y::real)"; |
|
148 |
test "999*x <= -396 * (y::real)"; |
|
149 |
||
150 |
test "(- ((2::real) * x) <= 2 * y)"; |
|
151 |
test "-99*x = -81 * (y::real)"; |
|
152 |
test "(-99*x) / (-81 * (y::real)) = z"; |
|
153 |
test "-99*x <= -81 * (y::real)"; |
|
154 |
test "-99*x < -81 * (y::real)"; |
|
155 |
||
156 |
test "-2 * x = -1 * (y::real)"; |
|
157 |
test "-2 * x = -(y::real)"; |
|
158 |
test "(-2 * x) / (-1 * (y::real)) = z"; |
|
159 |
test "-2 * x < -(y::real)"; |
|
160 |
test "-2 * x <= -1 * (y::real)"; |
|
161 |
test "-x < -23 * (y::real)"; |
|
162 |
test "-x <= -23 * (y::real)"; |
|
163 |
*) |
|
164 |
||
165 |
||
166 |
(** Declarations for ExtractCommonTerm **) |
|
167 |
||
168 |
local |
|
169 |
open Real_Numeral_Simprocs |
|
170 |
in |
|
171 |
||
172 |
structure CancelFactorCommon = |
|
173 |
struct |
|
174 |
val mk_sum = long_mk_prod |
|
175 |
val dest_sum = dest_prod |
|
176 |
val mk_coeff = mk_coeff |
|
177 |
val dest_coeff = dest_coeff |
|
178 |
val find_first = find_first [] |
|
179 |
val trans_tac = trans_tac |
|
180 |
val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@real_mult_ac)) |
|
181 |
end; |
|
182 |
||
183 |
structure EqCancelFactor = ExtractCommonTermFun |
|
184 |
(open CancelFactorCommon |
|
185 |
val prove_conv = Bin_Simprocs.prove_conv |
|
186 |
val mk_bal = HOLogic.mk_eq |
|
187 |
val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT |
|
188 |
val simplify_meta_eq = cancel_simplify_meta_eq real_mult_eq_cancel1 |
|
189 |
); |
|
190 |
||
191 |
||
192 |
structure DivideCancelFactor = ExtractCommonTermFun |
|
193 |
(open CancelFactorCommon |
|
194 |
val prove_conv = Bin_Simprocs.prove_conv |
|
195 |
val mk_bal = HOLogic.mk_binop "HOL.divide" |
|
196 |
val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT |
|
197 |
val simplify_meta_eq = cancel_simplify_meta_eq real_mult_div_cancel_disj |
|
198 |
); |
|
199 |
||
200 |
val real_cancel_factor = |
|
201 |
map prep_simproc |
|
202 |
[("real_eq_cancel_factor", ["(l::real) * m = n", "(l::real) = m * n"], EqCancelFactor.proc), |
|
203 |
("real_divide_cancel_factor", ["((l::real) * m) / n", "(l::real) / (m * n)"], |
|
204 |
DivideCancelFactor.proc)]; |
|
205 |
||
206 |
end; |
|
207 |
||
208 |
Addsimprocs real_cancel_factor; |
|
209 |
||
210 |
||
211 |
(*examples: |
|
212 |
print_depth 22; |
|
213 |
set timing; |
|
214 |
set trace_simp; |
|
215 |
fun test s = (Goal s; by (Asm_simp_tac 1)); |
|
216 |
||
217 |
test "x*k = k*(y::real)"; |
|
218 |
test "k = k*(y::real)"; |
|
219 |
test "a*(b*c) = (b::real)"; |
|
220 |
test "a*(b*c) = d*(b::real)*(x*a)"; |
|
221 |
||
222 |
||
223 |
test "(x*k) / (k*(y::real)) = (uu::real)"; |
|
224 |
test "(k) / (k*(y::real)) = (uu::real)"; |
|
225 |
test "(a*(b*c)) / ((b::real)) = (uu::real)"; |
|
226 |
test "(a*(b*c)) / (d*(b::real)*(x*a)) = (uu::real)"; |
|
227 |
||
228 |
(*FIXME: what do we do about this?*) |
|
229 |
test "a*(b*c)/(y*z) = d*(b::real)*(x*a)/z"; |
|
230 |
*) |
|
231 |
||
232 |
(****Augmentation of real linear arithmetic with |
|
233 |
rational coefficient handling****) |
|
234 |
||
235 |
val divide_1 = thm"divide_1"; |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
236 |
|
14288 | 237 |
val times_divide_eq_left = thm"times_divide_eq_left"; |
238 |
val times_divide_eq_right = thm"times_divide_eq_right"; |
|
239 |
||
14289 | 240 |
local |
241 |
||
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
242 |
(* reduce contradictory <= to False *) |
14288 | 243 |
val simps = [True_implies_equals, |
244 |
inst "w" "number_of ?v" real_add_mult_distrib2, |
|
14289 | 245 |
divide_1,times_divide_eq_right,times_divide_eq_left]; |
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
246 |
|
14293 | 247 |
val simprocs = [real_cancel_numeral_factors_divide, |
248 |
real_cancel_numeral_factors_divide]; |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
249 |
|
10693 | 250 |
fun cvar(th,_ $ (_ $ _ $ var)) = cterm_of (#sign(rep_thm th)) var; |
251 |
||
252 |
val real_mult_mono_thms = |
|
253 |
[(rotate_prems 1 real_mult_less_mono2, |
|
254 |
cvar(real_mult_less_mono2, hd(prems_of real_mult_less_mono2))), |
|
255 |
(real_mult_le_mono2, |
|
256 |
cvar(real_mult_le_mono2, hd(tl(prems_of real_mult_le_mono2))))] |
|
257 |
||
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
258 |
in |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
259 |
|
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
260 |
val real_arith_setup = |
10693 | 261 |
[Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} => |
10722 | 262 |
{add_mono_thms = add_mono_thms, |
10693 | 263 |
mult_mono_thms = mult_mono_thms @ real_mult_mono_thms, |
10722 | 264 |
inj_thms = inj_thms, |
265 |
lessD = lessD, |
|
266 |
simpset = simpset addsimps simps addsimprocs simprocs})]; |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
267 |
|
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
268 |
end; |
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
269 |
|
10722 | 270 |
(* |
271 |
Procedure "assoc_fold" needed? |
|
9436
62bb04ab4b01
rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff
changeset
|
272 |
*) |