src/HOL/Complex/Complex.thy
author huffman
Sat Sep 16 19:14:37 2006 +0200 (2006-09-16)
changeset 20556 2e8227b81bf1
parent 20485 3078fd2eec7b
child 20557 81dd3679f92c
permissions -rw-r--r--
add instance for real_algebra_1 and real_normed_div_algebra
paulson@13957
     1
(*  Title:       Complex.thy
paulson@14430
     2
    ID:      $Id$
paulson@13957
     3
    Author:      Jacques D. Fleuriot
paulson@13957
     4
    Copyright:   2001 University of Edinburgh
paulson@14387
     5
    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
paulson@13957
     6
*)
paulson@13957
     7
paulson@14377
     8
header {* Complex Numbers: Rectangular and Polar Representations *}
paulson@14373
     9
nipkow@15131
    10
theory Complex
nipkow@15140
    11
imports "../Hyperreal/HLog"
nipkow@15131
    12
begin
paulson@13957
    13
paulson@14373
    14
datatype complex = Complex real real
paulson@13957
    15
wenzelm@14691
    16
instance complex :: "{zero, one, plus, times, minus, inverse, power}" ..
paulson@13957
    17
paulson@13957
    18
consts
paulson@14373
    19
  "ii"    :: complex    ("\<i>")
paulson@14373
    20
paulson@14373
    21
consts Re :: "complex => real"
paulson@14373
    22
primrec "Re (Complex x y) = x"
paulson@14373
    23
paulson@14373
    24
consts Im :: "complex => real"
paulson@14373
    25
primrec "Im (Complex x y) = y"
paulson@14373
    26
paulson@14373
    27
lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
paulson@14373
    28
  by (induct z) simp
paulson@13957
    29
wenzelm@19765
    30
definition
paulson@13957
    31
paulson@13957
    32
  (*----------- modulus ------------*)
paulson@13957
    33
paulson@14323
    34
  cmod :: "complex => real"
wenzelm@19765
    35
  "cmod z = sqrt(Re(z) ^ 2 + Im(z) ^ 2)"
paulson@13957
    36
paulson@14323
    37
  (*----- injection from reals -----*)
paulson@14323
    38
paulson@14323
    39
  complex_of_real :: "real => complex"
wenzelm@19765
    40
  "complex_of_real r = Complex r 0"
paulson@14323
    41
paulson@13957
    42
  (*------- complex conjugate ------*)
paulson@13957
    43
paulson@14323
    44
  cnj :: "complex => complex"
wenzelm@19765
    45
  "cnj z = Complex (Re z) (-Im z)"
paulson@13957
    46
paulson@14323
    47
  (*------------ Argand -------------*)
paulson@13957
    48
paulson@14323
    49
  sgn :: "complex => complex"
wenzelm@19765
    50
  "sgn z = z / complex_of_real(cmod z)"
paulson@13957
    51
paulson@14323
    52
  arg :: "complex => real"
wenzelm@19765
    53
  "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
paulson@14323
    54
paulson@13957
    55
paulson@14323
    56
defs (overloaded)
paulson@14323
    57
paulson@14323
    58
  complex_zero_def:
paulson@14373
    59
  "0 == Complex 0 0"
paulson@13957
    60
paulson@14323
    61
  complex_one_def:
paulson@14373
    62
  "1 == Complex 1 0"
paulson@14323
    63
paulson@14373
    64
  i_def: "ii == Complex 0 1"
paulson@14323
    65
paulson@14373
    66
  complex_minus_def: "- z == Complex (- Re z) (- Im z)"
paulson@14323
    67
paulson@14323
    68
  complex_inverse_def:
paulson@14373
    69
   "inverse z ==
paulson@14373
    70
    Complex (Re z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>)) (- Im z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>))"
paulson@13957
    71
paulson@14323
    72
  complex_add_def:
paulson@14373
    73
    "z + w == Complex (Re z + Re w) (Im z + Im w)"
paulson@13957
    74
paulson@14323
    75
  complex_diff_def:
paulson@14373
    76
    "z - w == z + - (w::complex)"
paulson@13957
    77
paulson@14374
    78
  complex_mult_def:
paulson@14373
    79
    "z * w == Complex (Re z * Re w - Im z * Im w) (Re z * Im w + Im z * Re w)"
paulson@13957
    80
paulson@14373
    81
  complex_divide_def: "w / (z::complex) == w * inverse z"
paulson@14323
    82
paulson@13957
    83
wenzelm@19765
    84
definition
paulson@13957
    85
paulson@13957
    86
  (* abbreviation for (cos a + i sin a) *)
paulson@14323
    87
  cis :: "real => complex"
wenzelm@19765
    88
  "cis a = Complex (cos a) (sin a)"
paulson@13957
    89
paulson@13957
    90
  (* abbreviation for r*(cos a + i sin a) *)
paulson@14323
    91
  rcis :: "[real, real] => complex"
wenzelm@19765
    92
  "rcis r a = complex_of_real r * cis a"
paulson@13957
    93
paulson@13957
    94
  (* e ^ (x + iy) *)
paulson@14323
    95
  expi :: "complex => complex"
wenzelm@19765
    96
  "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
paulson@14323
    97
paulson@14323
    98
paulson@14373
    99
lemma complex_equality [intro?]: "Re z = Re w ==> Im z = Im w ==> z = w"
paulson@14373
   100
  by (induct z, induct w) simp
paulson@14323
   101
paulson@14374
   102
lemma Re [simp]: "Re(Complex x y) = x"
paulson@14373
   103
by simp
paulson@14323
   104
paulson@14374
   105
lemma Im [simp]: "Im(Complex x y) = y"
paulson@14373
   106
by simp
paulson@14323
   107
paulson@14323
   108
lemma complex_Re_Im_cancel_iff: "(w=z) = (Re(w) = Re(z) & Im(w) = Im(z))"
paulson@14373
   109
by (induct w, induct z, simp)
paulson@14323
   110
paulson@14374
   111
lemma complex_Re_zero [simp]: "Re 0 = 0"
paulson@14374
   112
by (simp add: complex_zero_def)
paulson@14374
   113
paulson@14374
   114
lemma complex_Im_zero [simp]: "Im 0 = 0"
paulson@14373
   115
by (simp add: complex_zero_def)
paulson@14323
   116
paulson@14374
   117
lemma complex_Re_one [simp]: "Re 1 = 1"
paulson@14374
   118
by (simp add: complex_one_def)
paulson@14323
   119
paulson@14374
   120
lemma complex_Im_one [simp]: "Im 1 = 0"
paulson@14373
   121
by (simp add: complex_one_def)
paulson@14323
   122
paulson@14374
   123
lemma complex_Re_i [simp]: "Re(ii) = 0"
paulson@14373
   124
by (simp add: i_def)
paulson@14323
   125
paulson@14374
   126
lemma complex_Im_i [simp]: "Im(ii) = 1"
paulson@14373
   127
by (simp add: i_def)
paulson@14323
   128
paulson@14374
   129
lemma Re_complex_of_real [simp]: "Re(complex_of_real z) = z"
paulson@14373
   130
by (simp add: complex_of_real_def)
paulson@14323
   131
paulson@14374
   132
lemma Im_complex_of_real [simp]: "Im(complex_of_real z) = 0"
paulson@14373
   133
by (simp add: complex_of_real_def)
paulson@14323
   134
paulson@14323
   135
paulson@14374
   136
