src/HOL/Multivariate_Analysis/Complex_Transcendental.thy
author paulson
Mon Jan 11 22:14:15 2016 +0000 (2016-01-11)
changeset 62131 1baed43f453e
parent 62087 44841d07ef1d
child 62381 a6479cb85944
child 62390 842917225d56
permissions -rw-r--r--
nonneg_Reals, nonpos_Reals, Cauchy integral formula, etc.
wenzelm@60420
     1
section \<open>Complex Transcendental Functions\<close>
lp15@59745
     2
lp15@61711
     3
text\<open>By John Harrison et al.  Ported from HOL Light by L C Paulson (2015)\<close>
lp15@61711
     4
lp15@59745
     5
theory Complex_Transcendental
eberlm@62049
     6
imports 
eberlm@62049
     7
  Complex_Analysis_Basics
eberlm@62049
     8
  Summation
lp15@59745
     9
begin
lp15@59745
    10
eberlm@62049
    11
(* TODO: Figure out what to do with Möbius transformations *)
eberlm@62049
    12
definition "moebius a b c d = (\<lambda>z. (a*z+b) / (c*z+d :: 'a :: field))"
eberlm@62049
    13
eberlm@62049
    14
lemma moebius_inverse: 
eberlm@62049
    15
  assumes "a * d \<noteq> b * c" "c * z + d \<noteq> 0"
eberlm@62049
    16
  shows   "moebius d (-b) (-c) a (moebius a b c d z) = z"
eberlm@62049
    17
proof -
eberlm@62049
    18
  from assms have "(-c) * moebius a b c d z + a \<noteq> 0" unfolding moebius_def
eberlm@62049
    19
    by (simp add: field_simps)
eberlm@62049
    20
  with assms show ?thesis
eberlm@62049
    21
    unfolding moebius_def by (simp add: moebius_def divide_simps) (simp add: algebra_simps)?
eberlm@62049
    22
qed
eberlm@62049
    23
eberlm@62049
    24
lemma moebius_inverse': 
eberlm@62049
    25
  assumes "a * d \<noteq> b * c" "c * z - a \<noteq> 0"
eberlm@62049
    26
  shows   "moebius a b c d (moebius d (-b) (-c) a z) = z"
eberlm@62049
    27
  using assms moebius_inverse[of d a "-b" "-c" z]
eberlm@62049
    28
  by (auto simp: algebra_simps)
eberlm@62049
    29
lp15@59870
    30
lemma cmod_add_real_less:
lp15@59870
    31
  assumes "Im z \<noteq> 0" "r\<noteq>0"
wenzelm@61945
    32
    shows "cmod (z + r) < cmod z + \<bar>r\<bar>"
lp15@59870
    33
proof (cases z)
lp15@59870
    34
  case (Complex x y)
lp15@59870
    35
  have "r * x / \<bar>r\<bar> < sqrt (x*x + y*y)"
lp15@59870
    36
    apply (rule real_less_rsqrt)
lp15@59870
    37
    using assms
lp15@59870
    38
    apply (simp add: Complex power2_eq_square)
lp15@59870
    39
    using not_real_square_gt_zero by blast
lp15@59870
    40
  then show ?thesis using assms Complex
lp15@59870
    41
    apply (auto simp: cmod_def)
lp15@59870
    42
    apply (rule power2_less_imp_less, auto)
lp15@59870
    43
    apply (simp add: power2_eq_square field_simps)
lp15@59870
    44
    done
lp15@59870
    45
qed
lp15@59870
    46
wenzelm@61945
    47
lemma cmod_diff_real_less: "Im z \<noteq> 0 \<Longrightarrow> x\<noteq>0 \<Longrightarrow> cmod (z - x) < cmod z + \<bar>x\<bar>"
lp15@59870
    48
  using cmod_add_real_less [of z "-x"]
lp15@59870
    49
  by simp
lp15@59870
    50
lp15@59870
    51
lemma cmod_square_less_1_plus:
lp15@59870
    52
  assumes "Im z = 0 \<Longrightarrow> \<bar>Re z\<bar> < 1"
lp15@59870
    53
    shows "(cmod z)\<^sup>2 < 1 + cmod (1 - z\<^sup>2)"
lp15@59870
    54
  using assms
lp15@59870
    55
  apply (cases "Im z = 0 \<or> Re z = 0")
lp15@59870
    56
  using abs_square_less_1
lp15@59870
    57
    apply (force simp add: Re_power2 Im_power2 cmod_def)
lp15@59870
    58
  using cmod_diff_real_less [of "1 - z\<^sup>2" "1"]
lp15@59870
    59
  apply (simp add: norm_power Im_power2)
lp15@59870
    60
  done
lp15@59870
    61
wenzelm@60420
    62
subsection\<open>The Exponential Function is Differentiable and Continuous\<close>
lp15@59745
    63
lp15@59745
    64
lemma complex_differentiable_within_exp: "exp complex_differentiable (at z within s)"
lp15@60150
    65
  using DERIV_exp complex_differentiable_at_within complex_differentiable_def by blast
lp15@59745
    66
lp15@59745
    67
lemma continuous_within_exp:
lp15@59745
    68
  fixes z::"'a::{real_normed_field,banach}"
lp15@59745
    69
  shows "continuous (at z within s) exp"
lp15@59745
    70
by (simp add: continuous_at_imp_continuous_within)
lp15@59745
    71
lp15@59745
    72
lemma continuous_on_exp:
lp15@59745
    73
  fixes s::"'a::{real_normed_field,banach} set"
lp15@59745
    74
  shows "continuous_on s exp"
lp15@59745
    75
by (simp add: continuous_on_exp continuous_on_id)
lp15@59745
    76
lp15@59745
    77
lemma holomorphic_on_exp: "exp holomorphic_on s"
lp15@59745
    78
  by (simp add: complex_differentiable_within_exp holomorphic_on_def)
lp15@59745
    79
wenzelm@60420
    80
subsection\<open>Euler and de Moivre formulas.\<close>
wenzelm@60420
    81
wenzelm@60420
    82
text\<open>The sine series times @{term i}\<close>
lp15@59745
    83
lemma sin_ii_eq: "(\<lambda>n. (ii * sin_coeff n) * z^n) sums (ii * sin z)"
lp15@59745
    84
proof -
lp15@59745
    85
  have "(\<lambda>n. ii * sin_coeff n *\<^sub>R z^n) sums (ii * sin z)"
lp15@59745
    86
    using sin_converges sums_mult by blast
lp15@59745
    87
  then show ?thesis
lp15@59745
    88
    by (simp add: scaleR_conv_of_real field_simps)
lp15@59745
    89
qed
lp15@59745
    90
lp15@59745
    91
theorem exp_Euler: "exp(ii * z) = cos(z) + ii * sin(z)"
lp15@59745
    92
proof -
lp15@59862
    93
  have "(\<lambda>n. (cos_coeff n + ii * sin_coeff n) * z^n)
lp15@59745
    94
        = (\<lambda>n. (ii * z) ^ n /\<^sub>R (fact n))"
lp15@59745
    95
  proof
lp15@59745
    96
    fix n
lp15@59745
    97
    show "(cos_coeff n + ii * sin_coeff n) * z^n = (ii * z) ^ n /\<^sub>R (fact n)"
lp15@59745
    98
      by (auto simp: cos_coeff_def sin_coeff_def scaleR_conv_of_real field_simps elim!: evenE oddE)
lp15@59745
    99
  qed
lp15@59745
   100
  also have "... sums (exp (ii * z))"
lp15@59745
   101
    by (rule exp_converges)
lp15@59745
   102
  finally have "(\<lambda>n. (cos_coeff n + ii * sin_coeff n) * z^n) sums (exp (ii * z))" .
lp15@59745
   103
  moreover have "(\<lambda>n. (cos_coeff n + ii * sin_coeff n) * z^n) sums (cos z + ii * sin z)"
lp15@59745
   104
    using sums_add [OF cos_converges [of z] sin_ii_eq [of z]]
lp15@59745
   105
    by (simp add: field_simps scaleR_conv_of_real)
lp15@59745
   106
  ultimately show ?thesis
lp15@59745
   107
    using sums_unique2 by blast
lp15@59745
   108
qed
lp15@59745
   109
lp15@59745
   110
corollary exp_minus_Euler: "exp(-(ii * z)) = cos(z) - ii * sin(z)"
lp15@59745
   111
  using exp_Euler [of "-z"]
lp15@59745
   112
  by simp
lp15@59745
   113
lp15@59745
   114
lemma sin_exp_eq: "sin z = (exp(ii * z) - exp(-(ii * z))) / (2*ii)"
lp15@59745
   115
  by (simp add: exp_Euler exp_minus_Euler)
lp15@59745
   116
lp15@59745
   117
lemma sin_exp_eq': "sin z = ii * (exp(-(ii * z)) - exp(ii * z)) / 2"
lp15@59745
   118
  by (simp add: exp_Euler exp_minus_Euler)
lp15@59745
   119
lp15@59745
   120
lemma cos_exp_eq:  "cos z = (exp(ii * z) + exp(-(ii * z))) / 2"
lp15@59745
   121
  by (simp add: exp_Euler exp_minus_Euler)
lp15@59745
   122
wenzelm@60420
   123
subsection\<open>Relationships between real and complex trig functions\<close>
lp15@59745
   124
lp15@59745
   125
lemma real_sin_eq [simp]:
lp15@59745
   126
  fixes x::real
lp15@59745
   127
  shows "Re(sin(of_real x)) = sin x"
lp15@59745
   128
  by (simp add: sin_of_real)
lp15@59862
   129
lp15@59745
   130
lemma real_cos_eq [simp]:
lp15@59745
   131
  fixes x::real
lp15@59745
   132
  shows "Re(cos(of_real x)) = cos x"
lp15@59745
   133
  by (simp add: cos_of_real)
lp15@59745
   134
lp15@59745
   135
lemma DeMoivre: "(cos z + ii * sin z) ^ n = cos(n * z) + ii * sin(n * z)"
lp15@59745
   136
  apply (simp add: exp_Euler [symmetric])
lp15@59745
   137
  by (metis exp_of_nat_mult mult.left_commute)
lp15@59745
   138
lp15@59745
   139
lemma exp_cnj:
lp15@59745
   140
  fixes z::complex
lp15@59745
   141
  shows "cnj (exp z) = exp (cnj z)"
lp15@59745
   142
proof -
lp15@59745
   143
  have "(\<lambda>n. cnj (z ^ n /\<^sub>R (fact n))) = (\<lambda>n. (cnj z)^n /\<^sub>R (fact n))"
lp15@59745
   144
    by auto
lp15@59745
   145
  also have "... sums (exp (cnj z))"
lp15@59745
   146
    by (rule exp_converges)
lp15@59745
   147
  finally have "(\<lambda>n. cnj (z ^ n /\<^sub>R (fact n))) sums (exp (cnj z))" .
lp15@59745
   148
  moreover have "(\<lambda>n. cnj (z ^ n /\<^sub>R (fact n))) sums (cnj (exp z))"
lp15@59862
   149
    by (metis exp_converges sums_cnj)
lp15@59745
   150
  ultimately show ?thesis
lp15@59745
   151
    using sums_unique2
lp15@59862
   152
    by blast
lp15@59745
   153
qed
lp15@59745
   154
lp15@59745
   155
lemma cnj_sin: "cnj(sin z) = sin(cnj z)"
lp15@59745
   156
  by (simp add: sin_exp_eq exp_cnj field_simps)
lp15@59745
   157
lp15@59745
   158
lemma cnj_cos: "cnj(cos z) = cos(cnj z)"
lp15@59745
   159
  by (simp add: cos_exp_eq exp_cnj field_simps)
lp15@59745
   160
lp15@59745
   161
lemma complex_differentiable_at_sin: "sin complex_differentiable at z"
lp15@59745
   162
  using DERIV_sin complex_differentiable_def by blast
lp15@59745
   163
lp15@59745
   164
lemma complex_differentiable_within_sin: "sin complex_differentiable (at z within s)"
lp15@59745
   165
  by (simp add: complex_differentiable_at_sin complex_differentiable_at_within)
lp15@59745
   166
lp15@59745
   167
lemma complex_differentiable_at_cos: "cos complex_differentiable at z"
lp15@59745
   168
  using DERIV_cos complex_differentiable_def by blast
lp15@59745
   169
lp15@59745
   170
lemma complex_differentiable_within_cos: "cos complex_differentiable (at z within s)"
lp15@59745
   171
  by (simp add: complex_differentiable_at_cos complex_differentiable_at_within)
lp15@59745
   172
lp15@59745
   173
lemma holomorphic_on_sin: "sin holomorphic_on s"
lp15@59745
   174
  by (simp add: complex_differentiable_within_sin holomorphic_on_def)
lp15@59745
   175
lp15@59745
   176
lemma holomorphic_on_cos: "cos holomorphic_on s"
lp15@59745
   177
  by (simp add: complex_differentiable_within_cos holomorphic_on_def)
lp15@59745
   178
wenzelm@60420
   179
subsection\<open>Get a nice real/imaginary separation in Euler's formula.\<close>
lp15@59745
   180
lp15@59862
   181
lemma Euler: "exp(z) = of_real(exp(Re z)) *
lp15@59745
   182
              (of_real(cos(Im z)) + ii * of_real(sin(Im z)))"
lp15@59745
   183
by (cases z) (simp add: exp_add exp_Euler cos_of_real exp_of_real sin_of_real)
lp15@59745
   184
lp15@59745
   185
lemma Re_sin: "Re(sin z) = sin(Re z) * (exp(Im z) + exp(-(Im z))) / 2"
lp15@59745
   186
  by (simp add: sin_exp_eq field_simps Re_divide Im_exp)
lp15@59745
   187
lp15@59745
   188
lemma Im_sin: "Im(sin z) = cos(Re z) * (exp(Im z) - exp(-(Im z))) / 2"
lp15@59745
   189
  by (simp add: sin_exp_eq field_simps Im_divide Re_exp)
lp15@59745
   190
lp15@59745
   191
lemma Re_cos: "Re(cos z) = cos(Re z) * (exp(Im z) + exp(-(Im z))) / 2"
lp15@59745
   192
  by (simp add: cos_exp_eq field_simps Re_divide Re_exp)
lp15@59745
   193
lp15@59745
   194
lemma Im_cos: "Im(cos z) = sin(Re z) * (exp(-(Im z)) - exp(Im z)) / 2"
lp15@59745
   195
  by (simp add: cos_exp_eq field_simps Im_divide Im_exp)
lp15@59862
   196
lp15@59862
   197
lemma Re_sin_pos: "0 < Re z \<Longrightarrow> Re z < pi \<Longrightarrow> Re (sin z) > 0"
lp15@59862
   198
  by (auto simp: Re_sin Im_sin add_pos_pos sin_gt_zero)
lp15@59862
   199
lp15@59862
   200
lemma Im_sin_nonneg: "Re z = 0 \<Longrightarrow> 0 \<le> Im z \<Longrightarrow> 0 \<le> Im (sin z)"
lp15@59862
   201
  by (simp add: Re_sin Im_sin algebra_simps)
lp15@59862
   202
lp15@59862
   203
lemma Im_sin_nonneg2: "Re z = pi \<Longrightarrow> Im z \<le> 0 \<Longrightarrow> 0 \<le> Im (sin z)"
lp15@59862
   204
  by (simp add: Re_sin Im_sin algebra_simps)
lp15@59862
   205
wenzelm@60420
   206
subsection\<open>More on the Polar Representation of Complex Numbers\<close>
lp15@59746
   207
lp15@59746
   208
lemma exp_Complex: "exp(Complex r t) = of_real(exp r) * Complex (cos t) (sin t)"
lp15@59862
   209
  by (simp add: exp_add exp_Euler exp_of_real sin_of_real cos_of_real)
lp15@59746
   210
lp15@59746
   211
lemma exp_eq_1: "exp z = 1 \<longleftrightarrow> Re(z) = 0 \<and> (\<exists>n::int. Im(z) = of_int (2 * n) * pi)"
lp15@59746
   212
apply auto
lp15@59746
   213
apply (metis exp_eq_one_iff norm_exp_eq_Re norm_one)
lp15@61609
   214
apply (metis Re_exp cos_one_2pi_int mult.commute mult.left_neutral norm_exp_eq_Re norm_one one_complex.simps(1))
lp15@61609
   215
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 sin_zero_iff_int2)
lp15@59746
   216
lp15@59746
   217
lemma exp_eq: "exp w = exp z \<longleftrightarrow> (\<exists>n::int. w = z + (of_int (2 * n) * pi) * ii)"
lp15@59746
   218
                (is "?lhs = ?rhs")
lp15@59746
   219
proof -
lp15@59746
   220
  have "exp w = exp z \<longleftrightarrow> exp (w-z) = 1"
lp15@59746
   221
    by (simp add: exp_diff)
lp15@59746
   222
  also have "... \<longleftrightarrow> (Re w = Re z \<and> (\<exists>n::int. Im w - Im z = of_int (2 * n) * pi))"
lp15@59746
   223
    by (simp add: exp_eq_1)
lp15@59746
   224
  also have "... \<longleftrightarrow> ?rhs"
lp15@59746
   225
    by (auto simp: algebra_simps intro!: complex_eqI)
lp15@59746
   226
  finally show ?thesis .
lp15@59746
   227
qed
lp15@59746
   228
wenzelm@61945
   229
lemma exp_complex_eqI: "\<bar>Im w - Im z\<bar> < 2*pi \<Longrightarrow> exp w = exp z \<Longrightarrow> w = z"
lp15@59746
   230
  by (auto simp: exp_eq abs_mult)
lp15@59746
   231
lp15@59862
   232
lemma exp_integer_2pi:
wenzelm@61070
   233
  assumes "n \<in> \<int>"
lp15@59746
   234
  shows "exp((2 * n * pi) * ii) = 1"
lp15@59746
   235
proof -
lp15@59746
   236
  have "exp((2 * n * pi) * ii) = exp 0"
lp15@59746
   237
    using assms
lp15@59746
   238
    by (simp only: Ints_def exp_eq) auto
lp15@59746
   239
  also have "... = 1"
lp15@59746
   240
    by simp
lp15@59746
   241
  finally show ?thesis .
lp15@59746
   242
qed
lp15@59746
   243
lp15@59746
   244
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
   245
proof -
lp15@59746
   246
  { assume "sin y = sin x" "cos y = cos x"
lp15@59746
   247
    then have "cos (y-x) = 1"
lp15@59746
   248
      using cos_add [of y "-x"] by simp
lp15@61609
   249
    then have "\<exists>n::int. y-x = n * 2 * pi"
lp15@59746
   250
      using cos_one_2pi_int by blast }
lp15@59746
   251
  then show ?thesis
lp15@59746
   252
  apply (auto simp: sin_add cos_add)
lp15@59746
   253
  apply (metis add.commute diff_add_cancel mult.commute)
lp15@59746
   254
  done
lp15@59746
   255
qed
lp15@59746
   256
lp15@59862
   257
lemma exp_i_ne_1:
lp15@59746
   258
  assumes "0 < x" "x < 2*pi"
lp15@59746
   259
  shows "exp(\<i> * of_real x) \<noteq> 1"
lp15@59862
   260
proof
lp15@59746
   261
  assume "exp (\<i> * of_real x) = 1"
lp15@59746
   262
  then have "exp (\<i> * of_real x) = exp 0"
lp15@59746
   263
    by simp
lp15@59746
   264
  then obtain n where "\<i> * of_real x = (of_int (2 * n) * pi) * \<i>"
lp15@59746
   265
    by (simp only: Ints_def exp_eq) auto
lp15@59746
   266
  then have  "of_real x = (of_int (2 * n) * pi)"
lp15@59746
   267
    by (metis complex_i_not_zero mult.commute mult_cancel_left of_real_eq_iff real_scaleR_def scaleR_conv_of_real)
lp15@59746
   268
  then have  "x = (of_int (2 * n) * pi)"
lp15@59746
   269
    by simp
lp15@59746
   270
  then show False using assms
lp15@59746
   271
    by (cases n) (auto simp: zero_less_mult_iff mult_less_0_iff)
lp15@59746
   272
qed
lp15@59746
   273
lp15@59862
   274
lemma sin_eq_0:
lp15@59746
   275
  fixes z::complex
lp15@59746
   276
  shows "sin z = 0 \<longleftrightarrow> (\<exists>n::int. z = of_real(n * pi))"
lp15@59746
   277
  by (simp add: sin_exp_eq exp_eq of_real_numeral)
lp15@59746
   278
lp15@59862
   279
lemma cos_eq_0:
lp15@59746
   280
  fixes z::complex
lp15@59746
   281
  shows "cos z = 0 \<longleftrightarrow> (\<exists>n::int. z = of_real(n * pi) + of_real pi/2)"
lp15@59746
   282
  using sin_eq_0 [of "z - of_real pi/2"]
lp15@59746
   283
  by (simp add: sin_diff algebra_simps)
lp15@59746
   284
lp15@59862
   285
lemma cos_eq_1:
lp15@59746
   286
  fixes z::complex
lp15@59746
   287
  shows "cos z = 1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi))"
lp15@59746
   288
proof -
lp15@59746
   289
  have "cos z = cos (2*(z/2))"
lp15@59746
   290
    by simp
lp15@59746
   291
  also have "... = 1 - 2 * sin (z/2) ^ 2"
lp15@59746
   292
    by (simp only: cos_double_sin)
lp15@59746
   293
  finally have [simp]: "cos z = 1 \<longleftrightarrow> sin (z/2) = 0"
lp15@59746
   294
    by simp
lp15@59746
   295
  show ?thesis
lp15@59746
   296
    by (auto simp: sin_eq_0 of_real_numeral)
lp15@59862
   297
qed
lp15@59746
   298
lp15@59746
   299
lemma csin_eq_1:
lp15@59746
   300
  fixes z::complex
lp15@59746
   301
  shows "sin z = 1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   302
  using cos_eq_1 [of "z - of_real pi/2"]
