src/HOL/Multivariate_Analysis/Complex_Transcendental.thy
author paulson <lp15@cam.ac.uk>
Thu Mar 19 14:24:51 2015 +0000 (2015-03-19)
changeset 59751 916c0f6c83e3
parent 59746 ddae5727c5a9
child 59862 44b3f4fa33ca
permissions -rw-r--r--
New material for complex sin, cos, tan, Ln, also some reorganisation
lp15@59746
     1
(*  Author: John Harrison
lp15@59745
     2
    Ported from "hol_light/Multivariate/transcendentals.ml" by L C Paulson (2015)
lp15@59745
     3
*)
lp15@59745
     4
lp15@59745
     5
section {* Complex Transcendental Functions *}
lp15@59745
     6
lp15@59745
     7
theory Complex_Transcendental
lp15@59745
     8
imports  "~~/src/HOL/Multivariate_Analysis/Complex_Analysis_Basics"
lp15@59745
     9
begin
lp15@59745
    10
lp15@59746
    11
subsection{*The Exponential Function is Differentiable and Continuous*}
lp15@59745
    12
lp15@59745
    13
lemma complex_differentiable_at_exp: "exp complex_differentiable at z"
lp15@59745
    14
  using DERIV_exp complex_differentiable_def by blast
lp15@59745
    15
lp15@59745
    16
lemma complex_differentiable_within_exp: "exp complex_differentiable (at z within s)"
lp15@59745
    17
  by (simp add: complex_differentiable_at_exp complex_differentiable_at_within)
lp15@59745
    18
lp15@59745
    19
lemma continuous_within_exp:
lp15@59745
    20
  fixes z::"'a::{real_normed_field,banach}"
lp15@59745
    21
  shows "continuous (at z within s) exp"
lp15@59745
    22
by (simp add: continuous_at_imp_continuous_within)
lp15@59745
    23
lp15@59745
    24
lemma continuous_on_exp:
lp15@59745
    25
  fixes s::"'a::{real_normed_field,banach} set"
lp15@59745
    26
  shows "continuous_on s exp"
lp15@59745
    27
by (simp add: continuous_on_exp continuous_on_id)
lp15@59745
    28
lp15@59745
    29
lemma holomorphic_on_exp: "exp holomorphic_on s"
lp15@59745
    30
  by (simp add: complex_differentiable_within_exp holomorphic_on_def)
lp15@59745
    31
lp15@59745
    32
subsection{*Euler and de Moivre formulas.*}
lp15@59745
    33
lp15@59745
    34
text{*The sine series times @{term i}*}
lp15@59745
    35
lemma sin_ii_eq: "(\<lambda>n. (ii * sin_coeff n) * z^n) sums (ii * sin z)"
lp15@59745
    36
proof -
lp15@59745
    37
  have "(\<lambda>n. ii * sin_coeff n *\<^sub>R z^n) sums (ii * sin z)"
lp15@59745
    38
    using sin_converges sums_mult by blast
lp15@59745
    39
  then show ?thesis
lp15@59745
    40
    by (simp add: scaleR_conv_of_real field_simps)
lp15@59745
    41
qed
lp15@59745
    42
lp15@59745
    43
theorem exp_Euler: "exp(ii * z) = cos(z) + ii * sin(z)"
lp15@59745
    44
proof -
lp15@59745
    45
  have "(\<lambda>n. (cos_coeff n + ii * sin_coeff n) * z^n) 
lp15@59745
    46
        = (\<lambda>n. (ii * z) ^ n /\<^sub>R (fact n))"
lp15@59745
    47
  proof
lp15@59745
    48
    fix n
lp15@59745
    49
    show "(cos_coeff n + ii * sin_coeff n) * z^n = (ii * z) ^ n /\<^sub>R (fact n)"
lp15@59745
    50
      by (auto simp: cos_coeff_def sin_coeff_def scaleR_conv_of_real field_simps elim!: evenE oddE)
lp15@59745
    51
  qed
lp15@59745
    52
  also have "... sums (exp (ii * z))"
lp15@59745
    53
    by (rule exp_converges)
lp15@59745
    54
  finally have "(\<lambda>n. (cos_coeff n + ii * sin_coeff n) * z^n) sums (exp (ii * z))" .
lp15@59745
    55
  moreover have "(\<lambda>n. (cos_coeff n + ii * sin_coeff n) * z^n) sums (cos z + ii * sin z)"
lp15@59745
    56
    using sums_add [OF cos_converges [of z] sin_ii_eq [of z]]
lp15@59745
    57
    by (simp add: field_simps scaleR_conv_of_real)
lp15@59745
    58
  ultimately show ?thesis
lp15@59745
    59
    using sums_unique2 by blast
lp15@59745
    60
qed
lp15@59745
    61
lp15@59745
    62
corollary exp_minus_Euler: "exp(-(ii * z)) = cos(z) - ii * sin(z)"
lp15@59745
    63
  using exp_Euler [of "-z"]
lp15@59745
    64
  by simp
lp15@59745
    65
lp15@59745
    66
lemma sin_exp_eq: "sin z = (exp(ii * z) - exp(-(ii * z))) / (2*ii)"
lp15@59745
    67
  by (simp add: exp_Euler exp_minus_Euler)
lp15@59745
    68
lp15@59745
    69
lemma sin_exp_eq': "sin z = ii * (exp(-(ii * z)) - exp(ii * z)) / 2"
lp15@59745
    70
  by (simp add: exp_Euler exp_minus_Euler)
lp15@59745
    71
lp15@59745
    72
lemma cos_exp_eq:  "cos z = (exp(ii * z) + exp(-(ii * z))) / 2"
lp15@59745
    73
  by (simp add: exp_Euler exp_minus_Euler)
lp15@59745
    74
lp15@59745
    75
subsection{*Relationships between real and complex trig functions*}
lp15@59745
    76
lp15@59745
    77
declare sin_of_real [simp] cos_of_real [simp]
lp15@59745
    78
lp15@59745
    79
lemma real_sin_eq [simp]:
lp15@59745
    80
  fixes x::real
lp15@59745
    81
  shows "Re(sin(of_real x)) = sin x"
lp15@59745
    82
  by (simp add: sin_of_real)
lp15@59745
    83
  
lp15@59745
    84
lemma real_cos_eq [simp]:
lp15@59745
    85
  fixes x::real
lp15@59745
    86
  shows "Re(cos(of_real x)) = cos x"
lp15@59745
    87
  by (simp add: cos_of_real)
lp15@59745
    88
lp15@59745
    89
lemma DeMoivre: "(cos z + ii * sin z) ^ n = cos(n * z) + ii * sin(n * z)"
lp15@59745
    90
  apply (simp add: exp_Euler [symmetric])
lp15@59745
    91
  by (metis exp_of_nat_mult mult.left_commute)
lp15@59745
    92
lp15@59745
    93
lemma exp_cnj:
lp15@59745
    94
  fixes z::complex
lp15@59745
    95
  shows "cnj (exp z) = exp (cnj z)"
lp15@59745
    96
proof -
lp15@59745
    97
  have "(\<lambda>n. cnj (z ^ n /\<^sub>R (fact n))) = (\<lambda>n. (cnj z)^n /\<^sub>R (fact n))"
lp15@59745
    98
    by auto
lp15@59745
    99
  also have "... sums (exp (cnj z))"
lp15@59745
   100
    by (rule exp_converges)
lp15@59745
   101
  finally have "(\<lambda>n. cnj (z ^ n /\<^sub>R (fact n))) sums (exp (cnj z))" .
lp15@59745
   102
  moreover have "(\<lambda>n. cnj (z ^ n /\<^sub>R (fact n))) sums (cnj (exp z))"
lp15@59745
   103
    by (metis exp_converges sums_cnj) 
lp15@59745
   104
  ultimately show ?thesis
lp15@59745
   105
    using sums_unique2
lp15@59745
   106
    by blast 
lp15@59745
   107
qed
lp15@59745
   108
lp15@59745
   109
lemma cnj_sin: "cnj(sin z) = sin(cnj z)"
lp15@59745
   110
  by (simp add: sin_exp_eq exp_cnj field_simps)
lp15@59745
   111
lp15@59745
   112
lemma cnj_cos: "cnj(cos z) = cos(cnj z)"
lp15@59745
   113
  by (simp add: cos_exp_eq exp_cnj field_simps)
lp15@59745
   114
lp15@59745
   115
lemma exp_in_Reals [simp]: "z \<in> \<real> \<Longrightarrow> exp z \<in> \<real>"
lp15@59745
   116
  by (metis Reals_cases Reals_of_real exp_of_real)
lp15@59745
   117
lp15@59745
   118
lemma sin_in_Reals [simp]: "z \<in> \<real> \<Longrightarrow> sin z \<in> \<real>"
lp15@59745
   119
  by (metis Reals_cases Reals_of_real sin_of_real)
lp15@59745
   120
lp15@59745
   121
lemma cos_in_Reals [simp]: "z \<in> \<real> \<Longrightarrow> cos z \<in> \<real>"
lp15@59745
   122
  by (metis Reals_cases Reals_of_real cos_of_real)
lp15@59745
   123
lp15@59745
   124
lemma complex_differentiable_at_sin: "sin complex_differentiable at z"
lp15@59745
   125
  using DERIV_sin complex_differentiable_def by blast
lp15@59745
   126
lp15@59745
   127
lemma complex_differentiable_within_sin: "sin complex_differentiable (at z within s)"
lp15@59745
   128
  by (simp add: complex_differentiable_at_sin complex_differentiable_at_within)
lp15@59745
   129
lp15@59745
   130
lemma complex_differentiable_at_cos: "cos complex_differentiable at z"
lp15@59745
   131
  using DERIV_cos complex_differentiable_def by blast
lp15@59745
   132
lp15@59745
   133
lemma complex_differentiable_within_cos: "cos complex_differentiable (at z within s)"
lp15@59745
   134
  by (simp add: complex_differentiable_at_cos complex_differentiable_at_within)
lp15@59745
   135
lp15@59745
   136
lemma holomorphic_on_sin: "sin holomorphic_on s"
lp15@59745
   137
  by (simp add: complex_differentiable_within_sin holomorphic_on_def)
lp15@59745
   138
lp15@59745
   139
lemma holomorphic_on_cos: "cos holomorphic_on s"
lp15@59745
   140
  by (simp add: complex_differentiable_within_cos holomorphic_on_def)
lp15@59745
   141
lp15@59745
   142
