File size: 6,222 Bytes
a0b506f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/-
  Step 2 (iteration 1): summability of the digamma series, no hypothesis on s.
  term s n = 1/(n+1) - 1/(n+s).  For large n the closed form (s-1)/((n+1)(n+s)) is O(n^-2).
-/
import Mathlib

namespace DigammaSeries2

open Complex Filter Topology

theorem cast_add_one_ne_zero (n : ℕ) : ((n : ℂ) + 1) ≠ 0 := by
  have h : ((n : ℂ) + 1) = ((n + 1 : ℕ) : ℂ) := by push_cast; ring
  rw [h, Ne, Nat.cast_eq_zero]
  omega

noncomputable def term (s : ℂ) (n : ℕ) : ℂ := 1 / (n + 1) - 1 / (n + s)

theorem term_eq (s : ℂ) (n : ℕ) (h : (n : ℂ) + s ≠ 0) :
    term s n = (s - 1) / (((n : ℂ) + 1) * ((n : ℂ) + s)) := by
  have h1 : ((n : ℂ) + 1) ≠ 0 := cast_add_one_ne_zero n
  simp only [term]
  field_simp
  ring

theorem norm_term_le (s : ℂ) (n : ℕ) (hn : Nat.ceil (2 * ‖s‖) + 1 ≤ n) :
    ‖term s n‖ ≤ (2 * ‖s - 1‖) * (1 / (n : ℝ) ^ 2) := by
  have hn1' : (1 : ℕ) ≤ n := le_trans (Nat.le_add_left 1 _) hn
  have hn0 : (0 : ℝ) < n := by exact_mod_cast hn1'
  have h2s : 2 * ‖s‖ ≤ n := by
    have h1 := Nat.le_ceil (2 * ‖s‖)
    have h2 : ((Nat.ceil (2 * ‖s‖) : ℕ) : ℝ) ≤ n := by
      exact_mod_cast (le_trans (Nat.le_succ _) hn)
    linarith
  have hnorm : ‖(n : ℂ)‖ = n := by simp
  have hns : (n : ℝ) / 2 ≤ ‖(n : ℂ) + s‖ := by
    have h1 : ‖(n : ℂ)‖ - ‖-s‖ ≤ ‖(n : ℂ) - (-s)‖ := norm_sub_norm_le _ _
    rw [norm_neg, sub_neg_eq_add, hnorm] at h1
    linarith
  have hn1 : (n : ℝ) ≤ ‖(n : ℂ) + 1‖ := by
    have h : ((n : ℂ) + 1) = ((n + 1 : ℕ) : ℂ) := by push_cast; ring
    rw [h, Complex.norm_natCast]
    push_cast
    linarith
  have hne : (n : ℂ) + s ≠ 0 := by
    intro h
    rw [h, norm_zero] at hns
    linarith
  have hprod : (n : ℝ) ^ 2 / 2 ≤ ‖(n : ℂ) + 1‖ * ‖(n : ℂ) + s‖ := by
    have : (n : ℝ) * ((n : ℝ) / 2) ≤ ‖(n : ℂ) + 1‖ * ‖(n : ℂ) + s‖ :=
      mul_le_mul hn1 hns (by positivity) (norm_nonneg _)
    nlinarith [this]
  have hpos : 0 < ‖(n : ℂ) + 1‖ * ‖(n : ℂ) + s‖ := lt_of_lt_of_le (by positivity) hprod
  rw [term_eq s n hne, norm_div, norm_mul, div_le_iff₀ hpos]
  have hk : ‖s - 1‖ = (2 * ‖s - 1‖) * (1 / (n : ℝ) ^ 2) * ((n : ℝ) ^ 2 / 2) := by
    field_simp
  calc ‖s - 1‖ = (2 * ‖s - 1‖) * (1 / (n : ℝ) ^ 2) * ((n : ℝ) ^ 2 / 2) := hk
    _ ≤ (2 * ‖s - 1‖) * (1 / (n : ℝ) ^ 2) * (‖(n : ℂ) + 1‖ * ‖(n : ℂ) + s‖) := by
        apply mul_le_mul_of_nonneg_left hprod
        positivity

/-- Summability of the digamma series for every complex `s` (Lean's `1/0 = 0` makes the
pole terms harmless, so no hypothesis is needed). -/
theorem summable_term (s : ℂ) : Summable (term s) := by
  have hsum : Summable (fun n : ℕ => (2 * ‖s - 1‖) * (1 / (n : ℝ) ^ 2)) :=
    (Real.summable_one_div_nat_pow.mpr (by norm_num)).mul_left _
  refine Summable.of_norm_bounded_eventually_nat hsum ?_
  filter_upwards [eventually_ge_atTop (Nat.ceil (2 * ‖s‖) + 1)] with n hn
  exact norm_term_le s n hn