lp15@59746
   303
  by (simp add: cos_diff algebra_simps)
lp15@59746
   304
lp15@59746
   305
lemma csin_eq_minus1:
lp15@59746
   306
  fixes z::complex
lp15@59746
   307
  shows "sin z = -1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi) + 3/2*pi)"
lp15@59746
   308
        (is "_ = ?rhs")
lp15@59746
   309
proof -
lp15@59746
   310
  have "sin z = -1 \<longleftrightarrow> sin (-z) = 1"
lp15@59746
   311
    by (simp add: equation_minus_iff)
lp15@59746
   312
  also have "...  \<longleftrightarrow> (\<exists>n::int. -z = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   313
    by (simp only: csin_eq_1)
lp15@59746
   314
  also have "...  \<longleftrightarrow> (\<exists>n::int. z = - of_real(2 * n * pi) - of_real pi/2)"
lp15@59746
   315
    apply (rule iff_exI)
lp15@59746
   316
    by (metis (no_types)  is_num_normalize(8) minus_minus of_real_def real_vector.scale_minus_left uminus_add_conv_diff)
lp15@59746
   317
  also have "... = ?rhs"
lp15@59746
   318
    apply (auto simp: of_real_numeral)
lp15@59746
   319
    apply (rule_tac [2] x="-(x+1)" in exI)
lp15@59746
   320
    apply (rule_tac x="-(x+1)" in exI)
lp15@59746
   321
    apply (simp_all add: algebra_simps)
lp15@59746
   322
    done
lp15@59746
   323
  finally show ?thesis .
lp15@59862
   324
qed
lp15@59746
   325
lp15@59862
   326
lemma ccos_eq_minus1:
lp15@59746
   327
  fixes z::complex
lp15@59746
   328
  shows "cos z = -1 \<longleftrightarrow> (\<exists>n::int. z = of_real(2 * n * pi) + pi)"
lp15@59746
   329
  using csin_eq_1 [of "z - of_real pi/2"]
lp15@59746
   330
  apply (simp add: sin_diff)
lp15@59746
   331
  apply (simp add: algebra_simps of_real_numeral equation_minus_iff)
lp15@59862
   332
  done
lp15@59746
   333
lp15@59746
   334
lemma sin_eq_1: "sin x = 1 \<longleftrightarrow> (\<exists>n::int. x = (2 * n + 1 / 2) * pi)"
lp15@59746
   335
                (is "_ = ?rhs")
lp15@59746
   336
proof -
lp15@59746
   337
  have "sin x = 1 \<longleftrightarrow> sin (complex_of_real x) = 1"
lp15@59746
   338
    by (metis of_real_1 one_complex.simps(1) real_sin_eq sin_of_real)
lp15@59746
   339
  also have "...  \<longleftrightarrow> (\<exists>n::int. complex_of_real x = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   340
    by (simp only: csin_eq_1)
lp15@59746
   341
  also have "...  \<longleftrightarrow> (\<exists>n::int. x = of_real(2 * n * pi) + of_real pi/2)"
lp15@59746
   342
    apply (rule iff_exI)
lp15@59746
   343
    apply (auto simp: algebra_simps of_real_numeral)
