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