subsection{*Unary Minus*}
paulson@14323
   137
paulson@14377
   138
lemma complex_minus [simp]: "- (Complex x y) = Complex (-x) (-y)"
paulson@14373
   139
by (simp add: complex_minus_def)
paulson@14323
   140
paulson@14374
   141
lemma complex_Re_minus [simp]: "Re (-z) = - Re z"
paulson@14373
   142
by (simp add: complex_minus_def)
paulson@14323
   143
paulson@14374
   144
lemma complex_Im_minus [simp]: "Im (-z) = - Im z"
paulson@14374
   145
by (simp add: complex_minus_def)
paulson@14323
   146
paulson@14323
   147
paulson@14323
   148
subsection{*Addition*}
paulson@14323
   149
paulson@14377
   150
lemma complex_add [simp]:
paulson@14377
   151
     "Complex x1 y1 + Complex x2 y2 = Complex (x1+x2) (y1+y2)"
paulson@14373
   152
by (simp add: complex_add_def)
paulson@14323
   153
paulson@14374
   154
lemma complex_Re_add [simp]: "Re(x + y) = Re(x) + Re(y)"
paulson@14373
   155
by (simp add: complex_add_def)
paulson@14323
   156
paulson@14374
   157
lemma complex_Im_add [simp]: "Im(x + y) = Im(x) + Im(y)"
paulson@14373
   158
by (simp add: complex_add_def)
paulson@14323
   159
paulson@14323
   160
lemma complex_add_commute: "(u::complex) + v = v + u"
paulson@14373
   161
by (simp add: complex_add_def add_commute)
paulson@14323
   162
paulson@14323
   163
lemma complex_add_assoc: "((u::complex) + v) + w = u + (v + w)"
paulson@14373
   164
by (simp add: complex_add_def add_assoc)
paulson@14323
   165
paulson@14323
   166
lemma complex_add_zero_left: "(0::complex) + z = z"
paulson@14373
   167
by (simp add: complex_add_def complex_zero_def)
paulson@14323
   168
paulson@14323
   169
lemma complex_add_zero_right: "z + (0::complex) = z"
paulson@14373
   170
by (simp add: complex_add_def complex_zero_def)
paulson@14323
   171
paulson@14373
   172
lemma complex_add_minus_left: "-z + z = (0::complex)"
paulson@14373
   173
by (simp add: complex_add_def complex_minus_def complex_zero_def)
paulson@14323
   174
paulson@14323
   175
lemma complex_diff:
paulson@14373
   176
      "Complex x1 y1 - Complex x2 y2 = Complex (x1-x2) (y1-y2)"
paulson@14373
   177
by (simp add: complex_add_def complex_minus_def complex_diff_def)
paulson@14323
   178
paulson@14374
   179
lemma complex_Re_diff [simp]: "Re(x - y) = Re(x) - Re(y)"
paulson@14374
   180
by (simp add: complex_diff_def)
paulson@14374
   181
paulson@14374
   182
lemma complex_Im_diff [simp]: "Im(x - y) = Im(x) - Im(y)"
paulson@14374
   183
by (simp add: complex_diff_def)
paulson@14374
   184
paulson@14374
   185
paulson@14323
   186
subsection{*Multiplication*}
paulson@14323
   187
paulson@14377
   188
lemma complex_mult [simp]:
paulson@14373
   189
     "Complex x1 y1 * Complex x2 y2 = Complex (x1*x2 - y1*y2) (x1*y2 + y1*x2)"
paulson@14373
   190
by (simp add: complex_mult_def)
paulson@14323
   191
paulson@14323
   192
lemma complex_mult_commute: "(w::complex) * z = z * w"
paulson@14373
   193
by (simp add: complex_mult_def mult_commute add_commute)
paulson@14323
   194
paulson@14323
   195
lemma complex_mult_assoc: "((u::complex) * v) * w = u * (v * w)"
paulson@14374
   196
by (simp add: complex_mult_def mult_ac add_ac
paulson@14373
   197
              right_diff_distrib right_distrib left_diff_distrib left_distrib)
paulson@14323
   198
paulson@14323
   199
lemma complex_mult_one_left: "(1::complex) * z = z"
paulson@14373
   200
by (simp add: complex_mult_def complex_one_def)
paulson@14323
   201
paulson@14323
   202
lemma complex_mult_one_right: "z * (1::complex) = z"
paulson@14373
   203
by (simp add: complex_mult_def complex_one_def)
paulson@14323
   204
paulson@14323
   205
paulson@14323
   206
subsection{*Inverse*}
paulson@14323
   207
paulson@14377
   208
lemma complex_inverse [simp]:
paulson@14373
   209
     "inverse (Complex x y) = Complex (x/(x ^ 2 + y ^ 2)) (-y/(x ^ 2 + y ^ 2))"
paulson@14373
   210
by (simp add: complex_inverse_def)
paulson@14335
   211
paulson@14354
   212
lemma complex_mult_inv_left: "z \<noteq> (0::complex) ==> inverse(z) * z = 1"
paulson@14374
   213
apply (induct z)
paulson@14374
   214
apply (rename_tac x y)
paulson@15234
   215
apply (auto simp add: times_divide_eq complex_mult complex_inverse 
paulson@15234
   216
             complex_one_def complex_zero_def add_divide_distrib [symmetric] 
paulson@15234
   217
             power2_eq_square mult_ac)
paulson@15234
   218
apply (simp_all add: real_sum_squares_not_zero real_sum_squares_not_zero2) 
paulson@14323
   219
done
paulson@14323
   220
paulson@14335
   221
paulson@14335
   222
subsection {* The field of complex numbers *}
paulson@14335
   223
paulson@14335
   224
instance complex :: field
paulson@14335
   225
proof
paulson@14335
   226
  fix z u v w :: complex
paulson@14335
   227
  show "(u + v) + w = u + (v + w)"
paulson@14374
   228
    by (rule complex_add_assoc)
paulson@14335
   229
  show "z + w = w + z"
paulson@14374
   230
    by (rule complex_add_commute)
paulson@14335
   231
  show "0 + z = z"
paulson@14374
   232
    by (rule complex_add_zero_left)
paulson@14335
   233
  show "-z + z = 0"
paulson@14374
   234
    by (rule complex_add_minus_left)
paulson@14335
   235
  show "z - w = z + -w"
paulson@14335
   236
    by (simp add: complex_diff_def)
paulson@14335
   237
  show "(u * v) * w = u * (v * w)"
paulson@14374
   238
    by (rule complex_mult_assoc)
paulson@14335
   239
  show "z * w = w * z"
paulson@14374
   240
    by (rule complex_mult_commute)
paulson@14335
   241
  show "1 * z = z"
paulson@14374
   242
    by (rule complex_mult_one_left)
paulson@14341
   243
  show "0 \<noteq> (1::complex)"
paulson@14373
   244
    by (simp add: complex_zero_def complex_one_def)
paulson@14335
   245
  show "(u + v) * w = u * w + v * w"
paulson@14421
   246
    by (simp add: complex_mult_def complex_add_def left_distrib 
paulson@14421
   247
                  diff_minus add_ac)
paulson@14430
   248
  show "z / w = z * inverse w"
paulson@14335
   249
    by (simp add: complex_divide_def)
paulson@14430
   250
  assume "w \<noteq> 0"
paulson@14430
   251
  thus "inverse w * w = 1"
paulson@14430
   252
    by (simp add: complex_mult_inv_left)
