src/HOL/Complex.thy
 author huffman Tue Sep 06 07:48:59 2011 -0700 (2011-09-06) changeset 44749 5b1e1432c320 parent 44748 7f6838b3474a child 44761 0694fc3248fd permissions -rw-r--r--
remove redundant lemma real_sum_squared_expand in favor of power2_sum
```     1 (*  Title:       HOL/Complex.thy
```
```     2     Author:      Jacques D. Fleuriot
```
```     3     Copyright:   2001 University of Edinburgh
```
```     4     Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
```
```     5 *)
```
```     6
```
```     7 header {* Complex Numbers: Rectangular and Polar Representations *}
```
```     8
```
```     9 theory Complex
```
```    10 imports Transcendental
```
```    11 begin
```
```    12
```
```    13 datatype complex = Complex real real
```
```    14
```
```    15 primrec Re :: "complex \<Rightarrow> real"
```
```    16   where Re: "Re (Complex x y) = x"
```
```    17
```
```    18 primrec Im :: "complex \<Rightarrow> real"
```
```    19   where Im: "Im (Complex x y) = y"
```
```    20
```
```    21 lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
```
```    22   by (induct z) simp
```
```    23
```
```    24 lemma complex_eqI [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y"
```
```    25   by (induct x, induct y) simp
```
```    26
```
```    27 lemma complex_eq_iff: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y"
```
```    28   by (induct x, induct y) simp
```
```    29
```
```    30
```
```    31 subsection {* Addition and Subtraction *}
```
```    32
```
```    33 instantiation complex :: ab_group_add
```
```    34 begin
```
```    35
```
```    36 definition complex_zero_def:
```
```    37   "0 = Complex 0 0"
```
```    38
```
```    39 definition complex_add_def:
```
```    40   "x + y = Complex (Re x + Re y) (Im x + Im y)"
```
```    41
```
```    42 definition complex_minus_def:
```
```    43   "- x = Complex (- Re x) (- Im x)"
```
```    44
```
```    45 definition complex_diff_def:
```
```    46   "x - (y\<Colon>complex) = x + - y"
```
```    47
```
```    48 lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
```
```    49   by (simp add: complex_zero_def)
```
```    50
```
```    51 lemma complex_Re_zero [simp]: "Re 0 = 0"
```
```    52   by (simp add: complex_zero_def)
```
```    53
```
```    54 lemma complex_Im_zero [simp]: "Im 0 = 0"
```
```    55   by (simp add: complex_zero_def)
```
```    56
```
```    57 lemma complex_add [simp]:
```
```    58   "Complex a b + Complex c d = Complex (a + c) (b + d)"
```
```    59   by (simp add: complex_add_def)
```
```    60
```
```    61 lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y"
```
```    62   by (simp add: complex_add_def)
```
```    63
```
```    64 lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y"
```
```    65   by (simp add: complex_add_def)
```
```    66
```
```    67 lemma complex_minus [simp]:
```
```    68   "- (Complex a b) = Complex (- a) (- b)"
```
```    69   by (simp add: complex_minus_def)
```
```    70
```
```    71 lemma complex_Re_minus [simp]: "Re (- x) = - Re x"
```
```    72   by (simp add: complex_minus_def)
```
```    73
```
```    74 lemma complex_Im_minus [simp]: "Im (- x) = - Im x"
```
```    75   by (simp add: complex_minus_def)
```
```    76
```
```    77 lemma complex_diff [simp]:
```
```    78   "Complex a b - Complex c d = Complex (a - c) (b - d)"
```
```    79   by (simp add: complex_diff_def)
```
```    80
```
```    81 lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y"
```
```    82   by (simp add: complex_diff_def)
```
```    83
```
```    84 lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y"
```
```    85   by (simp add: complex_diff_def)
```
```    86
```
```    87 instance
```
```    88   by intro_classes (simp_all add: complex_add_def complex_diff_def)
```
```    89
```
```    90 end
```
```    91
```
```    92
```
```    93 subsection {* Multiplication and Division *}
```
```    94
```
```    95 instantiation complex :: field_inverse_zero
```
```    96 begin
```
```    97
```
```    98 definition complex_one_def:
```
```    99   "1 = Complex 1 0"
```
```   100
```
```   101 definition complex_mult_def:
```
```   102   "x * y = Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)"
```
```   103
```
```   104 definition complex_inverse_def:
```
```   105   "inverse x =
```
```   106     Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))"
```
```   107
```
```   108 definition complex_divide_def:
```
```   109   "x / (y\<Colon>complex) = x * inverse y"
```
```   110
```
```   111 lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)"
```
```   112   by (simp add: complex_one_def)
```
```   113
```
```   114 lemma complex_Re_one [simp]: "Re 1 = 1"
```
```   115   by (simp add: complex_one_def)
```
```   116
```
```   117 lemma complex_Im_one [simp]: "Im 1 = 0"
```
```   118   by (simp add: complex_one_def)
```
```   119
```
```   120 lemma complex_mult [simp]:
```
```   121   "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)"
```
```   122   by (simp add: complex_mult_def)
```
```   123
```
```   124 lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y"
```
```   125   by (simp add: complex_mult_def)
```
```   126
```
```   127 lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y"
```
```   128   by (simp add: complex_mult_def)
```
```   129
```
```   130 lemma complex_inverse [simp]:
```
```   131   "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))"
```
```   132   by (simp add: complex_inverse_def)
```
```   133
```
```   134 lemma complex_Re_inverse:
```
```   135   "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
```
```   136   by (simp add: complex_inverse_def)
```
```   137
```
```   138 lemma complex_Im_inverse:
```
```   139   "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
```
```   140   by (simp add: complex_inverse_def)
```
```   141
```
```   142 instance
```
```   143   by intro_classes (simp_all add: complex_mult_def
```
```   144     right_distrib left_distrib right_diff_distrib left_diff_distrib
```
```   145     complex_inverse_def complex_divide_def
```
```   146     power2_eq_square add_divide_distrib [symmetric]
```
```   147     complex_eq_iff)
```
```   148
```
```   149 end
```
```   150
```
```   151
```
```   152 subsection {* Numerals and Arithmetic *}
```
```   153
```
```   154 instantiation complex :: number_ring
```
```   155 begin
```
```   156
```
```   157 definition complex_number_of_def:
```
```   158   "number_of w = (of_int w \<Colon> complex)"
```
```   159
```
```   160 instance
```
```   161   by intro_classes (simp only: complex_number_of_def)
```
```   162
```
```   163 end
```
```   164
```
```   165 lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n"
```
```   166   by (induct n) simp_all
```
```   167
```
```   168 lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0"
```
```   169   by (induct n) simp_all
```
```   170
```
```   171 lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z"
```
```   172   by (cases z rule: int_diff_cases) simp
```
```   173
```
```   174 lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
```
```   175   by (cases z rule: int_diff_cases) simp
```
```   176
```
```   177 lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v"
```
```   178   unfolding number_of_eq by (rule complex_Re_of_int)
```
```   179
```
```   180 lemma complex_Im_number_of [simp]: "Im (number_of v) = 0"
```
```   181   unfolding number_of_eq by (rule complex_Im_of_int)
```
```   182
```
```   183 lemma Complex_eq_number_of [simp]:
```
```   184   "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)"
```
```   185   by (simp add: complex_eq_iff)
```
```   186
```
```   187
```
```   188 subsection {* Scalar Multiplication *}
```
```   189
```
```   190 instantiation complex :: real_field
```
```   191 begin
```
```   192
```
```   193 definition complex_scaleR_def:
```
```   194   "scaleR r x = Complex (r * Re x) (r * Im x)"
```
```   195
```
```   196 lemma complex_scaleR [simp]:
```
```   197   "scaleR r (Complex a b) = Complex (r * a) (r * b)"
```
```   198   unfolding complex_scaleR_def by simp
```
```   199
```
```   200 lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x"
```
```   201   unfolding complex_scaleR_def by simp
```
```   202
```
```   203 lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x"
```
```   204   unfolding complex_scaleR_def by simp
```
```   205
```
```   206 instance
```
```   207 proof
```
```   208   fix a b :: real and x y :: complex
```
```   209   show "scaleR a (x + y) = scaleR a x + scaleR a y"
```
```   210     by (simp add: complex_eq_iff right_distrib)
```
```   211   show "scaleR (a + b) x = scaleR a x + scaleR b x"
```
```   212     by (simp add: complex_eq_iff left_distrib)
```
```   213   show "scaleR a (scaleR b x) = scaleR (a * b) x"
```
```   214     by (simp add: complex_eq_iff mult_assoc)
```
```   215   show "scaleR 1 x = x"
```
```   216     by (simp add: complex_eq_iff)
```
```   217   show "scaleR a x * y = scaleR a (x * y)"
```
```   218     by (simp add: complex_eq_iff algebra_simps)
```
```   219   show "x * scaleR a y = scaleR a (x * y)"
```
```   220     by (simp add: complex_eq_iff algebra_simps)
```
```   221 qed
```
```   222
```
```   223 end
```
```   224
```
```   225
```
```   226 subsection{* Properties of Embedding from Reals *}
```
```   227
```
```   228 abbreviation complex_of_real :: "real \<Rightarrow> complex"
```
```   229   where "complex_of_real \<equiv> of_real"
```
```   230
```
```   231 lemma complex_of_real_def: "complex_of_real r = Complex r 0"
```
```   232   by (simp add: of_real_def complex_scaleR_def)
```
```   233
```
```   234 lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
```
```   235   by (simp add: complex_of_real_def)
```
```   236
```
```   237 lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
```
```   238   by (simp add: complex_of_real_def)
```
```   239
```
```   240 lemma Complex_add_complex_of_real [simp]:
```
```   241   shows "Complex x y + complex_of_real r = Complex (x+r) y"
```
```   242   by (simp add: complex_of_real_def)
```
```   243
```
```   244 lemma complex_of_real_add_Complex [simp]:
```
```   245   shows "complex_of_real r + Complex x y = Complex (r+x) y"
```
```   246   by (simp add: complex_of_real_def)
```
```   247
```
```   248 lemma Complex_mult_complex_of_real:
```
```   249   shows "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
```
```   250   by (simp add: complex_of_real_def)
```
```   251
```
```   252 lemma complex_of_real_mult_Complex:
```
```   253   shows "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
```
```   254   by (simp add: complex_of_real_def)
```
```   255
```
```   256
```
```   257 subsection {* Vector Norm *}
```
```   258
```
```   259 instantiation complex :: real_normed_field
```
```   260 begin
```
```   261
```
```   262 definition complex_norm_def:
```
```   263   "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
```
```   264
```
```   265 abbreviation cmod :: "complex \<Rightarrow> real"
```
```   266   where "cmod \<equiv> norm"
```
```   267
```
```   268 definition complex_sgn_def:
```
```   269   "sgn x = x /\<^sub>R cmod x"
```
```   270
```
```   271 definition dist_complex_def:
```
```   272   "dist x y = cmod (x - y)"
```
```   273
```
```   274 definition open_complex_def:
```
```   275   "open (S :: complex set) \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
```
```   276
```
```   277 lemmas cmod_def = complex_norm_def
```
```   278
```
```   279 lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
```
```   280   by (simp add: complex_norm_def)
```
```   281
```
```   282 instance proof
```
```   283   fix r :: real and x y :: complex and S :: "complex set"
```
```   284   show "0 \<le> norm x"
```
```   285     by (induct x) simp
```
```   286   show "(norm x = 0) = (x = 0)"
```
```   287     by (induct x) simp
```
```   288   show "norm (x + y) \<le> norm x + norm y"
```
```   289     by (induct x, induct y)
```
```   290        (simp add: real_sqrt_sum_squares_triangle_ineq)
```
```   291   show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
```
```   292     by (induct x)
```
```   293        (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult)
```
```   294   show "norm (x * y) = norm x * norm y"
```
```   295     by (induct x, induct y)
```
```   296        (simp add: real_sqrt_mult [symmetric] power2_eq_square algebra_simps)
```
```   297   show "sgn x = x /\<^sub>R cmod x"
```
```   298     by (rule complex_sgn_def)
```
```   299   show "dist x y = cmod (x - y)"
```
```   300     by (rule dist_complex_def)
```
```   301   show "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
```
```   302     by (rule open_complex_def)
```
```   303 qed
```
```   304
```
```   305 end
```
```   306
```
```   307 lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
```
```   308   by simp
```
```   309
```
```   310 lemma cmod_complex_polar [simp]:
```
```   311   "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
```
```   312   by (simp add: norm_mult)
```
```   313
```
```   314 lemma complex_Re_le_cmod: "Re x \<le> cmod x"
```
```   315   unfolding complex_norm_def
```
```   316   by (rule real_sqrt_sum_squares_ge1)
```
```   317
```
```   318 lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
```
```   319   by (rule order_trans [OF _ norm_ge_zero], simp)
```
```   320
```
```   321 lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
```
```   322   by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
```
```   323
```
```   324 lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x"
```
```   325   by (cases x) simp
```
```   326
```
```   327 lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x"
```
```   328   by (cases x) simp
```
```   329
```
```   330
```
```   331 subsection {* Completeness of the Complexes *}
```
```   332
```
```   333 lemma bounded_linear_Re: "bounded_linear Re"
```
```   334   by (rule bounded_linear_intro [where K=1], simp_all add: complex_norm_def)
```
```   335
```
```   336 lemma bounded_linear_Im: "bounded_linear Im"
```
```   337   by (rule bounded_linear_intro [where K=1], simp_all add: complex_norm_def)
```
```   338
```
```   339 lemmas tendsto_Re [tendsto_intros] =
```
```   340   bounded_linear.tendsto [OF bounded_linear_Re]
```
```   341
```
```   342 lemmas tendsto_Im [tendsto_intros] =
```
```   343   bounded_linear.tendsto [OF bounded_linear_Im]
```
```   344
```
```   345 lemmas isCont_Re [simp] = bounded_linear.isCont [OF bounded_linear_Re]
```
```   346 lemmas isCont_Im [simp] = bounded_linear.isCont [OF bounded_linear_Im]
```
```   347 lemmas Cauchy_Re = bounded_linear.Cauchy [OF bounded_linear_Re]
```
```   348 lemmas Cauchy_Im = bounded_linear.Cauchy [OF bounded_linear_Im]
```
```   349
```
```   350 lemma tendsto_Complex [tendsto_intros]:
```
```   351   assumes "(f ---> a) F" and "(g ---> b) F"
```
```   352   shows "((\<lambda>x. Complex (f x) (g x)) ---> Complex a b) F"
```
```   353 proof (rule tendstoI)
```
```   354   fix r :: real assume "0 < r"
```
```   355   hence "0 < r / sqrt 2" by (simp add: divide_pos_pos)
```
```   356   have "eventually (\<lambda>x. dist (f x) a < r / sqrt 2) F"
```
```   357     using `(f ---> a) F` and `0 < r / sqrt 2` by (rule tendstoD)
```
```   358   moreover
```
```   359   have "eventually (\<lambda>x. dist (g x) b < r / sqrt 2) F"
```
```   360     using `(g ---> b) F` and `0 < r / sqrt 2` by (rule tendstoD)
```
```   361   ultimately
```
```   362   show "eventually (\<lambda>x. dist (Complex (f x) (g x)) (Complex a b) < r) F"
```
```   363     by (rule eventually_elim2)
```
```   364        (simp add: dist_norm real_sqrt_sum_squares_less)
```
```   365 qed
```
```   366
```
```   367 instance complex :: banach
```
```   368 proof
```
```   369   fix X :: "nat \<Rightarrow> complex"
```
```   370   assume X: "Cauchy X"
```
```   371   from Cauchy_Re [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))"
```
```   372     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
```
```   373   from Cauchy_Im [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))"
```
```   374     by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
```
```   375   have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))"
```
```   376     using tendsto_Complex [OF 1 2] by simp
```
```   377   thus "convergent X"
```
```   378     by (rule convergentI)
```
```   379 qed
```
```   380
```
```   381
```
```   382 subsection {* The Complex Number @{term "\<i>"} *}
```
```   383
```
```   384 definition "ii" :: complex  ("\<i>")
```
```   385   where i_def: "ii \<equiv> Complex 0 1"
```
```   386
```
```   387 lemma complex_Re_i [simp]: "Re ii = 0"
```
```   388   by (simp add: i_def)
```
```   389
```
```   390 lemma complex_Im_i [simp]: "Im ii = 1"
```
```   391   by (simp add: i_def)
```
```   392
```
```   393 lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
```
```   394   by (simp add: i_def)
```
```   395
```
```   396 lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
```
```   397   by (simp add: complex_eq_iff)
```
```   398
```
```   399 lemma complex_i_not_one [simp]: "ii \<noteq> 1"
```
```   400   by (simp add: complex_eq_iff)
```
```   401
```
```   402 lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w"
```
```   403   by (simp add: complex_eq_iff)
```
```   404
```
```   405 lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a"
```
```   406   by (simp add: complex_eq_iff)
```
```   407
```
```   408 lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a"
```
```   409   by (simp add: complex_eq_iff)
```
```   410
```
```   411 lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
```
```   412   by (simp add: i_def complex_of_real_def)
```
```   413
```
```   414 lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
```
```   415   by (simp add: i_def complex_of_real_def)
```
```   416
```
```   417 lemma i_squared [simp]: "ii * ii = -1"
```
```   418   by (simp add: i_def)
```
```   419
```
```   420 lemma power2_i [simp]: "ii\<twosuperior> = -1"
```
```   421   by (simp add: power2_eq_square)
```
```   422
```
```   423 lemma inverse_i [simp]: "inverse ii = - ii"
```
```   424   by (rule inverse_unique, simp)
```
```   425
```
```   426
```
```   427 subsection {* Complex Conjugation *}
```
```   428
```
```   429 definition cnj :: "complex \<Rightarrow> complex" where
```
```   430   "cnj z = Complex (Re z) (- Im z)"
```
```   431
```
```   432 lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)"
```
```   433   by (simp add: cnj_def)
```
```   434
```
```   435 lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x"
```
```   436   by (simp add: cnj_def)
```
```   437
```
```   438 lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x"
```
```   439   by (simp add: cnj_def)
```
```   440
```
```   441 lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
```
```   442   by (simp add: complex_eq_iff)
```
```   443
```
```   444 lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
```
```   445   by (simp add: cnj_def)
```
```   446
```
```   447 lemma complex_cnj_zero [simp]: "cnj 0 = 0"
```
```   448   by (simp add: complex_eq_iff)
```
```   449
```
```   450 lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
```
```   451   by (simp add: complex_eq_iff)
```
```   452
```
```   453 lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y"
```
```   454   by (simp add: complex_eq_iff)
```
```   455
```
```   456 lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y"
```
```   457   by (simp add: complex_eq_iff)
```
```   458
```
```   459 lemma complex_cnj_minus: "cnj (- x) = - cnj x"
```
```   460   by (simp add: complex_eq_iff)
```
```   461
```
```   462 lemma complex_cnj_one [simp]: "cnj 1 = 1"
```
```   463   by (simp add: complex_eq_iff)
```
```   464
```
```   465 lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y"
```
```   466   by (simp add: complex_eq_iff)
```
```   467
```
```   468 lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)"
```
```   469   by (simp add: complex_inverse_def)
```
```   470
```
```   471 lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y"
```
```   472   by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
```
```   473
```
```   474 lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n"
```
```   475   by (induct n, simp_all add: complex_cnj_mult)
```
```   476
```
```   477 lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n"
```
```   478   by (simp add: complex_eq_iff)
```
```   479
```
```   480 lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z"
```
```   481   by (simp add: complex_eq_iff)
```
```   482
```
```   483 lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w"
```
```   484   by (simp add: complex_eq_iff)
```
```   485
```
```   486 lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)"
```
```   487   by (simp add: complex_eq_iff)
```
```   488
```
```   489 lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
```
```   490   by (simp add: complex_norm_def)
```
```   491
```
```   492 lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x"
```
```   493   by (simp add: complex_eq_iff)
```
```   494
```
```   495 lemma complex_cnj_i [simp]: "cnj ii = - ii"
```
```   496   by (simp add: complex_eq_iff)
```
```   497
```
```   498 lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)"
```
```   499   by (simp add: complex_eq_iff)
```
```   500
```
```   501 lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii"
```
```   502   by (simp add: complex_eq_iff)
```
```   503
```
```   504 lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
```
```   505   by (simp add: complex_eq_iff power2_eq_square)
```
```   506
```
```   507 lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
```
```   508   by (simp add: norm_mult power2_eq_square)
```
```   509
```
```   510 lemma bounded_linear_cnj: "bounded_linear cnj"
```
```   511   using complex_cnj_add complex_cnj_scaleR
```
```   512   by (rule bounded_linear_intro [where K=1], simp)
```
```   513
```
```   514 lemmas tendsto_cnj [tendsto_intros] =
```
```   515   bounded_linear.tendsto [OF bounded_linear_cnj]
```
```   516
```
```   517 lemmas isCont_cnj [simp] =
```
```   518   bounded_linear.isCont [OF bounded_linear_cnj]
```
```   519
```
```   520
```
```   521 subsection{*The Functions @{term sgn} and @{term arg}*}
```
```   522
```
```   523 text {*------------ Argand -------------*}
```
```   524
```
```   525 definition arg :: "complex => real" where
```
```   526   "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
```
```   527
```
```   528 lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
```
```   529   by (simp add: sgn_div_norm divide_inverse scaleR_conv_of_real mult_commute)
```
```   530
```
```   531 lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
```
```   532   by (simp add: i_def complex_of_real_def)
```
```   533
```
```   534 lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
```
```   535   by (simp add: i_def complex_one_def)
```
```   536
```
```   537 lemma complex_eq_cancel_iff2 [simp]:
```
```   538   shows "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
```
```   539   by (simp add: complex_of_real_def)
```
```   540
```
```   541 lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
```
```   542   by (simp add: complex_sgn_def divide_inverse)
```
```   543
```
```   544 lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
```
```   545   by (simp add: complex_sgn_def divide_inverse)
```
```   546
```
```   547 lemma complex_inverse_complex_split:
```
```   548      "inverse(complex_of_real x + ii * complex_of_real y) =
```
```   549       complex_of_real(x/(x ^ 2 + y ^ 2)) -
```
```   550       ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
```
```   551   by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
```
```   552
```
```   553 (*----------------------------------------------------------------------------*)
```
```   554 (* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
```
```   555 (* many of the theorems are not used - so should they be kept?                *)
```
```   556 (*----------------------------------------------------------------------------*)
```
```   557
```
```   558 lemma cos_arg_i_mult_zero_pos:
```
```   559    "0 < y ==> cos (arg(Complex 0 y)) = 0"
```
```   560 apply (simp add: arg_def abs_if)
```
```   561 apply (rule_tac a = "pi/2" in someI2, auto)
```
```   562 apply (rule order_less_trans [of _ 0], auto)
```
```   563 done
```
```   564
```
```   565 lemma cos_arg_i_mult_zero_neg:
```
```   566    "y < 0 ==> cos (arg(Complex 0 y)) = 0"
```
```   567 apply (simp add: arg_def abs_if)
```
```   568 apply (rule_tac a = "- pi/2" in someI2, auto)
```
```   569 apply (rule order_trans [of _ 0], auto)
```
```   570 done
```
```   571
```
```   572 lemma cos_arg_i_mult_zero [simp]:
```
```   573      "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
```
```   574 by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
```
```   575
```
```   576
```
```   577 subsection{*Finally! Polar Form for Complex Numbers*}
```
```   578
```
```   579 text {* An abbreviation for @{text "cos a + i sin a"}. *}
```
```   580
```
```   581 definition cis :: "real \<Rightarrow> complex" where
```
```   582   "cis a = Complex (cos a) (sin a)"
```
```   583
```
```   584 text {* An abbreviation for @{text "r(cos a + i sin a)"}. *}
```
```   585
```
```   586 definition rcis :: "[real, real] \<Rightarrow> complex" where
```
```   587   "rcis r a = complex_of_real r * cis a"
```
```   588
```
```   589 abbreviation expi :: "complex \<Rightarrow> complex"
```
```   590   where "expi \<equiv> exp"
```
```   591
```
```   592 lemma cis_conv_exp: "cis b = exp (Complex 0 b)"
```
```   593 proof (rule complex_eqI)
```
```   594   { fix n have "Complex 0 b ^ n =
```
```   595     real (fact n) *\<^sub>R Complex (cos_coeff n * b ^ n) (sin_coeff n * b ^ n)"
```
```   596       apply (induct n)
```
```   597       apply (simp add: cos_coeff_def sin_coeff_def)
```
```   598       apply (simp add: sin_coeff_Suc cos_coeff_Suc del: mult_Suc)
```
```   599       done } note * = this
```
```   600   show "Re (cis b) = Re (exp (Complex 0 b))"
```
```   601     unfolding exp_def cis_def cos_def
```
```   602     by (subst bounded_linear.suminf[OF bounded_linear_Re summable_exp_generic],
```
```   603       simp add: * mult_assoc [symmetric])
```
```   604   show "Im (cis b) = Im (exp (Complex 0 b))"
```
```   605     unfolding exp_def cis_def sin_def
```
```   606     by (subst bounded_linear.suminf[OF bounded_linear_Im summable_exp_generic],
```
```   607       simp add: * mult_assoc [symmetric])
```
```   608 qed
```
```   609
```
```   610 lemma expi_def: "expi z = complex_of_real (exp (Re z)) * cis (Im z)"
```
```   611   unfolding cis_conv_exp exp_of_real [symmetric] mult_exp_exp by simp
```
```   612
```
```   613 lemma complex_split_polar:
```
```   614      "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
```
```   615 apply (induct z)
```
```   616 apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
```
```   617 done
```
```   618
```
```   619 lemma rcis_Ex: "\<exists>r a. z = rcis r a"
```
```   620 apply (induct z)
```
```   621 apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
```
```   622 done
```
```   623
```
```   624 lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
```
```   625   by (simp add: rcis_def cis_def)
```
```   626
```
```   627 lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
```
```   628   by (simp add: rcis_def cis_def)
```
```   629
```
```   630 lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
```
```   631 proof -
```
```   632   have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
```
```   633     by (simp only: power_mult_distrib right_distrib)
```
```   634   thus ?thesis by simp
```
```   635 qed
```
```   636
```
```   637 lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
```
```   638   by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
```
```   639
```
```   640 lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
```
```   641   by (simp add: cmod_def power2_eq_square)
```
```   642
```
```   643 lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
```
```   644   by simp
```
```   645
```
```   646 lemma cis_rcis_eq: "cis a = rcis 1 a"
```
```   647   by (simp add: rcis_def)
```
```   648
```
```   649 lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
```
```   650   by (simp add: rcis_def cis_def cos_add sin_add right_distrib
```
```   651     right_diff_distrib complex_of_real_def)
```
```   652
```
```   653 lemma cis_mult: "cis a * cis b = cis (a + b)"
```
```   654   by (simp add: cis_rcis_eq rcis_mult)
```
```   655
```
```   656 lemma cis_zero [simp]: "cis 0 = 1"
```
```   657   by (simp add: cis_def complex_one_def)
```
```   658
```
```   659 lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
```
```   660   by (simp add: rcis_def)
```
```   661
```
```   662 lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
```
```   663   by (simp add: rcis_def)
```
```   664
```
```   665 lemma complex_of_real_minus_one:
```
```   666    "complex_of_real (-(1::real)) = -(1::complex)"
```
```   667   by (simp add: complex_of_real_def complex_one_def)
```
```   668
```
```   669 lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
```
```   670   by (simp add: mult_assoc [symmetric])
```
```   671
```
```   672
```
```   673 lemma cis_real_of_nat_Suc_mult:
```
```   674    "cis (real (Suc n) * a) = cis a * cis (real n * a)"
```
```   675   by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
```
```   676
```
```   677 lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
```
```   678 apply (induct_tac "n")
```
```   679 apply (auto simp add: cis_real_of_nat_Suc_mult)
```
```   680 done
```
```   681
```
```   682 lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
```
```   683   by (simp add: rcis_def power_mult_distrib DeMoivre)
```
```   684
```
```   685 lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
```
```   686   by (simp add: cis_def complex_inverse_complex_split diff_minus)
```
```   687
```
```   688 lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
```
```   689   by (simp add: divide_inverse rcis_def)
```
```   690
```
```   691 lemma cis_divide: "cis a / cis b = cis (a - b)"
```
```   692   by (simp add: complex_divide_def cis_mult diff_minus)
```
```   693
```
```   694 lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
```
```   695 apply (simp add: complex_divide_def)
```
```   696 apply (case_tac "r2=0", simp)
```
```   697 apply (simp add: rcis_inverse rcis_mult diff_minus)
```
```   698 done
```
```   699
```
```   700 lemma Re_cis [simp]: "Re(cis a) = cos a"
```
```   701   by (simp add: cis_def)
```
```   702
```
```   703 lemma Im_cis [simp]: "Im(cis a) = sin a"
```
```   704   by (simp add: cis_def)
```
```   705
```
```   706 lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
```
```   707   by (auto simp add: DeMoivre)
```
```   708
```
```   709 lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
```
```   710   by (auto simp add: DeMoivre)
```
```   711
```
```   712 lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
```
```   713 apply (insert rcis_Ex [of z])
```
```   714 apply (auto simp add: expi_def rcis_def mult_assoc [symmetric])
```
```   715 apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
```
```   716 done
```
```   717
```
```   718 lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
```
```   719   by (simp add: expi_def cis_def)
```
```   720
```
```   721 text {* Legacy theorem names *}
```
```   722
```
```   723 lemmas expand_complex_eq = complex_eq_iff
```
```   724 lemmas complex_Re_Im_cancel_iff = complex_eq_iff
```
```   725 lemmas complex_equality = complex_eqI
```
```   726
```
```   727 end
```