theorem term_add_one_sub (s : ℂ) (n : ℕ) :
    term (s + 1) n - term s n = 1 / ((n : ℂ) + s) - 1 / ((n : ℂ) + 1 + s) := by
  simp only [term]
  have h : ((n : ℂ) + (s + 1)) = ((n : ℂ) + 1 + s) := by ring
  rw [h]
  ring

theorem tendsto_one_div_nat_add (s : ℂ) :
    Tendsto (fun n : ℕ => 1 / ((n : ℂ) + s)) atTop (𝓝 0) := by
  refine squeeze_zero_norm' ?_ (tendsto_const_div_atTop_nhds_zero_nat 2)
  filter_upwards [eventually_ge_atTop (Nat.ceil (2 * ‖s‖) + 1)] with n hn
  have hn1' : (1 : ℕ) ≤ n := le_trans (Nat.le_add_left 1 _) hn
  have hn0 : (0 : ℝ) < n := by exact_mod_cast hn1'
  have h2s : 2 * ‖s‖ ≤ n := by
    have h1 := Nat.le_ceil (2 * ‖s‖)
    have h2 : ((Nat.ceil (2 * ‖s‖) : ℕ) : ℝ) ≤ n := by
      exact_mod_cast (le_trans (Nat.le_succ _) hn)
    linarith
  have hnorm : ‖(n : ℂ)‖ = n := by simp
  have hns : (n : ℝ) / 2 ≤ ‖(n : ℂ) + s‖ := by
    have h1 : ‖(n : ℂ)‖ - ‖-s‖ ≤ ‖(n : ℂ) - (-s)‖ := norm_sub_norm_le _ _
    rw [norm_neg, sub_neg_eq_add, hnorm] at h1
    linarith
  have hpos : 0 < ‖(n : ℂ) + s‖ := lt_of_lt_of_le (by positivity) hns
  rw [norm_div, norm_one, div_le_div_iff₀ hpos hn0]
  linarith

/-- The functional equation of the series: the same recurrence as `Complex.digamma_apply_add_one`. -/
theorem tsum_term_add_one (s : ℂ) :
    ∑' n, term (s + 1) n = ∑' n, term s n + 1 / s := by
  have hd : HasSum (fun n => term (s + 1) n - term s n) (∑' n, term (s + 1) n - ∑' n, term s n) :=
    (summable_term (s + 1)).hasSum.sub (summable_term s).hasSum
  have hstep : ∀ n : ℕ, term (s + 1) n - term s n
      = 1 / ((n : ℂ) + s) - 1 / (((n + 1 : ℕ) : ℂ) + s) := by
    intro n
    rw [term_add_one_sub, Nat.cast_succ]
  have hfun : (fun N : ℕ => ∑ n ∈ Finset.range N, (term (s + 1) n - term s n))
      = fun N : ℕ => 1 / (((0 : ℕ) : ℂ) + s) - 1 / ((N : ℂ) + s) := by
    funext N
    simp_rw [hstep]
    exact Finset.sum_range_sub' (fun n : ℕ => 1 / ((n : ℂ) + s)) N
  have ht : Tendsto (fun N : ℕ => ∑ n ∈ Finset.range N, (term (s + 1) n - term s n)) atTop
      (𝓝 (1 / s)) := by
    rw [hfun]
    have h := (tendsto_const_nhds (x := (1 : ℂ) / s)).sub (tendsto_one_div_nat_add s)
    simpa using h
  have key := tendsto_nhds_unique hd.tendsto_sum_nat ht
  linear_combination key

noncomputable def digammaSeries (s : ℂ) : ℂ :=
  -(Real.eulerMascheroniConstant : ℂ) + ∑' n : ℕ, term s n

/-- The series obeys the digamma recurrence, for every `s`. -/
theorem digammaSeries_add_one (s : ℂ) : digammaSeries (s + 1) = digammaSeries s + 1 / s := by
  simp only [digammaSeries, tsum_term_add_one]
  ring

/-- Hence the difference `digamma - digammaSeries` is 1-periodic away from the poles. -/
theorem diff_periodic (s : ℂ) (hs : ∀ m : ℕ, s ≠ -m) :
    Complex.digamma (s + 1) - digammaSeries (s + 1) = Complex.digamma s - digammaSeries s := by
  rw [Complex.digamma_apply_add_one s hs, digammaSeries_add_one, one_div]
  ring

end DigammaSeries2

#print axioms DigammaSeries2.summable_term
#print axioms DigammaSeries2.digammaSeries_add_one
#print axioms DigammaSeries2.diff_periodic