paulson@14335
   253
qed
paulson@14335
   254
paulson@14373
   255
instance complex :: division_by_zero
paulson@14373
   256
proof
paulson@14430
   257
  show "inverse 0 = (0::complex)"
paulson@14373
   258
    by (simp add: complex_inverse_def complex_zero_def)
paulson@14373
   259
qed
paulson@14335
   260
paulson@14323
   261
huffman@20556
   262
subsection{*The real algebra of complex numbers*}
huffman@20556
   263
huffman@20556
   264
instance complex :: scaleR ..
huffman@20556
   265
huffman@20556
   266
defs (overloaded)
huffman@20556
   267
  complex_scaleR_def: "r *# x == Complex r 0 * x"
huffman@20556
   268
huffman@20556
   269
instance complex :: real_algebra_1
huffman@20556
   270
proof
huffman@20556
   271
  fix a b :: real
huffman@20556
   272
  fix x y :: complex
huffman@20556
   273
  show "a *# (x + y) = a *# x + a *# y"
huffman@20556
   274
    by (simp add: complex_scaleR_def right_distrib)
huffman@20556
   275
  show "(a + b) *# x = a *# x + b *# x"
huffman@20556
   276
    by (simp add: complex_scaleR_def left_distrib [symmetric])
huffman@20556
   277
  show "(a * b) *# x = a *# b *# x"
huffman@20556
   278
    by (simp add: complex_scaleR_def mult_assoc [symmetric])
huffman@20556
   279
  show "1 *# x = x"
huffman@20556
   280
    by (simp add: complex_scaleR_def complex_one_def [symmetric])
huffman@20556
   281
  show "a *# x * y = a *# (x * y)"
huffman@20556
   282
    by (simp add: complex_scaleR_def mult_assoc)
huffman@20556
   283
  show "x * a *# y = a *# (x * y)"
huffman@20556
   284
    by (simp add: complex_scaleR_def mult_left_commute)
huffman@20556
   285
qed
huffman@20556
   286
huffman@20556
   287
paulson@14323
   288
subsection{*Embedding Properties for @{term complex_of_real} Map*}
paulson@14323
   289
paulson@14377
   290
lemma Complex_add_complex_of_real [simp]:
paulson@14377
   291
     "Complex x y + complex_of_real r = Complex (x+r) y"
paulson@14377
   292
by (simp add: complex_of_real_def)
paulson@14377
   293
paulson@14377
   294
lemma complex_of_real_add_Complex [simp]:
paulson@14377
   295
     "complex_of_real r + Complex x y = Complex (r+x) y"
paulson@14377
   296
by (simp add: i_def complex_of_real_def)
paulson@14377
   297
paulson@14377
   298
lemma Complex_mult_complex_of_real:
paulson@14377
   299
     "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
paulson@14377
   300
by (simp add: complex_of_real_def)
paulson@14377
   301
paulson@14377
   302
lemma complex_of_real_mult_Complex:
paulson@14377
   303
     "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
paulson@14377
   304
by (simp add: i_def complex_of_real_def)
paulson@14377
   305
paulson@14377
   306
lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
paulson@14377
   307
by (simp add: i_def complex_of_real_def)
paulson@14377
   308
paulson@14377
   309
lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
paulson@14377
   310
by (simp add: i_def complex_of_real_def)
paulson@14377
   311
paulson@14374
   312
lemma complex_of_real_one [simp]: "complex_of_real 1 = 1"
paulson@14373
   313
by (simp add: complex_one_def complex_of_real_def)
paulson@14323
   314
paulson@14374
   315
lemma complex_of_real_zero [simp]: "complex_of_real 0 = 0"
paulson@14373
   316
by (simp add: complex_zero_def complex_of_real_def)
paulson@14323
   317
paulson@14374
   318
lemma complex_of_real_eq_iff [iff]:
paulson@14348
   319
     "(complex_of_real x = complex_of_real y) = (x = y)"
paulson@14374
   320
by (simp add: complex_of_real_def)
paulson@14323
   321
paulson@15013
   322
lemma complex_of_real_minus [simp]: "complex_of_real(-x) = - complex_of_real x"
paulson@14373
   323
by (simp add: complex_of_real_def complex_minus)
paulson@14323
   324
paulson@15013
   325
lemma complex_of_real_inverse [simp]:
paulson@14374
   326
     "complex_of_real(inverse x) = inverse(complex_of_real x)"
paulson@14348
   327
apply (case_tac "x=0", simp)
paulson@15013
   328
apply (simp add: complex_of_real_def divide_inverse power2_eq_square)
paulson@14323
   329
done
paulson@14323
   330
paulson@15013
   331
lemma complex_of_real_add [simp]:
paulson@15013
   332
     "complex_of_real (x + y) = complex_of_real x + complex_of_real y"
paulson@14373
   333
by (simp add: complex_add complex_of_real_def)
paulson@14323
   334
paulson@15013
   335
lemma complex_of_real_diff [simp]:
paulson@15013
   336
     "complex_of_real (x - y) = complex_of_real x - complex_of_real y"
paulson@15013
   337
by (simp add: complex_of_real_minus diff_minus)
paulson@14323
   338
paulson@15013
   339
lemma complex_of_real_mult [simp]:
paulson@15013
   340
     "complex_of_real (x * y) = complex_of_real x * complex_of_real y"
paulson@14373
   341
by (simp add: complex_mult complex_of_real_def)
paulson@14323
   342
paulson@15013
   343
lemma complex_of_real_divide [simp]:
paulson@15013
   344
      "complex_of_real(x/y) = complex_of_real x / complex_of_real y"
paulson@14373
   345
apply (simp add: complex_divide_def)
paulson@14373
   346
apply (case_tac "y=0", simp)
paulson@15013
   347
apply (simp add: complex_of_real_mult complex_of_real_inverse 
paulson@15013
   348
                 divide_inverse)
paulson@14323
   349
done
paulson@14323
   350
paulson@14377
   351
lemma complex_mod [simp]: "cmod (Complex x y) = sqrt(x ^ 2 + y ^ 2)"
paulson@14373
   352
by (simp add: cmod_def)
paulson@14323
   353
paulson@14374
   354
lemma complex_mod_zero [simp]: "cmod(0) = 0"
paulson@14373
   355
by (simp add: cmod_def)
paulson@14323
   356
paulson@14348
   357
lemma complex_mod_one [simp]: "cmod(1) = 1"
paulson@14353
   358
by (simp add: cmod_def power2_eq_square)
paulson@14323
   359
paulson@14374
   360
lemma complex_mod_complex_of_real [simp]: "cmod(complex_of_real x) = abs x"
paulson@14373
   361
by (simp add: complex_of_real_def power2_eq_square complex_mod)
paulson@14323
   362
paulson@14348
   363
lemma complex_of_real_abs:
paulson@14348
   364
     "complex_of_real (abs x) = complex_of_real(cmod(complex_of_real x))"
paulson@14373
   365
by simp
paulson@14348
   366
paulson@14323
   367
paulson@14377
   368
subsection{*The Functions @{term Re} and @{term Im}*}
paulson@14377
   369
paulson@14377
   370
lemma complex_Re_mult_eq: "Re (w * z) = Re w * Re z - Im w * Im z"
paulson@14377
   371
by (induct z, induct w, simp add: complex_mult)
paulson@14377
   372
paulson@14377
   373
