File: Mathlib/Analysis/SpecialFunctions/Stirling.lean

full_name: Stirling.stirlingSeq
code: /-- Define `stirlingSeq n` as $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$.
Stirling's formula states that this sequence has limit $\sqrt(π)$.
-/
noncomputable def stirlingSeq (n : ℕ) : ℝ 
goal: ℝ

full_name: Stirling.stirlingSeq_zero
code: @[simp]
theorem stirlingSeq_zero : stirlingSeq 0 = 0 
goal: Stirling.stirlingSeq 0 = 0

full_name: Stirling.stirlingSeq_one
code: @[simp]
theorem stirlingSeq_one : stirlingSeq 1 = exp 1 / √2 
goal: Stirling.stirlingSeq 1 = rexp 1 / √2

full_name: Stirling.log_stirlingSeq_formula
code: theorem log_stirlingSeq_formula (n : ℕ) :
    log (stirlingSeq n) = Real.log n ! - 1 / 2 * Real.log (2 * n) - n * log (n / exp 1) 
goal: Real.log (Stirling.stirlingSeq n) = Real.log ↑n ! - 1 / 2 * Real.log (2 * ↑n) - ↑n * Real.log (↑n / rexp 1)

full_name: Stirling.log_stirlingSeq_diff_hasSum
code: /-- The sequence `log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))` has the series expansion
   `∑ 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`
-/
theorem log_stirlingSeq_diff_hasSum (m : ℕ) :
    HasSum (fun k : ℕ => (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ ↑(k + 1))
      (log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))) 
goal: HasSum (fun k => 1 / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ (k + 1))
  (Real.log (Stirling.stirlingSeq (m + 1)) - Real.log (Stirling.stirlingSeq (m + 2)))

full_name: Stirling.log_stirlingSeq'_antitone
code: /-- The sequence `log ∘ stirlingSeq ∘ succ` is monotone decreasing -/
theorem log_stirlingSeq'_antitone : Antitone (Real.log ∘ stirlingSeq ∘ succ) 
goal: Antitone (Real.log ∘ Stirling.stirlingSeq ∘ Nat.succ)

full_name: Stirling.log_stirlingSeq_diff_le_geo_sum
code: /-- We have a bound for successive elements in the sequence `log (stirlingSeq k)`.
-/
theorem log_stirlingSeq_diff_le_geo_sum (n : ℕ) :
    log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤
      ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) 
goal: Real.log (Stirling.stirlingSeq (n + 1)) - Real.log (Stirling.stirlingSeq (n + 2)) ≤
  (1 / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - (1 / (2 * ↑(n + 1) + 1)) ^ 2)

full_name: Stirling.log_stirlingSeq_sub_log_stirlingSeq_succ
code: /-- We have the bound `log (stirlingSeq n) - log (stirlingSeq (n+1))` ≤ 1/(4 n^2)
-/
theorem log_stirlingSeq_sub_log_stirlingSeq_succ (n : ℕ) :
    log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≤ 1 / (4 * (↑(n + 1) : ℝ) ^ 2) 
goal: Real.log (Stirling.stirlingSeq (n + 1)) - Real.log (Stirling.stirlingSeq (n + 2)) ≤ 1 / (4 * ↑(n + 1) ^ 2)

full_name: Stirling.log_stirlingSeq_bounded_aux
code: /-- For any `n`, we have `log_stirlingSeq 1 - log_stirlingSeq n ≤ 1/4 * ∑' 1/k^2`  -/
theorem log_stirlingSeq_bounded_aux :
    ∃ c : ℝ, ∀ n : ℕ, log (stirlingSeq 1) - log (stirlingSeq (n + 1)) ≤ c 
goal: ∃ c, ∀ (n : ℕ), Real.log (Stirling.stirlingSeq 1) - Real.log (Stirling.stirlingSeq (n + 1)) ≤ c

full_name: Stirling.log_stirlingSeq_bounded_by_constant
code: /-- The sequence `log_stirlingSeq` is bounded below for `n ≥ 1`. -/
theorem log_stirlingSeq_bounded_by_constant : ∃ c, ∀ n : ℕ, c ≤ log (stirlingSeq (n + 1)) 
goal: ∃ c, ∀ (n : ℕ), c ≤ Real.log (Stirling.stirlingSeq (n + 1))

