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