
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: 
paulson@14323: theory Complex = HLog:
paulson@13957: 
paulson@14373: datatype complex = Complex real real
paulson@13957: 
paulson@14323: instance complex :: zero ..
paulson@14323: instance complex :: one ..
paulson@14323: instance complex :: plus ..
paulson@14323: instance complex :: times ..
paulson@14323: instance complex :: minus ..
paulson@14323: instance complex :: inverse ..
paulson@14323: instance complex :: power ..
paulson@13957: 
paulson@13957: consts
paulson@14373:   "ii"    :: complex    ("\<i>")
paulson@14373: 
paulson@14373: consts Re :: "complex => real"
paulson@14373: primrec "Re (Complex x y) = x"
paulson@14373: 
paulson@14373: consts Im :: "complex => real"
paulson@14373: primrec "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: 
paulson@13957: constdefs
paulson@13957: 
paulson@13957:   (*----------- modulus ------------*)
paulson@13957: 
paulson@14323:   cmod :: "complex => real"
paulson@14323:   "cmod z == sqrt(Re(z) ^ 2 + Im(z) ^ 2)"
paulson@13957: 
paulson@14323:   (*----- injection from reals -----*)
paulson@14323: 
paulson@14323:   complex_of_real :: "real => complex"
paulson@14373:   "complex_of_real r == Complex r 0"
paulson@14323: 
paulson@13957:   (*------- complex conjugate ------*)
paulson@13957: 
paulson@14323:   cnj :: "complex => complex"
paulson@14373:   "cnj z == Complex (Re z) (-Im z)"
paulson@13957: 
paulson@14323:   (*------------ Argand -------------*)
paulson@13957: 
paulson@14323:   sgn :: "complex => complex"
paulson@13957:   "sgn z == z / complex_of_real(cmod z)"
paulson@13957: 
paulson@14323:   arg :: "complex => real"
paulson@14354:   "arg z == @a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi"
paulson@14323: 
paulson@13957: 
paulson@14323: defs (overloaded)
paulson@14323: 
paulson@14323:   complex_zero_def:
paulson@14373:   "0 == Complex 0 0"
paulson@13957: 
paulson@14323:   complex_one_def:
paulson@14373:   "1 == Complex 1 0"
paulson@14323: 
paulson@14373:   i_def: "ii == Complex 0 1"
paulson@14323: 
paulson@14373:   complex_minus_def: "- z == Complex (- Re z) (- Im z)"
paulson@14323: 
paulson@14323:   complex_inverse_def:
paulson@14373:    "inverse z ==
paulson@14373:     Complex (Re z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>)) (- Im z / ((Re z)\<twosuperior> + (Im z)\<twosuperior>))"
paulson@13957: 
paulson@14323:   complex_add_def:
paulson@14373:     "z + w == Complex (Re z + Re w) (Im z + Im w)"
paulson@13957: 
paulson@14323:   complex_diff_def:
paulson@14373:     "z - w == z + - (w::complex)"
paulson@13957: 
paulson@14374:   complex_mult_def:
paulson@14373:     "z * w == Complex (Re z * Re w - Im z * Im w) (Re z * Im w + Im z * Re w)"
paulson@13957: 
paulson@14373:   complex_divide_def: "w / (z::complex) == w * inverse z"
paulson@14323: 
paulson@13957: 
paulson@13957: constdefs
paulson@13957: 
paulson@13957:   (* abbreviation for (cos a + i sin a) *)
paulson@14323:   cis :: "real => complex"
paulson@14377:   "cis a == Complex (cos a) (sin a)"
paulson@13957: 
paulson@13957:   (* abbreviation for r*(cos a + i sin a) *)
paulson@14323:   rcis :: "[real, real] => complex"
paulson@13957:   "rcis r a == complex_of_real r * cis a"
paulson@13957: 
paulson@13957:   (* e ^ (x + iy) *)
paulson@14323:   expi :: "complex => complex"
paulson@13957:   "expi z == complex_of_real(exp (Re z)) * cis (Im z)"
paulson@14323: 
paulson@14323: 
paulson@14373: lemma complex_equality [intro?]: "Re z = Re w ==> Im z = Im w ==> z = w"
paulson@14373:   by (induct z, induct w) simp
paulson@14323: 
paulson@14374: lemma Re [simp]: "Re(Complex x y) = x"
paulson@14373: by simp
paulson@14323: 
paulson@14374: lemma Im [simp]: "Im(Complex x y) = y"
paulson@14373: by simp
paulson@14323: 
paulson@14323: lemma complex_Re_Im_cancel_iff: "(w=z) = (Re(w) = Re(z) & Im(w) = Im(z))"
paulson@14373: by (induct w, induct z, simp)
paulson@14323: 
paulson@14374: lemma complex_Re_zero [simp]: "Re 0 = 0"
paulson@14374: by (simp add: complex_zero_def)
paulson@14374: 
paulson@14374: lemma complex_Im_zero [simp]: "Im 0 = 0"
paulson@14373: by (simp add: complex_zero_def)
paulson@14323: 
paulson@14374: lemma complex_Re_one [simp]: "Re 1 = 1"
paulson@14374: by (simp add: complex_one_def)
paulson@14323: 
paulson@14374: lemma complex_Im_one [simp]: "Im 1 = 0"
paulson@14373: by (simp add: complex_one_def)
paulson@14323: 
paulson@14374: lemma complex_Re_i [simp]: "Re(ii) = 0"
paulson@14373: by (simp add: i_def)
paulson@14323: 
paulson@14374: lemma complex_Im_i [simp]: "Im(ii) = 1"
paulson@14373: by (simp add: i_def)
paulson@14323: 
paulson@14374: lemma Re_complex_of_real [simp]: "Re(complex_of_real z) = z"
paulson@14373: by (simp add: complex_of_real_def)
paulson@14323: 
paulson@14374: lemma Im_complex_of_real [simp]: "Im(complex_of_real z) = 0"
paulson@14373: by (simp add: complex_of_real_def)
paulson@14323: 
paulson@14323: 
paulson@14374: subsection{*Unary Minus*}
paulson@14323: 
paulson@14377: lemma complex_minus [simp]: "- (Complex x y) = Complex (-x) (-y)"
paulson@14373: by (simp add: complex_minus_def)
paulson@14323: 
paulson@14374: lemma complex_Re_minus [simp]: "Re (-z) = - Re z"
paulson@14373: by (simp add: complex_minus_def)
paulson@14323: 
paulson@14374: lemma complex_Im_minus [simp]: "Im (-z) = - Im z"
paulson@14374: by (simp add: complex_minus_def)
paulson@14323: 
paulson@14323: 
paulson@14323: subsection{*Addition*}
paulson@14323: 
paulson@14377: lemma complex_add [simp]:
paulson@14377:      "Complex x1 y1 + Complex x2 y2 = Complex (x1+x2) (y1+y2)"
paulson@14373: by (simp add: complex_add_def)
paulson@14323: 
paulson@14374: lemma complex_Re_add [simp]: "Re(x + y) = Re(x) + Re(y)"
paulson@14373: by (simp add: complex_add_def)
paulson@14323: 
paulson@14374: lemma complex_Im_add [simp]: "Im(x + y) = Im(x) + Im(y)"
paulson@14373: by (simp add: complex_add_def)
paulson@14323: 
paulson@14323: lemma complex_add_commute: "(u::complex) + v = v + u"
paulson@14373: by (simp add: complex_add_def add_commute)
paulson@14323: 
paulson@14323: lemma complex_add_assoc: "((u::complex) + v) + w = u + (v + w)"
paulson@14373: by (simp add: complex_add_def add_assoc)
paulson@14323: 
paulson@14323: lemma complex_add_zero_left: "(0::complex) + z = z"
paulson@14373: by (simp add: complex_add_def complex_zero_def)
paulson@14323: 
paulson@14323: lemma complex_add_zero_right: "z + (0::complex) = z"
paulson@14373: by (simp add: complex_add_def complex_zero_def)
paulson@14323: 
paulson@14373: lemma complex_add_minus_left: "-z + z = (0::complex)"
paulson@14373: by (simp add: complex_add_def complex_minus_def complex_zero_def)
paulson@14323: 
paulson@14323: lemma complex_diff:
paulson@14373:       "Complex x1 y1 - Complex x2 y2 = Complex (x1-x2) (y1-y2)"
paulson@14373: by (simp add: complex_add_def complex_minus_def complex_diff_def)
paulson@14323: 
paulson@14374: lemma complex_Re_diff [simp]: "Re(x - y) = Re(x) - Re(y)"
paulson@14374: by (simp add: complex_diff_def)
paulson@14374: 
paulson@14374: lemma complex_Im_diff [simp]: "Im(x - y) = Im(x) - Im(y)"
paulson@14374: by (simp add: complex_diff_def)
paulson@14374: 
paulson@14374: 
paulson@14323: subsection{*Multiplication*}
paulson@14323: 
paulson@14377: lemma complex_mult [simp]:
paulson@14373:      "Complex x1 y1 * Complex x2 y2 = Complex (x1*x2 - y1*y2) (x1*y2 + y1*x2)"
paulson@14373: by (simp add: complex_mult_def)
paulson@14323: 
paulson@14323: lemma complex_mult_commute: "(w::complex) * z = z * w"
paulson@14373: by (simp add: complex_mult_def mult_commute add_commute)
paulson@14323: 
paulson@14323: lemma complex_mult_assoc: "((u::complex) * v) * w = u * (v * w)"
paulson@14374: by (simp add: complex_mult_def mult_ac add_ac
paulson@14373:               right_diff_distrib right_distrib left_diff_distrib left_distrib)
paulson@14323: 
paulson@14323: lemma complex_mult_one_left: "(1::complex) * z = z"
paulson@14373: by (simp add: complex_mult_def complex_one_def)
paulson@14323: 
paulson@14323: lemma complex_mult_one_right: "z * (1::complex) = z"
paulson@14373: by (simp add: complex_mult_def complex_one_def)
paulson@14323: 
paulson@14323: 
paulson@14323: subsection{*Inverse*}
paulson@14323: 
paulson@14377: lemma complex_inverse [simp]:
paulson@14373:      "inverse (Complex x y) = Complex (x/(x ^ 2 + y ^ 2)) (-y/(x ^ 2 + y ^ 2))"
paulson@14373: by (simp add: complex_inverse_def)
paulson@14335: 
paulson@14354: lemma complex_mult_inv_left: "z \<noteq> (0::complex) ==> inverse(z) * z = 1"
paulson@14374: apply (induct z)
paulson@14374: apply (rename_tac x y)
paulson@14374: apply (auto simp add: complex_mult complex_inverse complex_one_def
paulson@14353:        complex_zero_def add_divide_distrib [symmetric] power2_eq_square mult_ac)
paulson@14334: apply (drule_tac y = y in real_sum_squares_not_zero)
paulson@14334: apply (drule_tac [2] x = x in real_sum_squares_not_zero2, auto)
paulson@14323: done
paulson@14323: 
paulson@14335: 
paulson@14335: subsection {* The field of complex numbers *}
paulson@14335: 
paulson@14335: instance complex :: field
paulson@14335: proof
paulson@14335:   fix z u v w :: complex
paulson@14335:   show "(u + v) + w = u + (v + w)"
paulson@14374:     by (rule complex_add_assoc)
paulson@14335:   show "z + w = w + z"
paulson@14374:     by (rule complex_add_commute)
paulson@14335:   show "0 + z = z"
paulson@14374:     by (rule complex_add_zero_left)
paulson@14335:   show "-z + z = 0"
paulson@14374:     by (rule complex_add_minus_left)
paulson@14335:   show "z - w = z + -w"
paulson@14335:     by (simp add: complex_diff_def)
paulson@14335:   show "(u * v) * w = u * (v * w)"
paulson@14374:     by (rule complex_mult_assoc)
paulson@14335:   show "z * w = w * z"
paulson@14374:     by (rule complex_mult_commute)
paulson@14335:   show "1 * z = z"
paulson@14374:     by (rule complex_mult_one_left)
paulson@14341:   show "0 \<noteq> (1::complex)"
paulson@14373:     by (simp add: complex_zero_def complex_one_def)
paulson@14335:   show "(u + v) * w = u * w + v * w"
paulson@14373:     by (simp add: complex_mult_def complex_add_def left_distrib real_diff_def add_ac)
paulson@14341:   show "z+u = z+v ==> u=v"
paulson@14341:     proof -
paulson@14374:       assume eq: "z+u = z+v"
paulson@14341:       hence "(-z + z) + u = (-z + z) + v" by (simp only: eq complex_add_assoc)
paulson@14373:       thus "u = v" by (simp add: complex_add_minus_left complex_add_zero_left)
paulson@14341:     qed
paulson@14335:   assume neq: "w \<noteq> 0"
paulson@14335:   thus "z / w = z * inverse w"
paulson@14335:     by (simp add: complex_divide_def)
paulson@14335:   show "inverse w * w = 1"
paulson@14374:     by (simp add: neq complex_mult_inv_left)
paulson@14335: qed
paulson@14335: 
paulson@14373: instance complex :: division_by_zero
paulson@14373: proof
paulson@14373:   show inv: "inverse 0 = (0::complex)"
paulson@14373:     by (simp add: complex_inverse_def complex_zero_def)
paulson@14373:   fix x :: complex
paulson@14374:   show "x/0 = 0"
paulson@14373:     by (simp add: complex_divide_def inv)
paulson@14373: qed
paulson@14335: 
paulson@14323: 
paulson@14323: subsection{*Embedding Properties for @{term complex_of_real} Map*}
paulson@14323: 
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"
paulson@14377: by (simp add: i_def 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)"
paulson@14377: by (simp add: i_def complex_of_real_def)
paulson@14377: 
paulson@14377: lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
paulson@14377: by (simp add: i_def complex_of_real_def)
paulson@14377: 
paulson@14377: lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
paulson@14377: by (simp add: i_def complex_of_real_def)
paulson@14377: 
paulson@14374: lemma complex_of_real_one [simp]: "complex_of_real 1 = 1"
paulson@14373: by (simp add: complex_one_def complex_of_real_def)
paulson@14323: 
paulson@14374: lemma complex_of_real_zero [simp]: "complex_of_real 0 = 0"
paulson@14373: by (simp add: complex_zero_def complex_of_real_def)
paulson@14323: 
paulson@14374: lemma complex_of_real_eq_iff [iff]:
paulson@14348:      "(complex_of_real x = complex_of_real y) = (x = y)"
paulson@14374: by (simp add: complex_of_real_def)
paulson@14323: 
paulson@14323: lemma complex_of_real_minus: "complex_of_real(-x) = - complex_of_real x"
paulson@14373: by (simp add: complex_of_real_def complex_minus)
paulson@14323: 
paulson@14348: lemma complex_of_real_inverse:
paulson@14374:      "complex_of_real(inverse x) = inverse(complex_of_real x)"
paulson@14348: apply (case_tac "x=0", simp)
paulson@14374: apply (simp add: complex_inverse complex_of_real_def real_divide_def
paulson@14353:                  inverse_mult_distrib power2_eq_square)
paulson@14323: done
paulson@14323: 
paulson@14348: lemma complex_of_real_add:
paulson@14373:      "complex_of_real x + complex_of_real y = complex_of_real (x + y)"
paulson@14373: by (simp add: complex_add complex_of_real_def)
paulson@14323: 
paulson@14348: lemma complex_of_real_diff:
paulson@14373:      "complex_of_real x - complex_of_real y = complex_of_real (x - y)"
paulson@14374: by (simp add: complex_of_real_minus [symmetric] complex_diff_def 
paulson@14374:               complex_of_real_add)
paulson@14323: 
paulson@14348: lemma complex_of_real_mult:
paulson@14373:      "complex_of_real x * complex_of_real y = complex_of_real (x * y)"
paulson@14373: by (simp add: complex_mult complex_of_real_def)
paulson@14323: 
paulson@14323: lemma complex_of_real_divide:
paulson@14323:       "complex_of_real x / complex_of_real y = complex_of_real(x/y)"
paulson@14373: apply (simp add: complex_divide_def)
paulson@14373: apply (case_tac "y=0", simp)
paulson@14374: apply (simp add: complex_of_real_mult [symmetric] complex_of_real_inverse 
paulson@14374:                  real_divide_def)
paulson@14323: done
paulson@14323: 
paulson@14377: lemma complex_mod [simp]: "cmod (Complex x y) = sqrt(x ^ 2 + y ^ 2)"
paulson@14373: by (simp add: cmod_def)
paulson@14323: 
paulson@14374: lemma complex_mod_zero [simp]: "cmod(0) = 0"
paulson@14373: by (simp add: cmod_def)
paulson@14323: 
paulson@14348: lemma complex_mod_one [simp]: "cmod(1) = 1"
paulson@14353: by (simp add: cmod_def power2_eq_square)
paulson@14323: 
paulson@14374: lemma complex_mod_complex_of_real [simp]: "cmod(complex_of_real x) = abs x"
paulson@14373: by (simp add: complex_of_real_def power2_eq_square complex_mod)
paulson@14323: 
paulson@14348: lemma complex_of_real_abs:
paulson@14348:      "complex_of_real (abs x) = complex_of_real(cmod(complex_of_real x))"
paulson@14373: by simp
paulson@14348: 
paulson@14323: 
paulson@14377: subsection{*The Functions @{term Re} and @{term Im}*}
paulson@14377: 
paulson@14377: lemma complex_Re_mult_eq: "Re (w * z) = Re w * Re z - Im w * Im z"
paulson@14377: by (induct z, induct w, simp add: complex_mult)
paulson@14377: 
paulson@14377: lemma complex_Im_mult_eq: "Im (w * z) = Re w * Im z + Im w * Re z"
paulson@14377: by (induct z, induct w, simp add: complex_mult)
paulson@14377: 
paulson@14377: lemma Re_i_times [simp]: "Re(ii * z) = - Im z"
paulson@14377: by (simp add: complex_Re_mult_eq) 
paulson@14377: 
paulson@14377: lemma Re_times_i [simp]: "Re(z * ii) = - Im z"
paulson@14377: by (simp add: complex_Re_mult_eq) 
paulson@14377: 
paulson@14377: lemma Im_i_times [simp]: "Im(ii * z) = Re z"
paulson@14377: by (simp add: complex_Im_mult_eq) 
paulson@14377: 
paulson@14377: lemma Im_times_i [simp]: "Im(z * ii) = Re z"
paulson@14377: by (simp add: complex_Im_mult_eq) 
paulson@14377: 
paulson@14377: lemma complex_Re_mult: "[| Im w = 0; Im z = 0 |] ==> Re(w * z) = Re(w) * Re(z)"
paulson@14377: by (simp add: complex_Re_mult_eq)
paulson@14377: 
paulson@14377: lemma complex_Re_mult_complex_of_real [simp]:
paulson@14377:      "Re (z * complex_of_real c) = Re(z) * c"
paulson@14377: by (simp add: complex_Re_mult_eq)
paulson@14377: 
paulson@14377: lemma complex_Im_mult_complex_of_real [simp]:
paulson@14377:      "Im (z * complex_of_real c) = Im(z) * c"
paulson@14377: by (simp add: complex_Im_mult_eq)
paulson@14377: 
paulson@14377: lemma complex_Re_mult_complex_of_real2 [simp]:
paulson@14377:      "Re (complex_of_real c * z) = c * Re(z)"
paulson@14377: by (simp add: complex_Re_mult_eq)
paulson@14377: 
paulson@14377: lemma complex_Im_mult_complex_of_real2 [simp]:
paulson@14377:      "Im (complex_of_real c * z) = c * Im(z)"
paulson@14377: by (simp add: complex_Im_mult_eq)
paulson@14377:  
paulson@14377: 
paulson@14323: subsection{*Conjugation is an Automorphism*}
paulson@14323: 
paulson@14373: lemma complex_cnj: "cnj (Complex x y) = Complex x (-y)"
paulson@14373: by (simp add: cnj_def)
paulson@14323: 
paulson@14374: lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
paulson@14373: by (simp add: cnj_def complex_Re_Im_cancel_iff)
paulson@14323: 
paulson@14374: lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
paulson@14373: by (simp add: cnj_def)
paulson@14323: 
paulson@14374: lemma complex_cnj_complex_of_real [simp]:
paulson@14373:      "cnj (complex_of_real x) = complex_of_real x"
paulson@14373: by (simp add: complex_of_real_def complex_cnj)
paulson@14323: 
paulson@14374: lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
paulson@14373: by (induct z, simp add: complex_cnj complex_mod power2_eq_square)
paulson@14323: 
paulson@14323: lemma complex_cnj_minus: "cnj (-z) = - cnj z"
paulson@14373: by (simp add: cnj_def complex_minus complex_Re_minus complex_Im_minus)
paulson@14323: 
paulson@14323: lemma complex_cnj_inverse: "cnj(inverse z) = inverse(cnj z)"
paulson@14373: by (induct z, simp add: complex_cnj complex_inverse power2_eq_square)
paulson@14323: 
paulson@14323: lemma complex_cnj_add: "cnj(w + z) = cnj(w) + cnj(z)"
paulson@14373: by (induct w, induct z, simp add: complex_cnj complex_add)
paulson@14323: 
paulson@14323: lemma complex_cnj_diff: "cnj(w - z) = cnj(w) - cnj(z)"
paulson@14373: by (simp add: complex_diff_def complex_cnj_add complex_cnj_minus)
paulson@14323: 
paulson@14323: lemma complex_cnj_mult: "cnj(w * z) = cnj(w) * cnj(z)"
paulson@14373: by (induct w, induct z, simp add: complex_cnj complex_mult)
paulson@14323: 
paulson@14323: lemma complex_cnj_divide: "cnj(w / z) = (cnj w)/(cnj z)"
paulson@14373: by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
paulson@14323: 
paulson@14374: lemma complex_cnj_one [simp]: "cnj 1 = 1"
paulson@14373: by (simp add: cnj_def complex_one_def)
paulson@14323: 
paulson@14323: lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re(z))"
paulson@14373: by (induct z, simp add: complex_add complex_cnj complex_of_real_def)
paulson@14323: 
paulson@14323: lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im(z)) * ii"
paulson@14373: apply (induct z)
paulson@14374: apply (simp add: complex_add complex_cnj complex_of_real_def complex_diff_def
paulson@14354:                  complex_minus i_def complex_mult)
paulson@14323: done
paulson@14323: 
paulson@14354: lemma complex_cnj_zero [simp]: "cnj 0 = 0"
paulson@14334: by (simp add: cnj_def complex_zero_def)
paulson@14323: 
paulson@14374: lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
paulson@14373: by (induct z, simp add: complex_zero_def complex_cnj)
paulson@14323: 
paulson@14323: lemma complex_mult_cnj: "z * cnj z = complex_of_real (Re(z) ^ 2 + Im(z) ^ 2)"
paulson@14374: by (induct z,
paulson@14374:     simp add: complex_cnj complex_mult complex_of_real_def power2_eq_square)
paulson@14323: 
paulson@14323: 
paulson@14323: subsection{*Modulus*}
paulson@14323: 
paulson@14374: lemma complex_mod_eq_zero_cancel [simp]: "(cmod x = 0) = (x = 0)"
paulson@14373: apply (induct x)
paulson@14374: apply (auto intro: real_sum_squares_cancel real_sum_squares_cancel2
paulson@14373:             simp add: complex_mod complex_zero_def power2_eq_square)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_mod_complex_of_real_of_nat [simp]:
paulson@14373:      "cmod (complex_of_real(real (n::nat))) = real n"
paulson@14373: by simp
paulson@14323: 
paulson@14374: lemma complex_mod_minus [simp]: "cmod (-x) = cmod(x)"
paulson@14373: by (induct x, simp add: complex_mod complex_minus power2_eq_square)
paulson@14323: 
paulson@14323: lemma complex_mod_mult_cnj: "cmod(z * cnj(z)) = cmod(z) ^ 2"
paulson@14373: apply (induct z, simp add: complex_mod complex_cnj complex_mult)
paulson@14373: apply (simp add: power2_eq_square real_abs_def)
paulson@14323: done
paulson@14323: 
paulson@14373: lemma complex_mod_squared: "cmod(Complex x y) ^ 2 = x ^ 2 + y ^ 2"
paulson@14373: by (simp add: cmod_def)
paulson@14323: 
paulson@14374: lemma complex_mod_ge_zero [simp]: "0 \<le> cmod x"
paulson@14373: by (simp add: cmod_def)
paulson@14323: 
paulson@14374: lemma abs_cmod_cancel [simp]: "abs(cmod x) = cmod x"
paulson@14374: by (simp add: abs_if linorder_not_less)
paulson@14323: 
paulson@14323: lemma complex_mod_mult: "cmod(x*y) = cmod(x) * cmod(y)"
paulson@14373: apply (induct x, induct y)
paulson@14377: apply (auto simp add: complex_mult complex_mod real_sqrt_mult_distrib2[symmetric])
paulson@14348: apply (rule_tac n = 1 in power_inject_base)
paulson@14353: apply (auto simp add: power2_eq_square [symmetric] simp del: realpow_Suc)
paulson@14374: apply (auto simp add: real_diff_def power2_eq_square right_distrib left_distrib 
paulson@14374:                       add_ac mult_ac)
paulson@14323: done
paulson@14323: 
paulson@14377: lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
paulson@14377: by (simp add: cmod_def) 
paulson@14377: 
paulson@14377: lemma cmod_complex_polar [simp]:
paulson@14377:      "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
paulson@14377: by (simp only: cmod_unit_one complex_mod_mult, simp) 
paulson@14377: 
paulson@14374: lemma complex_mod_add_squared_eq:
paulson@14374:      "cmod(x + y) ^ 2 = cmod(x) ^ 2 + cmod(y) ^ 2 + 2 * Re(x * cnj y)"
paulson@14373: apply (induct x, induct y)
paulson@14323: apply (auto simp add: complex_add complex_mod_squared complex_mult complex_cnj real_diff_def simp del: realpow_Suc)
paulson@14353: apply (auto simp add: right_distrib left_distrib power2_eq_square mult_ac add_ac)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_Re_mult_cnj_le_cmod [simp]: "Re(x * cnj y) \<le> cmod(x * cnj y)"
paulson@14373: apply (induct x, induct y)
paulson@14323: apply (auto simp add: complex_mod complex_mult complex_cnj real_diff_def simp del: realpow_Suc)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_Re_mult_cnj_le_cmod2 [simp]: "Re(x * cnj y) \<le> cmod(x * y)"
paulson@14373: by (insert complex_Re_mult_cnj_le_cmod [of x y], simp add: complex_mod_mult)
paulson@14323: 
paulson@14374: lemma real_sum_squared_expand:
paulson@14374:      "((x::real) + y) ^ 2 = x ^ 2 + y ^ 2 + 2 * x * y"
paulson@14373: by (simp add: left_distrib right_distrib power2_eq_square)
paulson@14323: 
paulson@14374: lemma complex_mod_triangle_squared [simp]:
paulson@14374:      "cmod (x + y) ^ 2 \<le> (cmod(x) + cmod(y)) ^ 2"
paulson@14373: by (simp add: real_sum_squared_expand complex_mod_add_squared_eq real_mult_assoc complex_mod_mult [symmetric])
paulson@14323: 
paulson@14374: lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
paulson@14373: by (rule order_trans [OF _ complex_mod_ge_zero], simp)
paulson@14323: 
paulson@14374: lemma complex_mod_triangle_ineq [simp]: "cmod (x + y) \<le> cmod(x) + cmod(y)"
paulson@14334: apply (rule_tac n = 1 in realpow_increasing)
paulson@14323: apply (auto intro:  order_trans [OF _ complex_mod_ge_zero]
paulson@14353:             simp add: power2_eq_square [symmetric])
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
paulson@14373: by (insert complex_mod_triangle_ineq [THEN add_right_mono, of b a"-cmod b"], simp)
paulson@14323: 
paulson@14323: lemma complex_mod_diff_commute: "cmod (x - y) = cmod (y - x)"
paulson@14373: apply (induct x, induct y)
paulson@14353: apply (auto simp add: complex_diff complex_mod right_diff_distrib power2_eq_square left_diff_distrib add_ac mult_ac)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_mod_add_less:
paulson@14374:      "[| cmod x < r; cmod y < s |] ==> cmod (x + y) < r + s"
paulson@14334: by (auto intro: order_le_less_trans complex_mod_triangle_ineq)
paulson@14323: 
paulson@14374: lemma complex_mod_mult_less:
paulson@14374:      "[| cmod x < r; cmod y < s |] ==> cmod (x * y) < r * s"
paulson@14334: by (auto intro: real_mult_less_mono' simp add: complex_mod_mult)
paulson@14323: 
paulson@14374: lemma complex_mod_diff_ineq [simp]: "cmod(a) - cmod(b) \<le> cmod(a + b)"
paulson@14323: apply (rule linorder_cases [of "cmod(a)" "cmod (b)"])
paulson@14323: apply auto
paulson@14334: apply (rule order_trans [of _ 0], rule order_less_imp_le)
paulson@14374: apply (simp add: compare_rls, simp)
paulson@14323: apply (simp add: compare_rls)
paulson@14323: apply (rule complex_mod_minus [THEN subst])
paulson@14323: apply (rule order_trans)
paulson@14323: apply (rule_tac [2] complex_mod_triangle_ineq)
paulson@14373: apply (auto simp add: add_ac)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_Re_le_cmod [simp]: "Re z \<le> cmod z"
paulson@14373: by (induct z, simp add: complex_mod del: realpow_Suc)
paulson@14323: 
paulson@14354: lemma complex_mod_gt_zero: "z \<noteq> 0 ==> 0 < cmod z"
paulson@14373: apply (insert complex_mod_ge_zero [of z])
paulson@14334: apply (drule order_le_imp_less_or_eq, auto)
paulson@14323: done
paulson@14323: 
paulson@14323: 
paulson@14323: subsection{*A Few More Theorems*}
paulson@14323: 
paulson@14323: lemma complex_mod_inverse: "cmod(inverse x) = inverse(cmod x)"
paulson@14373: apply (case_tac "x=0", simp)
paulson@14323: apply (rule_tac c1 = "cmod x" in real_mult_left_cancel [THEN iffD1])
paulson@14323: apply (auto simp add: complex_mod_mult [symmetric])
paulson@14323: done
paulson@14323: 
paulson@14373: lemma complex_mod_divide: "cmod(x/y) = cmod(x)/(cmod y)"
paulson@14377: by (simp add: complex_divide_def real_divide_def complex_mod_mult complex_mod_inverse)
paulson@14323: 
paulson@14354: 
paulson@14354: subsection{*Exponentiation*}
paulson@14354: 
paulson@14354: primrec
paulson@14354:      complexpow_0:   "z ^ 0       = 1"
paulson@14354:      complexpow_Suc: "z ^ (Suc n) = (z::complex) * (z ^ n)"
paulson@14354: 
paulson@14354: 
paulson@14354: instance complex :: ringpower
paulson@14354: proof
paulson@14354:   fix z :: complex
paulson@14354:   fix n :: nat
paulson@14354:   show "z^0 = 1" by simp
paulson@14354:   show "z^(Suc n) = z * (z^n)" by simp
paulson@14354: qed
paulson@14323: 
paulson@14323: 
paulson@14354: lemma complex_of_real_pow: "complex_of_real (x ^ n) = (complex_of_real x) ^ n"
paulson@14323: apply (induct_tac "n")
paulson@14354: apply (auto simp add: complex_of_real_mult [symmetric])
paulson@14323: done
paulson@14323: 
paulson@14354: lemma complex_cnj_pow: "cnj(z ^ n) = cnj(z) ^ n"
paulson@14323: apply (induct_tac "n")
paulson@14354: apply (auto simp add: complex_cnj_mult)
paulson@14323: done
paulson@14323: 
paulson@14354: lemma complex_mod_complexpow: "cmod(x ^ n) = cmod(x) ^ n"
paulson@14354: apply (induct_tac "n")
paulson@14354: apply (auto simp add: complex_mod_mult)
paulson@14354: done
paulson@14354: 
paulson@14374: lemma complexpow_minus:
paulson@14374:      "(-x::complex) ^ n = (if even n then (x ^ n) else -(x ^ n))"
paulson@14354: by (induct_tac "n", auto)
paulson@14354: 
paulson@14354: lemma complexpow_i_squared [simp]: "ii ^ 2 = -(1::complex)"
paulson@14354: by (simp add: i_def complex_mult complex_one_def complex_minus numeral_2_eq_2)
paulson@14354: 
paulson@14354: lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
paulson@14373: by (simp add: i_def complex_zero_def)
paulson@14354: 
paulson@14354: 
paulson@14354: subsection{*The Function @{term sgn}*}
paulson@14323: 
paulson@14374: lemma sgn_zero [simp]: "sgn 0 = 0"
paulson@14373: by (simp add: sgn_def)
paulson@14323: 
paulson@14374: lemma sgn_one [simp]: "sgn 1 = 1"
paulson@14373: by (simp add: sgn_def)
paulson@14323: 
paulson@14323: lemma sgn_minus: "sgn (-z) = - sgn(z)"
paulson@14373: by (simp add: sgn_def)
paulson@14323: 
paulson@14374: lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
paulson@14377: by (simp add: sgn_def)
paulson@14323: 
paulson@14323: lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
paulson@14373: by (simp add: i_def complex_of_real_def complex_mult complex_add)
paulson@14323: 
paulson@14374: lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
paulson@14373: by (simp add: i_def complex_one_def complex_mult complex_minus)
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 complex_eq_cancel_iff2a [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@14377: lemma Complex_eq_0 [simp]: "(Complex x y = 0) = (x = 0 & y = 0)"
paulson@14377: by (simp add: complex_zero_def)
paulson@14323: 
paulson@14377: lemma Complex_eq_1 [simp]: "(Complex x y = 1) = (x = 1 & y = 0)"
paulson@14377: by (simp add: complex_one_def)
paulson@14323: 
paulson@14377: lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 & y = 1)"
paulson@14377: by (simp add: i_def)
paulson@14323: 
paulson@14374: lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
paulson@14373: apply (induct z)
paulson@14373: apply (simp add: sgn_def complex_divide_def complex_of_real_inverse [symmetric])
paulson@14373: apply (simp add: complex_of_real_def complex_mult real_divide_def)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
paulson@14373: apply (induct z)
paulson@14373: apply (simp add: sgn_def complex_divide_def complex_of_real_inverse [symmetric])
paulson@14373: apply (simp add: complex_of_real_def complex_mult real_divide_def)
paulson@14323: done
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))"
paulson@14374: by (simp add: complex_of_real_def i_def complex_mult complex_add
paulson@14373:          complex_diff_def complex_minus complex_inverse real_divide_def)
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 complex_of_real_zero_iff [simp]: "(complex_of_real y = 0) = (y = 0)"
paulson@14354: by (auto simp add: complex_zero_def complex_of_real_def)
paulson@14354: 
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 \<noteq> 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: 
paulson@14374: lemma complex_split_polar:
paulson@14377:      "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
paulson@14377: 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: "\<exists>r a. z = rcis r a"
paulson@14377: 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)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
paulson@14377: proof -
paulson@14377:   have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
paulson@14377:     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: 
paulson@14323: lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
paulson@14373: apply (simp add: cmod_def)
paulson@14323: apply (rule real_sqrt_eq_iff [THEN iffD2])
paulson@14323: apply (auto simp add: complex_mult_cnj)
paulson@14323: done
paulson@14323: 
paulson@14374: lemma complex_Re_cnj [simp]: "Re(cnj z) = Re z"
paulson@14373: by (induct z, simp add: complex_cnj)
paulson@14323: 
paulson@14374: lemma complex_Im_cnj [simp]: "Im(cnj z) = - Im z"
paulson@14374: by (induct z, simp add: complex_cnj)
paulson@14374: 
paulson@14374: lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
paulson@14373: by (induct z, simp add: complex_cnj complex_mult)
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@14377: by (simp add: rcis_def cis_def complex_of_real_mult_Complex cos_add sin_add right_distrib right_diff_distrib)
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)"
paulson@14377: by (simp add: complex_of_real_def complex_one_def complex_minus)
paulson@14323: 
paulson@14374: lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
paulson@14373: by (simp add: complex_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)"
paulson@14374: by (simp add: rcis_def power_mult_distrib DeMoivre complex_of_real_pow)
paulson@14323: 
paulson@14374: lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
paulson@14374: by (simp add: cis_def complex_inverse_complex_split complex_of_real_minus 
paulson@14374:               complex_diff_def)
paulson@14323: 
paulson@14323: lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
paulson@14377: by (simp add: divide_inverse_zero rcis_def complex_of_real_inverse)
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)"
paulson@14374: by (simp add: expi_def complex_Re_add exp_add complex_Im_add 
paulson@14374:               cis_mult [symmetric] complex_of_real_mult 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: "\<exists>a r. z = complex_of_real r * expi a"
paulson@14373: apply (insert rcis_Ex [of z])
paulson@14323: apply (auto simp add: expi_def rcis_def complex_mult_assoc [symmetric] complex_of_real_mult)
paulson@14334: apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
paulson@14323: done
paulson@14323: 
paulson@14323: 
paulson@14387: subsection{*Numerals and Arithmetic*}
paulson@14387: 
paulson@14387: instance complex :: number ..
paulson@14387: 
paulson@14387: primrec (*the type constraint is essential!*)
paulson@14387:   number_of_Pls: "number_of bin.Pls = 0"
paulson@14387:   number_of_Min: "number_of bin.Min = - (1::complex)"
paulson@14387:   number_of_BIT: "number_of(w BIT x) = (if x then 1 else 0) +
paulson@14387: 	                               (number_of w) + (number_of w)"
paulson@14387: 
paulson@14387: declare number_of_Pls [simp del]
paulson@14387:         number_of_Min [simp del]
paulson@14387:         number_of_BIT [simp del]
paulson@14387: 
paulson@14387: instance complex :: number_ring
paulson@14387: proof
paulson@14387:   show "Numeral0 = (0::complex)" by (rule number_of_Pls)
paulson@14387:   show "-1 = - (1::complex)" by (rule number_of_Min)
paulson@14387:   fix w :: bin and x :: bool
paulson@14387:   show "(number_of (w BIT x) :: complex) =
paulson@14387:         (if x then 1 else 0) + number_of w + number_of w"
paulson@14387:     by (rule number_of_BIT)
paulson@14387: qed
paulson@14387: 
paulson@14387: 
paulson@14387: text{*Collapse applications of @{term complex_of_real} to @{term number_of}*}
paulson@14387: lemma complex_number_of [simp]: "complex_of_real (number_of w) = number_of w"
paulson@14387: apply (induct w) 
paulson@14387: apply (simp_all only: number_of complex_of_real_add [symmetric] 
paulson@14387:                       complex_of_real_minus, simp_all) 
paulson@14387: done
paulson@14387: 
paulson@14387: text{*This theorem is necessary because theorems such as
paulson@14387:    @{text iszero_number_of_0} only hold for ordered rings. They cannot
paulson@14387:    be generalized to fields in general because they fail for finite fields.
paulson@14387:    They work for type complex because the reals can be embedded in them.*}
paulson@14387: lemma iszero_complex_number_of [simp]:
paulson@14387:      "iszero (number_of w :: complex) = iszero (number_of w :: real)"
paulson@14387: by (simp only: complex_of_real_zero_iff complex_number_of [symmetric] 
paulson@14387:                iszero_def)  
paulson@14387: 
paulson@14387: 
paulson@14387: (*These allow simplification of expressions involving mixed numbers.
paulson@14387:   Convert???
paulson@14387: Goalw [complex_number_of_def] 
paulson@14387:   "((number_of xa :: complex) + ii * number_of ya =  
paulson@14387:         number_of xb) =  
paulson@14387:    (((number_of xa :: complex) = number_of xb) &  
paulson@14387:     ((number_of ya :: complex) = 0))"
paulson@14387: by (auto_tac (claset(), HOL_ss addsimps [complex_eq_cancel_iff2,
paulson@14387:     complex_of_real_zero_iff]));
paulson@14387: qed "complex_number_of_eq_cancel_iff2";
paulson@14387: Addsimps [complex_number_of_eq_cancel_iff2];
paulson@14387: 
paulson@14387: Goalw [complex_number_of_def] 
paulson@14387:   "((number_of xa :: complex) + number_of ya * ii = \
paulson@14387: \       number_of xb) = \
paulson@14387: \  (((number_of xa :: complex) = number_of xb) & \
paulson@14387: \   ((number_of ya :: complex) = 0))";
paulson@14387: by (auto_tac (claset(), HOL_ss addsimps [complex_eq_cancel_iff2a,
paulson@14387:     complex_of_real_zero_iff]));
paulson@14387: qed "complex_number_of_eq_cancel_iff2a";
paulson@14387: Addsimps [complex_number_of_eq_cancel_iff2a];
paulson@14387: 
paulson@14387: Goalw [complex_number_of_def] 
paulson@14387:   "((number_of xa :: complex) + ii * number_of ya = \
paulson@14387: \    ii * number_of yb) = \
paulson@14387: \  (((number_of xa :: complex) = 0) & \
paulson@14387: \   ((number_of ya :: complex) = number_of yb))";
paulson@14387: by (auto_tac (claset(), HOL_ss addsimps [complex_eq_cancel_iff3,
paulson@14387:     complex_of_real_zero_iff]));
paulson@14387: qed "complex_number_of_eq_cancel_iff3";
paulson@14387: Addsimps [complex_number_of_eq_cancel_iff3];
paulson@14387: 
paulson@14387: Goalw [complex_number_of_def] 
paulson@14387:   "((number_of xa :: complex) + number_of ya * ii= \
paulson@14387: \    ii * number_of yb) = \
paulson@14387: \  (((number_of xa :: complex) = 0) & \
paulson@14387: \   ((number_of ya :: complex) = number_of yb))";
paulson@14387: by (auto_tac (claset(), HOL_ss addsimps [complex_eq_cancel_iff3a,
paulson@14387:     complex_of_real_zero_iff]));
paulson@14387: qed "complex_number_of_eq_cancel_iff3a";
paulson@14387: Addsimps [complex_number_of_eq_cancel_iff3a];
paulson@14387: *)
paulson@14387: 
paulson@14387: lemma complex_number_of_cnj [simp]: "cnj(number_of v :: complex) = number_of v"
paulson@14387: apply (subst complex_number_of [symmetric])
paulson@14387: apply (rule complex_cnj_complex_of_real)
paulson@14387: done
paulson@14387: 
paulson@14387: lemma complex_number_of_cmod: 
paulson@14387:       "cmod(number_of v :: complex) = abs (number_of v :: real)"
paulson@14387: by (simp only: complex_number_of [symmetric] complex_mod_complex_of_real)
paulson@14387: 
paulson@14387: lemma complex_number_of_Re [simp]: "Re(number_of v :: complex) = number_of v"
paulson@14387: by (simp only: complex_number_of [symmetric] Re_complex_of_real)
paulson@14387: 
paulson@14387: lemma complex_number_of_Im [simp]: "Im(number_of v :: complex) = 0"
paulson@14387: by (simp only: complex_number_of [symmetric] Im_complex_of_real)
paulson@14387: 
paulson@14387: lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
paulson@14387: by (simp add: expi_def complex_Re_mult_eq complex_Im_mult_eq cis_def)
paulson@14387: 
paulson@14387: 
paulson@14387: (*examples:
paulson@14387: print_depth 22
paulson@14387: set timing;
paulson@14387: set trace_simp;
paulson@14387: fun test s = (Goal s, by (Simp_tac 1)); 
paulson@14387: 
paulson@14387: test "23 * ii + 45 * ii= (x::complex)";
paulson@14387: 
paulson@14387: test "5 * ii + 12 - 45 * ii= (x::complex)";
paulson@14387: test "5 * ii + 40 - 12 * ii + 9 = (x::complex) + 89 * ii";
paulson@14387: test "5 * ii + 40 - 12 * ii + 9 - 78 = (x::complex) + 89 * ii";
paulson@14387: 
paulson@14387: test "l + 10 * ii + 90 + 3*l +  9 + 45 * ii= (x::complex)";
paulson@14387: test "87 + 10 * ii + 90 + 3*7 +  9 + 45 * ii= (x::complex)";
paulson@14387: 
paulson@14387: 
paulson@14387: fun test s = (Goal s; by (Asm_simp_tac 1)); 
paulson@14387: 
paulson@14387: test "x*k = k*(y::complex)";
paulson@14387: test "k = k*(y::complex)"; 
paulson@14387: test "a*(b*c) = (b::complex)";
paulson@14387: test "a*(b*c) = d*(b::complex)*(x*a)";
paulson@14387: 
paulson@14387: 
paulson@14387: test "(x*k) / (k*(y::complex)) = (uu::complex)";
paulson@14387: test "(k) / (k*(y::complex)) = (uu::complex)"; 
paulson@14387: test "(a*(b*c)) / ((b::complex)) = (uu::complex)";
paulson@14387: test "(a*(b*c)) / (d*(b::complex)*(x*a)) = (uu::complex)";
paulson@14387: 
paulson@14387: (*FIXME: what do we do about this?*)
paulson@14387: test "a*(b*c)/(y*z) = d*(b::complex)*(x*a)/z";
paulson@14387: *)
paulson@14387: 
paulson@14323: 
paulson@14323: ML
paulson@14323: {*
paulson@14323: val complex_zero_def = thm"complex_zero_def";
paulson@14323: val complex_one_def = thm"complex_one_def";
paulson@14323: val complex_minus_def = thm"complex_minus_def";
paulson@14323: val complex_diff_def = thm"complex_diff_def";
paulson@14323: val complex_divide_def = thm"complex_divide_def";
paulson@14323: val complex_mult_def = thm"complex_mult_def";
paulson@14323: val complex_add_def = thm"complex_add_def";
paulson@14323: val complex_of_real_def = thm"complex_of_real_def";
paulson@14323: val i_def = thm"i_def";
paulson@14323: val expi_def = thm"expi_def";
paulson@14323: val cis_def = thm"cis_def";
paulson@14323: val rcis_def = thm"rcis_def";
paulson@14323: val cmod_def = thm"cmod_def";
paulson@14323: val cnj_def = thm"cnj_def";
paulson@14323: val sgn_def = thm"sgn_def";
paulson@14323: val arg_def = thm"arg_def";
paulson@14323: val complexpow_0 = thm"complexpow_0";
paulson@14323: val complexpow_Suc = thm"complexpow_Suc";
paulson@14323: 
paulson@14323: val Re = thm"Re";
paulson@14323: val Im = thm"Im";
paulson@14323: val complex_Re_Im_cancel_iff = thm"complex_Re_Im_cancel_iff";
paulson@14323: val complex_Re_zero = thm"complex_Re_zero";
paulson@14323: val complex_Im_zero = thm"complex_Im_zero";
paulson@14323: val complex_Re_one = thm"complex_Re_one";
paulson@14323: val complex_Im_one = thm"complex_Im_one";
paulson@14323: val complex_Re_i = thm"complex_Re_i";
paulson@14323: val complex_Im_i = thm"complex_Im_i";
paulson@14323: val Re_complex_of_real = thm"Re_complex_of_real";
paulson@14323: val Im_complex_of_real = thm"Im_complex_of_real";
paulson@14323: val complex_minus = thm"complex_minus";
paulson@14323: val complex_Re_minus = thm"complex_Re_minus";
paulson@14323: val complex_Im_minus = thm"complex_Im_minus";
paulson@14323: val complex_add = thm"complex_add";
paulson@14323: val complex_Re_add = thm"complex_Re_add";
paulson@14323: val complex_Im_add = thm"complex_Im_add";
paulson@14323: val complex_add_commute = thm"complex_add_commute";
paulson@14323: val complex_add_assoc = thm"complex_add_assoc";
paulson@14323: val complex_add_zero_left = thm"complex_add_zero_left";
paulson@14323: val complex_add_zero_right = thm"complex_add_zero_right";
paulson@14323: val complex_diff = thm"complex_diff";
paulson@14323: val complex_mult = thm"complex_mult";
paulson@14323: val complex_mult_one_left = thm"complex_mult_one_left";
paulson@14323: val complex_mult_one_right = thm"complex_mult_one_right";
paulson@14323: val complex_inverse = thm"complex_inverse";
paulson@14323: val complex_of_real_one = thm"complex_of_real_one";
paulson@14323: val complex_of_real_zero = thm"complex_of_real_zero";
paulson@14323: val complex_of_real_eq_iff = thm"complex_of_real_eq_iff";
paulson@14323: val complex_of_real_minus = thm"complex_of_real_minus";
paulson@14323: val complex_of_real_inverse = thm"complex_of_real_inverse";
paulson@14323: val complex_of_real_add = thm"complex_of_real_add";
paulson@14323: val complex_of_real_diff = thm"complex_of_real_diff";
paulson@14323: val complex_of_real_mult = thm"complex_of_real_mult";
paulson@14323: val complex_of_real_divide = thm"complex_of_real_divide";
paulson@14323: val complex_of_real_pow = thm"complex_of_real_pow";
paulson@14323: val complex_mod = thm"complex_mod";
paulson@14323: val complex_mod_zero = thm"complex_mod_zero";
paulson@14323: val complex_mod_one = thm"complex_mod_one";
paulson@14323: val complex_mod_complex_of_real = thm"complex_mod_complex_of_real";
paulson@14323: val complex_of_real_abs = thm"complex_of_real_abs";
paulson@14323: val complex_cnj = thm"complex_cnj";
paulson@14323: val complex_cnj_cancel_iff = thm"complex_cnj_cancel_iff";
paulson@14323: val complex_cnj_cnj = thm"complex_cnj_cnj";
paulson@14323: val complex_cnj_complex_of_real = thm"complex_cnj_complex_of_real";
paulson@14323: val complex_mod_cnj = thm"complex_mod_cnj";
paulson@14323: val complex_cnj_minus = thm"complex_cnj_minus";
paulson@14323: val complex_cnj_inverse = thm"complex_cnj_inverse";
paulson@14323: val complex_cnj_add = thm"complex_cnj_add";
paulson@14323: val complex_cnj_diff = thm"complex_cnj_diff";
paulson@14323: val complex_cnj_mult = thm"complex_cnj_mult";
paulson@14323: val complex_cnj_divide = thm"complex_cnj_divide";
paulson@14323: val complex_cnj_one = thm"complex_cnj_one";
paulson@14323: val complex_cnj_pow = thm"complex_cnj_pow";
paulson@14323: val complex_add_cnj = thm"complex_add_cnj";
paulson@14323: val complex_diff_cnj = thm"complex_diff_cnj";
paulson@14323: val complex_cnj_zero = thm"complex_cnj_zero";
paulson@14323: val complex_cnj_zero_iff = thm"complex_cnj_zero_iff";
paulson@14323: val complex_mult_cnj = thm"complex_mult_cnj";
paulson@14323: val complex_mod_eq_zero_cancel = thm"complex_mod_eq_zero_cancel";
paulson@14323: val complex_mod_complex_of_real_of_nat = thm"complex_mod_complex_of_real_of_nat";
paulson@14323: val complex_mod_minus = thm"complex_mod_minus";
paulson@14323: val complex_mod_mult_cnj = thm"complex_mod_mult_cnj";
paulson@14323: val complex_mod_squared = thm"complex_mod_squared";
paulson@14323: val complex_mod_ge_zero = thm"complex_mod_ge_zero";
paulson@14323: val abs_cmod_cancel = thm"abs_cmod_cancel";
paulson@14323: val complex_mod_mult = thm"complex_mod_mult";
paulson@14323: val complex_mod_add_squared_eq = thm"complex_mod_add_squared_eq";
paulson@14323: val complex_Re_mult_cnj_le_cmod = thm"complex_Re_mult_cnj_le_cmod";
paulson@14323: val complex_Re_mult_cnj_le_cmod2 = thm"complex_Re_mult_cnj_le_cmod2";
paulson@14323: val real_sum_squared_expand = thm"real_sum_squared_expand";
paulson@14323: val complex_mod_triangle_squared = thm"complex_mod_triangle_squared";
paulson@14323: val complex_mod_minus_le_complex_mod = thm"complex_mod_minus_le_complex_mod";
paulson@14323: val complex_mod_triangle_ineq = thm"complex_mod_triangle_ineq";
paulson@14323: val complex_mod_triangle_ineq2 = thm"complex_mod_triangle_ineq2";
paulson@14323: val complex_mod_diff_commute = thm"complex_mod_diff_commute";
paulson@14323: val complex_mod_add_less = thm"complex_mod_add_less";
paulson@14323: val complex_mod_mult_less = thm"complex_mod_mult_less";
paulson@14323: val complex_mod_diff_ineq = thm"complex_mod_diff_ineq";
paulson@14323: val complex_Re_le_cmod = thm"complex_Re_le_cmod";
paulson@14323: val complex_mod_gt_zero = thm"complex_mod_gt_zero";
paulson@14323: val complex_mod_complexpow = thm"complex_mod_complexpow";
paulson@14323: val complexpow_minus = thm"complexpow_minus";
paulson@14323: val complex_mod_inverse = thm"complex_mod_inverse";
paulson@14323: val complex_mod_divide = thm"complex_mod_divide";
paulson@14323: val complexpow_i_squared = thm"complexpow_i_squared";
paulson@14323: val complex_i_not_zero = thm"complex_i_not_zero";
paulson@14323: val sgn_zero = thm"sgn_zero";
paulson@14323: val sgn_one = thm"sgn_one";
paulson@14323: val sgn_minus = thm"sgn_minus";
paulson@14323: val sgn_eq = thm"sgn_eq";
paulson@14323: val i_mult_eq = thm"i_mult_eq";
paulson@14323: val i_mult_eq2 = thm"i_mult_eq2";
paulson@14323: val Re_sgn = thm"Re_sgn";
paulson@14323: val Im_sgn = thm"Im_sgn";
paulson@14323: val complex_inverse_complex_split = thm"complex_inverse_complex_split";
paulson@14323: val cos_arg_i_mult_zero = thm"cos_arg_i_mult_zero";
paulson@14323: val complex_of_real_zero_iff = thm"complex_of_real_zero_iff";
paulson@14323: val rcis_Ex = thm"rcis_Ex";
paulson@14323: val Re_rcis = thm"Re_rcis";
paulson@14323: val Im_rcis = thm"Im_rcis";
paulson@14323: val complex_mod_rcis = thm"complex_mod_rcis";
paulson@14323: val complex_mod_sqrt_Re_mult_cnj = thm"complex_mod_sqrt_Re_mult_cnj";
paulson@14323: val complex_Re_cnj = thm"complex_Re_cnj";
paulson@14323: val complex_Im_cnj = thm"complex_Im_cnj";
paulson@14323: val complex_In_mult_cnj_zero = thm"complex_In_mult_cnj_zero";
paulson@14323: val complex_Re_mult = thm"complex_Re_mult";
paulson@14323: val complex_Re_mult_complex_of_real = thm"complex_Re_mult_complex_of_real";
paulson@14323: val complex_Im_mult_complex_of_real = thm"complex_Im_mult_complex_of_real";
paulson@14323: val complex_Re_mult_complex_of_real2 = thm"complex_Re_mult_complex_of_real2";
paulson@14323: val complex_Im_mult_complex_of_real2 = thm"complex_Im_mult_complex_of_real2";
paulson@14323: val cis_rcis_eq = thm"cis_rcis_eq";
paulson@14323: val rcis_mult = thm"rcis_mult";
paulson@14323: val cis_mult = thm"cis_mult";
paulson@14323: val cis_zero = thm"cis_zero";
paulson@14323: val rcis_zero_mod = thm"rcis_zero_mod";
paulson@14323: val rcis_zero_arg = thm"rcis_zero_arg";
paulson@14323: val complex_of_real_minus_one = thm"complex_of_real_minus_one";
paulson@14323: val complex_i_mult_minus = thm"complex_i_mult_minus";
paulson@14323: val cis_real_of_nat_Suc_mult = thm"cis_real_of_nat_Suc_mult";
paulson@14323: val DeMoivre = thm"DeMoivre";
paulson@14323: val DeMoivre2 = thm"DeMoivre2";
paulson@14323: val cis_inverse = thm"cis_inverse";
paulson@14323: val rcis_inverse = thm"rcis_inverse";
paulson@14323: val cis_divide = thm"cis_divide";
paulson@14323: val rcis_divide = thm"rcis_divide";
paulson@14323: val Re_cis = thm"Re_cis";
paulson@14323: val Im_cis = thm"Im_cis";
paulson@14323: val cos_n_Re_cis_pow_n = thm"cos_n_Re_cis_pow_n";
paulson@14323: val sin_n_Im_cis_pow_n = thm"sin_n_Im_cis_pow_n";
paulson@14323: val expi_add = thm"expi_add";
paulson@14323: val expi_zero = thm"expi_zero";
paulson@14323: val complex_Re_mult_eq = thm"complex_Re_mult_eq";
paulson@14323: val complex_Im_mult_eq = thm"complex_Im_mult_eq";
paulson@14323: val complex_expi_Ex = thm"complex_expi_Ex";
paulson@14323: *}
paulson@14323: 
paulson@13957: end
paulson@13957: 
paulson@13957: 