lp15@59746
   344
    apply (rule injD [OF inj_of_real [where 'a = complex]])
lp15@59746
   345
    apply (auto simp: of_real_numeral)
lp15@59746
   346
    done
lp15@59746
   347
  also have "... = ?rhs"
lp15@59746
   348
    by (auto simp: algebra_simps)
lp15@59746
   349
  finally show ?thesis .
lp15@59862
   350
qed
lp15@59746
   351
lp15@59746
   352
lemma sin_eq_minus1: "sin x = -1 \<longleftrightarrow> (\<exists>n::int. x = (2*n + 3/2) * pi)"  (is "_ = ?rhs")
lp15@59746
   353
proof -
lp15@59746
   354
  have "sin x = -1 \<longleftrightarrow> sin (complex_of_real x) = -1"
lp15@59746
   355
    by (metis Re_complex_of_real of_real_def scaleR_minus1_left sin_of_real)
lp15@59746
   356
  also have "...  \<longleftrightarrow> (\<exists>n::int. complex_of_real x = of_real(2 * n * pi) + 3/2*pi)"
lp15@59746
   357
    by (simp only: csin_eq_minus1)
lp15@59746
   358
  also have "...  \<longleftrightarrow> (\<exists>n::int. x = of_real(2 * n * pi) + 3/2*pi)"
lp15@59746
   359
    apply (rule iff_exI)
lp15@59746
   360
    apply (auto simp: algebra_simps)
lp15@59746
   361
    apply (rule injD [OF inj_of_real [where 'a = complex]], auto)
lp15@59746
   362
    done
lp15@59746
   363
  also have "... = ?rhs"
lp15@59746
   364
    by (auto simp: algebra_simps)
lp15@59746
   365
  finally show ?thesis .
lp15@59862
   366
qed
lp15@59746
   367
lp15@59746
   368
lemma cos_eq_minus1: "cos x = -1 \<longleftrightarrow> (\<exists>n::int. x = (2*n + 1) * pi)"
lp15@59746
   369
                      (is "_ = ?rhs")
lp15@59746
   370
proof -
lp15@59746
   371
  have "cos x = -1 \<longleftrightarrow> cos (complex_of_real x) = -1"
lp15@59746
   372
    by (metis Re_complex_of_real of_real_def scaleR_minus1_left cos_of_real)
lp15@59746
   373
  also have "...  \<longleftrightarrow> (\<exists>n::int. complex_of_real x = of_real(2 * n * pi) + pi)"
lp15@59746
   374
    by (simp only: ccos_eq_minus1)
lp15@59746
   375
  also have "...  \<longleftrightarrow> (\<exists>n::int. x = of_real(2 * n * pi) + pi)"
lp15@59746
   376
    apply (rule iff_exI)
lp15@59746
   377
    apply (auto simp: algebra_simps)
lp15@59746
   378
    apply (rule injD [OF inj_of_real [where 'a = complex]], auto)
lp15@59746
   379
    done
lp15@59746
   380
  also have "... = ?rhs"
lp15@59746
   381
    by (auto simp: algebra_simps)
lp15@59746
   382
  finally show ?thesis .
lp15@59862
   383
qed
lp15@59746
   384
wenzelm@61945
   385
lemma dist_exp_ii_1: "norm(exp(ii * of_real t) - 1) = 2 * \<bar>sin(t / 2)\<bar>"
lp15@59862
   386
  apply (simp add: exp_Euler cmod_def power2_diff sin_of_real cos_of_real algebra_simps)
lp15@59746
   387
  using cos_double_sin [of "t/2"]
lp15@59746
   388
  apply (simp add: real_sqrt_mult)
lp15@59746
   389
  done
lp15@59746
   390
lp15@59746
   391
lemma sinh_complex:
lp15@59746
   392
  fixes z :: complex
lp15@59746
   393
  shows "(exp z - inverse (exp z)) / 2 = -ii * sin(ii * z)"
lp15@59746
   394
  by (simp add: sin_exp_eq divide_simps exp_minus of_real_numeral)
lp15@59746
   395
lp15@59746
   396
lemma sin_ii_times:
lp15@59746
   397
  fixes z :: complex
lp15@59746
   398
  shows "sin(ii * z) = ii * ((exp z - inverse (exp z)) / 2)"
lp15@59746
   399
  using sinh_complex by auto
lp15@59746
   400
lp15@59746
   401
lemma sinh_real:
lp15@59746
   402
  fixes x :: real
lp15@59746
   403
  shows "of_real((exp x - inverse (exp x)) / 2) = -ii * sin(ii * of_real x)"
lp15@59746
   404
  by (simp add: exp_of_real sin_ii_times of_real_numeral)
lp15@59746
   405
lp15@59746
   406
lemma cosh_complex:
lp15@59746
   407
  fixes z :: complex
lp15@59746
   408
  shows "(exp z + inverse (exp z)) / 2 = cos(ii * z)"
lp15@59746
   409
  by (simp add: cos_exp_eq divide_simps exp_minus of_real_numeral exp_of_real)
lp15@59746
   410
lp15@59746
   411
lemma cosh_real:
lp15@59746
   412
  fixes x :: real
lp15@59746
   413
  shows "of_real((exp x + inverse (exp x)) / 2) = cos(ii * of_real x)"
lp15@59746
   414
  by (simp add: cos_exp_eq divide_simps exp_minus of_real_numeral exp_of_real)
lp15@59746
   415
lp15@59746
   416
lemmas cos_ii_times = cosh_complex [symmetric]
lp15@59746
   417
lp15@59862
   418
lemma norm_cos_squared:
lp15@59746
   419
    "norm(cos z) ^ 2 = cos(Re z) ^ 2 + (exp(Im z) - inverse(exp(Im z))) ^ 2 / 4"
lp15@59746
   420
  apply (cases z)
lp15@59746
   421
  apply (simp add: cos_add cmod_power2 cos_of_real sin_of_real)
lp15@61694
   422
  apply (simp add: cos_exp_eq sin_exp_eq exp_minus exp_of_real Re_divide Im_divide power_divide)
lp15@59746
   423
  apply (simp only: left_diff_distrib [symmetric] power_mult_distrib)
lp15@59746
   424
  apply (simp add: sin_squared_eq)
lp15@59746
   425
  apply (simp add: power2_eq_square algebra_simps divide_simps)
lp15@59746
   426
  done
lp15@59746
   427
lp15@59746
   428
lemma norm_sin_squared:
lp15@59746
   429
    "norm(sin z) ^ 2 = (exp(2 * Im z) + inverse(exp(2 * Im z)) - 2 * cos(2 * Re z)) / 4"
lp15@59746
   430
  apply (cases z)
lp15@59746
   431
  apply (simp add: sin_add cmod_power2 cos_of_real sin_of_real cos_double_cos exp_double)
lp15@61694
   432
  apply (simp add: cos_exp_eq sin_exp_eq exp_minus exp_of_real Re_divide Im_divide power_divide)
lp15@59746
   433
  apply (simp only: left_diff_distrib [symmetric] power_mult_distrib)
lp15@59746
   434
  apply (simp add: cos_squared_eq)
lp15@59746
   435
  apply (simp add: power2_eq_square algebra_simps divide_simps)
lp15@59862
   436
  done
lp15@59746
   437
lp15@59746
   438
lemma exp_uminus_Im: "exp (- Im z) \<le> exp (cmod z)"
lp15@59746
   439
  using abs_Im_le_cmod linear order_trans by fastforce
lp15@59746
   440
lp15@59862
   441
lemma norm_cos_le:
lp15@59746
   442
  fixes z::complex
lp15@59746
   443
  shows "norm(cos z) \<le> exp(norm z)"
lp15@59746
   444
proof -
lp15@59746
   445
  have "Im z \<le> cmod z"
lp15@59746
   446
    using abs_Im_le_cmod abs_le_D1 by auto
lp15@59746
   447
  with exp_uminus_Im show ?thesis
lp15@59746
   448
    apply (simp add: cos_exp_eq norm_divide)
lp15@59746
   449
    apply (rule order_trans [OF norm_triangle_ineq], simp)
lp15@59746
   450
    apply (metis add_mono exp_le_cancel_iff mult_2_right)
lp15@59746
   451
    done
lp15@59746
   452
qed
lp15@59746
   453
lp15@59862
   454
lemma norm_cos_plus1_le:
lp15@59746
   455
  fixes z::complex
lp15@59746
   456
  shows "norm(1 + cos z) \<le> 2 * exp(norm z)"
lp15@59746
   457
proof -
lp15@59746
   458
  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
   459
      by arith
lp15@59746
   460
  have *: "Im z \<le> cmod z"
lp15@59746
   461
    using abs_Im_le_cmod abs_le_D1 by auto
lp15@59746
   462
  have triangle3: "\<And>x y z. norm(x + y + z) \<le> norm(x) + norm(y) + norm(z)"
lp15@59746
   463
    by (simp add: norm_add_rule_thm)
lp15@59746
   464
  have "norm(1 + cos z) = cmod (1 + (exp (\<i> * z) + exp (- (\<i> * z))) / 2)"
lp15@59746
   465
    by (simp add: cos_exp_eq)
lp15@59746
   466
  also have "... = cmod ((2 + exp (\<i> * z) + exp (- (\<i> * z))) / 2)"
lp15@59746
   467
    by (simp add: field_simps)
lp15@59746
   468
  also have "... = cmod (2 + exp (\<i> * z) + exp (- (\<i> * z))) / 2"
lp15@59746
   469
    by (simp add: norm_divide)
lp15@59746
   470
  finally show ?thesis
lp15@59746
   471
    apply (rule ssubst, simp)
lp15@59746
   472
    apply (rule order_trans [OF triangle3], simp)
lp15@59746
   473
    using exp_uminus_Im *
lp15@59746
   474
    apply (auto intro: mono)
lp15@59746
   475
    done
lp15@59746
   476
qed
lp15@59746
   477
wenzelm@60420
   478
subsection\<open>Taylor series for complex exponential, sine and cosine.\<close>
lp15@59746
   479
lp15@59746
   480
declare power_Suc [simp del]
lp15@59746
   481
lp15@59862
   482
lemma Taylor_exp:
lp15@59746
   483
  "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
   484
proof (rule complex_taylor [of _ n "\<lambda>k. exp" "exp\<bar>Re z\<bar>" 0 z, simplified])
lp15@59746
   485
  show "convex (closed_segment 0 z)"
paulson@61518
   486
    by (rule convex_closed_segment [of 0 z])
lp15@59746
   487
next
lp15@59746
   488
  fix k x
lp15@59746
   489
  assume "x \<in> closed_segment 0 z" "k \<le> n"
lp15@59746
   490
  show "(exp has_field_derivative exp x) (at x within closed_segment 0 z)"
lp15@59746
   491
    using DERIV_exp DERIV_subset by blast
lp15@59746
   492
next
lp15@59746
   493
  fix x
lp15@59746
   494
  assume "x \<in> closed_segment 0 z"
lp15@59746
   495
  then show "Re x \<le> \<bar>Re z\<bar>"
lp15@59746
   496
    apply (auto simp: closed_segment_def scaleR_conv_of_real)
lp15@59746
   497
    by (meson abs_ge_self abs_ge_zero linear mult_left_le_one_le mult_nonneg_nonpos order_trans)
lp15@59746
   498
next
lp15@59746
   499
  show "0 \<in> closed_segment 0 z"
lp15@59746
   500
    by (auto simp: closed_segment_def)
lp15@59746
   501
next
lp15@59746
   502
  show "z \<in> closed_segment 0 z"
lp15@59746
   503
    apply (simp add: closed_segment_def scaleR_conv_of_real)
lp15@59746
   504
    using of_real_1 zero_le_one by blast
lp15@59862
   505
qed
lp15@59746
   506
lp15@59862
   507
lemma
lp15@59746
   508
  assumes "0 \<le> u" "u \<le> 1"
lp15@59862
   509
  shows cmod_sin_le_exp: "cmod (sin (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>"
lp15@59746
   510
    and cmod_cos_le_exp: "cmod (cos (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>"
lp15@59746
   511
proof -
lp15@59746
   512
  have mono: "\<And>u w z::real. w \<le> u \<Longrightarrow> z \<le> u \<Longrightarrow> w + z \<le> u*2"
lp15@59746
   513
    by arith
lp15@59746
   514
  show "cmod (sin (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>" using assms
lp15@59746
   515
    apply (auto simp: scaleR_conv_of_real norm_mult norm_power sin_exp_eq norm_divide)
lp15@59746
   516
    apply (rule order_trans [OF norm_triangle_ineq4])
lp15@59746
   517
    apply (rule mono)
lp15@59746
   518
    apply (auto simp: abs_if mult_left_le_one_le)
lp15@59746
   519
    apply (meson mult_nonneg_nonneg neg_le_0_iff_le not_le order_trans)
lp15@59746
   520
    apply (meson less_eq_real_def mult_nonneg_nonpos neg_0_le_iff_le order_trans)
lp15@59746
   521
    done
lp15@59746
   522
  show "cmod (cos (u *\<^sub>R z)) \<le> exp \<bar>Im z\<bar>" using assms
lp15@59746
   523
    apply (auto simp: scaleR_conv_of_real norm_mult norm_power cos_exp_eq norm_divide)
lp15@59746
   524
    apply (rule order_trans [OF norm_triangle_ineq])
lp15@59746
   525
    apply (rule mono)
lp15@59746
   526
    apply (auto simp: abs_if mult_left_le_one_le)
lp15@59746
   527
    apply (meson mult_nonneg_nonneg neg_le_0_iff_le not_le order_trans)
lp15@59746
   528
    apply (meson less_eq_real_def mult_nonneg_nonpos neg_0_le_iff_le order_trans)
lp15@59746
   529
    done
lp15@59746
   530
qed
lp15@59862
   531
lp15@59862
   532
lemma Taylor_sin:
lp15@59862
   533
  "norm(sin z - (\<Sum>k\<le>n. complex_of_real (sin_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 (sin z -
lp15@59746
   539
                 (\<Sum>i\<le>n. (-1) ^ (i div 2) * (if even i then sin 0 else cos 0) * z ^ i / (fact i)))
lp15@59862
   540
           \<le> exp \<bar>Im z\<bar> * cmod z ^ Suc n / (fact n)"
lp15@61609
   541
  proof (rule complex_taylor [of "closed_segment 0 z" n
lp15@61609
   542
                                 "\<lambda>k x. (-1)^(k div 2) * (if even k then sin x else cos x)"
lp15@60162
   543
                                 "exp\<bar>Im z\<bar>" 0 z,  simplified])
lp15@59746
   544
    fix k x
lp15@59746
   545
    show "((\<lambda>x. (- 1) ^ (k div 2) * (if even k then sin x else cos x)) has_field_derivative
lp15@59746
   546
            (- 1) ^ (Suc k div 2) * (if odd k then sin x else cos x))
lp15@59746
   547
            (at x within closed_segment 0 z)"
lp15@59746
   548
      apply (auto simp: power_Suc)
lp15@59746
   549
      apply (intro derivative_eq_intros | simp)+
lp15@59746
   550
      done
lp15@59746
   551
  next
lp15@59746
   552
    fix x
lp15@59746
   553
    assume "x \<in> closed_segment 0 z"
lp15@59746
   554
    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
   555
      by (auto simp: closed_segment_def norm_mult norm_power cmod_sin_le_exp cmod_cos_le_exp)
lp15@59862
   556
  qed
lp15@59746
   557
  have **: "\<And>k. complex_of_real (sin_coeff k) * z ^ k
lp15@59746
   558
            = (-1)^(k div 2) * (if even k then sin 0 else cos 0) * z^k / of_nat (fact k)"
lp15@59746
   559
    by (auto simp: sin_coeff_def elim!: oddE)
lp15@59746
   560
  show ?thesis
lp15@59746
   561
    apply (rule order_trans [OF _ *])
lp15@59746
   562
    apply (simp add: **)
lp15@59746
   563
    done
lp15@59746
   564
qed
lp15@59746
   565
lp15@59862
   566
lemma Taylor_cos:
lp15@59862
   567
  "norm(cos z - (\<Sum>k\<le>n. complex_of_real (cos_coeff k) * z ^ k))
lp15@59746
   568
   \<le> exp\<bar>Im z\<bar> * (norm z) ^ Suc n / (fact n)"
lp15@59746
   569
proof -
lp15@59746
   570
  have mono: "\<And>u w z::real. w \<le> u \<Longrightarrow> z \<le> u \<Longrightarrow> w + z \<le> u*2"
lp15@59746
   571
      by arith
lp15@59746
   572
  have *: "cmod (cos z -
lp15@59746
   573
                 (\<Sum>i\<le>n. (-1) ^ (Suc i div 2) * (if even i then cos 0 else sin 0) * z ^ i / (fact i)))
lp15@59862
   574
           \<le> exp \<bar>Im z\<bar> * cmod z ^ Suc n / (fact n)"
lp15@59746
   575
  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
   576
simplified])
lp15@59746
   577
    fix k x
lp15@59746
   578
    assume "x \<in> closed_segment 0 z" "k \<le> n"
lp15@59746
   579
    show "((\<lambda>x. (- 1) ^ (Suc k div 2) * (if even k then cos x else sin x)) has_field_derivative
lp15@59746
   580
            (- 1) ^ Suc (k div 2) * (if odd k then cos x else sin x))
lp15@59746
   581
             (at x within closed_segment 0 z)"
lp15@59746
   582
      apply (auto simp: power_Suc)
lp15@59746
   583
      apply (intro derivative_eq_intros | simp)+
lp15@59746
   584
      done
lp15@59746
   585
  next
lp15@59746
   586
    fix x
lp15@59746
   587
    assume "x \<in> closed_segment 0 z"
lp15@59746
   588
    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
   589
      by (auto simp: closed_segment_def norm_mult norm_power cmod_sin_le_exp cmod_cos_le_exp)
lp15@59862
   590
  qed
lp15@59746
   591
  have **: "\<And>k. complex_of_real (cos_coeff k) * z ^ k
lp15@59746
   592
            = (-1)^(Suc k div 2) * (if even k then cos 0 else sin 0) * z^k / of_nat (fact k)"
lp15@59746
   593
    by (auto simp: cos_coeff_def elim!: evenE)
lp15@59746
   594
  show ?thesis
lp15@59746
   595
    apply (rule order_trans [OF _ *])
lp15@59746
   596
    apply (simp add: **)
lp15@59746
   597
    done
lp15@59746
   598
qed
lp15@59746
   599
lp15@60162
   600
declare power_Suc [simp]
lp15@59746
   601
wenzelm@60420
   602
text\<open>32-bit Approximation to e\<close>
wenzelm@61945
   603
lemma e_approx_32: "\<bar>exp(1) - 5837465777 / 2147483648\<bar> \<le> (inverse(2 ^ 32)::real)"
lp15@59751
   604
  using Taylor_exp [of 1 14] exp_le
lp15@59751
   605
  apply (simp add: setsum_left_distrib in_Reals_norm Re_exp atMost_nat_numeral fact_numeral)
lp15@59751
   606
  apply (simp only: pos_le_divide_eq [symmetric], linarith)
lp15@59751
   607
  done
lp15@59751
   608
lp15@60017
   609
lemma e_less_3: "exp 1 < (3::real)"
lp15@60017
   610
  using e_approx_32
lp15@60017
   611
  by (simp add: abs_if split: split_if_asm)
lp15@60017
   612
lp15@60017
   613
lemma ln3_gt_1: "ln 3 > (1::real)"
lp15@60017
   614
  by (metis e_less_3 exp_less_cancel_iff exp_ln_iff less_trans ln_exp)
lp15@60017
   615
lp15@60017
   616
wenzelm@60420
   617
subsection\<open>The argument of a complex number\<close>
lp15@59746
   618
lp15@59746
   619
definition Arg :: "complex \<Rightarrow> real" where
lp15@59746
   620
 "Arg z \<equiv> if z = 0 then 0
lp15@59746
   621
           else THE t. 0 \<le> t \<and> t < 2*pi \<and>
lp15@59746
   622
                    z = of_real(norm z) * exp(ii * of_real t)"
lp15@59746
   623
lp15@59746
   624
lemma Arg_0 [simp]: "Arg(0) = 0"
lp15@59746
   625
  by (simp add: Arg_def)
lp15@59746
   626
lp15@59746
   627
lemma Arg_unique_lemma:
lp15@59746
   628
  assumes z:  "z = of_real(norm z) * exp(ii * of_real t)"
lp15@59746
   629
      and z': "z = of_real(norm z) * exp(ii * of_real t')"
lp15@59746
   630
      and t:  "0 \<le> t"  "t < 2*pi"
lp15@59746
   631
      and t': "0 \<le> t'" "t' < 2*pi"
lp15@59746
   632
      and nz: "z \<noteq> 0"
lp15@59746
   633
  shows "t' = t"
lp15@59746
   634
proof -
lp15@59746
   635
  have [dest]: "\<And>x y z::real. x\<ge>0 \<Longrightarrow> x+y < z \<Longrightarrow> y<z"
lp15@59746
   636
    by arith
lp15@59746
   637
  have "of_real (cmod z) * exp (\<i> * of_real t') = of_real (cmod z) * exp (\<i> * of_real t)"
lp15@59746
   638
    by (metis z z')
lp15@59746
   639
  then have "exp (\<i> * of_real t') = exp (\<i> * of_real t)"
lp15@59746
   640
    by (metis nz mult_left_cancel mult_zero_left z)
lp15@59746
   641
  then have "sin t' = sin t \<and> cos t' = cos t"
lp15@59746
   642
    apply (simp add: exp_Euler sin_of_real cos_of_real)
lp15@59746
   643
    by (metis Complex_eq complex.sel)
lp15@61609
   644
  then obtain n::int where n: "t' = t + 2 * n * pi"
lp15@59746
   645
    by (auto simp: sin_cos_eq_iff)
lp15@59746
   646
  then have "n=0"
lp15@59746
   647
    apply (rule_tac z=n in int_cases)
lp15@59746
   648
    using t t'
lp15@59746
   649
    apply (auto simp: mult_less_0_iff algebra_simps)
lp15@59746
   650
    done
lp15@59746
   651
  then show "t' = t"
lp15@59746
   652
      by (simp add: n)
lp15@59746
   653
qed
lp15@59746
   654
lp15@59746
   655
lemma Arg: "0 \<le> Arg z & Arg z < 2*pi & z = of_real(norm z) * exp(ii * of_real(Arg z))"
lp15@59746
   656
proof (cases "z=0")
lp15@59746
   657
  case True then show ?thesis
lp15@59746
   658
    by (simp add: Arg_def)
lp15@59746
   659
next
lp15@59746
   660
  case False
lp15@59746
   661
  obtain t where t: "0 \<le> t" "t < 2*pi"
lp15@59746
   662
             and ReIm: "Re z / cmod z = cos t" "Im z / cmod z = sin t"
lp15@59746
   663
    using sincos_total_2pi [OF complex_unit_circle [OF False]]
lp15@59746
   664
    by blast
lp15@59746
   665
  have z: "z = of_real(norm z) * exp(ii * of_real t)"
lp15@59746
   666
    apply (rule complex_eqI)
lp15@59746
   667
    using t False ReIm
lp15@59746
   668
    apply (auto simp: exp_Euler sin_of_real cos_of_real divide_simps)
lp15@59746
   669
    done
lp15@59746
   670
  show ?thesis
lp15@59746
   671
    apply (simp add: Arg_def False)
lp15@59746
   672
    apply (rule theI [where a=t])
lp15@59746
   673
    using t z False
lp15@59746
   674
    apply (auto intro: Arg_unique_lemma)
lp15@59746
   675
    done
lp15@59746
   676
qed
lp15@59746
   677
lp15@59746
   678
corollary
lp15@59746
   679
  shows Arg_ge_0: "0 \<le> Arg z"
lp15@59746
   680
    and Arg_lt_2pi: "Arg z < 2*pi"
lp15@59746
   681
    and Arg_eq: "z = of_real(norm z) * exp(ii * of_real(Arg z))"
lp15@59746
   682
  using Arg by auto
lp15@59746
   683
lp15@59746
   684
lemma complex_norm_eq_1_exp: "norm z = 1 \<longleftrightarrow> (\<exists>t. z = exp(ii * of_real t))"
lp15@59746
   685
  using Arg [of z] by auto
lp15@59746
   686
lp15@59746
   687
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
   688
  apply (rule Arg_unique_lemma [OF _ Arg_eq])
lp15@59746
   689
  using Arg [of z]
lp15@59746
   690
  apply (auto simp: norm_mult)
lp15@59746
   691
  done
lp15@59746
   692
lp15@59746
   693
lemma Arg_minus: "z \<noteq> 0 \<Longrightarrow> Arg (-z) = (if Arg z < pi then Arg z + pi else Arg z - pi)"
lp15@59746
   694
  apply (rule Arg_unique [of "norm z"])
lp15@59746
   695
  apply (rule complex_eqI)
lp15@59746
   696
  using Arg_ge_0 [of z] Arg_eq [of z] Arg_lt_2pi [of z] Arg_eq [of z]
lp15@59746
   697
  apply auto
lp15@59746
   698
  apply (auto simp: Re_exp Im_exp cos_diff sin_diff cis_conv_exp [symmetric])
lp15@59746
   699
  apply (metis Re_rcis Im_rcis rcis_def)+
lp15@59746
   700
  done
lp15@59746
   701
lp15@59746
   702
lemma Arg_times_of_real [simp]: "0 < r \<Longrightarrow> Arg (of_real r * z) = Arg z"
lp15@59746
   703
  apply (cases "z=0", simp)
lp15@59746
   704
  apply (rule Arg_unique [of "r * norm z"])
lp15@59746
   705
  using Arg
lp15@59746
   706
  apply auto
lp15@59746
   707
  done
lp15@59746
   708
lp15@59746
   709
lemma Arg_times_of_real2 [simp]: "0 < r \<Longrightarrow> Arg (z * of_real r) = Arg z"
lp15@59746
   710
  by (metis Arg_times_of_real mult.commute)
lp15@59746
   711
lp15@59746
   712
lemma Arg_divide_of_real [simp]: "0 < r \<Longrightarrow> Arg (z / of_real r) = Arg z"
lp15@59746
   713
  by (metis Arg_times_of_real2 less_numeral_extra(3) nonzero_eq_divide_eq of_real_eq_0_iff)
lp15@59746
   714
lp15@59746
   715
lemma Arg_le_pi: "Arg z \<le> pi \<longleftrightarrow> 0 \<le> Im z"
lp15@59746
   716
proof (cases "z=0")
lp15@59746
   717
  case True then show ?thesis
lp15@59746
   718
    by simp
lp15@59746
   719
next
lp15@59746
   720
  case False
lp15@59746
   721
  have "0 \<le> Im z \<longleftrightarrow> 0 \<le> Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   722
    by (metis Arg_eq)
lp15@59746
   723
  also have "... = (0 \<le> Im (exp (\<i> * complex_of_real (Arg z))))"
lp15@59746
   724
    using False
lp15@59746
   725
    by (simp add: zero_le_mult_iff)
lp15@59746
   726
  also have "... \<longleftrightarrow> Arg z \<le> pi"
lp15@59746
   727
    by (simp add: Im_exp) (metis Arg_ge_0 Arg_lt_2pi sin_lt_zero sin_ge_zero not_le)
lp15@59746
   728
  finally show ?thesis
lp15@59746
   729
    by blast
lp15@59746
   730
qed
lp15@59746
   731
lp15@59746
   732
lemma Arg_lt_pi: "0 < Arg z \<and> Arg z < pi \<longleftrightarrow> 0 < Im z"
lp15@59746
   733
proof (cases "z=0")
lp15@59746
   734
  case True then show ?thesis
lp15@59746
   735
    by simp
lp15@59746
   736
next
lp15@59746
   737
  case False
lp15@59746
   738
  have "0 < Im z \<longleftrightarrow> 0 < Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   739
    by (metis Arg_eq)
lp15@59746
   740
  also have "... = (0 < Im (exp (\<i> * complex_of_real (Arg z))))"
lp15@59746
   741
    using False
lp15@59746
   742
    by (simp add: zero_less_mult_iff)
lp15@59746
   743
  also have "... \<longleftrightarrow> 0 < Arg z \<and> Arg z < pi"
lp15@59746
   744
    using Arg_ge_0  Arg_lt_2pi sin_le_zero sin_gt_zero
lp15@59746
   745
    apply (auto simp: Im_exp)
lp15@59746
   746
    using le_less apply fastforce
lp15@59746
   747
    using not_le by blast
lp15@59746
   748
  finally show ?thesis
lp15@59746
   749
    by blast
lp15@59746
   750
qed
lp15@59746
   751
wenzelm@61070
   752
lemma Arg_eq_0: "Arg z = 0 \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re z"
lp15@59746
   753
proof (cases "z=0")
lp15@59746
   754
  case True then show ?thesis
lp15@59746
   755
    by simp
lp15@59746
   756
next
lp15@59746
   757
  case False
wenzelm@61070
   758
  have "z \<in> \<real> \<and> 0 \<le> Re z \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   759
    by (metis Arg_eq)
wenzelm@61070
   760
  also have "... \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re (exp (\<i> * complex_of_real (Arg z)))"
lp15@59746
   761
    using False
lp15@59746
   762
    by (simp add: zero_le_mult_iff)
lp15@59746
   763
  also have "... \<longleftrightarrow> Arg z = 0"
lp15@59746
   764
    apply (auto simp: Re_exp)
lp15@59746
   765
    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
   766
    using Arg_eq [of z]
lp15@59746
   767
    apply (auto simp: Reals_def)
lp15@59746
   768
    done
lp15@59746
   769
  finally show ?thesis
lp15@59746
   770
    by blast
lp15@59746
   771
qed
lp15@59746
   772
lp15@61609
   773
corollary Arg_gt_0:
lp15@60150
   774
  assumes "z \<in> \<real> \<Longrightarrow> Re z < 0"
lp15@60150
   775
    shows "Arg z > 0"
lp15@60150
   776
  using Arg_eq_0 Arg_ge_0 assms dual_order.strict_iff_order by fastforce
lp15@60150
   777
lp15@59746
   778
lemma Arg_of_real: "Arg(of_real x) = 0 \<longleftrightarrow> 0 \<le> x"
lp15@59746
   779
  by (simp add: Arg_eq_0)
lp15@59746
   780
lp15@59746
   781
lemma Arg_eq_pi: "Arg z = pi \<longleftrightarrow> z \<in> \<real> \<and> Re z < 0"
lp15@59746
   782
  apply  (cases "z=0", simp)
lp15@59746
   783
  using Arg_eq_0 [of "-z"]
lp15@59746
   784
  apply (auto simp: complex_is_Real_iff Arg_minus)
lp15@59746
   785
  apply (simp add: complex_Re_Im_cancel_iff)
lp15@59746
   786
  apply (metis Arg_minus pi_gt_zero add.left_neutral minus_minus minus_zero)
lp15@59746
   787
  done
lp15@59746
   788
lp15@59746
   789
lemma Arg_eq_0_pi: "Arg z = 0 \<or> Arg z = pi \<longleftrightarrow> z \<in> \<real>"
lp15@59746
   790
  using Arg_eq_0 Arg_eq_pi not_le by auto
lp15@59746
   791
lp15@59746
   792
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
   793
  apply (cases "z=0", simp)
lp15@59746
   794
  apply (rule Arg_unique [of "inverse (norm z)"])
lp15@61762
   795
  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
   796
  apply (auto simp: of_real_numeral algebra_simps exp_diff divide_simps)
lp15@59746
   797
  done
lp15@59746
   798
lp15@59746
   799
lemma Arg_eq_iff:
lp15@59746
   800
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   801
     shows "Arg w = Arg z \<longleftrightarrow> (\<exists>x. 0 < x & w = of_real x * z)"
lp15@59746
   802
  using assms Arg_eq [of z] Arg_eq [of w]
lp15@59746
   803
  apply auto
lp15@59746
   804
  apply (rule_tac x="norm w / norm z" in exI)
lp15@59746
   805
  apply (simp add: divide_simps)
lp15@59746
   806
  by (metis mult.commute mult.left_commute)
lp15@59746
   807
lp15@59746
   808
lemma Arg_inverse_eq_0: "Arg(inverse z) = 0 \<longleftrightarrow> Arg z = 0"
lp15@59746
   809
  using complex_is_Real_iff
lp15@59746
   810
  apply (simp add: Arg_eq_0)
lp15@59746
   811
  apply (auto simp: divide_simps not_sum_power2_lt_zero)
lp15@59746
   812
  done
lp15@59746
   813
lp15@59746
   814
lemma Arg_divide:
lp15@59746
   815
  assumes "w \<noteq> 0" "z \<noteq> 0" "Arg w \<le> Arg z"
lp15@59746
   816
    shows "Arg(z / w) = Arg z - Arg w"
lp15@59746
   817
  apply (rule Arg_unique [of "norm(z / w)"])
lp15@59746
   818
  using assms Arg_eq [of z] Arg_eq [of w] Arg_ge_0 [of w] Arg_lt_2pi [of z]
lp15@59746
   819
  apply (auto simp: exp_diff norm_divide algebra_simps divide_simps)
lp15@59746
   820
  done
lp15@59746
   821
lp15@59746
   822
lemma Arg_le_div_sum:
lp15@59746
   823
  assumes "w \<noteq> 0" "z \<noteq> 0" "Arg w \<le> Arg z"
lp15@59746
   824
    shows "Arg z = Arg w + Arg(z / w)"
lp15@59746
   825
  by (simp add: Arg_divide assms)
lp15@59746
   826
lp15@59746
   827
lemma Arg_le_div_sum_eq:
lp15@59746
   828
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   829
    shows "Arg w \<le> Arg z \<longleftrightarrow> Arg z = Arg w + Arg(z / w)"
lp15@59746
   830
  using assms
lp15@59746
   831
  by (auto simp: Arg_ge_0 intro: Arg_le_div_sum)
lp15@59746
   832
lp15@59746
   833
lemma Arg_diff:
lp15@59746
   834
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   835
    shows "Arg w - Arg z = (if Arg z \<le> Arg w then Arg(w / z) else Arg(w/z) - 2*pi)"
lp15@59746
   836
  using assms
lp15@59746
   837
  apply (auto simp: Arg_ge_0 Arg_divide not_le)
lp15@59746
   838
  using Arg_divide [of w z] Arg_inverse [of "w/z"]
lp15@59746
   839
  apply auto
lp15@59746
   840
  by (metis Arg_eq_0 less_irrefl minus_diff_eq right_minus_eq)
lp15@59746
   841
lp15@59746
   842
lemma Arg_add:
lp15@59746
   843
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   844
    shows "Arg w + Arg z = (if Arg w + Arg z < 2*pi then Arg(w * z) else Arg(w * z) + 2*pi)"
lp15@59746
   845
  using assms
lp15@59746
   846
  using Arg_diff [of "w*z" z] Arg_le_div_sum_eq [of z "w*z"]
lp15@59746
   847
  apply (auto simp: Arg_ge_0 Arg_divide not_le)
lp15@59746
   848
  apply (metis Arg_lt_2pi add.commute)
lp15@59746
   849
  apply (metis (no_types) Arg add.commute diff_0 diff_add_cancel diff_less_eq diff_minus_eq_add not_less)
lp15@59746
   850
  done
lp15@59746
   851
lp15@59746
   852
lemma Arg_times:
lp15@59746
   853
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59746
   854
    shows "Arg (w * z) = (if Arg w + Arg z < 2*pi then Arg w + Arg z
lp15@59746
   855
                            else (Arg w + Arg z) - 2*pi)"
lp15@59746
   856
  using Arg_add [OF assms]
lp15@59746
   857
  by auto
lp15@59746
   858
lp15@59746
   859
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
   860
  apply (cases "z=0", simp)
lp15@59746
   861
  apply (rule trans [of _ "Arg(inverse z)"])
lp15@59746
   862
  apply (simp add: Arg_eq_iff divide_simps complex_norm_square [symmetric] mult.commute)
lp15@59746
   863
  apply (metis norm_eq_zero of_real_power zero_less_power2)
lp15@59746
   864
  apply (auto simp: of_real_numeral Arg_inverse)
lp15@59746
   865
  done
lp15@59746
   866
lp15@59746
   867
lemma Arg_real: "z \<in> \<real> \<Longrightarrow> Arg z = (if 0 \<le> Re z then 0 else pi)"
lp15@59746
   868
  using Arg_eq_0 Arg_eq_0_pi
lp15@59746
   869
  by auto
lp15@59746
   870
lp15@59746
   871
lemma Arg_exp: "0 \<le> Im z \<Longrightarrow> Im z < 2*pi \<Longrightarrow> Arg(exp z) = Im z"
lp15@61762
   872
  by (rule Arg_unique [of  "exp(Re z)"]) (auto simp: exp_eq_polar)
lp15@61762
   873
lp15@61762
   874
lemma complex_split_polar:
lp15@61762
   875
  obtains r a::real where "z = complex_of_real r * (cos a + \<i> * sin a)" "0 \<le> r" "0 \<le> a" "a < 2*pi"
lp15@61762
   876
  using Arg cis.ctr cis_conv_exp by fastforce
lp15@59751
   877
lp15@61806
   878
lemma Re_Im_le_cmod: "Im w * sin \<phi> + Re w * cos \<phi> \<le> cmod w"
lp15@61806
   879
proof (cases w rule: complex_split_polar)
lp15@61806
   880
  case (1 r a) with sin_cos_le1 [of a \<phi>] show ?thesis
lp15@61806
   881
    apply (simp add: norm_mult cmod_unit_one)
lp15@61806
   882
    by (metis (no_types, hide_lams) abs_le_D1 distrib_left mult.commute mult.left_commute mult_left_le)
lp15@61806
   883
qed
lp15@61806
   884
wenzelm@60420
   885
subsection\<open>Analytic properties of tangent function\<close>
lp15@59751
   886
lp15@59751
   887
lemma cnj_tan: "cnj(tan z) = tan(cnj z)"
lp15@59751
   888
  by (simp add: cnj_cos cnj_sin tan_def)
lp15@59751
   889
lp15@59751
   890
lemma complex_differentiable_at_tan: "~(cos z = 0) \<Longrightarrow> tan complex_differentiable at z"
lp15@59751
   891
  unfolding complex_differentiable_def
lp15@59751
   892
  using DERIV_tan by blast
lp15@59751
   893
lp15@59751
   894
lemma complex_differentiable_within_tan: "~(cos z = 0)
lp15@59751
   895
         \<Longrightarrow> tan complex_differentiable (at z within s)"
lp15@59751
   896
  using complex_differentiable_at_tan complex_differentiable_at_within by blast
lp15@59751
   897
lp15@59751
   898
lemma continuous_within_tan: "~(cos z = 0) \<Longrightarrow> continuous (at z within s) tan"
lp15@59751
   899
  using continuous_at_imp_continuous_within isCont_tan by blast
lp15@59751
   900
lp15@59751
   901
lemma continuous_on_tan [continuous_intros]: "(\<And>z. z \<in> s \<Longrightarrow> ~(cos z = 0)) \<Longrightarrow> continuous_on s tan"
lp15@59751
   902
  by (simp add: continuous_at_imp_continuous_on)
lp15@59751
   903
lp15@59751
   904
lemma holomorphic_on_tan: "(\<And>z. z \<in> s \<Longrightarrow> ~(cos z = 0)) \<Longrightarrow> tan holomorphic_on s"
lp15@59751
   905
  by (simp add: complex_differentiable_within_tan holomorphic_on_def)
lp15@59751
   906
lp15@59751
   907
wenzelm@60420
   908
subsection\<open>Complex logarithms (the conventional principal value)\<close>
lp15@59751
   909
lp15@60020
   910
instantiation complex :: ln
lp15@60020
   911
begin
lp15@60017
   912
lp15@60020
   913
definition ln_complex :: "complex \<Rightarrow> complex"
lp15@60020
   914
  where "ln_complex \<equiv> \<lambda>z. THE w. exp w = z & -pi < Im(w) & Im(w) \<le> pi"
lp15@59751
   915
lp15@59751
   916
lemma
lp15@59751
   917
  assumes "z \<noteq> 0"
lp15@60020
   918
    shows exp_Ln [simp]:  "exp(ln z) = z"
lp15@60020
   919
      and mpi_less_Im_Ln: "-pi < Im(ln z)"
lp15@60020
   920
      and Im_Ln_le_pi:    "Im(ln z) \<le> pi"
lp15@59751
   921
proof -
lp15@59751
   922
  obtain \<psi> where z: "z / (cmod z) = Complex (cos \<psi>) (sin \<psi>)"
lp15@59751
   923
    using complex_unimodular_polar [of "z / (norm z)"] assms
lp15@59751
   924
    by (auto simp: norm_divide divide_simps)
lp15@59751
   925
  obtain \<phi> where \<phi>: "- pi < \<phi>" "\<phi> \<le> pi" "sin \<phi> = sin \<psi>" "cos \<phi> = cos \<psi>"
lp15@59751
   926
    using sincos_principal_value [of "\<psi>"] assms
lp15@59751
   927
    by (auto simp: norm_divide divide_simps)
lp15@60020
   928
  have "exp(ln z) = z & -pi < Im(ln z) & Im(ln z) \<le> pi" unfolding ln_complex_def
lp15@59751
   929
    apply (rule theI [where a = "Complex (ln(norm z)) \<phi>"])
lp15@59751
   930
    using z assms \<phi>
lp15@61762
   931
    apply (auto simp: field_simps exp_complex_eqI exp_eq_polar cis.code)
lp15@59751
   932
    done
lp15@60020
   933
  then show "exp(ln z) = z" "-pi < Im(ln z)" "Im(ln z) \<le> pi"
lp15@59751
   934
    by auto
lp15@59751
   935
qed
lp15@59751
   936
lp15@59751
   937
lemma Ln_exp [simp]:
lp15@59751
   938
  assumes "-pi < Im(z)" "Im(z) \<le> pi"
lp15@60020
   939
    shows "ln(exp z) = z"
lp15@59751
   940
  apply (rule exp_complex_eqI)
lp15@59751
   941
  using assms mpi_less_Im_Ln  [of "exp z"] Im_Ln_le_pi [of "exp z"]
lp15@59751
   942
  apply auto
lp15@59751
   943
  done
lp15@59751
   944
wenzelm@60420
   945
subsection\<open>Relation to Real Logarithm\<close>
lp15@60020
   946
lp15@60020
   947
lemma Ln_of_real:
lp15@60020
   948
  assumes "0 < z"
lp15@60020
   949
    shows "ln(of_real z::complex) = of_real(ln z)"
lp15@60020
   950
proof -
lp15@60020
   951
  have "ln(of_real (exp (ln z))::complex) = ln (exp (of_real (ln z)))"
lp15@60020
   952
    by (simp add: exp_of_real)
lp15@60020
   953
  also have "... = of_real(ln z)"
lp15@60020
   954
    using assms
lp15@60020
   955
    by (subst Ln_exp) auto
lp15@60020
   956
  finally show ?thesis
lp15@60020
   957
    using assms by simp
lp15@60020
   958
qed
lp15@60020
   959
lp15@60020
   960
corollary Ln_in_Reals [simp]: "z \<in> \<real> \<Longrightarrow> Re z > 0 \<Longrightarrow> ln z \<in> \<real>"
lp15@60020
   961
  by (auto simp: Ln_of_real elim: Reals_cases)
lp15@60020
   962
lp15@60150
   963
corollary Im_Ln_of_real [simp]: "r > 0 \<Longrightarrow> Im (ln (of_real r)) = 0"
lp15@60150
   964
  by (simp add: Ln_of_real)
lp15@60150
   965
wenzelm@61070
   966
lemma cmod_Ln_Reals [simp]: "z \<in> \<real> \<Longrightarrow> 0 < Re z \<Longrightarrow> cmod (ln z) = norm (ln (Re z))"
lp15@60150
   967
  using Ln_of_real by force
lp15@60150
   968
lp15@60020
   969
lemma Ln_1: "ln 1 = (0::complex)"
lp15@60020
   970
proof -
lp15@60020
   971
  have "ln (exp 0) = (0::complex)"
lp15@60020
   972
    by (metis (mono_tags, hide_lams) Ln_of_real exp_zero ln_one of_real_0 of_real_1 zero_less_one)
lp15@60020
   973
  then show ?thesis
lp15@60020
   974
    by simp
lp15@60020
   975
qed
lp15@60020
   976
lp15@60020
   977
instance
lp15@60020
   978
  by intro_classes (rule ln_complex_def Ln_1)
lp15@60020
   979
lp15@60020
   980
end
lp15@60020
   981
lp15@60020
   982
abbreviation Ln :: "complex \<Rightarrow> complex"
lp15@60020
   983
  where "Ln \<equiv> ln"
lp15@60020
   984
lp15@59751
   985
lemma Ln_eq_iff: "w \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> (Ln w = Ln z \<longleftrightarrow> w = z)"
lp15@59751
   986
  by (metis exp_Ln)
lp15@59751
   987
lp15@59751
   988
lemma Ln_unique: "exp(z) = w \<Longrightarrow> -pi < Im(z) \<Longrightarrow> Im(z) \<le> pi \<Longrightarrow> Ln w = z"
lp15@59751
   989
  using Ln_exp by blast
lp15@59751
   990
lp15@59751
   991
lemma Re_Ln [simp]: "z \<noteq> 0 \<Longrightarrow> Re(Ln z) = ln(norm z)"
lp15@60150
   992
  by (metis exp_Ln assms ln_exp norm_exp_eq_Re)
lp15@60150
   993
lp15@61609
   994
corollary ln_cmod_le:
lp15@60150
   995
  assumes z: "z \<noteq> 0"
lp15@60150
   996
    shows "ln (cmod z) \<le> cmod (Ln z)"
lp15@60150
   997
  using norm_exp [of "Ln z", simplified exp_Ln [OF z]]
lp15@60150
   998
  by (metis Re_Ln complex_Re_le_cmod z)
lp15@59751
   999
lp15@59751
  1000
lemma exists_complex_root:
lp15@59751
  1001
  fixes a :: complex
lp15@59751
  1002
  shows "n \<noteq> 0 \<Longrightarrow> \<exists>z. z ^ n = a"
lp15@59751
  1003
  apply (cases "a=0", simp)
lp15@59751
  1004
  apply (rule_tac x= "exp(Ln(a) / n)" in exI)
lp15@59751
  1005
  apply (auto simp: exp_of_nat_mult [symmetric])
lp15@59751
  1006
  done
lp15@59751
  1007
wenzelm@60420
  1008
subsection\<open>The Unwinding Number and the Ln-product Formula\<close>
wenzelm@60420
  1009
wenzelm@60420
  1010
text\<open>Note that in this special case the unwinding number is -1, 0 or 1.\<close>
lp15@59862
  1011
lp15@59862
  1012
definition unwinding :: "complex \<Rightarrow> complex" where
lp15@59862
  1013
   "unwinding(z) = (z - Ln(exp z)) / (of_real(2*pi) * ii)"
lp15@59862
  1014
lp15@59862
  1015
lemma unwinding_2pi: "(2*pi) * ii * unwinding(z) = z - Ln(exp z)"
lp15@59862
  1016
  by (simp add: unwinding_def)
lp15@59862
  1017
lp15@59862
  1018
lemma Ln_times_unwinding:
lp15@59862
  1019
    "w \<noteq> 0 \<Longrightarrow> z \<noteq> 0 \<Longrightarrow> Ln(w * z) = Ln(w) + Ln(z) - (2*pi) * ii * unwinding(Ln w + Ln z)"
lp15@59862
  1020
  using unwinding_2pi by (simp add: exp_add)
lp15@59862
  1021
lp15@59862
  1022
wenzelm@60420
  1023
subsection\<open>Derivative of Ln away from the branch cut\<close>
lp15@59751
  1024
lp15@59751
  1025
lemma
paulson@62131
  1026
  assumes "z \<notin> \<real>\<^sub>\<le>\<^sub>0"
lp15@59751
  1027
    shows has_field_derivative_Ln: "(Ln has_field_derivative inverse(z)) (at z)"
lp15@59751
  1028
      and Im_Ln_less_pi:           "Im (Ln z) < pi"
lp15@59751
  1029
proof -
lp15@59751
  1030
  have znz: "z \<noteq> 0"
lp15@59751
  1031
    using assms by auto
paulson@62131
  1032
  then have "Im (Ln z) \<noteq> pi"
paulson@62131
  1033
    by (metis (no_types) Im_exp Ln_in_Reals assms complex_nonpos_Reals_iff complex_is_Real_iff exp_Ln mult_zero_right not_less pi_neq_zero sin_pi znz)
paulson@62131
  1034
  then show *: "Im (Ln z) < pi" using assms Im_Ln_le_pi
paulson@62131
  1035
    by (simp add: le_neq_trans znz)
lp15@59751
  1036
  show "(Ln has_field_derivative inverse(z)) (at z)"
lp15@59751
  1037
    apply (rule has_complex_derivative_inverse_strong_x
lp15@59751
  1038
              [where f = exp and s = "{w. -pi < Im(w) & Im(w) < pi}"])
lp15@59751
  1039
    using znz *
lp15@59751
  1040
    apply (auto simp: continuous_on_exp open_Collect_conj open_halfspace_Im_gt open_halfspace_Im_lt)
lp15@59751
  1041
    apply (metis DERIV_exp exp_Ln)
lp15@59751
  1042
    apply (metis mpi_less_Im_Ln)
lp15@59751
  1043
    done
lp15@59751
  1044
qed
lp15@59751
  1045
lp15@59751
  1046
declare has_field_derivative_Ln [derivative_intros]
lp15@59751
  1047
declare has_field_derivative_Ln [THEN DERIV_chain2, derivative_intros]
lp15@59751
  1048
paulson@62131
  1049
lemma complex_differentiable_at_Ln: "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> Ln complex_differentiable at z"
lp15@59751
  1050
  using complex_differentiable_def has_field_derivative_Ln by blast
lp15@59751
  1051
paulson@62131
  1052
lemma complex_differentiable_within_Ln: "z \<notin> \<real>\<^sub>\<le>\<^sub>0
lp15@59751
  1053
         \<Longrightarrow> Ln complex_differentiable (at z within s)"
lp15@59751
  1054
  using complex_differentiable_at_Ln complex_differentiable_within_subset by blast
lp15@59751
  1055
paulson@62131
  1056
lemma continuous_at_Ln: "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> continuous (at z) Ln"
lp15@59751
  1057
  by (simp add: complex_differentiable_imp_continuous_at complex_differentiable_within_Ln)
lp15@59751
  1058
lp15@59862
  1059
lemma isCont_Ln' [simp]:
paulson@62131
  1060
   "\<lbrakk>isCont f z; f z \<notin> \<real>\<^sub>\<le>\<^sub>0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. Ln (f x)) z"
lp15@59862
  1061
  by (blast intro: isCont_o2 [OF _ continuous_at_Ln])
lp15@59862
  1062
paulson@62131
  1063
lemma continuous_within_Ln: "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> continuous (at z within s) Ln"
lp15@59751
  1064
  using continuous_at_Ln continuous_at_imp_continuous_within by blast
lp15@59751
  1065
paulson@62131
  1066
lemma continuous_on_Ln [continuous_intros]: "(\<And>z. z \<in> s \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> continuous_on s Ln"
lp15@59751
  1067
  by (simp add: continuous_at_imp_continuous_on continuous_within_Ln)
lp15@59751
  1068
paulson@62131
  1069
lemma holomorphic_on_Ln: "(\<And>z. z \<in> s \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> Ln holomorphic_on s"
lp15@59751
  1070
  by (simp add: complex_differentiable_within_Ln holomorphic_on_def)
lp15@59751
  1071
lp15@59751
  1072
wenzelm@60420
  1073
subsection\<open>Quadrant-type results for Ln\<close>
lp15@59751
  1074
lp15@59751
  1075
lemma cos_lt_zero_pi: "pi/2 < x \<Longrightarrow> x < 3*pi/2 \<Longrightarrow> cos x < 0"
lp15@59751
  1076
  using cos_minus_pi cos_gt_zero_pi [of "x-pi"]
lp15@59751
  1077
  by simp
lp15@59751
  1078
lp15@59751
  1079
lemma Re_Ln_pos_lt:
lp15@59751
  1080
  assumes "z \<noteq> 0"
wenzelm@61945
  1081
    shows "\<bar>Im(Ln z)\<bar> < pi/2 \<longleftrightarrow> 0 < Re(z)"
lp15@59751
  1082
proof -
lp15@59751
  1083
  { fix w
lp15@59751
  1084
    assume "w = Ln z"
lp15@59751
  1085
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1086
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1087
      by auto
wenzelm@61945
  1088
    then have "\<bar>Im w\<bar> < pi/2 \<longleftrightarrow> 0 < Re(exp w)"
lp15@59751
  1089
      apply (auto simp: Re_exp zero_less_mult_iff cos_gt_zero_pi)
lp15@59751
  1090
      using cos_lt_zero_pi [of "-(Im w)"] cos_lt_zero_pi [of "(Im w)"]
lp15@59751
  1091
      apply (simp add: abs_if split: split_if_asm)
lp15@59751
  1092
      apply (metis (no_types) cos_minus cos_pi_half eq_divide_eq_numeral1(1) eq_numeral_simps(4)
lp15@59751
  1093
               less_numeral_extra(3) linorder_neqE_linordered_idom minus_mult_minus minus_mult_right
lp15@59751
  1094
               mult_numeral_1_right)
lp15@59751
  1095
      done
lp15@59751
  1096
  }
lp15@59751
  1097
  then show ?thesis using assms
lp15@59751
  1098
    by auto
lp15@59751
  1099
qed
lp15@59751
  1100
lp15@59751
  1101
lemma Re_Ln_pos_le:
lp15@59751
  1102
  assumes "z \<noteq> 0"
wenzelm@61945
  1103
    shows "\<bar>Im(Ln z)\<bar> \<le> pi/2 \<longleftrightarrow> 0 \<le> Re(z)"
lp15@59751
  1104
proof -
lp15@59751
  1105
  { fix w
lp15@59751
  1106
    assume "w = Ln z"
lp15@59751
  1107
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1108
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1109
      by auto
wenzelm@61945
  1110
    then have "\<bar>Im w\<bar> \<le> pi/2 \<longleftrightarrow> 0 \<le> Re(exp w)"
lp15@59751
  1111
      apply (auto simp: Re_exp zero_le_mult_iff cos_ge_zero)
lp15@59751
  1112
      using cos_lt_zero_pi [of "- (Im w)"] cos_lt_zero_pi [of "(Im w)"] not_le
lp15@59751
  1113
      apply (auto simp: abs_if split: split_if_asm)
lp15@59751
  1114
      done
lp15@59751
  1115
  }
lp15@59751
  1116
  then show ?thesis using assms
lp15@59751
  1117
    by auto
lp15@59751
  1118
qed
lp15@59751
  1119
lp15@59751
  1120
lemma Im_Ln_pos_lt:
lp15@59751
  1121
  assumes "z \<noteq> 0"
lp15@59751
  1122
    shows "0 < Im(Ln z) \<and> Im(Ln z) < pi \<longleftrightarrow> 0 < Im(z)"
lp15@59751
  1123
proof -
lp15@59751
  1124
  { fix w
lp15@59751
  1125
    assume "w = Ln z"
lp15@59751
  1126
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1127
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1128
      by auto
lp15@59751
  1129
    then have "0 < Im w \<and> Im w < pi \<longleftrightarrow> 0 < Im(exp w)"
lp15@59751
  1130
      using sin_gt_zero [of "- (Im w)"] sin_gt_zero [of "(Im w)"]
lp15@59751
  1131
      apply (auto simp: Im_exp zero_less_mult_iff)
lp15@59751
  1132
      using less_linear apply fastforce
lp15@59751
  1133
      using less_linear apply fastforce
lp15@59751
  1134
      done
lp15@59751
  1135
  }
lp15@59751
  1136
  then show ?thesis using assms
lp15@59751
  1137
    by auto
lp15@59751
  1138
qed
lp15@59751
  1139
lp15@59751
  1140
lemma Im_Ln_pos_le:
lp15@59751
  1141
  assumes "z \<noteq> 0"
lp15@59751
  1142
    shows "0 \<le> Im(Ln z) \<and> Im(Ln z) \<le> pi \<longleftrightarrow> 0 \<le> Im(z)"
lp15@59751
  1143
proof -
lp15@59751
  1144
  { fix w
lp15@59751
  1145
    assume "w = Ln z"
lp15@59751
  1146
    then have w: "Im w \<le> pi" "- pi < Im w"
lp15@59751
  1147
      using Im_Ln_le_pi [of z]  mpi_less_Im_Ln [of z]  assms
lp15@59751
  1148
      by auto
lp15@59751
  1149
    then have "0 \<le> Im w \<and> Im w \<le> pi \<longleftrightarrow> 0 \<le> Im(exp w)"
lp15@59751
  1150
      using sin_ge_zero [of "- (Im w)"] sin_ge_zero [of "(Im w)"]
lp15@59751
  1151
      apply (auto simp: Im_exp zero_le_mult_iff sin_ge_zero)
lp15@59751
  1152
      apply (metis not_le not_less_iff_gr_or_eq pi_not_less_zero sin_eq_0_pi)
lp15@59751
  1153
      done }
lp15@59751
  1154
  then show ?thesis using assms
lp15@59751
  1155
    by auto
lp15@59751
  1156
qed
lp15@59751
  1157
wenzelm@61945
  1158
lemma Re_Ln_pos_lt_imp: "0 < Re(z) \<Longrightarrow> \<bar>Im(Ln z)\<bar> < pi/2"
lp15@59751
  1159
  by (metis Re_Ln_pos_lt less_irrefl zero_complex.simps(1))
lp15@59751
  1160
lp15@59751
  1161
lemma Im_Ln_pos_lt_imp: "0 < Im(z) \<Longrightarrow> 0 < Im(Ln z) \<and> Im(Ln z) < pi"
lp15@59751
  1162
  by (metis Im_Ln_pos_lt not_le order_refl zero_complex.simps(2))
lp15@59751
  1163
paulson@62131
  1164
text\<open>A reference to the set of positive real numbers\<close>
lp15@59751
  1165
lemma Im_Ln_eq_0: "z \<noteq> 0 \<Longrightarrow> (Im(Ln z) = 0 \<longleftrightarrow> 0 < Re(z) \<and> Im(z) = 0)"
paulson@62131
  1166
by (metis Im_complex_of_real Im_exp Ln_in_Reals Re_Ln_pos_lt Re_Ln_pos_lt_imp 
paulson@62131
  1167
          Re_complex_of_real complex_is_Real_iff exp_Ln exp_of_real pi_gt_zero)
lp15@59751
  1168
lp15@59751
  1169
lemma Im_Ln_eq_pi: "z \<noteq> 0 \<Longrightarrow> (Im(Ln z) = pi \<longleftrightarrow> Re(z) < 0 \<and> Im(z) = 0)"
paulson@62131
  1170
by (metis Im_Ln_eq_0 Im_Ln_pos_le Im_Ln_pos_lt add.left_neutral complex_eq less_eq_real_def 
paulson@62131
  1171
    mult_zero_right not_less_iff_gr_or_eq pi_ge_zero pi_neq_zero rcis_zero_arg rcis_zero_mod)
lp15@59751
  1172
lp15@59751
  1173
wenzelm@60420
  1174
subsection\<open>More Properties of Ln\<close>
lp15@59751
  1175
paulson@62131
  1176
lemma cnj_Ln: "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> cnj(Ln z) = Ln(cnj z)"
lp15@59751
  1177
  apply (cases "z=0", auto)
lp15@59751
  1178
  apply (rule exp_complex_eqI)
lp15@59751
  1179
  apply (auto simp: abs_if split: split_if_asm)
paulson@62131
  1180
  using Im_Ln_less_pi Im_Ln_le_pi apply force
paulson@62131
  1181
  apply (metis complex_cnj_zero_iff diff_minus_eq_add diff_strict_mono minus_less_iff 
paulson@62131
  1182
          mpi_less_Im_Ln mult.commute mult_2_right)
lp15@59751
  1183
  by (metis exp_Ln exp_cnj)
lp15@59751
  1184
paulson@62131
  1185
lemma Ln_inverse: "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> Ln(inverse z) = -(Ln z)"
lp15@59751
  1186
  apply (cases "z=0", auto)
lp15@59751
  1187
  apply (rule exp_complex_eqI)
lp15@59751
  1188
  using mpi_less_Im_Ln [of z] mpi_less_Im_Ln [of "inverse z"]
lp15@59751
  1189
  apply (auto simp: abs_if exp_minus split: split_if_asm)
paulson@62131
  1190
  apply (metis Im_Ln_less_pi Im_Ln_le_pi add.commute add_mono_thms_linordered_field(3) inverse_nonzero_iff_nonzero mult_2)
lp15@59751
  1191
  done
lp15@59751
  1192
lp15@59751
  1193
lemma Ln_minus1 [simp]: "Ln(-1) = ii * pi"
lp15@59751
  1194
  apply (rule exp_complex_eqI)
lp15@59751
  1195
  using Im_Ln_le_pi [of "-1"] mpi_less_Im_Ln [of "-1"] cis_conv_exp cis_pi
lp15@59751
  1196
  apply (auto simp: abs_if)
lp15@59751
  1197
  done
lp15@59751
  1198
lp15@59751
  1199
lemma Ln_ii [simp]: "Ln ii = ii * of_real pi/2"
lp15@59751
  1200
  using Ln_exp [of "ii * (of_real pi/2)"]
lp15@59751
  1201
  unfolding exp_Euler
lp15@59751
  1202
  by simp
lp15@59751
  1203
lp15@59751
  1204
lemma Ln_minus_ii [simp]: "Ln(-ii) = - (ii * pi/2)"
lp15@59751
  1205
proof -
paulson@62131
  1206
  have  "Ln(-ii) = Ln(inverse ii)"    by simp
paulson@62131
  1207
  also have "... = - (Ln ii)"         using Ln_inverse by blast
paulson@62131
  1208
  also have "... = - (ii * pi/2)"     by simp
lp15@59751
  1209
  finally show ?thesis .
lp15@59751
  1210
qed
lp15@59751
  1211
lp15@59751
  1212
lemma Ln_times:
lp15@59751
  1213
  assumes "w \<noteq> 0" "z \<noteq> 0"
lp15@59751
  1214
    shows "Ln(w * z) =
lp15@59751
  1215
                (if Im(Ln w + Ln z) \<le> -pi then
lp15@59751
  1216
                  (Ln(w) + Ln(z)) + ii * of_real(2*pi)
lp15@59751
  1217
                else if Im(Ln w + Ln z) > pi then
lp15@59751
  1218
                  (Ln(w) + Ln(z)) - ii * of_real(2*pi)
lp15@59751
  1219
                else Ln(w) + Ln(z))"
lp15@59751
  1220
  using pi_ge_zero Im_Ln_le_pi [of w] Im_Ln_le_pi [of z]
lp15@59751
  1221
  using assms mpi_less_Im_Ln [of w] mpi_less_Im_Ln [of z]
paulson@62131
  1222
  by (auto simp: exp_add exp_diff sin_double cos_double exp_Euler intro!: Ln_unique)
lp15@59751
  1223
lp15@60150
  1224
corollary Ln_times_simple:
lp15@59751
  1225
    "\<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
  1226
         \<Longrightarrow> Ln(w * z) = Ln(w) + Ln(z)"
lp15@59751
  1227
  by (simp add: Ln_times)
lp15@59751
  1228
lp15@60150
  1229
corollary Ln_times_of_real:
lp15@60150
  1230
    "\<lbrakk>r > 0; z \<noteq> 0\<rbrakk> \<Longrightarrow> Ln(of_real r * z) = ln r + Ln(z)"
lp15@60150
  1231
  using mpi_less_Im_Ln Im_Ln_le_pi
lp15@60150
  1232
  by (force simp: Ln_times)
lp15@60150
  1233
lp15@60150
  1234
corollary Ln_divide_of_real:
lp15@60150
  1235
    "\<lbrakk>r > 0; z \<noteq> 0\<rbrakk> \<Longrightarrow> Ln(z / of_real r) = Ln(z) - ln r"
lp15@60150
  1236
using Ln_times_of_real [of "inverse r" z]
lp15@61609
  1237
by (simp add: ln_inverse Ln_of_real mult.commute divide_inverse of_real_inverse [symmetric]
lp15@60150
  1238
         del: of_real_inverse)
lp15@60150
  1239
lp15@59751
  1240
lemma Ln_minus:
lp15@59751
  1241
  assumes "z \<noteq> 0"
lp15@59751
  1242
    shows "Ln(-z) = (if Im(z) \<le> 0 \<and> ~(Re(z) < 0 \<and> Im(z) = 0)
lp15@59751
  1243
                     then Ln(z) + ii * pi
lp15@59751
  1244
                     else Ln(z) - ii * pi)" (is "_ = ?rhs")
lp15@59751
  1245
  using Im_Ln_le_pi [of z] mpi_less_Im_Ln [of z] assms
lp15@59751
  1246
        Im_Ln_eq_pi [of z] Im_Ln_pos_lt [of z]
paulson@62131
  1247
    by (fastforce simp: exp_add exp_diff exp_Euler intro!: Ln_unique)
lp15@59751
  1248
lp15@59751
  1249
lemma Ln_inverse_if:
lp15@59751
  1250
  assumes "z \<noteq> 0"
paulson@62131
  1251
    shows "Ln (inverse z) = (if z \<in> \<real>\<^sub>\<le>\<^sub>0 then -(Ln z) + \<i> * 2 * complex_of_real pi else -(Ln z))"
paulson@62131
  1252
proof (cases "z \<in> \<real>\<^sub>\<le>\<^sub>0")
paulson@62131
  1253
  case False then show ?thesis
lp15@59751
  1254
    by (simp add: Ln_inverse)
lp15@59751
  1255
next
paulson@62131
  1256
  case True
lp15@59751
  1257
  then have z: "Im z = 0" "Re z < 0"
lp15@59751
  1258
    using assms
paulson@62131
  1259
    apply (auto simp: complex_nonpos_Reals_iff)
paulson@62131
  1260
    by (metis complex_is_Real_iff le_imp_less_or_eq of_real_0 of_real_Re)
lp15@59751
  1261
  have "Ln(inverse z) = Ln(- (inverse (-z)))"
lp15@59751
  1262
    by simp
lp15@59751
  1263
  also have "... = Ln (inverse (-z)) + \<i> * complex_of_real pi"
lp15@59751
  1264
    using assms z
lp15@59751
  1265
    apply (simp add: Ln_minus)
lp15@59751
  1266
    apply (simp add: field_simps)
lp15@59751
  1267
    done
lp15@59751
  1268
  also have "... = - Ln (- z) + \<i> * complex_of_real pi"
lp15@59751
  1269
    apply (subst Ln_inverse)
paulson@62131
  1270
    using z by (auto simp add: complex_nonneg_Reals_iff) 
lp15@59751
  1271
  also have "... = - (Ln z) + \<i> * 2 * complex_of_real pi"
lp15@59751
  1272
    apply (subst Ln_minus [OF assms])
lp15@59751
  1273
    using assms z
lp15@59751
  1274
    apply simp
lp15@59751
  1275
    done
paulson@62131
  1276
  finally show ?thesis by (simp add: True)
lp15@59751
  1277
qed
lp15@59751
  1278
lp15@59751
  1279
lemma Ln_times_ii:
lp15@59751
  1280
  assumes "z \<noteq> 0"
lp15@59751
  1281
    shows  "Ln(ii * z) = (if 0 \<le> Re(z) | Im(z) < 0
lp15@59751
  1282
                          then Ln(z) + ii * of_real pi/2
lp15@59751
  1283
                          else Ln(z) - ii * of_real(3 * pi/2))"
