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