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