lp15@59751
  1284
  using Im_Ln_le_pi [of z] mpi_less_Im_Ln [of z] assms
lp15@59751
  1285
        Im_Ln_eq_pi [of z] Im_Ln_pos_lt [of z] Re_Ln_pos_le [of z]
paulson@62131
  1286
  by (auto simp: Ln_times)
lp15@59751
  1287
eberlm@61524
  1288
lemma Ln_of_nat: "0 < n \<Longrightarrow> Ln (of_nat n) = of_real (ln (of_nat n))"
eberlm@61524
  1289
  by (subst of_real_of_nat_eq[symmetric], subst Ln_of_real[symmetric]) simp_all
eberlm@61524
  1290
lp15@61609
  1291
lemma Ln_of_nat_over_of_nat:
eberlm@61524
  1292
  assumes "m > 0" "n > 0"
eberlm@61524
  1293
  shows   "Ln (of_nat m / of_nat n) = of_real (ln (of_nat m) - ln (of_nat n))"
eberlm@61524
  1294
proof -
eberlm@61524
  1295
  have "of_nat m / of_nat n = (of_real (of_nat m / of_nat n) :: complex)" by simp
eberlm@61524
  1296
  also from assms have "Ln ... = of_real (ln (of_nat m / of_nat n))"
eberlm@61524
  1297
    by (simp add: Ln_of_real[symmetric])