lemma complex_Im_mult_eq: "Im (w * z) = Re w * Im z + Im w * Re z"
paulson@14377
   374
by (induct z, induct w, simp add: complex_mult)
paulson@14377
   375
paulson@14377
   376
lemma Re_i_times [simp]: "Re(ii * z) = - Im z"
paulson@14377
   377
by (simp add: complex_Re_mult_eq) 
paulson@14377
   378
paulson@14377
   379
lemma Re_times_i [simp]: "Re(z * ii) = - Im z"
paulson@14377
   380
by (simp add: complex_Re_mult_eq) 
paulson@14377
   381
paulson@14377
   382
lemma Im_i_times [simp]: "Im(ii * z) = Re z"
paulson@14377
   383
by (simp add: complex_Im_mult_eq) 
paulson@14377
   384
paulson@14377
   385
lemma Im_times_i [simp]: "Im(z * ii) = Re z"
paulson@14377
   386
by (simp add: complex_Im_mult_eq) 
paulson@14377
   387
paulson@14377
   388
lemma complex_Re_mult: "[| Im w = 0; Im z = 0 |] ==> Re(w * z) = Re(w) * Re(z)"
paulson@14377
   389
by (simp add: complex_Re_mult_eq)
paulson@14377
   390
paulson@14377
   391
lemma complex_Re_mult_complex_of_real [simp]:
paulson@14377
   392
     "Re (z * complex_of_real c) = Re(z) * c"
paulson@14377
   393
by (simp add: complex_Re_mult_eq)
paulson@14377
   394
paulson@14377
   395
lemma complex_Im_mult_complex_of_real [simp]:
paulson@14377
   396
     "Im (z * complex_of_real c) = Im(z) * c"
paulson@14377
   397
by (simp add: complex_Im_mult_eq)
paulson@14377
   398
paulson@14377
   399
lemma complex_Re_mult_complex_of_real2 [simp]:
paulson@14377
   400
     "Re (complex_of_real c * z) = c * Re(z)"
paulson@14377
   401
by (simp add: complex_Re_mult_eq)
paulson@14377
   402
paulson@14377
   403
lemma complex_Im_mult_complex_of_real2 [simp]:
paulson@14377
   404
     "Im (complex_of_real c * z) = c * Im(z)"
paulson@14377
   405
by (simp add: complex_Im_mult_eq)
paulson@14377
   406
 
paulson@14377
   407
paulson@14323
   408
subsection{*Conjugation is an Automorphism*}
paulson@14323
   409
paulson@14373
   410
lemma complex_cnj: "cnj (Complex x y) = Complex x (-y)"
paulson@14373
   411
by (simp add: cnj_def)
paulson@14323
   412
paulson@14374
   413
lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
paulson@14373
   414
by (simp add: cnj_def complex_Re_Im_cancel_iff)
paulson@14323
   415
paulson@14374
   416
lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
paulson@14373
   417
by (simp add: cnj_def)
paulson@14323
   418
paulson@14374
   419
lemma complex_cnj_complex_of_real [simp]:
paulson@14373
   420
     "cnj (complex_of_real x) = complex_of_real x"
paulson@14373
   421
by (simp add: complex_of_real_def complex_cnj)
paulson@14323
   422
paulson@14374
   423
lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
paulson@14373
   424
by (induct z, simp add: complex_cnj complex_mod power2_eq_square)
paulson@14323
   425
paulson@14323
   426
lemma complex_cnj_minus: "cnj (-z) = - cnj z"
paulson@14373
   427
by (simp add: cnj_def complex_minus complex_Re_minus complex_Im_minus)
paulson@14323
   428
paulson@14323
   429
lemma complex_cnj_inverse: "cnj(inverse z) = inverse(cnj z)"
paulson@14373
   430
by (induct z, simp add: complex_cnj complex_inverse power2_eq_square)
paulson@14323
   431
paulson@14323
   432
lemma complex_cnj_add: "cnj(w + z) = cnj(w) + cnj(z)"
paulson@14373
   433
by (induct w, induct z, simp add: complex_cnj complex_add)
paulson@14323
   434
paulson@14323
   435
lemma complex_cnj_diff: "cnj(w - z) = cnj(w) - cnj(z)"
paulson@15013
   436
by (simp add: diff_minus complex_cnj_add complex_cnj_minus)
paulson@14323
   437
paulson@14323
   438
lemma complex_cnj_mult: "cnj(w * z) = cnj(w) * cnj(z)"
paulson@14373
   439
by (induct w, induct z, simp add: complex_cnj complex_mult)
paulson@14323
   440
paulson@14323
   441
lemma complex_cnj_divide: "cnj(w / z) = (cnj w)/(cnj z)"
paulson@14373
   442
by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
paulson@14323
   443
paulson@14374
   444
lemma complex_cnj_one [simp]: "cnj 1 = 1"
paulson@14373
   445
by (simp add: cnj_def complex_one_def)
paulson@14323
   446
paulson@14323
   447
lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re(z))"
paulson@14373
   448
by (induct z, simp add: complex_add complex_cnj complex_of_real_def)
paulson@14323
   449
paulson@14323
   450
lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im(z)) * ii"
paulson@14373
   451
apply (induct z)
paulson@15013
   452
apply (simp add: complex_add complex_cnj complex_of_real_def diff_minus
paulson@14354
   453
                 complex_minus i_def complex_mult)
paulson@14323
   454
done
paulson@14323
   455
paulson@14354
   456
lemma complex_cnj_zero [simp]: "cnj 0 = 0"
paulson@14334
   457
by (simp add: cnj_def complex_zero_def)
paulson@14323
   458
paulson@14374
   459
lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
paulson@14373
   460
by (induct z, simp add: complex_zero_def complex_cnj)
paulson@14323
   461
paulson@14323
   462
lemma complex_mult_cnj: "z * cnj z = complex_of_real (Re(z) ^ 2 + Im(z) ^ 2)"
paulson@14374
   463
by (induct z,
paulson@14374
   464
    simp add: complex_cnj complex_mult complex_of_real_def power2_eq_square)
paulson@14323
   465
paulson@14323
   466
paulson@14323
   467
subsection{*Modulus*}
paulson@14323
   468
paulson@14374
   469
lemma complex_mod_eq_zero_cancel [simp]: "(cmod x = 0) = (x = 0)"
paulson@14373
   470
apply (induct x)
paulson@15085
   471
apply (auto iff: real_0_le_add_iff 
paulson@15085
   472
            intro: real_sum_squares_cancel real_sum_squares_cancel2
paulson@14373
   473
            simp add: complex_mod complex_zero_def power2_eq_square)
paulson@14323
   474
done
paulson@14323
   475
paulson@14374
   476
lemma complex_mod_complex_of_real_of_nat [simp]:
paulson@14373
   477
     "cmod (complex_of_real(real (n::nat))) = real n"
paulson@14373
   478
by simp
paulson@14323
   479
paulson@14374
   480
lemma complex_mod_minus [simp]: "cmod (-x) = cmod(x)"
paulson@14373
   481
by (induct x, simp add: complex_mod complex_minus power2_eq_square)
paulson@14323
   482
paulson@14323
   483
lemma complex_mod_mult_cnj: "cmod(z * cnj(z)) = cmod(z) ^ 2"
paulson@14373
   484
apply (induct z, simp add: complex_mod complex_cnj complex_mult)
paulson@15085
   485
apply (simp add: power2_eq_square abs_if linorder_not_less real_0_le_add_iff)
paulson@14323
   486
