src/HOL/Analysis/Harmonic_Numbers.thy
author wenzelm
Mon Mar 25 17:21:26 2019 +0100 (4 weeks ago)
changeset 69981 3dced198b9ec
parent 69597 ff784d5a5bfb
child 70113 c8deb8ba6d05
permissions -rw-r--r--
more strict AFP properties;
hoelzl@63627
     1
(*  Title:    HOL/Analysis/Harmonic_Numbers.thy
hoelzl@62055
     2
    Author:   Manuel Eberl, TU M√ľnchen
eberlm@62049
     3
*)
hoelzl@62055
     4
hoelzl@62055
     5
section \<open>Harmonic Numbers\<close>
hoelzl@62055
     6
eberlm@62049
     7
theory Harmonic_Numbers
hoelzl@63594
     8
imports
eberlm@62049
     9
  Complex_Transcendental
hoelzl@63594
    10
  Summation_Tests
eberlm@62049
    11
  Integral_Test
eberlm@62049
    12
begin
eberlm@62049
    13
hoelzl@62055
    14
text \<open>
wenzelm@62174
    15
  The definition of the Harmonic Numbers and the Euler-Mascheroni constant.
wenzelm@69597
    16
  Also provides a reasonably accurate approximation of \<^term>\<open>ln 2 :: real\<close>
wenzelm@62174
    17
  and the Euler-Mascheroni constant.
hoelzl@62055
    18
\<close>
hoelzl@62055
    19
eberlm@62049
    20
subsection \<open>The Harmonic numbers\<close>
eberlm@62049
    21
eberlm@68643
    22
definition%important harm :: "nat \<Rightarrow> 'a :: real_normed_field" where
eberlm@62049
    23
  "harm n = (\<Sum>k=1..n. inverse (of_nat k))"
eberlm@62049
    24
eberlm@62049
    25
lemma harm_altdef: "harm n = (\<Sum>k<n. inverse (of_nat (Suc k)))"
eberlm@62049
    26
  unfolding harm_def by (induction n) simp_all
eberlm@62049
    27
eberlm@62049
    28
lemma harm_Suc: "harm (Suc n) = harm n + inverse (of_nat (Suc n))"
eberlm@62049
    29
  by (simp add: harm_def)
eberlm@62049
    30
eberlm@62049
    31
lemma harm_nonneg: "harm n \<ge> (0 :: 'a :: {real_normed_field,linordered_field})"
nipkow@64267
    32
  unfolding harm_def by (intro sum_nonneg) simp_all
eberlm@62049
    33
eberlm@62065
    34
lemma harm_pos: "n > 0 \<Longrightarrow> harm n > (0 :: 'a :: {real_normed_field,linordered_field})"
nipkow@64267
    35
  unfolding harm_def by (intro sum_pos) simp_all
eberlm@62065
    36
eberlm@62049
    37
lemma of_real_harm: "of_real (harm n) = harm n"
eberlm@62049
    38
  unfolding harm_def by simp
hoelzl@63594
    39
eberlm@65395
    40
lemma abs_harm [simp]: "(abs (harm n) :: real) = harm n"
lp15@66495
    41
  using harm_nonneg[of n] by (rule abs_of_nonneg)
eberlm@65395
    42
eberlm@62049
    43
lemma norm_harm: "norm (harm n) = harm n"
eberlm@62049
    44
  by (subst of_real_harm [symmetric]) (simp add: harm_nonneg)
eberlm@62049
    45
hoelzl@63594
    46
lemma harm_expand:
eberlm@62065
    47
  "harm 0 = 0"
eberlm@62049
    48
  "harm (Suc 0) = 1"
eberlm@62049
    49
  "harm (numeral n) = harm (pred_numeral n) + inverse (numeral n)"
eberlm@62049
    50
proof -
eberlm@62049
    51
  have "numeral n = Suc (pred_numeral n)" by simp
eberlm@62049
    52
  also have "harm \<dots> = harm (pred_numeral n) + inverse (numeral n)"
eberlm@62049
    53
    by (subst harm_Suc, subst numeral_eq_Suc[symmetric]) simp
eberlm@62049
    54
  finally show "harm (numeral n) = harm (pred_numeral n) + inverse (numeral n)" .
eberlm@62065
    55
qed (simp_all add: harm_def)
eberlm@62049
    56
eberlm@68643
    57
theorem not_convergent_harm: "\<not>convergent (harm :: nat \<Rightarrow> 'a :: real_normed_field)"
eberlm@62049
    58
proof -
eberlm@62049
    59
  have "convergent (\<lambda>n. norm (harm n :: 'a)) \<longleftrightarrow>
eberlm@62049
    60
            convergent (harm :: nat \<Rightarrow> real)" by (simp add: norm_harm)
eberlm@62049
    61
  also have "\<dots> \<longleftrightarrow> convergent (\<lambda>n. \<Sum>k=Suc 0..Suc n. inverse (of_nat k) :: real)"
eberlm@62049
    62
    unfolding harm_def[abs_def] by (subst convergent_Suc_iff) simp_all
eberlm@62049
    63
  also have "... \<longleftrightarrow> convergent (\<lambda>n. \<Sum>k\<le>n. inverse (of_nat (Suc k)) :: real)"
nipkow@64267
    64
    by (subst sum_shift_bounds_cl_Suc_ivl) (simp add: atLeast0AtMost)
eberlm@62049
    65
  also have "... \<longleftrightarrow> summable (\<lambda>n. inverse (of_nat n) :: real)"
