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