src/HOL/Analysis/Complex_Transcendental.thy
changeset 68493 143b4cc8fc74
parent 68281 faa4b49d1b34
child 68499 d4312962161a
equal deleted inserted replaced
68491:f0f83ce0badd 68493:143b4cc8fc74
    58 lemma cmod_square_less_1_plus:
    58 lemma cmod_square_less_1_plus:
    59   assumes "Im z = 0 \<Longrightarrow> \<bar>Re z\<bar> < 1"
    59   assumes "Im z = 0 \<Longrightarrow> \<bar>Re z\<bar> < 1"
    60     shows "(cmod z)\<^sup>2 < 1 + cmod (1 - z\<^sup>2)"
    60     shows "(cmod z)\<^sup>2 < 1 + cmod (1 - z\<^sup>2)"
    61 proof (cases "Im z = 0 \<or> Re z = 0")
    61 proof (cases "Im z = 0 \<or> Re z = 0")
    62   case True
    62   case True
    63   with assms abs_square_less_1 show ?thesis 
    63   with assms abs_square_less_1 show ?thesis
    64     by (force simp add: Re_power2 Im_power2 cmod_def)
    64     by (force simp add: Re_power2 Im_power2 cmod_def)
    65 next
    65 next
    66   case False
    66   case False
    67   with cmod_diff_real_less [of "1 - z\<^sup>2" "1"] show ?thesis
    67   with cmod_diff_real_less [of "1 - z\<^sup>2" "1"] show ?thesis
    68     by (simp add: norm_power Im_power2)
    68     by (simp add: norm_power Im_power2)
   208 lemma exp_Complex: "exp(Complex r t) = of_real(exp r) * Complex (cos t) (sin t)"
   208 lemma exp_Complex: "exp(Complex r t) = of_real(exp r) * Complex (cos t) (sin t)"
   209   by (simp add: Complex_eq exp_add exp_Euler exp_of_real sin_of_real cos_of_real)
   209   by (simp add: Complex_eq exp_add exp_Euler exp_of_real sin_of_real cos_of_real)
   210 
   210 
   211 lemma exp_eq_1: "exp z = 1 \<longleftrightarrow> Re(z) = 0 \<and> (\<exists>n::int. Im(z) = of_int (2 * n) * pi)"
   211 lemma exp_eq_1: "exp z = 1 \<longleftrightarrow> Re(z) = 0 \<and> (\<exists>n::int. Im(z) = of_int (2 * n) * pi)"
   212                  (is "?lhs = ?rhs")
   212                  (is "?lhs = ?rhs")
   213 proof 
   213 proof
   214   assume "exp z = 1"
   214   assume "exp z = 1"
   215   then have "Re z = 0"
   215   then have "Re z = 0"
   216     by (metis exp_eq_one_iff norm_exp_eq_Re norm_one)
   216     by (metis exp_eq_one_iff norm_exp_eq_Re norm_one)
   217   with \<open>?lhs\<close> show ?rhs
   217   with \<open>?lhs\<close> show ?rhs
   218     by (metis Re_exp complex_Re_of_int cos_one_2pi_int exp_zero mult.commute mult_numeral_1 numeral_One of_int_mult of_int_numeral)
   218     by (metis Re_exp complex_Re_of_int cos_one_2pi_int exp_zero mult.commute mult_numeral_1 numeral_One of_int_mult of_int_numeral)
   768 lemma ln3_gt_1: "ln 3 > (1::real)"
   768 lemma ln3_gt_1: "ln 3 > (1::real)"
   769   by (simp add: less_trans [OF ln_272_gt_1])
   769   by (simp add: less_trans [OF ln_272_gt_1])
   770 
   770 
   771 subsection\<open>The argument of a complex number\<close>
   771 subsection\<open>The argument of a complex number\<close>
   772 
   772 
   773 definition Arg :: "complex \<Rightarrow> real" where
   773 definition Arg2pi :: "complex \<Rightarrow> real" where
   774  "Arg z \<equiv> if z = 0 then 0
   774  "Arg2pi z \<equiv> if z = 0 then 0
   775            else THE t. 0 \<le> t \<and> t < 2*pi \<and>
   775            else THE t. 0 \<le> t \<and> t < 2*pi \<and>
   776                     z = of_real(norm z) * exp(\<i> * of_real t)"
   776                     z = of_real(norm z) * exp(\<i> * of_real t)"
   777 
   777 
   778 lemma Arg_0 [simp]: "Arg(0) = 0"
   778 lemma Arg2pi_0 [simp]: "Arg2pi(0) = 0"
   779   by (simp add: Arg_def)
   779   by (simp add: Arg2pi_def)
   780 
   780 
   781 lemma Arg_unique_lemma:
   781 lemma Arg2pi_unique_lemma:
   782   assumes z:  "z = of_real(norm z) * exp(\<i> * of_real t)"
   782   assumes z:  "z = of_real(norm z) * exp(\<i> * of_real t)"
   783       and z': "z = of_real(norm z) * exp(\<i> * of_real t')"
   783       and z': "z = of_real(norm z) * exp(\<i> * of_real t')"
   784       and t:  "0 \<le> t"  "t < 2*pi"
   784       and t:  "0 \<le> t"  "t < 2*pi"
   785       and t': "0 \<le> t'" "t' < 2*pi"
   785       and t': "0 \<le> t'" "t' < 2*pi"
   786       and nz: "z \<noteq> 0"
   786       and nz: "z \<noteq> 0"
   801     by (cases n) (use t t' in \<open>auto simp: mult_less_0_iff algebra_simps\<close>)
   801     by (cases n) (use t t' in \<open>auto simp: mult_less_0_iff algebra_simps\<close>)
   802   then show "t' = t"
   802   then show "t' = t"
   803     by (simp add: n)
   803     by (simp add: n)
   804 qed
   804 qed
   805 
   805 
   806 lemma Arg: "0 \<le> Arg z & Arg z < 2*pi & z = of_real(norm z) * exp(\<i> * of_real(Arg z))"
   806 lemma Arg2pi: "0 \<le> Arg2pi z & Arg2pi z < 2*pi & z = of_real(norm z) * exp(\<i> * of_real(Arg2pi z))"
   807 proof (cases "z=0")
   807 proof (cases "z=0")
   808   case True then show ?thesis
   808   case True then show ?thesis
   809     by (simp add: Arg_def)
   809     by (simp add: Arg2pi_def)
   810 next
   810 next
   811   case False
   811   case False
   812   obtain t where t: "0 \<le> t" "t < 2*pi"
   812   obtain t where t: "0 \<le> t" "t < 2*pi"
   813              and ReIm: "Re z / cmod z = cos t" "Im z / cmod z = sin t"
   813              and ReIm: "Re z / cmod z = cos t" "Im z / cmod z = sin t"
   814     using sincos_total_2pi [OF complex_unit_circle [OF False]]
   814     using sincos_total_2pi [OF complex_unit_circle [OF False]]
   817     apply (rule complex_eqI)
   817     apply (rule complex_eqI)
   818     using t False ReIm
   818     using t False ReIm
   819     apply (auto simp: exp_Euler sin_of_real cos_of_real divide_simps)
   819     apply (auto simp: exp_Euler sin_of_real cos_of_real divide_simps)
   820     done
   820     done
   821   show ?thesis
   821   show ?thesis
   822     apply (simp add: Arg_def False)
   822     apply (simp add: Arg2pi_def False)
   823     apply (rule theI [where a=t])
   823     apply (rule theI [where a=t])
   824     using t z False
   824     using t z False
   825     apply (auto intro: Arg_unique_lemma)
   825     apply (auto intro: Arg2pi_unique_lemma)
   826     done
   826     done
   827 qed
   827 qed
   828 
   828 
   829 corollary
   829 corollary
   830   shows Arg_ge_0: "0 \<le> Arg z"
   830   shows Arg2pi_ge_0: "0 \<le> Arg2pi z"
   831     and Arg_lt_2pi: "Arg z < 2*pi"
   831     and Arg2pi_lt_2pi: "Arg2pi z < 2*pi"
   832     and Arg_eq: "z = of_real(norm z) * exp(\<i> * of_real(Arg z))"
   832     and Arg2pi_eq: "z = of_real(norm z) * exp(\<i> * of_real(Arg2pi z))"
   833   using Arg by auto
   833   using Arg2pi by auto
   834 
   834 
   835 lemma complex_norm_eq_1_exp: "norm z = 1 \<longleftrightarrow> exp(\<i> * of_real (Arg z)) = z"
   835 lemma complex_norm_eq_1_exp: "norm z = 1 \<longleftrightarrow> exp(\<i> * of_real (Arg2pi z)) = z"
   836   by (metis Arg_eq cis_conv_exp mult.left_neutral norm_cis of_real_1)
   836   by (metis Arg2pi_eq cis_conv_exp mult.left_neutral norm_cis of_real_1)
   837 
   837 
   838 lemma Arg_unique: "\<lbrakk>of_real r * exp(\<i> * of_real a) = z; 0 < r; 0 \<le> a; a < 2*pi\<rbrakk> \<Longrightarrow> Arg z = a"
   838 lemma Arg2pi_unique: "\<lbrakk>of_real r * exp(\<i> * of_real a) = z; 0 < r; 0 \<le> a; a < 2*pi\<rbrakk> \<Longrightarrow> Arg2pi z = a"
   839   by (rule Arg_unique_lemma [OF _ Arg_eq])
   839   by (rule Arg2pi_unique_lemma [OF _ Arg2pi_eq])
   840   (use Arg [of z] in \<open>auto simp: norm_mult\<close>)
   840   (use Arg2pi [of z] in \<open>auto simp: norm_mult\<close>)
   841 
   841 
   842 lemma Arg_minus: "z \<noteq> 0 \<Longrightarrow> Arg (-z) = (if Arg z < pi then Arg z + pi else Arg z - pi)"
   842 lemma Arg2pi_minus: "z \<noteq> 0 \<Longrightarrow> Arg2pi (-z) = (if Arg2pi z < pi then Arg2pi z + pi else Arg2pi z - pi)"
   843   apply (rule Arg_unique [of "norm z"])
   843   apply (rule Arg2pi_unique [of "norm z"])
   844   apply (rule complex_eqI)
   844   apply (rule complex_eqI)
   845   using Arg_ge_0 [of z] Arg_eq [of z] Arg_lt_2pi [of z] 
   845   using Arg2pi_ge_0 [of z] Arg2pi_eq [of z] Arg2pi_lt_2pi [of z]
   846   apply (auto simp: Re_exp Im_exp cos_diff sin_diff cis_conv_exp [symmetric])
   846   apply (auto simp: Re_exp Im_exp cos_diff sin_diff cis_conv_exp [symmetric])
   847   apply (metis Re_rcis Im_rcis rcis_def)+
   847   apply (metis Re_rcis Im_rcis rcis_def)+
   848   done
   848   done
   849 
   849 
   850 lemma Arg_times_of_real [simp]:
   850 lemma Arg2pi_times_of_real [simp]:
   851   assumes "0 < r" shows "Arg (of_real r * z) = Arg z"
   851   assumes "0 < r" shows "Arg2pi (of_real r * z) = Arg2pi z"
   852 proof (cases "z=0")
   852 proof (cases "z=0")
   853   case False
   853   case False
   854   show ?thesis
   854   show ?thesis
   855     by (rule Arg_unique [of "r * norm z"]) (use Arg False assms in auto)
   855     by (rule Arg2pi_unique [of "r * norm z"]) (use Arg2pi False assms in auto)
   856 qed auto
   856 qed auto
   857 
   857 
   858 lemma Arg_times_of_real2 [simp]: "0 < r \<Longrightarrow> Arg (z * of_real r) = Arg z"
   858 lemma Arg2pi_times_of_real2 [simp]: "0 < r \<Longrightarrow> Arg2pi (z * of_real r) = Arg2pi z"
   859   by (metis Arg_times_of_real mult.commute)
   859   by (metis Arg2pi_times_of_real mult.commute)
   860 
   860 
   861 lemma Arg_divide_of_real [simp]: "0 < r \<Longrightarrow> Arg (z / of_real r) = Arg z"
   861 lemma Arg2pi_divide_of_real [simp]: "0 < r \<Longrightarrow> Arg2pi (z / of_real r) = Arg2pi z"
   862   by (metis Arg_times_of_real2 less_numeral_extra(3) nonzero_eq_divide_eq of_real_eq_0_iff)
   862   by (metis Arg2pi_times_of_real2 less_numeral_extra(3) nonzero_eq_divide_eq of_real_eq_0_iff)
   863 
   863 
   864 lemma Arg_le_pi: "Arg z \<le> pi \<longleftrightarrow> 0 \<le> Im z"
   864 lemma Arg2pi_le_pi: "Arg2pi z \<le> pi \<longleftrightarrow> 0 \<le> Im z"
   865 proof (cases "z=0")
   865 proof (cases "z=0")
   866   case False
   866   case False
   867   have "0 \<le> Im z \<longleftrightarrow> 0 \<le> Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
   867   have "0 \<le> Im z \<longleftrightarrow> 0 \<le> Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg2pi z)))"
   868     by (metis Arg_eq)
   868     by (metis Arg2pi_eq)
   869   also have "... = (0 \<le> Im (exp (\<i> * complex_of_real (Arg z))))"
   869   also have "... = (0 \<le> Im (exp (\<i> * complex_of_real (Arg2pi z))))"
   870     using False  by (simp add: zero_le_mult_iff)
   870     using False  by (simp add: zero_le_mult_iff)
   871   also have "... \<longleftrightarrow> Arg z \<le> pi"
   871   also have "... \<longleftrightarrow> Arg2pi z \<le> pi"
   872     by (simp add: Im_exp) (metis Arg_ge_0 Arg_lt_2pi sin_lt_zero sin_ge_zero not_le)
   872     by (simp add: Im_exp) (metis Arg2pi_ge_0 Arg2pi_lt_2pi sin_lt_zero sin_ge_zero not_le)
   873   finally show ?thesis
   873   finally show ?thesis
   874     by blast
   874     by blast
   875 qed auto
   875 qed auto
   876 
   876 
   877 lemma Arg_lt_pi: "0 < Arg z \<and> Arg z < pi \<longleftrightarrow> 0 < Im z"
   877 lemma Arg2pi_lt_pi: "0 < Arg2pi z \<and> Arg2pi z < pi \<longleftrightarrow> 0 < Im z"
   878 proof (cases "z=0")
   878 proof (cases "z=0")
   879   case False
   879   case False
   880   have "0 < Im z \<longleftrightarrow> 0 < Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg z)))"
   880   have "0 < Im z \<longleftrightarrow> 0 < Im (of_real (cmod z) * exp (\<i> * complex_of_real (Arg2pi z)))"
   881     by (metis Arg_eq)
   881     by (metis Arg2pi_eq)
   882   also have "... = (0 < Im (exp (\<i> * complex_of_real (Arg z))))"
   882   also have "... = (0 < Im (exp (\<i> * complex_of_real (Arg2pi z))))"
   883     using False by (simp add: zero_less_mult_iff)
   883     using False by (simp add: zero_less_mult_iff)
   884   also have "... \<longleftrightarrow> 0 < Arg z \<and> Arg z < pi"
   884   also have "... \<longleftrightarrow> 0 < Arg2pi z \<and> Arg2pi z < pi"
   885     using Arg_ge_0 Arg_lt_2pi sin_le_zero sin_gt_zero
   885     using Arg2pi_ge_0 Arg2pi_lt_2pi sin_le_zero sin_gt_zero
   886     apply (auto simp: Im_exp)
   886     apply (auto simp: Im_exp)
   887     using le_less apply fastforce
   887     using le_less apply fastforce
   888     using not_le by blast
   888     using not_le by blast
   889   finally show ?thesis
   889   finally show ?thesis
   890     by blast
   890     by blast
   891 qed auto
   891 qed auto
   892 
   892 
   893 lemma Arg_eq_0: "Arg z = 0 \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re z"
   893 lemma Arg2pi_eq_0: "Arg2pi z = 0 \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re z"
   894 proof (cases "z=0")
   894 proof (cases "z=0")
   895   case False
   895   case False
   896   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)))"
   896   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 (Arg2pi z)))"
   897     by (metis Arg_eq)
   897     by (metis Arg2pi_eq)
   898   also have "... \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re (exp (\<i> * complex_of_real (Arg z)))"
   898   also have "... \<longleftrightarrow> z \<in> \<real> \<and> 0 \<le> Re (exp (\<i> * complex_of_real (Arg2pi z)))"
   899     using False  by (simp add: zero_le_mult_iff)
   899     using False  by (simp add: zero_le_mult_iff)
   900   also have "... \<longleftrightarrow> Arg z = 0"
   900   also have "... \<longleftrightarrow> Arg2pi z = 0"
   901   proof -
   901   proof -
   902     have [simp]: "Arg z = 0 \<Longrightarrow> z \<in> \<real>"
   902     have [simp]: "Arg2pi z = 0 \<Longrightarrow> z \<in> \<real>"
   903       using Arg_eq [of z] by (auto simp: Reals_def)
   903       using Arg2pi_eq [of z] by (auto simp: Reals_def)
   904     moreover have "\<lbrakk>z \<in> \<real>; 0 \<le> cos (Arg z)\<rbrakk> \<Longrightarrow> Arg z = 0"
   904     moreover have "\<lbrakk>z \<in> \<real>; 0 \<le> cos (Arg2pi z)\<rbrakk> \<Longrightarrow> Arg2pi z = 0"
   905       by (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)
   905       by (metis Arg2pi_lt_pi Arg2pi_ge_0 Arg2pi_le_pi cos_pi complex_is_Real_iff leD less_linear less_minus_one_simps(2) minus_minus neg_less_eq_nonneg order_refl)
   906     ultimately show ?thesis
   906     ultimately show ?thesis
   907       by (auto simp: Re_exp)
   907       by (auto simp: Re_exp)
   908   qed
   908   qed
   909   finally show ?thesis
   909   finally show ?thesis
   910     by blast
   910     by blast
   911 qed auto
   911 qed auto
   912 
   912 
   913 corollary Arg_gt_0:
   913 corollary Arg2pi_gt_0:
   914   assumes "z \<in> \<real> \<Longrightarrow> Re z < 0"
   914   assumes "z \<in> \<real> \<Longrightarrow> Re z < 0"
   915     shows "Arg z > 0"
   915     shows "Arg2pi z > 0"
   916   using Arg_eq_0 Arg_ge_0 assms dual_order.strict_iff_order by fastforce
   916   using Arg2pi_eq_0 Arg2pi_ge_0 assms dual_order.strict_iff_order by fastforce
   917 
   917 
   918 lemma Arg_of_real: "Arg(of_real x) = 0 \<longleftrightarrow> 0 \<le> x"
   918 lemma Arg2pi_of_real: "Arg2pi(of_real x) = 0 \<longleftrightarrow> 0 \<le> x"
   919   by (simp add: Arg_eq_0)
   919   by (simp add: Arg2pi_eq_0)
   920 
   920 
   921 lemma Arg_eq_pi: "Arg z = pi \<longleftrightarrow> z \<in> \<real> \<and> Re z < 0"
   921 lemma Arg2pi_eq_pi: "Arg2pi z = pi \<longleftrightarrow> z \<in> \<real> \<and> Re z < 0"
   922   using Arg_eq_0 [of "-z"]
   922   using Arg2pi_eq_0 [of "-z"]
   923   by (metis Arg_eq_0 Arg_gt_0 Arg_le_pi Arg_lt_pi complex_is_Real_iff dual_order.order_iff_strict not_less pi_neq_zero)
   923   by (metis Arg2pi_eq_0 Arg2pi_gt_0 Arg2pi_le_pi Arg2pi_lt_pi complex_is_Real_iff dual_order.order_iff_strict not_less pi_neq_zero)
   924 
   924 
   925 lemma Arg_eq_0_pi: "Arg z = 0 \<or> Arg z = pi \<longleftrightarrow> z \<in> \<real>"
   925 lemma Arg2pi_eq_0_pi: "Arg2pi z = 0 \<or> Arg2pi z = pi \<longleftrightarrow> z \<in> \<real>"
   926   using Arg_eq_0 Arg_eq_pi not_le by auto
   926   using Arg2pi_eq_0 Arg2pi_eq_pi not_le by auto
   927 
   927 
   928 lemma Arg_inverse: "Arg(inverse z) = (if z \<in> \<real> \<and> 0 \<le> Re z then Arg z else 2*pi - Arg z)"
   928 lemma Arg2pi_inverse: "Arg2pi(inverse z) = (if z \<in> \<real> \<and> 0 \<le> Re z then Arg2pi z else 2*pi - Arg2pi z)"
   929 proof (cases "z=0")
   929 proof (cases "z=0")
   930   case False
   930   case False
   931   show ?thesis
   931   show ?thesis
   932     apply (rule Arg_unique [of "inverse (norm z)"])
   932     apply (rule Arg2pi_unique [of "inverse (norm z)"])
   933     using False Arg_ge_0 [of z] Arg_lt_2pi [of z] Arg_eq [of z] Arg_eq_0 [of z] 
   933     using False Arg2pi_ge_0 [of z] Arg2pi_lt_2pi [of z] Arg2pi_eq [of z] Arg2pi_eq_0 [of z]
   934        apply (auto simp: exp_diff field_simps)
   934        apply (auto simp: exp_diff field_simps)
   935     done
   935     done
   936 qed auto
   936 qed auto
   937 
   937 
   938 lemma Arg_eq_iff:
   938 lemma Arg2pi_eq_iff:
   939   assumes "w \<noteq> 0" "z \<noteq> 0"
   939   assumes "w \<noteq> 0" "z \<noteq> 0"
   940      shows "Arg w = Arg z \<longleftrightarrow> (\<exists>x. 0 < x & w = of_real x * z)"
   940      shows "Arg2pi w = Arg2pi z \<longleftrightarrow> (\<exists>x. 0 < x & w = of_real x * z)"
   941   using assms Arg_eq [of z] Arg_eq [of w]
   941   using assms Arg2pi_eq [of z] Arg2pi_eq [of w]
   942   apply auto
   942   apply auto
   943   apply (rule_tac x="norm w / norm z" in exI)
   943   apply (rule_tac x="norm w / norm z" in exI)
   944   apply (simp add: divide_simps)
   944   apply (simp add: divide_simps)
   945   by (metis mult.commute mult.left_commute)
   945   by (metis mult.commute mult.left_commute)
   946 
   946 
   947 lemma Arg_inverse_eq_0: "Arg(inverse z) = 0 \<longleftrightarrow> Arg z = 0"
   947 lemma Arg2pi_inverse_eq_0: "Arg2pi(inverse z) = 0 \<longleftrightarrow> Arg2pi z = 0"
   948   by (metis Arg_eq_0 Arg_inverse inverse_inverse_eq)
   948   by (metis Arg2pi_eq_0 Arg2pi_inverse inverse_inverse_eq)
   949 
   949 
   950 lemma Arg_divide:
   950 lemma Arg2pi_divide:
   951   assumes "w \<noteq> 0" "z \<noteq> 0" "Arg w \<le> Arg z"
   951   assumes "w \<noteq> 0" "z \<noteq> 0" "Arg2pi w \<le> Arg2pi z"
   952     shows "Arg(z / w) = Arg z - Arg w"
   952     shows "Arg2pi(z / w) = Arg2pi z - Arg2pi w"
   953   apply (rule Arg_unique [of "norm(z / w)"])
   953   apply (rule Arg2pi_unique [of "norm(z / w)"])
   954   using assms Arg_eq Arg_ge_0 [of w] Arg_lt_2pi [of z]
   954   using assms Arg2pi_eq Arg2pi_ge_0 [of w] Arg2pi_lt_2pi [of z]
   955   apply (auto simp: exp_diff norm_divide field_simps)
   955   apply (auto simp: exp_diff norm_divide field_simps)
   956   done
   956   done
   957 
   957 
   958 lemma Arg_le_div_sum:
   958 lemma Arg2pi_le_div_sum:
   959   assumes "w \<noteq> 0" "z \<noteq> 0" "Arg w \<le> Arg z"
   959   assumes "w \<noteq> 0" "z \<noteq> 0" "Arg2pi w \<le> Arg2pi z"
   960     shows "Arg z = Arg w + Arg(z / w)"
   960     shows "Arg2pi z = Arg2pi w + Arg2pi(z / w)"
   961   by (simp add: Arg_divide assms)
   961   by (simp add: Arg2pi_divide assms)
   962 
   962 
   963 lemma Arg_le_div_sum_eq:
   963 lemma Arg2pi_le_div_sum_eq:
   964   assumes "w \<noteq> 0" "z \<noteq> 0"
   964   assumes "w \<noteq> 0" "z \<noteq> 0"
   965     shows "Arg w \<le> Arg z \<longleftrightarrow> Arg z = Arg w + Arg(z / w)"
   965     shows "Arg2pi w \<le> Arg2pi z \<longleftrightarrow> Arg2pi z = Arg2pi w + Arg2pi(z / w)"
   966   using assms by (auto simp: Arg_ge_0 intro: Arg_le_div_sum)
   966   using assms by (auto simp: Arg2pi_ge_0 intro: Arg2pi_le_div_sum)
   967 
   967 
   968 lemma Arg_diff:
   968 lemma Arg2pi_diff:
   969   assumes "w \<noteq> 0" "z \<noteq> 0"
   969   assumes "w \<noteq> 0" "z \<noteq> 0"
   970     shows "Arg w - Arg z = (if Arg z \<le> Arg w then Arg(w / z) else Arg(w/z) - 2*pi)"
   970     shows "Arg2pi w - Arg2pi z = (if Arg2pi z \<le> Arg2pi w then Arg2pi(w / z) else Arg2pi(w/z) - 2*pi)"
   971   using assms Arg_divide Arg_inverse [of "w/z"]
   971   using assms Arg2pi_divide Arg2pi_inverse [of "w/z"]
   972   apply (clarsimp simp add: Arg_ge_0 Arg_divide not_le)
   972   apply (clarsimp simp add: Arg2pi_ge_0 Arg2pi_divide not_le)
   973   by (metis Arg_eq_0 less_irrefl minus_diff_eq right_minus_eq)
   973   by (metis Arg2pi_eq_0 less_irrefl minus_diff_eq right_minus_eq)
   974 
   974 
   975 lemma Arg_add:
   975 lemma Arg2pi_add:
   976   assumes "w \<noteq> 0" "z \<noteq> 0"
   976   assumes "w \<noteq> 0" "z \<noteq> 0"
   977     shows "Arg w + Arg z = (if Arg w + Arg z < 2*pi then Arg(w * z) else Arg(w * z) + 2*pi)"
   977     shows "Arg2pi w + Arg2pi z = (if Arg2pi w + Arg2pi z < 2*pi then Arg2pi(w * z) else Arg2pi(w * z) + 2*pi)"
   978   using assms Arg_diff [of "w*z" z] Arg_le_div_sum_eq [of z "w*z"]
   978   using assms Arg2pi_diff [of "w*z" z] Arg2pi_le_div_sum_eq [of z "w*z"]
   979   apply (auto simp: Arg_ge_0 Arg_divide not_le)
   979   apply (auto simp: Arg2pi_ge_0 Arg2pi_divide not_le)
   980   apply (metis Arg_lt_2pi add.commute)
   980   apply (metis Arg2pi_lt_2pi add.commute)
   981   apply (metis (no_types) Arg add.commute diff_0 diff_add_cancel diff_less_eq diff_minus_eq_add not_less)
   981   apply (metis (no_types) Arg2pi add.commute diff_0 diff_add_cancel diff_less_eq diff_minus_eq_add not_less)
   982   done
   982   done
   983 
   983 
   984 lemma Arg_times:
   984 lemma Arg2pi_times:
   985   assumes "w \<noteq> 0" "z \<noteq> 0"
   985   assumes "w \<noteq> 0" "z \<noteq> 0"
   986     shows "Arg (w * z) = (if Arg w + Arg z < 2*pi then Arg w + Arg z
   986     shows "Arg2pi (w * z) = (if Arg2pi w + Arg2pi z < 2*pi then Arg2pi w + Arg2pi z
   987                             else (Arg w + Arg z) - 2*pi)"
   987                             else (Arg2pi w + Arg2pi z) - 2*pi)"
   988   using Arg_add [OF assms]
   988   using Arg2pi_add [OF assms]
   989   by auto
   989   by auto
   990 
   990 
   991 lemma Arg_cnj_eq_inverse: "z\<noteq>0 \<Longrightarrow> Arg (cnj z) = Arg (inverse z)"
   991 lemma Arg2pi_cnj_eq_inverse: "z\<noteq>0 \<Longrightarrow> Arg2pi (cnj z) = Arg2pi (inverse z)"
   992   apply (simp add: Arg_eq_iff divide_simps complex_norm_square [symmetric] mult.commute)
   992   apply (simp add: Arg2pi_eq_iff divide_simps complex_norm_square [symmetric] mult.commute)
   993   by (metis of_real_power zero_less_norm_iff zero_less_power)
   993   by (metis of_real_power zero_less_norm_iff zero_less_power)
   994 
   994 
   995 lemma Arg_cnj: "Arg(cnj z) = (if z \<in> \<real> \<and> 0 \<le> Re z then Arg z else 2*pi - Arg z)"
   995 lemma Arg2pi_cnj: "Arg2pi(cnj z) = (if z \<in> \<real> \<and> 0 \<le> Re z then Arg2pi z else 2*pi - Arg2pi z)"
   996 proof (cases "z=0")
   996 proof (cases "z=0")
   997   case False
   997   case False
   998   then show ?thesis
   998   then show ?thesis
   999     by (simp add: Arg_cnj_eq_inverse Arg_inverse)
   999     by (simp add: Arg2pi_cnj_eq_inverse Arg2pi_inverse)
  1000 qed auto
  1000 qed auto
  1001 
  1001 
  1002 lemma Arg_real: "z \<in> \<real> \<Longrightarrow> Arg z = (if 0 \<le> Re z then 0 else pi)"
  1002 lemma Arg2pi_real: "z \<in> \<real> \<Longrightarrow> Arg2pi z = (if 0 \<le> Re z then 0 else pi)"
  1003   using Arg_eq_0 Arg_eq_0_pi by auto
  1003   using Arg2pi_eq_0 Arg2pi_eq_0_pi by auto
  1004 
  1004 
  1005 lemma Arg_exp: "0 \<le> Im z \<Longrightarrow> Im z < 2*pi \<Longrightarrow> Arg(exp z) = Im z"
  1005 lemma Arg2pi_exp: "0 \<le> Im z \<Longrightarrow> Im z < 2*pi \<Longrightarrow> Arg2pi(exp z) = Im z"
  1006   by (rule Arg_unique [of "exp(Re z)"]) (auto simp: exp_eq_polar)
  1006   by (rule Arg2pi_unique [of "exp(Re z)"]) (auto simp: exp_eq_polar)
  1007 
  1007 
  1008 lemma complex_split_polar:
  1008 lemma complex_split_polar:
  1009   obtains r a::real where "z = complex_of_real r * (cos a + \<i> * sin a)" "0 \<le> r" "0 \<le> a" "a < 2*pi"
  1009   obtains r a::real where "z = complex_of_real r * (cos a + \<i> * sin a)" "0 \<le> r" "0 \<le> a" "a < 2*pi"
  1010   using Arg cis.ctr cis_conv_exp unfolding Complex_eq by fastforce
  1010   using Arg2pi cis.ctr cis_conv_exp unfolding Complex_eq by fastforce
  1011 
  1011 
  1012 lemma Re_Im_le_cmod: "Im w * sin \<phi> + Re w * cos \<phi> \<le> cmod w"
  1012 lemma Re_Im_le_cmod: "Im w * sin \<phi> + Re w * cos \<phi> \<le> cmod w"
  1013 proof (cases w rule: complex_split_polar)
  1013 proof (cases w rule: complex_split_polar)
  1014   case (1 r a) with sin_cos_le1 [of a \<phi>] show ?thesis
  1014   case (1 r a) with sin_cos_le1 [of a \<phi>] show ?thesis
  1015     apply (simp add: norm_mult cmod_unit_one)
  1015     apply (simp add: norm_mult cmod_unit_one)
  1106 lemma Ln_1 [simp]: "ln 1 = (0::complex)"
  1106 lemma Ln_1 [simp]: "ln 1 = (0::complex)"
  1107 proof -
  1107 proof -
  1108   have "ln (exp 0) = (0::complex)"
  1108   have "ln (exp 0) = (0::complex)"
  1109     by (simp add: del: exp_zero)
  1109     by (simp add: del: exp_zero)
  1110   then show ?thesis
  1110   then show ?thesis
  1111     by simp                              
  1111     by simp
  1112 qed
  1112 qed
  1113 
  1113 
  1114   
  1114 
  1115 lemma Ln_eq_zero_iff [simp]: "x \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> ln x = 0 \<longleftrightarrow> x = 1" for x::complex
  1115 lemma Ln_eq_zero_iff [simp]: "x \<notin> \<real>\<^sub>\<le>\<^sub>0 \<Longrightarrow> ln x = 0 \<longleftrightarrow> x = 1" for x::complex
  1116   by auto (metis exp_Ln exp_zero nonpos_Reals_zero_I)
  1116   by auto (metis exp_Ln exp_zero nonpos_Reals_zero_I)
  1117 
  1117 
  1118 instance
  1118 instance
  1119   by intro_classes (rule ln_complex_def Ln_1)
  1119   by intro_classes (rule ln_complex_def Ln_1)
  1212   using continuous_at_Ln continuous_at_imp_continuous_within by blast
  1212   using continuous_at_Ln continuous_at_imp_continuous_within by blast
  1213 
  1213 
  1214 lemma continuous_on_Ln [continuous_intros]: "(\<And>z. z \<in> S \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> continuous_on S Ln"
  1214 lemma continuous_on_Ln [continuous_intros]: "(\<And>z. z \<in> S \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> continuous_on S Ln"
  1215   by (simp add: continuous_at_imp_continuous_on continuous_within_Ln)
  1215   by (simp add: continuous_at_imp_continuous_on continuous_within_Ln)
  1216 
  1216 
  1217 lemma continuous_on_Ln' [continuous_intros]: 
  1217 lemma continuous_on_Ln' [continuous_intros]:
  1218   "continuous_on S f \<Longrightarrow> (\<And>z. z \<in> S \<Longrightarrow> f z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> continuous_on S (\<lambda>x. Ln (f x))"
  1218   "continuous_on S f \<Longrightarrow> (\<And>z. z \<in> S \<Longrightarrow> f z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> continuous_on S (\<lambda>x. Ln (f x))"
  1219   by (rule continuous_on_compose2[OF continuous_on_Ln, of "UNIV - nonpos_Reals" S f]) auto
  1219   by (rule continuous_on_compose2[OF continuous_on_Ln, of "UNIV - nonpos_Reals" S f]) auto
  1220 
  1220 
  1221 lemma holomorphic_on_Ln [holomorphic_intros]: "(\<And>z. z \<in> S \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> Ln holomorphic_on S"
  1221 lemma holomorphic_on_Ln [holomorphic_intros]: "(\<And>z. z \<in> S \<Longrightarrow> z \<notin> \<real>\<^sub>\<le>\<^sub>0) \<Longrightarrow> Ln holomorphic_on S"
  1222   by (simp add: field_differentiable_within_Ln holomorphic_on_def)
  1222   by (simp add: field_differentiable_within_Ln holomorphic_on_def)
  1252       using that \<open>3 \<le> x\<close> by (auto simp: Ln_Reals_eq in_Reals_norm group_add_class.diff_eq_eq)
  1252       using that \<open>3 \<le> x\<close> by (auto simp: Ln_Reals_eq in_Reals_norm group_add_class.diff_eq_eq)
  1253     show ?thesis
  1253     show ?thesis
  1254       using exp_le \<open>3 \<le> x\<close> x by (simp add: eq) (simp add: power_eq_if divide_simps ln_ge_iff)
  1254       using exp_le \<open>3 \<le> x\<close> x by (simp add: eq) (simp add: power_eq_if divide_simps ln_ge_iff)
  1255   qed
  1255   qed
  1256 qed
  1256 qed
  1257     
  1257 
  1258 
  1258 
  1259 subsection\<open>Quadrant-type results for Ln\<close>
  1259 subsection\<open>Quadrant-type results for Ln\<close>
  1260 
  1260 
  1261 lemma cos_lt_zero_pi: "pi/2 < x \<Longrightarrow> x < 3*pi/2 \<Longrightarrow> cos x < 0"
  1261 lemma cos_lt_zero_pi: "pi/2 < x \<Longrightarrow> x < 3*pi/2 \<Longrightarrow> cos x < 0"
  1262   using cos_minus_pi cos_gt_zero_pi [of "x-pi"]
  1262   using cos_minus_pi cos_gt_zero_pi [of "x-pi"]
  1365     also have "... < pi + pi"
  1365     also have "... < pi + pi"
  1366     proof -
  1366     proof -
  1367       have "\<bar>Im (cnj (Ln z))\<bar> < pi"
  1367       have "\<bar>Im (cnj (Ln z))\<bar> < pi"
  1368         by (simp add: False Im_Ln_less_pi abs_if assms minus_less_iff mpi_less_Im_Ln)
  1368         by (simp add: False Im_Ln_less_pi abs_if assms minus_less_iff mpi_less_Im_Ln)
  1369       moreover have "\<bar>Im (Ln (cnj z))\<bar> \<le> pi"
  1369       moreover have "\<bar>Im (Ln (cnj z))\<bar> \<le> pi"
  1370         by (meson abs_le_iff complex_cnj_zero_iff less_eq_real_def minus_less_iff  False Im_Ln_le_pi mpi_less_Im_Ln) 
  1370         by (meson abs_le_iff complex_cnj_zero_iff less_eq_real_def minus_less_iff  False Im_Ln_le_pi mpi_less_Im_Ln)
  1371       ultimately show ?thesis
  1371       ultimately show ?thesis
  1372         by simp
  1372         by simp
  1373     qed
  1373     qed
  1374     finally show "\<bar>Im (cnj (Ln z)) - Im (Ln (cnj z))\<bar> < 2 * pi"
  1374     finally show "\<bar>Im (cnj (Ln z)) - Im (Ln (cnj z))\<bar> < 2 * pi"
  1375       by simp
  1375       by simp
  1376     show "exp (cnj (Ln z)) = exp (Ln (cnj z))"
  1376     show "exp (cnj (Ln z)) = exp (Ln (cnj z))"
  1377       by (metis False complex_cnj_zero_iff exp_Ln exp_cnj)
  1377       by (metis False complex_cnj_zero_iff exp_Ln exp_cnj)
  1378   qed 
  1378   qed
  1379 qed (use assms in auto)
  1379 qed (use assms in auto)
  1380 
  1380 
  1381 
  1381 
  1382 lemma Ln_inverse: assumes "z \<notin> \<real>\<^sub>\<le>\<^sub>0" shows "Ln(inverse z) = -(Ln z)"
  1382 lemma Ln_inverse: assumes "z \<notin> \<real>\<^sub>\<le>\<^sub>0" shows "Ln(inverse z) = -(Ln z)"
  1383 proof (cases "z=0")
  1383 proof (cases "z=0")
  1393       moreover have "\<bar>Im (- Ln z)\<bar> \<le> pi"
  1393       moreover have "\<bar>Im (- Ln z)\<bar> \<le> pi"
  1394         using False Im_Ln_le_pi mpi_less_Im_Ln by fastforce
  1394         using False Im_Ln_le_pi mpi_less_Im_Ln by fastforce
  1395       ultimately show ?thesis
  1395       ultimately show ?thesis
  1396         by simp
  1396         by simp
  1397     qed
  1397     qed
  1398     finally show "\<bar>Im (Ln (inverse z)) - Im (- Ln z)\<bar> < 2 * pi" 
  1398     finally show "\<bar>Im (Ln (inverse z)) - Im (- Ln z)\<bar> < 2 * pi"
  1399       by simp
  1399       by simp
  1400     show "exp (Ln (inverse z)) = exp (- Ln z)"
  1400     show "exp (Ln (inverse z)) = exp (- Ln z)"
  1401       by (simp add: False exp_minus)
  1401       by (simp add: False exp_minus)
  1402   qed 
  1402   qed
  1403 qed (use assms in auto)
  1403 qed (use assms in auto)
  1404 
  1404 
  1405 lemma Ln_minus1 [simp]: "Ln(-1) = \<i> * pi"
  1405 lemma Ln_minus1 [simp]: "Ln(-1) = \<i> * pi"
  1406   apply (rule exp_complex_eqI)
  1406   apply (rule exp_complex_eqI)
  1407   using Im_Ln_le_pi [of "-1"] mpi_less_Im_Ln [of "-1"] cis_conv_exp cis_pi
  1407   using Im_Ln_le_pi [of "-1"] mpi_less_Im_Ln [of "-1"] cis_conv_exp cis_pi
  1527   assumes [measurable]: "f \<in> measurable M borel" "g \<in> measurable M borel"
  1527   assumes [measurable]: "f \<in> measurable M borel" "g \<in> measurable M borel"
  1528   shows   "(\<lambda>x. f x powr g x :: complex) \<in> measurable M borel"
  1528   shows   "(\<lambda>x. f x powr g x :: complex) \<in> measurable M borel"
  1529   using assms by (simp add: powr_def)
  1529   using assms by (simp add: powr_def)
  1530 
  1530 
  1531 
  1531 
  1532 subsection\<open>Relation between Ln and Arg, and hence continuity of Arg\<close>
  1532 subsection\<open>Relation between Ln and Arg2pi, and hence continuity of Arg2pi\<close>
  1533 
  1533 
  1534 lemma Arg_Ln:
  1534 lemma Arg2pi_Ln:
  1535   assumes "0 < Arg z" shows "Arg z = Im(Ln(-z)) + pi"
  1535   assumes "0 < Arg2pi z" shows "Arg2pi z = Im(Ln(-z)) + pi"
  1536 proof (cases "z = 0")
  1536 proof (cases "z = 0")
  1537   case True
  1537   case True
  1538   with assms show ?thesis
  1538   with assms show ?thesis
  1539     by simp
  1539     by simp
  1540 next
  1540 next
  1541   case False
  1541   case False
  1542   then have "z / of_real(norm z) = exp(\<i> * of_real(Arg z))"
  1542   then have "z / of_real(norm z) = exp(\<i> * of_real(Arg2pi z))"
  1543     using Arg [of z]
  1543     using Arg2pi [of z]
  1544     by (metis abs_norm_cancel nonzero_mult_div_cancel_left norm_of_real zero_less_norm_iff)
  1544     by (metis abs_norm_cancel nonzero_mult_div_cancel_left norm_of_real zero_less_norm_iff)
  1545   then have "- z / of_real(norm z) = exp (\<i> * (of_real (Arg z) - pi))"
  1545   then have "- z / of_real(norm z) = exp (\<i> * (of_real (Arg2pi z) - pi))"
  1546     using cis_conv_exp cis_pi
  1546     using cis_conv_exp cis_pi
  1547     by (auto simp: exp_diff algebra_simps)
  1547     by (auto simp: exp_diff algebra_simps)
  1548   then have "ln (- z / of_real(norm z)) = ln (exp (\<i> * (of_real (Arg z) - pi)))"
  1548   then have "ln (- z / of_real(norm z)) = ln (exp (\<i> * (of_real (Arg2pi z) - pi)))"
  1549     by simp
  1549     by simp
  1550   also have "... = \<i> * (of_real(Arg z) - pi)"
  1550   also have "... = \<i> * (of_real(Arg2pi z) - pi)"
  1551     using Arg [of z] assms pi_not_less_zero
  1551     using Arg2pi [of z] assms pi_not_less_zero
  1552     by auto
  1552     by auto
  1553   finally have "Arg z =  Im (Ln (- z / of_real (cmod z))) + pi"
  1553   finally have "Arg2pi z =  Im (Ln (- z / of_real (cmod z))) + pi"
  1554     by simp
  1554     by simp
  1555   also have "... = Im (Ln (-z) - ln (cmod z)) + pi"
  1555   also have "... = Im (Ln (-z) - ln (cmod z)) + pi"
  1556     by (metis diff_0_right minus_diff_eq zero_less_norm_iff Ln_divide_of_real False)
  1556     by (metis diff_0_right minus_diff_eq zero_less_norm_iff Ln_divide_of_real False)
  1557   also have "... = Im (Ln (-z)) + pi"
  1557   also have "... = Im (Ln (-z)) + pi"
  1558     by simp
  1558     by simp
  1559   finally show ?thesis .
  1559   finally show ?thesis .
  1560 qed
  1560 qed
  1561 
  1561 
  1562 lemma continuous_at_Arg:
  1562 lemma continuous_at_Arg2pi:
  1563   assumes "z \<notin> \<real>\<^sub>\<ge>\<^sub>0"
  1563   assumes "z \<notin> \<real>\<^sub>\<ge>\<^sub>0"
  1564     shows "continuous (at z) Arg"
  1564     shows "continuous (at z) Arg2pi"
  1565 proof -
  1565 proof -
  1566   have *: "isCont (\<lambda>z. Im (Ln (- z)) + pi) z"
  1566   have *: "isCont (\<lambda>z. Im (Ln (- z)) + pi) z"
  1567     by (rule Complex.isCont_Im isCont_Ln' continuous_intros | simp add: assms complex_is_Real_iff)+
  1567     by (rule Complex.isCont_Im isCont_Ln' continuous_intros | simp add: assms complex_is_Real_iff)+
  1568   have [simp]: "\<And>x. \<lbrakk>Im x \<noteq> 0\<rbrakk> \<Longrightarrow> Im (Ln (- x)) + pi = Arg x"
  1568   have [simp]: "\<And>x. \<lbrakk>Im x \<noteq> 0\<rbrakk> \<Longrightarrow> Im (Ln (- x)) + pi = Arg2pi x"
  1569     using Arg_Ln Arg_gt_0 complex_is_Real_iff by auto
  1569     using Arg2pi_Ln Arg2pi_gt_0 complex_is_Real_iff by auto
  1570   consider "Re z < 0" | "Im z \<noteq> 0" using assms
  1570   consider "Re z < 0" | "Im z \<noteq> 0" using assms
  1571     using complex_nonneg_Reals_iff not_le by blast
  1571     using complex_nonneg_Reals_iff not_le by blast
  1572   then have [simp]: "(\<lambda>z. Im (Ln (- z)) + pi) \<midarrow>z\<rightarrow> Arg z"
  1572   then have [simp]: "(\<lambda>z. Im (Ln (- z)) + pi) \<midarrow>z\<rightarrow> Arg2pi z"
  1573     using "*"  by (simp add: isCont_def) (metis Arg_Ln Arg_gt_0 complex_is_Real_iff)
  1573     using "*"  by (simp add: isCont_def) (metis Arg2pi_Ln Arg2pi_gt_0 complex_is_Real_iff)
  1574   show ?thesis
  1574   show ?thesis
  1575     unfolding continuous_at
  1575     unfolding continuous_at
  1576   proof (rule Lim_transform_within_open)
  1576   proof (rule Lim_transform_within_open)
  1577     show "\<And>x. \<lbrakk>x \<in> - \<real>\<^sub>\<ge>\<^sub>0; x \<noteq> z\<rbrakk> \<Longrightarrow> Im (Ln (- x)) + pi = Arg x"
  1577     show "\<And>x. \<lbrakk>x \<in> - \<real>\<^sub>\<ge>\<^sub>0; x \<noteq> z\<rbrakk> \<Longrightarrow> Im (Ln (- x)) + pi = Arg2pi x"
  1578       by (auto simp add: Arg_Ln [OF Arg_gt_0] complex_nonneg_Reals_iff)
  1578       by (auto simp add: Arg2pi_Ln [OF Arg2pi_gt_0] complex_nonneg_Reals_iff)
  1579   qed (use assms in auto)
  1579   qed (use assms in auto)
  1580 qed
  1580 qed
  1581 
  1581 
  1582 lemma Ln_series:
  1582 lemma Ln_series:
  1583   fixes z :: complex
  1583   fixes z :: complex
  1660              (\<Sum>i. norm (-(z^2) * inverse (of_nat (i+2)) * (-z)^i))"
  1660              (\<Sum>i. norm (-(z^2) * inverse (of_nat (i+2)) * (-z)^i))"
  1661     by (intro summable_norm)
  1661     by (intro summable_norm)
  1662        (auto simp: norm_power norm_inverse norm_mult mult_ac simp del: of_nat_add of_nat_Suc)
  1662        (auto simp: norm_power norm_inverse norm_mult mult_ac simp del: of_nat_add of_nat_Suc)
  1663   also have "norm ((-z)^2 * (-z)^i) * inverse (of_nat (i+2)) \<le> norm ((-z)^2 * (-z)^i) * 1" for i
  1663   also have "norm ((-z)^2 * (-z)^i) * inverse (of_nat (i+2)) \<le> norm ((-z)^2 * (-z)^i) * 1" for i
  1664     by (intro mult_left_mono) (simp_all add: divide_simps)
  1664     by (intro mult_left_mono) (simp_all add: divide_simps)
  1665   hence "(\<Sum>i. norm (-(z^2) * inverse (of_nat (i+2)) * (-z)^i)) 
  1665   hence "(\<Sum>i. norm (-(z^2) * inverse (of_nat (i+2)) * (-z)^i))
  1666          \<le> (\<Sum>i. norm (-(z^2) * (-z)^i))" 
  1666          \<le> (\<Sum>i. norm (-(z^2) * (-z)^i))"
  1667     using A assms
  1667     using A assms
  1668     apply (simp_all only: norm_power norm_inverse norm_divide norm_mult)
  1668     apply (simp_all only: norm_power norm_inverse norm_divide norm_mult)
  1669     apply (intro suminf_le summable_mult summable_geometric)
  1669     apply (intro suminf_le summable_mult summable_geometric)
  1670     apply (auto simp: norm_power field_simps simp del: of_nat_add of_nat_Suc)
  1670     apply (auto simp: norm_power field_simps simp del: of_nat_add of_nat_Suc)
  1671     done
  1671     done
  1676   also have "norm z^2 * ... = norm z^2 / (1 - norm z)" by (simp add: divide_inverse)
  1676   also have "norm z^2 * ... = norm z^2 / (1 - norm z)" by (simp add: divide_inverse)
  1677   finally show ?thesis .
  1677   finally show ?thesis .
  1678 qed
  1678 qed
  1679 
  1679 
  1680 
  1680 
  1681 text\<open>Relation between Arg and arctangent in upper halfplane\<close>
  1681 text\<open>Relation between Arg2pi and arctangent in upper halfplane\<close>
  1682 lemma Arg_arctan_upperhalf:
  1682 lemma Arg2pi_arctan_upperhalf:
  1683   assumes "0 < Im z"
  1683   assumes "0 < Im z"
  1684     shows "Arg z = pi/2 - arctan(Re z / Im z)"
  1684     shows "Arg2pi z = pi/2 - arctan(Re z / Im z)"
  1685 proof (cases "z = 0")
  1685 proof (cases "z = 0")
  1686   case False
  1686   case False
  1687   show ?thesis
  1687   show ?thesis
  1688   proof (rule Arg_unique [of "norm z"])
  1688   proof (rule Arg2pi_unique [of "norm z"])
  1689     show "(cmod z) * exp (\<i> * (pi / 2 - arctan (Re z / Im z))) = z"
  1689     show "(cmod z) * exp (\<i> * (pi / 2 - arctan (Re z / Im z))) = z"
  1690       apply (auto simp: exp_Euler cos_diff sin_diff)
  1690       apply (auto simp: exp_Euler cos_diff sin_diff)
  1691       using assms norm_complex_def [of z, symmetric]
  1691       using assms norm_complex_def [of z, symmetric]
  1692       apply (simp add: sin_of_real cos_of_real sin_arctan cos_arctan field_simps real_sqrt_divide)
  1692       apply (simp add: sin_of_real cos_of_real sin_arctan cos_arctan field_simps real_sqrt_divide)
  1693       apply (metis complex_eq)
  1693       apply (metis complex_eq)
  1694       done
  1694       done
  1695   qed (use False arctan [of "Re z / Im z"] in auto)
  1695   qed (use False arctan [of "Re z / Im z"] in auto)
  1696 qed (use assms in auto)
  1696 qed (use assms in auto)
  1697 
  1697 
  1698 lemma Arg_eq_Im_Ln:
  1698 lemma Arg2pi_eq_Im_Ln:
  1699   assumes "0 \<le> Im z" "0 < Re z"
  1699   assumes "0 \<le> Im z" "0 < Re z"
  1700     shows "Arg z = Im (Ln z)"
  1700     shows "Arg2pi z = Im (Ln z)"
  1701 proof (cases "Im z = 0")
  1701 proof (cases "Im z = 0")
  1702   case True then show ?thesis
  1702   case True then show ?thesis
  1703     using Arg_eq_0 Ln_in_Reals assms(2) complex_is_Real_iff by auto
  1703     using Arg2pi_eq_0 Ln_in_Reals assms(2) complex_is_Real_iff by auto
  1704 next
  1704 next
  1705   case False
  1705   case False
  1706   then have *: "Arg z > 0"
  1706   then have *: "Arg2pi z > 0"
  1707     using Arg_gt_0 complex_is_Real_iff by blast
  1707     using Arg2pi_gt_0 complex_is_Real_iff by blast
  1708   then have "z \<noteq> 0"
  1708   then have "z \<noteq> 0"
  1709     by auto
  1709     by auto
  1710   with * assms False show ?thesis
  1710   with * assms False show ?thesis
  1711     by (subst Arg_Ln) (auto simp: Ln_minus)
  1711     by (subst Arg2pi_Ln) (auto simp: Ln_minus)
  1712 qed
  1712 qed
  1713 
  1713 
  1714 lemma continuous_within_upperhalf_Arg:
  1714 lemma continuous_within_upperhalf_Arg2pi:
  1715   assumes "z \<noteq> 0"
  1715   assumes "z \<noteq> 0"
  1716     shows "continuous (at z within {z. 0 \<le> Im z}) Arg"
  1716     shows "continuous (at z within {z. 0 \<le> Im z}) Arg2pi"
  1717 proof (cases "z \<in> \<real>\<^sub>\<ge>\<^sub>0")
  1717 proof (cases "z \<in> \<real>\<^sub>\<ge>\<^sub>0")
  1718   case False then show ?thesis
  1718   case False then show ?thesis
  1719     using continuous_at_Arg continuous_at_imp_continuous_within by auto
  1719     using continuous_at_Arg2pi continuous_at_imp_continuous_within by auto
  1720 next
  1720 next
  1721   case True
  1721   case True
  1722   then have z: "z \<in> \<real>" "0 < Re z"
  1722   then have z: "z \<in> \<real>" "0 < Re z"
  1723     using assms  by (auto simp: complex_nonneg_Reals_iff complex_is_Real_iff complex_neq_0)
  1723     using assms  by (auto simp: complex_nonneg_Reals_iff complex_is_Real_iff complex_neq_0)
  1724   then have [simp]: "Arg z = 0" "Im (Ln z) = 0"
  1724   then have [simp]: "Arg2pi z = 0" "Im (Ln z) = 0"
  1725     by (auto simp: Arg_eq_0 Im_Ln_eq_0 assms complex_is_Real_iff)
  1725     by (auto simp: Arg2pi_eq_0 Im_Ln_eq_0 assms complex_is_Real_iff)
  1726   show ?thesis
  1726   show ?thesis
  1727   proof (clarsimp simp add: continuous_within Lim_within dist_norm)
  1727   proof (clarsimp simp add: continuous_within Lim_within dist_norm)
  1728     fix e::real
  1728     fix e::real
  1729     assume "0 < e"
  1729     assume "0 < e"
  1730     moreover have "continuous (at z) (\<lambda>x. Im (Ln x))"
  1730     moreover have "continuous (at z) (\<lambda>x. Im (Ln x))"
  1737       then have "\<bar>Re x - Re z\<bar> < Re z / 2"
  1737       then have "\<bar>Re x - Re z\<bar> < Re z / 2"
  1738         by (metis le_less_trans abs_Re_le_cmod minus_complex.simps(1))
  1738         by (metis le_less_trans abs_Re_le_cmod minus_complex.simps(1))
  1739       then have "0 < Re x"
  1739       then have "0 < Re x"
  1740         using z by linarith
  1740         using z by linarith
  1741     }
  1741     }
  1742     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"
  1742     then show "\<exists>d>0. \<forall>x. 0 \<le> Im x \<longrightarrow> x \<noteq> z \<and> cmod (x - z) < d \<longrightarrow> \<bar>Arg2pi x\<bar> < e"
  1743       apply (rule_tac x="min d (Re z / 2)" in exI)
  1743       apply (rule_tac x="min d (Re z / 2)" in exI)
  1744       using z d
  1744       using z d
  1745       apply (auto simp: Arg_eq_Im_Ln)
  1745       apply (auto simp: Arg2pi_eq_Im_Ln)
  1746       done
  1746       done
  1747   qed
  1747   qed
  1748 qed
  1748 qed
  1749 
  1749 
  1750 lemma continuous_on_upperhalf_Arg: "continuous_on ({z. 0 \<le> Im z} - {0}) Arg"
  1750 lemma continuous_on_upperhalf_Arg2pi: "continuous_on ({z. 0 \<le> Im z} - {0}) Arg2pi"
  1751   unfolding continuous_on_eq_continuous_within
  1751   unfolding continuous_on_eq_continuous_within
  1752   by (metis DiffE Diff_subset continuous_within_subset continuous_within_upperhalf_Arg insertCI)
  1752   by (metis DiffE Diff_subset continuous_within_subset continuous_within_upperhalf_Arg2pi insertCI)
  1753 
  1753 
  1754 lemma open_Arg_less_Int:
  1754 lemma open_Arg2pi2pi_less_Int:
  1755   assumes "0 \<le> s" "t \<le> 2*pi"
  1755   assumes "0 \<le> s" "t \<le> 2*pi"
  1756     shows "open ({y. s < Arg y} \<inter> {y. Arg y < t})"
  1756     shows "open ({y. s < Arg2pi y} \<inter> {y. Arg2pi y < t})"
  1757 proof -
  1757 proof -
  1758   have 1: "continuous_on (UNIV - \<real>\<^sub>\<ge>\<^sub>0) Arg"
  1758   have 1: "continuous_on (UNIV - \<real>\<^sub>\<ge>\<^sub>0) Arg2pi"
  1759     using continuous_at_Arg continuous_at_imp_continuous_within
  1759     using continuous_at_Arg2pi continuous_at_imp_continuous_within
  1760     by (auto simp: continuous_on_eq_continuous_within)
  1760     by (auto simp: continuous_on_eq_continuous_within)
  1761   have 2: "open (UNIV - \<real>\<^sub>\<ge>\<^sub>0 :: complex set)"  by (simp add: open_Diff)
  1761   have 2: "open (UNIV - \<real>\<^sub>\<ge>\<^sub>0 :: complex set)"  by (simp add: open_Diff)
  1762   have "open ({z. s < z} \<inter> {z. z < t})"
  1762   have "open ({z. s < z} \<inter> {z. z < t})"
  1763     using open_lessThan [of t] open_greaterThan [of s]
  1763     using open_lessThan [of t] open_greaterThan [of s]
  1764     by (metis greaterThan_def lessThan_def open_Int)
  1764     by (metis greaterThan_def lessThan_def open_Int)
  1765   moreover have "{y. s < Arg y} \<inter> {y. Arg y < t} \<subseteq> - \<real>\<^sub>\<ge>\<^sub>0"
  1765   moreover have "{y. s < Arg2pi y} \<inter> {y. Arg2pi y < t} \<subseteq> - \<real>\<^sub>\<ge>\<^sub>0"
  1766     using assms by (auto simp: Arg_real complex_nonneg_Reals_iff complex_is_Real_iff)
  1766     using assms by (auto simp: Arg2pi_real complex_nonneg_Reals_iff complex_is_Real_iff)
  1767   ultimately show ?thesis
  1767   ultimately show ?thesis
  1768     using continuous_imp_open_vimage [OF 1 2, of  "{z. Re z > s} \<inter> {z. Re z < t}"]
  1768     using continuous_imp_open_vimage [OF 1 2, of  "{z. Re z > s} \<inter> {z. Re z < t}"]
  1769     by auto
  1769     by auto
  1770 qed
  1770 qed
  1771 
  1771 
  1772 lemma open_Arg_gt: "open {z. t < Arg z}"
  1772 lemma open_Arg2pi2pi_gt: "open {z. t < Arg2pi z}"
  1773 proof (cases "t < 0")
  1773 proof (cases "t < 0")
  1774   case True then have "{z. t < Arg z} = UNIV"
  1774   case True then have "{z. t < Arg2pi z} = UNIV"
  1775     using Arg_ge_0 less_le_trans by auto
  1775     using Arg2pi_ge_0 less_le_trans by auto
  1776   then show ?thesis
  1776   then show ?thesis
  1777     by simp
  1777     by simp
  1778 next
  1778 next
  1779   case False then show ?thesis
  1779   case False then show ?thesis
  1780     using open_Arg_less_Int [of t "2*pi"] Arg_lt_2pi
  1780     using open_Arg2pi2pi_less_Int [of t "2*pi"] Arg2pi_lt_2pi
  1781     by auto
  1781     by auto
  1782 qed
  1782 qed
  1783 
  1783 
  1784 lemma closed_Arg_le: "closed {z. Arg z \<le> t}"
  1784 lemma closed_Arg2pi2pi_le: "closed {z. Arg2pi z \<le> t}"
  1785   using open_Arg_gt [of t]
  1785   using open_Arg2pi2pi_gt [of t]
  1786   by (simp add: closed_def Set.Collect_neg_eq [symmetric] not_le)
  1786   by (simp add: closed_def Set.Collect_neg_eq [symmetric] not_le)
  1787 
  1787 
  1788 subsection\<open>Complex Powers\<close>
  1788 subsection\<open>Complex Powers\<close>
  1789 
  1789 
  1790 lemma powr_to_1 [simp]: "z powr 1 = (z::complex)"
  1790 lemma powr_to_1 [simp]: "z powr 1 = (z::complex)"
  1888 qed (use assms in auto)
  1888 qed (use assms in auto)
  1889 
  1889 
  1890 declare has_field_derivative_powr[THEN DERIV_chain2, derivative_intros]
  1890 declare has_field_derivative_powr[THEN DERIV_chain2, derivative_intros]
  1891 
  1891 
  1892 lemma has_field_derivative_powr_of_int:
  1892 lemma has_field_derivative_powr_of_int:
  1893   fixes z :: complex 
  1893   fixes z :: complex
  1894   assumes gderiv:"(g has_field_derivative gd) (at z within s)" and "g z\<noteq>0"
  1894   assumes gderiv:"(g has_field_derivative gd) (at z within s)" and "g z\<noteq>0"
  1895   shows "((\<lambda>z. g z powr of_int n) has_field_derivative (n * g z powr (of_int n - 1) * gd)) (at z within s)"
  1895   shows "((\<lambda>z. g z powr of_int n) has_field_derivative (n * g z powr (of_int n - 1) * gd)) (at z within s)"
  1896 proof -
  1896 proof -
  1897   define dd where "dd = of_int n * g z powr (of_int (n - 1)) * gd"
  1897   define dd where "dd = of_int n * g z powr (of_int (n - 1)) * gd"
  1898   obtain e where "e>0" and e_dist:"\<forall>y\<in>s. dist z y < e \<longrightarrow> g y \<noteq> 0"
  1898   obtain e where "e>0" and e_dist:"\<forall>y\<in>s. dist z y < e \<longrightarrow> g y \<noteq> 0"
  1903     have "dd=dd'"
  1903     have "dd=dd'"
  1904     proof (cases "n=0")
  1904     proof (cases "n=0")
  1905       case False
  1905       case False
  1906       then have "n-1 \<ge>0" using \<open>n\<ge>0\<close> by auto
  1906       then have "n-1 \<ge>0" using \<open>n\<ge>0\<close> by auto
  1907       then have "g z powr (of_int (n - 1)) = g z ^ (nat n - 1)"
  1907       then have "g z powr (of_int (n - 1)) = g z ^ (nat n - 1)"
  1908         using powr_of_int[OF \<open>g z\<noteq>0\<close>,of "n-1"] by (simp add: nat_diff_distrib') 
  1908         using powr_of_int[OF \<open>g z\<noteq>0\<close>,of "n-1"] by (simp add: nat_diff_distrib')
  1909       then show ?thesis unfolding dd_def dd'_def by simp
  1909       then show ?thesis unfolding dd_def dd'_def by simp
  1910     qed (simp add:dd_def dd'_def)
  1910     qed (simp add:dd_def dd'_def)
  1911     then have "((\<lambda>z. g z powr of_int n) has_field_derivative dd) (at z within s)
  1911     then have "((\<lambda>z. g z powr of_int n) has_field_derivative dd) (at z within s)
  1912                 \<longleftrightarrow> ((\<lambda>z. g z powr of_int n) has_field_derivative dd') (at z within s)"
  1912                 \<longleftrightarrow> ((\<lambda>z. g z powr of_int n) has_field_derivative dd') (at z within s)"
  1913       by simp
  1913       by simp
  1956   qed
  1956   qed
  1957   ultimately show ?thesis by force
  1957   ultimately show ?thesis by force
  1958 qed
  1958 qed
  1959 
  1959 
  1960 lemma field_differentiable_powr_of_int:
  1960 lemma field_differentiable_powr_of_int:
  1961   fixes z :: complex 
  1961   fixes z :: complex
  1962   assumes gderiv:"g field_differentiable (at z within s)" and "g z\<noteq>0"
  1962   assumes gderiv:"g field_differentiable (at z within s)" and "g z\<noteq>0"
  1963   shows "(\<lambda>z. g z powr of_int n) field_differentiable (at z within s)"
  1963   shows "(\<lambda>z. g z powr of_int n) field_differentiable (at z within s)"
  1964 using has_field_derivative_powr_of_int assms(2) field_differentiable_def gderiv by blast
  1964 using has_field_derivative_powr_of_int assms(2) field_differentiable_def gderiv by blast
  1965 
  1965 
  1966 lemma holomorphic_on_powr_of_int [holomorphic_intros]:
  1966 lemma holomorphic_on_powr_of_int [holomorphic_intros]:
  1970   case True
  1970   case True
  1971   then have "?thesis \<longleftrightarrow> (\<lambda>z. (f z) ^ nat n) holomorphic_on s"
  1971   then have "?thesis \<longleftrightarrow> (\<lambda>z. (f z) ^ nat n) holomorphic_on s"
  1972     apply (rule_tac holomorphic_cong)
  1972     apply (rule_tac holomorphic_cong)
  1973     using assms(2) by (auto simp add:powr_of_int)
  1973     using assms(2) by (auto simp add:powr_of_int)
  1974   moreover have "(\<lambda>z. (f z) ^ nat n) holomorphic_on s"
  1974   moreover have "(\<lambda>z. (f z) ^ nat n) holomorphic_on s"
  1975     using assms(1) by (auto intro:holomorphic_intros)    
  1975     using assms(1) by (auto intro:holomorphic_intros)
  1976   ultimately show ?thesis by auto
  1976   ultimately show ?thesis by auto
  1977 next
  1977 next
  1978   case False
  1978   case False
  1979   then have "?thesis \<longleftrightarrow> (\<lambda>z. inverse (f z) ^ nat (-n)) holomorphic_on s"
  1979   then have "?thesis \<longleftrightarrow> (\<lambda>z. inverse (f z) ^ nat (-n)) holomorphic_on s"
  1980     apply (rule_tac holomorphic_cong)
  1980     apply (rule_tac holomorphic_cong)
  1981     using assms(2) by (auto simp add:powr_of_int power_inverse)
  1981     using assms(2) by (auto simp add:powr_of_int power_inverse)
  1982   moreover have "(\<lambda>z. inverse (f z) ^ nat (-n)) holomorphic_on s"
  1982   moreover have "(\<lambda>z. inverse (f z) ^ nat (-n)) holomorphic_on s"
  1983     using assms by (auto intro!:holomorphic_intros) 
  1983     using assms by (auto intro!:holomorphic_intros)
  1984   ultimately show ?thesis by auto
  1984   ultimately show ?thesis by auto
  1985 qed
  1985 qed
  1986 
  1986 
  1987 lemma has_field_derivative_powr_right [derivative_intros]:
  1987 lemma has_field_derivative_powr_right [derivative_intros]:
  1988     "w \<noteq> 0 \<Longrightarrow> ((\<lambda>z. w powr z) has_field_derivative Ln w * w powr z) (at z)"
  1988     "w \<noteq> 0 \<Longrightarrow> ((\<lambda>z. w powr z) has_field_derivative Ln w * w powr z) (at z)"
  2192   have "norm (Ln (of_nat n) / of_nat n powr s) < e" if "n \<ge> nat \<lceil>exp xo\<rceil>" for n
  2192   have "norm (Ln (of_nat n) / of_nat n powr s) < e" if "n \<ge> nat \<lceil>exp xo\<rceil>" for n
  2193     using e xo [of "ln n"] that
  2193     using e xo [of "ln n"] that
  2194     apply (auto simp: norm_divide norm_powr_real divide_simps)
  2194     apply (auto simp: norm_divide norm_powr_real divide_simps)
  2195     apply (metis exp_less_mono exp_ln not_le of_nat_0_less_iff)
  2195     apply (metis exp_less_mono exp_ln not_le of_nat_0_less_iff)
  2196     done
  2196     done
  2197   then show "\<exists>no. \<forall>n\<ge>no. norm (Ln (of_nat n) / of_nat n powr s) < e" 
  2197   then show "\<exists>no. \<forall>n\<ge>no. norm (Ln (of_nat n) / of_nat n powr s) < e"
  2198     by blast
  2198     by blast
  2199 qed
  2199 qed
  2200 
  2200 
  2201 lemma lim_Ln_over_n: "((\<lambda>n. Ln(of_nat n) / of_nat n) \<longlongrightarrow> 0) sequentially"
  2201 lemma lim_Ln_over_n: "((\<lambda>n. Ln(of_nat n) / of_nat n) \<longlongrightarrow> 0) sequentially"
  2202   using lim_Ln_over_power [of 1] by simp
  2202   using lim_Ln_over_power [of 1] by simp
  2502   shows Re_Arctan_bounds: "\<bar>Re(Arctan z)\<bar> < pi/2"
  2502   shows Re_Arctan_bounds: "\<bar>Re(Arctan z)\<bar> < pi/2"
  2503     and has_field_derivative_Arctan: "(Arctan has_field_derivative inverse(1 + z\<^sup>2)) (at z)"
  2503     and has_field_derivative_Arctan: "(Arctan has_field_derivative inverse(1 + z\<^sup>2)) (at z)"
  2504 proof -
  2504 proof -
  2505   have nz0: "1 + \<i>*z \<noteq> 0"
  2505   have nz0: "1 + \<i>*z \<noteq> 0"
  2506     using assms
  2506     using assms
  2507     by (metis abs_one add_diff_cancel_left' complex_i_mult_minus diff_0 i_squared imaginary_unit.simps 
  2507     by (metis abs_one add_diff_cancel_left' complex_i_mult_minus diff_0 i_squared imaginary_unit.simps
  2508                 less_asym neg_equal_iff_equal)
  2508                 less_asym neg_equal_iff_equal)
  2509   have "z \<noteq> -\<i>" using assms
  2509   have "z \<noteq> -\<i>" using assms
  2510     by auto
  2510     by auto
  2511   then have zz: "1 + z * z \<noteq> 0"
  2511   then have zz: "1 + z * z \<noteq> 0"
  2512     by (metis abs_one assms i_squared imaginary_unit.simps less_irrefl minus_unique square_eq_iff)
  2512     by (metis abs_one assms i_squared imaginary_unit.simps less_irrefl minus_unique square_eq_iff)
  2845 lemma pi_approx: "3.141592653588 \<le> pi" "pi \<le> 3.1415926535899"
  2845 lemma pi_approx: "3.141592653588 \<le> pi" "pi \<le> 3.1415926535899"
  2846   unfolding pi_machin
  2846   unfolding pi_machin
  2847   using arctan_bounds[of "1/5"   4]
  2847   using arctan_bounds[of "1/5"   4]
  2848         arctan_bounds[of "1/239" 4]
  2848         arctan_bounds[of "1/239" 4]
  2849   by (simp_all add: eval_nat_numeral)
  2849   by (simp_all add: eval_nat_numeral)
  2850     
  2850 
  2851 corollary pi_gt3: "pi > 3"
  2851 corollary pi_gt3: "pi > 3"
  2852   using pi_approx by simp
  2852   using pi_approx by simp
  2853 
  2853 
  2854 
  2854 
  2855 subsection\<open>Inverse Sine\<close>
  2855 subsection\<open>Inverse Sine\<close>
  2985   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)
  2985   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)
  2986 
  2986 
  2987 lemma has_field_derivative_Arcsin:
  2987 lemma has_field_derivative_Arcsin:
  2988   assumes "Im z = 0 \<Longrightarrow> \<bar>Re z\<bar> < 1"
  2988   assumes "Im z = 0 \<Longrightarrow> \<bar>Re z\<bar> < 1"
  2989     shows "(Arcsin has_field_derivative inverse(cos(Arcsin z))) (at z)"
  2989     shows "(Arcsin has_field_derivative inverse(cos(Arcsin z))) (at z)"
  2990 proof - 
  2990 proof -
  2991   have "(sin (Arcsin z))\<^sup>2 \<noteq> 1"
  2991   have "(sin (Arcsin z))\<^sup>2 \<noteq> 1"
  2992     using assms one_minus_z2_notin_nonpos_Reals by force
  2992     using assms one_minus_z2_notin_nonpos_Reals by force
  2993   then have "cos (Arcsin z) \<noteq> 0"
  2993   then have "cos (Arcsin z) \<noteq> 0"
  2994     by (metis diff_0_right power_zero_numeral sin_squared_eq)
  2994     by (metis diff_0_right power_zero_numeral sin_squared_eq)
  2995   then show ?thesis
  2995   then show ?thesis
  3680 qed
  3680 qed
  3681 
  3681 
  3682 lemma homotopic_loops_imp_homotopic_circlemaps:
  3682 lemma homotopic_loops_imp_homotopic_circlemaps:
  3683   assumes "homotopic_loops S p q"
  3683   assumes "homotopic_loops S p q"
  3684     shows "homotopic_with (\<lambda>h. True) (sphere 0 1) S
  3684     shows "homotopic_with (\<lambda>h. True) (sphere 0 1) S
  3685                           (p \<circ> (\<lambda>z. (Arg z / (2 * pi))))
  3685                           (p \<circ> (\<lambda>z. (Arg2pi z / (2 * pi))))
  3686                           (q \<circ> (\<lambda>z. (Arg z / (2 * pi))))"
  3686                           (q \<circ> (\<lambda>z. (Arg2pi z / (2 * pi))))"
  3687 proof -
  3687 proof -
  3688   obtain h where conth: "continuous_on ({0..1::real} \<times> {0..1}) h"
  3688   obtain h where conth: "continuous_on ({0..1::real} \<times> {0..1}) h"
  3689              and him: "h ` ({0..1} \<times> {0..1}) \<subseteq> S"
  3689              and him: "h ` ({0..1} \<times> {0..1}) \<subseteq> S"
  3690              and h0: "(\<forall>x. h (0, x) = p x)"
  3690              and h0: "(\<forall>x. h (0, x) = p x)"
  3691              and h1: "(\<forall>x. h (1, x) = q x)"
  3691              and h1: "(\<forall>x. h (1, x) = q x)"
  3692              and h01: "(\<forall>t\<in>{0..1}. h (t, 1) = h (t, 0)) "
  3692              and h01: "(\<forall>t\<in>{0..1}. h (t, 1) = h (t, 0)) "
  3693     using assms
  3693     using assms
  3694     by (auto simp: homotopic_loops_def sphere_def homotopic_with_def pathstart_def pathfinish_def)
  3694     by (auto simp: homotopic_loops_def sphere_def homotopic_with_def pathstart_def pathfinish_def)
  3695   define j where "j \<equiv> \<lambda>z. if 0 \<le> Im (snd z)
  3695   define j where "j \<equiv> \<lambda>z. if 0 \<le> Im (snd z)
  3696                           then h (fst z, Arg (snd z) / (2 * pi))
  3696                           then h (fst z, Arg2pi (snd z) / (2 * pi))
  3697                           else h (fst z, 1 - Arg (cnj (snd z)) / (2 * pi))"
  3697                           else h (fst z, 1 - Arg2pi (cnj (snd z)) / (2 * pi))"
  3698   have Arg_eq: "1 - Arg (cnj y) / (2 * pi) = Arg y / (2 * pi) \<or> Arg y = 0 \<and> Arg (cnj y) = 0" if "cmod y = 1" for y
  3698   have Arg2pi_eq: "1 - Arg2pi (cnj y) / (2 * pi) = Arg2pi y / (2 * pi) \<or> Arg2pi y = 0 \<and> Arg2pi (cnj y) = 0" if "cmod y = 1" for y
  3699     using that Arg_eq_0_pi Arg_eq_pi by (force simp: Arg_cnj divide_simps)
  3699     using that Arg2pi_eq_0_pi Arg2pi_eq_pi by (force simp: Arg2pi_cnj divide_simps)
  3700   show ?thesis
  3700   show ?thesis
  3701   proof (simp add: homotopic_with; intro conjI ballI exI)
  3701   proof (simp add: homotopic_with; intro conjI ballI exI)
  3702     show "continuous_on ({0..1} \<times> sphere 0 1) (\<lambda>w. h (fst w, Arg (snd w) / (2 * pi)))"
  3702     show "continuous_on ({0..1} \<times> sphere 0 1) (\<lambda>w. h (fst w, Arg2pi (snd w) / (2 * pi)))"
  3703     proof (rule continuous_on_eq)
  3703     proof (rule continuous_on_eq)
  3704       show j: "j x = h (fst x, Arg (snd x) / (2 * pi))" if "x \<in> {0..1} \<times> sphere 0 1" for x
  3704       show j: "j x = h (fst x, Arg2pi (snd x) / (2 * pi))" if "x \<in> {0..1} \<times> sphere 0 1" for x
  3705         using Arg_eq that h01 by (force simp: j_def)
  3705         using Arg2pi_eq that h01 by (force simp: j_def)
  3706       have eq:  "S = S \<inter> (UNIV \<times> {z. 0 \<le> Im z}) \<union> S \<inter> (UNIV \<times> {z. Im z \<le> 0})" for S :: "(real*complex)set"
  3706       have eq:  "S = S \<inter> (UNIV \<times> {z. 0 \<le> Im z}) \<union> S \<inter> (UNIV \<times> {z. Im z \<le> 0})" for S :: "(real*complex)set"
  3707         by auto
  3707         by auto
  3708       have c1: "continuous_on ({0..1} \<times> sphere 0 1 \<inter> UNIV \<times> {z. 0 \<le> Im z}) (\<lambda>x. h (fst x, Arg (snd x) / (2 * pi)))"
  3708       have c1: "continuous_on ({0..1} \<times> sphere 0 1 \<inter> UNIV \<times> {z. 0 \<le> Im z}) (\<lambda>x. h (fst x, Arg2pi (snd x) / (2 * pi)))"
  3709         apply (intro continuous_intros continuous_on_compose2 [OF conth]  continuous_on_compose2 [OF continuous_on_upperhalf_Arg])
  3709         apply (intro continuous_intros continuous_on_compose2 [OF conth]  continuous_on_compose2 [OF continuous_on_upperhalf_Arg2pi])
  3710             apply (auto simp: Arg)
  3710             apply (auto simp: Arg2pi)
  3711         apply (meson Arg_lt_2pi linear not_le)
  3711         apply (meson Arg2pi_lt_2pi linear not_le)
  3712         done
  3712         done
  3713       have c2: "continuous_on ({0..1} \<times> sphere 0 1 \<inter> UNIV \<times> {z. Im z \<le> 0}) (\<lambda>x. h (fst x, 1 - Arg (cnj (snd x)) / (2 * pi)))"
  3713       have c2: "continuous_on ({0..1} \<times> sphere 0 1 \<inter> UNIV \<times> {z. Im z \<le> 0}) (\<lambda>x. h (fst x, 1 - Arg2pi (cnj (snd x)) / (2 * pi)))"
  3714         apply (intro continuous_intros continuous_on_compose2 [OF conth]  continuous_on_compose2 [OF continuous_on_upperhalf_Arg])
  3714         apply (intro continuous_intros continuous_on_compose2 [OF conth]  continuous_on_compose2 [OF continuous_on_upperhalf_Arg2pi])
  3715             apply (auto simp: Arg)
  3715             apply (auto simp: Arg2pi)
  3716         apply (meson Arg_lt_2pi linear not_le)
  3716         apply (meson Arg2pi_lt_2pi linear not_le)
  3717         done
  3717         done
  3718       show "continuous_on ({0..1} \<times> sphere 0 1) j"
  3718       show "continuous_on ({0..1} \<times> sphere 0 1) j"
  3719         apply (simp add: j_def)
  3719         apply (simp add: j_def)
  3720         apply (subst eq)
  3720         apply (subst eq)
  3721         apply (rule continuous_on_cases_local)
  3721         apply (rule continuous_on_cases_local)
  3722             apply (simp_all add: eq [symmetric] closedin_closed_Int closed_Times closed_halfspace_Im_le closed_halfspace_Im_ge c1 c2)
  3722             apply (simp_all add: eq [symmetric] closedin_closed_Int closed_Times closed_halfspace_Im_le closed_halfspace_Im_ge c1 c2)
  3723         using Arg_eq h01
  3723         using Arg2pi_eq h01
  3724         by force
  3724         by force
  3725     qed
  3725     qed
  3726     have "(\<lambda>w. h (fst w, Arg (snd w) / (2 * pi))) ` ({0..1} \<times> sphere 0 1) \<subseteq> h ` ({0..1} \<times> {0..1})"
  3726     have "(\<lambda>w. h (fst w, Arg2pi (snd w) / (2 * pi))) ` ({0..1} \<times> sphere 0 1) \<subseteq> h ` ({0..1} \<times> {0..1})"
  3727       by (auto simp: Arg_ge_0 Arg_lt_2pi less_imp_le)
  3727       by (auto simp: Arg2pi_ge_0 Arg2pi_lt_2pi less_imp_le)
  3728     also have "... \<subseteq> S"
  3728     also have "... \<subseteq> S"
  3729       using him by blast
  3729       using him by blast
  3730     finally show "(\<lambda>w. h (fst w, Arg (snd w) / (2 * pi))) ` ({0..1} \<times> sphere 0 1) \<subseteq> S" .
  3730     finally show "(\<lambda>w. h (fst w, Arg2pi (snd w) / (2 * pi))) ` ({0..1} \<times> sphere 0 1) \<subseteq> S" .
  3731   qed (auto simp: h0 h1)
  3731   qed (auto simp: h0 h1)
  3732 qed
  3732 qed
  3733 
  3733 
  3734 lemma simply_connected_homotopic_loops:
  3734 lemma simply_connected_homotopic_loops:
  3735   "simply_connected S \<longleftrightarrow>
  3735   "simply_connected S \<longleftrightarrow>
  3792 proof (clarsimp simp add: simply_connected_eq_contractible_loop_some assms)
  3792 proof (clarsimp simp add: simply_connected_eq_contractible_loop_some assms)
  3793   fix p
  3793   fix p
  3794   assume p: "path p" "path_image p \<subseteq> S" "pathfinish p = pathstart p"
  3794   assume p: "path p" "path_image p \<subseteq> S" "pathfinish p = pathstart p"
  3795   then have "homotopic_loops S p p"
  3795   then have "homotopic_loops S p p"
  3796     by (simp add: homotopic_loops_refl)
  3796     by (simp add: homotopic_loops_refl)
  3797   then obtain a where homp: "homotopic_with (\<lambda>h. True) (sphere 0 1) S (p \<circ> (\<lambda>z. Arg z / (2 * pi))) (\<lambda>x. a)"
  3797   then obtain a where homp: "homotopic_with (\<lambda>h. True) (sphere 0 1) S (p \<circ> (\<lambda>z. Arg2pi z / (2 * pi))) (\<lambda>x. a)"
  3798     by (metis homotopic_with_imp_subset2 homotopic_loops_imp_homotopic_circlemaps homotopic_with_imp_continuous hom)
  3798     by (metis homotopic_with_imp_subset2 homotopic_loops_imp_homotopic_circlemaps homotopic_with_imp_continuous hom)
  3799   show "\<exists>a. a \<in> S \<and> homotopic_loops S p (linepath a a)"
  3799   show "\<exists>a. a \<in> S \<and> homotopic_loops S p (linepath a a)"
  3800   proof (intro exI conjI)
  3800   proof (intro exI conjI)
  3801     show "a \<in> S"
  3801     show "a \<in> S"
  3802       using homotopic_with_imp_subset2 [OF homp]
  3802       using homotopic_with_imp_subset2 [OF homp]
  3803       by (metis dist_0_norm image_subset_iff mem_sphere norm_one)
  3803       by (metis dist_0_norm image_subset_iff mem_sphere norm_one)
  3804     have teq: "\<And>t. \<lbrakk>0 \<le> t; t \<le> 1\<rbrakk>
  3804     have teq: "\<And>t. \<lbrakk>0 \<le> t; t \<le> 1\<rbrakk>
  3805                \<Longrightarrow> t = Arg (exp (2 * of_real pi * of_real t * \<i>)) / (2 * pi) \<or> t=1 \<and> Arg (exp (2 * of_real pi * of_real t * \<i>)) = 0"
  3805                \<Longrightarrow> t = Arg2pi (exp (2 * of_real pi * of_real t * \<i>)) / (2 * pi) \<or> t=1 \<and> Arg2pi (exp (2 * of_real pi * of_real t * \<i>)) = 0"
  3806       apply (rule disjCI)
  3806       apply (rule disjCI)
  3807       using Arg_of_real [of 1] apply (auto simp: Arg_exp)
  3807       using Arg2pi_of_real [of 1] apply (auto simp: Arg2pi_exp)
  3808       done
  3808       done
  3809     have "homotopic_loops S p (p \<circ> (\<lambda>z. Arg z / (2 * pi)) \<circ> exp \<circ> (\<lambda>t. 2 * complex_of_real pi * complex_of_real t * \<i>))"
  3809     have "homotopic_loops S p (p \<circ> (\<lambda>z. Arg2pi z / (2 * pi)) \<circ> exp \<circ> (\<lambda>t. 2 * complex_of_real pi * complex_of_real t * \<i>))"
  3810       apply (rule homotopic_loops_eq [OF p])
  3810       apply (rule homotopic_loops_eq [OF p])
  3811       using p teq apply (fastforce simp: pathfinish_def pathstart_def)
  3811       using p teq apply (fastforce simp: pathfinish_def pathstart_def)
  3812       done
  3812       done
  3813     then
  3813     then
  3814     show "homotopic_loops S p (linepath a a)"
  3814     show "homotopic_loops S p (linepath a a)"
  3853   shows "(path_image \<gamma>) homeomorphic sphere a r"
  3853   shows "(path_image \<gamma>) homeomorphic sphere a r"
  3854 proof -
  3854 proof -
  3855   have "homotopic_loops (path_image \<gamma>) \<gamma> \<gamma>"
  3855   have "homotopic_loops (path_image \<gamma>) \<gamma> \<gamma>"
  3856     by (simp add: assms homotopic_loops_refl simple_path_imp_path)
  3856     by (simp add: assms homotopic_loops_refl simple_path_imp_path)
  3857   then have hom: "homotopic_with (\<lambda>h. True) (sphere 0 1) (path_image \<gamma>)
  3857   then have hom: "homotopic_with (\<lambda>h. True) (sphere 0 1) (path_image \<gamma>)
  3858                (\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi))) (\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi)))"
  3858                (\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi))) (\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi)))"
  3859     by (rule homotopic_loops_imp_homotopic_circlemaps)
  3859     by (rule homotopic_loops_imp_homotopic_circlemaps)
  3860   have "\<exists>g. homeomorphism (sphere 0 1) (path_image \<gamma>) (\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi))) g"
  3860   have "\<exists>g. homeomorphism (sphere 0 1) (path_image \<gamma>) (\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi))) g"
  3861   proof (rule homeomorphism_compact)
  3861   proof (rule homeomorphism_compact)
  3862     show "continuous_on (sphere 0 1) (\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi)))"
  3862     show "continuous_on (sphere 0 1) (\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi)))"
  3863       using hom homotopic_with_imp_continuous by blast
  3863       using hom homotopic_with_imp_continuous by blast
  3864     show "inj_on (\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi))) (sphere 0 1)"
  3864     show "inj_on (\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi))) (sphere 0 1)"
  3865     proof
  3865     proof
  3866       fix x y
  3866       fix x y
  3867       assume xy: "x \<in> sphere 0 1" "y \<in> sphere 0 1"
  3867       assume xy: "x \<in> sphere 0 1" "y \<in> sphere 0 1"
  3868          and eq: "(\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi))) x = (\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi))) y"
  3868          and eq: "(\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi))) x = (\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi))) y"
  3869       then have "(Arg x / (2*pi)) = (Arg y / (2*pi))"
  3869       then have "(Arg2pi x / (2*pi)) = (Arg2pi y / (2*pi))"
  3870       proof -
  3870       proof -
  3871         have "(Arg x / (2*pi)) \<in> {0..1}" "(Arg y / (2*pi)) \<in> {0..1}"
  3871         have "(Arg2pi x / (2*pi)) \<in> {0..1}" "(Arg2pi y / (2*pi)) \<in> {0..1}"
  3872           using Arg_ge_0 Arg_lt_2pi dual_order.strict_iff_order by fastforce+
  3872           using Arg2pi_ge_0 Arg2pi_lt_2pi dual_order.strict_iff_order by fastforce+
  3873         with eq show ?thesis
  3873         with eq show ?thesis
  3874           using \<open>simple_path \<gamma>\<close> Arg_lt_2pi unfolding simple_path_def o_def
  3874           using \<open>simple_path \<gamma>\<close> Arg2pi_lt_2pi unfolding simple_path_def o_def
  3875           by (metis eq_divide_eq_1 not_less_iff_gr_or_eq)
  3875           by (metis eq_divide_eq_1 not_less_iff_gr_or_eq)
  3876       qed
  3876       qed
  3877       with xy show "x = y"
  3877       with xy show "x = y"
  3878         by (metis Arg Arg_0 dist_0_norm divide_cancel_right dual_order.strict_iff_order mem_sphere)
  3878         by (metis Arg2pi Arg2pi_0 dist_0_norm divide_cancel_right dual_order.strict_iff_order mem_sphere)
  3879     qed
  3879     qed
  3880     have "\<And>z. cmod z = 1 \<Longrightarrow> \<exists>x\<in>{0..1}. \<gamma> (Arg z / (2*pi)) = \<gamma> x"
  3880     have "\<And>z. cmod z = 1 \<Longrightarrow> \<exists>x\<in>{0..1}. \<gamma> (Arg2pi z / (2*pi)) = \<gamma> x"
  3881        by (metis Arg_ge_0 Arg_lt_2pi atLeastAtMost_iff divide_less_eq_1 less_eq_real_def zero_less_mult_iff pi_gt_zero zero_le_divide_iff zero_less_numeral)
  3881        by (metis Arg2pi_ge_0 Arg2pi_lt_2pi atLeastAtMost_iff divide_less_eq_1 less_eq_real_def zero_less_mult_iff pi_gt_zero zero_le_divide_iff zero_less_numeral)
  3882      moreover have "\<exists>z\<in>sphere 0 1. \<gamma> x = \<gamma> (Arg z / (2*pi))" if "0 \<le> x" "x \<le> 1" for x
  3882      moreover have "\<exists>z\<in>sphere 0 1. \<gamma> x = \<gamma> (Arg2pi z / (2*pi))" if "0 \<le> x" "x \<le> 1" for x
  3883      proof (cases "x=1")
  3883      proof (cases "x=1")
  3884        case True
  3884        case True
  3885        then show ?thesis
  3885        then show ?thesis
  3886          apply (rule_tac x=1 in bexI)
  3886          apply (rule_tac x=1 in bexI)
  3887          apply (metis loop Arg_of_real divide_eq_0_iff of_real_1 pathfinish_def pathstart_def \<open>0 \<le> x\<close>, auto)
  3887          apply (metis loop Arg2pi_of_real divide_eq_0_iff of_real_1 pathfinish_def pathstart_def \<open>0 \<le> x\<close>, auto)
  3888          done
  3888          done
  3889      next
  3889      next
  3890        case False
  3890        case False
  3891        then have *: "(Arg (exp (\<i>*(2* of_real pi* of_real x))) / (2*pi)) = x"
  3891        then have *: "(Arg2pi (exp (\<i>*(2* of_real pi* of_real x))) / (2*pi)) = x"
  3892          using that by (auto simp: Arg_exp divide_simps)
  3892          using that by (auto simp: Arg2pi_exp divide_simps)
  3893        show ?thesis
  3893        show ?thesis
  3894          by (rule_tac x="exp(\<i> * of_real(2*pi*x))" in bexI) (auto simp: *)
  3894          by (rule_tac x="exp(\<i> * of_real(2*pi*x))" in bexI) (auto simp: *)
  3895     qed
  3895     qed
  3896     ultimately show "(\<gamma> \<circ> (\<lambda>z. Arg z / (2*pi))) ` sphere 0 1 = path_image \<gamma>"
  3896     ultimately show "(\<gamma> \<circ> (\<lambda>z. Arg2pi z / (2*pi))) ` sphere 0 1 = path_image \<gamma>"
  3897       by (auto simp: path_image_def image_iff)
  3897       by (auto simp: path_image_def image_iff)
  3898     qed auto
  3898     qed auto
  3899     then have "path_image \<gamma> homeomorphic sphere (0::complex) 1"
  3899     then have "path_image \<gamma> homeomorphic sphere (0::complex) 1"
  3900       using homeomorphic_def homeomorphic_sym by blast
  3900       using homeomorphic_def homeomorphic_sym by blast
  3901   also have "... homeomorphic sphere a r"
  3901   also have "... homeomorphic sphere a r"