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