Offline · exact source
Exact Lean source

YoungMultinomialLocalStirling

formalization/Cloning/YoungMultinomialLocalStirling.lean

Source hash: 09bb63434ca302bbb8db33e35442c243db9cbd97182d434f9d917abed74d12c9

Full source copied without mathematical changes from the snapshot whose input hash matches the passing audit. Select a line number for a stable source pointer.

The declarations belong to the compiled inventory covered by the project’s shared axiom audit. That audit records an aggregate union, without attributing axioms to individual declarations.

Declarations in this module
1import Mathlib.Analysis.SpecialFunctions.Stirling
2import Mathlib.Analysis.SpecialFunctions.Log.Deriv
3import Mathlib.Topology.Instances.Nat
4 
5/-!
6# Exact factorial mass and vanishing Stirling remainders
7 
8These identities concern the literal factorial multinomial mass. The residual
9is obtained from Mathlib's proved Stirling formula.
10-/
11 
12noncomputable section
13open scoped BigOperators Topology
14open Filter
15namespace Cloning.YoungMultinomial
16 
17/-- The logarithmic Stirling residual. -/
18def stirlingResidual (n : ℕ) : ℝ :=
19  Real.log (Stirling.stirlingSeq n) - Real.log (Real.sqrt Real.pi)
20 
21theorem stirlingResidual_tendsto_zero : Tendsto stirlingResidual atTop (𝓝 0) := by
22  simpa [stirlingResidual] using
23    (Real.continuousAt_log (by positivity : Real.sqrt Real.pi ≠ 0)).tendsto.comp
24      Stirling.tendsto_stirlingSeq_sqrt_pi |>.sub_const (Real.log (Real.sqrt Real.pi))
25 
26/-- Every coordinate that grows at least linearly has vanishing residual,
27with no convergence assumption on its normalized count. -/
28theorem stirlingResidual_tendsto_of_lower_bound (m : ℕ → ℕ) (a : ℝ) (ha : 0 < a)
29    (hm : ∀ᶠ N : ℕ in atTop, a * (N : ℝ) ≤ (m N : ℝ)) :
30    Tendsto (fun N ↦ stirlingResidual (m N)) atTop (𝓝 0) := by
31  have hr : Tendsto (fun N ↦ (m N : ℝ)) atTop atTop :=
32    tendsto_atTop_mono' atTop hm (tendsto_natCast_atTop_atTop.const_mul_atTop ha)
33  exact stirlingResidual_tendsto_zero.comp (tendsto_natCast_atTop_iff.mp hr)
34 
35/-- The exact logarithmic factorial decomposition, for every positive count. -/
36theorem log_factorial_eq (n : ℕ) (hn : 0 < n) :
37    Real.log (n.factorial : ℝ) =
38      ((n : ℝ) + 1 / 2) * Real.log n - n +
39        1 / 2 * Real.log (2 * Real.pi) + stirlingResidual n := by
40  have hn0 : (n : ℝ) ≠ 0 := by positivity
41  have h := Stirling.log_stirlingSeq_formula n
42  rw [Real.log_div hn0 (Real.exp_ne_zero 1), Real.log_exp,
43    Real.log_mul (by norm_num : (2 : ℝ) ≠ 0) hn0] at h
44  rw [stirlingResidual, Real.log_sqrt (by positivity),
45    Real.log_mul (by norm_num : (2 : ℝ) ≠ 0) Real.pi_ne_zero]
46  linarith
47 
48/-- The actual multinomial probability mass. -/
49def multinomialMass {ι : Type*} [Fintype ι] (N : ℕ) (p : ι → ℝ) (μ : ι → ℕ) : ℝ :=
50  (N.factorial : ℝ) * (∏ i, p i ^ μ i) / ∏ i, ((μ i).factorial : ℝ)
51 
52theorem multinomialMass_pos {ι : Type*} [Fintype ι] (N : ℕ)
53    (p : ι → ℝ) (μ : ι → ℕ) (hp : ∀ i, 0 < p i) :
54    0 < multinomialMass N p μ := by
55  unfold multinomialMass
56  exact div_pos (mul_pos (by positivity) (Finset.prod_pos fun i _ ↦ pow_pos (hp i) _))
57    (Finset.prod_pos fun i _ ↦ by positivity)
58 
59/-- Exact logarithm of the factorial formula. -/
60theorem log_multinomialMass {ι : Type*} [Fintype ι] (N : ℕ)
61    (p : ι → ℝ) (μ : ι → ℕ) (hp : ∀ i, 0 < p i) :
62    Real.log (multinomialMass N p μ) =
63      Real.log (N.factorial : ℝ) + (∑ i, (μ i : ℝ) * Real.log (p i)) -
64        ∑ i, Real.log ((μ i).factorial : ℝ) := by
65  have hprod : (∏ i, p i ^ μ i) ≠ 0 := Finset.prod_ne_zero_iff.mpr
66    (fun i _ ↦ pow_ne_zero _ (hp i).ne')
67  rw [multinomialMass, Real.log_div (mul_ne_zero (by positivity) hprod) (by positivity),
68    Real.log_mul (by positivity) hprod,
69    Real.log_prod (fun i _ ↦ pow_ne_zero _ (hp i).ne'), Real.log_prod (fun i _ ↦ by positivity)]
70  simp only [Real.log_pow]
71 
72/-- Fully expanded multinomial logarithm with a genuine vanishing Stirling
73residual and no unproved asymptotic estimate. -/
74theorem log_multinomialMass_stirling {ι : Type*} [Fintype ι] (N : ℕ)
75    (p : ι → ℝ) (μ : ι → ℕ) (hp : ∀ i, 0 < p i)
76    (hN : 0 < N) (hμ : ∀ i, 0 < μ i) (hsum : ∑ i, μ i = N) :
77    Real.log (multinomialMass N p μ) =
78      ((N : ℝ) + 1 / 2) * Real.log N -
79      (∑ i, ((μ i : ℝ) + 1 / 2) * Real.log (μ i)) +
80      (∑ i, (μ i : ℝ) * Real.log (p i)) +
81      (1 - Fintype.card ι) / 2 * Real.log (2 * Real.pi) +
82      stirlingResidual N - ∑ i, stirlingResidual (μ i) := by
83  rw [log_multinomialMass N p μ hp, log_factorial_eq N hN]
84  simp_rw [log_factorial_eq _ (hμ _)]
85  simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, Finset.sum_const,
86    Finset.card_univ, nsmul_eq_mul]
87  have hs : (∑ i, (μ i : ℝ)) = N := by exact_mod_cast hsum
88  rw [hs]
89  ring
90 
91end Cloning.YoungMultinomial