src/HOL/Analysis/Harmonic_Numbers.thy
changeset 68643 3db6c9338ec1
parent 67399 eab6ce8368fa
child 69064 5840724b1d71
equal deleted inserted replaced
68642:d812b6ee711b 68643:3db6c9338ec1
    17   and the Euler-Mascheroni constant.
    17   and the Euler-Mascheroni constant.
    18 \<close>
    18 \<close>
    19 
    19 
    20 subsection \<open>The Harmonic numbers\<close>
    20 subsection \<open>The Harmonic numbers\<close>
    21 
    21 
    22 definition harm :: "nat \<Rightarrow> 'a :: real_normed_field" where
    22 definition%important harm :: "nat \<Rightarrow> 'a :: real_normed_field" where
    23   "harm n = (\<Sum>k=1..n. inverse (of_nat k))"
    23   "harm n = (\<Sum>k=1..n. inverse (of_nat k))"
    24 
    24 
    25 lemma harm_altdef: "harm n = (\<Sum>k<n. inverse (of_nat (Suc k)))"
    25 lemma harm_altdef: "harm n = (\<Sum>k<n. inverse (of_nat (Suc k)))"
    26   unfolding harm_def by (induction n) simp_all
    26   unfolding harm_def by (induction n) simp_all
    27 
    27 
    52   also have "harm \<dots> = harm (pred_numeral n) + inverse (numeral n)"
    52   also have "harm \<dots> = harm (pred_numeral n) + inverse (numeral n)"
    53     by (subst harm_Suc, subst numeral_eq_Suc[symmetric]) simp
    53     by (subst harm_Suc, subst numeral_eq_Suc[symmetric]) simp
    54   finally show "harm (numeral n) = harm (pred_numeral n) + inverse (numeral n)" .
    54   finally show "harm (numeral n) = harm (pred_numeral n) + inverse (numeral n)" .
    55 qed (simp_all add: harm_def)
    55 qed (simp_all add: harm_def)
    56 
    56 
    57 lemma not_convergent_harm: "\<not>convergent (harm :: nat \<Rightarrow> 'a :: real_normed_field)"
    57 theorem not_convergent_harm: "\<not>convergent (harm :: nat \<Rightarrow> 'a :: real_normed_field)"
    58 proof -
    58 proof -
    59   have "convergent (\<lambda>n. norm (harm n :: 'a)) \<longleftrightarrow>
    59   have "convergent (\<lambda>n. norm (harm n :: 'a)) \<longleftrightarrow>
    60             convergent (harm :: nat \<Rightarrow> real)" by (simp add: norm_harm)
    60             convergent (harm :: nat \<Rightarrow> real)" by (simp add: norm_harm)
    61   also have "\<dots> \<longleftrightarrow> convergent (\<lambda>n. \<Sum>k=Suc 0..Suc n. inverse (of_nat k) :: real)"
    61   also have "\<dots> \<longleftrightarrow> convergent (\<lambda>n. \<Sum>k=Suc 0..Suc n. inverse (of_nat k) :: real)"
    62     unfolding harm_def[abs_def] by (subst convergent_Suc_iff) simp_all
    62     unfolding harm_def[abs_def] by (subst convergent_Suc_iff) simp_all
   154   have "convergent (\<lambda>n. harm (Suc n) - ln (of_nat (Suc n) :: real))"
   154   have "convergent (\<lambda>n. harm (Suc n) - ln (of_nat (Suc n) :: real))"
   155     by (subst A) (fact euler_mascheroni.sum_integral_diff_series_convergent)
   155     by (subst A) (fact euler_mascheroni.sum_integral_diff_series_convergent)
   156   thus ?thesis by (subst (asm) convergent_Suc_iff)
   156   thus ?thesis by (subst (asm) convergent_Suc_iff)
   157 qed
   157 qed
   158 
   158 
   159 lemma euler_mascheroni_LIMSEQ:
   159 lemma%important euler_mascheroni_LIMSEQ:
   160   "(\<lambda>n. harm n - ln (of_nat n) :: real) \<longlonglongrightarrow> euler_mascheroni"
   160   "(\<lambda>n. harm n - ln (of_nat n) :: real) \<longlonglongrightarrow> euler_mascheroni"
   161   unfolding euler_mascheroni_def
   161   unfolding euler_mascheroni_def
   162   by (simp add: convergent_LIMSEQ_iff [symmetric] euler_mascheroni_convergent)
   162   by (simp add: convergent_LIMSEQ_iff [symmetric] euler_mascheroni_convergent)
   163 
   163 
   164 lemma euler_mascheroni_LIMSEQ_of_real:
   164 lemma euler_mascheroni_LIMSEQ_of_real:
   185        sums (of_real euler_mascheroni :: 'a :: {banach, real_normed_field})"
   185        sums (of_real euler_mascheroni :: 'a :: {banach, real_normed_field})"
   186     by (subst sums_of_real_iff) (rule euler_mascheroni_sum_real)
   186     by (subst sums_of_real_iff) (rule euler_mascheroni_sum_real)
   187   thus ?thesis by simp
   187   thus ?thesis by simp
   188 qed
   188 qed
   189 
   189 
   190 lemma alternating_harmonic_series_sums: "(\<lambda>k. (-1)^k / real_of_nat (Suc k)) sums ln 2"
   190 theorem alternating_harmonic_series_sums: "(\<lambda>k. (-1)^k / real_of_nat (Suc k)) sums ln 2"
   191 proof -
   191 proof -
   192   let ?f = "\<lambda>n. harm n - ln (real_of_nat n)"
   192   let ?f = "\<lambda>n. harm n - ln (real_of_nat n)"
   193   let ?g = "\<lambda>n. if even n then 0 else (2::real)"
   193   let ?g = "\<lambda>n. if even n then 0 else (2::real)"
   194   let ?em = "\<lambda>n. harm n - ln (real_of_nat n)"
   194   let ?em = "\<lambda>n. harm n - ln (real_of_nat n)"
   195   have "eventually (\<lambda>n. ?em (2*n) - ?em n + ln 2 = (\<Sum>k<2*n. (-1)^k / real_of_nat (Suc k))) at_top"
   195   have "eventually (\<lambda>n. ?em (2*n) - ?em n + ln 2 = (\<Sum>k<2*n. (-1)^k / real_of_nat (Suc k))) at_top"
   248       by (induction n) (simp_all add: inverse_eq_divide)
   248       by (induction n) (simp_all add: inverse_eq_divide)
   249   qed
   249   qed
   250 qed
   250 qed
   251 
   251 
   252 
   252 
   253 subsection \<open>Bounds on the Euler-Mascheroni constant\<close>
   253 subsection%unimportant \<open>Bounds on the Euler-Mascheroni constant\<close>
   254 
   254 
   255 (* TODO: Move? *)
   255 (* TODO: Move? *)
   256 lemma ln_inverse_approx_le:
   256 lemma ln_inverse_approx_le:
   257   assumes "(x::real) > 0" "a > 0"
   257   assumes "(x::real) > 0" "a > 0"
   258   shows   "ln (x + a) - ln x \<le> a * (inverse x + inverse (x + a))/2" (is "_ \<le> ?A")
   258   shows   "ln (x + a) - ln x \<le> a * (inverse x + inverse (x + a))/2" (is "_ \<le> ?A")
   338   finally show ?thesis .
   338   finally show ?thesis .
   339 qed
   339 qed
   340 
   340 
   341 
   341 
   342 lemma euler_mascheroni_lower:
   342 lemma euler_mascheroni_lower:
   343         "euler_mascheroni \<ge> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 2))"
   343           "euler_mascheroni \<ge> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 2))"
   344   and euler_mascheroni_upper:
   344     and euler_mascheroni_upper:
   345         "euler_mascheroni \<le> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 1))"
   345           "euler_mascheroni \<le> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 1))"
   346 proof -
   346 proof -
   347   define D :: "_ \<Rightarrow> real"
   347   define D :: "_ \<Rightarrow> real"
   348     where "D n = inverse (of_nat (n+1)) + ln (of_nat (n+1)) - ln (of_nat (n+2))" for n
   348     where "D n = inverse (of_nat (n+1)) + ln (of_nat (n+1)) - ln (of_nat (n+2))" for n
   349   let ?g = "\<lambda>n. ln (of_nat (n+2)) - ln (of_nat (n+1)) - inverse (of_nat (n+1)) :: real"
   349   let ?g = "\<lambda>n. ln (of_nat (n+2)) - ln (of_nat (n+1)) - inverse (of_nat (n+1)) :: real"
   350   define inv where [abs_def]: "inv n = inverse (real_of_nat n)" for n
   350   define inv where [abs_def]: "inv n = inverse (real_of_nat n)" for n