author | paulson |
Tue, 10 Feb 2004 12:02:11 +0100 | |
changeset 14378 | 69c4d5997669 |
parent 14377 | f454b3004f8f |
permissions | -rw-r--r-- |
13957 | 1 |
(* Title: NSComplexBin.ML |
2 |
Author: Jacques D. Fleuriot |
|
3 |
Copyright: 2001 University of Edinburgh |
|
4 |
Descrition: Binary arithmetic for the nonstandard complex numbers |
|
5 |
*) |
|
6 |
||
7 |
(** hcomplex_of_complex (coercion from complex to nonstandard complex) **) |
|
8 |
||
9 |
Goal "hcomplex_of_complex (number_of w) = number_of w"; |
|
10 |
by (simp_tac (simpset() addsimps [hcomplex_number_of_def]) 1); |
|
11 |
qed "hcomplex_number_of"; |
|
12 |
Addsimps [hcomplex_number_of]; |
|
13 |
||
14 |
Goalw [hypreal_of_real_def] |
|
15 |
"hcomplex_of_hypreal (hypreal_of_real x) = \ |
|
16 |
\ hcomplex_of_complex(complex_of_real x)"; |
|
17 |
by (simp_tac (simpset() addsimps [hcomplex_of_hypreal, |
|
18 |
hcomplex_of_complex_def,complex_of_real_def]) 1); |
|
19 |
qed "hcomplex_of_hypreal_eq_hcomplex_of_complex"; |
|
20 |
||
21 |
Goalw [complex_number_of_def,hypreal_number_of_def] |
|
22 |
"hcomplex_of_complex (number_of w) = hcomplex_of_hypreal(number_of w)"; |
|
23 |
by (rtac (hcomplex_of_hypreal_eq_hcomplex_of_complex RS sym) 1); |
|
24 |
qed "hcomplex_hypreal_number_of"; |
|
25 |
||
26 |
Goalw [hcomplex_number_of_def] "Numeral0 = (0::hcomplex)"; |
|
14320 | 27 |
by(Simp_tac 1); |
13957 | 28 |
qed "hcomplex_numeral_0_eq_0"; |
29 |
||
30 |
Goalw [hcomplex_number_of_def] "Numeral1 = (1::hcomplex)"; |
|
14320 | 31 |
by(Simp_tac 1); |
13957 | 32 |
qed "hcomplex_numeral_1_eq_1"; |
33 |
||
34 |
(* |
|
35 |
Goal "z + hcnj z = \ |
|
36 |
\ hcomplex_of_hypreal (2 * hRe(z))"; |
|
37 |
by (res_inst_tac [("z","z")] eq_Abs_hcomplex 1); |
|
38 |
by (auto_tac (claset(),HOL_ss addsimps [hRe,hcnj,hcomplex_add, |
|
39 |
hypreal_mult,hcomplex_of_hypreal,complex_add_cnj])); |
|
40 |
qed "hcomplex_add_hcnj"; |
|
41 |
||
42 |
Goal "z - hcnj z = \ |
|
43 |
\ hcomplex_of_hypreal (hypreal_of_real #2 * hIm(z)) * iii"; |
|
44 |
by (res_inst_tac [("z","z")] eq_Abs_hcomplex 1); |
|
45 |
by (auto_tac (claset(),simpset() addsimps [hIm,hcnj,hcomplex_diff, |
|
46 |
hypreal_of_real_def,hypreal_mult,hcomplex_of_hypreal, |
|
47 |
complex_diff_cnj,iii_def,hcomplex_mult])); |
|
48 |
qed "hcomplex_diff_hcnj"; |
|
49 |
*) |
|
50 |
||
51 |
(** Addition **) |
|
52 |
||
53 |
Goal "(number_of v :: hcomplex) + number_of v' = number_of (bin_add v v')"; |
|
54 |
by (simp_tac |
|
55 |
(HOL_ss addsimps [hcomplex_number_of_def, |
|
56 |
hcomplex_of_complex_add RS sym, add_complex_number_of]) 1); |
|
57 |
qed "add_hcomplex_number_of"; |
|
58 |
Addsimps [add_hcomplex_number_of]; |
|
59 |
||
60 |
||
61 |
(** Subtraction **) |
|
62 |
||
63 |
Goalw [hcomplex_number_of_def] |
|
64 |
"- (number_of w :: hcomplex) = number_of (bin_minus w)"; |
|
65 |
by (simp_tac |
|
66 |
(HOL_ss addsimps [minus_complex_number_of, hcomplex_of_complex_minus RS sym]) 1); |
|
67 |
qed "minus_hcomplex_number_of"; |
|
68 |
Addsimps [minus_hcomplex_number_of]; |
|
69 |
||
70 |
Goalw [hcomplex_number_of_def, hcomplex_diff_def] |
|
71 |
"(number_of v :: hcomplex) - number_of w = \ |
|
72 |
\ number_of (bin_add v (bin_minus w))"; |
|
73 |
by (Simp_tac 1); |
|
74 |
qed "diff_hcomplex_number_of"; |
|
75 |
Addsimps [diff_hcomplex_number_of]; |
|
76 |
||
77 |
||
78 |
(** Multiplication **) |
|
79 |
||
80 |
Goal "(number_of v :: hcomplex) * number_of v' = number_of (bin_mult v v')"; |
|
81 |
by (simp_tac |
|
82 |
(HOL_ss addsimps [hcomplex_number_of_def, |
|
83 |
hcomplex_of_complex_mult RS sym, mult_complex_number_of]) 1); |
|
84 |
qed "mult_hcomplex_number_of"; |
|
85 |
Addsimps [mult_hcomplex_number_of]; |
|
86 |
||
87 |
Goal "(2::hcomplex) = 1 + 1"; |
|
88 |
by (simp_tac (simpset() addsimps [hcomplex_numeral_1_eq_1 RS sym]) 1); |
|
89 |
val lemma = result(); |
|
90 |
||
91 |
(*For specialist use: NOT as default simprules*) |
|
92 |
Goal "2 * z = (z+z::hcomplex)"; |
|
93 |
by (simp_tac (simpset() addsimps [lemma, hcomplex_add_mult_distrib]) 1); |
|
94 |
qed "hcomplex_mult_2"; |
|
95 |
||
96 |
Goal "z * 2 = (z+z::hcomplex)"; |
|
97 |
by (stac hcomplex_mult_commute 1 THEN rtac hcomplex_mult_2 1); |
|
98 |
qed "hcomplex_mult_2_right"; |
|
99 |
||
100 |
(** Equals (=) **) |
|
101 |
||
102 |
Goal "((number_of v :: hcomplex) = number_of v') = \ |
|
14378
69c4d5997669
generic of_nat and of_int functions, and generalization of iszero
paulson
parents:
14377
diff
changeset
|
103 |
\ iszero (number_of (bin_add v (bin_minus v')) :: int)"; |
13957 | 104 |
by (simp_tac |
105 |
(HOL_ss addsimps [hcomplex_number_of_def, |
|
106 |
hcomplex_of_complex_eq_iff, eq_complex_number_of]) 1); |
|
107 |
qed "eq_hcomplex_number_of"; |
|
108 |
Addsimps [eq_hcomplex_number_of]; |
|
109 |
||
110 |
(*** New versions of existing theorems involving 0, 1hc ***) |
|
111 |
||
112 |
Goal "- 1 = (-1::hcomplex)"; |
|
113 |
by (simp_tac (simpset() addsimps [hcomplex_numeral_1_eq_1 RS sym]) 1); |
|
114 |
qed "hcomplex_minus_1_eq_m1"; |
|
115 |
||
116 |
Goal "-1 * z = -(z::hcomplex)"; |
|
117 |
by (simp_tac (simpset() addsimps [hcomplex_minus_1_eq_m1 RS sym]) 1); |
|
118 |
qed "hcomplex_mult_minus1"; |
|
119 |
||
120 |
Goal "z * -1 = -(z::hcomplex)"; |
|
121 |
by (stac hcomplex_mult_commute 1 THEN rtac hcomplex_mult_minus1 1); |
|
122 |
qed "hcomplex_mult_minus1_right"; |
|
123 |
||
124 |
Addsimps [hcomplex_mult_minus1,hcomplex_mult_minus1_right]; |
|
125 |
||
126 |
(*Maps 0 to Numeral0 and 1 to Numeral1 and -Numeral1 to -1*) |
|
127 |
val hcomplex_numeral_ss = |
|
128 |
complex_numeral_ss addsimps [hcomplex_numeral_0_eq_0 RS sym, hcomplex_numeral_1_eq_1 RS sym, |
|
129 |
hcomplex_minus_1_eq_m1]; |
|
130 |
||
131 |
fun rename_numerals th = |
|
132 |
asm_full_simplify hcomplex_numeral_ss (Thm.transfer (the_context ()) th); |
|
133 |
||
134 |
||
135 |
(*Now insert some identities previously stated for 0 and 1hc*) |
|
136 |
||
137 |
||
138 |
Addsimps [hcomplex_numeral_0_eq_0,hcomplex_numeral_1_eq_1]; |
|
139 |
||
140 |
Goal "number_of v + (number_of w + z) = (number_of(bin_add v w) + z::hcomplex)"; |
|
141 |
by (auto_tac (claset(),simpset() addsimps [hcomplex_add_assoc RS sym])); |
|
142 |
qed "hcomplex_add_number_of_left"; |
|
143 |
||
144 |
Goal "number_of v *(number_of w * z) = (number_of(bin_mult v w) * z::hcomplex)"; |
|
145 |
by (simp_tac (simpset() addsimps [hcomplex_mult_assoc RS sym]) 1); |
|
146 |
qed "hcomplex_mult_number_of_left"; |
|
147 |
||
148 |
Goalw [hcomplex_diff_def] |
|
149 |
"number_of v + (number_of w - c) = number_of(bin_add v w) - (c::hcomplex)"; |
|
150 |
by (rtac hcomplex_add_number_of_left 1); |
|
151 |
qed "hcomplex_add_number_of_diff1"; |
|
152 |
||
153 |
Goal "number_of v + (c - number_of w) = \ |
|
154 |
\ number_of (bin_add v (bin_minus w)) + (c::hcomplex)"; |
|
14335 | 155 |
by (auto_tac (claset(),simpset() addsimps [hcomplex_diff_def]@ add_ac)); |
13957 | 156 |
qed "hcomplex_add_number_of_diff2"; |
157 |
||
158 |
Addsimps [hcomplex_add_number_of_left, hcomplex_mult_number_of_left, |
|
159 |
hcomplex_add_number_of_diff1, hcomplex_add_number_of_diff2]; |
|
160 |
||
161 |
||
162 |
(**** Simprocs for numeric literals ****) |
|
163 |
||
164 |
structure HComplex_Numeral_Simprocs = |
|
165 |
struct |
|
166 |
||
167 |
(*Utilities*) |
|
168 |
||
169 |
val hcomplexT = Type("NSComplex.hcomplex",[]); |
|
170 |
||
171 |
fun mk_numeral n = HOLogic.number_of_const hcomplexT $ HOLogic.mk_bin n; |
|
172 |
||
173 |
val dest_numeral = Complex_Numeral_Simprocs.dest_numeral; |
|
174 |
||
175 |
val find_first_numeral = Complex_Numeral_Simprocs.find_first_numeral; |
|
176 |
||
177 |
val zero = mk_numeral 0; |
|
178 |
val mk_plus = HOLogic.mk_binop "op +"; |
|
179 |
||
180 |
val uminus_const = Const ("uminus", hcomplexT --> hcomplexT); |
|
181 |
||
182 |
(*Thus mk_sum[t] yields t+0; longer sums don't have a trailing zero*) |
|
183 |
fun mk_sum [] = zero |
|
184 |
| mk_sum [t,u] = mk_plus (t, u) |
|
185 |
| mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
|
186 |
||
187 |
(*this version ALWAYS includes a trailing zero*) |
|
188 |
fun long_mk_sum [] = zero |
|
189 |
| long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts); |
|
190 |
||
191 |
val dest_plus = HOLogic.dest_bin "op +" hcomplexT; |
|
192 |
||
193 |
(*decompose additions AND subtractions as a sum*) |
|
194 |
fun dest_summing (pos, Const ("op +", _) $ t $ u, ts) = |
|
195 |
dest_summing (pos, t, dest_summing (pos, u, ts)) |
|
196 |
| dest_summing (pos, Const ("op -", _) $ t $ u, ts) = |
|
197 |
dest_summing (pos, t, dest_summing (not pos, u, ts)) |
|
198 |
| dest_summing (pos, t, ts) = |
|
199 |
if pos then t::ts else uminus_const$t :: ts; |
|
200 |
||
201 |
fun dest_sum t = dest_summing (true, t, []); |
|
202 |
||
203 |
val mk_diff = HOLogic.mk_binop "op -"; |
|
204 |
val dest_diff = HOLogic.dest_bin "op -" hcomplexT; |
|
205 |
||
206 |
val one = mk_numeral 1; |
|
207 |
val mk_times = HOLogic.mk_binop "op *"; |
|
208 |
||
209 |
fun mk_prod [] = one |
|
210 |
| mk_prod [t] = t |
|
211 |
| mk_prod (t :: ts) = if t = one then mk_prod ts |
|
212 |
else mk_times (t, mk_prod ts); |
|
213 |
||
214 |
val dest_times = HOLogic.dest_bin "op *" hcomplexT; |
|
215 |
||
216 |
fun dest_prod t = |
|
217 |
let val (t,u) = dest_times t |
|
218 |
in dest_prod t @ dest_prod u end |
|
219 |
handle TERM _ => [t]; |
|
220 |
||
221 |
(*DON'T do the obvious simplifications; that would create special cases*) |
|
222 |
fun mk_coeff (k, ts) = mk_times (mk_numeral k, ts); |
|
223 |
||
224 |
(*Express t as a product of (possibly) a numeral with other sorted terms*) |
|
225 |
fun dest_coeff sign (Const ("uminus", _) $ t) = dest_coeff (~sign) t |
|
226 |
| dest_coeff sign t = |
|
227 |
let val ts = sort Term.term_ord (dest_prod t) |
|
228 |
val (n, ts') = find_first_numeral [] ts |
|
229 |
handle TERM _ => (1, ts) |
|
230 |
in (sign*n, mk_prod ts') end; |
|
231 |
||
232 |
(*Find first coefficient-term THAT MATCHES u*) |
|
233 |
fun find_first_coeff past u [] = raise TERM("find_first_coeff", []) |
|
234 |
| find_first_coeff past u (t::terms) = |
|
235 |
let val (n,u') = dest_coeff 1 t |
|
236 |
in if u aconv u' then (n, rev past @ terms) |
|
237 |
else find_first_coeff (t::past) u terms |
|
238 |
end |
|
239 |
handle TERM _ => find_first_coeff (t::past) u terms; |
|
240 |
||
241 |
||
242 |
||
243 |
(*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1*) |
|
244 |
val add_0s = map rename_numerals [hcomplex_add_zero_left, hcomplex_add_zero_right]; |
|
245 |
val mult_plus_1s = map rename_numerals [hcomplex_mult_one_left, hcomplex_mult_one_right]; |
|
246 |
val mult_minus_1s = map rename_numerals [hcomplex_mult_minus1, hcomplex_mult_minus1_right]; |
|
247 |
val mult_1s = mult_plus_1s @ mult_minus_1s; |
|
248 |
||
249 |
(*To perform binary arithmetic*) |
|
250 |
val bin_simps = |
|
251 |
[hcomplex_numeral_0_eq_0 RS sym, hcomplex_numeral_1_eq_1 RS sym, |
|
252 |
add_hcomplex_number_of, hcomplex_add_number_of_left, |
|
253 |
minus_hcomplex_number_of, diff_hcomplex_number_of, mult_hcomplex_number_of, |
|
254 |
hcomplex_mult_number_of_left] @ bin_arith_simps @ bin_rel_simps; |
|
255 |
||
14123 | 256 |
(*Binary arithmetic BUT NOT ADDITION since it may collapse adjacent terms |
257 |
during re-arrangement*) |
|
258 |
val non_add_bin_simps = |
|
259 |
bin_simps \\ [hcomplex_add_number_of_left, add_hcomplex_number_of]; |
|
260 |
||
13957 | 261 |
(*To evaluate binary negations of coefficients*) |
262 |
val hcomplex_minus_simps = NCons_simps @ |
|
263 |
[hcomplex_minus_1_eq_m1,minus_hcomplex_number_of, |
|
264 |
bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min, |
|
265 |
bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min]; |
|
266 |
||
267 |
||
268 |
(*To let us treat subtraction as addition*) |
|
14335 | 269 |
val diff_simps = [hcomplex_diff_def, minus_add_distrib, minus_minus]; |
13957 | 270 |
|
271 |
(*push the unary minus down: - x * y = x * - y *) |
|
272 |
val hcomplex_minus_mult_eq_1_to_2 = |
|
14335 | 273 |
[minus_mult_left RS sym, minus_mult_right] MRS trans |
13957 | 274 |
|> standard; |
275 |
||
276 |
(*to extract again any uncancelled minuses*) |
|
277 |
val hcomplex_minus_from_mult_simps = |
|
14335 | 278 |
[minus_minus, minus_mult_left RS sym, minus_mult_right RS sym]; |
13957 | 279 |
|
280 |
(*combine unary minus with numeric literals, however nested within a product*) |
|
281 |
val hcomplex_mult_minus_simps = |
|
14335 | 282 |
[hcomplex_mult_assoc, minus_mult_left, hcomplex_minus_mult_eq_1_to_2]; |
13957 | 283 |
|
284 |
(*Final simplification: cancel + and * *) |
|
285 |
val simplify_meta_eq = |
|
286 |
Int_Numeral_Simprocs.simplify_meta_eq |
|
14335 | 287 |
[add_zero_left, add_zero_right, |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
14335
diff
changeset
|
288 |
mult_zero_left, mult_zero_right, mult_1, mult_1_right]; |
13957 | 289 |
|
290 |
val prep_simproc = Complex_Numeral_Simprocs.prep_simproc; |
|
291 |
||
292 |
||
293 |
structure CancelNumeralsCommon = |
|
294 |
struct |
|
295 |
val mk_sum = mk_sum |
|
296 |
val dest_sum = dest_sum |
|
297 |
val mk_coeff = mk_coeff |
|
298 |
val dest_coeff = dest_coeff 1 |
|
299 |
val find_first_coeff = find_first_coeff [] |
|
300 |
val trans_tac = Real_Numeral_Simprocs.trans_tac |
|
301 |
val norm_tac = |
|
302 |
ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@ |
|
14335 | 303 |
hcomplex_minus_simps@add_ac)) |
14123 | 304 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps non_add_bin_simps@hcomplex_mult_minus_simps)) |
13957 | 305 |
THEN ALLGOALS |
306 |
(simp_tac (HOL_ss addsimps hcomplex_minus_from_mult_simps@ |
|
14335 | 307 |
add_ac@mult_ac)) |
13957 | 308 |
val numeral_simp_tac = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
309 |
val simplify_meta_eq = simplify_meta_eq |
|
310 |
end; |
|
311 |
||
312 |
||
313 |
structure EqCancelNumerals = CancelNumeralsFun |
|
314 |
(open CancelNumeralsCommon |
|
315 |
val prove_conv = Bin_Simprocs.prove_conv |
|
316 |
val mk_bal = HOLogic.mk_eq |
|
317 |
val dest_bal = HOLogic.dest_bin "op =" hcomplexT |
|
14373 | 318 |
val bal_add1 = eq_add_iff1 RS trans |
319 |
val bal_add2 = eq_add_iff2 RS trans |
|
13957 | 320 |
); |
321 |
||
322 |
||
323 |
val cancel_numerals = |
|
324 |
map prep_simproc |
|
325 |
[("hcomplexeq_cancel_numerals", |
|
326 |
["(l::hcomplex) + m = n", "(l::hcomplex) = m + n", |
|
327 |
"(l::hcomplex) - m = n", "(l::hcomplex) = m - n", |
|
328 |
"(l::hcomplex) * m = n", "(l::hcomplex) = m * n"], |
|
329 |
EqCancelNumerals.proc)]; |
|
330 |
||
331 |
structure CombineNumeralsData = |
|
332 |
struct |
|
333 |
val add = op + : int*int -> int |
|
334 |
val mk_sum = long_mk_sum (*to work for e.g. #2*x + #3*x *) |
|
335 |
val dest_sum = dest_sum |
|
336 |
val mk_coeff = mk_coeff |
|
337 |
val dest_coeff = dest_coeff 1 |
|
14373 | 338 |
val left_distrib = combine_common_factor RS trans |
13957 | 339 |
val prove_conv = Bin_Simprocs.prove_conv_nohyps |
340 |
val trans_tac = Real_Numeral_Simprocs.trans_tac |
|
341 |
val norm_tac = |
|
342 |
ALLGOALS (simp_tac (HOL_ss addsimps add_0s@mult_1s@diff_simps@ |
|
14335 | 343 |
hcomplex_minus_simps@add_ac)) |
14123 | 344 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps non_add_bin_simps@hcomplex_mult_minus_simps)) |
13957 | 345 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps hcomplex_minus_from_mult_simps@ |
14335 | 346 |
add_ac@mult_ac)) |
13957 | 347 |
val numeral_simp_tac = ALLGOALS |
348 |
(simp_tac (HOL_ss addsimps add_0s@bin_simps)) |
|
349 |
val simplify_meta_eq = simplify_meta_eq |
|
350 |
end; |
|
351 |
||
352 |
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData); |
|
353 |
||
354 |
val combine_numerals = |
|
355 |
prep_simproc ("hcomplex_combine_numerals", |
|
356 |
["(i::hcomplex) + j", "(i::hcomplex) - j"], |
|
357 |
CombineNumerals.proc); |
|
358 |
||
359 |
(** Declarations for ExtractCommonTerm **) |
|
360 |
||
361 |
(*this version ALWAYS includes a trailing one*) |
|
362 |
fun long_mk_prod [] = one |
|
363 |
| long_mk_prod (t :: ts) = mk_times (t, mk_prod ts); |
|
364 |
||
365 |
(*Find first term that matches u*) |
|
366 |
fun find_first past u [] = raise TERM("find_first", []) |
|
367 |
| find_first past u (t::terms) = |
|
368 |
if u aconv t then (rev past @ terms) |
|
369 |
else find_first (t::past) u terms |
|
370 |
handle TERM _ => find_first (t::past) u terms; |
|
371 |
||
372 |
(*Final simplification: cancel + and * *) |
|
373 |
fun cancel_simplify_meta_eq cancel_th th = |
|
374 |
Int_Numeral_Simprocs.simplify_meta_eq |
|
375 |
[hcomplex_mult_one_left, hcomplex_mult_one_right] |
|
376 |
(([th, cancel_th]) MRS trans); |
|
377 |
||
378 |
(*** Making constant folding work for 0 and 1 too ***) |
|
379 |
||
380 |
structure HComplexAbstractNumeralsData = |
|
381 |
struct |
|
382 |
val dest_eq = HOLogic.dest_eq o HOLogic.dest_Trueprop o concl_of |
|
383 |
val is_numeral = Bin_Simprocs.is_numeral |
|
384 |
val numeral_0_eq_0 = hcomplex_numeral_0_eq_0 |
|
385 |
val numeral_1_eq_1 = hcomplex_numeral_1_eq_1 |
|
386 |
val prove_conv = Bin_Simprocs.prove_conv_nohyps_novars |
|
387 |
fun norm_tac simps = ALLGOALS (simp_tac (HOL_ss addsimps simps)) |
|
388 |
val simplify_meta_eq = Bin_Simprocs.simplify_meta_eq |
|
389 |
end |
|
390 |
||
391 |
structure HComplexAbstractNumerals = AbstractNumeralsFun (HComplexAbstractNumeralsData) |
|
392 |
||
393 |
(*For addition, we already have rules for the operand 0. |
|
394 |
Multiplication is omitted because there are already special rules for |
|
395 |
both 0 and 1 as operands. Unary minus is trivial, just have - 1 = -1. |
|
396 |
For the others, having three patterns is a compromise between just having |
|
397 |
one (many spurious calls) and having nine (just too many!) *) |
|
398 |
val eval_numerals = |
|
399 |
map prep_simproc |
|
400 |
[("hcomplex_add_eval_numerals", |
|
401 |
["(m::hcomplex) + 1", "(m::hcomplex) + number_of v"], |
|
402 |
HComplexAbstractNumerals.proc add_hcomplex_number_of), |
|
403 |
("hcomplex_diff_eval_numerals", |
|
404 |
["(m::hcomplex) - 1", "(m::hcomplex) - number_of v"], |
|
405 |
HComplexAbstractNumerals.proc diff_hcomplex_number_of), |
|
406 |
("hcomplex_eq_eval_numerals", |
|
407 |
["(m::hcomplex) = 0", "(m::hcomplex) = 1", "(m::hcomplex) = number_of v"], |
|
408 |
HComplexAbstractNumerals.proc eq_hcomplex_number_of)] |
|
409 |
||
410 |
end; |
|
411 |
||
412 |
Addsimprocs HComplex_Numeral_Simprocs.eval_numerals; |
|
413 |
Addsimprocs HComplex_Numeral_Simprocs.cancel_numerals; |
|
414 |
Addsimprocs [HComplex_Numeral_Simprocs.combine_numerals]; |
|
415 |
||
416 |
||
417 |
(*examples: |
|
418 |
print_depth 22; |
|
419 |
set timing; |
|
420 |
set trace_simp; |
|
421 |
fun test s = (Goal s, by (Simp_tac 1)); |
|
422 |
||
423 |
test "l + 2 + 2 + 2 + (l + 2) + (oo + 2) = (uu::hcomplex)"; |
|
424 |
test " 2*u = (u::hcomplex)"; |
|
425 |
test "(i + j + 12 + (k::hcomplex)) - 15 = y"; |
|
426 |
test "(i + j + 12 + (k::hcomplex)) - 5 = y"; |
|
427 |
||
428 |
test "( 2*x - (u*v) + y) - v* 3*u = (w::hcomplex)"; |
|
429 |
test "( 2*x*u*v + (u*v)* 4 + y) - v*u* 4 = (w::hcomplex)"; |
|
430 |
test "( 2*x*u*v + (u*v)* 4 + y) - v*u = (w::hcomplex)"; |
|
431 |
test "u*v - (x*u*v + (u*v)* 4 + y) = (w::hcomplex)"; |
|
432 |
||
433 |
test "(i + j + 12 + (k::hcomplex)) = u + 15 + y"; |
|
434 |
test "(i + j* 2 + 12 + (k::hcomplex)) = j + 5 + y"; |
|
435 |
||
436 |
test " 2*y + 3*z + 6*w + 2*y + 3*z + 2*u = 2*y' + 3*z' + 6*w' + 2*y' + 3*z' + u + (vv::hcomplex)"; |
|
437 |
||
438 |
test "a + -(b+c) + b = (d::hcomplex)"; |
|
439 |
test "a + -(b+c) - b = (d::hcomplex)"; |
|
440 |
||
441 |
(*negative numerals*) |
|
442 |
test "(i + j + -2 + (k::hcomplex)) - (u + 5 + y) = zz"; |
|
443 |
||
444 |
test "(i + j + -12 + (k::hcomplex)) - 15 = y"; |
|
445 |
test "(i + j + 12 + (k::hcomplex)) - -15 = y"; |
|
446 |
test "(i + j + -12 + (k::hcomplex)) - -15 = y"; |
|
447 |
*) |
|
448 |
||
449 |
(** Constant folding for hcomplex plus and times **) |
|
450 |
||
451 |
structure HComplex_Times_Assoc_Data : ASSOC_FOLD_DATA = |
|
452 |
struct |
|
453 |
val ss = HOL_ss |
|
454 |
val eq_reflection = eq_reflection |
|
455 |
val sg_ref = Sign.self_ref (Theory.sign_of (the_context ())) |
|
456 |
val T = HComplex_Numeral_Simprocs.hcomplexT |
|
457 |
val plus = Const ("op *", [T,T] ---> T) |
|
14335 | 458 |
val add_ac = mult_ac |
13957 | 459 |
end; |
460 |
||
461 |
structure HComplex_Times_Assoc = Assoc_Fold (HComplex_Times_Assoc_Data); |
|
462 |
||
463 |
Addsimprocs [HComplex_Times_Assoc.conv]; |
|
464 |
||
465 |
Addsimps [hcomplex_of_complex_zero_iff]; |
|
466 |
||
467 |
||
468 |
(** extra thms **) |
|
469 |
||
470 |
Goal "(hcnj z = 0) = (z = 0)"; |
|
471 |
by (auto_tac (claset(),simpset() addsimps [hcomplex_hcnj_zero_iff])); |
|
472 |
qed "hcomplex_hcnj_num_zero_iff"; |
|
473 |
Addsimps [hcomplex_hcnj_num_zero_iff]; |
|
474 |
||
475 |
Goal "0 = Abs_hcomplex (hcomplexrel `` {%n. 0})"; |
|
476 |
by (simp_tac (simpset() addsimps [hcomplex_zero_def RS meta_eq_to_obj_eq RS sym]) 1); |
|
477 |
qed "hcomplex_zero_num"; |
|
478 |
||
479 |
Goal "1 = Abs_hcomplex (hcomplexrel `` {%n. 1})"; |
|
480 |
by (simp_tac (simpset() addsimps [hcomplex_one_def RS meta_eq_to_obj_eq RS sym]) 1); |
|
481 |
qed "hcomplex_one_num"; |
|
482 |
||
483 |
(*** Real and imaginary stuff ***) |
|
484 |
||
14377 | 485 |
(*Convert??? |
13957 | 486 |
Goalw [hcomplex_number_of_def] |
487 |
"((number_of xa :: hcomplex) + iii * number_of ya = \ |
|
488 |
\ number_of xb + iii * number_of yb) = \ |
|
489 |
\ (((number_of xa :: hcomplex) = number_of xb) & \ |
|
490 |
\ ((number_of ya :: hcomplex) = number_of yb))"; |
|
491 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iff, |
|
492 |
hcomplex_hypreal_number_of])); |
|
493 |
qed "hcomplex_number_of_eq_cancel_iff"; |
|
494 |
Addsimps [hcomplex_number_of_eq_cancel_iff]; |
|
495 |
||
496 |
Goalw [hcomplex_number_of_def] |
|
497 |
"((number_of xa :: hcomplex) + number_of ya * iii = \ |
|
498 |
\ number_of xb + number_of yb * iii) = \ |
|
499 |
\ (((number_of xa :: hcomplex) = number_of xb) & \ |
|
500 |
\ ((number_of ya :: hcomplex) = number_of yb))"; |
|
501 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iffA, |
|
502 |
hcomplex_hypreal_number_of])); |
|
503 |
qed "hcomplex_number_of_eq_cancel_iffA"; |
|
504 |
Addsimps [hcomplex_number_of_eq_cancel_iffA]; |
|
505 |
||
506 |
Goalw [hcomplex_number_of_def] |
|
507 |
"((number_of xa :: hcomplex) + number_of ya * iii = \ |
|
508 |
\ number_of xb + iii * number_of yb) = \ |
|
509 |
\ (((number_of xa :: hcomplex) = number_of xb) & \ |
|
510 |
\ ((number_of ya :: hcomplex) = number_of yb))"; |
|
511 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iffB, |
|
512 |
hcomplex_hypreal_number_of])); |
|
513 |
qed "hcomplex_number_of_eq_cancel_iffB"; |
|
514 |
Addsimps [hcomplex_number_of_eq_cancel_iffB]; |
|
515 |
||
516 |
Goalw [hcomplex_number_of_def] |
|
517 |
"((number_of xa :: hcomplex) + iii * number_of ya = \ |
|
518 |
\ number_of xb + number_of yb * iii) = \ |
|
519 |
\ (((number_of xa :: hcomplex) = number_of xb) & \ |
|
520 |
\ ((number_of ya :: hcomplex) = number_of yb))"; |
|
521 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iffC, |
|
522 |
hcomplex_hypreal_number_of])); |
|
523 |
qed "hcomplex_number_of_eq_cancel_iffC"; |
|
524 |
Addsimps [hcomplex_number_of_eq_cancel_iffC]; |
|
525 |
||
526 |
Goalw [hcomplex_number_of_def] |
|
527 |
"((number_of xa :: hcomplex) + iii * number_of ya = \ |
|
528 |
\ number_of xb) = \ |
|
529 |
\ (((number_of xa :: hcomplex) = number_of xb) & \ |
|
530 |
\ ((number_of ya :: hcomplex) = 0))"; |
|
531 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iff2, |
|
532 |
hcomplex_hypreal_number_of,hcomplex_of_hypreal_zero_iff])); |
|
533 |
qed "hcomplex_number_of_eq_cancel_iff2"; |
|
534 |
Addsimps [hcomplex_number_of_eq_cancel_iff2]; |
|
535 |
||
536 |
Goalw [hcomplex_number_of_def] |
|
537 |
"((number_of xa :: hcomplex) + number_of ya * iii = \ |
|
538 |
\ number_of xb) = \ |
|
539 |
\ (((number_of xa :: hcomplex) = number_of xb) & \ |
|
540 |
\ ((number_of ya :: hcomplex) = 0))"; |
|
541 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iff2a, |
|
542 |
hcomplex_hypreal_number_of,hcomplex_of_hypreal_zero_iff])); |
|
543 |
qed "hcomplex_number_of_eq_cancel_iff2a"; |
|
544 |
Addsimps [hcomplex_number_of_eq_cancel_iff2a]; |
|
545 |
||
546 |
Goalw [hcomplex_number_of_def] |
|
547 |
"((number_of xa :: hcomplex) + iii * number_of ya = \ |
|
548 |
\ iii * number_of yb) = \ |
|
549 |
\ (((number_of xa :: hcomplex) = 0) & \ |
|
550 |
\ ((number_of ya :: hcomplex) = number_of yb))"; |
|
551 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iff3, |
|
552 |
hcomplex_hypreal_number_of,hcomplex_of_hypreal_zero_iff])); |
|
553 |
qed "hcomplex_number_of_eq_cancel_iff3"; |
|
554 |
Addsimps [hcomplex_number_of_eq_cancel_iff3]; |
|
555 |
||
556 |
Goalw [hcomplex_number_of_def] |
|
557 |
"((number_of xa :: hcomplex) + number_of ya * iii= \ |
|
558 |
\ iii * number_of yb) = \ |
|
559 |
\ (((number_of xa :: hcomplex) = 0) & \ |
|
560 |
\ ((number_of ya :: hcomplex) = number_of yb))"; |
|
561 |
by (auto_tac (claset(), HOL_ss addsimps [hcomplex_eq_cancel_iff3a, |
|
562 |
hcomplex_hypreal_number_of,hcomplex_of_hypreal_zero_iff])); |
|
563 |
qed "hcomplex_number_of_eq_cancel_iff3a"; |
|
564 |
Addsimps [hcomplex_number_of_eq_cancel_iff3a]; |
|
14377 | 565 |
*) |
13957 | 566 |
|
567 |
Goalw [hcomplex_number_of_def] "hcnj (number_of v :: hcomplex) = number_of v"; |
|
568 |
by (rtac (hcomplex_hypreal_number_of RS ssubst) 1); |
|
569 |
by (rtac hcomplex_hcnj_hcomplex_of_hypreal 1); |
|
570 |
qed "hcomplex_number_of_hcnj"; |
|
571 |
Addsimps [hcomplex_number_of_hcnj]; |
|
572 |
||
573 |
Goalw [hcomplex_number_of_def] |
|
574 |
"hcmod(number_of v :: hcomplex) = abs (number_of v :: hypreal)"; |
|
575 |
by (rtac (hcomplex_hypreal_number_of RS ssubst) 1); |
|
576 |
by (auto_tac (claset(), HOL_ss addsimps [hcmod_hcomplex_of_hypreal])); |
|
577 |
qed "hcomplex_number_of_hcmod"; |
|
578 |
Addsimps [hcomplex_number_of_hcmod]; |
|
579 |
||
580 |
Goalw [hcomplex_number_of_def] |
|
581 |
"hRe(number_of v :: hcomplex) = number_of v"; |
|
582 |
by (rtac (hcomplex_hypreal_number_of RS ssubst) 1); |
|
583 |
by (auto_tac (claset(), HOL_ss addsimps [hRe_hcomplex_of_hypreal])); |
|
584 |
qed "hcomplex_number_of_hRe"; |
|
585 |
Addsimps [hcomplex_number_of_hRe]; |
|
586 |
||
587 |
Goalw [hcomplex_number_of_def] |
|
588 |
"hIm(number_of v :: hcomplex) = 0"; |
|
589 |
by (rtac (hcomplex_hypreal_number_of RS ssubst) 1); |
|
590 |
by (auto_tac (claset(), HOL_ss addsimps [hIm_hcomplex_of_hypreal])); |
|
591 |
qed "hcomplex_number_of_hIm"; |
|
592 |
Addsimps [hcomplex_number_of_hIm]; |
|
593 |
||
594 |
||
595 |