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