done
paulson@14323
   487
paulson@14373
   488
lemma complex_mod_squared: "cmod(Complex x y) ^ 2 = x ^ 2 + y ^ 2"
paulson@14373
   489
by (simp add: cmod_def)
paulson@14323
   490
paulson@14374
   491
lemma complex_mod_ge_zero [simp]: "0 \<le> cmod x"
paulson@14373
   492
by (simp add: cmod_def)
paulson@14323
   493
paulson@14374
   494
lemma abs_cmod_cancel [simp]: "abs(cmod x) = cmod x"
paulson@14374
   495
by (simp add: abs_if linorder_not_less)
paulson@14323
   496
paulson@14323
   497
lemma complex_mod_mult: "cmod(x*y) = cmod(x) * cmod(y)"
paulson@14373
   498
apply (induct x, induct y)
paulson@14377
   499
apply (auto simp add: complex_mult complex_mod real_sqrt_mult_distrib2[symmetric])
paulson@14348
   500
apply (rule_tac n = 1 in power_inject_base)
paulson@14353
   501
apply (auto simp add: power2_eq_square [symmetric] simp del: realpow_Suc)
paulson@14374
   502
apply (auto simp add: real_diff_def power2_eq_square right_distrib left_distrib 
paulson@14374
   503
                      add_ac mult_ac)
paulson@14323
   504
done
paulson@14323
   505
paulson@14377
   506
lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
paulson@14377
   507
by (simp add: cmod_def) 
paulson@14377
   508
paulson@14377
   509
lemma cmod_complex_polar [simp]:
paulson@14377
   510
     "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
paulson@14377
   511
by (simp only: cmod_unit_one complex_mod_mult, simp) 
paulson@14377
   512
paulson@14374
   513
lemma complex_mod_add_squared_eq:
paulson@14374
   514
     "cmod(x + y) ^ 2 = cmod(x) ^ 2 + cmod(y) ^ 2 + 2 * Re(x * cnj y)"
paulson@14373
   515
apply (induct x, induct y)
paulson@14323
   516
apply (auto simp add: complex_add complex_mod_squared complex_mult complex_cnj real_diff_def simp del: realpow_Suc)
paulson@14353
   517
apply (auto simp add: right_distrib left_distrib power2_eq_square mult_ac add_ac)
paulson@14323
   518
done
paulson@14323
   519
paulson@14374
   520
lemma complex_Re_mult_cnj_le_cmod [simp]: "Re(x * cnj y) \<le> cmod(x * cnj y)"
paulson@14373
   521
apply (induct x, induct y)
paulson@14323
   522
apply (auto simp add: complex_mod complex_mult complex_cnj real_diff_def simp del: realpow_Suc)
paulson@14323
   523
done
paulson@14323
   524
paulson@14374
   525
lemma complex_Re_mult_cnj_le_cmod2 [simp]: "Re(x * cnj y) \<le> cmod(x * y)"
paulson@14373
   526
by (insert complex_Re_mult_cnj_le_cmod [of x y], simp add: complex_mod_mult)
paulson@14323
   527
paulson@14374
   528
lemma real_sum_squared_expand:
paulson@14374
   529
     "((x::real) + y) ^ 2 = x ^ 2 + y ^ 2 + 2 * x * y"
paulson@14373
   530
by (simp add: left_distrib right_distrib power2_eq_square)
paulson@14323
   531
paulson@14374
   532
lemma complex_mod_triangle_squared [simp]:
paulson@14374
   533
     "cmod (x + y) ^ 2 \<le> (cmod(x) + cmod(y)) ^ 2"
paulson@14373
   534
by (simp add: real_sum_squared_expand complex_mod_add_squared_eq real_mult_assoc complex_mod_mult [symmetric])
paulson@14323
   535
paulson@14374
   536
lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
paulson@14373
   537
by (rule order_trans [OF _ complex_mod_ge_zero], simp)
paulson@14323
   538
paulson@14374
   539
lemma complex_mod_triangle_ineq [simp]: "cmod (x + y) \<le> cmod(x) + cmod(y)"
paulson@14334
   540
apply (rule_tac n = 1 in realpow_increasing)
paulson@14323
   541
apply (auto intro:  order_trans [OF _ complex_mod_ge_zero]
paulson@15085
   542
            simp add: add_increasing power2_eq_square [symmetric])
paulson@14323
   543
done
paulson@14323
   544
paulson@14374
   545
lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
paulson@14373
   546
by (insert complex_mod_triangle_ineq [THEN add_right_mono, of b a"-cmod b"], simp)
paulson@14323
   547
paulson@14323
   548
lemma complex_mod_diff_commute: "cmod (x - y) = cmod (y - x)"
paulson@14373
   549
apply (induct x, induct y)
paulson@14353
   550
apply (auto simp add: complex_diff complex_mod right_diff_distrib power2_eq_square left_diff_distrib add_ac mult_ac)
paulson@14323
   551
done
paulson@14323
   552
paulson@14374
   553
lemma complex_mod_add_less:
paulson@14374
   554
     "[| cmod x < r; cmod y < s |] ==> cmod (x + y) < r + s"
paulson@14334
   555
by (auto intro: order_le_less_trans complex_mod_triangle_ineq)
paulson@14323
   556
paulson@14374
   557
lemma complex_mod_mult_less:
paulson@14374
   558
     "[| cmod x < r; cmod y < s |] ==> cmod (x * y) < r * s"
paulson@14334
   559
