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