eberlm@61524
  1298
  also from assms have "... = of_real (ln (of_nat m) - ln (of_nat n))"
eberlm@61524
  1299
    by (simp add: ln_div)
eberlm@61524
  1300
  finally show ?thesis .
eberlm@61524
  1301
qed
eberlm@61524
  1302
lp15@59751
  1303
wenzelm@60420
  1304
subsection\<open>Relation between Ln and Arg, and hence continuity of Arg\<close>
lp15@60150
  1305
lp15@61609
  1306
lemma Arg_Ln:
lp15@60150
  1307
  assumes "0 < Arg z" shows "Arg z = Im(Ln(-z)) + pi"
lp15@60150
  1308
proof (cases "z = 0")
lp15@60150
  1309
  case True
lp15@60150
  1310
  with assms show ?thesis
lp15@60150
  1311
    by simp
lp15@60150
  1312
next
lp15@60150
  1313
  case False
lp15@60150
  1314
  then have "z / of_real(norm z) = exp(ii * of_real(Arg z))"
lp15@60150
  1315
    using Arg [of z]
lp15@60150
  1316
    by (metis abs_norm_cancel nonzero_mult_divide_cancel_left norm_of_real zero_less_norm_iff)
lp15@60150
  1317
  then have "- z / of_real(norm z) = exp (\<i> * (of_real (Arg z) - pi))"
lp15@60150
  1318
    using cis_conv_exp cis_pi
lp15@60150
  1319
    by (auto simp: exp_diff algebra_simps)
lp15@60150
  1320
  then have "ln (- z / of_real(norm z)) = ln (exp (\<i> * (of_real (Arg z) - pi)))"
lp15@60150
  1321
    by simp
lp15@60150
  1322
  also have "... = \<i> * (of_real(Arg z) - pi)"
lp15@60150
  1323
    using Arg [of z] assms pi_not_less_zero
lp15@60150
  1324
    by auto
lp15@60150
  1325
  finally have "Arg z =  Im (Ln (- z / of_real (cmod z))) + pi"
lp15@60150
  1326
    by simp
lp15@60150
  1327
  also have "... = Im (Ln (-z) - ln (cmod z)) + pi"
lp15@60150
  1328
    by (metis diff_0_right minus_diff_eq zero_less_norm_iff Ln_divide_of_real False)
lp15@60150
  1329
  also have "... = Im (Ln (-z)) + pi"
lp15@60150
  1330
    by simp
lp15@60150
  1331
  finally show ?thesis .
lp15@60150
  1332
qed
lp15@60150
  1333
lp15@61609
  1334
lemma continuous_at_Arg:
paulson@62131
  1335
  assumes "z \<notin> \<real>\<^sub>\<ge>\<^sub>0"
lp15@60150
  1336
    shows "continuous (at z) Arg"
lp15@60150
  1337
proof -
lp15@60150
  1338
  have *: "isCont (\<lambda>z. Im (Ln (- z)) + pi) z"