by (auto intro: real_mult_less_mono' simp add: complex_mod_mult)
paulson@14323
   560
paulson@14374
   561
lemma complex_mod_diff_ineq [simp]: "cmod(a) - cmod(b) \<le> cmod(a + b)"
paulson@14323
   562
apply (rule linorder_cases [of "cmod(a)" "cmod (b)"])
paulson@14323
   563
apply auto
paulson@14334
   564
apply (rule order_trans [of _ 0], rule order_less_imp_le)
paulson@14374
   565
apply (simp add: compare_rls, simp)
paulson@14323
   566
apply (simp add: compare_rls)
paulson@14323
   567
apply (rule complex_mod_minus [THEN subst])
paulson@14323
   568
apply (rule order_trans)
paulson@14323
   569
apply (rule_tac [2] complex_mod_triangle_ineq)
paulson@14373
   570
apply (auto simp add: add_ac)
paulson@14323
   571
done
paulson@14323
   572
paulson@14374
   573
lemma complex_Re_le_cmod [simp]: "Re z \<le> cmod z"
paulson@14373
   574
by (induct z, simp add: complex_mod del: realpow_Suc)
paulson@14323
   575
paulson@14354
   576
lemma complex_mod_gt_zero: "z \<noteq> 0 ==> 0 < cmod z"
paulson@14373
   577
apply (insert complex_mod_ge_zero [of z])
paulson@14334
   578
apply (drule order_le_imp_less_or_eq, auto)
paulson@14323
   579
done
paulson@14323
   580
paulson@14323
   581
huffman@20556
   582
subsection{*The normed division algebra of complex numbers*}
huffman@20556
   583
huffman@20556
   584
instance complex :: norm ..
huffman@20556
   585
huffman@20556
   586
defs (overloaded)
huffman@20556
   587
  complex_norm_def: "norm == cmod"
huffman@20556
   588
huffman@20556
   589
lemma of_real_complex_of_real: "of_real r = complex_of_real r"
huffman@20556
   590
by (simp add: complex_of_real_def of_real_def complex_scaleR_def)
huffman@20556
   591
huffman@20556
   592
instance complex :: real_normed_div_algebra
huffman@20556
   593
proof (intro_classes, unfold complex_norm_def)
huffman@20556
   594
  fix r :: real
huffman@20556
   595
  fix x y :: complex
huffman@20556
   596
  show "0 \<le> cmod x"
huffman@20556
   597
    by (rule complex_mod_ge_zero)
huffman@20556
   598
  show "(cmod x = 0) = (x = 0)"
huffman@20556
   599
    by (rule complex_mod_eq_zero_cancel)
huffman@20556
   600
  show "cmod (x + y) \<le> cmod x + cmod y"
huffman@20556
   601
    by (rule complex_mod_triangle_ineq)
huffman@20556
   602
  show "cmod (of_real r) = abs r"
huffman@20556
   603
    by (simp add: of_real_complex_of_real)
huffman@20556
   604
  show "cmod (x * y) = cmod x * cmod y"
huffman@20556
   605
    by (rule complex_mod_mult)
huffman@20556
   606
  show "cmod 1 = 1"
huffman@20556
   607
    by (rule complex_mod_one)
huffman@20556
   608
qed
huffman@20556
   609
paulson@14323
   610
subsection{*A Few More Theorems*}
paulson@14323
   611
paulson@14323
   612
lemma complex_mod_inverse: "cmod(inverse x) = inverse(cmod x)"
paulson@14373
   613
apply (case_tac "x=0", simp)
paulson@14323
   614
apply (rule_tac c1 = "cmod x" in real_mult_left_cancel [THEN iffD1])
paulson@14323
   615
apply (auto simp add: complex_mod_mult [symmetric])
paulson@14323
   616
done
paulson@14323
   617
paulson@14373
   618
lemma complex_mod_divide: "cmod(x/y) = cmod(x)/(cmod y)"
paulson@15013
   619
by (simp add: complex_divide_def divide_inverse complex_mod_mult complex_mod_inverse)
paulson@14323
   620
paulson@14354
   621
paulson@14354
   622
subsection{*Exponentiation*}
paulson@14354
   623
paulson@14354
   624
primrec
paulson@14354
   625
     complexpow_0:   "z ^ 0       = 1"
paulson@14354
   626
     complexpow_Suc: "z ^ (Suc n) = (z::complex) * (z ^ n)"
paulson@14354
   627
paulson@14354
   628
paulson@15003
   629
instance complex :: recpower
paulson@14354
   630
proof
paulson@14354
   631
  fix z :: complex
paulson@14354
   632
  fix n :: nat
paulson@14354
   633
  show "z^0 = 1" by simp
paulson@14354
   634
  show "z^(Suc n) = z * (z^n)" by simp
paulson@14354
   635
qed
paulson@14323
   636
paulson@14323
   637
paulson@14354
   638
lemma complex_of_real_pow: "complex_of_real (x ^ n) = (complex_of_real x) ^ n"
paulson@14323
   639
apply (induct_tac "n")
paulson@14354
   640
apply (auto simp add: complex_of_real_mult [symmetric])
paulson@14323
   641
done
paulson@14323
   642
paulson@14354
   643
lemma complex_cnj_pow: "cnj(z ^ n) = cnj(z) ^ n"
paulson@14323
   644
apply (induct_tac "n")
paulson@14354
   645
apply (auto simp add: complex_cnj_mult)
paulson@14323
   646
done
paulson@14323
   647
paulson@14354
   648
lemma complex_mod_complexpow: "cmod(x ^ n) = cmod(x) ^ n"
paulson@14354
   649
apply (induct_tac "n")
paulson@14354
   650
apply (auto simp add: complex_mod_mult)
paulson@14354
   651
done
paulson@14354
   652
paulson@14354
   653
lemma complexpow_i_squared [simp]: "ii ^ 2 = -(1::complex)"
paulson@14354
   654
by (simp add: i_def complex_mult complex_one_def complex_minus numeral_2_eq_2)
paulson@14354
   655
paulson@14354
   656
lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
paulson@14373
   657
by (simp add: i_def complex_zero_def)
paulson@14354
   658
paulson@14354
   659
paulson@14354
   660
subsection{*The Function @{term sgn}*}
paulson@14323
   661
paulson@14374
   662
lemma sgn_zero [simp]: "sgn 0 = 0"
paulson@14373
   663
by (simp add: sgn_def)
paulson@14323
   664
paulson@14374
   665
lemma sgn_one [simp]: "sgn 1 = 1"
paulson@14373
   666
by (simp add: sgn_def)
paulson@14323
   667
paulson@14323
   668
lemma sgn_minus: "sgn (-z) = - sgn(z)"
paulson@14373
   669
by (simp add: sgn_def)
paulson@14323
   670
paulson@14374
   671
lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
paulson@14377
   672
by (simp add: sgn_def)
paulson@14323
   673
paulson@14323
   674
lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
paulson@14373
   675
by (simp add: i_def complex_of_real_def complex_mult complex_add)
paulson@14323
   676
paulson@14374
   677
lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
paulson@14373
   678
by (simp add: i_def complex_one_def complex_mult complex_minus)
paulson@14323
   679
paulson@14374
   680
lemma complex_eq_cancel_iff2 [simp]:
paulson@14377
   681
     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
paulson@14377
   682
by (simp add: complex_of_real_def) 
paulson@14323
   683
paulson@14374
   684
lemma complex_eq_cancel_iff2a [simp]:
paulson@14377
   685
     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
paulson@14377
   686
by (simp add: complex_of_real_def)
paulson@14323
   687
paulson@14377
   688
lemma Complex_eq_0 [simp]: "(Complex x y = 0) = (x = 0 & y = 0)"
paulson@14377
   689
by (simp add: complex_zero_def)
paulson@14323
   690
paulson@14377
   691
lemma Complex_eq_1 [simp]: "(Complex x y = 1) = (x = 1 & y = 0)"
paulson@14377
   692
by (simp add: complex_one_def)
paulson@14323
   693
paulson@14377
   694
lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 & y = 1)"
paulson@14377
   695
by (simp add: i_def)
paulson@14323
   696
paulson@15013
   697
paulson@15013
   698
paulson@14374
   699
lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
paulson@15013
   700
proof (induct z)
paulson@15013
   701
  case (Complex x y)
paulson@15013
   702
    have "sqrt (x\<twosuperior> + y\<twosuperior>) * inverse (x\<twosuperior> + y\<twosuperior>) = inverse (sqrt (x\<twosuperior> + y\<twosuperior>))"
paulson@15013
   703
      by (simp add: divide_inverse [symmetric] sqrt_divide_self_eq)
paulson@15013
   704
    thus "Re (sgn (Complex x y)) = Re (Complex x y) /cmod (Complex x y)"
paulson@15013
   705
       by (simp add: sgn_def complex_of_real_def divide_inverse)
paulson@15013
   706
qed
paulson@15013
   707
paulson@14323
   708
paulson@14374
   709
lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
paulson@15013
   710
proof (induct z)
paulson@15013
   711
  case (Complex x y)
paulson@15013
   712
    have "sqrt (x\<twosuperior> + y\<twosuperior>) * inverse (x\<twosuperior> + y\<twosuperior>) = inverse (sqrt (x\<twosuperior> + y\<twosuperior>))"