eberlm@62049
    66
    by (subst summable_Suc_iff [symmetric]) (simp add: summable_iff_convergent')
eberlm@62049
    67
  also have "\<not>..." by (rule not_summable_harmonic)
eberlm@62049
    68
  finally show ?thesis by (blast dest: convergent_norm)
eberlm@62049
    69
qed
eberlm@62049
    70
eberlm@62065
    71
lemma harm_pos_iff [simp]: "harm n > (0 :: 'a :: {real_normed_field,linordered_field}) \<longleftrightarrow> n > 0"
eberlm@62065
    72
  by (rule iffI, cases n, simp add: harm_expand, simp, rule harm_pos)
eberlm@62065
    73
eberlm@62065
    74
lemma ln_diff_le_inverse:
eberlm@62065
    75
  assumes "x \<ge> (1::real)"
eberlm@62065
    76
  shows   "ln (x + 1) - ln x < 1 / x"
eberlm@62065
    77
proof -
eberlm@62065
    78
  from assms have "\<exists>z>x. z < x + 1 \<and> ln (x + 1) - ln x = (x + 1 - x) * inverse z"
eberlm@62065
    79
    by (intro MVT2) (auto intro!: derivative_eq_intros simp: field_simps)
eberlm@62065
    80
  then obtain z where z: "z > x" "z < x + 1" "ln (x + 1) - ln x = inverse z" by auto
eberlm@62065
    81
  have "ln (x + 1) - ln x = inverse z" by fact
eberlm@62065
    82
  also from z(1,2) assms have "\<dots> < 1 / x" by (simp add: field_simps)
eberlm@62065
    83
  finally show ?thesis .
eberlm@62065
    84
qed
eberlm@62065
    85
eberlm@62065
    86
lemma ln_le_harm: "ln (real n + 1) \<le> (harm n :: real)"
eberlm@62065
    87
proof (induction n)
eberlm@62065
    88
  fix n assume IH: "ln (real n + 1) \<le> harm n"
eberlm@62065
    89
  have "ln (real (Suc n) + 1) = ln (real n + 1) + (ln (real n + 2) - ln (real n + 1))" by simp
eberlm@62065
    90
  also have "(ln (real n + 2) - ln (real n + 1)) \<le> 1 / real (Suc n)"
eberlm@62065
    91
    using ln_diff_le_inverse[of "real n + 1"] by (simp add: add_ac)
eberlm@62065
    92
  also note IH
eberlm@62065
    93
  also have "harm n + 1 / real (Suc n) = harm (Suc n)" by (simp add: harm_Suc field_simps)
eberlm@62065
    94
  finally show "ln (real (Suc n) + 1) \<le> harm (Suc n)" by - simp
eberlm@62065
    95
qed (simp_all add: harm_def)
eberlm@62065
    96
eberlm@65395
    97
lemma harm_at_top: "filterlim (harm :: nat \<Rightarrow> real) at_top sequentially"
eberlm@65395
    98
proof (rule filterlim_at_top_mono)
eberlm@65395
    99
  show "eventually (\<lambda>n. harm n \<ge> ln (real (Suc n))) at_top"
eberlm@65395
   100
    using ln_le_harm by (intro always_eventually allI) (simp_all add: add_ac)
eberlm@65395
   101
  show "filterlim (\<lambda>n. ln (real (Suc n))) at_top sequentially"
lp15@66495
   102
    by (intro filterlim_compose[OF ln_at_top] filterlim_compose[OF filterlim_real_sequentially]
eberlm@65395
   103
              filterlim_Suc)
eberlm@65395
   104
qed
eberlm@65395
   105
eberlm@62049
   106
lp15@66495
   107
subsection \<open>The Euler-Mascheroni constant\<close>
eberlm@62049
   108
eberlm@62049
   109
text \<open>
eberlm@62049
   110
  The limit of the difference between the partial harmonic sum and the natural logarithm
eberlm@62049
   111
  (approximately 0.577216). This value occurs e.g. in the definition of the Gamma function.
eberlm@62049
   112
 \<close>
eberlm@62049
   113
definition euler_mascheroni :: "'a :: real_normed_algebra_1" where
eberlm@62049
   114
  "euler_mascheroni = of_real (lim (\<lambda>n. harm n - ln (of_nat n)))"
eberlm@62049
   115
eberlm@62049
   116
lemma of_real_euler_mascheroni [simp]: "of_real euler_mascheroni = euler_mascheroni"
eberlm@62049
   117
  by (simp add: euler_mascheroni_def)
eberlm@62049
   118
eberlm@62049
   119
interpretation euler_mascheroni: antimono_fun_sum_integral_diff "\<lambda>x. inverse (x + 1)"
eberlm@62049
   120
  by unfold_locales (auto intro!: continuous_intros)
eberlm@62049
   121
eberlm@62049
   122
lemma euler_mascheroni_sum_integral_diff_series:
eberlm@62049
   123
  "euler_mascheroni.sum_integral_diff_series n = harm (Suc n) - ln (of_nat (Suc n))"
eberlm@62049
   124
proof -
eberlm@62049
   125
  have "harm (Suc n) = (\<Sum>k=0..n. inverse (of_nat k + 1) :: real)" unfolding harm_def
nipkow@64267
   126
    unfolding One_nat_def by (subst sum_shift_bounds_cl_Suc_ivl) (simp add: add_ac)
eberlm@62049
   127
  moreover have "((\<lambda>x. inverse (x + 1) :: real) has_integral ln (of_nat n + 1) - ln (0 + 1))
eberlm@62049
   128
                   {0..of_nat n}"
eberlm@62049
   129
    by (intro fundamental_theorem_of_calculus)
eberlm@62049
   130
       (auto intro!: derivative_eq_intros simp: divide_inverse
eberlm@62049
   131
           has_field_derivative_iff_has_vector_derivative[symmetric])
eberlm@62049
   132
  hence "integral {0..of_nat n} (\<lambda>x. inverse (x + 1) :: real) = ln (of_nat (Suc n))"
eberlm@62049
   133
    by (auto dest!: integral_unique)
hoelzl@63594
   134
  ultimately show ?thesis
eberlm@62049
   135
    by (simp add: euler_mascheroni.sum_integral_diff_series_def atLeast0AtMost)
eberlm@62049
   136
qed
eberlm@62049
   137
eberlm@62049
   138
lemma euler_mascheroni_sequence_decreasing:
eberlm@62049
   139
  "m > 0 \<Longrightarrow> m \<le> n \<Longrightarrow> harm n - ln (of_nat n) \<le> harm m - ln (of_nat m :: real)"
eberlm@62049
   140
  by (cases m, simp, cases n, simp, hypsubst,
eberlm@62049
   141
      subst (1 2) euler_mascheroni_sum_integral_diff_series [symmetric],
eberlm@62049
   142
      rule euler_mascheroni.sum_integral_diff_series_antimono, simp)
eberlm@62049
   143
eberlm@62049
   144
lemma euler_mascheroni_sequence_nonneg:
eberlm@62049
   145
  "n > 0 \<Longrightarrow> harm n - ln (of_nat n) \<ge> (0::real)"
eberlm@62049
   146
  by (cases n, simp, hypsubst, subst euler_mascheroni_sum_integral_diff_series [symmetric],
eberlm@62049
   147
      rule euler_mascheroni.sum_integral_diff_series_nonneg)
eberlm@62049
   148
eberlm@62049
   149
lemma euler_mascheroni_convergent: "convergent (\<lambda>n. harm n - ln (of_nat n) :: real)"
eberlm@62049
   150
proof -
hoelzl@63594
   151
  have A: "(\<lambda>n. harm (Suc n) - ln (of_nat (Suc n))) =
eberlm@62049
   152
             euler_mascheroni.sum_integral_diff_series"
eberlm@62049
   153
    by (subst euler_mascheroni_sum_integral_diff_series [symmetric]) (rule refl)
eberlm@62049
   154
  have "convergent (\<lambda>n. harm (Suc n) - ln (of_nat (Suc n) :: real))"
eberlm@62049
   155
    by (subst A) (fact euler_mascheroni.sum_integral_diff_series_convergent)
eberlm@62049
   156
  thus ?thesis by (subst (asm) convergent_Suc_iff)
eberlm@62049
   157
qed
eberlm@62049
   158
eberlm@68643
   159
lemma%important euler_mascheroni_LIMSEQ:
eberlm@62049
   160
  "(\<lambda>n. harm n - ln (of_nat n) :: real) \<longlonglongrightarrow> euler_mascheroni"
eberlm@62049
   161
  unfolding euler_mascheroni_def
eberlm@62049
   162
  by (simp add: convergent_LIMSEQ_iff [symmetric] euler_mascheroni_convergent)
eberlm@62049
   163
hoelzl@63594
   164
lemma euler_mascheroni_LIMSEQ_of_real:
hoelzl@63594
   165
  "(\<lambda>n. of_real (harm n - ln (of_nat n))) \<longlonglongrightarrow>
eberlm@62049
   166
      (euler_mascheroni :: 'a :: {real_normed_algebra_1, topological_space})"
eberlm@62049
   167
proof -
eberlm@62049
   168
  have "(\<lambda>n. of_real (harm n - ln (of_nat n))) \<longlonglongrightarrow> (of_real (euler_mascheroni) :: 'a)"
eberlm@62049
   169
    by (intro tendsto_of_real euler_mascheroni_LIMSEQ)
eberlm@62049
   170
  thus ?thesis by simp
eberlm@62049
   171
qed
eberlm@62049
   172
eberlm@63721
   173
lemma euler_mascheroni_sum_real:
eberlm@62049
   174
  "(\<lambda>n. inverse (of_nat (n+1)) + ln (of_nat (n+1)) - ln (of_nat (n+2)) :: real)
hoelzl@63594
   175
       sums euler_mascheroni"
eberlm@62049
   176
 using sums_add[OF telescope_sums[OF LIMSEQ_Suc[OF euler_mascheroni_LIMSEQ]]
eberlm@62049
   177
                   telescope_sums'[OF LIMSEQ_inverse_real_of_nat]]
eberlm@62049
   178
  by (simp_all add: harm_def algebra_simps)
eberlm@62049
   179
eberlm@63721
   180
lemma euler_mascheroni_sum:
eberlm@63721
   181
  "(\<lambda>n. inverse (of_nat (n+1)) + of_real (ln (of_nat (n+1))) - of_real (ln (of_nat (n+2))))
eberlm@63721
   182
       sums (euler_mascheroni :: 'a :: {banach, real_normed_field})"
eberlm@63721
   183
proof -
eberlm@63721
   184
  have "(\<lambda>n. of_real (inverse (of_nat (n+1)) + ln (of_nat (n+1)) - ln (of_nat (n+2))))
eberlm@63721
   185
       sums (of_real euler_mascheroni :: 'a :: {banach, real_normed_field})"
eberlm@63721
   186
    by (subst sums_of_real_iff) (rule euler_mascheroni_sum_real)
eberlm@63721
   187
  thus ?thesis by simp
eberlm@63721
   188
qed
eberlm@63721
   189
eberlm@68643
   190
theorem alternating_harmonic_series_sums: "(\<lambda>k. (-1)^k / real_of_nat (Suc k)) sums ln 2"
eberlm@62049
   191
proof -
eberlm@62049
   192
  let ?f = "\<lambda>n. harm n - ln (real_of_nat n)"
eberlm@62049
   193
  let ?g = "\<lambda>n. if even n then 0 else (2::real)"
eberlm@62049
   194
  let ?em = "\<lambda>n. harm n - ln (real_of_nat n)"
eberlm@62049
   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"
eberlm@62049
   196
    using eventually_gt_at_top[of "0::nat"]
eberlm@62049
   197
  proof eventually_elim
eberlm@62049
   198
    fix n :: nat assume n: "n > 0"
eberlm@62049
   199
    have "(\<Sum>k<2*n. (-1)^k / real_of_nat (Suc k)) =
eberlm@62049
   200
              (\<Sum>k<2*n. ((-1)^k + ?g k) / of_nat (Suc k)) - (\<Sum>k<2*n. ?g k / of_nat (Suc k))"
nipkow@64267
   201
      by (simp add: sum.distrib algebra_simps divide_inverse)
eberlm@62049
   202
    also have "(\<Sum>k<2*n. ((-1)^k + ?g k) / real_of_nat (Suc k)) = harm (2*n)"
nipkow@64267
   203
      unfolding harm_altdef by (intro sum.cong) (auto simp: field_simps)
eberlm@62049
   204
    also have "(\<Sum>k<2*n. ?g k / real_of_nat (Suc k)) = (\<Sum>k|k<2*n \<and> odd k. ?g k / of_nat (Suc k))"
nipkow@64267
   205
      by (intro sum.mono_neutral_right) auto
eberlm@62049
   206
    also have "\<dots> = (\<Sum>k|k<2*n \<and> odd k. 2 / (real_of_nat (Suc k)))"
nipkow@64267
   207
      by (intro sum.cong) auto
hoelzl@63594
   208
    also have "(\<Sum>k|k<2*n \<and> odd k. 2 / (real_of_nat (Suc k))) = harm n"
eberlm@62049
   209
      unfolding harm_altdef
nipkow@64267
   210
      by (intro sum.reindex_cong[of "\<lambda>n. 2*n+1"]) (auto simp: inj_on_def field_simps elim!: oddE)
eberlm@62049
   211
    also have "harm (2*n) - harm n = ?em (2*n) - ?em n + ln 2" using n
eberlm@62049
   212
      by (simp_all add: algebra_simps ln_mult)
eberlm@62049
   213
    finally show "?em (2*n) - ?em n + ln 2 = (\<Sum>k<2*n. (-1)^k / real_of_nat (Suc k))" ..
eberlm@62049
   214
  qed
hoelzl@63594
   215
  moreover have "(\<lambda>n. ?em (2*n) - ?em n + ln (2::real))
eberlm@62049
   216
                     \<longlonglongrightarrow> euler_mascheroni - euler_mascheroni + ln 2"
eberlm@62049
   217
    by (intro tendsto_intros euler_mascheroni_LIMSEQ filterlim_compose[OF euler_mascheroni_LIMSEQ]
eberlm@66447
   218
              filterlim_subseq) (auto simp: strict_mono_def)
eberlm@62049
   219
  hence "(\<lambda>n. ?em (2*n) - ?em n + ln (2::real)) \<longlonglongrightarrow> ln 2" by simp
eberlm@62049
   220
  ultimately have "(\<lambda>n. (\<Sum>k<2*n. (-1)^k / real_of_nat (Suc k))) \<longlonglongrightarrow> ln 2"
eberlm@62049
   221
    by (rule Lim_transform_eventually)
hoelzl@63594
   222
eberlm@62049
   223
  moreover have "summable (\<lambda>k. (-1)^k * inverse (real_of_nat (Suc k)))"
eberlm@62049
   224
    using LIMSEQ_inverse_real_of_nat
eberlm@62049
   225
    by (intro summable_Leibniz(1) decseq_imp_monoseq decseq_SucI) simp_all
eberlm@62049
   226
  hence A: "(\<lambda>n. \<Sum>k<n. (-1)^k / real_of_nat (Suc k)) \<longlonglongrightarrow> (\<Sum>k. (-1)^k / real_of_nat (Suc k))"
eberlm@62049
   227
    by (simp add: summable_sums_iff divide_inverse sums_def)
nipkow@69064
   228
  from filterlim_compose[OF this filterlim_subseq[of "(*) (2::nat)"]]
eberlm@62049
   229
    have "(\<lambda>n. \<Sum>k<2*n. (-1)^k / real_of_nat (Suc k)) \<longlonglongrightarrow> (\<Sum>k. (-1)^k / real_of_nat (Suc k))"
eberlm@66447
   230
    by (simp add: strict_mono_def)
eberlm@62049
   231
  ultimately have "(\<Sum>k. (- 1) ^ k / real_of_nat (Suc k)) = ln 2" by (intro LIMSEQ_unique)
eberlm@62049
   232
  with A show ?thesis by (simp add: sums_def)
eberlm@62049
   233
qed
eberlm@62049
   234
hoelzl@63594
   235
lemma alternating_harmonic_series_sums':
eberlm@62049
   236
  "(\<lambda>k. inverse (real_of_nat (2*k+1)) - inverse (real_of_nat (2*k+2))) sums ln 2"
eberlm@62049
   237
unfolding sums_def
eberlm@62049
   238
proof (rule Lim_transform_eventually)
eberlm@62049
   239
  show "(\<lambda>n. \<Sum>k<2*n. (-1)^k / (real_of_nat (Suc k))) \<longlonglongrightarrow> ln 2"
hoelzl@63594
   240
    using alternating_harmonic_series_sums unfolding sums_def
eberlm@62049
   241
    by (rule filterlim_compose) (rule mult_nat_left_at_top, simp)
eberlm@62049
   242
  show "eventually (\<lambda>n. (\<Sum>k<2*n. (-1)^k / (real_of_nat (Suc k))) =
eberlm@62049
   243
            (\<Sum>k<n. inverse (real_of_nat (2*k+1)) - inverse (real_of_nat (2*k+2)))) sequentially"
eberlm@62049
   244
  proof (intro always_eventually allI)
eberlm@62049
   245
    fix n :: nat
eberlm@62049
   246
    show "(\<Sum>k<2*n. (-1)^k / (real_of_nat (Suc k))) =
eberlm@62049
   247
              (\<Sum>k<n. inverse (real_of_nat (2*k+1)) - inverse (real_of_nat (2*k+2)))"
eberlm@62049
   248
      by (induction n) (simp_all add: inverse_eq_divide)
eberlm@62049
   249
  qed
hoelzl@63594
   250
qed
eberlm@62049
   251
eberlm@62049
   252
eberlm@68643
   253
subsection%unimportant \<open>Bounds on the Euler-Mascheroni constant\<close>
eberlm@62049
   254
eberlm@62085
   255
(* TODO: Move? *)
eberlm@62049
   256
lemma ln_inverse_approx_le:
eberlm@62049
   257
  assumes "(x::real) > 0" "a > 0"
eberlm@62049
   258
  shows   "ln (x + a) - ln x \<le> a * (inverse x + inverse (x + a))/2" (is "_ \<le> ?A")
eberlm@62049
   259
proof -
wenzelm@63040
   260
  define f' where "f' = (inverse (x + a) - inverse x)/a"
eberlm@62049
   261
  have f'_nonpos: "f' \<le> 0" using assms by (simp add: f'_def divide_simps)
eberlm@62049
   262
  let ?f = "\<lambda>t. (t - x) * f' + inverse x"
eberlm@62049
   263
  let ?F = "\<lambda>t. (t - x)^2 * f' / 2 + t * inverse x"
lp15@66554
   264
  have diff: "\<And>t. t \<in> {x..x+a} \<Longrightarrow> (?F has_vector_derivative ?f t) (at t within {x..x+a})" 
lp15@66554
   265
    using assms
hoelzl@63594
   266
    by (auto intro!: derivative_eq_intros
eberlm@62049
   267
             simp: has_field_derivative_iff_has_vector_derivative[symmetric])
eberlm@62049
   268
  from assms have "(?f has_integral (?F (x+a) - ?F x)) {x..x+a}"
eberlm@62049
   269
    by (intro fundamental_theorem_of_calculus[OF _ diff])
eberlm@62049
   270
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric] field_simps
eberlm@62049
   271
             intro!: derivative_eq_intros)
eberlm@62049
   272
  also have "?F (x+a) - ?F x = (a*2 + f'*a\<^sup>2*x) / (2*x)" using assms by (simp add: field_simps)
hoelzl@63594
   273
  also have "f'*a^2 = - (a^2) / (x*(x + a))" using assms
eberlm@62049
   274
    by (simp add: divide_simps f'_def power2_eq_square)
eberlm@62049
   275
  also have "(a*2 + - a\<^sup>2/(x*(x+a))*x) / (2*x) = ?A" using assms
eberlm@62049
   276
    by (simp add: divide_simps power2_eq_square) (simp add: algebra_simps)
eberlm@62049
   277
  finally have int1: "((\<lambda>t. (t - x) * f' + inverse x) has_integral ?A) {x..x + a}" .
eberlm@62049
   278
eberlm@62049
   279
  from assms have int2: "(inverse has_integral (ln (x + a) - ln x)) {x..x+a}"
eberlm@62049
   280
    by (intro fundamental_theorem_of_calculus)
eberlm@62049
   281
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric] divide_simps
eberlm@62049
   282
             intro!: derivative_eq_intros)
eberlm@62049
   283
  hence "ln (x + a) - ln x = integral {x..x+a} inverse" by (simp add: integral_unique)
eberlm@62049
   284
  also have ineq: "\<forall>xa\<in>{x..x + a}. inverse xa \<le> (xa - x) * f' + inverse x"
eberlm@62049
   285
  proof
eberlm@62049
   286
    fix t assume t': "t \<in> {x..x+a}"
eberlm@62049
   287
    with assms have t: "0 \<le> (t - x) / a" "(t - x) / a \<le> 1" by simp_all
eberlm@62049
   288
    have "inverse t = inverse ((1 - (t - x) / a) *\<^sub>R x + ((t - x) / a) *\<^sub>R (x + a))" (is "_ = ?A")
eberlm@62049
   289
      using assms t' by (simp add: field_simps)
eberlm@62049
   290
    also from assms have "convex_on {x..x+a} inverse" by (intro convex_on_inverse) auto
hoelzl@63594
   291
    from convex_onD_Icc[OF this _ t] assms
eberlm@62049
   292
      have "?A \<le> (1 - (t - x) / a) * inverse x + (t - x) / a * inverse (x + a)" by simp
eberlm@62049
   293
    also have "\<dots> = (t - x) * f' + inverse x" using assms
eberlm@62049
   294
      by (simp add: f'_def divide_simps) (simp add: f'_def field_simps)
eberlm@62049
   295
    finally show "inverse t \<le> (t - x) * f' + inverse x" .
eberlm@62049
   296
  qed
eberlm@62049
   297
  hence "integral {x..x+a} inverse \<le> integral {x..x+a} ?f" using f'_nonpos assms
lp15@66495
   298
    by (blast intro: integral_le has_integral_integrable[OF int1] has_integral_integrable[OF int2] ineq)
eberlm@62049
   299
  also have "\<dots> = ?A" using int1 by (rule integral_unique)
eberlm@62049
   300
  finally show ?thesis .
eberlm@62049
   301
qed
eberlm@62049
   302
eberlm@62049
   303
lemma ln_inverse_approx_ge:
eberlm@62049
   304
  assumes "(x::real) > 0" "x < y"
eberlm@62049
   305
  shows   "ln y - ln x \<ge> 2 * (y - x) / (x + y)" (is "_ \<ge> ?A")
eberlm@62049
   306
proof -
wenzelm@63040
   307
  define m where "m = (x+y)/2"
wenzelm@63040
   308
  define f' where "f' = -inverse (m^2)"
eberlm@62049
   309
  from assms have m: "m > 0" by (simp add: m_def)
eberlm@62049
   310
  let ?F = "\<lambda>t. (t - m)^2 * f' / 2 + t / m"
eberlm@62049
   311
  from assms have "((\<lambda>t. (t - m) * f' + inverse m) has_integral (?F y - ?F x)) {x..y}"
eberlm@62049
   312
    by (intro fundamental_theorem_of_calculus)
eberlm@62049
   313
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric] divide_simps
eberlm@62049
   314
             intro!: derivative_eq_intros)
