13957
|
1 |
(* Title: NSComplexArith0.ML
|
|
2 |
Author: Jacques D. Fleuriot
|
|
3 |
Copyright: 2001 University of Edinburgh
|
|
4 |
Description: Assorted facts that need binary literals
|
|
5 |
Also, common factor cancellation (see e.g. HyperArith0)
|
|
6 |
*)
|
|
7 |
|
|
8 |
(****
|
|
9 |
Goal "((x * y = #0) = (x = #0 | y = (#0::hcomplex)))";
|
|
10 |
by (auto_tac (claset(),simpset() addsimps [rename_numerals hcomplex_mult_zero_iff]));
|
|
11 |
qed "hcomplex_mult_is_0";
|
|
12 |
AddIffs [hcomplex_mult_is_0];
|
|
13 |
****)
|
|
14 |
|
|
15 |
(** Division and inverse **)
|
|
16 |
|
|
17 |
Goal "0/x = (0::hcomplex)";
|
|
18 |
by (simp_tac (simpset() addsimps [hcomplex_divide_def]) 1);
|
|
19 |
qed "hcomplex_0_divide";
|
|
20 |
Addsimps [hcomplex_0_divide];
|
|
21 |
|
|
22 |
Goalw [hcomplex_divide_def] "x/(0::hcomplex) = 0";
|
|
23 |
by (stac HCOMPLEX_INVERSE_ZERO 1);
|
|
24 |
by (Simp_tac 1);
|
|
25 |
qed "HCOMPLEX_DIVIDE_ZERO";
|
|
26 |
|
|
27 |
Goal "inverse (x::hcomplex) = 1/x";
|
|
28 |
by (simp_tac (simpset() addsimps [hcomplex_divide_def]) 1);
|
|
29 |
qed "hcomplex_inverse_eq_divide";
|
|
30 |
|
|
31 |
Goal "(inverse(x::hcomplex) = 0) = (x = 0)";
|
|
32 |
by (auto_tac (claset(),
|
|
33 |
simpset() addsimps [HCOMPLEX_INVERSE_ZERO]));
|
|
34 |
by (blast_tac (claset() addIs [ccontr] addDs [hcomplex_inverse_not_zero]) 1);
|
|
35 |
qed "hcomplex_inverse_zero_iff";
|
|
36 |
Addsimps [hcomplex_inverse_zero_iff];
|
|
37 |
|
|
38 |
Goal "(x/y = 0) = (x=0 | y=(0::hcomplex))";
|
|
39 |
by (auto_tac (claset(), simpset() addsimps [hcomplex_divide_def]));
|
|
40 |
qed "hcomplex_divide_eq_0_iff";
|
|
41 |
Addsimps [hcomplex_divide_eq_0_iff];
|
|
42 |
|
|
43 |
Goal "h ~= (0::hcomplex) ==> h/h = 1";
|
|
44 |
by (asm_simp_tac
|
|
45 |
(simpset() addsimps [hcomplex_divide_def]) 1);
|
|
46 |
qed "hcomplex_divide_self_eq";
|
|
47 |
Addsimps [hcomplex_divide_self_eq];
|
|
48 |
|
|
49 |
bind_thm ("hcomplex_mult_minus_right", hcomplex_minus_mult_eq2 RS sym);
|
|
50 |
|
|
51 |
Goal "!!k::hcomplex. (k*m = k*n) = (k = 0 | m=n)";
|
|
52 |
by (case_tac "k=0" 1);
|
|
53 |
by (auto_tac (claset(), simpset() addsimps [hcomplex_mult_left_cancel]));
|
|
54 |
qed "hcomplex_mult_eq_cancel1";
|
|
55 |
|
|
56 |
Goal "!!k::hcomplex. (m*k = n*k) = (k = 0 | m=n)";
|
|
57 |
by (case_tac "k=0" 1);
|
|
58 |
by (auto_tac (claset(), simpset() addsimps [hcomplex_mult_right_cancel]));
|
|
59 |
qed "hcomplex_mult_eq_cancel2";
|
|
60 |
|
|
61 |
Goal "!!k::hcomplex. k~=0 ==> (k*m) / (k*n) = (m/n)";
|
|
62 |
by (asm_simp_tac
|
|
63 |
(simpset() addsimps [hcomplex_divide_def, hcomplex_inverse_distrib]) 1);
|
|
64 |
by (subgoal_tac "k * m * (inverse k * inverse n) = \
|
|
65 |
\ (k * inverse k) * (m * inverse n)" 1);
|
|
66 |
by (Asm_full_simp_tac 1);
|
|
67 |
by (asm_full_simp_tac (HOL_ss addsimps hcomplex_mult_ac) 1);
|
|
68 |
qed "hcomplex_mult_div_cancel1";
|
|
69 |
|
|
70 |
(*For ExtractCommonTerm*)
|
|
71 |
Goal "(k*m) / (k*n) = (if k = (0::hcomplex) then 0 else m/n)";
|
|
72 |
by (simp_tac (simpset() addsimps [hcomplex_mult_div_cancel1]) 1);
|
|
73 |
qed "hcomplex_mult_div_cancel_disj";
|
|
74 |
|
|
75 |
|
|
76 |
local
|
|
77 |
open HComplex_Numeral_Simprocs
|
|
78 |
in
|
|
79 |
|
|
80 |
val rel_hcomplex_number_of = [eq_hcomplex_number_of];
|
|
81 |
|
|
82 |
|
|
83 |
structure CancelNumeralFactorCommon =
|
|
84 |
struct
|
|
85 |
val mk_coeff = mk_coeff
|
|
86 |
val dest_coeff = dest_coeff 1
|
|
87 |
val trans_tac = Real_Numeral_Simprocs.trans_tac
|
|
88 |
val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps hcomplex_minus_from_mult_simps @ mult_1s))
|
|
89 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@hcomplex_mult_minus_simps))
|
|
90 |
THEN ALLGOALS (simp_tac (HOL_ss addsimps hcomplex_mult_ac))
|
|
91 |
val numeral_simp_tac =
|
|
92 |
ALLGOALS (simp_tac (HOL_ss addsimps rel_hcomplex_number_of@bin_simps))
|
|
93 |
val simplify_meta_eq = simplify_meta_eq
|
|
94 |
end
|
|
95 |
|
|
96 |
|
|
97 |
structure DivCancelNumeralFactor = CancelNumeralFactorFun
|
|
98 |
(open CancelNumeralFactorCommon
|
|
99 |
val prove_conv = Bin_Simprocs.prove_conv
|
|
100 |
val mk_bal = HOLogic.mk_binop "HOL.divide"
|
|
101 |
val dest_bal = HOLogic.dest_bin "HOL.divide" hcomplexT
|
|
102 |
val cancel = hcomplex_mult_div_cancel1 RS trans
|
|
103 |
val neg_exchanges = false
|
|
104 |
)
|
|
105 |
|
|
106 |
|
|
107 |
structure EqCancelNumeralFactor = CancelNumeralFactorFun
|
|
108 |
(open CancelNumeralFactorCommon
|
|
109 |
val prove_conv = Bin_Simprocs.prove_conv
|
|
110 |
val mk_bal = HOLogic.mk_eq
|
|
111 |
val dest_bal = HOLogic.dest_bin "op =" hcomplexT
|
|
112 |
val cancel = hcomplex_mult_eq_cancel1 RS trans
|
|
113 |
val neg_exchanges = false
|
|
114 |
)
|
|
115 |
|
|
116 |
|
|
117 |
val hcomplex_cancel_numeral_factors_relations =
|
|
118 |
map prep_simproc
|
|
119 |
[("hcomplexeq_cancel_numeral_factor",
|
|
120 |
["(l::hcomplex) * m = n", "(l::hcomplex) = m * n"],
|
|
121 |
EqCancelNumeralFactor.proc)];
|
|
122 |
|
|
123 |
val hcomplex_cancel_numeral_factors_divide = prep_simproc
|
|
124 |
("hcomplexdiv_cancel_numeral_factor",
|
|
125 |
["((l::hcomplex) * m) / n", "(l::hcomplex) / (m * n)",
|
|
126 |
"((number_of v)::hcomplex) / (number_of w)"],
|
|
127 |
DivCancelNumeralFactor.proc);
|
|
128 |
|
|
129 |
val hcomplex_cancel_numeral_factors =
|
|
130 |
hcomplex_cancel_numeral_factors_relations @
|
|
131 |
[hcomplex_cancel_numeral_factors_divide];
|
|
132 |
|
|
133 |
end;
|
|
134 |
|
|
135 |
|
|
136 |
Addsimprocs hcomplex_cancel_numeral_factors;
|
|
137 |
|
|
138 |
|
|
139 |
(*examples:
|
|
140 |
print_depth 22;
|
|
141 |
set timing;
|
|
142 |
set trace_simp;
|
|
143 |
fun test s = (Goal s; by (Simp_tac 1));
|
|
144 |
|
|
145 |
|
|
146 |
test "#9*x = #12 * (y::hcomplex)";
|
|
147 |
test "(#9*x) / (#12 * (y::hcomplex)) = z";
|
|
148 |
|
|
149 |
test "#-99*x = #132 * (y::hcomplex)";
|
|
150 |
|
|
151 |
test "#999*x = #-396 * (y::hcomplex)";
|
|
152 |
test "(#999*x) / (#-396 * (y::hcomplex)) = z";
|
|
153 |
|
|
154 |
test "#-99*x = #-81 * (y::hcomplex)";
|
|
155 |
test "(#-99*x) / (#-81 * (y::hcomplex)) = z";
|
|
156 |
|
|
157 |
test "#-2 * x = #-1 * (y::hcomplex)";
|
|
158 |
test "#-2 * x = -(y::hcomplex)";
|
|
159 |
test "(#-2 * x) / (#-1 * (y::hcomplex)) = z";
|
|
160 |
|
|
161 |
*)
|
|
162 |
|
|
163 |
|
|
164 |
(** Declarations for ExtractCommonTerm **)
|
|
165 |
|
|
166 |
local
|
|
167 |
open HComplex_Numeral_Simprocs
|
|
168 |
in
|
|
169 |
|
|
170 |
structure CancelFactorCommon =
|
|
171 |
struct
|
|
172 |
val mk_sum = long_mk_prod
|
|
173 |
val dest_sum = dest_prod
|
|
174 |
val mk_coeff = mk_coeff
|
|
175 |
val dest_coeff = dest_coeff
|
|
176 |
val find_first = find_first []
|
|
177 |
val trans_tac = Real_Numeral_Simprocs.trans_tac
|
|
178 |
val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@hcomplex_mult_ac))
|
|
179 |
end;
|
|
180 |
|
|
181 |
|
|
182 |
structure EqCancelFactor = ExtractCommonTermFun
|
|
183 |
(open CancelFactorCommon
|
|
184 |
val prove_conv = Bin_Simprocs.prove_conv
|
|
185 |
val mk_bal = HOLogic.mk_eq
|
|
186 |
val dest_bal = HOLogic.dest_bin "op =" hcomplexT
|
|
187 |
val simplify_meta_eq = cancel_simplify_meta_eq hcomplex_mult_eq_cancel1
|
|
188 |
);
|
|
189 |
|
|
190 |
|
|
191 |
structure DivideCancelFactor = ExtractCommonTermFun
|
|
192 |
(open CancelFactorCommon
|
|
193 |
val prove_conv = Bin_Simprocs.prove_conv
|
|
194 |
val mk_bal = HOLogic.mk_binop "HOL.divide"
|
|
195 |
val dest_bal = HOLogic.dest_bin "HOL.divide" hcomplexT
|
|
196 |
val simplify_meta_eq = cancel_simplify_meta_eq hcomplex_mult_div_cancel_disj
|
|
197 |
);
|
|
198 |
|
|
199 |
val hcomplex_cancel_factor =
|
|
200 |
map prep_simproc
|
|
201 |
[("hcomplex_eq_cancel_factor", ["(l::hcomplex) * m = n", "(l::hcomplex) = m * n"],
|
|
202 |
EqCancelFactor.proc),
|
|
203 |
("hcomplex_divide_cancel_factor", ["((l::hcomplex) * m) / n", "(l::hcomplex) / (m * n)"],
|
|
204 |
DivideCancelFactor.proc)];
|
|
205 |
|
|
206 |
end;
|
|
207 |
|
|
208 |
Addsimprocs hcomplex_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::hcomplex)";
|
|
218 |
test "k = k*(y::hcomplex)";
|
|
219 |
test "a*(b*c) = (b::hcomplex)";
|
|
220 |
test "a*(b*c) = d*(b::hcomplex)*(x*a)";
|
|
221 |
|
|
222 |
|
|
223 |
test "(x*k) / (k*(y::hcomplex)) = (uu::hcomplex)";
|
|
224 |
test "(k) / (k*(y::hcomplex)) = (uu::hcomplex)";
|
|
225 |
test "(a*(b*c)) / ((b::hcomplex)) = (uu::hcomplex)";
|
|
226 |
test "(a*(b*c)) / (d*(b::hcomplex)*(x*a)) = (uu::hcomplex)";
|
|
227 |
|
|
228 |
(*FIXME: what do we do about this?*)
|
|
229 |
test "a*(b*c)/(y*z) = d*(b::hcomplex)*(x*a)/z";
|
|
230 |
*)
|
|
231 |
|
|
232 |
|
|
233 |
Goal "z~=0 ==> ((x::hcomplex) = y/z) = (x*z = y)";
|
|
234 |
by (subgoal_tac "(x*z = y) = (x*z = (y/z)*z)" 1);
|
|
235 |
by (asm_simp_tac (simpset() addsimps [hcomplex_divide_def, hcomplex_mult_assoc]) 2);
|
|
236 |
by (etac ssubst 1);
|
|
237 |
by (stac hcomplex_mult_eq_cancel2 1);
|
|
238 |
by (Asm_simp_tac 1);
|
|
239 |
qed "hcomplex_eq_divide_eq";
|
|
240 |
Addsimps [inst "z" "number_of ?w" hcomplex_eq_divide_eq];
|
|
241 |
|
|
242 |
Goal "z~=0 ==> (y/z = (x::hcomplex)) = (y = x*z)";
|
|
243 |
by (subgoal_tac "(y = x*z) = ((y/z)*z = x*z)" 1);
|
|
244 |
by (asm_simp_tac (simpset() addsimps [hcomplex_divide_def, hcomplex_mult_assoc]) 2);
|
|
245 |
by (etac ssubst 1);
|
|
246 |
by (stac hcomplex_mult_eq_cancel2 1);
|
|
247 |
by (Asm_simp_tac 1);
|
|
248 |
qed "hcomplex_divide_eq_eq";
|
|
249 |
Addsimps [inst "z" "number_of ?w" hcomplex_divide_eq_eq];
|
|
250 |
|
|
251 |
Goal "(m/k = n/k) = (k = 0 | m = (n::hcomplex))";
|
|
252 |
by (case_tac "k=0" 1);
|
|
253 |
by (asm_simp_tac (simpset() addsimps [HCOMPLEX_DIVIDE_ZERO]) 1);
|
|
254 |
by (asm_simp_tac (simpset() addsimps [hcomplex_divide_eq_eq, hcomplex_eq_divide_eq,
|
|
255 |
hcomplex_mult_eq_cancel2]) 1);
|
|
256 |
qed "hcomplex_divide_eq_cancel2";
|
|
257 |
|
|
258 |
Goal "(k/m = k/n) = (k = 0 | m = (n::hcomplex))";
|
|
259 |
by (case_tac "m=0 | n = 0" 1);
|
|
260 |
by (auto_tac (claset(),
|
|
261 |
simpset() addsimps [HCOMPLEX_DIVIDE_ZERO, hcomplex_divide_eq_eq,
|
|
262 |
hcomplex_eq_divide_eq, hcomplex_mult_eq_cancel1]));
|
|
263 |
qed "hcomplex_divide_eq_cancel1";
|
|
264 |
|
|
265 |
(** Division by 1, -1 **)
|
|
266 |
|
|
267 |
Goal "(x::hcomplex)/1 = x";
|
|
268 |
by (simp_tac (simpset() addsimps [hcomplex_divide_def]) 1);
|
|
269 |
qed "hcomplex_divide_1";
|
|
270 |
Addsimps [hcomplex_divide_1];
|
|
271 |
|
|
272 |
Goal "x/-1 = -(x::hcomplex)";
|
|
273 |
by (Simp_tac 1);
|
|
274 |
qed "hcomplex_divide_minus1";
|
|
275 |
Addsimps [hcomplex_divide_minus1];
|
|
276 |
|
|
277 |
Goal "-1/(x::hcomplex) = - (1/x)";
|
|
278 |
by (simp_tac (simpset() addsimps [hcomplex_divide_def, hcomplex_minus_inverse]) 1);
|
|
279 |
qed "hcomplex_minus1_divide";
|
|
280 |
Addsimps [hcomplex_minus1_divide];
|
|
281 |
|
|
282 |
|
|
283 |
Goal "(x = - y) = (y = - (x::hcomplex))";
|
|
284 |
by Auto_tac;
|
|
285 |
qed "hcomplex_equation_minus";
|
|
286 |
|
|
287 |
Goal "(- x = y) = (- (y::hcomplex) = x)";
|
|
288 |
by Auto_tac;
|
|
289 |
qed "hcomplex_minus_equation";
|
|
290 |
|
|
291 |
Goal "(x + - a = (0::hcomplex)) = (x=a)";
|
|
292 |
by (simp_tac (simpset() addsimps [hcomplex_diff_eq_eq,symmetric hcomplex_diff_def]) 1);
|
|
293 |
qed "hcomplex_add_minus_iff";
|
|
294 |
Addsimps [hcomplex_add_minus_iff];
|
|
295 |
|
|
296 |
Goal "(-b = -a) = (b = (a::hcomplex))";
|
|
297 |
by Auto_tac;
|
|
298 |
by (etac ( inj_hcomplex_minus RS injD) 1);
|
|
299 |
qed "hcomplex_minus_eq_cancel";
|
|
300 |
Addsimps [hcomplex_minus_eq_cancel];
|
|
301 |
|
|
302 |
(*Distributive laws for literals*)
|
|
303 |
Addsimps (map (inst "w" "number_of ?v")
|
|
304 |
[hcomplex_add_mult_distrib, hcomplex_add_mult_distrib2,
|
|
305 |
hcomplex_diff_mult_distrib, hcomplex_diff_mult_distrib2]);
|
|
306 |
|
|
307 |
Addsimps [inst "x" "number_of ?v" hcomplex_equation_minus];
|
|
308 |
|
|
309 |
Addsimps [inst "y" "number_of ?v" hcomplex_minus_equation];
|
|
310 |
|
|
311 |
Goal "(x+y = (0::hcomplex)) = (y = -x)";
|
|
312 |
by Auto_tac;
|
|
313 |
by (dtac (sym RS (hcomplex_diff_eq_eq RS iffD2)) 1);
|
|
314 |
by Auto_tac;
|
|
315 |
qed "hcomplex_add_eq_0_iff";
|
|
316 |
AddIffs [hcomplex_add_eq_0_iff];
|
|
317 |
|
|
318 |
Goalw [hcomplex_diff_def]"-(x-y) = y - (x::hcomplex)";
|
|
319 |
by (auto_tac (claset(),simpset() addsimps [hcomplex_add_commute]));
|
|
320 |
qed "hcomplex_minus_diff_eq";
|
|
321 |
Addsimps [hcomplex_minus_diff_eq];
|
|
322 |
|
|
323 |
Addsimps [inst "x" "number_of ?w" hcomplex_inverse_eq_divide];
|
|
324 |
|
|
325 |
Goal "[|(x::hcomplex) ~= 0; y ~= 0 |] \
|
|
326 |
\ ==> inverse(x) + inverse(y) = (x + y)*inverse(x*y)";
|
|
327 |
by (asm_full_simp_tac (simpset() addsimps [hcomplex_inverse_distrib,
|
|
328 |
hcomplex_add_mult_distrib,hcomplex_mult_assoc RS sym]) 1);
|
|
329 |
qed "hcomplex_inverse_add";
|
|
330 |
|
|
331 |
Addsimps [hcomplex_of_complex_zero,hcomplex_of_complex_one];
|