lp15@60150
  1339
    by (rule Complex.isCont_Im isCont_Ln' continuous_intros | simp add: assms complex_is_Real_iff)+
paulson@62131
  1340
  have [simp]: "\<And>x. \<lbrakk>Im x \<noteq> 0\<rbrakk> \<Longrightarrow> Im (Ln (- x)) + pi = Arg x"
paulson@62131
  1341
      using Arg_Ln Arg_gt_0 complex_is_Real_iff by auto
paulson@62131
  1342
  consider "Re z < 0" | "Im z \<noteq> 0" using assms
paulson@62131
  1343
    using complex_nonneg_Reals_iff not_le by blast 
paulson@62131
  1344
  then have [simp]: "(\<lambda>z. Im (Ln (- z)) + pi) \<midarrow>z\<rightarrow> Arg z"
paulson@62131
  1345
      using "*"  by (simp add: isCont_def) (metis Arg_Ln Arg_gt_0 complex_is_Real_iff)
paulson@62131
  1346
  show ?thesis
paulson@62131
  1347
      apply (simp add: continuous_at)
paulson@62131
  1348
      apply (rule Lim_transform_within_open [where s= "-\<real>\<^sub>\<ge>\<^sub>0" and f = "\<lambda>z. Im(Ln(-z)) + pi"])
paulson@62131
  1349
      apply (auto simp add: not_le Arg_Ln [OF Arg_gt_0] complex_nonneg_Reals_iff closed_def [symmetric])
paulson@62131
  1350
      using assms apply (force simp add: complex_nonneg_Reals_iff)
paulson@62131
  1351
      done
lp15@60150
  1352
qed
lp15@60150
  1353
eberlm@62049
  1354
lemma Ln_series:
eberlm@62049
  1355
  fixes z :: complex
eberlm@62049
  1356
  assumes "norm z < 1"
eberlm@62049
  1357
  shows   "(\<lambda>n. (-1)^Suc n / of_nat n * z^n) sums ln (1 + z)" (is "(\<lambda>n. ?f n * z^n) sums _")
eberlm@62049
  1358
proof -
eberlm@62049
  1359
  let ?F = "\<lambda>z. \<Sum>n. ?f n * z^n" and ?F' = "\<lambda>z. \<Sum>n. diffs ?f n * z^n"
eberlm@62049
  1360
  have r: "conv_radius ?f = 1"
eberlm@62049
  1361
    by (intro conv_radius_ratio_limit_nonzero[of _ 1])
eberlm@62049
  1362
       (simp_all add: norm_divide LIMSEQ_Suc_n_over_n del: of_nat_Suc)
eberlm@62049
  1363
eberlm@62049
  1364
  have "\<exists>c. \<forall>z\<in>ball 0 1. ln (1 + z) - ?F z = c"
eberlm@62049
  1365
  proof (rule has_field_derivative_zero_constant)
eberlm@62049
  1366
    fix z :: complex assume z': "z \<in> ball 0 1"
eberlm@62049
  1367
    hence z: "norm z < 1" by (simp add: dist_0_norm)
eberlm@62049
  1368
    def t \<equiv> "of_real (1 + norm z) / 2 :: complex"
eberlm@62049
  1369
    from z have t: "norm z < norm t" "norm t < 1" unfolding t_def
eberlm@62049
  1370
      by (simp_all add: field_simps norm_divide del: of_real_add)
eberlm@62049
  1371
eberlm@62049
  1372
    have "Re (-z) \<le> norm (-z)" by (rule complex_Re_le_cmod)
eberlm@62049
  1373
    also from z have "... < 1" by simp
eberlm@62049
  1374
    finally have "((\<lambda>z. ln (1 + z)) has_field_derivative inverse (1+z)) (at z)"
paulson@62131
  1375
      by (auto intro!: derivative_eq_intros simp: complex_nonpos_Reals_iff)
eberlm@62049
  1376
    moreover have "(?F has_field_derivative ?F' z) (at z)" using t r
eberlm@62049
  1377
      by (intro termdiffs_strong[of _ t] summable_in_conv_radius) simp_all
eberlm@62049
  1378
    ultimately have "((\<lambda>z. ln (1 + z) - ?F z) has_field_derivative (inverse (1 + z) - ?F' z)) 
eberlm@62049
  1379
                       (at z within ball 0 1)"
eberlm@62049
  1380
      by (intro derivative_intros) (simp_all add: at_within_open[OF z'])
eberlm@62049
  1381
    also have "(\<lambda>n. of_nat n * ?f n * z ^ (n - Suc 0)) sums ?F' z" using t r
eberlm@62049
  1382
      by (intro diffs_equiv termdiff_converges[OF t(1)] summable_in_conv_radius) simp_all
eberlm@62049
  1383
    from sums_split_initial_segment[OF this, of 1]
eberlm@62049
  1384
      have "(\<lambda>i. (-z) ^ i) sums ?F' z" by (simp add: power_minus[of z] del: of_nat_Suc)
eberlm@62049
  1385
    hence "?F' z = inverse (1 + z)" using z by (simp add: sums_iff suminf_geometric divide_inverse)
eberlm@62049
  1386
    also have "inverse (1 + z) - inverse (1 + z) = 0" by simp
eberlm@62049
  1387
    finally show "((\<lambda>z. ln (1 + z) - ?F z) has_field_derivative 0) (at z within ball 0 1)" .
eberlm@62049
  1388
  qed simp_all
eberlm@62049
  1389
  then obtain c where c: "\<And>z. z \<in> ball 0 1 \<Longrightarrow> ln (1 + z) - ?F z = c" by blast
eberlm@62049
  1390
  from c[of 0] have "c = 0" by (simp only: powser_zero) simp
eberlm@62049
  1391
  with c[of z] assms have "ln (1 + z) = ?F z" by (simp add: dist_0_norm)
eberlm@62049
  1392
  moreover have "summable (\<lambda>n. ?f n * z^n)" using assms r
eberlm@62049
  1393
    by (intro summable_in_conv_radius) simp_all
eberlm@62049
  1394
  ultimately show ?thesis by (simp add: sums_iff)
eberlm@62049
  1395
qed
eberlm@62049
  1396
eberlm@62049
  1397
lemma Ln_approx_linear:
eberlm@62049
  1398
  fixes z :: complex
eberlm@62049
  1399
  assumes "norm z < 1"
eberlm@62049
  1400
  shows   "norm (ln (1 + z) - z) \<le> norm z^2 / (1 - norm z)"
eberlm@62049
  1401
proof -
eberlm@62049
  1402
  let ?f = "\<lambda>n. (-1)^Suc n / of_nat n"
eberlm@62049
  1403
  from assms have "(\<lambda>n. ?f n * z^n) sums ln (1 + z)" using Ln_series by simp
eberlm@62049
  1404
  moreover have "(\<lambda>n. (if n = 1 then 1 else 0) * z^n) sums z" using powser_sums_if[of 1] by simp
eberlm@62049
  1405
  ultimately have "(\<lambda>n. (?f n - (if n = 1 then 1 else 0)) * z^n) sums (ln (1 + z) - z)"
eberlm@62049
  1406
    by (subst left_diff_distrib, intro sums_diff) simp_all
eberlm@62049
  1407
  from sums_split_initial_segment[OF this, of "Suc 1"]
eberlm@62049
  1408
    have "(\<lambda>i. (-(z^2)) * inverse (2 + of_nat i) * (- z)^i) sums (Ln (1 + z) - z)"
eberlm@62049
  1409
    by (simp add: power2_eq_square mult_ac power_minus[of z] divide_inverse)
eberlm@62049
  1410
  hence "(Ln (1 + z) - z) = (\<Sum>i. (-(z^2)) * inverse (of_nat (i+2)) * (-z)^i)"
eberlm@62049
  1411
    by (simp add: sums_iff)
eberlm@62049
  1412
  also have A: "summable (\<lambda>n. norm z^2 * (inverse (real_of_nat (Suc (Suc n))) * cmod z ^ n))"
eberlm@62049
  1413
    by (rule summable_mult, rule summable_comparison_test_ev[OF _ summable_geometric[of "norm z"]])
eberlm@62049
  1414
       (auto simp: assms field_simps intro!: always_eventually)
eberlm@62049
  1415
  hence "norm (\<Sum>i. (-(z^2)) * inverse (of_nat (i+2)) * (-z)^i) \<le> 
eberlm@62049
  1416
             (\<Sum>i. norm (-(z^2) * inverse (of_nat (i+2)) * (-z)^i))"
eberlm@62049
  1417
    by (intro summable_norm)
eberlm@62049
  1418
       (auto simp: norm_power norm_inverse norm_mult mult_ac simp del: of_nat_add of_nat_Suc)
eberlm@62049
  1419
  also have "norm ((-z)^2 * (-z)^i) * inverse (of_nat (i+2)) \<le> norm ((-z)^2 * (-z)^i) * 1" for i
eberlm@62049
  1420
    by (intro mult_left_mono) (simp_all add: divide_simps)
eberlm@62049
  1421
  hence "(\<Sum>i. norm (-(z^2) * inverse (of_nat (i+2)) * (-z)^i)) \<le> 
eberlm@62049
  1422
           (\<Sum>i. norm (-(z^2) * (-z)^i))" using A assms
eberlm@62049
  1423
    apply (simp_all only: norm_power norm_inverse norm_divide norm_mult)
eberlm@62049
  1424
    apply (intro suminf_le summable_mult summable_geometric)
eberlm@62049
  1425
    apply (auto simp: norm_power field_simps simp del: of_nat_add of_nat_Suc)
eberlm@62049
  1426
    done
eberlm@62049
  1427
  also have "... = norm z^2 * (\<Sum>i. norm z^i)" using assms
eberlm@62049
  1428
    by (subst suminf_mult [symmetric]) (auto intro!: summable_geometric simp: norm_mult norm_power)
eberlm@62049
  1429
  also have "(\<Sum>i. norm z^i) = inverse (1 - norm z)" using assms
eberlm@62049
  1430
    by (subst suminf_geometric) (simp_all add: divide_inverse)
eberlm@62049
  1431
  also have "norm z^2 * ... = norm z^2 / (1 - norm z)" by (simp add: divide_inverse)
eberlm@62049
  1432
  finally show ?thesis .
eberlm@62049
  1433
qed
eberlm@62049
  1434
eberlm@62049
  1435
wenzelm@60420
  1436
text\<open>Relation between Arg and arctangent in upper halfplane\<close>
lp15@61609
  1437
lemma Arg_arctan_upperhalf:
lp15@60150
  1438
  assumes "0 < Im z"
lp15@60150
  1439
    shows "Arg z = pi/2 - arctan(Re z / Im z)"
lp15@60150
  1440
proof (cases "z = 0")
lp15@60150
  1441
  case True with assms show ?thesis
lp15@60150
  1442
    by simp
lp15@60150
  1443
next
lp15@60150
  1444
  case False
lp15@60150
  1445
  show ?thesis
lp15@60150
  1446
    apply (rule Arg_unique [of "norm z"])
lp15@60150
  1447
    using False assms arctan [of "Re z / Im z"] pi_ge_two pi_half_less_two
lp15@60150
  1448
    apply (auto simp: exp_Euler cos_diff sin_diff)
lp15@60150
  1449
    using norm_complex_def [of z, symmetric]
paulson@62131
  1450
    apply (simp add: sin_of_real cos_of_real sin_arctan cos_arctan field_simps real_sqrt_divide)
lp15@60150
  1451
    apply (metis complex_eq mult.assoc ring_class.ring_distribs(2))
lp15@60150
  1452
    done
lp15@60150
  1453
qed
lp15@60150
  1454
lp15@61609
  1455
lemma Arg_eq_Im_Ln:
lp15@61609
  1456
  assumes "0 \<le> Im z" "0 < Re z"
lp15@60150
  1457
    shows "Arg z = Im (Ln z)"
lp15@60150
  1458
proof (cases "z = 0 \<or> Im z = 0")
lp15@60150
  1459
  case True then show ?thesis
lp15@61609
  1460
    using assms Arg_eq_0 complex_is_Real_iff
lp15@60150
  1461
    apply auto
lp15@60150
  1462
    by (metis Arg_eq_0_pi Arg_eq_pi Im_Ln_eq_0 Im_Ln_eq_pi less_numeral_extra(3) zero_complex.simps(1))
lp15@60150
  1463
next
lp15@61609
  1464
  case False
lp15@60150
  1465
  then have "Arg z > 0"
lp15@60150
  1466
    using Arg_gt_0 complex_is_Real_iff by blast
lp15@60150
  1467
  then show ?thesis
lp15@61609
  1468
    using assms False
lp15@60150
  1469
    by (subst Arg_Ln) (auto simp: Ln_minus)
lp15@60150
  1470
qed
lp15@60150
  1471
lp15@61609
  1472
lemma continuous_within_upperhalf_Arg:
lp15@60150
  1473
  assumes "z \<noteq> 0"
lp15@60150
  1474
    shows "continuous (at z within {z. 0 \<le> Im z}) Arg"
paulson@62131
  1475
proof (cases "z \<in> \<real>\<^sub>\<ge>\<^sub>0")
lp15@60150
  1476
  case False then show ?thesis
lp15@60150
  1477
    using continuous_at_Arg continuous_at_imp_continuous_within by auto
lp15@60150
  1478
next
lp15@60150
  1479
  case True
lp15@60150
  1480
  then have z: "z \<in> \<real>" "0 < Re z"
paulson@62131
  1481
    using assms  by (auto simp: complex_nonneg_Reals_iff complex_is_Real_iff complex_neq_0)
lp15@60150
  1482
  then have [simp]: "Arg z = 0" "Im (Ln z) = 0"
lp15@60150
  1483
    by (auto simp: Arg_eq_0 Im_Ln_eq_0 assms complex_is_Real_iff)
lp15@61609
  1484
  show ?thesis
lp15@60150
  1485
  proof (clarsimp simp add: continuous_within Lim_within dist_norm)
lp15@60150
  1486
    fix e::real
lp15@60150
  1487
    assume "0 < e"
lp15@60150
  1488
    moreover have "continuous (at z) (\<lambda>x. Im (Ln x))"
paulson@62131
  1489
      using z by (simp add: continuous_at_Ln complex_nonpos_Reals_iff)
lp15@60150
  1490
    ultimately
lp15@60150
  1491
    obtain d where d: "d>0" "\<And>x. x \<noteq> z \<Longrightarrow> cmod (x - z) < d \<Longrightarrow> \<bar>Im (Ln x)\<bar> < e"
lp15@60150
  1492
      by (auto simp: continuous_within Lim_within dist_norm)
lp15@60150
  1493
    { fix x
lp15@60150
  1494
      assume "cmod (x - z) < Re z / 2"
lp15@60150
  1495
      then have "\<bar>Re x - Re z\<bar> < Re z / 2"
lp15@60150
  1496
        by (metis le_less_trans abs_Re_le_cmod minus_complex.simps(1))
lp15@60150
  1497
      then have "0 < Re x"
lp15@60150
  1498
        using z by linarith
lp15@60150
  1499
    }
lp15@60150
  1500
    then show "\<exists>d>0. \<forall>x. 0 \<le> Im x \<longrightarrow> x \<noteq> z \<and> cmod (x - z) < d \<longrightarrow> \<bar>Arg x\<bar> < e"
lp15@60150
  1501
      apply (rule_tac x="min d (Re z / 2)" in exI)
lp15@60150
  1502
      using z d
lp15@60150
  1503
      apply (auto simp: Arg_eq_Im_Ln)
lp15@60150
  1504
      done
lp15@60150
  1505
  qed
lp15@60150
  1506
qed
lp15@60150
  1507
lp15@60150
  1508
lemma continuous_on_upperhalf_Arg: "continuous_on ({z. 0 \<le> Im z} - {0}) Arg"
lp15@60150
  1509
  apply (auto simp: continuous_on_eq_continuous_within)
lp15@60150
  1510
  by (metis Diff_subset continuous_within_subset continuous_within_upperhalf_Arg)
lp15@60150
  1511
lp15@61609
  1512
lemma open_Arg_less_Int:
lp15@60150
  1513
  assumes "0 \<le> s" "t \<le> 2*pi"
lp15@60150
  1514
    shows "open ({y. s < Arg y} \<inter> {y. Arg y < t})"
lp15@60150
  1515
proof -
paulson@62131
  1516
  have 1: "continuous_on (UNIV - \<real>\<^sub>\<ge>\<^sub>0) Arg"
lp15@61609
  1517
    using continuous_at_Arg continuous_at_imp_continuous_within
paulson@62131
  1518
    by (auto simp: continuous_on_eq_continuous_within)
paulson@62131
  1519
  have 2: "open (UNIV - \<real>\<^sub>\<ge>\<^sub>0 :: complex set)"  by (simp add: open_Diff)
lp15@60150
  1520
  have "open ({z. s < z} \<inter> {z. z < t})"
lp15@60150
  1521
    using open_lessThan [of t] open_greaterThan [of s]
lp15@60150
  1522
    by (metis greaterThan_def lessThan_def open_Int)
paulson@62131
  1523
  moreover have "{y. s < Arg y} \<inter> {y. Arg y < t} \<subseteq> - \<real>\<^sub>\<ge>\<^sub>0"
paulson@62131
  1524
    using assms by (auto simp: Arg_real complex_nonneg_Reals_iff complex_is_Real_iff)
lp15@60150
  1525
  ultimately show ?thesis
lp15@61609
  1526
    using continuous_imp_open_vimage [OF 1 2, of  "{z. Re z > s} \<inter> {z. Re z < t}"]
lp15@60150
  1527
    by auto
lp15@60150
  1528
qed
lp15@60150
  1529
lp15@60150
  1530
lemma open_Arg_gt: "open {z. t < Arg z}"
lp15@60150
  1531
proof (cases "t < 0")
lp15@60150
  1532
  case True then have "{z. t < Arg z} = UNIV"
lp15@60150
  1533
    using Arg_ge_0 less_le_trans by auto
lp15@60150
  1534
  then show ?thesis
lp15@60150
  1535
    by simp
lp15@60150
  1536
next
lp15@60150
  1537
  case False then show ?thesis
lp15@60150
  1538
    using open_Arg_less_Int [of t "2*pi"] Arg_lt_2pi
lp15@60150
  1539
    by auto
lp15@60150
  1540
qed
lp15@60150
  1541
lp15@60150
  1542
lemma closed_Arg_le: "closed {z. Arg z \<le> t}"
lp15@60150
  1543
  using open_Arg_gt [of t]
lp15@60150
  1544
  by (simp add: closed_def Set.Collect_neg_eq [symmetric] not_le)
lp15@60017
  1545
wenzelm@60420
  1546
subsection\<open>Complex Powers\<close>
lp15@60017
  1547
lp15@60017
  1548
lemma powr_to_1 [simp]: "z powr 1 = (z::complex)"
lp15@60020
  1549
  by (simp add: powr_def)
lp15@60017
  1550
lp15@60017
  1551
lemma powr_nat:
lp15@60017
  1552
  fixes n::nat and z::complex shows "z powr n = (if z = 0 then 0 else z^n)"
lp15@60020
  1553
  by (simp add: exp_of_nat_mult powr_def)
lp15@60017
  1554
lp15@60809
  1555
lemma powr_add_complex:
lp15@60017
  1556
  fixes w::complex shows "w powr (z1 + z2) = w powr z1 * w powr z2"
lp15@60017
  1557
  by (simp add: powr_def algebra_simps exp_add)
lp15@60017
  1558
lp15@60809
  1559
lemma powr_minus_complex:
lp15@60017
  1560
  fixes w::complex shows  "w powr (-z) = inverse(w powr z)"
lp15@60017
  1561
  by (simp add: powr_def exp_minus)
lp15@60017
  1562
lp15@60809
  1563
lemma powr_diff_complex:
lp15@60017
  1564
  fixes w::complex shows  "w powr (z1 - z2) = w powr z1 / w powr z2"
lp15@60017
  1565
  by (simp add: powr_def algebra_simps exp_diff)
lp15@60017
  1566
lp15@60017
  1567
lemma norm_powr_real: "w \<in> \<real> \<Longrightarrow> 0 < Re w \<Longrightarrow> norm(w powr z) = exp(Re z * ln(Re w))"
lp15@60020
  1568
  apply (simp add: powr_def)
lp15@60017
  1569
  using Im_Ln_eq_0 complex_is_Real_iff norm_complex_def
lp15@60017
  1570
  by auto
lp15@60017
  1571
eberlm@61524
  1572
lemma cnj_powr:
eberlm@61524
  1573
  assumes "Im a = 0 \<Longrightarrow> Re a \<ge> 0"
eberlm@61524
  1574
  shows   "cnj (a powr b) = cnj a powr cnj b"
eberlm@61524
  1575
proof (cases "a = 0")
eberlm@61524
  1576
  case False
paulson@62131
  1577
  with assms have "a \<notin> \<real>\<^sub>\<le>\<^sub>0" by (auto simp: complex_eq_iff complex_nonpos_Reals_iff)
eberlm@61524
  1578
  with False show ?thesis by (simp add: powr_def exp_cnj cnj_Ln)
eberlm@61524
  1579
qed simp
eberlm@61524
  1580
lp15@60017
  1581
lemma powr_real_real:
lp15@60017
  1582
    "\<lbrakk>w \<in> \<real>; z \<in> \<real>; 0 < Re w\<rbrakk> \<Longrightarrow> w powr z = exp(Re z * ln(Re w))"
lp15@60020
  1583
  apply (simp add: powr_def)
lp15@60017
  1584
  by (metis complex_eq complex_is_Real_iff diff_0 diff_0_right diff_minus_eq_add exp_ln exp_not_eq_zero
lp15@60017
  1585
       exp_of_real Ln_of_real mult_zero_right of_real_0 of_real_mult)
lp15@60017
  1586
lp15@60017
  1587
lemma powr_of_real:
lp15@60020
  1588
  fixes x::real and y::real
lp15@60020
  1589
  shows "0 < x \<Longrightarrow> of_real x powr (of_real y::complex) = of_real (x powr y)"
lp15@60020
  1590
  by (simp add: powr_def) (metis exp_of_real of_real_mult Ln_of_real)
lp15@60017
  1591
lp15@60017
  1592
lemma norm_powr_real_mono:
lp15@60020
  1593
    "\<lbrakk>w \<in> \<real>; 1 < Re w\<rbrakk>
lp15@60020
  1594
     \<Longrightarrow> cmod(w powr z1) \<le> cmod(w powr z2) \<longleftrightarrow> Re z1 \<le> Re z2"
lp15@60020
  1595
  by (auto simp: powr_def algebra_simps Reals_def Ln_of_real)
lp15@60017
  1596
lp15@60017
  1597
lemma powr_times_real:
lp15@60017
  1598
    "\<lbrakk>x \<in> \<real>; y \<in> \<real>; 0 \<le> Re x; 0 \<le> Re y\<rbrakk>
lp15@60017
  1599
           \<Longrightarrow> (x * y) powr z = x powr z * y powr z"
lp15@60020
  1600
  by (auto simp: Reals_def powr_def Ln_times exp_add algebra_simps less_eq_real_def Ln_of_real)
lp15@60017
  1601
eberlm@61524
  1602
lemma powr_neg_real_complex:
eberlm@61524
  1603
  shows   "(- of_real x) powr a = (-1) powr (of_real (sgn x) * a) * of_real x powr (a :: complex)"
eberlm@61524
  1604
proof (cases "x = 0")
eberlm@61524
  1605
  assume x: "x \<noteq> 0"
eberlm@61524
  1606
  hence "(-x) powr a = exp (a * ln (-of_real x))" by (simp add: powr_def)
eberlm@61524
  1607
  also from x have "ln (-of_real x) = Ln (of_real x) + of_real (sgn x) * pi * \<i>"
eberlm@61524
  1608
    by (simp add: Ln_minus Ln_of_real)
eberlm@61524
  1609
  also from x assms have "exp (a * ...) = cis pi powr (of_real (sgn x) * a) * of_real x powr a"
eberlm@61524
  1610
    by (simp add: powr_def exp_add algebra_simps Ln_of_real cis_conv_exp)
eberlm@61524
  1611
  also note cis_pi
eberlm@61524
  1612
  finally show ?thesis by simp
eberlm@61524
  1613
qed simp_all
eberlm@61524
  1614
lp15@60017
  1615
lemma has_field_derivative_powr:
paulson@62131
  1616
  fixes z :: complex
paulson@62131
  1617
  shows "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> ((\<lambda>z. z powr s) has_field_derivative (s * z powr (s - 1))) (at z)"
lp15@60017
  1618
  apply (cases "z=0", auto)
lp15@60020
  1619
  apply (simp add: powr_def)
lp15@60017
  1620
  apply (rule DERIV_transform_at [where d = "norm z" and f = "\<lambda>z. exp (s * Ln z)"])
lp15@60020
  1621
  apply (auto simp: dist_complex_def)
lp15@60017
  1622
  apply (intro derivative_eq_intros | simp add: assms)+
lp15@60017
  1623
  apply (simp add: field_simps exp_diff)
lp15@60017
  1624
  done
lp15@60017
  1625
paulson@62131
  1626
declare has_field_derivative_powr[THEN DERIV_chain2, derivative_intros]
eberlm@61524
  1627
eberlm@61524
  1628
lp15@60017
  1629
lemma has_field_derivative_powr_right:
lp15@60017
  1630
    "w \<noteq> 0 \<Longrightarrow> ((\<lambda>z. w powr z) has_field_derivative Ln w * w powr z) (at z)"
lp15@60020
  1631
  apply (simp add: powr_def)
lp15@60017
  1632
  apply (intro derivative_eq_intros | simp add: assms)+
lp15@60017
  1633
  done
lp15@60017
  1634
lp15@60017
  1635
lemma complex_differentiable_powr_right:
lp15@60017
  1636
    "w \<noteq> 0 \<Longrightarrow> (\<lambda>z. w powr z) complex_differentiable (at z)"
lp15@60017
  1637
using complex_differentiable_def has_field_derivative_powr_right by blast
lp15@60017
  1638
lp15@60017
  1639
lemma holomorphic_on_powr_right:
lp15@60017
  1640
    "f holomorphic_on s \<Longrightarrow> w \<noteq> 0 \<Longrightarrow> (\<lambda>z. w powr (f z)) holomorphic_on s"
lp15@60017
  1641
    unfolding holomorphic_on_def
lp15@60017
  1642
    using DERIV_chain' complex_differentiable_def has_field_derivative_powr_right by fastforce
lp15@60017
  1643
lp15@60017
  1644
lemma norm_powr_real_powr:
lp15@60017
  1645
  "w \<in> \<real> \<Longrightarrow> 0 < Re w \<Longrightarrow> norm(w powr z) = Re w powr Re z"
lp15@60020
  1646
  by (auto simp add: norm_powr_real powr_def Im_Ln_eq_0 complex_is_Real_iff in_Reals_norm)
lp15@60017
  1647
lp15@60150
  1648
wenzelm@60420
  1649
subsection\<open>Some Limits involving Logarithms\<close>
lp15@61609
  1650
lp15@60150
  1651
lemma lim_Ln_over_power:
lp15@60150
  1652
  fixes s::complex
lp15@60150
  1653
  assumes "0 < Re s"
wenzelm@61973
  1654
    shows "((\<lambda>n. Ln n / (n powr s)) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1655
proof (simp add: lim_sequentially dist_norm, clarify)
lp15@61609
  1656
  fix e::real
lp15@60150
  1657
  assume e: "0 < e"
lp15@60150
  1658
  have "\<exists>xo>0. \<forall>x\<ge>xo. 0 < e * 2 + (e * Re s * 2 - 2) * x + e * (Re s)\<^sup>2 * x\<^sup>2"
lp15@60150
  1659
  proof (rule_tac x="2/(e * (Re s)\<^sup>2)" in exI, safe)
lp15@60150
  1660
    show "0 < 2 / (e * (Re s)\<^sup>2)"
lp15@60150
  1661
      using e assms by (simp add: field_simps)
lp15@60150
  1662
  next
lp15@60150
  1663
    fix x::real
lp15@60150
  1664
    assume x: "2 / (e * (Re s)\<^sup>2) \<le> x"
lp15@60150
  1665
    then have "x>0"
lp15@60150
  1666
    using e assms
lp15@60150
  1667
      by (metis less_le_trans mult_eq_0_iff mult_pos_pos pos_less_divide_eq power2_eq_square
lp15@60150
  1668
                zero_less_numeral)
lp15@60150
  1669
    then show "0 < e * 2 + (e * Re s * 2 - 2) * x + e * (Re s)\<^sup>2 * x\<^sup>2"
lp15@60150
  1670
      using e assms x
lp15@60150
  1671
      apply (auto simp: field_simps)
lp15@60150
  1672
      apply (rule_tac y = "e * (x\<^sup>2 * (Re s)\<^sup>2)" in le_less_trans)
lp15@60150
  1673
      apply (auto simp: power2_eq_square field_simps add_pos_pos)
lp15@60150
  1674
      done
lp15@60150
  1675
  qed
lp15@60150
  1676
  then have "\<exists>xo>0. \<forall>x\<ge>xo. x / e < 1 + (Re s * x) + (1/2) * (Re s * x)^2"
lp15@60150
  1677
    using e  by (simp add: field_simps)
lp15@60150
  1678
  then have "\<exists>xo>0. \<forall>x\<ge>xo. x / e < exp (Re s * x)"
lp15@60150
  1679
    using assms
lp15@60150
  1680
    by (force intro: less_le_trans [OF _ exp_lower_taylor_quadratic])
lp15@60150
  1681
  then have "\<exists>xo>0. \<forall>x\<ge>xo. x < e * exp (Re s * x)"
lp15@60150
  1682
    using e   by (auto simp: field_simps)
lp15@60150
  1683
  with e show "\<exists>no. \<forall>n\<ge>no. norm (Ln (of_nat n) / of_nat n powr s) < e"
lp15@60150
  1684
    apply (auto simp: norm_divide norm_powr_real divide_simps)
wenzelm@61942
  1685
    apply (rule_tac x="nat \<lceil>exp xo\<rceil>" in exI)
lp15@60150
  1686
    apply clarify
lp15@60150
  1687
    apply (drule_tac x="ln n" in spec)
lp15@61609
  1688
    apply (auto simp: exp_less_mono nat_ceiling_le_eq not_le)
lp15@60150
  1689
    apply (metis exp_less_mono exp_ln not_le of_nat_0_less_iff)
lp15@60150
  1690
    done
lp15@60150
  1691
qed
lp15@60150
  1692
wenzelm@61973
  1693
lemma lim_Ln_over_n: "((\<lambda>n. Ln(of_nat n) / of_nat n) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1694
  using lim_Ln_over_power [of 1]
lp15@60150
  1695
  by simp
lp15@60150
  1696
wenzelm@61070
  1697
lemma Ln_Reals_eq: "x \<in> \<real> \<Longrightarrow> Re x > 0 \<Longrightarrow> Ln x = of_real (ln (Re x))"
lp15@60017
  1698
  using Ln_of_real by force
lp15@60017
  1699
wenzelm@61070
  1700
lemma powr_Reals_eq: "x \<in> \<real> \<Longrightarrow> Re x > 0 \<Longrightarrow> x powr complex_of_real y = of_real (x powr y)"
lp15@60150
  1701
  by (simp add: powr_of_real)
lp15@60150
  1702
lp15@60150
  1703
lemma lim_ln_over_power:
lp15@60150
  1704
  fixes s :: real
lp15@60150
  1705
  assumes "0 < s"
wenzelm@61973
  1706
    shows "((\<lambda>n. ln n / (n powr s)) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1707
  using lim_Ln_over_power [of "of_real s", THEN filterlim_sequentially_Suc [THEN iffD2]] assms
lp15@60150
  1708
  apply (subst filterlim_sequentially_Suc [symmetric])
lp15@60150
  1709
  apply (simp add: lim_sequentially dist_norm
lp15@61609
  1710
          Ln_Reals_eq norm_powr_real_powr norm_divide)
lp15@60150
  1711
  done
lp15@60150
  1712
wenzelm@61973
  1713
lemma lim_ln_over_n: "((\<lambda>n. ln(real_of_nat n) / of_nat n) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1714
  using lim_ln_over_power [of 1, THEN filterlim_sequentially_Suc [THEN iffD2]]
lp15@60150
  1715
  apply (subst filterlim_sequentially_Suc [symmetric])
lp15@61609
  1716
  apply (simp add: lim_sequentially dist_norm)
lp15@60150
  1717
  done
lp15@60150
  1718
lp15@60150
  1719
lemma lim_1_over_complex_power:
lp15@60150
  1720
  assumes "0 < Re s"
wenzelm@61973
  1721
    shows "((\<lambda>n. 1 / (of_nat n powr s)) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1722
proof -
lp15@60150
  1723
  have "\<forall>n>0. 3 \<le> n \<longrightarrow> 1 \<le> ln (real_of_nat n)"
lp15@60150
  1724
    using ln3_gt_1
lp15@60150
  1725
    by (force intro: order_trans [of _ "ln 3"] ln3_gt_1)
wenzelm@61969
  1726
  moreover have "(\<lambda>n. cmod (Ln (of_nat n) / of_nat n powr s)) \<longlonglongrightarrow> 0"
lp15@60150
  1727
    using lim_Ln_over_power [OF assms]
lp15@60150
  1728
    by (metis tendsto_norm_zero_iff)
lp15@60150
  1729
  ultimately show ?thesis
lp15@60150
  1730
    apply (auto intro!: Lim_null_comparison [where g = "\<lambda>n. norm (Ln(of_nat n) / of_nat n powr s)"])
lp15@60150
  1731
    apply (auto simp: norm_divide divide_simps eventually_sequentially)
lp15@60150
  1732
    done
lp15@60150
  1733
qed
lp15@60150
  1734
lp15@60150
  1735
lemma lim_1_over_real_power:
lp15@60150
  1736
  fixes s :: real
lp15@60150
  1737
  assumes "0 < s"
wenzelm@61973
  1738
    shows "((\<lambda>n. 1 / (of_nat n powr s)) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1739
  using lim_1_over_complex_power [of "of_real s", THEN filterlim_sequentially_Suc [THEN iffD2]] assms
lp15@60150
  1740
  apply (subst filterlim_sequentially_Suc [symmetric])
lp15@60150
  1741
  apply (simp add: lim_sequentially dist_norm)
lp15@61609
  1742
  apply (simp add: Ln_Reals_eq norm_powr_real_powr norm_divide)
lp15@60150
  1743
  done
lp15@60150
  1744
wenzelm@61973
  1745
lemma lim_1_over_Ln: "((\<lambda>n. 1 / Ln(of_nat n)) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1746
proof (clarsimp simp add: lim_sequentially dist_norm norm_divide divide_simps)
lp15@60150
  1747
  fix r::real
lp15@60150
  1748
  assume "0 < r"
lp15@60150
  1749
  have ir: "inverse (exp (inverse r)) > 0"
lp15@60150
  1750
    by simp
lp15@60150
  1751
  obtain n where n: "1 < of_nat n * inverse (exp (inverse r))"
lp15@60150
  1752
    using ex_less_of_nat_mult [of _ 1, OF ir]
lp15@60150
  1753
    by auto
lp15@60150
  1754
  then have "exp (inverse r) < of_nat n"
lp15@60150
  1755
    by (simp add: divide_simps)
lp15@60150
  1756
  then have "ln (exp (inverse r)) < ln (of_nat n)"
lp15@60150
  1757
    by (metis exp_gt_zero less_trans ln_exp ln_less_cancel_iff)
wenzelm@60420
  1758
  with \<open>0 < r\<close> have "1 < r * ln (real_of_nat n)"
lp15@60150
  1759
    by (simp add: field_simps)
lp15@60150
  1760
  moreover have "n > 0" using n
lp15@60150
  1761
    using neq0_conv by fastforce
lp15@60150
  1762
  ultimately show "\<exists>no. \<forall>n. Ln (of_nat n) \<noteq> 0 \<longrightarrow> no \<le> n \<longrightarrow> 1 < r * cmod (Ln (of_nat n))"
wenzelm@60420
  1763
    using n \<open>0 < r\<close>
lp15@60150
  1764
    apply (rule_tac x=n in exI)
lp15@60150
  1765
    apply (auto simp: divide_simps)
lp15@60150
  1766
    apply (erule less_le_trans, auto)
lp15@60150
  1767
    done
lp15@60150
  1768
qed
lp15@60150
  1769
wenzelm@61973
  1770
lemma lim_1_over_ln: "((\<lambda>n. 1 / ln(real_of_nat n)) \<longlongrightarrow> 0) sequentially"
lp15@60150
  1771
  using lim_1_over_Ln [THEN filterlim_sequentially_Suc [THEN iffD2]] assms
lp15@60150
  1772
  apply (subst filterlim_sequentially_Suc [symmetric])
lp15@60150
  1773
  apply (simp add: lim_sequentially dist_norm)
lp15@61609
  1774
  apply (simp add: Ln_Reals_eq norm_powr_real_powr norm_divide)
lp15@60150
  1775
  done
lp15@60150
  1776
lp15@60017
  1777
wenzelm@60420
  1778
subsection\<open>Relation between Square Root and exp/ln, hence its derivative\<close>
lp15@59751
  1779
lp15@59751
  1780
lemma csqrt_exp_Ln:
lp15@59751
  1781
  assumes "z \<noteq> 0"
lp15@59751
  1782
    shows "csqrt z = exp(Ln(z) / 2)"
lp15@59751
  1783
proof -
lp15@59751
  1784
  have "(exp (Ln z / 2))\<^sup>2 = (exp (Ln z))"
lp15@59751
  1785
    by (metis exp_double nonzero_mult_divide_cancel_left times_divide_eq_right zero_neq_numeral)
lp15@59751
  1786
  also have "... = z"
lp15@59751
  1787
    using assms exp_Ln by blast
lp15@59751
  1788
  finally have "csqrt z = csqrt ((exp (Ln z / 2))\<^sup>2)"
lp15@59751
  1789
    by simp
lp15@59751
  1790
  also have "... = exp (Ln z / 2)"
lp15@59751
  1791
    apply (subst csqrt_square)
lp15@59751
  1792
    using cos_gt_zero_pi [of "(Im (Ln z) / 2)"] Im_Ln_le_pi mpi_less_Im_Ln assms
lp15@59751
  1793
    apply (auto simp: Re_exp Im_exp zero_less_mult_iff zero_le_mult_iff, fastforce+)
lp15@59751
  1794
    done
lp15@59751
  1795
  finally show ?thesis using assms csqrt_square
lp15@59751
  1796
    by simp
lp15@59751
  1797
qed
lp15@59751
  1798
lp15@59751
  1799
lemma csqrt_inverse:
paulson@62131
  1800
  assumes "z \<notin> \<real>\<^sub>\<le>\<^sub>0"
lp15@59751
  1801
    shows "csqrt (inverse z) = inverse (csqrt z)"
lp15@59751
  1802
proof (cases "z=0", simp)
paulson@62131
  1803
  assume "z \<noteq> 0"
lp15@59751
  1804
  then show ?thesis
paulson@62131
  1805
    using assms csqrt_exp_Ln Ln_inverse exp_minus
lp15@59751
  1806
    by (simp add: csqrt_exp_Ln Ln_inverse exp_minus)
lp15@59751
  1807
qed
lp15@59751
  1808
lp15@59751
  1809
lemma cnj_csqrt:
paulson@62131
  1810
  assumes "z \<notin> \<real>\<^sub>\<le>\<^sub>0"
lp15@59751
  1811
    shows "cnj(csqrt z) = csqrt(cnj z)"
lp15@59751
  1812
proof (cases "z=0", simp)
paulson@62131
  1813
  assume "z \<noteq> 0"
lp15@59751
  1814
  then show ?thesis
paulson@62131
  1815
     by (simp add: assms cnj_Ln csqrt_exp_Ln exp_cnj) 
lp15@59751
  1816
qed
lp15@59751
  1817
lp15@59751
  1818
lemma has_field_derivative_csqrt:
paulson@62131
  1819
  assumes "z \<notin> \<real>\<^sub>\<le>\<^sub>0"
lp15@59751
  1820
    shows "(csqrt has_field_derivative inverse(2 * csqrt z)) (at z)"
lp15@59751
  1821
proof -
lp15@59751
  1822
  have z: "z \<noteq> 0"
lp15@59751
  1823
    using assms by auto
lp15@59751
  1824
  then have *: "inverse z = inverse (2*z) * 2"
lp15@59751
  1825
    by (simp add: divide_simps)
paulson@62131
  1826
  have [simp]: "exp (Ln z / 2) * inverse z = inverse (csqrt z)"
paulson@62131
  1827
    by (simp add: z field_simps csqrt_exp_Ln [symmetric]) (metis power2_csqrt power2_eq_square)
paulson@62131
  1828
  have "Im z = 0 \<Longrightarrow> 0 < Re z"
paulson@62131
  1829
    using assms complex_nonpos_Reals_iff not_less by blast
paulson@62131
  1830
  with z have "((\<lambda>z. exp (Ln z / 2)) has_field_derivative inverse (2 * csqrt z)) (at z)"
paulson@62131
  1831
    by (force intro: derivative_eq_intros * simp add: assms)
paulson@62131
  1832
  then show ?thesis
paulson@62131
  1833
    apply (rule DERIV_transform_at[where d = "norm z"])
paulson@62131
  1834
    apply (intro z derivative_eq_intros | simp add: assms)+
lp15@59751
  1835
    using z
lp15@59751
  1836
    apply (metis csqrt_exp_Ln dist_0_norm less_irrefl)
lp15@59751
  1837
    done
lp15@59751
  1838
qed
lp15@59751
  1839
lp15@59751
  1840
lemma complex_differentiable_at_csqrt:
paulson@62131
  1841
    "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> csqrt complex_differentiable at z"
lp15@59751
  1842
  using complex_differentiable_def has_field_derivative_csqrt by blast
lp15@59751
  1843
lp15@59751
  1844
lemma complex_differentiable_within_csqrt:
paulson@62131
  1845
    "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> csqrt complex_differentiable (at z within s)"
lp15@59751
  1846
  using complex_differentiable_at_csqrt complex_differentiable_within_subset by blast
lp15@59751
  1847
lp15@59751
  1848
lemma continuous_at_csqrt:
paulson@62131
  1849
    "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> continuous (at z) csqrt"
lp15@59751
  1850
  by (simp add: complex_differentiable_within_csqrt complex_differentiable_imp_continuous_at)
lp15@59751
  1851
lp15@59862
  1852
corollary isCont_csqrt' [simp]:
paulson@62131
  1853
   "\<lbrakk>isCont f z; f z \<notin> \<real>\<^sub>\<le>\<^sub>0\<rbrakk> \<Longrightarrow> isCont (\<lambda>x. csqrt (f x)) z"
lp15@59862
  1854
  by (blast intro: isCont_o2 [OF _ continuous_at_csqrt])
lp15@59862
  1855
lp15@59751
  1856
lemma continuous_within_csqrt:
paulson@62131
  1857
    "z \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> continuous (at z within s) csqrt"
lp15@59751
  1858
  by (simp add: complex_differentiable_imp_continuous_at complex_differentiable_within_csqrt)
lp15@59751
  1859
lp15@59751
  1860
lemma continuous_on_csqrt [continuous_intros]:
paulson@62131
  1861
    "(\<And>z. z \<in> s \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> continuous_on s csqrt"
lp15@59751
  1862
  by (simp add: continuous_at_imp_continuous_on continuous_within_csqrt)
lp15@59751
  1863
lp15@59751
  1864
lemma holomorphic_on_csqrt:
paulson@62131
  1865
    "(\<And>z. z \<in> s \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> csqrt holomorphic_on s"
lp15@59751
  1866
  by (simp add: complex_differentiable_within_csqrt holomorphic_on_def)
lp15@59751
  1867
lp15@59751
  1868
lemma continuous_within_closed_nontrivial:
lp15@59751
  1869
    "closed s \<Longrightarrow> a \<notin> s ==> continuous (at a within s) f"
lp15@59751
  1870
  using open_Compl
lp15@59751
  1871
  by (force simp add: continuous_def eventually_at_topological filterlim_iff open_Collect_neg)
lp15@59751
  1872
lp15@59751
  1873
lemma continuous_within_csqrt_posreal:
lp15@59751
  1874
    "continuous (at z within (\<real> \<inter> {w. 0 \<le> Re(w)})) csqrt"
paulson@62131
  1875
proof (cases "z \<in> \<real>\<^sub>\<le>\<^sub>0")
paulson@62131
  1876
  case True 
lp15@59751
  1877
  then have "Im z = 0" "Re z < 0 \<or> z = 0"
paulson@62131
  1878
    using cnj.code complex_cnj_zero_iff  by (auto simp: complex_nonpos_Reals_iff) fastforce
lp15@59751
  1879
  then show ?thesis
lp15@59751
  1880
    apply (auto simp: continuous_within_closed_nontrivial [OF closed_Real_halfspace_Re_ge])
lp15@59751
  1881
    apply (auto simp: continuous_within_eps_delta norm_conv_dist [symmetric])
lp15@59751
  1882
    apply (rule_tac x="e^2" in exI)
lp15@59751
  1883
    apply (auto simp: Reals_def)
paulson@62131
  1884
    by (metis linear not_less real_sqrt_less_iff real_sqrt_pow2_iff real_sqrt_power)
paulson@62131
  1885
next
paulson@62131
  1886
  case False
paulson@62131
  1887
    then show ?thesis   by (blast intro: continuous_within_csqrt)
lp15@59751
  1888
qed
lp15@59751
  1889
wenzelm@60420
  1890
subsection\<open>Complex arctangent\<close>
wenzelm@60420
  1891
paulson@62131
  1892
text\<open>The branch cut gives standard bounds in the real case.\<close>
lp15@59870
  1893
lp15@59870
  1894
definition Arctan :: "complex \<Rightarrow> complex" where
lp15@59870
  1895
    "Arctan \<equiv> \<lambda>z. (\<i>/2) * Ln((1 - \<i>*z) / (1 + \<i>*z))"
lp15@59870
  1896
eberlm@62049
  1897
lemma Arctan_def_moebius: "Arctan z = \<i>/2 * Ln (moebius (-\<i>) 1 \<i> 1 z)"
eberlm@62049
  1898
  by (simp add: Arctan_def moebius_def add_ac)
eberlm@62049
  1899
eberlm@62049
  1900
lemma Ln_conv_Arctan:
eberlm@62049
  1901
  assumes "z \<noteq> -1"
eberlm@62049
  1902
  shows   "Ln z = -2*\<i> * Arctan (moebius 1 (- 1) (- \<i>) (- \<i>) z)"
eberlm@62049
  1903
proof -
eberlm@62049
  1904
  have "Arctan (moebius 1 (- 1) (- \<i>) (- \<i>) z) =
eberlm@62049
  1905
             \<i>/2 * Ln (moebius (- \<i>) 1 \<i> 1 (moebius 1 (- 1) (- \<i>) (- \<i>) z))"
eberlm@62049
  1906
    by (simp add: Arctan_def_moebius)
eberlm@62049
  1907
  also from assms have "\<i> * z \<noteq> \<i> * (-1)" by (subst mult_left_cancel) simp
eberlm@62049
  1908
  hence "\<i> * z - -\<i> \<noteq> 0" by (simp add: eq_neg_iff_add_eq_0)
eberlm@62049
  1909
  from moebius_inverse'[OF _ this, of 1 1]
eberlm@62049
  1910
    have "moebius (- \<i>) 1 \<i> 1 (moebius 1 (- 1) (- \<i>) (- \<i>) z) = z" by simp
eberlm@62049
  1911
  finally show ?thesis by (simp add: field_simps)
eberlm@62049
  1912
qed
eberlm@62049
  1913
lp15@59870
  1914
lemma Arctan_0 [simp]: "Arctan 0 = 0"
lp15@59870
  1915
  by (simp add: Arctan_def)
lp15@59870
  1916
lp15@59870
  1917
lemma Im_complex_div_lemma: "Im((1 - \<i>*z) / (1 + \<i>*z)) = 0 \<longleftrightarrow> Re z = 0"
lp15@59870
  1918
  by (auto simp: Im_complex_div_eq_0 algebra_simps)
lp15@59870
  1919
lp15@59870
  1920
lemma Re_complex_div_lemma: "0 < Re((1 - \<i>*z) / (1 + \<i>*z)) \<longleftrightarrow> norm z < 1"
lp15@59870
  1921
  by (simp add: Re_complex_div_gt_0 algebra_simps cmod_def power2_eq_square)
lp15@59870
  1922
lp15@59870
  1923
lemma tan_Arctan:
lp15@59870
  1924
  assumes "z\<^sup>2 \<noteq> -1"
lp15@59870
  1925
    shows [simp]:"tan(Arctan z) = z"
lp15@59870
  1926
proof -
lp15@59870
  1927
  have "1 + \<i>*z \<noteq> 0"
lp15@59870
  1928
    by (metis assms complex_i_mult_minus i_squared minus_unique power2_eq_square power2_minus)
lp15@59870
  1929
  moreover
lp15@59870
  1930
  have "1 - \<i>*z \<noteq> 0"
lp15@59870
  1931
    by (metis assms complex_i_mult_minus i_squared power2_eq_square power2_minus right_minus_eq)
lp15@59870
  1932
  ultimately
lp15@59870
  1933
  show ?thesis
lp15@59870
  1934
    by (simp add: Arctan_def tan_def sin_exp_eq cos_exp_eq exp_minus csqrt_exp_Ln [symmetric]
lp15@59870
  1935
                  divide_simps power2_eq_square [symmetric])
lp15@59870
  1936
qed
lp15@59870
  1937
lp15@59870
  1938
lemma Arctan_tan [simp]:
lp15@59870
  1939
  assumes "\<bar>Re z\<bar> < pi/2"
lp15@59870
  1940
    shows "Arctan(tan z) = z"
lp15@59870
  1941
proof -
wenzelm@61945
  1942
  have ge_pi2: "\<And>n::int. \<bar>of_int (2*n + 1) * pi/2\<bar> \<ge> pi/2"
lp15@59870
  1943
    by (case_tac n rule: int_cases) (auto simp: abs_mult)
lp15@59870
  1944
  have "exp (\<i>*z)*exp (\<i>*z) = -1 \<longleftrightarrow> exp (2*\<i>*z) = -1"
lp15@59870
  1945
    by (metis distrib_right exp_add mult_2)
lp15@59870
  1946
  also have "... \<longleftrightarrow> exp (2*\<i>*z) = exp (\<i>*pi)"
lp15@59870
  1947
    using cis_conv_exp cis_pi by auto
lp15@59870
  1948
  also have "... \<longleftrightarrow> exp (2*\<i>*z - \<i>*pi) = 1"
lp15@59870
  1949
    by (metis (no_types) diff_add_cancel diff_minus_eq_add exp_add exp_minus_inverse mult.commute)
lp15@59870
  1950
  also have "... \<longleftrightarrow> Re(\<i>*2*z - \<i>*pi) = 0 \<and> (\<exists>n::int. Im(\<i>*2*z - \<i>*pi) = of_int (2 * n) * pi)"
lp15@59870
  1951
    by (simp add: exp_eq_1)
lp15@59870
  1952
  also have "... \<longleftrightarrow> Im z = 0 \<and> (\<exists>n::int. 2 * Re z = of_int (2*n + 1) * pi)"
lp15@59870
  1953
    by (simp add: algebra_simps)
lp15@59870
  1954
  also have "... \<longleftrightarrow> False"
lp15@59870
  1955
    using assms ge_pi2
lp15@59870
  1956
    apply (auto simp: algebra_simps)
lp15@61609
  1957
    by (metis abs_mult_pos not_less of_nat_less_0_iff of_nat_numeral)
lp15@59870
  1958
  finally have *: "exp (\<i>*z)*exp (\<i>*z) + 1 \<noteq> 0"
lp15@59870
  1959
    by (auto simp: add.commute minus_unique)
lp15@59870
  1960
  show ?thesis
lp15@59870
  1961
    using assms *
lp15@59870
  1962
    apply (simp add: Arctan_def tan_def sin_exp_eq cos_exp_eq exp_minus divide_simps
lp15@59870
  1963
                     ii_times_eq_iff power2_eq_square [symmetric])
lp15@59870
  1964
    apply (rule Ln_unique)
lp15@59870
  1965
    apply (auto simp: divide_simps exp_minus)
lp15@59870
  1966
    apply (simp add: algebra_simps exp_double [symmetric])
lp15@59870
  1967
    done
lp15@59870
  1968
qed
lp15@59870
  1969
lp15@59870
  1970
lemma
wenzelm@61945
  1971
  assumes "Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1"
wenzelm@61945
  1972
  shows Re_Arctan_bounds: "\<bar>Re(Arctan z)\<bar> < pi/2"
lp15@59870
  1973
    and has_field_derivative_Arctan: "(Arctan has_field_derivative inverse(1 + z\<^sup>2)) (at z)"
lp15@59870
  1974
proof -
lp15@59870
  1975
  have nz0: "1 + \<i>*z \<noteq> 0"
lp15@59870
  1976
    using assms
lp15@60141
  1977
    by (metis abs_one complex_i_mult_minus diff_0_right diff_minus_eq_add ii.simps(1) ii.simps(2)
lp15@59870
  1978
              less_irrefl minus_diff_eq mult.right_neutral right_minus_eq)
lp15@59870
  1979
  have "z \<noteq> -\<i>" using assms
lp15@59870
  1980
    by auto
lp15@59870
  1981
  then have zz: "1 + z * z \<noteq> 0"
lp15@59870
  1982
    by (metis abs_one assms i_squared ii.simps less_irrefl minus_unique square_eq_iff)
lp15@59870
  1983
  have nz1: "1 - \<i>*z \<noteq> 0"
lp15@59870
  1984
    using assms by (force simp add: ii_times_eq_iff)
lp15@59870
  1985
  have nz2: "inverse (1 + \<i>*z) \<noteq> 0"
lp15@59870
  1986
    using assms
lp15@59870
  1987
    by (metis Im_complex_div_lemma Re_complex_div_lemma cmod_eq_Im divide_complex_def
lp15@59870
  1988
              less_irrefl mult_zero_right zero_complex.simps(1) zero_complex.simps(2))
lp15@59870
  1989
  have nzi: "((1 - \<i>*z) * inverse (1 + \<i>*z)) \<noteq> 0"
lp15@59870
  1990
    using nz1 nz2 by auto
paulson@62131
  1991
  have "Im ((1 - \<i>*z) / (1 + \<i>*z)) = 0 \<Longrightarrow> 0 < Re ((1 - \<i>*z) / (1 + \<i>*z))"
lp15@59870
  1992
    apply (simp add: divide_complex_def)
lp15@59870
  1993
    apply (simp add: divide_simps split: split_if_asm)
lp15@59870
  1994
    using assms
lp15@59870
  1995
    apply (auto simp: algebra_simps abs_square_less_1 [unfolded power2_eq_square])
lp15@59870
  1996
    done
paulson@62131
  1997
  then have *: "((1 - \<i>*z) / (1 + \<i>*z)) \<notin> \<real>\<^sub>\<le>\<^sub>0"
paulson@62131
  1998
    by (auto simp add: complex_nonpos_Reals_iff)
wenzelm@61945
  1999
  show "\<bar>Re(Arctan z)\<bar> < pi/2"
lp15@59870
  2000
    unfolding Arctan_def divide_complex_def
lp15@59870
  2001
    using mpi_less_Im_Ln [OF nzi]
paulson@62131
  2002
    apply (auto simp: abs_if intro!: Im_Ln_less_pi * [unfolded divide_complex_def])
paulson@62131
  2003
    done
lp15@59870
  2004
  show "(Arctan has_field_derivative inverse(1 + z\<^sup>2)) (at z)"
lp15@59870
  2005
    unfolding Arctan_def scaleR_conv_of_real
lp15@59870
  2006
    apply (rule DERIV_cong)
lp15@59870
  2007
    apply (intro derivative_eq_intros | simp add: nz0 *)+
lp15@59870
  2008
    using nz0 nz1 zz
lp15@59870
  2009
    apply (simp add: divide_simps power2_eq_square)
lp15@59870
  2010
    apply (auto simp: algebra_simps)
lp15@59870
  2011
    done
lp15@59870
  2012
qed
lp15@59870
  2013
wenzelm@61945
  2014
lemma complex_differentiable_at_Arctan: "(Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1) \<Longrightarrow> Arctan complex_differentiable at z"
lp15@59870
  2015
  using has_field_derivative_Arctan
lp15@59870
  2016
  by (auto simp: complex_differentiable_def)
lp15@59870
  2017
lp15@59870
  2018
lemma complex_differentiable_within_Arctan:
wenzelm@61945
  2019
    "(Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1) \<Longrightarrow> Arctan complex_differentiable (at z within s)"
lp15@59870
  2020
  using complex_differentiable_at_Arctan complex_differentiable_at_within by blast
lp15@59870
  2021
lp15@59870
  2022
declare has_field_derivative_Arctan [derivative_intros]
lp15@59870
  2023
declare has_field_derivative_Arctan [THEN DERIV_chain2, derivative_intros]
lp15@59870
  2024
lp15@59870
  2025
lemma continuous_at_Arctan:
wenzelm@61945
  2026
    "(Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1) \<Longrightarrow> continuous (at z) Arctan"
lp15@59870
  2027
  by (simp add: complex_differentiable_imp_continuous_at complex_differentiable_within_Arctan)
lp15@59870
  2028
lp15@59870
  2029
lemma continuous_within_Arctan:
wenzelm@61945
  2030
    "(Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1) \<Longrightarrow> continuous (at z within s) Arctan"
lp15@59870
  2031
  using continuous_at_Arctan continuous_at_imp_continuous_within by blast
lp15@59870
  2032
lp15@59870
  2033
lemma continuous_on_Arctan [continuous_intros]:
wenzelm@61945
  2034
    "(\<And>z. z \<in> s \<Longrightarrow> Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1) \<Longrightarrow> continuous_on s Arctan"
lp15@59870
  2035
  by (auto simp: continuous_at_imp_continuous_on continuous_within_Arctan)
lp15@59870
  2036
lp15@59870
  2037
lemma holomorphic_on_Arctan:
wenzelm@61945
  2038
    "(\<And>z. z \<in> s \<Longrightarrow> Re z = 0 \<Longrightarrow> \<bar>Im z\<bar> < 1) \<Longrightarrow> Arctan holomorphic_on s"
lp15@59870
  2039
  by (simp add: complex_differentiable_within_Arctan holomorphic_on_def)
lp15@59870
  2040
eberlm@62049
  2041
lemma Arctan_series:
eberlm@62049
  2042
  assumes z: "norm (z :: complex) < 1"
eberlm@62049
  2043
  defines "g \<equiv> \<lambda>n. if odd n then -\<i>*\<i>^n / n else 0"
eberlm@62049
  2044
  defines "h \<equiv> \<lambda>z n. (-1)^n / of_nat (2*n+1) * (z::complex)^(2*n+1)"
eberlm@62049
  2045
  shows   "(\<lambda>n. g n * z^n) sums Arctan z"
eberlm@62049
  2046
  and     "h z sums Arctan z"
eberlm@62049
  2047
proof -
eberlm@62049
  2048
  def G \<equiv> "\<lambda>z. (\<Sum>n. g n * z^n)"
eberlm@62049
  2049
  have summable: "summable (\<lambda>n. g n * u^n)" if "norm u < 1" for u
eberlm@62049
  2050
  proof (cases "u = 0")
eberlm@62049
  2051
    assume u: "u \<noteq> 0"
eberlm@62049
  2052
    have "(\<lambda>n. ereal (norm (h u n) / norm (h u (Suc n)))) = (\<lambda>n. ereal (inverse (norm u)^2) * 
eberlm@62049
  2053
              ereal ((2 + inverse (real (Suc n))) / (2 - inverse (real (Suc n)))))"
eberlm@62049
  2054
    proof
eberlm@62049
  2055
      fix n
eberlm@62049
  2056
      have "ereal (norm (h u n) / norm (h u (Suc n))) = 
eberlm@62049
  2057
             ereal (inverse (norm u)^2) * ereal ((of_nat (2*Suc n+1) / of_nat (Suc n)) / 
eberlm@62049
  2058
                 (of_nat (2*Suc n-1) / of_nat (Suc n)))"
eberlm@62049
  2059
      by (simp add: h_def norm_mult norm_power norm_divide divide_simps 
eberlm@62049
  2060
                    power2_eq_square eval_nat_numeral del: of_nat_add of_nat_Suc)
eberlm@62049
  2061
      also have "of_nat (2*Suc n+1) / of_nat (Suc n) = (2::real) + inverse (real (Suc n))"
eberlm@62049
  2062
        by (auto simp: divide_simps simp del: of_nat_Suc) simp_all?
eberlm@62049
  2063
      also have "of_nat (2*Suc n-1) / of_nat (Suc n) = (2::real) - inverse (real (Suc n))"
eberlm@62049
  2064
        by (auto simp: divide_simps simp del: of_nat_Suc) simp_all?      
eberlm@62049
  2065
      finally show "ereal (norm (h u n) / norm (h u (Suc n))) = ereal (inverse (norm u)^2) * 
eberlm@62049
  2066
              ereal ((2 + inverse (real (Suc n))) / (2 - inverse (real (Suc n))))" .
eberlm@62049
  2067
    qed
eberlm@62049
  2068
    also have "\<dots> \<longlonglongrightarrow> ereal (inverse (norm u)^2) * ereal ((2 + 0) / (2 - 0))"
eberlm@62049
  2069
      by (intro tendsto_intros LIMSEQ_inverse_real_of_nat) simp_all
eberlm@62049
  2070
    finally have "liminf (\<lambda>n. ereal (cmod (h u n) / cmod (h u (Suc n)))) = inverse (norm u)^2"
eberlm@62049
  2071
      by (intro lim_imp_Liminf) simp_all
eberlm@62049
  2072
    moreover from power_strict_mono[OF that, of 2] u have "inverse (norm u)^2 > 1"
eberlm@62049
  2073
      by (simp add: divide_simps)
eberlm@62049
  2074
    ultimately have A: "liminf (\<lambda>n. ereal (cmod (h u n) / cmod (h u (Suc n)))) > 1" by simp
eberlm@62049
  2075
    from u have "summable (h u)"
eberlm@62049
  2076
      by (intro summable_norm_cancel[OF ratio_test_convergence[OF _ A]])
eberlm@62049
  2077
         (auto simp: h_def norm_divide norm_mult norm_power simp del: of_nat_Suc 
eberlm@62049
  2078
               intro!: mult_pos_pos divide_pos_pos always_eventually)
eberlm@62049
  2079
    thus "summable (\<lambda>n. g n * u^n)"
eberlm@62049
  2080
      by (subst summable_mono_reindex[of "\<lambda>n. 2*n+1", symmetric])
eberlm@62049
  2081
         (auto simp: power_mult subseq_def g_def h_def elim!: oddE)
eberlm@62049
  2082
  qed (simp add: h_def)
eberlm@62049
  2083
eberlm@62049
  2084
  have "\<exists>c. \<forall>u\<in>ball 0 1. Arctan u - G u = c"
eberlm@62049
  2085
  proof (rule has_field_derivative_zero_constant)
eberlm@62049
  2086
    fix u :: complex assume "u \<in> ball 0 1"
eberlm@62049
  2087
    hence u: "norm u < 1" by (simp add: dist_0_norm)
eberlm@62049
  2088
    def K \<equiv> "(norm u + 1) / 2"
eberlm@62049
  2089
    from u and abs_Im_le_cmod[of u] have Im_u: "\<bar>Im u\<bar> < 1" by linarith
eberlm@62049
  2090
    from u have K: "0 \<le> K" "norm u < K" "K < 1" by (simp_all add: K_def)
eberlm@62049
  2091
    hence "(G has_field_derivative (\<Sum>n. diffs g n * u ^ n)) (at u)" unfolding G_def
eberlm@62049
  2092
      by (intro termdiffs_strong[of _ "of_real K"] summable) simp_all
eberlm@62049
  2093
    also have "(\<lambda>n. diffs g n * u^n) = (\<lambda>n. if even n then (\<i>*u)^n else 0)"
eberlm@62049
  2094
      by (intro ext) (simp_all del: of_nat_Suc add: g_def diffs_def power_mult_distrib)
eberlm@62049
  2095
    also have "suminf \<dots> = (\<Sum>n. (-(u^2))^n)"
eberlm@62049
  2096
      by (subst suminf_mono_reindex[of "\<lambda>n. 2*n", symmetric]) 
eberlm@62049
  2097
         (auto elim!: evenE simp: subseq_def power_mult power_mult_distrib)
eberlm@62049
  2098
    also from u have "norm u^2 < 1^2" by (intro power_strict_mono) simp_all
eberlm@62049
  2099
    hence "(\<Sum>n. (-(u^2))^n) = inverse (1 + u^2)" 
eberlm@62049
  2100
      by (subst suminf_geometric) (simp_all add: norm_power inverse_eq_divide)
eberlm@62049
  2101
    finally have "(G has_field_derivative inverse (1 + u\<^sup>2)) (at u)" .
eberlm@62049
  2102
    from DERIV_diff[OF has_field_derivative_Arctan this] Im_u u
eberlm@62049
  2103
      show "((\<lambda>u. Arctan u - G u) has_field_derivative 0) (at u within ball 0 1)"
eberlm@62049
  2104
      by (simp_all add: dist_0_norm at_within_open[OF _ open_ball])
eberlm@62049
  2105
  qed simp_all
eberlm@62049
  2106
  then obtain c where c: "\<And>u. norm u < 1 \<Longrightarrow> Arctan u - G u = c" by (auto simp: dist_0_norm)
eberlm@62049
  2107
  from this[of 0] have "c = 0" by (simp add: G_def g_def powser_zero)
eberlm@62049
  2108
  with c z have "Arctan z = G z" by simp
eberlm@62049
  2109
  with summable[OF z] show "(\<lambda>n. g n * z^n) sums Arctan z" unfolding G_def by (simp add: sums_iff)
eberlm@62049
  2110
  thus "h z sums Arctan z" by (subst (asm) sums_mono_reindex[of "\<lambda>n. 2*n+1", symmetric])
eberlm@62049
  2111
                              (auto elim!: oddE simp: subseq_def power_mult g_def h_def)
eberlm@62049
  2112
qed
eberlm@62049
  2113
eberlm@62049
  2114
text \<open>A quickly-converging series for the logarithm, based on the arctangent.\<close>
eberlm@62049
  2115
lemma ln_series_quadratic:
eberlm@62049
  2116
  assumes x: "x > (0::real)"
eberlm@62049
  2117
  shows "(\<lambda>n. (2*((x - 1) / (x + 1)) ^ (2*n+1) / of_nat (2*n+1))) sums ln x"
eberlm@62049
  2118
proof -
eberlm@62049
  2119
  def y \<equiv> "of_real ((x-1)/(x+1)) :: complex"
eberlm@62049
  2120
  from x have x': "complex_of_real x \<noteq> of_real (-1)"  by (subst of_real_eq_iff) auto
eberlm@62049
  2121
  from x have "\<bar>x - 1\<bar> < \<bar>x + 1\<bar>" by linarith
eberlm@62049
  2122
  hence "norm (complex_of_real (x - 1) / complex_of_real (x + 1)) < 1"
eberlm@62049
  2123
    by (simp add: norm_divide del: of_real_add of_real_diff)
eberlm@62049
  2124
  hence "norm (\<i> * y) < 1" unfolding y_def by (subst norm_mult) simp
eberlm@62049
  2125
  hence "(\<lambda>n. (-2*\<i>) * ((-1)^n / of_nat (2*n+1) * (\<i>*y)^(2*n+1))) sums ((-2*\<i>) * Arctan (\<i>*y))"
eberlm@62049
  2126
    by (intro Arctan_series sums_mult) simp_all
eberlm@62049
  2127
  also have "(\<lambda>n. (-2*\<i>) * ((-1)^n / of_nat (2*n+1) * (\<i>*y)^(2*n+1))) = 
eberlm@62049
  2128
                 (\<lambda>n. (-2*\<i>) * ((-1)^n * (\<i>*y*(-y\<^sup>2)^n)/of_nat (2*n+1)))"
eberlm@62049
  2129
    by (intro ext) (simp_all add: power_mult power_mult_distrib)
eberlm@62049
  2130
  also have "\<dots> = (\<lambda>n. 2*y* ((-1) * (-y\<^sup>2))^n/of_nat (2*n+1))"
eberlm@62049
  2131
    by (intro ext, subst power_mult_distrib) (simp add: algebra_simps power_mult)
eberlm@62049
  2132
  also have "\<dots> = (\<lambda>n. 2*y^(2*n+1) / of_nat (2*n+1))" 
eberlm@62049
  2133
    by (subst power_add, subst power_mult) (simp add: mult_ac)
eberlm@62049
  2134
  also have "\<dots> = (\<lambda>n. of_real (2*((x-1)/(x+1))^(2*n+1) / of_nat (2*n+1)))"
eberlm@62049
  2135
    by (intro ext) (simp add: y_def)
eberlm@62049
  2136
  also have "\<i> * y = (of_real x - 1) / (-\<i> * (of_real x + 1))"
eberlm@62049
  2137
    by (subst divide_divide_eq_left [symmetric]) (simp add: y_def)
eberlm@62049
  2138
  also have "\<dots> = moebius 1 (-1) (-\<i>) (-\<i>) (of_real x)" by (simp add: moebius_def algebra_simps)
eberlm@62049
  2139
  also from x' have "-2*\<i>*Arctan \<dots> = Ln (of_real x)" by (intro Ln_conv_Arctan [symmetric]) simp_all
eberlm@62049
  2140
  also from x have "\<dots> = ln x" by (rule Ln_of_real)
eberlm@62049
  2141
  finally show ?thesis by (subst (asm) sums_of_real_iff)
eberlm@62049
  2142
qed
lp15@59870
  2143
wenzelm@60420
  2144
subsection \<open>Real arctangent\<close>
lp15@59870
  2145
lp15@59870
  2146
lemma norm_exp_ii_times [simp]: "norm (exp(\<i> * of_real y)) = 1"
lp15@59870
  2147
  by simp
lp15@59870
  2148
lp15@59870
  2149
lemma norm_exp_imaginary: "norm(exp z) = 1 \<Longrightarrow> Re z = 0"
lp15@59870
  2150
  by (simp add: complex_norm_eq_1_exp)
lp15@59870
  2151
lp15@59870
  2152
lemma Im_Arctan_of_real [simp]: "Im (Arctan (of_real x)) = 0"
lp15@59870
  2153
  unfolding Arctan_def divide_complex_def
lp15@59870
  2154
  apply (simp add: complex_eq_iff)
lp15@59870
  2155
  apply (rule norm_exp_imaginary)
lp15@59870
  2156
  apply (subst exp_Ln, auto)
lp15@59870
  2157
  apply (simp_all add: cmod_def complex_eq_iff)
lp15@59870
  2158
  apply (auto simp: divide_simps)
lp15@61609
  2159
  apply (metis power_one sum_power2_eq_zero_iff zero_neq_one, algebra)
lp15@59870
  2160
  done
lp15@59870
  2161
lp15@59870
  2162
lemma arctan_eq_Re_Arctan: "arctan x = Re (Arctan (of_real x))"
lp15@59870
  2163
proof (rule arctan_unique)
lp15@59870
  2164
  show "- (pi / 2) < Re (Arctan (complex_of_real x))"
lp15@59870
  2165
    apply (simp add: Arctan_def)
lp15@59870
  2166
    apply (rule Im_Ln_less_pi)
paulson@62131
  2167
    apply (auto simp: Im_complex_div_lemma complex_nonpos_Reals_iff)
lp15@59870
  2168
    done
lp15@59870
  2169
next
lp15@59870
  2170
  have *: " (1 - \<i>*x) / (1 + \<i>*x) \<noteq> 0"
lp15@59870
  2171
    by (simp add: divide_simps) ( simp add: complex_eq_iff)
lp15@59870
  2172
  show "Re (Arctan (complex_of_real x)) < pi / 2"
lp15@59870
  2173
    using mpi_less_Im_Ln [OF *]
lp15@59870
  2174
    by (simp add: Arctan_def)
lp15@59870
  2175
next
lp15@59870
  2176
  have "tan (Re (Arctan (of_real x))) = Re (tan (Arctan (of_real x)))"
lp15@59870
  2177
    apply (auto simp: tan_def Complex.Re_divide Re_sin Re_cos Im_sin Im_cos)
lp15@59870
  2178
    apply (simp add: field_simps)
lp15@59870
  2179
    by (simp add: power2_eq_square)
lp15@59870
  2180
  also have "... = x"
lp15@59870
  2181
    apply (subst tan_Arctan, auto)
lp15@59870
  2182
    by (metis diff_0_right minus_diff_eq mult_zero_left not_le of_real_1 of_real_eq_iff of_real_minus of_real_power power2_eq_square real_minus_mult_self_le zero_less_one)
lp15@59870
  2183
  finally show "tan (Re (Arctan (complex_of_real x))) = x" .
lp15@59870
  2184
qed
lp15@59870
  2185
lp15@59870
  2186
lemma Arctan_of_real: "Arctan (of_real x) = of_real (arctan x)"
lp15@59870
  2187
  unfolding arctan_eq_Re_Arctan divide_complex_def
lp15@59870
  2188
  by (simp add: complex_eq_iff)
lp15@59870
  2189
lp15@59870
  2190
lemma Arctan_in_Reals [simp]: "z \<in> \<real> \<Longrightarrow> Arctan z \<in> \<real>"
lp15@59870
  2191
  by (metis Reals_cases Reals_of_real Arctan_of_real)
lp15@59870
  2192
lp15@59870
  2193
declare arctan_one [simp]
lp15@59870
  2194
lp15@59870
  2195
lemma arctan_less_pi4_pos: "x < 1 \<Longrightarrow> arctan x < pi/4"
lp15@59870
  2196
  by (metis arctan_less_iff arctan_one)
lp15@59870
  2197
lp15@59870
  2198
lemma arctan_less_pi4_neg: "-1 < x \<Longrightarrow> -(pi/4) < arctan x"
lp15@59870
  2199
  by (metis arctan_less_iff arctan_minus arctan_one)
lp15@59870
  2200
wenzelm@61945
  2201
lemma arctan_less_pi4: "\<bar>x\<bar> < 1 \<Longrightarrow> \<bar>arctan x\<bar> < pi/4"
lp15@59870
  2202
  by (metis abs_less_iff arctan_less_pi4_pos arctan_minus)
lp15@59870
  2203
wenzelm@61945
  2204
lemma arctan_le_pi4: "\<bar>x\<bar> \<le> 1 \<Longrightarrow> \<bar>arctan x\<bar> \<le> pi/4"
lp15@59870
  2205
  by (metis abs_le_iff arctan_le_iff arctan_minus arctan_one)
lp15@59870
  2206
wenzelm@61945
  2207
lemma abs_arctan: "\<bar>arctan x\<bar> = arctan \<bar>x\<bar>"
lp15@59870
  2208
  by (simp add: abs_if arctan_minus)
lp15@59870
  2209
lp15@59870
  2210
lemma arctan_add_raw:
wenzelm@61945
  2211
  assumes "\<bar>arctan x + arctan y\<bar> < pi/2"
lp15@59870
  2212
    shows "arctan x + arctan y = arctan((x + y) / (1 - x * y))"
lp15@59870
  2213
proof (rule arctan_unique [symmetric])
lp15@59870
  2214
  show 12: "- (pi / 2) < arctan x + arctan y" "arctan x + arctan y < pi / 2"
lp15@59870
  2215
    using assms by linarith+
lp15@59870
  2216
  show "tan (arctan x + arctan y) = (x + y) / (1 - x * y)"
lp15@59870
  2217
    using cos_gt_zero_pi [OF 12]
lp15@59870
  2218
    by (simp add: arctan tan_add)
lp15@59870
  2219
qed
lp15@59870
  2220
lp15@59870
  2221
lemma arctan_inverse:
lp15@59870
  2222
  assumes "0 < x"
lp15@59870
  2223
    shows "arctan(inverse x) = pi/2 - arctan x"
lp15@59870
  2224
proof -
lp15@59870
  2225
  have "arctan(inverse x) = arctan(inverse(tan(arctan x)))"
lp15@59870
  2226
    by (simp add: arctan)
lp15@59870
  2227
  also have "... = arctan (tan (pi / 2 - arctan x))"
lp15@59870
  2228
    by (simp add: tan_cot)
lp15@59870
  2229
  also have "... = pi/2 - arctan x"
lp15@59870
  2230
  proof -
lp15@59870
  2231
    have "0 < pi - arctan x"
lp15@59870
  2232
    using arctan_ubound [of x] pi_gt_zero by linarith
lp15@59870
  2233
    with assms show ?thesis
lp15@59870
  2234
      by (simp add: Transcendental.arctan_tan)
lp15@59870
  2235
  qed
lp15@59870
  2236
  finally show ?thesis .
lp15@59870
  2237
qed
lp15@59870
  2238
lp15@59870
  2239
lemma arctan_add_small:
wenzelm@61945
  2240
  assumes "\<bar>x * y\<bar> < 1"
lp15@59870