src/HOL/Complex/Complex.thy
author huffman
Mon May 14 18:03:25 2007 +0200 (2007-05-14)
changeset 22968 7134874437ac
parent 22956 617140080e6a
child 22972 3e96b98d37c6
permissions -rw-r--r--
tuned
     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 instance complex :: "{zero, one, plus, times, minus, inverse, power}" ..
    17 
    18 consts
    19   "ii"    :: complex    ("\<i>")
    20 
    21 consts Re :: "complex => real"
    22 primrec Re: "Re (Complex x y) = x"
    23 
    24 consts Im :: "complex => real"
    25 primrec Im: "Im (Complex x y) = y"
    26 
    27 lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
    28   by (induct z) simp
    29 
    30 defs (overloaded)
    31 
    32   complex_zero_def:
    33   "0 == Complex 0 0"
    34 
    35   complex_one_def:
    36   "1 == Complex 1 0"
    37 
    38   i_def: "ii == Complex 0 1"
    39 
    40   complex_minus_def: "- z == Complex (- Re z) (- Im z)"
    41 
    42   complex_inverse_def:
    43    "inverse z ==
    44     Complex (Re z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>)) (- Im z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>))"
    45 
    46   complex_add_def:
    47     "z + w == Complex (Re z + Re w) (Im z + Im w)"
    48 
    49   complex_diff_def:
    50     "z - w == z + - (w::complex)"
    51 
    52   complex_mult_def:
    53     "z * w == Complex (Re z * Re w - Im z * Im w) (Re z * Im w + Im z * Re w)"
    54 
    55   complex_divide_def: "w / (z::complex) == w * inverse z"
    56 
    57 
    58 lemma complex_equality [intro?]: "Re z = Re w ==> Im z = Im w ==> z = w"
    59   by (induct z, induct w) simp
    60 
    61 lemma complex_Re_Im_cancel_iff: "(w=z) = (Re(w) = Re(z) & Im(w) = Im(z))"
    62 by (induct w, induct z, simp)
    63 
    64 lemma complex_Re_zero [simp]: "Re 0 = 0"
    65 by (simp add: complex_zero_def)
    66 
    67 lemma complex_Im_zero [simp]: "Im 0 = 0"
    68 by (simp add: complex_zero_def)
    69 
    70 lemma Complex_eq_0 [simp]: "(Complex x y = 0) = (x = 0 \<and> y = 0)"
    71 by (simp add: complex_zero_def)
    72 
    73 lemma complex_Re_one [simp]: "Re 1 = 1"
    74 by (simp add: complex_one_def)
    75 
    76 lemma complex_Im_one [simp]: "Im 1 = 0"
    77 by (simp add: complex_one_def)
    78 
    79 lemma Complex_eq_1 [simp]: "(Complex x y = 1) = (x = 1 \<and> y = 0)"
    80 by (simp add: complex_one_def)
    81 
    82 lemma complex_Re_i [simp]: "Re(ii) = 0"
    83 by (simp add: i_def)
    84 
    85 lemma complex_Im_i [simp]: "Im(ii) = 1"
    86 by (simp add: i_def)
    87 
    88 lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
    89 by (simp add: i_def)
    90 
    91 
    92 subsection{*Unary Minus*}
    93 
    94 lemma complex_minus [simp]: "- (Complex x y) = Complex (-x) (-y)"
    95 by (simp add: complex_minus_def)
    96 
    97 lemma complex_Re_minus [simp]: "Re (-z) = - Re z"
    98 by (simp add: complex_minus_def)
    99 
   100 lemma complex_Im_minus [simp]: "Im (-z) = - Im z"
   101 by (simp add: complex_minus_def)
   102 
   103 
   104 subsection{*Addition*}
   105 
   106 lemma complex_add [simp]:
   107      "Complex x1 y1 + Complex x2 y2 = Complex (x1+x2) (y1+y2)"
   108 by (simp add: complex_add_def)
   109 
   110 lemma complex_Re_add [simp]: "Re(x + y) = Re(x) + Re(y)"
   111 by (simp add: complex_add_def)
   112 
   113 lemma complex_Im_add [simp]: "Im(x + y) = Im(x) + Im(y)"
   114 by (simp add: complex_add_def)
   115 
   116 lemma complex_add_commute: "(u::complex) + v = v + u"
   117 by (simp add: complex_add_def add_commute)
   118 
   119 lemma complex_add_assoc: "((u::complex) + v) + w = u + (v + w)"
   120 by (simp add: complex_add_def add_assoc)
   121 
   122 lemma complex_add_zero_left: "(0::complex) + z = z"
   123 by (simp add: complex_add_def complex_zero_def)
   124 
   125 lemma complex_add_zero_right: "z + (0::complex) = z"
   126 by (simp add: complex_add_def complex_zero_def)
   127 
   128 lemma complex_add_minus_left: "-z + z = (0::complex)"
   129 by (simp add: complex_add_def complex_minus_def complex_zero_def)
   130 
   131 lemma complex_diff:
   132       "Complex x1 y1 - Complex x2 y2 = Complex (x1-x2) (y1-y2)"
   133 by (simp add: complex_add_def complex_minus_def complex_diff_def)
   134 
   135 lemma complex_Re_diff [simp]: "Re(x - y) = Re(x) - Re(y)"
   136 by (simp add: complex_diff_def)
   137 
   138 lemma complex_Im_diff [simp]: "Im(x - y) = Im(x) - Im(y)"
   139 by (simp add: complex_diff_def)
   140 
   141 
   142 subsection{*Multiplication*}
   143 
   144 lemma complex_mult [simp]:
   145      "Complex x1 y1 * Complex x2 y2 = Complex (x1*x2 - y1*y2) (x1*y2 + y1*x2)"
   146 by (simp add: complex_mult_def)
   147 
   148 lemma complex_mult_commute: "(w::complex) * z = z * w"
   149 by (simp add: complex_mult_def mult_commute add_commute)
   150 
   151 lemma complex_mult_assoc: "((u::complex) * v) * w = u * (v * w)"
   152 by (simp add: complex_mult_def mult_ac add_ac
   153               right_diff_distrib right_distrib left_diff_distrib left_distrib)
   154 
   155 lemma complex_mult_one_left: "(1::complex) * z = z"
   156 by (simp add: complex_mult_def complex_one_def)
   157 
   158 lemma complex_mult_one_right: "z * (1::complex) = z"
   159 by (simp add: complex_mult_def complex_one_def)
   160 
   161 
   162 subsection{*Inverse*}
   163 
   164 lemma complex_inverse [simp]:
   165   "inverse (Complex x y) = Complex (x / (x\<twosuperior> + y\<twosuperior>)) (- y / (x\<twosuperior> + y\<twosuperior>))"
   166 by (simp add: complex_inverse_def)
   167 
   168 lemma complex_mult_inv_left: "z \<noteq> (0::complex) ==> inverse(z) * z = 1"
   169 apply (induct z)
   170 apply (simp add: power2_eq_square [symmetric] add_divide_distrib [symmetric])
   171 done
   172 
   173 
   174 subsection {* The field of complex numbers *}
   175 
   176 instance complex :: field
   177 proof
   178   fix z u v w :: complex
   179   show "(u + v) + w = u + (v + w)"
   180     by (rule complex_add_assoc)
   181   show "z + w = w + z"
   182     by (rule complex_add_commute)
   183   show "0 + z = z"
   184     by (rule complex_add_zero_left)
   185   show "-z + z = 0"
   186     by (rule complex_add_minus_left)
   187   show "z - w = z + -w"
   188     by (simp add: complex_diff_def)
   189   show "(u * v) * w = u * (v * w)"
   190     by (rule complex_mult_assoc)
   191   show "z * w = w * z"
   192     by (rule complex_mult_commute)
   193   show "1 * z = z"
   194     by (rule complex_mult_one_left)
   195   show "0 \<noteq> (1::complex)"
   196     by (simp add: complex_zero_def complex_one_def)
   197   show "(u + v) * w = u * w + v * w"
   198     by (simp add: complex_mult_def complex_add_def left_distrib 
   199                   diff_minus add_ac)
   200   show "z / w = z * inverse w"
   201     by (simp add: complex_divide_def)
   202   assume "w \<noteq> 0"
   203   thus "inverse w * w = 1"
   204     by (simp add: complex_mult_inv_left)
   205 qed
   206 
   207 instance complex :: division_by_zero
   208 proof
   209   show "inverse 0 = (0::complex)"
   210     by (simp add: complex_inverse_def complex_zero_def)
   211 qed
   212 
   213 
   214 subsection{*The real algebra of complex numbers*}
   215 
   216 instance complex :: scaleR ..
   217 
   218 defs (overloaded)
   219   complex_scaleR_def: "r *# x == Complex r 0 * x"
   220 
   221 instance complex :: real_field
   222 proof
   223   fix a b :: real
   224   fix x y :: complex
   225   show "a *# (x + y) = a *# x + a *# y"
   226     by (simp add: complex_scaleR_def right_distrib)
   227   show "(a + b) *# x = a *# x + b *# x"
   228     by (simp add: complex_scaleR_def left_distrib [symmetric])
   229   show "a *# b *# x = (a * b) *# x"
   230     by (simp add: complex_scaleR_def mult_assoc [symmetric])
   231   show "1 *# x = x"
   232     by (simp add: complex_scaleR_def complex_one_def [symmetric])
   233   show "a *# x * y = a *# (x * y)"
   234     by (simp add: complex_scaleR_def mult_assoc)
   235   show "x * a *# y = a *# (x * y)"
   236     by (simp add: complex_scaleR_def mult_left_commute)
   237 qed
   238 
   239 
   240 subsection{*Embedding Properties for @{term complex_of_real} Map*}
   241 
   242 abbreviation
   243   complex_of_real :: "real => complex" where
   244   "complex_of_real == of_real"
   245 
   246 lemma complex_of_real_def: "complex_of_real r = Complex r 0"
   247 by (simp add: of_real_def complex_scaleR_def)
   248 
   249 lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
   250 by (simp add: complex_of_real_def)
   251 
   252 lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
   253 by (simp add: complex_of_real_def)
   254 
   255 lemma Complex_add_complex_of_real [simp]:
   256      "Complex x y + complex_of_real r = Complex (x+r) y"
   257 by (simp add: complex_of_real_def)
   258 
   259 lemma complex_of_real_add_Complex [simp]:
   260      "complex_of_real r + Complex x y = Complex (r+x) y"
   261 by (simp add: i_def complex_of_real_def)
   262 
   263 lemma Complex_mult_complex_of_real:
   264      "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
   265 by (simp add: complex_of_real_def)
   266 
   267 lemma complex_of_real_mult_Complex:
   268      "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
   269 by (simp add: i_def complex_of_real_def)
   270 
   271 lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
   272 by (simp add: i_def complex_of_real_def)
   273 
   274 lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
   275 by (simp add: i_def complex_of_real_def)
   276 
   277 
   278 subsection{*The Functions @{term Re} and @{term Im}*}
   279 
   280 lemma complex_Re_mult_eq: "Re (w * z) = Re w * Re z - Im w * Im z"
   281 by (induct z, induct w, simp)
   282 
   283 lemma complex_Im_mult_eq: "Im (w * z) = Re w * Im z + Im w * Re z"
   284 by (induct z, induct w, simp)
   285 
   286 lemma Re_i_times [simp]: "Re(ii * z) = - Im z"
   287 by (simp add: complex_Re_mult_eq)
   288 
   289 lemma Re_times_i [simp]: "Re(z * ii) = - Im z"
   290 by (simp add: complex_Re_mult_eq)
   291 
   292 lemma Im_i_times [simp]: "Im(ii * z) = Re z"
   293 by (simp add: complex_Im_mult_eq)
   294 
   295 lemma Im_times_i [simp]: "Im(z * ii) = Re z"
   296 by (simp add: complex_Im_mult_eq)
   297 
   298 lemma complex_Re_mult: "[| Im w = 0; Im z = 0 |] ==> Re(w * z) = Re(w) * Re(z)"
   299 by (simp add: complex_Re_mult_eq)
   300 
   301 lemma complex_Re_mult_complex_of_real [simp]:
   302      "Re (z * complex_of_real c) = Re(z) * c"
   303 by (simp add: complex_Re_mult_eq)
   304 
   305 lemma complex_Im_mult_complex_of_real [simp]:
   306      "Im (z * complex_of_real c) = Im(z) * c"
   307 by (simp add: complex_Im_mult_eq)
   308 
   309 lemma complex_Re_mult_complex_of_real2 [simp]:
   310      "Re (complex_of_real c * z) = c * Re(z)"
   311 by (simp add: complex_Re_mult_eq)
   312 
   313 lemma complex_Im_mult_complex_of_real2 [simp]:
   314      "Im (complex_of_real c * z) = c * Im(z)"
   315 by (simp add: complex_Im_mult_eq)
   316 
   317 
   318 subsection{*Conjugation is an Automorphism*}
   319 
   320 definition
   321   cnj :: "complex => complex" where
   322   "cnj z = Complex (Re z) (-Im z)"
   323 
   324 lemma complex_cnj: "cnj (Complex x y) = Complex x (-y)"
   325 by (simp add: cnj_def)
   326 
   327 lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
   328 by (simp add: cnj_def complex_Re_Im_cancel_iff)
   329 
   330 lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
   331 by (simp add: cnj_def)
   332 
   333 lemma complex_cnj_complex_of_real [simp]:
   334      "cnj (complex_of_real x) = complex_of_real x"
   335 by (simp add: complex_of_real_def complex_cnj)
   336 
   337 lemma complex_cnj_minus: "cnj (-z) = - cnj z"
   338 by (simp add: cnj_def)
   339 
   340 lemma complex_cnj_inverse: "cnj(inverse z) = inverse(cnj z)"
   341 by (induct z, simp add: complex_cnj power2_eq_square)
   342 
   343 lemma complex_cnj_add: "cnj(w + z) = cnj(w) + cnj(z)"
   344 by (induct w, induct z, simp add: complex_cnj)
   345 
   346 lemma complex_cnj_diff: "cnj(w - z) = cnj(w) - cnj(z)"
   347 by (simp add: diff_minus complex_cnj_add complex_cnj_minus)
   348 
   349 lemma complex_cnj_mult: "cnj(w * z) = cnj(w) * cnj(z)"
   350 by (induct w, induct z, simp add: complex_cnj)
   351 
   352 lemma complex_cnj_divide: "cnj(w / z) = (cnj w)/(cnj z)"
   353 by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
   354 
   355 lemma complex_cnj_one [simp]: "cnj 1 = 1"
   356 by (simp add: cnj_def complex_one_def)
   357 
   358 lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re(z))"
   359 by (induct z, simp add: complex_cnj complex_of_real_def)
   360 
   361 lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im(z)) * ii"
   362 apply (induct z)
   363 apply (simp add: complex_add complex_cnj complex_of_real_def diff_minus
   364                  complex_minus i_def complex_mult)
   365 done
   366 
   367 lemma complex_cnj_zero [simp]: "cnj 0 = 0"
   368 by (simp add: cnj_def complex_zero_def)
   369 
   370 lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
   371 by (induct z, simp add: complex_zero_def complex_cnj)
   372 
   373 lemma complex_mult_cnj: "z * cnj z = complex_of_real (Re(z) ^ 2 + Im(z) ^ 2)"
   374 by (induct z, simp add: complex_cnj complex_of_real_def power2_eq_square)
   375 
   376 
   377 subsection{*Modulus*}
   378 
   379 instance complex :: norm
   380   complex_norm_def: "norm z \<equiv> sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)" ..
   381 
   382 abbreviation
   383   cmod :: "complex \<Rightarrow> real" where
   384   "cmod \<equiv> norm"
   385 
   386 lemmas cmod_def = complex_norm_def
   387 
   388 lemma complex_mod [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
   389 by (simp add: cmod_def)
   390 
   391 lemma complex_mod_triangle_ineq [simp]: "cmod (x + y) \<le> cmod x + cmod y"
   392 apply (simp add: cmod_def)
   393 apply (rule real_sqrt_sum_squares_triangle_ineq)
   394 done
   395 
   396 lemma complex_mod_mult: "cmod (x * y) = cmod x * cmod y"
   397 apply (induct x, induct y)
   398 apply (simp add: real_sqrt_mult_distrib [symmetric])
   399 apply (simp add: power2_sum power2_diff power_mult_distrib ring_distrib)
   400 done
   401 
   402 lemma complex_mod_complex_of_real: "cmod (complex_of_real x) = \<bar>x\<bar>"
   403 by (simp add: complex_of_real_def)
   404 
   405 lemma complex_norm_scaleR:
   406   "norm (scaleR a x) = \<bar>a\<bar> * norm (x::complex)"
   407 unfolding scaleR_conv_of_real
   408 by (simp only: complex_mod_mult complex_mod_complex_of_real)
   409 
   410 instance complex :: real_normed_field
   411 proof
   412   fix r :: real
   413   fix x y :: complex
   414   show "0 \<le> cmod x"
   415     by (induct x) simp
   416   show "(cmod x = 0) = (x = 0)"
   417     by (induct x) simp
   418   show "cmod (x + y) \<le> cmod x + cmod y"
   419     by (rule complex_mod_triangle_ineq)
   420   show "cmod (scaleR r x) = \<bar>r\<bar> * cmod x"
   421     by (rule complex_norm_scaleR)
   422   show "cmod (x * y) = cmod x * cmod y"
   423     by (rule complex_mod_mult)
   424 qed
   425 
   426 lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
   427 by (induct z, simp add: complex_cnj)
   428 
   429 lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
   430 by (simp add: complex_mod_mult power2_eq_square)
   431 
   432 lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
   433 by simp
   434 
   435 lemma cmod_complex_polar [simp]:
   436      "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
   437 apply (simp only: cmod_unit_one complex_mod_mult)
   438 apply (simp add: complex_mod_complex_of_real)
   439 done
   440 
   441 lemma complex_Re_le_cmod: "Re x \<le> cmod x"
   442 unfolding complex_norm_def
   443 by (rule real_sqrt_sum_squares_ge1)
   444 
   445 lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
   446 by (rule order_trans [OF _ norm_ge_zero], simp)
   447 
   448 lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
   449 by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
   450 
   451 lemmas real_sum_squared_expand = power2_sum [where 'a=real]
   452 
   453 
   454 subsection{*Exponentiation*}
   455 
   456 primrec
   457      complexpow_0:   "z ^ 0       = 1"
   458      complexpow_Suc: "z ^ (Suc n) = (z::complex) * (z ^ n)"
   459 
   460 
   461 instance complex :: recpower
   462 proof
   463   fix z :: complex
   464   fix n :: nat
   465   show "z^0 = 1" by simp
   466   show "z^(Suc n) = z * (z^n)" by simp
   467 qed
   468 
   469 lemma complex_cnj_pow: "cnj(z ^ n) = cnj(z) ^ n"
   470 apply (induct_tac "n")
   471 apply (auto simp add: complex_cnj_mult)
   472 done
   473 
   474 lemma complexpow_i_squared [simp]: "ii ^ 2 = -(1::complex)"
   475 by (simp add: i_def complex_one_def numeral_2_eq_2)
   476 
   477 lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
   478 by (simp add: i_def complex_zero_def)
   479 
   480 
   481 subsection{*The Function @{term sgn}*}
   482 
   483 definition
   484   (*------------ Argand -------------*)
   485 
   486   sgn :: "complex => complex" where
   487   "sgn z = z / complex_of_real(cmod z)"
   488 
   489 definition
   490   arg :: "complex => real" where
   491   "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
   492 
   493 lemma sgn_zero [simp]: "sgn 0 = 0"
   494 by (simp add: sgn_def)
   495 
   496 lemma sgn_one [simp]: "sgn 1 = 1"
   497 by (simp add: sgn_def)
   498 
   499 lemma sgn_minus: "sgn (-z) = - sgn(z)"
   500 by (simp add: sgn_def)
   501 
   502 lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
   503 by (simp add: sgn_def)
   504 
   505 lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
   506 by (simp add: i_def complex_of_real_def)
   507 
   508 lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
   509 by (simp add: i_def complex_one_def)
   510 
   511 lemma complex_eq_cancel_iff2 [simp]:
   512      "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
   513 by (simp add: complex_of_real_def)
   514 
   515 lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
   516 proof (induct z)
   517   case (Complex x y)
   518     have "sqrt (x\<twosuperior> + y\<twosuperior>) * inverse (x\<twosuperior> + y\<twosuperior>) = inverse (sqrt (x\<twosuperior> + y\<twosuperior>))"
   519       by (simp add: divide_inverse [symmetric] sqrt_divide_self_eq)
   520     thus "Re (sgn (Complex x y)) = Re (Complex x y) /cmod (Complex x y)"
   521        by (simp add: sgn_def complex_of_real_def divide_inverse)
   522 qed
   523 
   524 
   525 lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
   526 proof (induct z)
   527   case (Complex x y)
   528     have "sqrt (x\<twosuperior> + y\<twosuperior>) * inverse (x\<twosuperior> + y\<twosuperior>) = inverse (sqrt (x\<twosuperior> + y\<twosuperior>))"
   529       by (simp add: divide_inverse [symmetric] sqrt_divide_self_eq)
   530     thus "Im (sgn (Complex x y)) = Im (Complex x y) /cmod (Complex x y)"
   531        by (simp add: sgn_def complex_of_real_def divide_inverse)
   532 qed
   533 
   534 lemma complex_inverse_complex_split:
   535      "inverse(complex_of_real x + ii * complex_of_real y) =
   536       complex_of_real(x/(x ^ 2 + y ^ 2)) -
   537       ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
   538 by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
   539 
   540 (*----------------------------------------------------------------------------*)
   541 (* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
   542 (* many of the theorems are not used - so should they be kept?                *)
   543 (*----------------------------------------------------------------------------*)
   544 
   545 lemma cos_arg_i_mult_zero_pos:
   546    "0 < y ==> cos (arg(Complex 0 y)) = 0"
   547 apply (simp add: arg_def abs_if)
   548 apply (rule_tac a = "pi/2" in someI2, auto)
   549 apply (rule order_less_trans [of _ 0], auto)
   550 done
   551 
   552 lemma cos_arg_i_mult_zero_neg:
   553    "y < 0 ==> cos (arg(Complex 0 y)) = 0"
   554 apply (simp add: arg_def abs_if)
   555 apply (rule_tac a = "- pi/2" in someI2, auto)
   556 apply (rule order_trans [of _ 0], auto)
   557 done
   558 
   559 lemma cos_arg_i_mult_zero [simp]:
   560      "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
   561 by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
   562 
   563 
   564 subsection{*Finally! Polar Form for Complex Numbers*}
   565 
   566 definition
   567 
   568   (* abbreviation for (cos a + i sin a) *)
   569   cis :: "real => complex" where
   570   "cis a = Complex (cos a) (sin a)"
   571 
   572 definition
   573   (* abbreviation for r*(cos a + i sin a) *)
   574   rcis :: "[real, real] => complex" where
   575   "rcis r a = complex_of_real r * cis a"
   576 
   577 definition
   578   (* e ^ (x + iy) *)
   579   expi :: "complex => complex" where
   580   "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
   581 
   582 lemma complex_split_polar:
   583      "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
   584 apply (induct z)
   585 apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
   586 done
   587 
   588 lemma rcis_Ex: "\<exists>r a. z = rcis r a"
   589 apply (induct z)
   590 apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
   591 done
   592 
   593 lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
   594 by (simp add: rcis_def cis_def)
   595 
   596 lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
   597 by (simp add: rcis_def cis_def)
   598 
   599 lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
   600 proof -
   601   have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
   602     by (simp only: power_mult_distrib right_distrib)
   603   thus ?thesis by simp
   604 qed
   605 
   606 lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
   607 by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
   608 
   609 lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
   610 apply (simp add: cmod_def)
   611 apply (simp add: complex_mult_cnj del: of_real_add)
   612 done
   613 
   614 lemma complex_Re_cnj [simp]: "Re(cnj z) = Re z"
   615 by (induct z, simp add: complex_cnj)
   616 
   617 lemma complex_Im_cnj [simp]: "Im(cnj z) = - Im z"
   618 by (induct z, simp add: complex_cnj)
   619 
   620 lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
   621 by (induct z, simp add: complex_cnj complex_mult)
   622 
   623 
   624 (*---------------------------------------------------------------------------*)
   625 (*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
   626 (*---------------------------------------------------------------------------*)
   627 
   628 lemma cis_rcis_eq: "cis a = rcis 1 a"
   629 by (simp add: rcis_def)
   630 
   631 lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
   632 by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib
   633               complex_of_real_def)
   634 
   635 lemma cis_mult: "cis a * cis b = cis (a + b)"
   636 by (simp add: cis_rcis_eq rcis_mult)
   637 
   638 lemma cis_zero [simp]: "cis 0 = 1"
   639 by (simp add: cis_def complex_one_def)
   640 
   641 lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
   642 by (simp add: rcis_def)
   643 
   644 lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
   645 by (simp add: rcis_def)
   646 
   647 lemma complex_of_real_minus_one:
   648    "complex_of_real (-(1::real)) = -(1::complex)"
   649 by (simp add: complex_of_real_def complex_one_def)
   650 
   651 lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
   652 by (simp add: complex_mult_assoc [symmetric])
   653 
   654 
   655 lemma cis_real_of_nat_Suc_mult:
   656    "cis (real (Suc n) * a) = cis a * cis (real n * a)"
   657 by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
   658 
   659 lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
   660 apply (induct_tac "n")
   661 apply (auto simp add: cis_real_of_nat_Suc_mult)
   662 done
   663 
   664 lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
   665 by (simp add: rcis_def power_mult_distrib DeMoivre)
   666 
   667 lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
   668 by (simp add: cis_def complex_inverse_complex_split diff_minus)
   669 
   670 lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
   671 by (simp add: divide_inverse rcis_def)
   672 
   673 lemma cis_divide: "cis a / cis b = cis (a - b)"
   674 by (simp add: complex_divide_def cis_mult real_diff_def)
   675 
   676 lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
   677 apply (simp add: complex_divide_def)
   678 apply (case_tac "r2=0", simp)
   679 apply (simp add: rcis_inverse rcis_mult real_diff_def)
   680 done
   681 
   682 lemma Re_cis [simp]: "Re(cis a) = cos a"
   683 by (simp add: cis_def)
   684 
   685 lemma Im_cis [simp]: "Im(cis a) = sin a"
   686 by (simp add: cis_def)
   687 
   688 lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
   689 by (auto simp add: DeMoivre)
   690 
   691 lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
   692 by (auto simp add: DeMoivre)
   693 
   694 lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
   695 by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac)
   696 
   697 lemma expi_zero [simp]: "expi (0::complex) = 1"
   698 by (simp add: expi_def)
   699 
   700 lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
   701 apply (insert rcis_Ex [of z])
   702 apply (auto simp add: expi_def rcis_def complex_mult_assoc [symmetric])
   703 apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
   704 done
   705 
   706 
   707 subsection{*Numerals and Arithmetic*}
   708 
   709 instance complex :: number ..
   710 
   711 defs (overloaded)
   712   complex_number_of_def: "(number_of w :: complex) == of_int w"
   713     --{*the type constraint is essential!*}
   714 
   715 instance complex :: number_ring
   716 by (intro_classes, simp add: complex_number_of_def)
   717 
   718 lemma complex_number_of: "complex_of_real (number_of w) = number_of w"
   719 by (rule of_real_number_of_eq)
   720 
   721 lemma complex_number_of_cnj [simp]: "cnj(number_of v :: complex) = number_of v"
   722 by (simp only: complex_number_of [symmetric] complex_cnj_complex_of_real)
   723 
   724 lemma complex_number_of_cmod: 
   725       "cmod(number_of v :: complex) = abs (number_of v :: real)"
   726 by (simp only: complex_number_of [symmetric] complex_mod_complex_of_real)
   727 
   728 lemma complex_number_of_Re [simp]: "Re(number_of v :: complex) = number_of v"
   729 by (simp only: complex_number_of [symmetric] Re_complex_of_real)
   730 
   731 lemma complex_number_of_Im [simp]: "Im(number_of v :: complex) = 0"
   732 by (simp only: complex_number_of [symmetric] Im_complex_of_real)
   733 
   734 lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
   735 by (simp add: expi_def complex_Re_mult_eq complex_Im_mult_eq cis_def)
   736 
   737 
   738 (*examples:
   739 print_depth 22
   740 set timing;
   741 set trace_simp;
   742 fun test s = (Goal s, by (Simp_tac 1)); 
   743 
   744 test "23 * ii + 45 * ii= (x::complex)";
   745 
   746 test "5 * ii + 12 - 45 * ii= (x::complex)";
   747 test "5 * ii + 40 - 12 * ii + 9 = (x::complex) + 89 * ii";
   748 test "5 * ii + 40 - 12 * ii + 9 - 78 = (x::complex) + 89 * ii";
   749 
   750 test "l + 10 * ii + 90 + 3*l +  9 + 45 * ii= (x::complex)";
   751 test "87 + 10 * ii + 90 + 3*7 +  9 + 45 * ii= (x::complex)";
   752 
   753 
   754 fun test s = (Goal s; by (Asm_simp_tac 1)); 
   755 
   756 test "x*k = k*(y::complex)";
   757 test "k = k*(y::complex)"; 
   758 test "a*(b*c) = (b::complex)";
   759 test "a*(b*c) = d*(b::complex)*(x*a)";
   760 
   761 
   762 test "(x*k) / (k*(y::complex)) = (uu::complex)";
   763 test "(k) / (k*(y::complex)) = (uu::complex)"; 
   764 test "(a*(b*c)) / ((b::complex)) = (uu::complex)";
   765 test "(a*(b*c)) / (d*(b::complex)*(x*a)) = (uu::complex)";
   766 
   767 FIXME: what do we do about this?
   768 test "a*(b*c)/(y*z) = d*(b::complex)*(x*a)/z";
   769 *)
   770 
   771 end