src/HOL/Complex.thy
 changeset 28952 15a4b2cf8c34 parent 28944 e27abf0db984 child 29233 ce6d35a0bed6
```     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/HOL/Complex.thy	Wed Dec 03 15:58:44 2008 +0100
1.3 @@ -0,0 +1,718 @@
1.4 +(*  Title:       Complex.thy
1.5 +    Author:      Jacques D. Fleuriot
1.6 +    Copyright:   2001 University of Edinburgh
1.7 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
1.8 +*)
1.9 +
1.10 +header {* Complex Numbers: Rectangular and Polar Representations *}
1.11 +
1.12 +theory Complex
1.13 +imports Transcendental
1.14 +begin
1.15 +
1.16 +datatype complex = Complex real real
1.17 +
1.18 +primrec
1.19 +  Re :: "complex \<Rightarrow> real"
1.20 +where
1.21 +  Re: "Re (Complex x y) = x"
1.22 +
1.23 +primrec
1.24 +  Im :: "complex \<Rightarrow> real"
1.25 +where
1.26 +  Im: "Im (Complex x y) = y"
1.27 +
1.28 +lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
1.29 +  by (induct z) simp
1.30 +
1.31 +lemma complex_equality [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y"
1.32 +  by (induct x, induct y) simp
1.33 +
1.34 +lemma expand_complex_eq: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y"
1.35 +  by (induct x, induct y) simp
1.36 +
1.37 +lemmas complex_Re_Im_cancel_iff = expand_complex_eq
1.38 +
1.39 +
1.40 +subsection {* Addition and Subtraction *}
1.41 +
1.43 +begin
1.44 +
1.45 +definition
1.46 +  complex_zero_def: "0 = Complex 0 0"
1.47 +
1.48 +definition
1.49 +  complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)"
1.50 +
1.51 +definition
1.52 +  complex_minus_def: "- x = Complex (- Re x) (- Im x)"
1.53 +
1.54 +definition
1.55 +  complex_diff_def: "x - (y\<Colon>complex) = x + - y"
1.56 +
1.57 +lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
1.58 +  by (simp add: complex_zero_def)
1.59 +
1.60 +lemma complex_Re_zero [simp]: "Re 0 = 0"
1.61 +  by (simp add: complex_zero_def)
1.62 +
1.63 +lemma complex_Im_zero [simp]: "Im 0 = 0"
1.64 +  by (simp add: complex_zero_def)
1.65 +
1.67 +  "Complex a b + Complex c d = Complex (a + c) (b + d)"
1.69 +
1.70 +lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y"
1.72 +
1.73 +lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y"
1.75 +
1.76 +lemma complex_minus [simp]:
1.77 +  "- (Complex a b) = Complex (- a) (- b)"
1.78 +  by (simp add: complex_minus_def)
1.79 +
1.80 +lemma complex_Re_minus [simp]: "Re (- x) = - Re x"
1.81 +  by (simp add: complex_minus_def)
1.82 +
1.83 +lemma complex_Im_minus [simp]: "Im (- x) = - Im x"
1.84 +  by (simp add: complex_minus_def)
1.85 +
1.86 +lemma complex_diff [simp]:
1.87 +  "Complex a b - Complex c d = Complex (a - c) (b - d)"
1.88 +  by (simp add: complex_diff_def)
1.89 +
1.90 +lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y"
1.91 +  by (simp add: complex_diff_def)
1.92 +
1.93 +lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y"
1.94 +  by (simp add: complex_diff_def)
1.95 +
1.96 +instance
1.98 +
1.99 +end
1.100 +
1.101 +
1.102 +
1.103 +subsection {* Multiplication and Division *}
1.104 +
1.105 +instantiation complex :: "{field, division_by_zero}"
1.106 +begin
1.107 +
1.108 +definition
1.109 +  complex_one_def: "1 = Complex 1 0"
1.110 +
1.111 +definition
1.112 +  complex_mult_def: "x * y =
1.113 +    Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)"
1.114 +
1.115 +definition
1.116 +  complex_inverse_def: "inverse x =
1.117 +    Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))"
1.118 +
1.119 +definition
1.120 +  complex_divide_def: "x / (y\<Colon>complex) = x * inverse y"
1.121 +
1.122 +lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)"
1.123 +  by (simp add: complex_one_def)
1.124 +
1.125 +lemma complex_Re_one [simp]: "Re 1 = 1"
1.126 +  by (simp add: complex_one_def)
1.127 +
1.128 +lemma complex_Im_one [simp]: "Im 1 = 0"
1.129 +  by (simp add: complex_one_def)
1.130 +
1.131 +lemma complex_mult [simp]:
1.132 +  "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)"
1.133 +  by (simp add: complex_mult_def)
1.134 +
1.135 +lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y"
1.136 +  by (simp add: complex_mult_def)
1.137 +
1.138 +lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y"
1.139 +  by (simp add: complex_mult_def)
1.140 +
1.141 +lemma complex_inverse [simp]:
1.142 +  "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))"
1.143 +  by (simp add: complex_inverse_def)
1.144 +
1.145 +lemma complex_Re_inverse:
1.146 +  "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
1.147 +  by (simp add: complex_inverse_def)
1.148 +
1.149 +lemma complex_Im_inverse:
1.150 +  "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
1.151 +  by (simp add: complex_inverse_def)
1.152 +
1.153 +instance
1.154 +  by intro_classes (simp_all add: complex_mult_def
1.155 +  right_distrib left_distrib right_diff_distrib left_diff_distrib
1.156 +  complex_inverse_def complex_divide_def
1.158 +  expand_complex_eq)
1.159 +
1.160 +end
1.161 +
1.162 +
1.163 +subsection {* Exponentiation *}
1.164 +
1.165 +instantiation complex :: recpower
1.166 +begin
1.167 +
1.168 +primrec power_complex where
1.169 +  complexpow_0:     "z ^ 0     = (1\<Colon>complex)"
1.170 +  | complexpow_Suc: "z ^ Suc n = (z\<Colon>complex) * z ^ n"
1.171 +
1.172 +instance by intro_classes simp_all
1.173 +
1.174 +end
1.175 +
1.176 +
1.177 +subsection {* Numerals and Arithmetic *}
1.178 +
1.179 +instantiation complex :: number_ring
1.180 +begin
1.181 +
1.182 +definition number_of_complex where
1.183 +  complex_number_of_def: "number_of w = (of_int w \<Colon> complex)"
1.184 +
1.185 +instance
1.186 +  by intro_classes (simp only: complex_number_of_def)
1.187 +
1.188 +end
1.189 +
1.190 +lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n"
1.191 +by (induct n) simp_all
1.192 +
1.193 +lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0"
1.194 +by (induct n) simp_all
1.195 +
1.196 +lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z"
1.197 +by (cases z rule: int_diff_cases) simp
1.198 +
1.199 +lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
1.200 +by (cases z rule: int_diff_cases) simp
1.201 +
1.202 +lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v"
1.203 +unfolding number_of_eq by (rule complex_Re_of_int)
1.204 +
1.205 +lemma complex_Im_number_of [simp]: "Im (number_of v) = 0"
1.206 +unfolding number_of_eq by (rule complex_Im_of_int)
1.207 +
1.208 +lemma Complex_eq_number_of [simp]:
1.209 +  "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)"
1.211 +
1.212 +
1.213 +subsection {* Scalar Multiplication *}
1.214 +
1.215 +instantiation complex :: real_field
1.216 +begin
1.217 +
1.218 +definition
1.219 +  complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)"
1.220 +
1.221 +lemma complex_scaleR [simp]:
1.222 +  "scaleR r (Complex a b) = Complex (r * a) (r * b)"
1.223 +  unfolding complex_scaleR_def by simp
1.224 +
1.225 +lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x"
1.226 +  unfolding complex_scaleR_def by simp
1.227 +
1.228 +lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x"
1.229 +  unfolding complex_scaleR_def by simp
1.230 +
1.231 +instance
1.232 +proof
1.233 +  fix a b :: real and x y :: complex
1.234 +  show "scaleR a (x + y) = scaleR a x + scaleR a y"
1.235 +    by (simp add: expand_complex_eq right_distrib)
1.236 +  show "scaleR (a + b) x = scaleR a x + scaleR b x"
1.237 +    by (simp add: expand_complex_eq left_distrib)
1.238 +  show "scaleR a (scaleR b x) = scaleR (a * b) x"
1.239 +    by (simp add: expand_complex_eq mult_assoc)
1.240 +  show "scaleR 1 x = x"
1.241 +    by (simp add: expand_complex_eq)
1.242 +  show "scaleR a x * y = scaleR a (x * y)"
1.243 +    by (simp add: expand_complex_eq ring_simps)
1.244 +  show "x * scaleR a y = scaleR a (x * y)"
1.245 +    by (simp add: expand_complex_eq ring_simps)
1.246 +qed
1.247 +
1.248 +end
1.249 +
1.250 +
1.251 +subsection{* Properties of Embedding from Reals *}
1.252 +
1.253 +abbreviation
1.254 +  complex_of_real :: "real \<Rightarrow> complex" where
1.255 +    "complex_of_real \<equiv> of_real"
1.256 +
1.257 +lemma complex_of_real_def: "complex_of_real r = Complex r 0"
1.258 +by (simp add: of_real_def complex_scaleR_def)
1.259 +
1.260 +lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
1.262 +
1.263 +lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
1.265 +
1.267 +     "Complex x y + complex_of_real r = Complex (x+r) y"
1.269 +
1.271 +     "complex_of_real r + Complex x y = Complex (r+x) y"
1.273 +
1.274 +lemma Complex_mult_complex_of_real:
1.275 +     "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
1.277 +
1.278 +lemma complex_of_real_mult_Complex:
1.279 +     "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
1.281 +
1.282 +
1.283 +subsection {* Vector Norm *}
1.284 +
1.285 +instantiation complex :: real_normed_field
1.286 +begin
1.287 +
1.288 +definition
1.289 +  complex_norm_def: "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
1.290 +
1.291 +abbreviation
1.292 +  cmod :: "complex \<Rightarrow> real" where
1.293 +  "cmod \<equiv> norm"
1.294 +
1.295 +definition
1.296 +  complex_sgn_def: "sgn x = x /\<^sub>R cmod x"
1.297 +
1.298 +lemmas cmod_def = complex_norm_def
1.299 +
1.300 +lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
1.301 +  by (simp add: complex_norm_def)
1.302 +
1.303 +instance
1.304 +proof
1.305 +  fix r :: real and x y :: complex
1.306 +  show "0 \<le> norm x"
1.307 +    by (induct x) simp
1.308 +  show "(norm x = 0) = (x = 0)"
1.309 +    by (induct x) simp
1.310 +  show "norm (x + y) \<le> norm x + norm y"
1.311 +    by (induct x, induct y)
1.313 +  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
1.314 +    by (induct x)
1.315 +       (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult)
1.316 +  show "norm (x * y) = norm x * norm y"
1.317 +    by (induct x, induct y)
1.318 +       (simp add: real_sqrt_mult [symmetric] power2_eq_square ring_simps)
1.319 +  show "sgn x = x /\<^sub>R cmod x" by(simp add: complex_sgn_def)
1.320 +qed
1.321 +
1.322 +end
1.323 +
1.324 +lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
1.325 +by simp
1.326 +
1.327 +lemma cmod_complex_polar [simp]:
1.328 +     "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
1.330 +
1.331 +lemma complex_Re_le_cmod: "Re x \<le> cmod x"
1.332 +unfolding complex_norm_def
1.333 +by (rule real_sqrt_sum_squares_ge1)
1.334 +
1.335 +lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
1.336 +by (rule order_trans [OF _ norm_ge_zero], simp)
1.337 +
1.338 +lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
1.339 +by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
1.340 +
1.341 +lemmas real_sum_squared_expand = power2_sum [where 'a=real]
1.342 +
1.343 +lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x"
1.344 +by (cases x) simp
1.345 +
1.346 +lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x"
1.347 +by (cases x) simp
1.348 +
1.349 +subsection {* Completeness of the Complexes *}
1.350 +
1.351 +interpretation Re: bounded_linear ["Re"]
1.352 +apply (unfold_locales, simp, simp)
1.353 +apply (rule_tac x=1 in exI)
1.355 +done
1.356 +
1.357 +interpretation Im: bounded_linear ["Im"]
1.358 +apply (unfold_locales, simp, simp)
1.359 +apply (rule_tac x=1 in exI)
1.361 +done
1.362 +
1.363 +lemma LIMSEQ_Complex:
1.364 +  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. Complex (X n) (Y n)) ----> Complex a b"
1.365 +apply (rule LIMSEQ_I)
1.366 +apply (subgoal_tac "0 < r / sqrt 2")
1.367 +apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
1.368 +apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
1.369 +apply (rename_tac M N, rule_tac x="max M N" in exI, safe)
1.372 +done
1.373 +
1.374 +instance complex :: banach
1.375 +proof
1.376 +  fix X :: "nat \<Rightarrow> complex"
1.377 +  assume X: "Cauchy X"
1.378 +  from Re.Cauchy [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))"
1.379 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
1.380 +  from Im.Cauchy [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))"
1.381 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
1.382 +  have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))"
1.383 +    using LIMSEQ_Complex [OF 1 2] by simp
1.384 +  thus "convergent X"
1.385 +    by (rule convergentI)
1.386 +qed
1.387 +
1.388 +
1.389 +subsection {* The Complex Number @{term "\<i>"} *}
1.390 +
1.391 +definition
1.392 +  "ii" :: complex  ("\<i>") where
1.393 +  i_def: "ii \<equiv> Complex 0 1"
1.394 +
1.395 +lemma complex_Re_i [simp]: "Re ii = 0"
1.397 +
1.398 +lemma complex_Im_i [simp]: "Im ii = 1"
1.400 +
1.401 +lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
1.403 +
1.404 +lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
1.406 +
1.407 +lemma complex_i_not_one [simp]: "ii \<noteq> 1"
1.409 +
1.410 +lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w"
1.412 +
1.413 +lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a"
1.415 +
1.416 +lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a"
1.418 +
1.419 +lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
1.420 +by (simp add: i_def complex_of_real_def)
1.421 +
1.422 +lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
1.423 +by (simp add: i_def complex_of_real_def)
1.424 +
1.425 +lemma i_squared [simp]: "ii * ii = -1"
1.427 +
1.428 +lemma power2_i [simp]: "ii\<twosuperior> = -1"
1.430 +
1.431 +lemma inverse_i [simp]: "inverse ii = - ii"
1.432 +by (rule inverse_unique, simp)
1.433 +
1.434 +
1.435 +subsection {* Complex Conjugation *}
1.436 +
1.437 +definition
1.438 +  cnj :: "complex \<Rightarrow> complex" where
1.439 +  "cnj z = Complex (Re z) (- Im z)"
1.440 +
1.441 +lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)"
1.443 +
1.444 +lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x"
1.446 +
1.447 +lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x"
1.449 +
1.450 +lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
1.452 +
1.453 +lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
1.455 +
1.456 +lemma complex_cnj_zero [simp]: "cnj 0 = 0"
1.458 +
1.459 +lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
1.461 +
1.462 +lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y"
1.464 +
1.465 +lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y"
1.467 +
1.468 +lemma complex_cnj_minus: "cnj (- x) = - cnj x"
1.470 +
1.471 +lemma complex_cnj_one [simp]: "cnj 1 = 1"
1.473 +
1.474 +lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y"
1.476 +
1.477 +lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)"
1.479 +
1.480 +lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y"
1.481 +by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
1.482 +
1.483 +lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n"
1.484 +by (induct n, simp_all add: complex_cnj_mult)
1.485 +
1.486 +lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n"
1.488 +
1.489 +lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z"
1.491 +
1.492 +lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w"
1.494 +
1.495 +lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)"
1.497 +
1.498 +lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
1.500 +
1.501 +lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x"
1.503 +
1.504 +lemma complex_cnj_i [simp]: "cnj ii = - ii"
1.506 +
1.507 +lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)"
1.509 +
1.510 +lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii"
1.512 +
1.513 +lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
1.514 +by (simp add: expand_complex_eq power2_eq_square)
1.515 +
1.516 +lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
1.517 +by (simp add: norm_mult power2_eq_square)
1.518 +
1.519 +interpretation cnj: bounded_linear ["cnj"]
1.520 +apply (unfold_locales)
1.522 +apply (rule complex_cnj_scaleR)
1.523 +apply (rule_tac x=1 in exI, simp)
1.524 +done
1.525 +
1.526 +
1.527 +subsection{*The Functions @{term sgn} and @{term arg}*}
1.528 +
1.529 +text {*------------ Argand -------------*}
1.530 +
1.531 +definition
1.532 +  arg :: "complex => real" where
1.533 +  "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
1.534 +
1.535 +lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
1.536 +by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute)
1.537 +
1.538 +lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
1.539 +by (simp add: i_def complex_of_real_def)
1.540 +
1.541 +lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
1.542 +by (simp add: i_def complex_one_def)
1.543 +
1.544 +lemma complex_eq_cancel_iff2 [simp]:
1.545 +     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
1.547 +
1.548 +lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
1.549 +by (simp add: complex_sgn_def divide_inverse)
1.550 +
1.551 +lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
1.552 +by (simp add: complex_sgn_def divide_inverse)
1.553 +
1.554 +lemma complex_inverse_complex_split:
1.555 +     "inverse(complex_of_real x + ii * complex_of_real y) =
1.556 +      complex_of_real(x/(x ^ 2 + y ^ 2)) -
1.557 +      ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
1.558 +by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
1.559 +
1.560 +(*----------------------------------------------------------------------------*)
1.561 +(* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
1.562 +(* many of the theorems are not used - so should they be kept?                *)
1.563 +(*----------------------------------------------------------------------------*)
1.564 +
1.565 +lemma cos_arg_i_mult_zero_pos:
1.566 +   "0 < y ==> cos (arg(Complex 0 y)) = 0"
1.567 +apply (simp add: arg_def abs_if)
1.568 +apply (rule_tac a = "pi/2" in someI2, auto)
1.569 +apply (rule order_less_trans [of _ 0], auto)
1.570 +done
1.571 +
1.572 +lemma cos_arg_i_mult_zero_neg:
1.573 +   "y < 0 ==> cos (arg(Complex 0 y)) = 0"
1.574 +apply (simp add: arg_def abs_if)
1.575 +apply (rule_tac a = "- pi/2" in someI2, auto)
1.576 +apply (rule order_trans [of _ 0], auto)
1.577 +done
1.578 +
1.579 +lemma cos_arg_i_mult_zero [simp]:
1.580 +     "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
1.581 +by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
1.582 +
1.583 +
1.584 +subsection{*Finally! Polar Form for Complex Numbers*}
1.585 +
1.586 +definition
1.587 +
1.588 +  (* abbreviation for (cos a + i sin a) *)
1.589 +  cis :: "real => complex" where
1.590 +  "cis a = Complex (cos a) (sin a)"
1.591 +
1.592 +definition
1.593 +  (* abbreviation for r*(cos a + i sin a) *)
1.594 +  rcis :: "[real, real] => complex" where
1.595 +  "rcis r a = complex_of_real r * cis a"
1.596 +
1.597 +definition
1.598 +  (* e ^ (x + iy) *)
1.599 +  expi :: "complex => complex" where
1.600 +  "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
1.601 +
1.602 +lemma complex_split_polar:
1.603 +     "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
1.604 +apply (induct z)
1.605 +apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
1.606 +done
1.607 +
1.608 +lemma rcis_Ex: "\<exists>r a. z = rcis r a"
1.609 +apply (induct z)
1.610 +apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
1.611 +done
1.612 +
1.613 +lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
1.614 +by (simp add: rcis_def cis_def)
1.615 +
1.616 +lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
1.617 +by (simp add: rcis_def cis_def)
1.618 +
1.619 +lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
1.620 +proof -
1.621 +  have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
1.622 +    by (simp only: power_mult_distrib right_distrib)
1.623 +  thus ?thesis by simp
1.624 +qed
1.625 +
1.626 +lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
1.628 +
1.629 +lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
1.630 +by (simp add: cmod_def power2_eq_square)
1.631 +
1.632 +lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
1.633 +by simp
1.634 +
1.635 +
1.636 +(*---------------------------------------------------------------------------*)
1.637 +(*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
1.638 +(*---------------------------------------------------------------------------*)
1.639 +
1.640 +lemma cis_rcis_eq: "cis a = rcis 1 a"
1.642 +
1.643 +lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
1.645 +              complex_of_real_def)
1.646 +
1.647 +lemma cis_mult: "cis a * cis b = cis (a + b)"
1.648 +by (simp add: cis_rcis_eq rcis_mult)
1.649 +
1.650 +lemma cis_zero [simp]: "cis 0 = 1"
1.651 +by (simp add: cis_def complex_one_def)
1.652 +
1.653 +lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
1.655 +
1.656 +lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
1.658 +
1.659 +lemma complex_of_real_minus_one:
1.660 +   "complex_of_real (-(1::real)) = -(1::complex)"
1.661 +by (simp add: complex_of_real_def complex_one_def)
1.662 +
1.663 +lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
1.664 +by (simp add: mult_assoc [symmetric])
1.665 +
1.666 +
1.667 +lemma cis_real_of_nat_Suc_mult:
1.668 +   "cis (real (Suc n) * a) = cis a * cis (real n * a)"
1.670 +
1.671 +lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
1.672 +apply (induct_tac "n")
1.673 +apply (auto simp add: cis_real_of_nat_Suc_mult)
1.674 +done
1.675 +
1.676 +lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
1.677 +by (simp add: rcis_def power_mult_distrib DeMoivre)
1.678 +
1.679 +lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
1.680 +by (simp add: cis_def complex_inverse_complex_split diff_minus)
1.681 +
1.682 +lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
1.683 +by (simp add: divide_inverse rcis_def)
1.684 +
1.685 +lemma cis_divide: "cis a / cis b = cis (a - b)"
1.686 +by (simp add: complex_divide_def cis_mult real_diff_def)
1.687 +
1.688 +lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
1.690 +apply (case_tac "r2=0", simp)
1.691 +apply (simp add: rcis_inverse rcis_mult real_diff_def)
1.692 +done
1.693 +
1.694 +lemma Re_cis [simp]: "Re(cis a) = cos a"
1.696 +
1.697 +lemma Im_cis [simp]: "Im(cis a) = sin a"
1.699 +
1.700 +lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
1.701 +by (auto simp add: DeMoivre)
1.702 +
1.703 +lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
1.704 +by (auto simp add: DeMoivre)
1.705 +
1.706 +lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
1.708 +
1.709 +lemma expi_zero [simp]: "expi (0::complex) = 1"