Theorem: Stirling.log_stirlingSeq_diff_hasSum
File: Mathlib/Analysis/SpecialFunctions/Stirling.lean

tactic: let f (k : ℕ) := (1 : ℝ) / (2 * k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
state_before: m : ℕ
⊢ HasSum (fun k => 1 / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ (k + 1))
    (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)))
state_after: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ HasSum (fun k => 1 / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ (k + 1))
    (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)))

tactic: change HasSum (fun k => f (k + 1)) _
state_before: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ HasSum (fun k => 1 / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ (k + 1))
    (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)))
state_after: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ HasSum (fun k => f (k + 1)) (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)))

tactic: rw [hasSum_nat_add_iff]
state_before: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ HasSum (fun k => f (k + 1)) (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)))
state_after: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ HasSum f (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)) + ∑ i ∈ range 1, f i)

tactic: convert (hasSum_log_one_add_inv m.cast_add_one_pos).mul_left ((↑(m + 1) : ℝ) + 1 / 2) using 1
state_before: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ HasSum f (Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)) + ∑ i ∈ range 1, f i)
state_after: case h.e'_5
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ f = fun i => (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑i + 1)) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * i + 1))

case h.e'_6
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)) + ∑ i ∈ range 1, f i =
    (↑(m + 1) + 1 / 2) * Real.log (1 + (↑m + 1)⁻¹)

tactic: ext k
state_before: case h.e'_5
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ f = fun i => (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑i + 1)) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * i + 1))
state_after: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ f k = (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k + 1))

tactic: dsimp only [f]
state_before: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ f k = (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k + 1))
state_after: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k =
    (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k + 1))

tactic: rw [← pow_mul, pow_add]
state_before: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k =
    (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k + 1))
state_after: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * ↑(m + 1) + 1)) ^ (2 * k) =
    (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))

tactic: push_cast
state_before: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * ↑(m + 1) + 1)) ^ (2 * k) =
    (↑(m + 1) + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))
state_after: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k) =
    (↑m + 1 + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))

tactic: field_simp
state_before: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ 1 / (2 * ↑k + 1) * (1 / (2 * (↑m + 1) + 1)) ^ (2 * k) =
    (↑m + 1 + 1 / 2) * (2 * (1 / (2 * ↑k + 1)) * ((1 / (2 * (↑m + 1) + 1)) ^ (2 * k) * (1 / (2 * (↑m + 1) + 1)) ^ 1))
state_after: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ (2 * ↑k + 1) * ((2 * (↑m + 1) + 1) ^ (2 * k) * (2 * (↑m + 1) + 1)) =
    ((↑m + 1) * 2 + 1) * ((2 * ↑k + 1) * (2 * (↑m + 1) + 1) ^ (2 * k))

tactic: ring
state_before: case h.e'_5.h
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
k : ℕ
⊢ (2 * ↑k + 1) * ((2 * (↑m + 1) + 1) ^ (2 * k) * (2 * (↑m + 1) + 1)) =
    ((↑m + 1) * 2 + 1) * ((2 * ↑k + 1) * (2 * (↑m + 1) + 1) ^ (2 * k))
state_after: no goals

tactic: have h : ∀ x ≠ (0 : ℝ), 1 + x⁻¹ = (x + 1) / x := fun x hx ↦ by field_simp [hx]
state_before: case h.e'_6
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
⊢ Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)) + ∑ i ∈ range 1, f i =
    (↑(m + 1) + 1 / 2) * Real.log (1 + (↑m + 1)⁻¹)
state_after: case h.e'_6
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
h : ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
⊢ Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)) + ∑ i ∈ range 1, f i =
    (↑(m + 1) + 1 / 2) * Real.log (1 + (↑m + 1)⁻¹)

tactic: simp (disch := positivity) only [log_stirlingSeq_formula, log_div, log_mul, log_exp,
  factorial_succ, cast_mul, cast_succ, cast_zero, range_one, sum_singleton, h]
state_before: case h.e'_6
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
h : ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
⊢ Real.log (stirlingSeq (m + 1)) - Real.log (stirlingSeq (m + 2)) + ∑ i ∈ range 1, f i =
    (↑(m + 1) + 1 / 2) * Real.log (1 + (↑m + 1)⁻¹)
state_after: case h.e'_6
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
h : ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
⊢ Real.log (↑m + 1) + Real.log ↑m ! - 1 / 2 * (Real.log 2 + Real.log (↑m + 1)) - (↑m + 1) * (Real.log (↑m + 1) - 1) -
        (Real.log (↑m + 1 + 1) + (Real.log (↑m + 1) + Real.log ↑m !) - 1 / 2 * (Real.log 2 + Real.log (↑m + 1 + 1)) -
          (↑m + 1 + 1) * (Real.log (↑m + 1 + 1) - 1)) +
      f 0 =
    (↑m + 1 + 1 / 2) * (Real.log (↑m + 1 + 1) - Real.log (↑m + 1))

tactic: ring
state_before: case h.e'_6
m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
h : ∀ (x : ℝ), x ≠ 0 → 1 + x⁻¹ = (x + 1) / x
⊢ Real.log (↑m + 1) + Real.log ↑m ! - 1 / 2 * (Real.log 2 + Real.log (↑m + 1)) - (↑m + 1) * (Real.log (↑m + 1) - 1) -
        (Real.log (↑m + 1 + 1) + (Real.log (↑m + 1) + Real.log ↑m !) - 1 / 2 * (Real.log 2 + Real.log (↑m + 1 + 1)) -
          (↑m + 1 + 1) * (Real.log (↑m + 1 + 1) - 1)) +
      f 0 =
    (↑m + 1 + 1 / 2) * (Real.log (↑m + 1 + 1) - Real.log (↑m + 1))
state_after: no goals

tactic: field_simp [hx]
state_before: m : ℕ
f : ℕ → ℝ := fun k => 1 / (2 * ↑k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
x : ℝ
hx : x ≠ 0
⊢ 1 + x⁻¹ = (x + 1) / x
state_after: no goals