Offline · exact source
Exact Lean source

CountMultinomialPMF

formalization/Cloning/CountMultinomialPMF.lean

Source hash: abfb688fd4000c5432fc8c9f3a1c59865872e9355f32dfacf5812fbb9b0b5dd5

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.GeneralCoherentMultiplicity
2import Cloning.YoungUniformLocalPhysicalLattice
3import Cloning.YoungMultinomialLocalStirling
4 
5/-! The actual independent-word count PMF and its exact factorial multinomial mass. -/
6noncomputable section
7open scoped BigOperators Topology Classical
8open Filter MeasureTheory
9namespace Cloning.CountMultinomial
10open Cloning.YoungGeneral Cloning.GeneralSymmetricOccupation Cloning.YoungHyperplane Cloning.YoungMultinomial
11set_option backward.isDefEq.respectTransparency false
12set_option maxHeartbeats 1400000
13 
14def wordPMF (d N : ℕ) (p : Fin d → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i=1) :
15    PMF (Word N d) :=
16  PMF.ofFintype (fun w ↦ ENNReal.ofReal (wordWeight p w)) (by
17    rw [← ENNReal.ofReal_sum_of_nonneg (fun w _ ↦ wordWeight_nonneg p hp w),
18      wordWeight_sum p hs, ENNReal.ofReal_one])
19 
20theorem wordPMF_toReal (d N : ℕ) (p : Fin d → ℝ) (hp : ∀ i, 0 ≤ p i)
21    (hs : ∑ i, p i=1) (w : Word N d) : (wordPMF d N p hp hs w).toReal=wordWeight p w := by
22  simp only [wordPMF, PMF.ofFintype_apply, ENNReal.toReal_ofReal (wordWeight_nonneg p hp w)]
23 
24def countShape {d N : ℕ} (w : Word N d) : Shape d N := fun i ↦
25  ⟨profile w i, Nat.lt_succ_of_le (by
26    have hh := Finset.single_le_sum (fun j (_ : j∈Finset.univ) ↦ Nat.zero_le (profile w j))
27      (Finset.mem_univ i)
28    simpa only [profile_sum] using hh)⟩
29 
30theorem countShape_sum {d N : ℕ} (w : Word N d) : ∑ i, (countShape w i).val=N :=
31  profile_sum w
32 
33theorem profile_eq_rowCount {d N : ℕ} (w : Word N d) (i : Fin d) : profile w i=rowCount w i := by
34  simp only [profile, rowCount, Fintype.card_subtype]
35 
36theorem countShape_eq_iff {d N : ℕ} (w : Word N d) (μ : Shape d N) :
37    countShape w=μ ↔ profile w=(fun i ↦ (μ i).val) := by
38  constructor
39  · intro h; exact congrArg (fun z : Shape d N ↦ fun i ↦ (z i).val) h
40  · intro h; funext i; exact Fin.ext (congrFun h i)
41 
42def countPMF (d N : ℕ) (p : Fin d → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i=1) :
43    PMF (Shape d N) := (wordPMF d N p hp hs).map countShape
44 
45theorem countPMF_eq_sum (d N : ℕ) (p : Fin d → ℝ) (hp : ∀ i, 0 ≤ p i)
46    (hs : ∑ i, p i=1) (μ : Shape d N) :
47    (countPMF d N p hp hs μ).toReal=
48      ∑ w : Word N d, if countShape w=μ then wordWeight p w else 0 := by
49  rw [countPMF, PMF.map_apply, tsum_fintype, ENNReal.toReal_sum]
50  · apply Finset.sum_congr rfl
51    intro w _
52    by_cases hw : countShape w=μ
53    · simp only [hw, if_pos, wordPMF_toReal]
54    · simp only [Ne.symm hw, hw, if_false, ENNReal.toReal_zero]
55  · intro w _
56    split_ifs
57    · exact PMF.apply_ne_top _ _
58    · exact ENNReal.zero_ne_top
59 
60theorem countPMF_eq_zero_of_sum {d N : ℕ} (p : Fin d → ℝ) (hp : ∀ i, 0 ≤ p i)
61    (hs : ∑ i, p i=1) (μ : Shape d N) (hμ : (∑ i, (μ i).val)≠N) :
62    countPMF d N p hp hs μ=0 := by
63  rw [countPMF, PMF.map_apply, tsum_fintype]
64  apply Finset.sum_eq_zero
65  intro w _
66  have hw : μ≠countShape w := by intro h; exact hμ (h ▸ countShape_sum w)
67  simp only [hw, if_false]
68 
69/-- This is the actual count law of independent letters, including its literal factorial weight. -/
70theorem countPMF_formula (d N : ℕ) (p : Fin d → ℝ) (hp : ∀ i, 0 ≤ p i)
71    (hs : ∑ i, p i=1) (μ : Shape d N) (hμ : ∑ i, (μ i).val=N) :
72    (countPMF d N p hp hs μ).toReal=multinomialMass N p (fun i ↦ (μ i).val) := by
73  let q : Occupation N d := ⟨fun i ↦ (μ i).val, exists_word_of_sum _ hμ⟩
74  have he w : countShape w=μ ↔ label w=q := by
75    rw [countShape_eq_iff]
76    exact ⟨fun h ↦ Subtype.ext h, fun h ↦ congrArg Subtype.val h⟩
77  have hweight w (hw : countShape w=μ) : wordWeight p w=∏ i, p i^(μ i).val := by
78    rw [wordWeight_eq_row_product]
79    apply Finset.prod_congr rfl
80    intro i _
81    rw [← profile_eq_rowCount, congrFun ((countShape_eq_iff w μ).mp hw) i]
82  rw [countPMF_eq_sum]
83  have hsum : (∑ w : Word N d, if countShape w=μ then wordWeight p w else 0)=
84      (multiplicity q : ℝ)*(∏ i, p i^(μ i).val) := by
85    calc
86      _ = ∑ w : Word N d, if label w=q then (∏ i, p i^(μ i).val) else 0 := by
87        apply Finset.sum_congr rfl
88        intro w _
89        by_cases hw : countShape w=μ
90        · simp only [hw, (he w).mp hw, if_pos, hweight w hw]
91        · simp only [hw, (he w).not.mp hw, if_false]
92      _ = _ := by simp only [← Finset.sum_filter, Finset.sum_const, nsmul_eq_mul, GeneralSymmetricOccupation.multiplicity]
93  rw [hsum]
94  have hm := multiplicity_mul_factorials q
95  have hmr : (multiplicity q : ℝ)*(∏ i, ((μ i).val.factorial : ℝ))=(N.factorial : ℝ) := by
96    exact_mod_cast hm
97  have hf : (∏ i, ((μ i).val.factorial : ℝ))≠0 := by positivity
98  unfold multinomialMass
99  apply (eq_div_iff hf).mpr
100  rw [mul_assoc, mul_comm (∏ i, p i^(μ i).val), ← mul_assoc, hmr]
101 
102end Cloning.CountMultinomial