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