hoelzl@63594
   315
  also from m have "?F y - ?F x = ((y - m)^2 - (x - m)^2) * f' / 2 + (y - x) / m"
eberlm@62049
   316
    by (simp add: field_simps)
eberlm@62049
   317
  also have "((y - m)^2 - (x - m)^2) = 0" by (simp add: m_def power2_eq_square field_simps)
eberlm@62049
   318
  also have "0 * f' / 2 + (y - x) / m = ?A" by (simp add: m_def)
eberlm@62049
   319
  finally have int1: "((\<lambda>t. (t - m) * f' + inverse m) has_integral ?A) {x..y}" .
eberlm@62049
   320
eberlm@62049
   321
  from assms have int2: "(inverse has_integral (ln y - ln x)) {x..y}"
eberlm@62049
   322
    by (intro fundamental_theorem_of_calculus)
eberlm@62049
   323
       (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric] divide_simps
eberlm@62049
   324
             intro!: derivative_eq_intros)
eberlm@62049
   325
  hence "ln y - ln x = integral {x..y} inverse" by (simp add: integral_unique)
eberlm@62049
   326
  also have ineq: "\<forall>xa\<in>{x..y}. inverse xa \<ge> (xa - m) * f' + inverse m"
eberlm@62049
   327
  proof
