paulson@13957: (* Title: Complex.thy paulson@13957: Author: Jacques D. Fleuriot paulson@13957: Copyright: 2001 University of Edinburgh paulson@14387: Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4 paulson@13957: *) paulson@13957: paulson@14377: header {* Complex Numbers: Rectangular and Polar Representations *} paulson@14373: nipkow@15131: theory Complex haftmann@28952: imports Transcendental nipkow@15131: begin paulson@13957: paulson@14373: datatype complex = Complex real real paulson@13957: haftmann@25712: primrec haftmann@25712: Re :: "complex \ real" haftmann@25712: where haftmann@25712: Re: "Re (Complex x y) = x" paulson@14373: haftmann@25712: primrec haftmann@25712: Im :: "complex \ real" haftmann@25712: where haftmann@25712: Im: "Im (Complex x y) = y" paulson@14373: paulson@14373: lemma complex_surj [simp]: "Complex (Re z) (Im z) = z" paulson@14373: by (induct z) simp paulson@13957: huffman@23125: lemma complex_equality [intro?]: "\Re x = Re y; Im x = Im y\ \ x = y" haftmann@25712: by (induct x, induct y) simp huffman@23125: haftmann@25599: lemma expand_complex_eq: "x = y \ Re x = Re y \ Im x = Im y" haftmann@25712: by (induct x, induct y) simp huffman@23125: huffman@23125: lemmas complex_Re_Im_cancel_iff = expand_complex_eq huffman@23125: huffman@23125: huffman@23125: subsection {* Addition and Subtraction *} huffman@23125: haftmann@25599: instantiation complex :: ab_group_add haftmann@25571: begin haftmann@25571: haftmann@25571: definition haftmann@25571: complex_zero_def: "0 = Complex 0 0" haftmann@25571: haftmann@25571: definition haftmann@25571: complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)" huffman@23124: haftmann@25571: definition haftmann@25571: complex_minus_def: "- x = Complex (- Re x) (- Im x)" paulson@14323: haftmann@25571: definition haftmann@25571: complex_diff_def: "x - (y\complex) = x + - y" haftmann@25571: haftmann@25599: lemma Complex_eq_0 [simp]: "Complex a b = 0 \ a = 0 \ b = 0" haftmann@25599: by (simp add: complex_zero_def) paulson@14323: paulson@14374: lemma complex_Re_zero [simp]: "Re 0 = 0" haftmann@25599: by (simp add: complex_zero_def) paulson@14374: paulson@14374: lemma complex_Im_zero [simp]: "Im 0 = 0" haftmann@25599: by (simp add: complex_zero_def) haftmann@25599: haftmann@25712: lemma complex_add [simp]: haftmann@25712: "Complex a b + Complex c d = Complex (a + c) (b + d)" haftmann@25712: by (simp add: complex_add_def) haftmann@25712: haftmann@25599: lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y" haftmann@25599: by (simp add: complex_add_def) haftmann@25599: haftmann@25599: lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y" haftmann@25599: by (simp add: complex_add_def) paulson@14323: haftmann@25712: lemma complex_minus [simp]: haftmann@25712: "- (Complex a b) = Complex (- a) (- b)" haftmann@25599: by (simp add: complex_minus_def) huffman@23125: huffman@23125: lemma complex_Re_minus [simp]: "Re (- x) = - Re x" haftmann@25599: by (simp add: complex_minus_def) huffman@23125: huffman@23125: lemma complex_Im_minus [simp]: "Im (- x) = - Im x" haftmann@25599: by (simp add: complex_minus_def) huffman@23125: huffman@23275: lemma complex_diff [simp]: huffman@23125: "Complex a b - Complex c d = Complex (a - c) (b - d)" haftmann@25599: by (simp add: complex_diff_def) huffman@23125: huffman@23125: lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y" haftmann@25599: by (simp add: complex_diff_def) huffman@23125: huffman@23125: lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y" haftmann@25599: by (simp add: complex_diff_def) huffman@23125: haftmann@25712: instance haftmann@25712: by intro_classes (simp_all add: complex_add_def complex_diff_def) haftmann@25712: haftmann@25712: end haftmann@25712: haftmann@25712: huffman@23125: huffman@23125: subsection {* Multiplication and Division *} huffman@23125: haftmann@25712: instantiation complex :: "{field, division_by_zero}" haftmann@25571: begin haftmann@25571: haftmann@25571: definition haftmann@25571: complex_one_def: "1 = Complex 1 0" haftmann@25571: haftmann@25571: definition haftmann@25571: complex_mult_def: "x * y = haftmann@25571: Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)" huffman@23125: haftmann@25571: definition haftmann@25571: complex_inverse_def: "inverse x = haftmann@25571: Complex (Re x / ((Re x)\ + (Im x)\)) (- Im x / ((Re x)\ + (Im x)\))" huffman@23125: haftmann@25571: definition haftmann@25571: complex_divide_def: "x / (y\complex) = x * inverse y" haftmann@25571: huffman@23125: lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \ b = 0)" haftmann@25712: by (simp add: complex_one_def) huffman@22861: paulson@14374: lemma complex_Re_one [simp]: "Re 1 = 1" haftmann@25712: by (simp add: complex_one_def) paulson@14323: paulson@14374: lemma complex_Im_one [simp]: "Im 1 = 0" haftmann@25712: by (simp add: complex_one_def) paulson@14323: huffman@23125: lemma complex_mult [simp]: huffman@23125: "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)" haftmann@25712: by (simp add: complex_mult_def) paulson@14323: huffman@23125: lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y" haftmann@25712: by (simp add: complex_mult_def) paulson@14323: huffman@23125: lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y" haftmann@25712: by (simp add: complex_mult_def) paulson@14323: paulson@14377: lemma complex_inverse [simp]: huffman@23125: "inverse (Complex a b) = Complex (a / (a\ + b\)) (- b / (a\ + b\))" haftmann@25712: by (simp add: complex_inverse_def) paulson@14335: huffman@23125: lemma complex_Re_inverse: huffman@23125: "Re (inverse x) = Re x / ((Re x)\ + (Im x)\)" haftmann@25712: by (simp add: complex_inverse_def) paulson@14323: huffman@23125: lemma complex_Im_inverse: huffman@23125: "Im (inverse x) = - Im x / ((Re x)\ + (Im x)\)" haftmann@25712: by (simp add: complex_inverse_def) paulson@14335: haftmann@25712: instance haftmann@25712: by intro_classes (simp_all add: complex_mult_def haftmann@25712: right_distrib left_distrib right_diff_distrib left_diff_distrib haftmann@25712: complex_inverse_def complex_divide_def haftmann@25712: power2_eq_square add_divide_distrib [symmetric] haftmann@25712: expand_complex_eq) paulson@14335: haftmann@25712: end huffman@23125: huffman@23125: huffman@23125: subsection {* Numerals and Arithmetic *} huffman@23125: haftmann@25571: instantiation complex :: number_ring haftmann@25571: begin huffman@23125: haftmann@25712: definition number_of_complex where haftmann@25571: complex_number_of_def: "number_of w = (of_int w \ complex)" haftmann@25571: haftmann@25571: instance haftmann@25712: by intro_classes (simp only: complex_number_of_def) haftmann@25571: haftmann@25571: end huffman@23125: huffman@23125: lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n" huffman@23125: by (induct n) simp_all huffman@20556: huffman@23125: lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0" huffman@23125: by (induct n) simp_all huffman@23125: huffman@23125: lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z" huffman@23125: by (cases z rule: int_diff_cases) simp huffman@23125: huffman@23125: lemma complex_Im_of_int [simp]: "Im (of_int z) = 0" huffman@23125: by (cases z rule: int_diff_cases) simp huffman@23125: huffman@23125: lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v" haftmann@25502: unfolding number_of_eq by (rule complex_Re_of_int) huffman@20556: huffman@23125: lemma complex_Im_number_of [simp]: "Im (number_of v) = 0" haftmann@25502: unfolding number_of_eq by (rule complex_Im_of_int) huffman@23125: huffman@23125: lemma Complex_eq_number_of [simp]: huffman@23125: "(Complex a b = number_of w) = (a = number_of w \ b = 0)" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: huffman@23125: subsection {* Scalar Multiplication *} huffman@20556: haftmann@25712: instantiation complex :: real_field haftmann@25571: begin haftmann@25571: haftmann@25571: definition haftmann@25571: complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)" haftmann@25571: huffman@23125: lemma complex_scaleR [simp]: huffman@23125: "scaleR r (Complex a b) = Complex (r * a) (r * b)" haftmann@25712: unfolding complex_scaleR_def by simp huffman@23125: huffman@23125: lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x" haftmann@25712: unfolding complex_scaleR_def by simp huffman@23125: huffman@23125: lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x" haftmann@25712: unfolding complex_scaleR_def by simp huffman@22972: haftmann@25712: instance huffman@20556: proof huffman@23125: fix a b :: real and x y :: complex huffman@23125: show "scaleR a (x + y) = scaleR a x + scaleR a y" huffman@23125: by (simp add: expand_complex_eq right_distrib) huffman@23125: show "scaleR (a + b) x = scaleR a x + scaleR b x" huffman@23125: by (simp add: expand_complex_eq left_distrib) huffman@23125: show "scaleR a (scaleR b x) = scaleR (a * b) x" huffman@23125: by (simp add: expand_complex_eq mult_assoc) huffman@23125: show "scaleR 1 x = x" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: show "scaleR a x * y = scaleR a (x * y)" nipkow@29667: by (simp add: expand_complex_eq algebra_simps) huffman@23125: show "x * scaleR a y = scaleR a (x * y)" nipkow@29667: by (simp add: expand_complex_eq algebra_simps) huffman@20556: qed huffman@20556: haftmann@25712: end haftmann@25712: huffman@20556: huffman@23125: subsection{* Properties of Embedding from Reals *} paulson@14323: huffman@20557: abbreviation huffman@23125: complex_of_real :: "real \ complex" where huffman@23125: "complex_of_real \ of_real" huffman@20557: huffman@20557: lemma complex_of_real_def: "complex_of_real r = Complex r 0" huffman@20557: by (simp add: of_real_def complex_scaleR_def) huffman@20557: huffman@20557: lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z" huffman@20557: by (simp add: complex_of_real_def) huffman@20557: huffman@20557: lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0" huffman@20557: by (simp add: complex_of_real_def) huffman@20557: paulson@14377: lemma Complex_add_complex_of_real [simp]: paulson@14377: "Complex x y + complex_of_real r = Complex (x+r) y" paulson@14377: by (simp add: complex_of_real_def) paulson@14377: paulson@14377: lemma complex_of_real_add_Complex [simp]: paulson@14377: "complex_of_real r + Complex x y = Complex (r+x) y" huffman@23125: by (simp add: complex_of_real_def) paulson@14377: paulson@14377: lemma Complex_mult_complex_of_real: paulson@14377: "Complex x y * complex_of_real r = Complex (x*r) (y*r)" paulson@14377: by (simp add: complex_of_real_def) paulson@14377: paulson@14377: lemma complex_of_real_mult_Complex: paulson@14377: "complex_of_real r * Complex x y = Complex (r*x) (r*y)" huffman@23125: by (simp add: complex_of_real_def) huffman@20557: paulson@14377: huffman@23125: subsection {* Vector Norm *} paulson@14323: haftmann@25712: instantiation complex :: real_normed_field haftmann@25571: begin haftmann@25571: huffman@31413: definition complex_norm_def: huffman@31413: "norm z = sqrt ((Re z)\ + (Im z)\)" haftmann@25571: huffman@20557: abbreviation huffman@22861: cmod :: "complex \ real" where haftmann@25712: "cmod \ norm" haftmann@25571: huffman@31413: definition complex_sgn_def: huffman@31413: "sgn x = x /\<^sub>R cmod x" haftmann@25571: huffman@31413: definition dist_complex_def: huffman@31413: "dist x y = cmod (x - y)" huffman@31413: huffman@31417: definition topo_complex_def: huffman@31417: "topo = {S::complex set. \x\S. \e>0. \y. dist y x < e \ y \ S}" huffman@31292: huffman@20557: lemmas cmod_def = complex_norm_def huffman@20557: huffman@23125: lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\ + y\)" haftmann@25712: by (simp add: complex_norm_def) huffman@22852: huffman@31413: instance proof huffman@31417: fix r :: real and x y :: complex huffman@23125: show "0 \ norm x" huffman@22861: by (induct x) simp huffman@23125: show "(norm x = 0) = (x = 0)" huffman@22861: by (induct x) simp huffman@23125: show "norm (x + y) \ norm x + norm y" huffman@23125: by (induct x, induct y) huffman@23125: (simp add: real_sqrt_sum_squares_triangle_ineq) huffman@23125: show "norm (scaleR r x) = \r\ * norm x" huffman@23125: by (induct x) huffman@23125: (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult) huffman@23125: show "norm (x * y) = norm x * norm y" huffman@23125: by (induct x, induct y) nipkow@29667: (simp add: real_sqrt_mult [symmetric] power2_eq_square algebra_simps) huffman@31292: show "sgn x = x /\<^sub>R cmod x" huffman@31292: by (rule complex_sgn_def) huffman@31292: show "dist x y = cmod (x - y)" huffman@31292: by (rule dist_complex_def) huffman@31417: show "topo = {S::complex set. \x\S. \e>0. \y. dist y x < e \ y \ S}" huffman@31417: by (rule topo_complex_def) huffman@24520: qed huffman@20557: haftmann@25712: end haftmann@25712: huffman@22861: lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1" huffman@22861: by simp paulson@14323: huffman@22861: lemma cmod_complex_polar [simp]: huffman@22861: "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r" huffman@23125: by (simp add: norm_mult) huffman@22861: huffman@22861: lemma complex_Re_le_cmod: "Re x \ cmod x" huffman@22861: unfolding complex_norm_def huffman@22861: by (rule real_sqrt_sum_squares_ge1) huffman@22861: huffman@22861: lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \ cmod x" huffman@22861: by (rule order_trans [OF _ norm_ge_zero], simp) huffman@22861: huffman@22861: lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \ cmod a" huffman@22861: by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp) paulson@14323: huffman@22861: lemmas real_sum_squared_expand = power2_sum [where 'a=real] paulson@14323: chaieb@26117: lemma abs_Re_le_cmod: "\Re x\ \ cmod x" chaieb@26117: by (cases x) simp chaieb@26117: chaieb@26117: lemma abs_Im_le_cmod: "\Im x\ \ cmod x" chaieb@26117: by (cases x) simp paulson@14354: huffman@23123: subsection {* Completeness of the Complexes *} huffman@23123: wenzelm@30729: interpretation Re: bounded_linear "Re" huffman@23123: apply (unfold_locales, simp, simp) huffman@23123: apply (rule_tac x=1 in exI) huffman@23123: apply (simp add: complex_norm_def) huffman@23123: done huffman@23123: wenzelm@30729: interpretation Im: bounded_linear "Im" huffman@23123: apply (unfold_locales, simp, simp) huffman@23123: apply (rule_tac x=1 in exI) huffman@23123: apply (simp add: complex_norm_def) huffman@23123: done huffman@23123: huffman@23123: lemma LIMSEQ_Complex: huffman@23123: "\X ----> a; Y ----> b\ \ (\n. Complex (X n) (Y n)) ----> Complex a b" huffman@23123: apply (rule LIMSEQ_I) huffman@23123: apply (subgoal_tac "0 < r / sqrt 2") huffman@23123: apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe) huffman@23123: apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe) huffman@23123: apply (rename_tac M N, rule_tac x="max M N" in exI, safe) huffman@23123: apply (simp add: real_sqrt_sum_squares_less) huffman@23123: apply (simp add: divide_pos_pos) huffman@23123: done huffman@23123: huffman@23123: instance complex :: banach huffman@23123: proof huffman@23123: fix X :: "nat \ complex" huffman@23123: assume X: "Cauchy X" huffman@23123: from Re.Cauchy [OF X] have 1: "(\n. Re (X n)) ----> lim (\n. Re (X n))" huffman@23123: by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff) huffman@23123: from Im.Cauchy [OF X] have 2: "(\n. Im (X n)) ----> lim (\n. Im (X n))" huffman@23123: by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff) huffman@23123: have "X ----> Complex (lim (\n. Re (X n))) (lim (\n. Im (X n)))" huffman@23123: using LIMSEQ_Complex [OF 1 2] by simp huffman@23123: thus "convergent X" huffman@23123: by (rule convergentI) huffman@23123: qed huffman@23123: huffman@23123: huffman@23125: subsection {* The Complex Number @{term "\"} *} huffman@23125: huffman@23125: definition huffman@23125: "ii" :: complex ("\") where huffman@23125: i_def: "ii \ Complex 0 1" huffman@23125: huffman@23125: lemma complex_Re_i [simp]: "Re ii = 0" huffman@23125: by (simp add: i_def) paulson@14354: huffman@23125: lemma complex_Im_i [simp]: "Im ii = 1" huffman@23125: by (simp add: i_def) huffman@23125: huffman@23125: lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \ y = 1)" huffman@23125: by (simp add: i_def) huffman@23125: huffman@23125: lemma complex_i_not_zero [simp]: "ii \ 0" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_i_not_one [simp]: "ii \ 1" huffman@23125: by (simp add: expand_complex_eq) huffman@23124: huffman@23125: lemma complex_i_not_number_of [simp]: "ii \ number_of w" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r" huffman@23125: by (simp add: i_def complex_of_real_def) huffman@23125: huffman@23125: lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r" huffman@23125: by (simp add: i_def complex_of_real_def) huffman@23125: huffman@23125: lemma i_squared [simp]: "ii * ii = -1" huffman@23125: by (simp add: i_def) huffman@23125: huffman@23125: lemma power2_i [simp]: "ii\ = -1" huffman@23125: by (simp add: power2_eq_square) huffman@23125: huffman@23125: lemma inverse_i [simp]: "inverse ii = - ii" huffman@23125: by (rule inverse_unique, simp) paulson@14354: paulson@14354: huffman@23125: subsection {* Complex Conjugation *} huffman@23125: huffman@23125: definition huffman@23125: cnj :: "complex \ complex" where huffman@23125: "cnj z = Complex (Re z) (- Im z)" huffman@23125: huffman@23125: lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)" huffman@23125: by (simp add: cnj_def) huffman@23125: huffman@23125: lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x" huffman@23125: by (simp add: cnj_def) huffman@23125: huffman@23125: lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x" huffman@23125: by (simp add: cnj_def) huffman@23125: huffman@23125: lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z" huffman@23125: by (simp add: cnj_def) huffman@23125: huffman@23125: lemma complex_cnj_zero [simp]: "cnj 0 = 0" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_minus: "cnj (- x) = - cnj x" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_one [simp]: "cnj 1 = 1" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)" huffman@23125: by (simp add: complex_inverse_def) paulson@14323: huffman@23125: lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y" huffman@23125: by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse) huffman@23125: huffman@23125: lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n" huffman@23125: by (induct n, simp_all add: complex_cnj_mult) huffman@23125: huffman@23125: lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z" huffman@23125: by (simp add: complex_norm_def) paulson@14323: huffman@23125: lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_cnj_i [simp]: "cnj ii = - ii" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)" huffman@23125: by (simp add: expand_complex_eq) huffman@23125: huffman@23125: lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii" huffman@23125: by (simp add: expand_complex_eq) paulson@14354: huffman@23125: lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\ + (Im z)\)" huffman@23125: by (simp add: expand_complex_eq power2_eq_square) huffman@23125: huffman@23125: lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\" huffman@23125: by (simp add: norm_mult power2_eq_square) huffman@23125: wenzelm@30729: interpretation cnj: bounded_linear "cnj" huffman@23125: apply (unfold_locales) huffman@23125: apply (rule complex_cnj_add) huffman@23125: apply (rule complex_cnj_scaleR) huffman@23125: apply (rule_tac x=1 in exI, simp) huffman@23125: done paulson@14354: paulson@14354: huffman@22972: subsection{*The Functions @{term sgn} and @{term arg}*} paulson@14323: huffman@22972: text {*------------ Argand -------------*} huffman@20557: wenzelm@21404: definition wenzelm@21404: arg :: "complex => real" where huffman@20557: "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \ pi)" huffman@20557: paulson@14374: lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)" nipkow@24506: by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute) paulson@14323: paulson@14323: lemma i_mult_eq: "ii * ii = complex_of_real (-1)" huffman@20725: by (simp add: i_def complex_of_real_def) paulson@14323: paulson@14374: lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)" huffman@20725: by (simp add: i_def complex_one_def) paulson@14323: paulson@14374: lemma complex_eq_cancel_iff2 [simp]: paulson@14377: "(Complex x y = complex_of_real xa) = (x = xa & y = 0)" paulson@14377: by (simp add: complex_of_real_def) paulson@14323: paulson@14374: lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z" nipkow@24506: by (simp add: complex_sgn_def divide_inverse) paulson@14323: paulson@14374: lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z" nipkow@24506: by (simp add: complex_sgn_def divide_inverse) paulson@14323: paulson@14323: lemma complex_inverse_complex_split: paulson@14323: "inverse(complex_of_real x + ii * complex_of_real y) = paulson@14323: complex_of_real(x/(x ^ 2 + y ^ 2)) - paulson@14323: ii * complex_of_real(y/(x ^ 2 + y ^ 2))" huffman@20725: by (simp add: complex_of_real_def i_def diff_minus divide_inverse) paulson@14323: paulson@14323: (*----------------------------------------------------------------------------*) paulson@14323: (* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *) paulson@14323: (* many of the theorems are not used - so should they be kept? *) paulson@14323: (*----------------------------------------------------------------------------*) paulson@14323: paulson@14354: lemma cos_arg_i_mult_zero_pos: paulson@14377: "0 < y ==> cos (arg(Complex 0 y)) = 0" paulson@14373: apply (simp add: arg_def abs_if) paulson@14334: apply (rule_tac a = "pi/2" in someI2, auto) paulson@14334: apply (rule order_less_trans [of _ 0], auto) paulson@14323: done paulson@14323: paulson@14354: lemma cos_arg_i_mult_zero_neg: paulson@14377: "y < 0 ==> cos (arg(Complex 0 y)) = 0" paulson@14373: apply (simp add: arg_def abs_if) paulson@14334: apply (rule_tac a = "- pi/2" in someI2, auto) paulson@14334: apply (rule order_trans [of _ 0], auto) paulson@14323: done paulson@14323: paulson@14374: lemma cos_arg_i_mult_zero [simp]: paulson@14377: "y \ 0 ==> cos (arg(Complex 0 y)) = 0" paulson@14377: by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg) paulson@14323: paulson@14323: paulson@14323: subsection{*Finally! Polar Form for Complex Numbers*} paulson@14323: huffman@20557: definition huffman@20557: huffman@20557: (* abbreviation for (cos a + i sin a) *) wenzelm@21404: cis :: "real => complex" where huffman@20557: "cis a = Complex (cos a) (sin a)" huffman@20557: wenzelm@21404: definition huffman@20557: (* abbreviation for r*(cos a + i sin a) *) wenzelm@21404: rcis :: "[real, real] => complex" where huffman@20557: "rcis r a = complex_of_real r * cis a" huffman@20557: wenzelm@21404: definition huffman@20557: (* e ^ (x + iy) *) wenzelm@21404: expi :: "complex => complex" where huffman@20557: "expi z = complex_of_real(exp (Re z)) * cis (Im z)" huffman@20557: paulson@14374: lemma complex_split_polar: paulson@14377: "\r a. z = complex_of_real r * (Complex (cos a) (sin a))" huffman@20725: apply (induct z) paulson@14377: apply (auto simp add: polar_Ex complex_of_real_mult_Complex) paulson@14323: done paulson@14323: paulson@14354: lemma rcis_Ex: "\r a. z = rcis r a" huffman@20725: apply (induct z) paulson@14377: apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex) paulson@14323: done paulson@14323: paulson@14374: lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a" paulson@14373: by (simp add: rcis_def cis_def) paulson@14323: paulson@14348: lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a" paulson@14373: by (simp add: rcis_def cis_def) paulson@14323: paulson@14377: lemma sin_cos_squared_add2_mult: "(r * cos a)\ + (r * sin a)\ = r\" paulson@14377: proof - paulson@14377: have "(r * cos a)\ + (r * sin a)\ = r\ * ((cos a)\ + (sin a)\)" huffman@20725: by (simp only: power_mult_distrib right_distrib) paulson@14377: thus ?thesis by simp paulson@14377: qed paulson@14323: paulson@14374: lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r" paulson@14377: by (simp add: rcis_def cis_def sin_cos_squared_add2_mult) paulson@14323: huffman@23125: lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))" huffman@23125: by (simp add: cmod_def power2_eq_square) huffman@23125: paulson@14374: lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0" huffman@23125: by simp paulson@14323: paulson@14323: paulson@14323: (*---------------------------------------------------------------------------*) paulson@14323: (* (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b) *) paulson@14323: (*---------------------------------------------------------------------------*) paulson@14323: paulson@14323: lemma cis_rcis_eq: "cis a = rcis 1 a" paulson@14373: by (simp add: rcis_def) paulson@14323: paulson@14374: lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)" paulson@15013: by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib paulson@15013: complex_of_real_def) paulson@14323: paulson@14323: lemma cis_mult: "cis a * cis b = cis (a + b)" paulson@14373: by (simp add: cis_rcis_eq rcis_mult) paulson@14323: paulson@14374: lemma cis_zero [simp]: "cis 0 = 1" paulson@14377: by (simp add: cis_def complex_one_def) paulson@14323: paulson@14374: lemma rcis_zero_mod [simp]: "rcis 0 a = 0" paulson@14373: by (simp add: rcis_def) paulson@14323: paulson@14374: lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r" paulson@14373: by (simp add: rcis_def) paulson@14323: paulson@14323: lemma complex_of_real_minus_one: paulson@14323: "complex_of_real (-(1::real)) = -(1::complex)" huffman@20725: by (simp add: complex_of_real_def complex_one_def) paulson@14323: paulson@14374: lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x" huffman@23125: by (simp add: mult_assoc [symmetric]) paulson@14323: paulson@14323: paulson@14323: lemma cis_real_of_nat_Suc_mult: paulson@14323: "cis (real (Suc n) * a) = cis a * cis (real n * a)" paulson@14377: by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib) paulson@14323: paulson@14323: lemma DeMoivre: "(cis a) ^ n = cis (real n * a)" paulson@14323: apply (induct_tac "n") paulson@14323: apply (auto simp add: cis_real_of_nat_Suc_mult) paulson@14323: done paulson@14323: paulson@14374: lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)" huffman@22890: by (simp add: rcis_def power_mult_distrib DeMoivre) paulson@14323: paulson@14374: lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)" huffman@20725: by (simp add: cis_def complex_inverse_complex_split diff_minus) paulson@14323: paulson@14323: lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)" huffman@22884: by (simp add: divide_inverse rcis_def) paulson@14323: paulson@14323: lemma cis_divide: "cis a / cis b = cis (a - b)" paulson@14373: by (simp add: complex_divide_def cis_mult real_diff_def) paulson@14323: paulson@14354: lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)" paulson@14373: apply (simp add: complex_divide_def) paulson@14373: apply (case_tac "r2=0", simp) paulson@14373: apply (simp add: rcis_inverse rcis_mult real_diff_def) paulson@14323: done paulson@14323: paulson@14374: lemma Re_cis [simp]: "Re(cis a) = cos a" paulson@14373: by (simp add: cis_def) paulson@14323: paulson@14374: lemma Im_cis [simp]: "Im(cis a) = sin a" paulson@14373: by (simp add: cis_def) paulson@14323: paulson@14323: lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)" paulson@14334: by (auto simp add: DeMoivre) paulson@14323: paulson@14323: lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)" paulson@14334: by (auto simp add: DeMoivre) paulson@14323: paulson@14323: lemma expi_add: "expi(a + b) = expi(a) * expi(b)" huffman@20725: by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac) paulson@14323: paulson@14374: lemma expi_zero [simp]: "expi (0::complex) = 1" paulson@14373: by (simp add: expi_def) paulson@14323: paulson@14374: lemma complex_expi_Ex: "\a r. z = complex_of_real r * expi a" paulson@14373: apply (insert rcis_Ex [of z]) huffman@23125: apply (auto simp add: expi_def rcis_def mult_assoc [symmetric]) paulson@14334: apply (rule_tac x = "ii * complex_of_real a" in exI, auto) paulson@14323: done paulson@14323: paulson@14387: lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1" huffman@23125: by (simp add: expi_def cis_def) paulson@14387: paulson@13957: end