paulson@15013
   713
      by (simp add: divide_inverse [symmetric] sqrt_divide_self_eq)
paulson@15013
   714
    thus "Im (sgn (Complex x y)) = Im (Complex x y) /cmod (Complex x y)"
paulson@15013
   715
       by (simp add: sgn_def complex_of_real_def divide_inverse)
paulson@15013
   716
qed
paulson@14323
   717
paulson@14323
   718
lemma complex_inverse_complex_split:
paulson@14323
   719
     "inverse(complex_of_real x + ii * complex_of_real y) =
paulson@14323
   720
      complex_of_real(x/(x ^ 2 + y ^ 2)) -
paulson@14323
   721
      ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
paulson@14374
   722
by (simp add: complex_of_real_def i_def complex_mult complex_add
paulson@15013
   723
         diff_minus complex_minus complex_inverse divide_inverse)
paulson@14323
   724
paulson@14323
   725
(*----------------------------------------------------------------------------*)
paulson@14323
   726
(* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
paulson@14323
   727
(* many of the theorems are not used - so should they be kept?                *)
paulson@14323
   728
(*----------------------------------------------------------------------------*)
paulson@14323
   729
paulson@14354
   730
lemma complex_of_real_zero_iff [simp]: "(complex_of_real y = 0) = (y = 0)"
paulson@14354
   731
by (auto simp add: complex_zero_def complex_of_real_def)
paulson@14354
   732
paulson@14354
   733
lemma cos_arg_i_mult_zero_pos:
paulson@14377
   734
   "0 < y ==> cos (arg(Complex 0 y)) = 0"
paulson@14373
   735
apply (simp add: arg_def abs_if)
paulson@14334
   736
apply (rule_tac a = "pi/2" in someI2, auto)
paulson@14334
   737
apply (rule order_less_trans [of _ 0], auto)
paulson@14323
   738
done
paulson@14323
   739
paulson@14354
   740
lemma cos_arg_i_mult_zero_neg:
paulson@14377
   741
   "y < 0 ==> cos (arg(Complex 0 y)) = 0"
paulson@14373
   742
apply (simp add: arg_def abs_if)
paulson@14334
   743
apply (rule_tac a = "- pi/2" in someI2, auto)
paulson@14334
   744
apply (rule order_trans [of _ 0], auto)
paulson@14323
   745
done
paulson@14323
   746
paulson@14374
   747
lemma cos_arg_i_mult_zero [simp]:
paulson@14377
   748
     "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
paulson@14377
   749
by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
paulson@14323
   750
paulson@14323
   751
paulson@14323
   752
subsection{*Finally! Polar Form for Complex Numbers*}
paulson@14323
   753
paulson@14374
   754
lemma complex_split_polar:
paulson@14377
   755
     "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
paulson@14377
   756
apply (induct z) 
paulson@14377
   757
apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
paulson@14323
   758
done
paulson@14323
   759
paulson@14354
   760
lemma rcis_Ex: "\<exists>r a. z = rcis r a"
paulson@14377
   761
apply (induct z) 
paulson@14377
   762
apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
paulson@14323
   763
done
paulson@14323
   764
paulson@14374
   765
lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
paulson@14373
   766
by (simp add: rcis_def cis_def)
paulson@14323
   767
paulson@14348
   768
lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
paulson@14373
   769
by (simp add: rcis_def cis_def)
paulson@14323
   770
paulson@14377
   771
lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
paulson@14377
   772
proof -
paulson@14377
   773
  have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
paulson@14377
   774
    by (simp only: power_mult_distrib right_distrib) 
paulson@14377
   775
  thus ?thesis by simp
paulson@14377
   776
qed
paulson@14323
   777
paulson@14374
   778
lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
paulson@14377
   779
by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
paulson@14323
   780
paulson@14323
   781
lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
paulson@14373
   782
apply (simp add: cmod_def)
paulson@14323
   783
apply (rule real_sqrt_eq_iff [THEN iffD2])
paulson@14323
   784
apply (auto simp add: complex_mult_cnj)
paulson@14323
   785
done
paulson@14323
   786
paulson@14374
   787
lemma complex_Re_cnj [simp]: "Re(cnj z) = Re z"
paulson@14373
   788
by (induct z, simp add: complex_cnj)
paulson@14323
   789
paulson@14374
   790
lemma complex_Im_cnj [simp]: "Im(cnj z) = - Im z"
paulson@14374
   791
by (induct z, simp add: complex_cnj)
paulson@14374
   792
paulson@14374
   793
lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
paulson@14373
   794
by (induct z, simp add: complex_cnj complex_mult)
paulson@14323
   795
paulson@14323
   796
paulson@14323
   797
(*---------------------------------------------------------------------------*)
paulson@14323
   798
(*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
paulson@14323
   799
(*---------------------------------------------------------------------------*)
paulson@14323
   800
paulson@14323
   801
lemma cis_rcis_eq: "cis a = rcis 1 a"
paulson@14373
   802
by (simp add: rcis_def)
paulson@14323
   803
paulson@14374
   804
lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
paulson@15013
   805
by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib
paulson@15013
   806
              complex_of_real_def)
paulson@14323
   807
paulson@14323
   808
lemma cis_mult: "cis a * cis b = cis (a + b)"
paulson@14373
   809
by (simp add: cis_rcis_eq rcis_mult)
paulson@14323
   810
paulson@14374
   811
lemma cis_zero [simp]: "cis 0 = 1"
paulson@14377
   812
by (simp add: cis_def complex_one_def)
paulson@14323
   813
paulson@14374
   814
lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
paulson@14373
   815
by (simp add: rcis_def)
paulson@14323
   816
paulson@14374
   817
lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
paulson@14373
   818
by (simp add: rcis_def)
paulson@14323
   819
paulson@14323
   820
lemma complex_of_real_minus_one:
paulson@14323
   821
   "complex_of_real (-(1::real)) = -(1::complex)"
paulson@14377
   822
by (simp add: complex_of_real_def complex_one_def complex_minus)
paulson@14323
   823
paulson@14374
   824
lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
paulson@14373
   825
by (simp add: complex_mult_assoc [symmetric])
paulson@14323
   826
paulson@14323
   827
paulson@14323
   828
lemma cis_real_of_nat_Suc_mult:
paulson@14323
   829
   "cis (real (Suc n) * a) = cis a * cis (real n * a)"
paulson@14377
   830
by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
paulson@14323
   831
paulson@14323
   832
lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
paulson@14323
   833
apply (induct_tac "n")
paulson@14323
   834
apply (auto simp add: cis_real_of_nat_Suc_mult)
paulson@14323
   835
done
paulson@14323
   836
paulson@14374
   837
lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
paulson@14374
   838
by (simp add: rcis_def power_mult_distrib DeMoivre complex_of_real_pow)
paulson@14323
   839
paulson@14374
   840
lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
paulson@14374
   841
by (simp add: cis_def complex_inverse_complex_split complex_of_real_minus 
paulson@15013
   842
              diff_minus)
paulson@14323
   843
paulson@14323
   844
lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
paulson@14430
   845
by (simp add: divide_inverse rcis_def complex_of_real_inverse)
paulson@14323
   846
paulson@14323
   847
lemma cis_divide: "cis a / cis b = cis (a - b)"
paulson@14373
   848
by (simp add: complex_divide_def cis_mult real_diff_def)
paulson@14323
   849
paulson@14354
   850
lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
paulson@14373
   851
apply (simp add: complex_divide_def)
paulson@14373
   852
apply (case_tac "r2=0", simp)
paulson@14373
   853
apply (simp add: rcis_inverse rcis_mult real_diff_def)
paulson@14323
   854
done
paulson@14323
   855
paulson@14374
   856
lemma Re_cis [simp]: "Re(cis a) = cos a"
paulson@14373
   857
by (simp add: cis_def)
paulson@14323
   858
paulson@14374
   859
lemma Im_cis [simp]: "Im(cis a) = sin a"
paulson@14373
   860
by (simp add: cis_def)
paulson@14323
   861
paulson@14323
   862
lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
paulson@14334
   863
by (auto simp add: DeMoivre)
paulson@14323
   864
paulson@14323
   865
lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
paulson@14334
   866
by (auto simp add: DeMoivre)
paulson@14323
   867
paulson@14323
   868
lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
paulson@14374
   869
by (simp add: expi_def complex_Re_add exp_add complex_Im_add 
paulson@14374
   870
              cis_mult [symmetric] complex_of_real_mult mult_ac)
paulson@14323
   871
paulson@14374
   872
lemma expi_zero [simp]: "expi (0::complex) = 1"
paulson@14373
   873
by (simp add: expi_def)
paulson@14323
   874
paulson@14374
   875
lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
paulson@14373
   876
apply (insert rcis_Ex [of z])
paulson@14323
   877
apply (auto simp add: expi_def rcis_def complex_mult_assoc [symmetric] complex_of_real_mult)
paulson@14334
   878
apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
paulson@14323
   879
done
paulson@14323
   880
paulson@14323
   881
paulson@14387
   882
subsection{*Numerals and Arithmetic*}
paulson@14387
   883
paulson@14387
   884
instance complex :: number ..
paulson@14387
   885
paulson@15013
   886
defs (overloaded)
haftmann@20485
   887
  complex_number_of_def: "(number_of w :: complex) == of_int w"
paulson@15013
   888
    --{*the type constraint is essential!*}
paulson@14387
   889
paulson@14387
   890
instance complex :: number_ring
paulson@15013
   891
by (intro_classes, simp add: complex_number_of_def) 
paulson@15013
   892
paulson@15013
   893
paulson@15013
   894
lemma complex_of_real_of_nat [simp]: "complex_of_real (of_nat n) = of_nat n"
wenzelm@19765
   895
  by (induct n) simp_all
paulson@15013
   896
paulson@15013
   897
lemma complex_of_real_of_int [simp]: "complex_of_real (of_int z) = of_int z"
paulson@15013
   898
proof (cases z)
paulson@15013
   899
  case (1 n)
wenzelm@19765
   900
  thus ?thesis by simp
paulson@15013
   901
next
paulson@15013
   902
  case (2 n)
wenzelm@19765
   903
  thus ?thesis 
wenzelm@19765
   904
    by (simp only: of_int_minus complex_of_real_minus, simp)
paulson@14387
   905
qed
paulson@14387
   906
paulson@14387
   907
paulson@14387
   908
text{*Collapse applications of @{term complex_of_real} to @{term number_of}*}
paulson@14387
   909
lemma complex_number_of [simp]: "complex_of_real (number_of w) = number_of w"
paulson@15013
   910
by (simp add: complex_number_of_def real_number_of_def) 
paulson@14387
   911
paulson@14387
   912
text{*This theorem is necessary because theorems such as
paulson@14387
   913
   @{text iszero_number_of_0} only hold for ordered rings. They cannot
paulson@14387
   914
   be generalized to fields in general because they fail for finite fields.
paulson@14387
   915
   They work for type complex because the reals can be embedded in them.*}
paulson@14387
   916
lemma iszero_complex_number_of [simp]:
paulson@14387
   917
     "iszero (number_of w :: complex) = iszero (number_of w :: real)"
paulson@14387
   918
by (simp only: complex_of_real_zero_iff complex_number_of [symmetric] 
paulson@14387
   919
               iszero_def)  
paulson@14387
   920
paulson@14387
   921
lemma complex_number_of_cnj [simp]: "cnj(number_of v :: complex) = number_of v"
paulson@15481
   922
by (simp only: complex_number_of [symmetric] complex_cnj_complex_of_real)
paulson@14387
   923
paulson@14387
   924
lemma complex_number_of_cmod: 
paulson@14387
   925
      "cmod(number_of v :: complex) = abs (number_of v :: real)"
paulson@14387
   926
by (simp only: complex_number_of [symmetric] complex_mod_complex_of_real)
paulson@14387
   927
paulson@14387
   928
lemma complex_number_of_Re [simp]: "Re(number_of v :: complex) = number_of v"
paulson@14387
   929
by (simp only: complex_number_of [symmetric] Re_complex_of_real)
paulson@14387
   930
paulson@14387
   931
lemma complex_number_of_Im [simp]: "Im(number_of v :: complex) = 0"
paulson@14387
   932
by (simp only: complex_number_of [symmetric] Im_complex_of_real)
paulson@14387
   933
paulson@14387
   934
lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
paulson@14387
   935
by (simp add: expi_def complex_Re_mult_eq complex_Im_mult_eq cis_def)
paulson@14387
   936
paulson@14387
   937
paulson@14387
   938
(*examples:
paulson@14387
   939
print_depth 22
paulson@14387
   940
set timing;
paulson@14387
   941
set trace_simp;
paulson@14387
   942
fun test s = (Goal s, by (Simp_tac 1)); 
paulson@14387
   943
paulson@14387
   944
test "23 * ii + 45 * ii= (x::complex)";
paulson@14387
   945
paulson@14387
   946
test "5 * ii + 12 - 45 * ii= (x::complex)";
paulson@14387
   947
test "5 * ii + 40 - 12 * ii + 9 = (x::complex) + 89 * ii";
paulson@14387
   948
test "5 * ii + 40 - 12 * ii + 9 - 78 = (x::complex) + 89 * ii";
paulson@14387
   949
paulson@14387
   950
test "l + 10 * ii + 90 + 3*l +  9 + 45 * ii= (x::complex)";
paulson@14387
   951
test "87 + 10 * ii + 90 + 3*7 +  9 + 45 * ii= (x::complex)";
paulson@14387
   952
paulson@14387
   953
paulson@14387
   954
fun test s = (Goal s; by (Asm_simp_tac 1)); 
paulson@14387
   955
paulson@14387
   956
test "x*k = k*(y::complex)";
paulson@14387
   957
test "k = k*(y::complex)"; 
paulson@14387
   958
test "a*(b*c) = (b::complex)";
paulson@14387
   959
test "a*(b*c) = d*(b::complex)*(x*a)";
paulson@14387
   960
paulson@14387
   961
paulson@14387
   962
test "(x*k) / (k*(y::complex)) = (uu::complex)";
paulson@14387
   963
test "(k) / (k*(y::complex)) = (uu::complex)"; 
paulson@14387
   964
test "(a*(b*c)) / ((b::complex)) = (uu::complex)";
paulson@14387
   965
test "(a*(b*c)) / (d*(b::complex)*(x*a)) = (uu::complex)";
paulson@14387
   966
paulson@15003
   967
FIXME: what do we do about this?
paulson@14387
   968
test "a*(b*c)/(y*z) = d*(b::complex)*(x*a)/z";
paulson@14387
   969
*)
paulson@14387
   970
paulson@13957
   971
end
paulson@13957
   972
paulson@13957
   973