full_name: Stirling.stirlingSeq'_pos
code: /-- The sequence `stirlingSeq` is positive for `n > 0`  -/
theorem stirlingSeq'_pos (n : ℕ) : 0 < stirlingSeq (n + 1) 
goal: 0 < Stirling.stirlingSeq (n + 1)

full_name: Stirling.stirlingSeq'_bounded_by_pos_constant
code: /-- The sequence `stirlingSeq` has a positive lower bound.
-/
theorem stirlingSeq'_bounded_by_pos_constant : ∃ a, 0 < a ∧ ∀ n : ℕ, a ≤ stirlingSeq (n + 1) 
goal: ∃ a, 0 < a ∧ ∀ (n : ℕ), a ≤ Stirling.stirlingSeq (n + 1)

full_name: Stirling.stirlingSeq'_antitone
code: /-- The sequence `stirlingSeq ∘ succ` is monotone decreasing -/
theorem stirlingSeq'_antitone : Antitone (stirlingSeq ∘ succ) 
goal: Antitone (Stirling.stirlingSeq ∘ Nat.succ)

full_name: Stirling.stirlingSeq_has_pos_limit_a
code: /-- The limit `a` of the sequence `stirlingSeq` satisfies `0 < a` -/
theorem stirlingSeq_has_pos_limit_a : ∃ a : ℝ, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a) 
goal: ∃ a, 0 < a ∧ Filter.Tendsto Stirling.stirlingSeq Filter.atTop (𝓝 a)

full_name: Stirling.tendsto_self_div_two_mul_self_add_one
code: /-- The sequence `n / (2 * n + 1)` tends to `1/2` -/
theorem tendsto_self_div_two_mul_self_add_one :
    Tendsto (fun n : ℕ => (n : ℝ) / (2 * n + 1)) atTop (𝓝 (1 / 2)) 
goal: Filter.Tendsto (fun n => ↑n / (2 * ↑n + 1)) Filter.atTop (𝓝 (1 / 2))

full_name: Stirling.stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq
code: /-- For any `n ≠ 0`, we have the identity
`(stirlingSeq n)^4 / (stirlingSeq (2*n))^2 * (n / (2 * n + 1)) = W n`, where `W n` is the
`n`-th partial product of Wallis' formula for `π / 2`. -/
theorem stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq (n : ℕ) (hn : n ≠ 0) :
    stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (n / (2 * n + 1)) = Wallis.W n 
goal: Stirling.stirlingSeq n ^ 4 / Stirling.stirlingSeq (2 * n) ^ 2 * (↑n / (2 * ↑n + 1)) = Real.Wallis.W n

full_name: Stirling.second_wallis_limit
code: /-- Suppose the sequence `stirlingSeq` (defined above) has the limit `a ≠ 0`.
Then the Wallis sequence `W n` has limit `a^2 / 2`.
-/
theorem second_wallis_limit (a : ℝ) (hane : a ≠ 0) (ha : Tendsto stirlingSeq atTop (𝓝 a)) :
    Tendsto Wallis.W atTop (𝓝 (a ^ 2 / 2)) 
goal: Filter.Tendsto Real.Wallis.W Filter.atTop (𝓝 (a ^ 2 / 2))

full_name: Stirling.tendsto_stirlingSeq_sqrt_pi
code: /-- **Stirling's Formula** -/
theorem tendsto_stirlingSeq_sqrt_pi : Tendsto stirlingSeq atTop (𝓝 (√π)) 
goal: Filter.Tendsto Stirling.stirlingSeq Filter.atTop (𝓝 √π)

full_name: Stirling.factorial_isEquivalent_stirling
code: /-- **Stirling's Formula**, formulated in terms of `Asymptotics.IsEquivalent`. -/
lemma factorial_isEquivalent_stirling :
    (fun n ↦ n ! : ℕ → ℝ) ~[atTop] fun n ↦ Real.sqrt (2 * n * π) * (n / exp 1) ^ n 
goal: (fun n => ↑n !) ~[Filter.atTop] fun n => √(2 * ↑n * π) * (↑n / rexp 1) ^ n