eberlm@62049
   328
    fix t assume t: "t \<in> {x..y}"
eberlm@62049
   329
    from t assms have "inverse t - inverse m \<ge> f' * (t - m)"
eberlm@62049
   330
      by (intro convex_on_imp_above_tangent[of "{0<..}"] convex_on_inverse)
eberlm@62049
   331
         (auto simp: m_def interior_open f'_def power2_eq_square intro!: derivative_eq_intros)
eberlm@62049
   332
    thus "(t - m) * f' + inverse m \<le> inverse t" by (simp add: algebra_simps)
eberlm@62049
   333
  qed
eberlm@62049
   334
  hence "integral {x..y} inverse \<ge> integral {x..y} (\<lambda>t. (t - m) * f' + inverse m)"
lp15@66495
   335
    using int1 int2 by (blast intro: integral_le has_integral_integrable)
eberlm@62049
   336
  also have "integral {x..y} (\<lambda>t. (t - m) * f' + inverse m) = ?A"
eberlm@62049
   337
    using integral_unique[OF int1] by simp
eberlm@62049
   338
  finally show ?thesis .
eberlm@62049
   339
qed
eberlm@62049
   340
eberlm@62049
   341
hoelzl@63594
   342
lemma euler_mascheroni_lower:
eberlm@68643
   343
          "euler_mascheroni \<ge> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 2))"
eberlm@68643
   344
    and euler_mascheroni_upper:
eberlm@68643
   345
          "euler_mascheroni \<le> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 1))"
eberlm@62049
   346
proof -
wenzelm@63040
   347
  define D :: "_ \<Rightarrow> real"
wenzelm@63040
   348
    where "D n = inverse (of_nat (n+1)) + ln (of_nat (n+1)) - ln (of_nat (n+2))" for n
eberlm@62049
   349
  let ?g = "\<lambda>n. ln (of_nat (n+2)) - ln (of_nat (n+1)) - inverse (of_nat (n+1)) :: real"
wenzelm@63040
   350
  define inv where [abs_def]: "inv n = inverse (real_of_nat n)" for n
eberlm@62049
   351
  fix n :: nat
eberlm@63721
   352
  note summable = sums_summable[OF euler_mascheroni_sum_real, folded D_def]
eberlm@62049
   353
  have sums: "(\<lambda>k. (inv (Suc (k + (n+1))) - inv (Suc (Suc k + (n+1))))/2) sums ((inv (Suc (0 + (n+1))) - 0)/2)"
eberlm@62049
   354
    unfolding inv_def
eberlm@62049
   355
    by (intro sums_divide telescope_sums' LIMSEQ_ignore_initial_segment LIMSEQ_inverse_real_of_nat)
eberlm@62049
   356
  have sums': "(\<lambda>k. (inv (Suc (k + n)) - inv (Suc (Suc k + n)))/2) sums ((inv (Suc (0 + n)) - 0)/2)"
eberlm@62049
   357
    unfolding inv_def
eberlm@62049
   358
    by (intro sums_divide telescope_sums' LIMSEQ_ignore_initial_segment LIMSEQ_inverse_real_of_nat)
eberlm@63721
   359
  from euler_mascheroni_sum_real have "euler_mascheroni = (\<Sum>k. D k)"
eberlm@62049
   360
    by (simp add: sums_iff D_def)
eberlm@62049
   361
  also have "\<dots> = (\<Sum>k. D (k + Suc n)) + (\<Sum>k\<le>n. D k)"
lp15@66495
   362
    by (subst suminf_split_initial_segment[OF summable, of "Suc n"],
eberlm@63721
   363
        subst lessThan_Suc_atMost) simp
eberlm@62049
   364
  finally have sum: "(\<Sum>k\<le>n. D k) - euler_mascheroni = -(\<Sum>k. D (k + Suc n))" by simp
eberlm@62049
   365
eberlm@62049
   366
  note sum
eberlm@62049
   367
  also have "\<dots> \<le> -(\<Sum>k. (inv (k + Suc n + 1) - inv (k + Suc n + 2)) / 2)"
eberlm@62049
   368
  proof (intro le_imp_neg_le suminf_le allI summable_ignore_initial_segment[OF summable])
eberlm@62049
   369
    fix k' :: nat
wenzelm@63040
   370
    define k where "k = k' + Suc n"
eberlm@62049
   371
    hence k: "k > 0" by (simp add: k_def)
eberlm@62049
   372
    have "real_of_nat (k+1) > 0" by (simp add: k_def)
eberlm@62049
   373
    with ln_inverse_approx_le[OF this zero_less_one]
eberlm@62049
   374
      have "ln (of_nat k + 2) - ln (of_nat k + 1) \<le> (inv (k+1) + inv (k+2))/2"
eberlm@62049
   375
      by (simp add: inv_def add_ac)
eberlm@62049
   376
    hence "(inv (k+1) - inv (k+2))/2 \<le> inv (k+1) + ln (of_nat (k+1)) - ln (of_nat (k+2))"
eberlm@62049
   377
      by (simp add: field_simps)
eberlm@62049
   378
    also have "\<dots> = D k" unfolding D_def inv_def ..
eberlm@62049
   379
    finally show "D (k' + Suc n) \<ge> (inv (k' + Suc n + 1) - inv (k' + Suc n + 2)) / 2"
eberlm@62049
   380
      by (simp add: k_def)
hoelzl@63594
   381
    from sums_summable[OF sums]
eberlm@62049
   382
      show "summable (\<lambda>k. (inv (k + Suc n + 1) - inv (k + Suc n + 2))/2)" by simp
eberlm@62049
   383
  qed
eberlm@62049
   384
  also from sums have "\<dots> = -inv (n+2) / 2" by (simp add: sums_iff)
hoelzl@63594
   385
  finally have "euler_mascheroni \<ge> (\<Sum>k\<le>n. D k) + 1 / (of_nat (2 * (n+2)))"
eberlm@62085
   386
    by (simp add: inv_def field_simps)
eberlm@62049
   387
  also have "(\<Sum>k\<le>n. D k) = harm (Suc n) - (\<Sum>k\<le>n. ln (real_of_nat (Suc k+1)) - ln (of_nat (k+1)))"
nipkow@64267
   388
    unfolding harm_altdef D_def by (subst lessThan_Suc_atMost) (simp add:  sum.distrib sum_subtractf)
eberlm@62049
   389
  also have "(\<Sum>k\<le>n. ln (real_of_nat (Suc k+1)) - ln (of_nat (k+1))) = ln (of_nat (n+2))"
nipkow@64267
   390
    by (subst atLeast0AtMost [symmetric], subst sum_Suc_diff) simp_all
eberlm@62049
   391
  finally show "euler_mascheroni \<ge> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 2))"
eberlm@62049
   392
    by simp
hoelzl@63594
   393
eberlm@62049
   394
  note sum
eberlm@62049
   395
  also have "-(\<Sum>k. D (k + Suc n)) \<ge> -(\<Sum>k. (inv (Suc (k + n)) - inv (Suc (Suc k + n)))/2)"
eberlm@62049
   396
  proof (intro le_imp_neg_le suminf_le allI summable_ignore_initial_segment[OF summable])
eberlm@62049
   397
    fix k' :: nat
wenzelm@63040
   398
    define k where "k = k' + Suc n"
eberlm@62049
   399
    hence k: "k > 0" by (simp add: k_def)
eberlm@62049
   400
    have "real_of_nat (k+1) > 0" by (simp add: k_def)
eberlm@62049
   401
    from ln_inverse_approx_ge[of "of_nat k + 1" "of_nat k + 2"]
eberlm@62049
   402
      have "2 / (2 * real_of_nat k + 3) \<le> ln (of_nat (k+2)) - ln (real_of_nat (k+1))"
eberlm@62049
   403
      by (simp add: add_ac)
hoelzl@63594
   404
    hence "D k \<le> 1 / real_of_nat (k+1) - 2 / (2 * real_of_nat k + 3)"
eberlm@62049
   405
      by (simp add: D_def inverse_eq_divide inv_def)
eberlm@62049
   406
    also have "\<dots> = inv ((k+1)*(2*k+3))" unfolding inv_def by (simp add: field_simps)
eberlm@62049
   407
    also have "\<dots> \<le> inv (2*k*(k+1))" unfolding inv_def using k
hoelzl@63594
   408
      by (intro le_imp_inverse_le)
eberlm@62049
   409
         (simp add: algebra_simps, simp del: of_nat_add)
eberlm@62049
   410
    also have "\<dots> = (inv k - inv (k+1))/2" unfolding inv_def using k
eberlm@62049
   411
      by (simp add: divide_simps del: of_nat_mult) (simp add: algebra_simps)
eberlm@62049
   412
    finally show "D k \<le> (inv (Suc (k' + n)) - inv (Suc (Suc k' + n)))/2" unfolding k_def by simp
eberlm@62049
   413
  next
hoelzl@63594
   414
    from sums_summable[OF sums']
eberlm@62049
   415
      show "summable (\<lambda>k. (inv (Suc (k + n)) - inv (Suc (Suc k + n)))/2)" by simp
eberlm@62049
   416
  qed
eberlm@62049
   417
  also from sums' have "(\<Sum>k. (inv (Suc (k + n)) - inv (Suc (Suc k + n)))/2) = inv (n+1)/2"
eberlm@62049
   418
    by (simp add: sums_iff)
hoelzl@63594
   419
  finally have "euler_mascheroni \<le> (\<Sum>k\<le>n. D k) + 1 / of_nat (2 * (n+1))"
eberlm@62049
   420
    by (simp add: inv_def field_simps)
eberlm@62049
   421
  also have "(\<Sum>k\<le>n. D k) = harm (Suc n) - (\<Sum>k\<le>n. ln (real_of_nat (Suc k+1)) - ln (of_nat (k+1)))"
nipkow@64267
   422
    unfolding harm_altdef D_def by (subst lessThan_Suc_atMost) (simp add:  sum.distrib sum_subtractf)
eberlm@62049
   423
  also have "(\<Sum>k\<le>n. ln (real_of_nat (Suc k+1)) - ln (of_nat (k+1))) = ln (of_nat (n+2))"
nipkow@64267
   424
    by (subst atLeast0AtMost [symmetric], subst sum_Suc_diff) simp_all
eberlm@62049
   425
  finally show "euler_mascheroni \<le> harm (Suc n) - ln (real_of_nat (n + 2)) + 1/real_of_nat (2 * (n + 1))"
eberlm@62049
   426
    by simp
eberlm@62049
   427
qed
eberlm@62049
   428
eberlm@62049
   429
lemma euler_mascheroni_pos: "euler_mascheroni > (0::real)"
eberlm@62049
   430
  using euler_mascheroni_lower[of 0] ln_2_less_1 by (simp add: harm_def)
eberlm@62049
   431
eberlm@62085
   432
context
eberlm@62085
   433
begin
eberlm@62085
   434
eberlm@62085
   435
private lemma ln_approx_aux:
eberlm@62049
   436
  fixes n :: nat and x :: real
eberlm@62049
   437
  defines "y \<equiv> (x-1)/(x+1)"
eberlm@62049
   438
  assumes x: "x > 0" "x \<noteq> 1"
hoelzl@63594
   439
  shows "inverse (2*y^(2*n+1)) * (ln x - (\<Sum>k<n. 2*y^(2*k+1) / of_nat (2*k+1))) \<in>
eberlm@62049
   440
            {0..(1 / (1 - y^2) / of_nat (2*n+1))}"
eberlm@62049
   441
proof -
eberlm@62049
   442
  from x have norm_y: "norm y < 1" unfolding y_def by simp
eberlm@62049
   443
  from power_strict_mono[OF this, of 2] have norm_y': "norm y^2 < 1" by simp
eberlm@62049
   444
eberlm@62049
   445
  let ?f = "\<lambda>k. 2 * y ^ (2*k+1) / of_nat (2*k+1)"
eberlm@62049
   446
  note sums = ln_series_quadratic[OF x(1)]
wenzelm@63040
   447
  define c where "c = inverse (2*y^(2*n+1))"
eberlm@62049
   448
  let ?d = "c * (ln x - (\<Sum>k<n. ?f k))"
eberlm@62049
   449
  have "\<forall>k. y\<^sup>2^k / of_nat (2*(k+n)+1) \<le> y\<^sup>2 ^ k / of_nat (2*n+1)"
eberlm@62049
   450
    by (intro allI divide_left_mono mult_right_mono mult_pos_pos zero_le_power[of "y^2"]) simp_all
eberlm@62049
   451
  moreover {
eberlm@62049
   452
    have "(\<lambda>k. ?f (k + n)) sums (ln x - (\<Sum>k<n. ?f k))"
eberlm@62049
   453
      using sums_split_initial_segment[OF sums] by (simp add: y_def)
eberlm@62049
   454
    hence "(\<lambda>k. c * ?f (k + n)) sums ?d" by (rule sums_mult)
eberlm@62049
   455
    also have "(\<lambda>k. c * (2*y^(2*(k+n)+1) / of_nat (2*(k+n)+1))) =
eberlm@62049
   456
                   (\<lambda>k. (c * (2*y^(2*n+1))) * ((y^2)^k / of_nat (2*(k+n)+1)))"
eberlm@62049
   457
      by (simp only: ring_distribs power_add power_mult) (simp add: mult_ac)
eberlm@62049
   458
    also from x have "c * (2*y^(2*n+1)) = 1" by (simp add: c_def y_def)
eberlm@62049
   459
    finally have "(\<lambda>k. (y^2)^k / of_nat (2*(k+n)+1)) sums ?d" by simp
eberlm@62049
   460
  } note sums' = this
eberlm@62049
   461
  moreover from norm_y' have "(\<lambda>k. (y^2)^k / of_nat (2*n+1)) sums (1 / (1 - y^2) / of_nat (2*n+1))"
eberlm@62049
   462
    by (intro sums_divide geometric_sums) (simp_all add: norm_power)
eberlm@62049
   463
  ultimately have "?d \<le> (1 / (1 - y^2) / of_nat (2*n+1))" by (rule sums_le)
eberlm@62049
   464
  moreover have "c * (ln x - (\<Sum>k<n. 2 * y ^ (2 * k + 1) / real_of_nat (2 * k + 1))) \<ge> 0"
eberlm@62049
   465
    by (intro sums_le[OF _ sums_zero sums']) simp_all
eberlm@62049
   466
  ultimately show ?thesis unfolding c_def by simp
eberlm@62049
   467
qed
eberlm@62049
   468
eberlm@62049
   469
lemma
eberlm@62049
   470
  fixes n :: nat and x :: real
eberlm@62049
   471
  defines "y \<equiv> (x-1)/(x+1)"
eberlm@62049
   472
  defines "approx \<equiv> (\<Sum>k<n. 2*y^(2*k+1) / of_nat (2*k+1))"
eberlm@62049
   473
  defines "d \<equiv> y^(2*n+1) / (1 - y^2) / of_nat (2*n+1)"
eberlm@62049
   474
  assumes x: "x > 1"
eberlm@62049
   475
  shows   ln_approx_bounds: "ln x \<in> {approx..approx + 2*d}"
eberlm@62049
   476
  and     ln_approx_abs:    "abs (ln x - (approx + d)) \<le> d"
eberlm@62049
   477
proof -
wenzelm@63040
   478
  define c where "c = 2*y^(2*n+1)"
hoelzl@63594
   479
  from x have c_pos: "c > 0" unfolding c_def y_def
eberlm@62049
   480
    by (intro mult_pos_pos zero_less_power) simp_all
eberlm@62049
   481
  have A: "inverse c * (ln x - (\<Sum>k<n. 2*y^(2*k+1) / of_nat (2*k+1))) \<in>
eberlm@62049
   482
              {0.. (1 / (1 - y^2) / of_nat (2*n+1))}" using assms unfolding y_def c_def
eberlm@62049
   483
    by (intro ln_approx_aux) simp_all
eberlm@62049
   484
  hence "inverse c * (ln x - (\<Sum>k<n. 2*y^(2*k+1)/of_nat (2*k+1))) \<le> (1 / (1-y^2) / of_nat (2*n+1))"
eberlm@62049
   485
    by simp
hoelzl@63594
   486
  hence "(ln x - (\<Sum>k<n. 2*y^(2*k+1) / of_nat (2*k+1))) / c \<le> (1 / (1 - y^2) / of_nat (2*n+1))"
eberlm@62049
   487
    by (auto simp add: divide_simps)
eberlm@62049
   488
  with c_pos have "ln x \<le> c / (1 - y^2) / of_nat (2*n+1) + approx"
eberlm@62049
   489
    by (subst (asm) pos_divide_le_eq) (simp_all add: mult_ac approx_def)
eberlm@62049
   490
  moreover {
eberlm@62049
   491
    from A c_pos have "0 \<le> c * (inverse c * (ln x - (\<Sum>k<n. 2*y^(2*k+1) / of_nat (2*k+1))))"
eberlm@62049
   492
      by (intro mult_nonneg_nonneg[of c]) simp_all
hoelzl@63594
   493
    also have "\<dots> = (c * inverse c) * (ln x - (\<Sum>k<n. 2*y^(2*k+1) / of_nat (2*k+1)))"
eberlm@62049
   494
      by (simp add: mult_ac)
eberlm@62049
   495
    also from c_pos have "c * inverse c = 1" by simp
eberlm@62049
   496
    finally have "ln x \<ge> approx" by (simp add: approx_def)
eberlm@62049
   497
  }
eberlm@62049
   498
  ultimately show "ln x \<in> {approx..approx + 2*d}" by (simp add: c_def d_def)
eberlm@62049
   499
  thus "abs (ln x - (approx + d)) \<le> d" by auto
eberlm@62049
   500
qed
eberlm@62049
   501
eberlm@62049
   502
end
eberlm@62049
   503
eberlm@62049
   504
lemma euler_mascheroni_bounds:
eberlm@62049
   505
  fixes n :: nat assumes "n \<ge> 1" defines "t \<equiv> harm n - ln (of_nat (Suc n)) :: real"
eberlm@62049
   506
  shows "euler_mascheroni \<in> {t + inverse (of_nat (2*(n+1)))..t + inverse (of_nat (2*n))}"
eberlm@62049
   507
  using assms euler_mascheroni_upper[of "n-1"] euler_mascheroni_lower[of "n-1"]
eberlm@62085
   508
  unfolding t_def by (cases n) (simp_all add: harm_Suc t_def inverse_eq_divide)
eberlm@62049
   509
eberlm@62049
   510
lemma euler_mascheroni_bounds':
eberlm@62049
   511
  fixes n :: nat assumes "n \<ge> 1" "ln (real_of_nat (Suc n)) \<in> {l<..<u}"
hoelzl@63594
   512
  shows "euler_mascheroni \<in>
eberlm@62049
   513
           {harm n - u + inverse (of_nat (2*(n+1)))<..<harm n - l + inverse (of_nat (2*n))}"
eberlm@62049
   514
  using euler_mascheroni_bounds[OF assms(1)] assms(2) by auto
eberlm@62049
   515
eberlm@62085
   516
eberlm@62085
   517
text \<open>
wenzelm@69597
   518
  Approximation of \<^term>\<open>ln 2\<close>. The lower bound is accurate to about 0.03; the upper
eberlm@62085
   519
  bound is accurate to about 0.0015.
eberlm@62085
   520
\<close>
hoelzl@63594
   521
lemma ln2_ge_two_thirds: "2/3 \<le> ln (2::real)"
eberlm@62085
   522
  and ln2_le_25_over_36: "ln (2::real) \<le> 25/36"
eberlm@62085
   523
  using ln_approx_bounds[of 2 1, simplified, simplified eval_nat_numeral, simplified] by simp_all
eberlm@62085
   524
eberlm@62085
   525
eberlm@62085
   526
text \<open>
lp15@66495
   527
  Approximation of the Euler-Mascheroni constant. The lower bound is accurate to about 0.0015;
eberlm@62085
   528
  the upper bound is accurate to about 0.015.
eberlm@62085
   529
\<close>
eberlm@62085
   530
lemma euler_mascheroni_gt_19_over_33: "(euler_mascheroni :: real) > 19/33" (is ?th1)
eberlm@62085
   531
  and euler_mascheroni_less_13_over_22: "(euler_mascheroni :: real) < 13/22" (is ?th2)
eberlm@62049
   532
proof -
nipkow@65109
   533
  have "ln (real (Suc 7)) = 3 * ln 2" by (simp add: ln_powr [symmetric])
eberlm@62085
   534
  also from ln_approx_bounds[of 2 3] have "\<dots> \<in> {3*307/443<..<3*4615/6658}"
eberlm@62085
   535
    by (simp add: eval_nat_numeral)
eberlm@62085
   536
  finally have "ln (real (Suc 7)) \<in> \<dots>" .
eberlm@62085
   537
  from euler_mascheroni_bounds'[OF _ this] have "?th1 \<and> ?th2" by (simp_all add: harm_expand)
eberlm@62085
   538
  thus ?th1 ?th2 by blast+
eberlm@62049
   539
qed
eberlm@62049
   540
eberlm@62085
   541
end