1 (* Title: Complex.thy |
|
2 ID: $Id$ |
|
3 Author: Jacques D. Fleuriot |
|
4 Copyright: 2001 University of Edinburgh |
|
5 Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4 |
|
6 *) |
|
7 |
|
8 header {* Complex Numbers: Rectangular and Polar Representations *} |
|
9 |
|
10 theory Complex |
|
11 imports "../Hyperreal/Transcendental" |
|
12 begin |
|
13 |
|
14 datatype complex = Complex real real |
|
15 |
|
16 primrec |
|
17 Re :: "complex \<Rightarrow> real" |
|
18 where |
|
19 Re: "Re (Complex x y) = x" |
|
20 |
|
21 primrec |
|
22 Im :: "complex \<Rightarrow> real" |
|
23 where |
|
24 Im: "Im (Complex x y) = y" |
|
25 |
|
26 lemma complex_surj [simp]: "Complex (Re z) (Im z) = z" |
|
27 by (induct z) simp |
|
28 |
|
29 lemma complex_equality [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y" |
|
30 by (induct x, induct y) simp |
|
31 |
|
32 lemma expand_complex_eq: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y" |
|
33 by (induct x, induct y) simp |
|
34 |
|
35 lemmas complex_Re_Im_cancel_iff = expand_complex_eq |
|
36 |
|
37 |
|
38 subsection {* Addition and Subtraction *} |
|
39 |
|
40 instantiation complex :: ab_group_add |
|
41 begin |
|
42 |
|
43 definition |
|
44 complex_zero_def: "0 = Complex 0 0" |
|
45 |
|
46 definition |
|
47 complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)" |
|
48 |
|
49 definition |
|
50 complex_minus_def: "- x = Complex (- Re x) (- Im x)" |
|
51 |
|
52 definition |
|
53 complex_diff_def: "x - (y\<Colon>complex) = x + - y" |
|
54 |
|
55 lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0" |
|
56 by (simp add: complex_zero_def) |
|
57 |
|
58 lemma complex_Re_zero [simp]: "Re 0 = 0" |
|
59 by (simp add: complex_zero_def) |
|
60 |
|
61 lemma complex_Im_zero [simp]: "Im 0 = 0" |
|
62 by (simp add: complex_zero_def) |
|
63 |
|
64 lemma complex_add [simp]: |
|
65 "Complex a b + Complex c d = Complex (a + c) (b + d)" |
|
66 by (simp add: complex_add_def) |
|
67 |
|
68 lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y" |
|
69 by (simp add: complex_add_def) |
|
70 |
|
71 lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y" |
|
72 by (simp add: complex_add_def) |
|
73 |
|
74 lemma complex_minus [simp]: |
|
75 "- (Complex a b) = Complex (- a) (- b)" |
|
76 by (simp add: complex_minus_def) |
|
77 |
|
78 lemma complex_Re_minus [simp]: "Re (- x) = - Re x" |
|
79 by (simp add: complex_minus_def) |
|
80 |
|
81 lemma complex_Im_minus [simp]: "Im (- x) = - Im x" |
|
82 by (simp add: complex_minus_def) |
|
83 |
|
84 lemma complex_diff [simp]: |
|
85 "Complex a b - Complex c d = Complex (a - c) (b - d)" |
|
86 by (simp add: complex_diff_def) |
|
87 |
|
88 lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y" |
|
89 by (simp add: complex_diff_def) |
|
90 |
|
91 lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y" |
|
92 by (simp add: complex_diff_def) |
|
93 |
|
94 instance |
|
95 by intro_classes (simp_all add: complex_add_def complex_diff_def) |
|
96 |
|
97 end |
|
98 |
|
99 |
|
100 |
|
101 subsection {* Multiplication and Division *} |
|
102 |
|
103 instantiation complex :: "{field, division_by_zero}" |
|
104 begin |
|
105 |
|
106 definition |
|
107 complex_one_def: "1 = Complex 1 0" |
|
108 |
|
109 definition |
|
110 complex_mult_def: "x * y = |
|
111 Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)" |
|
112 |
|
113 definition |
|
114 complex_inverse_def: "inverse x = |
|
115 Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))" |
|
116 |
|
117 definition |
|
118 complex_divide_def: "x / (y\<Colon>complex) = x * inverse y" |
|
119 |
|
120 lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)" |
|
121 by (simp add: complex_one_def) |
|
122 |
|
123 lemma complex_Re_one [simp]: "Re 1 = 1" |
|
124 by (simp add: complex_one_def) |
|
125 |
|
126 lemma complex_Im_one [simp]: "Im 1 = 0" |
|
127 by (simp add: complex_one_def) |
|
128 |
|
129 lemma complex_mult [simp]: |
|
130 "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)" |
|
131 by (simp add: complex_mult_def) |
|
132 |
|
133 lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y" |
|
134 by (simp add: complex_mult_def) |
|
135 |
|
136 lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y" |
|
137 by (simp add: complex_mult_def) |
|
138 |
|
139 lemma complex_inverse [simp]: |
|
140 "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))" |
|
141 by (simp add: complex_inverse_def) |
|
142 |
|
143 lemma complex_Re_inverse: |
|
144 "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)" |
|
145 by (simp add: complex_inverse_def) |
|
146 |
|
147 lemma complex_Im_inverse: |
|
148 "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)" |
|
149 by (simp add: complex_inverse_def) |
|
150 |
|
151 instance |
|
152 by intro_classes (simp_all add: complex_mult_def |
|
153 right_distrib left_distrib right_diff_distrib left_diff_distrib |
|
154 complex_inverse_def complex_divide_def |
|
155 power2_eq_square add_divide_distrib [symmetric] |
|
156 expand_complex_eq) |
|
157 |
|
158 end |
|
159 |
|
160 |
|
161 subsection {* Exponentiation *} |
|
162 |
|
163 instantiation complex :: recpower |
|
164 begin |
|
165 |
|
166 primrec power_complex where |
|
167 complexpow_0: "z ^ 0 = (1\<Colon>complex)" |
|
168 | complexpow_Suc: "z ^ Suc n = (z\<Colon>complex) * z ^ n" |
|
169 |
|
170 instance by intro_classes simp_all |
|
171 |
|
172 end |
|
173 |
|
174 |
|
175 subsection {* Numerals and Arithmetic *} |
|
176 |
|
177 instantiation complex :: number_ring |
|
178 begin |
|
179 |
|
180 definition number_of_complex where |
|
181 complex_number_of_def: "number_of w = (of_int w \<Colon> complex)" |
|
182 |
|
183 instance |
|
184 by intro_classes (simp only: complex_number_of_def) |
|
185 |
|
186 end |
|
187 |
|
188 lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n" |
|
189 by (induct n) simp_all |
|
190 |
|
191 lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0" |
|
192 by (induct n) simp_all |
|
193 |
|
194 lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z" |
|
195 by (cases z rule: int_diff_cases) simp |
|
196 |
|
197 lemma complex_Im_of_int [simp]: "Im (of_int z) = 0" |
|
198 by (cases z rule: int_diff_cases) simp |
|
199 |
|
200 lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v" |
|
201 unfolding number_of_eq by (rule complex_Re_of_int) |
|
202 |
|
203 lemma complex_Im_number_of [simp]: "Im (number_of v) = 0" |
|
204 unfolding number_of_eq by (rule complex_Im_of_int) |
|
205 |
|
206 lemma Complex_eq_number_of [simp]: |
|
207 "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)" |
|
208 by (simp add: expand_complex_eq) |
|
209 |
|
210 |
|
211 subsection {* Scalar Multiplication *} |
|
212 |
|
213 instantiation complex :: real_field |
|
214 begin |
|
215 |
|
216 definition |
|
217 complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)" |
|
218 |
|
219 lemma complex_scaleR [simp]: |
|
220 "scaleR r (Complex a b) = Complex (r * a) (r * b)" |
|
221 unfolding complex_scaleR_def by simp |
|
222 |
|
223 lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x" |
|
224 unfolding complex_scaleR_def by simp |
|
225 |
|
226 lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x" |
|
227 unfolding complex_scaleR_def by simp |
|
228 |
|
229 instance |
|
230 proof |
|
231 fix a b :: real and x y :: complex |
|
232 show "scaleR a (x + y) = scaleR a x + scaleR a y" |
|
233 by (simp add: expand_complex_eq right_distrib) |
|
234 show "scaleR (a + b) x = scaleR a x + scaleR b x" |
|
235 by (simp add: expand_complex_eq left_distrib) |
|
236 show "scaleR a (scaleR b x) = scaleR (a * b) x" |
|
237 by (simp add: expand_complex_eq mult_assoc) |
|
238 show "scaleR 1 x = x" |
|
239 by (simp add: expand_complex_eq) |
|
240 show "scaleR a x * y = scaleR a (x * y)" |
|
241 by (simp add: expand_complex_eq ring_simps) |
|
242 show "x * scaleR a y = scaleR a (x * y)" |
|
243 by (simp add: expand_complex_eq ring_simps) |
|
244 qed |
|
245 |
|
246 end |
|
247 |
|
248 |
|
249 subsection{* Properties of Embedding from Reals *} |
|
250 |
|
251 abbreviation |
|
252 complex_of_real :: "real \<Rightarrow> complex" where |
|
253 "complex_of_real \<equiv> of_real" |
|
254 |
|
255 lemma complex_of_real_def: "complex_of_real r = Complex r 0" |
|
256 by (simp add: of_real_def complex_scaleR_def) |
|
257 |
|
258 lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z" |
|
259 by (simp add: complex_of_real_def) |
|
260 |
|
261 lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0" |
|
262 by (simp add: complex_of_real_def) |
|
263 |
|
264 lemma Complex_add_complex_of_real [simp]: |
|
265 "Complex x y + complex_of_real r = Complex (x+r) y" |
|
266 by (simp add: complex_of_real_def) |
|
267 |
|
268 lemma complex_of_real_add_Complex [simp]: |
|
269 "complex_of_real r + Complex x y = Complex (r+x) y" |
|
270 by (simp add: complex_of_real_def) |
|
271 |
|
272 lemma Complex_mult_complex_of_real: |
|
273 "Complex x y * complex_of_real r = Complex (x*r) (y*r)" |
|
274 by (simp add: complex_of_real_def) |
|
275 |
|
276 lemma complex_of_real_mult_Complex: |
|
277 "complex_of_real r * Complex x y = Complex (r*x) (r*y)" |
|
278 by (simp add: complex_of_real_def) |
|
279 |
|
280 |
|
281 subsection {* Vector Norm *} |
|
282 |
|
283 instantiation complex :: real_normed_field |
|
284 begin |
|
285 |
|
286 definition |
|
287 complex_norm_def: "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)" |
|
288 |
|
289 abbreviation |
|
290 cmod :: "complex \<Rightarrow> real" where |
|
291 "cmod \<equiv> norm" |
|
292 |
|
293 definition |
|
294 complex_sgn_def: "sgn x = x /\<^sub>R cmod x" |
|
295 |
|
296 lemmas cmod_def = complex_norm_def |
|
297 |
|
298 lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)" |
|
299 by (simp add: complex_norm_def) |
|
300 |
|
301 instance |
|
302 proof |
|
303 fix r :: real and x y :: complex |
|
304 show "0 \<le> norm x" |
|
305 by (induct x) simp |
|
306 show "(norm x = 0) = (x = 0)" |
|
307 by (induct x) simp |
|
308 show "norm (x + y) \<le> norm x + norm y" |
|
309 by (induct x, induct y) |
|
310 (simp add: real_sqrt_sum_squares_triangle_ineq) |
|
311 show "norm (scaleR r x) = \<bar>r\<bar> * norm x" |
|
312 by (induct x) |
|
313 (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult) |
|
314 show "norm (x * y) = norm x * norm y" |
|
315 by (induct x, induct y) |
|
316 (simp add: real_sqrt_mult [symmetric] power2_eq_square ring_simps) |
|
317 show "sgn x = x /\<^sub>R cmod x" by(simp add: complex_sgn_def) |
|
318 qed |
|
319 |
|
320 end |
|
321 |
|
322 lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1" |
|
323 by simp |
|
324 |
|
325 lemma cmod_complex_polar [simp]: |
|
326 "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r" |
|
327 by (simp add: norm_mult) |
|
328 |
|
329 lemma complex_Re_le_cmod: "Re x \<le> cmod x" |
|
330 unfolding complex_norm_def |
|
331 by (rule real_sqrt_sum_squares_ge1) |
|
332 |
|
333 lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x" |
|
334 by (rule order_trans [OF _ norm_ge_zero], simp) |
|
335 |
|
336 lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a" |
|
337 by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp) |
|
338 |
|
339 lemmas real_sum_squared_expand = power2_sum [where 'a=real] |
|
340 |
|
341 lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x" |
|
342 by (cases x) simp |
|
343 |
|
344 lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x" |
|
345 by (cases x) simp |
|
346 |
|
347 subsection {* Completeness of the Complexes *} |
|
348 |
|
349 interpretation Re: bounded_linear ["Re"] |
|
350 apply (unfold_locales, simp, simp) |
|
351 apply (rule_tac x=1 in exI) |
|
352 apply (simp add: complex_norm_def) |
|
353 done |
|
354 |
|
355 interpretation Im: bounded_linear ["Im"] |
|
356 apply (unfold_locales, simp, simp) |
|
357 apply (rule_tac x=1 in exI) |
|
358 apply (simp add: complex_norm_def) |
|
359 done |
|
360 |
|
361 lemma LIMSEQ_Complex: |
|
362 "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. Complex (X n) (Y n)) ----> Complex a b" |
|
363 apply (rule LIMSEQ_I) |
|
364 apply (subgoal_tac "0 < r / sqrt 2") |
|
365 apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe) |
|
366 apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe) |
|
367 apply (rename_tac M N, rule_tac x="max M N" in exI, safe) |
|
368 apply (simp add: real_sqrt_sum_squares_less) |
|
369 apply (simp add: divide_pos_pos) |
|
370 done |
|
371 |
|
372 instance complex :: banach |
|
373 proof |
|
374 fix X :: "nat \<Rightarrow> complex" |
|
375 assume X: "Cauchy X" |
|
376 from Re.Cauchy [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))" |
|
377 by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff) |
|
378 from Im.Cauchy [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))" |
|
379 by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff) |
|
380 have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))" |
|
381 using LIMSEQ_Complex [OF 1 2] by simp |
|
382 thus "convergent X" |
|
383 by (rule convergentI) |
|
384 qed |
|
385 |
|
386 |
|
387 subsection {* The Complex Number @{term "\<i>"} *} |
|
388 |
|
389 definition |
|
390 "ii" :: complex ("\<i>") where |
|
391 i_def: "ii \<equiv> Complex 0 1" |
|
392 |
|
393 lemma complex_Re_i [simp]: "Re ii = 0" |
|
394 by (simp add: i_def) |
|
395 |
|
396 lemma complex_Im_i [simp]: "Im ii = 1" |
|
397 by (simp add: i_def) |
|
398 |
|
399 lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)" |
|
400 by (simp add: i_def) |
|
401 |
|
402 lemma complex_i_not_zero [simp]: "ii \<noteq> 0" |
|
403 by (simp add: expand_complex_eq) |
|
404 |
|
405 lemma complex_i_not_one [simp]: "ii \<noteq> 1" |
|
406 by (simp add: expand_complex_eq) |
|
407 |
|
408 lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w" |
|
409 by (simp add: expand_complex_eq) |
|
410 |
|
411 lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a" |
|
412 by (simp add: expand_complex_eq) |
|
413 |
|
414 lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a" |
|
415 by (simp add: expand_complex_eq) |
|
416 |
|
417 lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r" |
|
418 by (simp add: i_def complex_of_real_def) |
|
419 |
|
420 lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r" |
|
421 by (simp add: i_def complex_of_real_def) |
|
422 |
|
423 lemma i_squared [simp]: "ii * ii = -1" |
|
424 by (simp add: i_def) |
|
425 |
|
426 lemma power2_i [simp]: "ii\<twosuperior> = -1" |
|
427 by (simp add: power2_eq_square) |
|
428 |
|
429 lemma inverse_i [simp]: "inverse ii = - ii" |
|
430 by (rule inverse_unique, simp) |
|
431 |
|
432 |
|
433 subsection {* Complex Conjugation *} |
|
434 |
|
435 definition |
|
436 cnj :: "complex \<Rightarrow> complex" where |
|
437 "cnj z = Complex (Re z) (- Im z)" |
|
438 |
|
439 lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)" |
|
440 by (simp add: cnj_def) |
|
441 |
|
442 lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x" |
|
443 by (simp add: cnj_def) |
|
444 |
|
445 lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x" |
|
446 by (simp add: cnj_def) |
|
447 |
|
448 lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)" |
|
449 by (simp add: expand_complex_eq) |
|
450 |
|
451 lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z" |
|
452 by (simp add: cnj_def) |
|
453 |
|
454 lemma complex_cnj_zero [simp]: "cnj 0 = 0" |
|
455 by (simp add: expand_complex_eq) |
|
456 |
|
457 lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)" |
|
458 by (simp add: expand_complex_eq) |
|
459 |
|
460 lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y" |
|
461 by (simp add: expand_complex_eq) |
|
462 |
|
463 lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y" |
|
464 by (simp add: expand_complex_eq) |
|
465 |
|
466 lemma complex_cnj_minus: "cnj (- x) = - cnj x" |
|
467 by (simp add: expand_complex_eq) |
|
468 |
|
469 lemma complex_cnj_one [simp]: "cnj 1 = 1" |
|
470 by (simp add: expand_complex_eq) |
|
471 |
|
472 lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y" |
|
473 by (simp add: expand_complex_eq) |
|
474 |
|
475 lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)" |
|
476 by (simp add: complex_inverse_def) |
|
477 |
|
478 lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y" |
|
479 by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse) |
|
480 |
|
481 lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n" |
|
482 by (induct n, simp_all add: complex_cnj_mult) |
|
483 |
|
484 lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n" |
|
485 by (simp add: expand_complex_eq) |
|
486 |
|
487 lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z" |
|
488 by (simp add: expand_complex_eq) |
|
489 |
|
490 lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w" |
|
491 by (simp add: expand_complex_eq) |
|
492 |
|
493 lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)" |
|
494 by (simp add: expand_complex_eq) |
|
495 |
|
496 lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z" |
|
497 by (simp add: complex_norm_def) |
|
498 |
|
499 lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x" |
|
500 by (simp add: expand_complex_eq) |
|
501 |
|
502 lemma complex_cnj_i [simp]: "cnj ii = - ii" |
|
503 by (simp add: expand_complex_eq) |
|
504 |
|
505 lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)" |
|
506 by (simp add: expand_complex_eq) |
|
507 |
|
508 lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii" |
|
509 by (simp add: expand_complex_eq) |
|
510 |
|
511 lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)" |
|
512 by (simp add: expand_complex_eq power2_eq_square) |
|
513 |
|
514 lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>" |
|
515 by (simp add: norm_mult power2_eq_square) |
|
516 |
|
517 interpretation cnj: bounded_linear ["cnj"] |
|
518 apply (unfold_locales) |
|
519 apply (rule complex_cnj_add) |
|
520 apply (rule complex_cnj_scaleR) |
|
521 apply (rule_tac x=1 in exI, simp) |
|
522 done |
|
523 |
|
524 |
|
525 subsection{*The Functions @{term sgn} and @{term arg}*} |
|
526 |
|
527 text {*------------ Argand -------------*} |
|
528 |
|
529 definition |
|
530 arg :: "complex => real" where |
|
531 "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)" |
|
532 |
|
533 lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)" |
|
534 by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute) |
|
535 |
|
536 lemma i_mult_eq: "ii * ii = complex_of_real (-1)" |
|
537 by (simp add: i_def complex_of_real_def) |
|
538 |
|
539 lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)" |
|
540 by (simp add: i_def complex_one_def) |
|
541 |
|
542 lemma complex_eq_cancel_iff2 [simp]: |
|
543 "(Complex x y = complex_of_real xa) = (x = xa & y = 0)" |
|
544 by (simp add: complex_of_real_def) |
|
545 |
|
546 lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z" |
|
547 by (simp add: complex_sgn_def divide_inverse) |
|
548 |
|
549 lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z" |
|
550 by (simp add: complex_sgn_def divide_inverse) |
|
551 |
|
552 lemma complex_inverse_complex_split: |
|
553 "inverse(complex_of_real x + ii * complex_of_real y) = |
|
554 complex_of_real(x/(x ^ 2 + y ^ 2)) - |
|
555 ii * complex_of_real(y/(x ^ 2 + y ^ 2))" |
|
556 by (simp add: complex_of_real_def i_def diff_minus divide_inverse) |
|
557 |
|
558 (*----------------------------------------------------------------------------*) |
|
559 (* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *) |
|
560 (* many of the theorems are not used - so should they be kept? *) |
|
561 (*----------------------------------------------------------------------------*) |
|
562 |
|
563 lemma cos_arg_i_mult_zero_pos: |
|
564 "0 < y ==> cos (arg(Complex 0 y)) = 0" |
|
565 apply (simp add: arg_def abs_if) |
|
566 apply (rule_tac a = "pi/2" in someI2, auto) |
|
567 apply (rule order_less_trans [of _ 0], auto) |
|
568 done |
|
569 |
|
570 lemma cos_arg_i_mult_zero_neg: |
|
571 "y < 0 ==> cos (arg(Complex 0 y)) = 0" |
|
572 apply (simp add: arg_def abs_if) |
|
573 apply (rule_tac a = "- pi/2" in someI2, auto) |
|
574 apply (rule order_trans [of _ 0], auto) |
|
575 done |
|
576 |
|
577 lemma cos_arg_i_mult_zero [simp]: |
|
578 "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0" |
|
579 by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg) |
|
580 |
|
581 |
|
582 subsection{*Finally! Polar Form for Complex Numbers*} |
|
583 |
|
584 definition |
|
585 |
|
586 (* abbreviation for (cos a + i sin a) *) |
|
587 cis :: "real => complex" where |
|
588 "cis a = Complex (cos a) (sin a)" |
|
589 |
|
590 definition |
|
591 (* abbreviation for r*(cos a + i sin a) *) |
|
592 rcis :: "[real, real] => complex" where |
|
593 "rcis r a = complex_of_real r * cis a" |
|
594 |
|
595 definition |
|
596 (* e ^ (x + iy) *) |
|
597 expi :: "complex => complex" where |
|
598 "expi z = complex_of_real(exp (Re z)) * cis (Im z)" |
|
599 |
|
600 lemma complex_split_polar: |
|
601 "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))" |
|
602 apply (induct z) |
|
603 apply (auto simp add: polar_Ex complex_of_real_mult_Complex) |
|
604 done |
|
605 |
|
606 lemma rcis_Ex: "\<exists>r a. z = rcis r a" |
|
607 apply (induct z) |
|
608 apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex) |
|
609 done |
|
610 |
|
611 lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a" |
|
612 by (simp add: rcis_def cis_def) |
|
613 |
|
614 lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a" |
|
615 by (simp add: rcis_def cis_def) |
|
616 |
|
617 lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>" |
|
618 proof - |
|
619 have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)" |
|
620 by (simp only: power_mult_distrib right_distrib) |
|
621 thus ?thesis by simp |
|
622 qed |
|
623 |
|
624 lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r" |
|
625 by (simp add: rcis_def cis_def sin_cos_squared_add2_mult) |
|
626 |
|
627 lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))" |
|
628 by (simp add: cmod_def power2_eq_square) |
|
629 |
|
630 lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0" |
|
631 by simp |
|
632 |
|
633 |
|
634 (*---------------------------------------------------------------------------*) |
|
635 (* (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b) *) |
|
636 (*---------------------------------------------------------------------------*) |
|
637 |
|
638 lemma cis_rcis_eq: "cis a = rcis 1 a" |
|
639 by (simp add: rcis_def) |
|
640 |
|
641 lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)" |
|
642 by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib |
|
643 complex_of_real_def) |
|
644 |
|
645 lemma cis_mult: "cis a * cis b = cis (a + b)" |
|
646 by (simp add: cis_rcis_eq rcis_mult) |
|
647 |
|
648 lemma cis_zero [simp]: "cis 0 = 1" |
|
649 by (simp add: cis_def complex_one_def) |
|
650 |
|
651 lemma rcis_zero_mod [simp]: "rcis 0 a = 0" |
|
652 by (simp add: rcis_def) |
|
653 |
|
654 lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r" |
|
655 by (simp add: rcis_def) |
|
656 |
|
657 lemma complex_of_real_minus_one: |
|
658 "complex_of_real (-(1::real)) = -(1::complex)" |
|
659 by (simp add: complex_of_real_def complex_one_def) |
|
660 |
|
661 lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x" |
|
662 by (simp add: mult_assoc [symmetric]) |
|
663 |
|
664 |
|
665 lemma cis_real_of_nat_Suc_mult: |
|
666 "cis (real (Suc n) * a) = cis a * cis (real n * a)" |
|
667 by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib) |
|
668 |
|
669 lemma DeMoivre: "(cis a) ^ n = cis (real n * a)" |
|
670 apply (induct_tac "n") |
|
671 apply (auto simp add: cis_real_of_nat_Suc_mult) |
|
672 done |
|
673 |
|
674 lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)" |
|
675 by (simp add: rcis_def power_mult_distrib DeMoivre) |
|
676 |
|
677 lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)" |
|
678 by (simp add: cis_def complex_inverse_complex_split diff_minus) |
|
679 |
|
680 lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)" |
|
681 by (simp add: divide_inverse rcis_def) |
|
682 |
|
683 lemma cis_divide: "cis a / cis b = cis (a - b)" |
|
684 by (simp add: complex_divide_def cis_mult real_diff_def) |
|
685 |
|
686 lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)" |
|
687 apply (simp add: complex_divide_def) |
|
688 apply (case_tac "r2=0", simp) |
|
689 apply (simp add: rcis_inverse rcis_mult real_diff_def) |
|
690 done |
|
691 |
|
692 lemma Re_cis [simp]: "Re(cis a) = cos a" |
|
693 by (simp add: cis_def) |
|
694 |
|
695 lemma Im_cis [simp]: "Im(cis a) = sin a" |
|
696 by (simp add: cis_def) |
|
697 |
|
698 lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)" |
|
699 by (auto simp add: DeMoivre) |
|
700 |
|
701 lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)" |
|
702 by (auto simp add: DeMoivre) |
|
703 |
|
704 lemma expi_add: "expi(a + b) = expi(a) * expi(b)" |
|
705 by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac) |
|
706 |
|
707 lemma expi_zero [simp]: "expi (0::complex) = 1" |
|
708 by (simp add: expi_def) |
|
709 |
|
710 lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a" |
|
711 apply (insert rcis_Ex [of z]) |
|
712 apply (auto simp add: expi_def rcis_def mult_assoc [symmetric]) |
|
713 apply (rule_tac x = "ii * complex_of_real a" in exI, auto) |
|
714 done |
|
715 |
|
716 lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1" |
|
717 by (simp add: expi_def cis_def) |
|
718 |
|
719 end |
|