Offline · exact source
Exact Lean source

YoungMultinomialLocal

formalization/Cloning/YoungMultinomialLocal.lean

Source hash: b88d0e73b3c484c470e2d829904540dfd16fbcf4eefed57154294f5a7af5e89e

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 Cloning.YoungMultinomialLocalEntropy
2import Cloning.YoungMultinomialLocalStirling
3 
4/-!
5# The multinomial local Gaussian approximation
6 
7The finite-count identities and the asymptotic estimates below concern the
8literal multinomial mass, and the Gaussian logarithm is explicit.
9-/
10 
11noncomputable section
12open scoped BigOperators Topology
13open Filter
14namespace Cloning.YoungMultinomial
15 
16/-- Logarithm of the Gaussian approximation to one lattice probability.
17The cell volume is accounted for when this mass is interpolated. -/
18def gaussianLogMass {ι : Type*} [Fintype ι] (N : ℕ) (p x : ι → ℝ) : ℝ :=
19  (1 - Fintype.card ι) / 2 * Real.log (2 * Real.pi * N) -
20    1 / 2 * (∑ i, Real.log (p i)) - ∑ i, (x i) ^ 2 / (2 * p i)
21 
22def gaussianMass {ι : Type*} [Fintype ι] (N : ℕ) (p x : ι → ℝ) : ℝ :=
23  Real.exp (gaussianLogMass N p x)
24 
25/-- Exact entropy representation of the literal multinomial mass. -/
26theorem log_multinomialMass_entropy {ι : Type*} [Fintype ι]
27    (N : ℕ) (p q : ι → ℝ) (μ : ι → ℕ) (hp : ∀ i, 0 < p i)
28    (hN : 0 < N) (hq : ∀ i, 0 < q i) (hsum : ∑ i, q i = 1)
29    (hcount : ∀ i, (μ i : ℝ) = N * q i) :
30    Real.log (multinomialMass N p μ) =
31      (1 - Fintype.card ι) / 2 * Real.log (2 * Real.pi * N) -
32      1 / 2 * (∑ i, Real.log (q i)) -
33      N * (∑ i, q i * Real.log (q i / p i)) +
34      stirlingResidual N - ∑ i, stirlingResidual (μ i) := by
35  have hn : (0 : ℝ) < N := by exact_mod_cast hN
36  have hμ : ∀ i, 0 < μ i := fun i ↦ by
37    exact_mod_cast (hcount i ▸ mul_pos hn (hq i) : (0 : ℝ) < μ i)
38  have hsμ : ∑ i, μ i = N := by
39    have hr : (∑ i, (μ i : ℝ)) = N := by
40      simp_rw [hcount]
41      rw [← Finset.mul_sum, hsum, mul_one]
42    exact_mod_cast hr
43  rw [log_multinomialMass_stirling N p μ hp hN hμ hsμ]
44  have hlogs i : Real.log (μ i : ℝ) = Real.log N + Real.log (q i) := by
45    rw [hcount, Real.log_mul hn.ne' (hq i).ne']
46  simp_rw [hlogs, hcount, Real.log_div (hq _).ne' (hp _).ne']
47  rw [Real.log_mul (mul_ne_zero (by norm_num : (2 : ℝ) ≠ 0) Real.pi_ne_zero) hn.ne']
48  have hterm i : ((N : ℝ) * q i + 1 / 2) * (Real.log N + Real.log (q i)) =
49      (N : ℝ) * Real.log N * q i + 1 / 2 * Real.log N +
50        N * (q i * Real.log (q i)) + 1 / 2 * Real.log (q i) := by ring
51  simp_rw [hterm, mul_sub]
52  simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, Finset.sum_const,
53    Finset.card_univ, nsmul_eq_mul, ← Finset.mul_sum, hsum, mul_one]
54  simp_rw [mul_assoc (N : ℝ) _ (Real.log (p _)), ← Finset.mul_sum]
55  ring
56 
57/-- Exact central-window log error, separated into an entropy error, a
58smooth prefactor change, and the proved Stirling residual. -/
59theorem central_log_error_eq {ι : Type*} [Fintype ι]
60    (N : ℕ) (p x : ι → ℝ) (μ : ι → ℕ) (hp : ∀ i, 0 < p i)
61    (hN : 0 < N) (hsum : ∑ i, p i = 1) (hzero : ∑ i, x i = 0)
62    (hq : ∀ i, 0 < p i + x i / Real.sqrt N)
63    (hcount : ∀ i, (μ i : ℝ) = N * (p i + x i / Real.sqrt N)) :
64    Real.log (multinomialMass N p μ) - gaussianLogMass N p x =
65      -(N * (∑ i, (p i + x i / Real.sqrt N) *
66          Real.log ((p i + x i / Real.sqrt N) / p i)) -
67        ∑ i, (x i) ^ 2 / (2 * p i)) -
68      1 / 2 * (∑ i, Real.log ((p i + x i / Real.sqrt N) / p i)) +
69      stirlingResidual N - ∑ i, stirlingResidual (μ i) := by
70  have hs : (∑ i, (p i + x i / Real.sqrt N)) = 1 := by
71    simp only [Finset.sum_add_distrib, div_eq_mul_inv, ← Finset.sum_mul, hsum,
72      hzero, zero_mul, add_zero]
73  rw [log_multinomialMass_entropy N p _ μ hp hN hq hs hcount, gaussianLogMass]
74  simp_rw [Real.log_div (hq _).ne' (hp _).ne', Finset.sum_sub_distrib]
75  ring
76 
77end Cloning.YoungMultinomial