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