subsection{* Get a nice real/imaginary separation in Euler's formula.*}
lp15@59745
   143
lp15@59745
   144
lemma Euler: "exp(z) = of_real(exp(Re z)) * 
lp15@59745
   145
              (of_real(cos(Im z)) + ii * of_real(sin(Im z)))"
lp15@59745
   146
by (cases z) (simp add: exp_add exp_Euler cos_of_real exp_of_real sin_of_real)
lp15@59745
   147
lp15@59745
   148
lemma Re_sin: "Re(sin z) = sin(Re z) * (exp(Im z) + exp(-(Im z))) / 2"
lp15@59745
   149
  by (simp add: sin_exp_eq field_simps Re_divide Im_exp)
lp15@59745
   150
lp15@59745
   151
lemma Im_sin: "Im(sin z) = cos(Re z) * (exp(Im z) - exp(-(Im z))) / 2"
lp15@59745
   152
  by (simp add: sin_exp_eq field_simps Im_divide Re_exp)
lp15@59745
   153
lp15@59745
   154
lemma Re_cos: "Re(cos z) = cos(Re z) * (exp(Im z) + exp(-(Im z))) / 2"
lp15@59745
   155
  by (simp add: cos_exp_eq field_simps Re_divide Re_exp)
lp15@59745
   156
lp15@59745
   157
lemma Im_cos: "Im(cos z) = sin(Re z) * (exp(-(Im z)) - exp(Im z)) / 2"
lp15@59745
   158
  by (simp add: cos_exp_eq field_simps Im_divide Im_exp)
lp15@59746
   159
  
lp15@59746
   160
subsection{*More on the Polar Representation of Complex Numbers*}
lp15@59746
   161
lp15@59746
   162
lemma exp_Complex: "exp(Complex r t) = of_real(exp r) * Complex (cos t) (sin t)"
lp15@59746
   163
  by (simp add: exp_add exp_Euler exp_of_real)
lp15@59746
   164
lp15@59746
   165
lemma exp_eq_1: "exp z = 1 \<longleftrightarrow> Re(z) = 0 \<and> (\<exists>n::int. Im(z) = of_int (2 * n) * pi)"
lp15@59746
   166
apply auto
lp15@59746
   167
apply (metis exp_eq_one_iff norm_exp_eq_Re norm_one)
lp15@59746
   168
apply (metis Re_exp cos_one_2pi_int mult.commute mult.left_neutral norm_exp_eq_Re norm_one one_complex.simps(1) real_of_int_def)
lp15@59746
   169
by (metis Im_exp Re_exp complex_Re_Im_cancel_iff cos_one_2pi_int sin_double Re_complex_of_real complex_Re_numeral exp_zero mult.assoc mult.left_commute mult_eq_0_iff mult_numeral_1 numeral_One of_real_0 real_of_int_def sin_zero_iff_int2)
lp15@59746
   170
lp15@59746
   171
lemma exp_eq: "exp w = exp z \<longleftrightarrow> (\<exists>n::int. w = z + (of_int (2 * n) * pi) * ii)"
lp15@59746
   172
                (is "?lhs = ?rhs")
lp15@59746
   173
proof -
lp15@59746
   174
  have "exp w = exp z \<longleftrightarrow> exp (w-z) = 1"
lp15@59746
   175
    by (simp add: exp_diff)
lp15@59746
   176
  also have "... \<longleftrightarrow> (Re w = Re z \<and> (\<exists>n::int. Im w - Im z = of_int (2 * n) * pi))"
lp15@59746
   177
    by (simp add: exp_eq_1)
lp15@59746
   178
  also have "... \<longleftrightarrow> ?rhs"
lp15@59746
   179
    by (auto simp: algebra_simps intro!: complex_eqI)
lp15@59746
   180
  finally show ?thesis .
lp15@59746
   181
qed
lp15@59746
   182
lp15@59746
   183
lemma exp_complex_eqI: "abs(Im w - Im z) < 2*pi \<Longrightarrow> exp w = exp z \<Longrightarrow> w = z"
lp15@59746
   184
  by (auto simp: exp_eq abs_mult)
lp15@59746
   185
lp15@59746
   186
lemma exp_integer_2pi: 
lp15@59746
   187
  assumes "n \<in> Ints"
lp15@59746
   188
  shows "exp((2 * n * pi) * ii) = 1"
lp15@59746
   189
proof -
lp15@59746
   190
  have "exp((2 * n * pi) * ii) = exp 0"
lp15@59746
   191
    using assms
lp15@59746
   192
    by (simp only: Ints_def exp_eq) auto
lp15@59746
   193
  also have "... = 1"
lp15@59746
   194
    by simp
lp15@59746
   195
  finally show ?thesis .
lp15@59746
   196
qed
lp15@59746
   197
lp15@59746
   198
lemma sin_cos_eq_iff: "sin y = sin x \<and> cos y = cos x \<longleftrightarrow> (\<exists>n::int. y = x + 2 * n * pi)"
lp15@59746
   199
proof -
lp15@59746
   200
  { assume "sin y = sin x" "cos y = cos x"
lp15@59746
   201
    then have "cos (y-x) = 1"
lp15@59746
   202
      using cos_add [of y "-x"] by simp
lp15@59746
   203
    then have "\<exists>n::int. y-x = real n * 2 * pi"
lp15@59746
   204
      using cos_one_2pi_int by blast }
lp15@59746
   205
  then show ?thesis
lp15@59746
   206
  apply (auto simp: sin_add cos_add)
lp15@59746
   207
  apply (metis add.commute diff_add_cancel mult.commute)
lp15@59746
   208
  done
lp15@59746
   209
qed
lp15@59746
   210
lp15@59746
   211
lemma exp_i_ne_1: 
lp15@59746
   212
  assumes "0 < x" "x < 2*pi"
lp15@59746
   213
  shows "exp(\<i> * of_real x) \<noteq> 1"
lp15@59746
   214
proof 
lp15@59746
   215
  assume "exp (\<i> * of_real x) = 1"
lp15@59746
   216
  then have "exp (\<i> * of_real x) = exp 0"
lp15@59746
   217
    by simp
lp15@59746
   218
  then obtain n where "\<i> * of_real x = (of_int (2 * n) * pi) * \<i>"
lp15@59746
   219
    by (simp only: Ints_def exp_eq) auto
lp15@59746
   220
  then have  "of_real x = (of_int (2 * n) * pi)"
lp15@59746
   221
    by (metis complex_i_not_zero mult.commute mult_cancel_left of_real_eq_iff real_scaleR_def scaleR_conv_of_real)
lp15@59746
   222
  then have  "x = (of_int (2 * n) * pi)"
lp15@59746
   223
    by simp
lp15@59746
   224
  then show False using assms
lp15@59746
   225
    by (cases n) (auto simp: zero_less_mult_iff mult_less_0_iff)
lp15@59746
   226
qed
lp15@59746
   227
lp15@59746
   228
lemma sin_eq_0: 
lp15@59746
   229
  fixes z::complex
lp15@59746
   230
  shows "sin z = 0 \<longleftrightarrow> (\<exists>n::int. z = of_real(n * pi))"
lp15@59746
   231
  by (simp add: sin_exp_eq exp_eq of_real_numeral)
lp15@59746
   232
lp15@59746
   233
lemma cos_eq_0: 
lp15@59746
   234
  fixes z::complex
lp15@59746
   235
  shows "cos z = 0 \<longleftrightarrow> (\<exists>n::int. z = of_real(n * pi) + of_real pi/2)"
lp15@59746
   236
  using sin_eq_0 [of "z - of_real pi/2"]
lp15@59746
   237
  by (simp add: sin_diff algebra_simps)
lp15@59746
   238
lp15@59746
   239
lemma cos_eq_1: 
lp15@59746
   240
  fixes z::complex
lp15@59746
   241
  shows "cos z = 1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi))"
lp15@59746
   242
proof -
lp15@59746
   243
  have "cos z = cos (2*(z/2))"
lp15@59746
   244
    by simp
lp15@59746
   245
  also have "... = 1 - 2 * sin (z/2) ^ 2"
lp15@59746
   246
    by (simp only: cos_double_sin)
lp15@59746
   247
  finally have [simp]: "cos z = 1 \<longleftrightarrow> sin (z/2) = 0"
lp15@59746
   248
    by simp
lp15@59746
   249
  show ?thesis
lp15@59746
   250
    by (auto simp: sin_eq_0 of_real_numeral)
lp15@59746
   251
qed  
lp15@59746
   252
lp15@59746
   253
lemma csin_eq_1:
lp15@59746
   254
  fixes z::complex
lp15@59746
   255
  shows "sin z = 1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   256
  using cos_eq_1 [of "z - of_real pi/2"]
lp15@59746
   257
  by (simp add: cos_diff algebra_simps)
lp15@59746
   258
lp15@59746
   259
lemma csin_eq_minus1:
lp15@59746
   260
  fixes z::complex
lp15@59746
   261
  shows "sin z = -1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi) + 3/2*pi)"
lp15@59746
   262
        (is "_ = ?rhs")
lp15@59746
   263
proof -
lp15@59746
   264
  have "sin z = -1 \<longleftrightarrow> sin (-z) = 1"
lp15@59746
   265
    by (simp add: equation_minus_iff)
lp15@59746
   266
  also have "...  \<longleftrightarrow> (\<exists>n::int. -z = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   267
    by (simp only: csin_eq_1)
lp15@59746
   268
  also have "...  \<longleftrightarrow> (\<exists>n::int. z = - of_real(2 * n * pi) - of_real pi/2)"
lp15@59746
   269
    apply (rule iff_exI)
lp15@59746
   270
    by (metis (no_types)  is_num_normalize(8) minus_minus of_real_def real_vector.scale_minus_left uminus_add_conv_diff)
lp15@59746
   271
  also have "... = ?rhs"
lp15@59746
   272
    apply (auto simp: of_real_numeral)
lp15@59746
   273
    apply (rule_tac [2] x="-(x+1)" in exI)
lp15@59746
   274
    apply (rule_tac x="-(x+1)" in exI)
lp15@59746
   275
    apply (simp_all add: algebra_simps)
lp15@59746
   276
    done
lp15@59746
   277
  finally show ?thesis .
lp15@59746
   278
qed  
lp15@59746
   279
lp15@59746
   280
lemma ccos_eq_minus1: 
lp15@59746
   281
  fixes z::complex
lp15@59746
   282
  shows "cos z = -1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi) + pi)"
lp15@59746
   283
  using csin_eq_1 [of "z - of_real pi/2"]
lp15@59746
   284
  apply (simp add: sin_diff)
lp15@59746
   285
  apply (simp add: algebra_simps of_real_numeral equation_minus_iff)
lp15@59746
   286
  done       
lp15@59746
   287
lp15@59746
   288
lemma sin_eq_1: "sin x = 1 \<longleftrightarrow> (\<exists>n::int. x = (2 * n + 1 / 2) * pi)"
lp15@59746
   289
                (is "_ = ?rhs")
lp15@59746
   290
proof -
lp15@59746
   291
  have "sin x = 1 \<longleftrightarrow> sin (complex_of_real x) = 1"
lp15@59746
   292
    by (metis of_real_1 one_complex.simps(1) real_sin_eq sin_of_real)
lp15@59746
   293
  also have "...  \<longleftrightarrow> (\<exists>n::int. complex_of_real x = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   294
    by (simp only: csin_eq_1)
lp15@59746
   295
  also have "...  \<longleftrightarrow> (\<exists>n::int. x = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   296
    apply (rule iff_exI)
lp15@59746
   297
    apply (auto simp: algebra_simps of_real_numeral)
lp15@59746
   298
    apply (rule injD [OF inj_of_real [where 'a = complex]])
lp15@59746
   299
    apply (auto simp: of_real_numeral)
lp15@59746
   300
    done
lp15@59746
   301
  also have "... = ?rhs"
lp15@59746
   302
    by (auto simp: algebra_simps)
lp15@59746
   303
  finally show ?thesis .
lp15@59746
   304
qed  
lp15@59746
   305
lp15@59746
   306
lemma sin_eq_minus1: "sin x = -1 \<longleftrightarrow> (\<exists>n::int. x = (2*n + 3/2) * pi)"  (is "_ = ?rhs")
lp15@59746
   307
proof -
lp15@59746
   308
  have "sin x = -1 \<longleftrightarrow> sin (complex_of_real x) = -1"
lp15@59746
   309
    by (metis Re_complex_of_real of_real_def scaleR_minus1_left sin_of_real)
lp15@59746
   310
  also have "...  \<longleftrightarrow> (\<exists>n::int. complex_of_real x = of_real(2 * n * pi) + 3/2*pi)"
lp15@59746
   311
    by (simp only: csin_eq_minus1)
lp15@59746
   312
  also have "...  \<longleftrightarrow> (\<exists>n::int. x = of_real(2 * n * pi) + 3/2*pi)"
lp15@59746
   313
    apply (rule iff_exI)
lp15@59746
   314
    apply (auto simp: algebra_simps)
lp15@59746
   315
    apply (rule injD [OF inj_of_real [where 'a = complex]], auto)
lp15@59746
   316
    done
lp15@59746
   317
  also have "... = ?rhs"
lp15@59746
   318
    by (auto simp: algebra_simps)
lp15@59746
   319
  finally show ?thesis .
lp15@59746
   320
qed  
lp15@59746
   321
lp15@59746
   322
lemma cos_eq_minus1: "cos x = -1 \<longleftrightarrow> (\<exists>n::int. x = (2*n + 1) * pi)"
lp15@59746
   323
                      (is "_ = ?rhs")
lp15@59746
   324
proof -
lp15@59746
   325
  have "cos x = -1 \<longleftrightarrow> cos (complex_of_real x) = -1"
lp15@59746
   326
    by (metis Re_complex_of_real of_real_def scaleR_minus1_left cos_of_real)
lp15@59746
   327
  also have "...  \<longleftrightarrow> (\<exists>n::int. complex_of_real x = of_real(2 * n * pi) + pi)"
lp15@59746
   328
    by (simp only: ccos_eq_minus1)
lp15@59746
   329
  also have "...  \<longleftrightarrow> (\<exists>n::int. x = of_real(2 * n * pi) + pi)"
lp15@59746
   330
    apply (rule iff_exI)
lp15@59746
   331
    apply (auto simp: algebra_simps)
lp15@59746
   332
    apply (rule injD [OF inj_of_real [where 'a = complex]], auto)
lp15@59746
   333
    done
lp15@59746
   334
  also have "... = ?rhs"
lp15@59746
   335
    by (auto simp: algebra_simps)
lp15@59746
   336
  finally show ?thesis .
lp15@59746
   337
qed  
lp15@59746
   338
lp15@59746
   339
lemma dist_exp_ii_1: "norm(exp(ii * of_real t) - 1) = 2 * abs(sin(t / 2))"
lp15@59746
   340
  apply (simp add: exp_Euler cmod_def power2_diff algebra_simps)
lp15@59746
   341
  using cos_double_sin [of "t/2"]
lp15@59746
   342
  apply (simp add: real_sqrt_mult)
lp15@59746
   343
  done
lp15@59746
   344
lp15@59746
   345
lemma sinh_complex:
lp15@59746
   346
  fixes z :: complex
lp15@59746
   347
  shows "(exp z - inverse (exp z)) / 2 = -ii * sin(ii * z)"
lp15@59746
   348
  by (simp add: sin_exp_eq divide_simps exp_minus of_real_numeral)
lp15@59746
   349
lp15@59746
   350
lemma sin_ii_times:
lp15@59746
   351
  fixes z :: complex
lp15@59746
   352
  shows "sin(ii * z) = ii * ((exp z - inverse (exp z)) / 2)"
lp15@59746
   353
  using sinh_complex by auto
lp15@59746
   354
lp15@59746
   355
lemma sinh_real:
lp15@59746
   356
  fixes x :: real
lp15@59746
   357
  shows "of_real((exp x - inverse (exp x)) / 2) = -ii * sin(ii * of_real x)"
lp15@59746
   358
  by (simp add: exp_of_real sin_ii_times of_real_numeral)
lp15@59746
   359
lp15@59746
   360
lemma cosh_complex:
lp15@59746
   361
  fixes z :: complex
lp15@59746
   362
  shows "(exp z + inverse (exp z)) / 2 = cos(ii * z)"
lp15@59746
   363
  by (simp add: cos_exp_eq divide_simps exp_minus of_real_numeral exp_of_real)
lp15@59746
   364
lp15@59746
   365
lemma cosh_real:
lp15@59746
   366
  fixes x :: real
lp15@59746
   367
  shows "of_real((exp x + inverse (exp x)) / 2) = cos(ii * of_real x)"
lp15@59746
   368
  by (simp add: cos_exp_eq divide_simps exp_minus of_real_numeral exp_of_real)
lp15@59746
   369
lp15@59746
   370
lemmas cos_ii_times = cosh_complex [symmetric]
lp15@59746
   371
lp15@59746
   372
lemma norm_cos_squared: 
lp15@59746
   373
    "norm(cos z) ^ 2 = cos(Re z) ^ 2 + (exp(Im z) - inverse(exp(Im z))) ^ 2 / 4"
lp15@59746
   374
  apply (cases z)
lp15@59746
   375
  apply (simp add: cos_add cmod_power2 cos_of_real sin_of_real)
lp15@59746
   376
  apply (simp add: cos_exp_eq sin_exp_eq exp_minus exp_of_real Re_divide Im_divide)
lp15@59746
   377
  apply (simp only: left_diff_distrib [symmetric] power_mult_distrib)
lp15@59746
   378
  apply (simp add: sin_squared_eq)
lp15@59746
   379
  apply (simp add: power2_eq_square algebra_simps divide_simps)
lp15@59746
   380
  done
lp15@59746
   381
lp15@59746
   382
lemma norm_sin_squared:
lp15@59746
   383
    "norm(sin z) ^ 2 = (exp(2 * Im z) + inverse(exp(2 * Im z)) - 2 * cos(2 * Re z)) / 4"
lp15@59746
   384
  apply (cases z)
lp15@59746
   385
  apply (simp add: sin_add cmod_power2 cos_of_real sin_of_real cos_double_cos exp_double)
lp15@59746
   386
  apply (simp add: cos_exp_eq sin_exp_eq exp_minus exp_of_real Re_divide Im_divide)
lp15@59746
   387
  apply (simp only: left_diff_distrib [symmetric] power_mult_distrib)
lp15@59746
   388
  apply (simp add: cos_squared_eq)
lp15@59746
   389
  apply (simp add: power2_eq_square algebra_simps divide_simps)
lp15@59746
   390
  done 
lp15@59746
   391
lp15@59746
   392
lemma exp_uminus_Im: "exp (- Im z) \<le> exp (cmod z)"
lp15@59746
   393
  using abs_Im_le_cmod linear order_trans by fastforce
lp15@59746
   394
lp15@59746
   395
lemma norm_cos_le: 
lp15@59746
   396
  fixes z::complex
lp15@59746
   397
  shows "norm(cos z) \<le> exp(norm z)"
lp15@59746
   398
proof -
lp15@59746
   399
  have "Im z \<le> cmod z"
lp15@59746
   400
    using abs_Im_le_cmod abs_le_D1 by auto
lp15@59746
   401
  with exp_uminus_Im show ?thesis
lp15@59746
   402
    apply (simp add: cos_exp_eq norm_divide)
lp15@59746
   403
    apply (rule order_trans [OF norm_triangle_ineq], simp)
lp15@59746
   404
    apply (metis add_mono exp_le_cancel_iff mult_2_right)
lp15@59746
   405
    done
lp15@59746
   406
qed
lp15@59746
   407
lp15@59746
   408
lemma norm_cos_plus1_le: 
lp15@59746
   409
  fixes z::complex
lp15@59746
   410
  shows "norm(1 + cos z) \<le> 2 * exp(norm z)"
lp15@59746
   411
proof -
lp15@59746
   412
  have mono: "\<And>u w z::real. (1 \<le> w | 1 \<le> z) \<Longrightarrow> (w \<le> u & z \<le> u) \<Longrightarrow> 2 + w + z \<le> 4 * u"
lp15@59746
   413
      by arith
lp15@59746
   414
  have *: "Im z \<le> cmod z"
lp15@59746
   415
    using abs_Im_le_cmod abs_le_D1 by auto
lp15@59746
   416
  have triangle3: "\<And>x y z. norm(x + y + z) \<le> norm(x) + norm(y) + norm(z)"
lp15@59746
   417
    by (simp add: norm_add_rule_thm)
lp15@59746
   418
  have "norm(1 + cos z) = cmod (1 + (exp (\<i> * z) + exp (- (\<i> * z))) / 2)"
lp15@59746
   419
    by (simp add: cos_exp_eq)
lp15@59746
   420
  also have "... = cmod ((2 + exp (\<i> * z) + exp (- (\<i> * z))) / 2)"
lp15@59746
   421
    by (simp add: field_simps)
lp15@59746
   422
  also have "... = cmod (2 + exp (\<i> * z) + exp (- (\<i> * z))) / 2"
lp15@59746
   423
    by (simp add: norm_divide)
lp15@59746
   424
  finally show ?thesis
lp15@59746
   425
    apply (rule ssubst, simp)
lp15@59746
   426
    apply (rule order_trans [OF triangle3], simp)
lp15@59746
   427
    using exp_uminus_Im *
lp15@59746
   428
    apply (auto intro: mono)
lp15@59746
   429
    done
lp15@59746
   430
qed
lp15@59746
   431
lp15@59746
   432
subsection{* Taylor series for complex exponential, sine and cosine.*}
lp15@59746
   433
lp15@59746
   434
context 
lp15@59746
   435
begin
lp15@59746
   436
lp15@59746
   437
declare power_Suc [simp del]
lp15@59746
   438
lp15@59746
   439
lemma Taylor_exp: 
lp15@59746
   440
  "norm(exp z - (\<Sum>k\<le>n. z ^ k / (fact k))) \<le> exp\<bar>Re z\<bar> * (norm z) ^ (Suc n) / (fact n)"
lp15@59746
   441
proof (rule complex_taylor [of _ n "\<lambda>k. exp" "exp\<bar>Re z\<bar>" 0 z, simplified])
lp15@59746
   442
  show "convex (closed_segment 0 z)"
lp15@59746
   443
    by (rule convex_segment [of 0 z])
lp15@59746
   444
next
lp15@59746
   445
  fix k x
lp15@59746
   446
  assume "x \<in> closed_segment 0 z" "k \<le> n"
lp15@59746
   447
  show "(exp has_field_derivative exp x) (at x within closed_segment 0 z)"
lp15@59746
   448
    using DERIV_exp DERIV_subset by blast
lp15@59746
   449
next
lp15@59746
   450
  fix x
lp15@59746
   451
  assume "x \<in> closed_segment 0 z"
lp15@59746
   452
  then show "Re x \<le> \<bar>Re z\<bar>"
lp15@59746
   453
    apply (auto simp: closed_segment_def scaleR_conv_of_real)
lp15@59746
   454
    by (meson abs_ge_self abs_ge_zero linear mult_left_le_one_le mult_nonneg_nonpos order_trans)
lp15@59746
   455
next
lp15@59746
   456
  show "0 \<in> closed_segment 0 z"
lp15@59746
   457
    by (auto simp: closed_segment_def)
lp15@59746
   458
next
lp15@59746
   459
  show "z \<in> closed_segment 0 z"
lp15@59746
   460
    apply (simp add: closed_segment_def scaleR_conv_of_real)
lp15@59746
   461
    using of_real_1 zero_le_one by blast
lp15@59746
   462
qed 
lp15@59746
   463
lp15@59746
   464
lemma 
lp15@59746
   465
  assumes "0 \<le> u" "u \<le> 1"
lp15@59746
   466
  shows cmod_sin_le_exp: "cmod (sin (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>" 
lp15@59746
   467
    and cmod_cos_le_exp: "cmod (cos (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>"
lp15@59746
   468
proof -
lp15@59746
   469
  have mono: "\<And>u w z::real. w \<le> u \<Longrightarrow> z \<le> u \<Longrightarrow> w + z \<le> u*2"
lp15@59746
   470
    by arith
lp15@59746
   471
  show "cmod (sin (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>" using assms
lp15@59746
   472
    apply (auto simp: scaleR_conv_of_real norm_mult norm_power sin_exp_eq norm_divide)
lp15@59746
   473
    apply (rule order_trans [OF norm_triangle_ineq4])
lp15@59746
   474
    apply (rule mono)
lp15@59746
   475
    apply (auto simp: abs_if mult_left_le_one_le)
lp15@59746
   476
    apply (meson mult_nonneg_nonneg neg_le_0_iff_le not_le order_trans)
lp15@59746
   477
    apply (meson less_eq_real_def mult_nonneg_nonpos neg_0_le_iff_le order_trans)
lp15@59746
   478
    done
lp15@59746
   479
  show "cmod (cos (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>" using assms
lp15@59746
   480
    apply (auto simp: scaleR_conv_of_real norm_mult norm_power cos_exp_eq norm_divide)
lp15@59746
   481
    apply (rule order_trans [OF norm_triangle_ineq])
lp15@59746
   482
    apply (rule mono)
lp15@59746
   483
    apply (auto simp: abs_if mult_left_le_one_le)
lp15@59746
   484
    apply (meson mult_nonneg_nonneg neg_le_0_iff_le not_le order_trans)
lp15@59746
   485
    apply (meson less_eq_real_def mult_nonneg_nonpos neg_0_le_iff_le order_trans)
lp15@59746
   486
    done
lp15@59746
   487
qed
lp15@59746
   488
    
lp15@59746
   489
lemma Taylor_sin: 
lp15@59746
   490
  "norm(sin z - (\<Sum>k\<le>n. complex_of_real (sin_coeff k) * z ^ k)) 
lp15@59746
   491
   \<le> exp\<bar>Im z\<bar> * (norm z) ^ (Suc n) / (fact n)"
lp15@59746
   492
proof -
lp15@59746
   493
  have mono: "\<And>u w z::real. w \<le> u \<Longrightarrow> z \<le> u \<Longrightarrow> w + z \<le> u*2"
lp15@59746
   494
      by arith
lp15@59746
   495
  have *: "cmod (sin z -
lp15@59746
   496
                 (\<Sum>i\<le>n. (-1) ^ (i div 2) * (if even i then sin 0 else cos 0) * z ^ i / (fact i)))
lp15@59746
   497
           \<le> exp \<bar>Im z\<bar> * cmod z ^ Suc n / (fact n)" 
lp15@59746
   498
  proof (rule complex_taylor [of "closed_segment 0 z" n "\<lambda>k x. (-1)^(k div 2) * (if even k then sin x else cos x)" "exp\<bar>Im z\<bar>" 0 z,
lp15@59746
   499
simplified])
lp15@59746
   500
  show "convex (closed_segment 0 z)"
lp15@59746
   501
    by (rule convex_segment [of 0 z])
lp15@59746
   502
  next
lp15@59746
   503
    fix k x
lp15@59746
   504
    show "((\<lambda>x. (- 1) ^ (k div 2) * (if even k then sin x else cos x)) has_field_derivative
lp15@59746
   505
            (- 1) ^ (Suc k div 2) * (if odd k then sin x else cos x))
lp15@59746
   506
            (at x within closed_segment 0 z)"
lp15@59746
   507
      apply (auto simp: power_Suc)
lp15@59746
   508
      apply (intro derivative_eq_intros | simp)+
lp15@59746
   509
      done
lp15@59746
   510
  next
lp15@59746
   511
    fix x
lp15@59746
   512
    assume "x \<in> closed_segment 0 z"
lp15@59746
   513
    then show "cmod ((- 1) ^ (Suc n div 2) * (if odd n then sin x else cos x)) \<le> exp \<bar>Im z\<bar>"
lp15@59746
   514
      by (auto simp: closed_segment_def norm_mult norm_power cmod_sin_le_exp cmod_cos_le_exp)
lp15@59746
   515
  next
lp15@59746
   516
    show "0 \<in> closed_segment 0 z"
lp15@59746
   517
      by (auto simp: closed_segment_def)
lp15@59746
   518
  next
lp15@59746
   519
    show "z \<in> closed_segment 0 z"
lp15@59746
   520
      apply (simp add: closed_segment_def scaleR_conv_of_real)
lp15@59746
   521
      using of_real_1 zero_le_one by blast
lp15@59746
   522
  qed 
lp15@59746
   523
  have **: "\<And>k. complex_of_real (sin_coeff k) * z ^ k
lp15@59746
   524
            = (-1)^(k div 2) * (if even k then sin 0 else cos 0) * z^k / of_nat (fact k)"
lp15@59746
   525
    by (auto simp: sin_coeff_def elim!: oddE)
lp15@59746
   526
  show ?thesis
lp15@59746
   527
    apply (rule order_trans [OF _ *])
lp15@59746
   528
    apply (simp add: **)
lp15@59746
   529
    done
lp15@59746
   530
qed
lp15@59746
   531
lp15@59746
   532
lemma Taylor_cos: 
lp15@59746
   533
  "norm(cos z - (\<Sum>k\<le>n. complex_of_real (cos_coeff k) * z ^ k)) 
lp15@59746
   534
   \<le> exp\<bar>Im z\<bar> * (norm z) ^ Suc n / (fact n)"
lp15@59746
   535
proof -
lp15@59746
   536
  have mono: "\<And>u w z::real. w \<le> u \<Longrightarrow> z \<le> u \<Longrightarrow> w + z \<le> u*2"
lp15@59746
   537
      by arith
lp15@59746
   538
  have *: "cmod (cos z -
lp15@59746
   539
                 (\<Sum>i\<le>n. (-1) ^ (Suc i div 2) * (if even i then cos 0 else sin 0) * z ^ i / (fact i)))
lp15@59746
   540
           \<le> exp \<bar>Im z\<bar> * cmod z ^ Suc n / (fact n)" 
lp15@59746
   541
  proof (rule complex_taylor [of "closed_segment 0 z" n "\<lambda>k x. (-1)^(Suc k div 2) * (if even k then cos x else sin x)" "exp\<bar>Im z\<bar>" 0 z,
lp15@59746
   542
simplified])
lp15@59746
   543
  show "convex (closed_segment 0 z)"
lp15@59746
   544
    by (rule convex_segment [of 0 z])
lp15@59746
   545
  next
lp15@59746
   546
    fix k x
lp15@59746
   547
    assume "x \<in> closed_segment 0 z" "k \<le> n"
lp15@59746
   548
    show "((\<lambda>x. (- 1) ^ (Suc k div 2) * (if even k then cos x else sin x)) has_field_derivative
lp15@59746
   549
            (- 1) ^ Suc (k div 2) * (if odd k then cos x else sin x))
lp15@59746
   550
             (at x within closed_segment 0 z)"
lp15@59746
   551
      apply (auto simp: power_Suc)
lp15@59746
   552
      apply (intro derivative_eq_intros | simp)+
lp15@59746
   553
      done
lp15@59746
   554
  next
lp15@59746
   555
    fix x
lp15@59746
   556
    assume "x \<in> closed_segment 0 z"
lp15@59746
   557
    then show "cmod ((- 1) ^ Suc (n div 2) * (if odd n then cos x else sin x)) \<le> exp \<bar>Im z\<bar>"
lp15@59746
   558
      by (auto simp: closed_segment_def norm_mult norm_power cmod_sin_le_exp cmod_cos_le_exp)
lp15@59746
   559
  next
lp15@59746
   560
    show "0 \<in> closed_segment 0 z"
lp15@59746
   561
      by (auto simp: closed_segment_def)
lp15@59746
   562
  next
lp15@59746
   563
    show "z \<in> closed_segment 0 z"
lp15@59746
   564
      apply (simp add: closed_segment_def scaleR_conv_of_real)
lp15@59746
   565
      using of_real_1 zero_le_one by blast
lp15@59746
   566
  qed 
lp15@59746
   567
  have **: "\<And>k. complex_of_real (cos_coeff k) * z ^ k
lp15@59746
   568
            = (-1)^(Suc k div 2) * (if even k then cos 0 else sin 0) * z^k / of_nat (fact k)"
lp15@59746
   569
    by (auto simp: cos_coeff_def elim!: evenE)
lp15@59746
   570
  show ?thesis
lp15@59746
   571
    apply (rule order_trans [OF _ *])
lp15@59746
   572
    apply (simp add: **)
lp15@59746
   573
    done
lp15@59746
   574
qed
lp15@59746
   575
lp15@59746
   576
end (* of context *)
lp15@59746
   577
lp15@59751
   578
text{*32-bit Approximation to e*}
lp15@59751
   579
lemma e_approx_32: "abs(exp(1) - 5837465777 / 2147483648) \<le> (inverse(2 ^ 32)::real)"
lp15@59751
   580
  using Taylor_exp [of 1 14] exp_le
lp15@59751
   581
  apply (simp add: setsum_left_distrib in_Reals_norm Re_exp atMost_nat_numeral fact_numeral)
lp15@59751
   582
  apply (simp only: pos_le_divide_eq [symmetric], linarith)
lp15@59751
   583
  done
lp15@59751
   584
lp15@59746
   585
subsection{*The argument of a complex number*}
lp15@59746
   586
lp15@59746
   587
definition Arg :: "complex \<Rightarrow> real" where
lp15@59746
   588
 "Arg z \<equiv> if z = 0 then 0
lp15@59746
   589
           else THE t. 0 \<le> t \<and> t < 2*pi \<and>
lp15@59746
   590
                    z = of_real(norm z) * exp(ii * of_real t)"
lp15@59746
   591
lp15@59746
   592
lemma Arg_0 [simp]: "Arg(0) = 0"
lp15@59746
   593
  by (simp add: Arg_def)
lp15@59746
   594
lp15@59746
   595
lemma Arg_unique_lemma:
lp15@59746
   596
  assumes z:  "z = of_real(norm z) * exp(ii * of_real t)"
lp15@59746
   597
      and z': "z = of_real(norm z) * exp(ii * of_real t')"
lp15@59746
   598
      and t:  "0 \<le> t"  "t < 2*pi"
lp15@59746
   599
      and t': "0 \<le> t'" "t' < 2*pi"
lp15@59746
   600
      and nz: "z \<noteq> 0"
lp15@59746
   601
  shows "t' = t"
lp15@59746
   602
proof -
lp15@59746
   603
  have [dest]: "\<And>x y z::real. x\<ge>0 \<Longrightarrow> x+y < z \<Longrightarrow> y<z"
lp15@59746
   604
    by arith
lp15@59746
   605
  have "of_real (cmod z) * exp (\<i> * of_real t') = of_real (cmod z) * exp (\<i> * of_real t)"
lp15@59746
   606
    by (metis z z')
lp15@59746
   607
  then have "exp (\<i> * of_real t') = exp (\<i> * of_real t)"
lp15@59746
   608
    by (metis nz mult_left_cancel mult_zero_left z)
lp15@59746
   609
  then have "sin t' = sin t \<and> cos t' = cos t"
lp15@59746
   610
    apply (simp add: exp_Euler sin_of_real cos_of_real)
lp15@59746
   611
    by (metis Complex_eq complex.sel)
lp15@59746
   612
  then obtain n::int where n: "t' = t + 2 * real n * pi"
lp15@59746
   613
    by (auto simp: sin_cos_eq_iff)
lp15@59746
   614
  then have "n=0"
lp15@59746
   615
    apply (rule_tac z=n in int_cases)
lp15@59746
   616
    using t t'
lp15@59746
   617
    apply (auto simp: mult_less_0_iff algebra_simps)
lp15@59746
   618
    done
lp15@59746
   619
  then show "t' = t"
lp15@59746
   620
      by (simp add: n)
lp15@59746
   621
qed
lp15@59746
   622
lp15@59746
   623
lemma Arg: "0 \<le> Arg z & Arg z < 2*pi & z = of_real(norm z) * exp(ii * of_real(Arg z))"
lp15@59746
   624
proof (cases "z=0")
lp15@59746
   625
  case True then show ?thesis
lp15@59746
   626
    by (simp add: Arg_def)
lp15@59746
   627
next
lp15@59746
   628
  case False
lp15@59746
   629
  obtain t where t: "0 \<le> t" "t < 2*pi"
lp15@59746
   630
             and ReIm: "Re z / cmod z = cos t" "Im z / cmod z = sin t"
lp15@59746
   631
    using sincos_total_2pi [OF complex_unit_circle [OF False]]
lp15@59746
   632
    by blast
lp15@59746
   633
  have z: "z = of_real(norm z) * exp(ii * of_real t)"
lp15@59746
   634
    apply (rule complex_eqI)
lp15@59746
   635
    using t False ReIm
lp15@59746
   636
    apply (auto simp: exp_Euler sin_of_real cos_of_real divide_simps)
lp15@59746
   637
    done
lp15@59746
   638
  show ?thesis
lp15@59746
   639
    apply (simp add: Arg_def False)
lp15@59746
   640
    apply (rule theI [where a=t])
lp15@59746
   641
    using t z False
lp15@59746
   642
    apply (auto intro: Arg_unique_lemma)
lp15@59746
   643
    done
lp15@59746
   644
qed
lp15@59746
   645
lp15@59746
   646
lp15@59746
   647
corollary
lp15@59746
   648
  shows Arg_ge_0: "0 \<le> Arg z"
lp15@59746
   649
    and Arg_lt_2pi: "Arg z < 2*pi"
lp15@59746
   650
    and Arg_eq: "z = of_real(norm z) * exp(ii * of_real(Arg z))"
lp15@59746
   651
  using Arg by auto
lp15@59746
   652
lp15@59746
   653
lemma complex_norm_eq_1_exp: "norm z = 1 \<longleftrightarrow> (\<exists>t. z = exp(ii * of_real t))"
lp15@59746
   654
  using Arg [of z] by auto
lp15@59746
   655
lp15@59746
   656
lemma Arg_unique: "\<lbrakk>of_real r * exp(ii * of_real a) = z; 0 < r; 0 \<le> a; a < 2*pi\<rbrakk> \<Longrightarrow> Arg z = a"
lp15@59746
   657
  apply (rule Arg_unique_lemma [OF _ Arg_eq])
lp15@59746
   658
  using Arg [of z]
lp15@59746
   659
  apply (auto simp: norm_mult)
lp15@59746
   660
  done
lp15@59746
   661
lp15@59746
   662
lemma Arg_minus: "z \<noteq> 0 \<Longrightarrow> Arg (-z) = (if Arg z < pi then Arg z + pi else Arg z - pi)"
lp15@59746
   663
  apply (rule Arg_unique [of "norm z"])
lp15@59746
   664
  apply (rule complex_eqI)
lp15@59746
   665
  using Arg_ge_0 [of z] Arg_eq [of z] Arg_lt_2pi [of z] Arg_eq [of z]
lp15@59746
   666
  apply auto
lp15@59746
   667
  apply (auto simp: Re_exp Im_exp cos_diff sin_diff cis_conv_exp [symmetric])
lp15@59746
   668
  apply (metis Re_rcis Im_rcis rcis_def)+
lp15@59746
   669
  done
lp15@59746
   670
lp15@59746
   671
lemma Arg_times_of_real [simp]: "0 < r \<Longrightarrow> Arg (of_real r * z) = Arg z"
lp15@59746
   672
  apply (cases "z=0", simp)
lp15@59746
   673
  apply (rule Arg_unique [of "r * norm z"])
lp15@59746
   674
  using Arg
lp15@59746
   675
  apply auto
lp15@59746
   676
  done
lp15@59746
   677
lp15@59746
   678
lemma Arg_times_of_real2 [simp]: "0 < r \<Longrightarrow> Arg (z * of_real r) = Arg z"
lp15@59746
   679
  by (metis Arg_times_of_real mult.commute)
lp15@59746
   680
lp15@59746
   681
lemma Arg_divide_of_real [simp]: "0 < r \<Longrightarrow> Arg (z / of_real r) = Arg z"
lp15@59746
   682
  by (metis Arg_times_of_real2 less_numeral_extra(3) nonzero_eq_divide_eq of_real_eq_0_iff)
lp15@59746
   683
lp15@59746
   684
lemma Arg_le_pi: "Arg z \<le> pi \<longleftrightarrow> 0 \<le> Im z"
lp15@59746
   685
proof (cases "z=0")
lp15@59746
   686
  case True then show ?thesis
lp15@59746
   687
    by simp
lp15@59746
   688
next
lp15@59746
   689
  case False
lp15@59746
   690
  have "0 \<le> Im z \<longleftrightarrow> 0 \<le> Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   691
    by (metis Arg_eq)
lp15@59746
   692
  also have "... = (0 \<le> Im (exp (\<i> * complex_of_real (Arg z))))"
lp15@59746
   693
    using False
lp15@59746
   694
    by (simp add: zero_le_mult_iff)
lp15@59746
   695
  also have "... \<longleftrightarrow> Arg z \<le> pi"
lp15@59746
   696
    by (simp add: Im_exp) (metis Arg_ge_0 Arg_lt_2pi sin_lt_zero sin_ge_zero not_le)
lp15@59746
   697
  finally show ?thesis
lp15@59746
   698
    by blast
lp15@59746
   699
qed
lp15@59746
   700
lp15@59746
   701
lemma Arg_lt_pi: "0 < Arg z \<and> Arg z < pi \<longleftrightarrow> 0 < Im z"
lp15@59746
   702
proof (cases "z=0")
lp15@59746
   703
  case True then show ?thesis
lp15@59746
   704
    by simp
lp15@59746
   705
next
lp15@59746
   706
  case False
lp15@59746
   707
  have "0 < Im z \<longleftrightarrow> 0 < Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   708
    by (metis Arg_eq)
lp15@59746
   709
  also have "... = (0 < Im (exp (\<i> * complex_of_real (Arg z))))"
lp15@59746
   710
    using False
lp15@59746
   711
    by (simp add: zero_less_mult_iff)
lp15@59746
   712
  also have "... \<longleftrightarrow> 0 < Arg z \<and> Arg z < pi"
lp15@59746
   713
    using Arg_ge_0  Arg_lt_2pi sin_le_zero sin_gt_zero
lp15@59746
   714
    apply (auto simp: Im_exp)
lp15@59746
   715
    using le_less apply fastforce
lp15@59746
   716
    using not_le by blast
lp15@59746
   717
  finally show ?thesis
lp15@59746
   718
    by blast
lp15@59746
   719
qed
lp15@59746
   720
lp15@59746
   721
lemma Arg_eq_0: "Arg z = 0 \<longleftrightarrow> z \<in> Reals \<and> 0 \<le> Re z"
lp15@59746
   722
proof (cases "z=0")
lp15@59746
   723
  case True then show ?thesis
lp15@59746
   724
    by simp
lp15@59746
   725
next
lp15@59746
   726
  case False
lp15@59746
   727
  have "z \<in> Reals \<and> 0 \<le> Re z \<longleftrightarrow> z \<in> Reals \<and> 0 \<le> Re (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   728
    by (metis Arg_eq)
lp15@59746
   729
  also have "... \<longleftrightarrow> z \<in> Reals \<and> 0 \<le> Re (exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   730
    using False
lp15@59746
   731
    by (simp add: zero_le_mult_iff)
lp15@59746
   732
  also have "... \<longleftrightarrow> Arg z = 0"
lp15@59746
   733
    apply (auto simp: Re_exp)
lp15@59746
   734
    apply (metis Arg_lt_pi Arg_ge_0 Arg_le_pi cos_pi complex_is_Real_iff leD less_linear less_minus_one_simps(2) minus_minus neg_less_eq_nonneg order_refl)
lp15@59746
   735
    using Arg_eq [of z]
lp15@59746
   736
    apply (auto simp: Reals_def)
lp15@59746
   737
    done
lp15@59746
   738
  finally show ?thesis
lp15@59746
   739
    by blast
lp15@59746
   740
qed
lp15@59746
   741
lp15@59746
   742
lemma Arg_of_real: "Arg(of_real x) = 0 \<longleftrightarrow> 0 \<le> x"
lp15@59746
   743
  by (simp add: Arg_eq_0)
lp15@59746
   744
lp15@59746
   745
lemma Arg_eq_pi: "Arg z = pi \<longleftrightarrow> z \<in> \<real> \<and> Re z < 0"
lp15@59746
   746
  apply  (cases "z=0", simp)
lp15@59746
   747
  using Arg_eq_0 [of "-z"]
lp15@59746
   748
  apply (auto simp: complex_is_Real_iff Arg_minus)
lp15@59746
   749
  apply (simp add: complex_Re_Im_cancel_iff)
lp15@59746
   750
  apply (metis Arg_minus pi_gt_zero add.left_neutral minus_minus minus_zero)
lp15@59746
   751
  done
lp15@59746
   752
lp15@59746
   753
lemma Arg_eq_0_pi: "Arg z = 0 \<or> Arg z = pi \<longleftrightarrow> z \<in> \<real>"
lp15@59746
   754
  using Arg_eq_0 Arg_eq_pi not_le by auto
lp15@59746
   755
lp15@59746
   756
lemma Arg_inverse: "Arg(inverse z) = (if z \<in> \<real> \<and> 0 \<le> Re z then Arg z else 2*pi - Arg z)"
lp15@59746
   757
  apply (cases "z=0", simp)
lp15@59746
   758
  apply (rule Arg_unique [of "inverse (norm z)"])
lp15@59746
   759
  using Arg_ge_0 [of z] Arg_lt_2pi [of z] Arg_eq [of z] Arg_eq_0 [of z] Exp_two_pi_i
lp15@59746
   760
  apply (auto simp: of_real_numeral algebra_simps exp_diff divide_simps)
lp15@59746
   761
  done
lp15@59746
   762
lp15@59746
   763
lemma Arg_eq_iff:
lp15@59746
   764
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   765
     shows "Arg w = Arg z \<longleftrightarrow> (\<exists>x. 0 < x & w = of_real x * z)"
lp15@59746
   766
  using assms Arg_eq [of z] Arg_eq [of w]
lp15@59746
   767
  apply auto
lp15@59746
   768
  apply (rule_tac x="norm w / norm z" in exI)
lp15@59746
   769
  apply (simp add: divide_simps)
lp15@59746
   770
  by (metis mult.commute mult.left_commute)
lp15@59746
   771
lp15@59746
   772
lemma Arg_inverse_eq_0: "Arg(inverse z) = 0 \<longleftrightarrow> Arg z = 0"
lp15@59746
   773
  using complex_is_Real_iff
lp15@59746
   774
  apply (simp add: Arg_eq_0)
lp15@59746
   775
  apply (auto simp: divide_simps not_sum_power2_lt_zero)
lp15@59746
   776
  done
lp15@59746
   777
lp15@59746
   778
lemma Arg_divide:
lp15@59746
   779
  assumes "w \<noteq> 0" "z \<noteq> 0" "Arg w \<le> Arg z"
lp15@59746
   780
    shows "Arg(z / w) = Arg z - Arg w"
lp15@59746
   781
  apply (rule Arg_unique [of "norm(z / w)"])
lp15@59746
   782
  using assms Arg_eq [of z] Arg_eq [of w] Arg_ge_0 [of w] Arg_lt_2pi [of z]
lp15@59746
   783
  apply (auto simp: exp_diff norm_divide algebra_simps divide_simps)
lp15@59746
   784
  done
lp15@59746
   785
lp15@59746
   786
lemma Arg_le_div_sum:
lp15@59746
   787
  assumes "w \<noteq> 0" "z \<noteq> 0" "Arg w \<le> Arg z"
lp15@59746
   788
    shows "Arg z = Arg w + Arg(z / w)"
lp15@59746
   789
  by (simp add: Arg_divide assms)
lp15@59746
   790
lp15@59746
   791
lemma Arg_le_div_sum_eq:
lp15@59746
   792
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   793
    shows "Arg w \<le> Arg z \<longleftrightarrow> Arg z = Arg w + Arg(z / w)"
lp15@59746
   794
  using assms
lp15@59746
   795
  by (auto simp: Arg_ge_0 intro: Arg_le_div_sum)
lp15@59746
   796
lp15@59746
   797
lemma Arg_diff:
lp15@59746
   798
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   799
    shows "Arg w - Arg z = (if Arg z \<le> Arg w then Arg(w / z) else Arg(w/z) - 2*pi)"
lp15@59746
   800
  using assms
lp15@59746
   801
  apply (auto simp: Arg_ge_0 Arg_divide not_le)
lp15@59746
   802
  using Arg_divide [of w z] Arg_inverse [of "w/z"]
lp15@59746
   803
  apply auto
lp15@59746
   804
  by (metis Arg_eq_0 less_irrefl minus_diff_eq right_minus_eq)
lp15@59746
   805
lp15@59746
   806
lemma Arg_add:
lp15@59746
   807
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   808
    shows "Arg w + Arg z = (if Arg w + Arg z < 2*pi then Arg(w * z) else Arg(w * z) + 2*pi)"
lp15@59746
   809
  using assms
lp15@59746
   810
  using Arg_diff [of "w*z" z] Arg_le_div_sum_eq [of z "w*z"]
lp15@59746
   811
  apply (auto simp: Arg_ge_0 Arg_divide not_le)
lp15@59746
   812
  apply (metis Arg_lt_2pi add.commute)
lp15@59746
   813
  apply (metis (no_types) Arg add.commute diff_0 diff_add_cancel diff_less_eq diff_minus_eq_add not_less)
lp15@59746
   814
  done
lp15@59746
   815
lp15@59746
   816
lemma Arg_times:
lp15@59746
   817
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   818
    shows "Arg (w * z) = (if Arg w + Arg z < 2*pi then Arg w + Arg z
lp15@59746
   819
                            else (Arg w + Arg z) - 2*pi)"
lp15@59746
   820
  using Arg_add [OF assms]
lp15@59746
   821
  by auto
lp15@59746
   822
lp15@59746
   823
lemma Arg_cnj: "Arg(cnj z) = (if z \<in> \<real> \<and> 0 \<le> Re z then Arg z else 2*pi - Arg z)"
lp15@59746
   824
  apply (cases "z=0", simp)
lp15@59746
   825
  apply (rule trans [of _ "Arg(inverse z)"])
lp15@59746
   826
  apply (simp add: Arg_eq_iff divide_simps complex_norm_square [symmetric] mult.commute)
lp15@59746
   827
  apply (metis norm_eq_zero of_real_power zero_less_power2)
lp15@59746
   828
  apply (auto simp: of_real_numeral Arg_inverse)
lp15@59746
   829
  done
lp15@59746
   830
lp15@59746
   831
lemma Arg_real: "z \<in> \<real> \<Longrightarrow> Arg z = (if 0 \<le> Re z then 0 else pi)"
lp15@59746
   832
  using Arg_eq_0 Arg_eq_0_pi
lp15@59746
   833
  by auto
lp15@59746
   834
lp15@59746
   835
lemma Arg_exp: "0 \<le> Im z \<Longrightarrow> Im z < 2*pi \<Longrightarrow> Arg(exp z) = Im z"
lp15@59746
   836
  by (rule Arg_unique [of  "exp(Re z)"]) (auto simp: Exp_eq_polar)
lp15@59746
   837
lp15@59751
   838
lp15@59751
   839
subsection{*Analytic properties of tangent function*}
lp15@59751
   840
lp15@59751
   841
lemma cnj_tan: "cnj(tan z) = tan(cnj z)"
lp15@59751
   842
  by (simp add: cnj_cos cnj_sin tan_def)
lp15@59751
   843
lp15@59751
   844
lemma complex_differentiable_at_tan: "~(cos z = 0) \<Longrightarrow> tan complex_differentiable at z"
lp15@59751
   845
  unfolding complex_differentiable_def
lp15@59751
   846
  using DERIV_tan by blast
lp15@59751
   847
lp15@59751
   848
lemma complex_differentiable_within_tan: "~(cos z = 0)
lp15@59751
   849
         \<Longrightarrow> tan complex_differentiable (at z within s)"
lp15@59751
   850
  using complex_differentiable_at_tan complex_differentiable_at_within by blast
lp15@59751
   851
lp15@59751
   852
lemma continuous_within_tan: "~(cos z = 0) \<Longrightarrow> continuous (at z within s) tan"
lp15@59751
   853
  using continuous_at_imp_continuous_within isCont_tan by blast
lp15@59751
   854
lp15@59751
   855
lemma continuous_on_tan [continuous_intros]: "(\<And>z. z \<in> s \<Longrightarrow> ~(cos z = 0)) \<Longrightarrow> continuous_on s tan"
lp15@59751
   856
  by (simp add: continuous_at_imp_continuous_on)
lp15@59751
   857
lp15@59751
   858
lemma holomorphic_on_tan: "(\<And>z. z \<in> s \<Longrightarrow> ~(cos z = 0)) \<Longrightarrow> tan holomorphic_on s"
lp15@59751
   859
  by (simp add: complex_differentiable_within_tan holomorphic_on_def)
lp15@59751
   860
lp15@59751
   861
lp15@59751
   862
subsection{*Complex logarithms (the conventional principal value)*}
lp15@59751
   863
lp15@59751
   864
definition Ln where
lp15@59751
   865
   "Ln \<equiv> \<lambda>z. THE w. exp w = z & -pi < Im(w) & Im(w) \<le> pi"
lp15@59751
   866
lp15@59751
   867
lemma
lp15@59751
   868
  assumes "z \<noteq> 0"
lp15@59751
   869
    shows exp_Ln [simp]: "exp(Ln z) = z"
lp15@59751
   870
      and mpi_less_Im_Ln: "-pi < Im(Ln z)"
lp15@59751
   871
      and Im_Ln_le_pi:    "Im(Ln z) \<le> pi"
lp15@59751
   872
proof -
lp15@59751
   873
  obtain \<psi> where z: "z / (cmod z) = Complex (cos \<psi>) (sin \<psi>)"
lp15@59751
   874
    using complex_unimodular_polar [of "z / (norm z)"] assms
lp15@59751
   875
    by (auto simp: norm_divide divide_simps)
lp15@59751
   876
  obtain \<phi> where \<phi>: "- pi < \<phi>" "\<phi> \<le> pi" "sin \<phi> = sin \<psi>" "cos \<phi> = cos \<psi>"
lp15@59751
   877
    using sincos_principal_value [of "\<psi>"] assms
lp15@59751
   878
    by (auto simp: norm_divide divide_simps)
lp15@59751
   879
  have "exp(Ln z) = z & -pi < Im(Ln z) & Im(Ln z) \<le> pi" unfolding Ln_def
lp15@59751
   880
    apply (rule theI [where a = "Complex (ln(norm z)) \<phi>"])
lp15@59751
   881
    using z assms \<phi>
lp15@59751
   882
    apply (auto simp: field_simps exp_complex_eqI Exp_eq_polar cis.code)
lp15@59751
   883
    done
lp15@59751
   884
  then show "exp(Ln z) = z" "-pi < Im(Ln z)" "Im(Ln z) \<le> pi"
lp15@59751
   885
    by auto
lp15@59751
   886
qed
lp15@59751
   887
lp15@59751
   888
lemma Ln_exp [simp]:
lp15@59751
   889
  assumes "-pi < Im(z)" "Im(z) \<le> pi"
lp15@59751
   890
    shows "Ln(exp z) = z"
lp15@59751
   891
  apply (rule exp_complex_eqI)
lp15@59751
   892
  using assms mpi_less_Im_Ln  [of "exp z"] Im_Ln_le_pi [of "exp z"]
lp15@59751
   893
  apply auto
lp15@59751
   894
  done
lp15@59751
   895
lp15@59751
   896
lemma Ln_eq_iff: "w \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (Ln w = Ln z \<longleftrightarrow> w = z)"
lp15@59751
   897
  by (metis exp_Ln)
lp15@59751
   898
lp15@59751
   899
lemma Ln_unique: "exp(z) = w \<Longrightarrow> -pi < Im(z) \<Longrightarrow> Im(z) \<le> pi \<Longrightarrow> Ln w = z"
lp15@59751
   900
  using Ln_exp by blast
lp15@59751
   901
lp15@59751
   902
lemma Re_Ln [simp]: "z \<noteq> 0 \<Longrightarrow> Re(Ln z) = ln(norm z)"
lp15@59751
   903
by (metis exp_Ln assms ln_exp norm_exp_eq_Re)
lp15@59751
   904
lp15@59751
   905
lemma exists_complex_root:
lp15@59751
   906
  fixes a :: complex
lp15@59751
   907
  shows "n \<noteq> 0 \<Longrightarrow> \<exists>z. z ^ n = a"
lp15@59751
   908
  apply (cases "a=0", simp)
lp15@59751
   909
  apply (rule_tac x= "exp(Ln(a) / n)" in exI)
lp15@59751
   910
  apply (auto simp: exp_of_nat_mult [symmetric])
lp15@59751
   911
  done
lp15@59751
   912
lp15@59751
   913
subsection{*Derivative of Ln away from the branch cut*}
lp15@59751
   914
lp15@59751
   915
lemma
lp15@59751
   916
  assumes "Im(z) = 0 \<Longrightarrow> 0 < Re(z)"
lp15@59751
   917
    shows has_field_derivative_Ln: "(Ln has_field_derivative inverse(z)) (at z)"
lp15@59751
   918
      and Im_Ln_less_pi:           "Im (Ln z) < pi"
lp15@59751
   919
proof -
lp15@59751
   920
  have znz: "z \<noteq> 0"
lp15@59751
   921
    using assms by auto
lp15@59751
   922
  then show *: "Im (Ln z) < pi" using assms
lp15@59751
   923
    by (metis exp_Ln Im_Ln_le_pi Im_exp Re_exp abs_of_nonneg cmod_eq_Re cos_pi mult.right_neutral mult_minus_right mult_zero_right neg_less_0_iff_less norm_exp_eq_Re not_less not_less_iff_gr_or_eq sin_pi)
lp15@59751
   924
  show "(Ln has_field_derivative inverse(z)) (at z)"
lp15@59751
   925
    apply (rule has_complex_derivative_inverse_strong_x
lp15@59751
   926
              [where f = exp and s = "{w. -pi < Im(w) & Im(w) < pi}"])
lp15@59751
   927
    using znz *
lp15@59751
   928
    apply (auto simp: continuous_on_exp open_Collect_conj open_halfspace_Im_gt open_halfspace_Im_lt)
lp15@59751
   929
    apply (metis DERIV_exp exp_Ln)
lp15@59751
   930
    apply (metis mpi_less_Im_Ln)
lp15@59751
   931
    done
lp15@59751
   932
qed
lp15@59751
   933
lp15@59751
   934
declare has_field_derivative_Ln [derivative_intros]
lp15@59751
   935
declare has_field_derivative_Ln [THEN DERIV_chain2, derivative_intros]
lp15@59751
   936
lp15@59751
   937
lemma complex_differentiable_at_Ln: "(Im(z) = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> Ln complex_differentiable at z"
lp15@59751
   938
  using complex_differentiable_def has_field_derivative_Ln by blast
lp15@59751
   939
lp15@59751
   940
lemma complex_differentiable_within_Ln: "(Im(z) = 0 \<Longrightarrow> 0 < Re(z))
lp15@59751
   941
         \<Longrightarrow> Ln complex_differentiable (at z within s)"
lp15@59751
   942
  using complex_differentiable_at_Ln complex_differentiable_within_subset by blast
lp15@59751
   943
lp15@59751
   944
lemma continuous_at_Ln: "(Im(z) = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> continuous (at z) Ln"
lp15@59751
   945
  by (simp add: complex_differentiable_imp_continuous_at complex_differentiable_within_Ln)
lp15@59751
   946
lp15@59751
   947
lemma continuous_within_Ln: "(Im(z) = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> continuous (at z within s) Ln"
lp15@59751
   948
  using continuous_at_Ln continuous_at_imp_continuous_within by blast
lp15@59751
   949
lp15@59751
   950
lemma continuous_on_Ln [continuous_intros]: "(\<And>z. z \<in> s \<Longrightarrow> Im(z) = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> continuous_on s Ln"
lp15@59751
   951
  by (simp add: continuous_at_imp_continuous_on continuous_within_Ln)
lp15@59751
   952
lp15@59751
   953
lemma holomorphic_on_Ln: "(\<And>z. z \<in> s \<Longrightarrow> Im(z) = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> Ln holomorphic_on s"
lp15@59751
   954
  by (simp add: complex_differentiable_within_Ln holomorphic_on_def)
lp15@59751
   955
lp15@59751
   956
lp15@59751
   957
subsection{*Relation to Real Logarithm*}
lp15@59751
   958
lp15@59751
   959
lemma ln_of_real:
lp15@59751
   960
  assumes "0 < z"
lp15@59751
   961
    shows "Ln(of_real z) = of_real(ln z)"
lp15@59751
   962
proof -
lp15@59751
   963
  have "Ln(of_real (exp (ln z))) = Ln (exp (of_real (ln z)))"
lp15@59751
   964
    by (simp add: exp_of_real)
lp15@59751
   965
  also have "... = of_real(ln z)"
lp15@59751
   966
    using assms
lp15@59751
   967
    by (subst Ln_exp) auto
lp15@59751
   968
  finally show ?thesis
lp15@59751
   969
    using assms by simp
lp15@59751
   970
qed
lp15@59751
   971
lp15@59751
   972
lp15@59751
   973
subsection{*Quadrant-type results for Ln*}
lp15@59751
   974
lp15@59751
   975
lemma cos_lt_zero_pi: "pi/2 < x \<Longrightarrow> x < 3*pi/2 \<Longrightarrow> cos x < 0"
lp15@59751
   976
  using cos_minus_pi cos_gt_zero_pi [of "x-pi"]
lp15@59751
   977
  by simp
lp15@59751
   978
lp15@59751
   979
lemma Re_Ln_pos_lt:
lp15@59751
   980
  assumes "z \<noteq> 0"
lp15@59751
   981
    shows "abs(Im(Ln z)) < pi/2 \<longleftrightarrow> 0 < Re(z)"
lp15@59751
   982
proof -
lp15@59751
   983
  { fix w
lp15@59751
   984
    assume "w = Ln z"
lp15@59751
   985
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
   986
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
   987
      by auto
lp15@59751
   988
    then have "abs(Im w) < pi/2 \<longleftrightarrow> 0 < Re(exp w)"
lp15@59751
   989
      apply (auto simp: Re_exp zero_less_mult_iff cos_gt_zero_pi)
lp15@59751
   990
      using cos_lt_zero_pi [of "-(Im w)"] cos_lt_zero_pi [of "(Im w)"]
lp15@59751
   991
      apply (simp add: abs_if split: split_if_asm)
lp15@59751
   992
      apply (metis (no_types) cos_minus cos_pi_half eq_divide_eq_numeral1(1) eq_numeral_simps(4)
lp15@59751
   993
               less_numeral_extra(3) linorder_neqE_linordered_idom minus_mult_minus minus_mult_right
lp15@59751
   994
               mult_numeral_1_right)
lp15@59751
   995
      done
lp15@59751
   996
  }
lp15@59751
   997
  then show ?thesis using assms
lp15@59751
   998
    by auto
lp15@59751
   999
qed
lp15@59751
  1000
lp15@59751
  1001
lemma Re_Ln_pos_le:
lp15@59751
  1002
  assumes "z \<noteq> 0"
lp15@59751
  1003
    shows "abs(Im(Ln z)) \<le> pi/2 \<longleftrightarrow> 0 \<le> Re(z)"
lp15@59751
  1004
proof -
lp15@59751
  1005
  { fix w
lp15@59751
  1006
    assume "w = Ln z"
lp15@59751
  1007
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1008
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1009
      by auto
lp15@59751
  1010
    then have "abs(Im w) \<le> pi/2 \<longleftrightarrow> 0 \<le> Re(exp w)"
lp15@59751
  1011
      apply (auto simp: Re_exp zero_le_mult_iff cos_ge_zero)
lp15@59751
  1012
      using cos_lt_zero_pi [of "- (Im w)"] cos_lt_zero_pi [of "(Im w)"] not_le
lp15@59751
  1013
      apply (auto simp: abs_if split: split_if_asm)
lp15@59751
  1014
      done
lp15@59751
  1015
  }
lp15@59751
  1016
  then show ?thesis using assms
lp15@59751
  1017
    by auto
lp15@59751
  1018
qed
lp15@59751
  1019
lp15@59751
  1020
lemma Im_Ln_pos_lt:
lp15@59751
  1021
  assumes "z \<noteq> 0"
lp15@59751
  1022
    shows "0 < Im(Ln z) \<and> Im(Ln z) < pi \<longleftrightarrow> 0 < Im(z)"
lp15@59751
  1023
proof -
lp15@59751
  1024
  { fix w
lp15@59751
  1025
    assume "w = Ln z"
lp15@59751
  1026
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1027
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1028
      by auto
lp15@59751
  1029
    then have "0 < Im w \<and> Im w < pi \<longleftrightarrow> 0 < Im(exp w)"
lp15@59751
  1030
      using sin_gt_zero [of "- (Im w)"] sin_gt_zero [of "(Im w)"]
lp15@59751
  1031
      apply (auto simp: Im_exp zero_less_mult_iff)
lp15@59751
  1032
      using less_linear apply fastforce
lp15@59751
  1033
      using less_linear apply fastforce
lp15@59751
  1034
      done
lp15@59751
  1035
  }
lp15@59751
  1036
  then show ?thesis using assms
lp15@59751
  1037
    by auto
lp15@59751
  1038
qed
lp15@59751
  1039
lp15@59751
  1040
lemma Im_Ln_pos_le:
lp15@59751
  1041
  assumes "z \<noteq> 0"
lp15@59751
  1042
    shows "0 \<le> Im(Ln z) \<and> Im(Ln z) \<le> pi \<longleftrightarrow> 0 \<le> Im(z)"
lp15@59751
  1043
proof -
lp15@59751
  1044
  { fix w
lp15@59751
  1045
    assume "w = Ln z"
lp15@59751
  1046
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1047
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1048
      by auto
lp15@59751
  1049
    then have "0 \<le> Im w \<and> Im w \<le> pi \<longleftrightarrow> 0 \<le> Im(exp w)"
lp15@59751
  1050
      using sin_ge_zero [of "- (Im w)"] sin_ge_zero [of "(Im w)"]
lp15@59751
  1051
      apply (auto simp: Im_exp zero_le_mult_iff sin_ge_zero)
lp15@59751
  1052
      apply (metis not_le not_less_iff_gr_or_eq pi_not_less_zero sin_eq_0_pi)
lp15@59751
  1053
      done }
lp15@59751
  1054
  then show ?thesis using assms
lp15@59751
  1055
    by auto
lp15@59751
  1056
qed
lp15@59751
  1057
lp15@59751
  1058
lemma Re_Ln_pos_lt_imp: "0 < Re(z) \<Longrightarrow> abs(Im(Ln z)) < pi/2"
lp15@59751
  1059
  by (metis Re_Ln_pos_lt less_irrefl zero_complex.simps(1))
lp15@59751
  1060
lp15@59751
  1061
lemma Im_Ln_pos_lt_imp: "0 < Im(z) \<Longrightarrow> 0 < Im(Ln z) \<and> Im(Ln z) < pi"
lp15@59751
  1062
  by (metis Im_Ln_pos_lt not_le order_refl zero_complex.simps(2))
lp15@59751
  1063
lp15@59751
  1064
lemma Im_Ln_eq_0: "z \<noteq> 0 \<Longrightarrow> (Im(Ln z) = 0 \<longleftrightarrow> 0 < Re(z) \<and> Im(z) = 0)"
lp15@59751
  1065
  by (metis exp_Ln Im_Ln_less_pi Im_Ln_pos_le Im_Ln_pos_lt Re_complex_of_real add.commute add.left_neutral
lp15@59751
  1066
       complex_eq exp_of_real le_less mult_zero_right norm_exp_eq_Re norm_le_zero_iff not_le of_real_0)
lp15@59751
  1067
lp15@59751
  1068
lemma Im_Ln_eq_pi: "z \<noteq> 0 \<Longrightarrow> (Im(Ln z) = pi \<longleftrightarrow> Re(z) < 0 \<and> Im(z) = 0)"
lp15@59751
  1069
  by (metis Im_Ln_eq_0 Im_Ln_less_pi Im_Ln_pos_le Im_Ln_pos_lt add.right_neutral complex_eq mult_zero_right not_less not_less_iff_gr_or_eq of_real_0)
lp15@59751
  1070
lp15@59751
  1071
lp15@59751
  1072
subsection{*More Properties of Ln*}
lp15@59751
  1073
lp15@59751
  1074
lemma cnj_Ln: "(Im z = 0 \<Longrightarrow> 0 < Re z) \<Longrightarrow> cnj(Ln z) = Ln(cnj z)"
lp15@59751
  1075
  apply (cases "z=0", auto)
lp15@59751
  1076
  apply (rule exp_complex_eqI)
lp15@59751
  1077
  apply (auto simp: abs_if split: split_if_asm)
lp15@59751
  1078
  apply (metis Im_Ln_less_pi add_mono_thms_linordered_field(5) cnj.simps(1) cnj.simps(2) mult_2 neg_equal_0_iff_equal)
lp15@59751
  1079
  apply (metis add_mono_thms_linordered_field(5) complex_cnj_zero_iff diff_0_right diff_minus_eq_add minus_diff_eq mpi_less_Im_Ln mult.commute mult_2_right neg_less_iff_less)
lp15@59751
  1080
  by (metis exp_Ln exp_cnj)
lp15@59751
  1081
lp15@59751
  1082
lemma Ln_inverse: "(Im(z) = 0 \<Longrightarrow> 0 < Re z) \<Longrightarrow> Ln(inverse z) = -(Ln z)"
lp15@59751
  1083
  apply (cases "z=0", auto)
lp15@59751
  1084
  apply (rule exp_complex_eqI)
lp15@59751
  1085
  using mpi_less_Im_Ln [of z] mpi_less_Im_Ln [of "inverse z"]
lp15@59751
  1086
  apply (auto simp: abs_if exp_minus split: split_if_asm)
lp15@59751
  1087
  apply (metis Im_Ln_less_pi Im_Ln_pos_le add_less_cancel_left add_strict_mono
lp15@59751
  1088
               inverse_inverse_eq inverse_zero le_less mult.commute mult_2_right)
lp15@59751
  1089
  done
lp15@59751
  1090
lp15@59751
  1091
lemma Ln_1 [simp]: "Ln(1) = 0"
lp15@59751
  1092
proof -
lp15@59751
  1093
  have "Ln (exp 0) = 0"
lp15@59751
  1094
    by (metis exp_zero ln_exp ln_of_real of_real_0 of_real_1 zero_less_one)
lp15@59751
  1095
  then show ?thesis
lp15@59751
  1096
    by simp
lp15@59751
  1097
qed
lp15@59751
  1098
lp15@59751
  1099
lemma Ln_minus1 [simp]: "Ln(-1) = ii * pi"
lp15@59751
  1100
  apply (rule exp_complex_eqI)
lp15@59751
  1101
  using Im_Ln_le_pi [of "-1"] mpi_less_Im_Ln [of "-1"] cis_conv_exp cis_pi
lp15@59751
  1102
  apply (auto simp: abs_if)
lp15@59751
  1103
  done
lp15@59751
  1104
lp15@59751
  1105
lemma Ln_ii [simp]: "Ln ii = ii * of_real pi/2"
lp15@59751
  1106
  using Ln_exp [of "ii * (of_real pi/2)"]
lp15@59751
  1107
  unfolding exp_Euler
lp15@59751
  1108
  by simp
lp15@59751
  1109
lp15@59751
  1110
lemma Ln_minus_ii [simp]: "Ln(-ii) = - (ii * pi/2)"
lp15@59751
  1111
proof -
lp15@59751
  1112
  have  "Ln(-ii) = Ln(1/ii)"
lp15@59751
  1113
    by simp
lp15@59751
  1114
  also have "... = - (Ln ii)"
lp15@59751
  1115
    by (metis Ln_inverse ii.sel(2) inverse_eq_divide zero_neq_one)
lp15@59751
  1116
  also have "... = - (ii * pi/2)"
lp15@59751
  1117
    by (simp add: Ln_ii)
lp15@59751
  1118
  finally show ?thesis .
lp15@59751
  1119
qed
lp15@59751
  1120
lp15@59751
  1121
lemma Ln_times:
lp15@59751
  1122
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59751
  1123
    shows "Ln(w * z) =
lp15@59751
  1124
                (if Im(Ln w + Ln z) \<le> -pi then
lp15@59751
  1125
                  (Ln(w) + Ln(z)) + ii * of_real(2*pi)
lp15@59751
  1126
                else if Im(Ln w + Ln z) > pi then
lp15@59751
  1127
                  (Ln(w) + Ln(z)) - ii * of_real(2*pi)
lp15@59751
  1128
                else Ln(w) + Ln(z))"
lp15@59751
  1129
  using pi_ge_zero Im_Ln_le_pi [of w] Im_Ln_le_pi [of z]
lp15@59751
  1130
  using assms mpi_less_Im_Ln [of w] mpi_less_Im_Ln [of z]
lp15@59751
  1131
  by (auto simp: of_real_numeral exp_add exp_diff sin_double cos_double exp_Euler intro!: Ln_unique)
lp15@59751
  1132
lp15@59751
  1133
lemma Ln_times_simple:
lp15@59751
  1134
    "\<lbrakk>w \<noteq> 0; z \<noteq> 0; -pi < Im(Ln w) + Im(Ln z); Im(Ln w) + Im(Ln z) \<le> pi\<rbrakk>
lp15@59751
  1135
         \<Longrightarrow> Ln(w * z) = Ln(w) + Ln(z)"
lp15@59751
  1136
  by (simp add: Ln_times)
lp15@59751
  1137
lp15@59751
  1138
lemma Ln_minus:
lp15@59751
  1139
  assumes "z \<noteq> 0"
lp15@59751
  1140
    shows "Ln(-z) = (if Im(z) \<le> 0 \<and> ~(Re(z) < 0 \<and> Im(z) = 0)
lp15@59751
  1141
                     then Ln(z) + ii * pi
lp15@59751
  1142
                     else Ln(z) - ii * pi)" (is "_ = ?rhs")
lp15@59751
  1143
  using Im_Ln_le_pi [of z] mpi_less_Im_Ln [of z] assms
lp15@59751
  1144
        Im_Ln_eq_pi [of z] Im_Ln_pos_lt [of z]
lp15@59751
  1145
    by (auto simp: of_real_numeral exp_add exp_diff exp_Euler intro!: Ln_unique)
lp15@59751
  1146
lp15@59751
  1147
lemma Ln_inverse_if:
lp15@59751
  1148
  assumes "z \<noteq> 0"
lp15@59751
  1149
    shows "Ln (inverse z) =
lp15@59751
  1150
            (if (Im(z) = 0 \<longrightarrow> 0 < Re z)
lp15@59751
  1151
             then -(Ln z)
lp15@59751
  1152
             else -(Ln z) + \<i> * 2 * complex_of_real pi)"
lp15@59751
  1153
proof (cases "(Im(z) = 0 \<longrightarrow> 0 < Re z)")
lp15@59751
  1154
  case True then show ?thesis
lp15@59751
  1155
    by (simp add: Ln_inverse)
lp15@59751
  1156
next
lp15@59751
  1157
  case False
lp15@59751
  1158
  then have z: "Im z = 0" "Re z < 0"
lp15@59751
  1159
    using assms
lp15@59751
  1160
    apply auto
lp15@59751
  1161
    by (metis cnj.code complex_cnj_cnj not_less_iff_gr_or_eq zero_complex.simps(1) zero_complex.simps(2))
lp15@59751
  1162
  have "Ln(inverse z) = Ln(- (inverse (-z)))"
lp15@59751
  1163
    by simp
lp15@59751
  1164
  also have "... = Ln (inverse (-z)) + \<i> * complex_of_real pi"
lp15@59751
  1165
    using assms z
lp15@59751
  1166
    apply (simp add: Ln_minus)
lp15@59751
  1167
    apply (simp add: field_simps)
lp15@59751
  1168
    done
lp15@59751
  1169
  also have "... = - Ln (- z) + \<i> * complex_of_real pi"
lp15@59751
  1170
    apply (subst Ln_inverse)
lp15@59751
  1171
    using z assms by auto
lp15@59751
  1172
  also have "... = - (Ln z) + \<i> * 2 * complex_of_real pi"
lp15@59751
  1173
    apply (subst Ln_minus [OF assms])
lp15@59751
  1174
    using assms z
lp15@59751
  1175
    apply simp
lp15@59751
  1176
    done
lp15@59751
  1177
  finally show ?thesis
lp15@59751
  1178
    using assms z
lp15@59751
  1179
    by simp
lp15@59751
  1180
qed
lp15@59751
  1181
lp15@59751
  1182
lemma Ln_times_ii:
lp15@59751
  1183
  assumes "z \<noteq> 0"
lp15@59751
  1184
    shows  "Ln(ii * z) = (if 0 \<le> Re(z) | Im(z) < 0
lp15@59751
  1185
                          then Ln(z) + ii * of_real pi/2
lp15@59751
  1186
                          else Ln(z) - ii * of_real(3 * pi/2))"
lp15@59751
  1187
  using Im_Ln_le_pi [of z] mpi_less_Im_Ln [of z] assms
lp15@59751
  1188
        Im_Ln_eq_pi [of z] Im_Ln_pos_lt [of z] Re_Ln_pos_le [of z]
lp15@59751
  1189
  by (auto simp: of_real_numeral Ln_times)
lp15@59751
  1190
lp15@59751
  1191
lp15@59751
  1192
subsection{*Relation between Square Root and exp/ln, hence its derivative*}
lp15@59751
  1193
lp15@59751
  1194
lemma csqrt_exp_Ln:
lp15@59751
  1195
  assumes "z \<noteq> 0"
lp15@59751
  1196
    shows "csqrt z = exp(Ln(z) / 2)"
lp15@59751
  1197
proof -
lp15@59751
  1198
  have "(exp (Ln z / 2))\<^sup>2 = (exp (Ln z))"
lp15@59751
  1199
    by (metis exp_double nonzero_mult_divide_cancel_left times_divide_eq_right zero_neq_numeral)
lp15@59751
  1200
  also have "... = z"
lp15@59751
  1201
    using assms exp_Ln by blast
lp15@59751
  1202
  finally have "csqrt z = csqrt ((exp (Ln z / 2))\<^sup>2)"
lp15@59751
  1203
    by simp
lp15@59751
  1204
  also have "... = exp (Ln z / 2)"
lp15@59751
  1205
    apply (subst csqrt_square)
lp15@59751
  1206
    using cos_gt_zero_pi [of "(Im (Ln z) / 2)"] Im_Ln_le_pi mpi_less_Im_Ln assms
lp15@59751
  1207
    apply (auto simp: Re_exp Im_exp zero_less_mult_iff zero_le_mult_iff, fastforce+)
lp15@59751
  1208
    done
lp15@59751
  1209
  finally show ?thesis using assms csqrt_square
lp15@59751
  1210
    by simp
lp15@59751
  1211
qed
lp15@59751
  1212
lp15@59751
  1213
lemma csqrt_inverse:
lp15@59751
  1214
  assumes "Im(z) = 0 \<Longrightarrow> 0 < Re z"
lp15@59751
  1215
    shows "csqrt (inverse z) = inverse (csqrt z)"
lp15@59751
  1216
proof (cases "z=0", simp)
lp15@59751
  1217
  assume "z \<noteq> 0 "
lp15@59751
  1218
  then show ?thesis
lp15@59751
  1219
    using assms
lp15@59751
  1220
    by (simp add: csqrt_exp_Ln Ln_inverse exp_minus)
lp15@59751
  1221
qed
lp15@59751
  1222
lp15@59751
  1223
lemma cnj_csqrt:
lp15@59751
  1224
  assumes "Im z = 0 \<Longrightarrow> 0 \<le> Re(z)"
lp15@59751
  1225
    shows "cnj(csqrt z) = csqrt(cnj z)"
lp15@59751
  1226
proof (cases "z=0", simp)
lp15@59751
  1227
  assume z: "z \<noteq> 0"
lp15@59751
  1228
  then have "Im z = 0 \<Longrightarrow> 0 < Re(z)"
lp15@59751
  1229
    using assms cnj.code complex_cnj_zero_iff by fastforce
lp15@59751
  1230
  then show ?thesis
lp15@59751
  1231
   using z by (simp add: csqrt_exp_Ln cnj_Ln exp_cnj)
lp15@59751
  1232
qed
lp15@59751
  1233
lp15@59751
  1234
lemma has_field_derivative_csqrt:
lp15@59751
  1235
  assumes "Im z = 0 \<Longrightarrow> 0 < Re(z)"
lp15@59751
  1236
    shows "(csqrt has_field_derivative inverse(2 * csqrt z)) (at z)"
lp15@59751
  1237
proof -
lp15@59751
  1238
  have z: "z \<noteq> 0"
lp15@59751
  1239
    using assms by auto
lp15@59751
  1240
  then have *: "inverse z = inverse (2*z) * 2"
lp15@59751
  1241
    by (simp add: divide_simps)
lp15@59751
  1242
  show ?thesis
lp15@59751
  1243
    apply (rule DERIV_transform_at [where f = "\<lambda>z. exp(Ln(z) / 2)" and d = "norm z"])
lp15@59751
  1244
    apply (intro derivative_eq_intros | simp add: assms)+
lp15@59751
  1245
    apply (rule *)
lp15@59751
  1246
    using z
lp15@59751
  1247
    apply (auto simp: field_simps csqrt_exp_Ln [symmetric])
lp15@59751
  1248
    apply (metis power2_csqrt power2_eq_square)
lp15@59751
  1249
    apply (metis csqrt_exp_Ln dist_0_norm less_irrefl)
lp15@59751
  1250
    done
lp15@59751
  1251
qed
lp15@59751
  1252
lp15@59751
  1253
lemma complex_differentiable_at_csqrt:
lp15@59751
  1254
    "(Im z = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> csqrt complex_differentiable at z"
lp15@59751
  1255
  using complex_differentiable_def has_field_derivative_csqrt by blast
lp15@59751
  1256
lp15@59751
  1257
lemma complex_differentiable_within_csqrt:
lp15@59751
  1258
    "(Im z = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> csqrt complex_differentiable (at z within s)"
lp15@59751
  1259
  using complex_differentiable_at_csqrt complex_differentiable_within_subset by blast
lp15@59751
  1260
lp15@59751
  1261
lemma continuous_at_csqrt:
lp15@59751
  1262
    "(Im z = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> continuous (at z) csqrt"
lp15@59751
  1263
  by (simp add: complex_differentiable_within_csqrt complex_differentiable_imp_continuous_at)
lp15@59751
  1264
lp15@59751
  1265
lemma continuous_within_csqrt:
lp15@59751
  1266
    "(Im z = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> continuous (at z within s) csqrt"
lp15@59751
  1267
  by (simp add: complex_differentiable_imp_continuous_at complex_differentiable_within_csqrt)
lp15@59751
  1268
lp15@59751
  1269
lemma continuous_on_csqrt [continuous_intros]:
lp15@59751
  1270
    "(\<And>z. z \<in> s \<and> Im z = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> continuous_on s csqrt"
lp15@59751
  1271
  by (simp add: continuous_at_imp_continuous_on continuous_within_csqrt)
lp15@59751
  1272
lp15@59751
  1273
lemma holomorphic_on_csqrt:
lp15@59751
  1274
    "(\<And>z. z \<in> s \<and> Im z = 0 \<Longrightarrow> 0 < Re(z)) \<Longrightarrow> csqrt holomorphic_on s"
lp15@59751
  1275
  by (simp add: complex_differentiable_within_csqrt holomorphic_on_def)
lp15@59751
  1276
lp15@59751
  1277
lemma continuous_within_closed_nontrivial:
lp15@59751
  1278
    "closed s \<Longrightarrow> a \<notin> s ==> continuous (at a within s) f"
lp15@59751
  1279
  using open_Compl
lp15@59751
  1280
  by (force simp add: continuous_def eventually_at_topological filterlim_iff open_Collect_neg)
lp15@59751
  1281
lp15@59751
  1282
lemma closed_Real_halfspace_Re_ge: "closed (\<real> \<inter> {w. x \<le> Re(w)})"
lp15@59751
  1283
  using closed_halfspace_Re_ge
lp15@59751
  1284
  by (simp add: closed_Int closed_complex_Reals)
lp15@59751
  1285
lp15@59751
  1286
lemma continuous_within_csqrt_posreal:
lp15@59751
  1287
    "continuous (at z within (\<real> \<inter> {w. 0 \<le> Re(w)})) csqrt"
lp15@59751
  1288
proof (cases "Im z = 0 --> 0 < Re(z)")
lp15@59751
  1289
  case True then show ?thesis
lp15@59751
  1290
    by (blast intro: continuous_within_csqrt)
lp15@59751
  1291
next
lp15@59751
  1292
  case False
lp15@59751
  1293
  then have "Im z = 0" "Re z < 0 \<or> z = 0"
lp15@59751
  1294
    using False cnj.code complex_cnj_zero_iff by auto force
lp15@59751
  1295
  then show ?thesis
lp15@59751
  1296
    apply (auto simp: continuous_within_closed_nontrivial [OF closed_Real_halfspace_Re_ge])
lp15@59751
  1297
    apply (auto simp: continuous_within_eps_delta norm_conv_dist [symmetric])
lp15@59751
  1298
    apply (rule_tac x="e^2" in exI)
lp15@59751
  1299
    apply (auto simp: Reals_def)
lp15@59751
  1300
by (metis linear not_less real_sqrt_less_iff real_sqrt_pow2_iff real_sqrt_power)
lp15@59751
  1301
qed
lp15@59751
  1302
lp15@59751
  1303
lp15@59745
  1304
end