Download data/lean/OAI/Combinatorics/ExpectationThreshold/SelectorCountingWords.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 5.56 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ExpectationThreshold/SelectorCountingWords.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/ExpectationThreshold/SelectorCountingWords.lean
-
curl -L -o SelectorCountingWords.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/ExpectationThreshold/SelectorCountingWords.lean
5.56 kB
| import Mathlib.Algebra.BigOperators.Ring.Finset | |
| import Mathlib.Algebra.Order.BigOperators.Group.Finset | |
| import Mathlib.Algebra.Order.BigOperators.GroupWithZero.Finset | |
| import Mathlib.Data.Fintype.Pi | |
| import Mathlib.Basic.Real.Basic | |
| namespace OAI | |
| /-! | |
| # Counting finite words by their color profiles | |
| The coefficient attached to a profile is the actual cardinality of its fiber | |
| among finite words. Regrouping the weighted sum over words proves the finite | |
| multinomial identity without introducing a factorial formula or a counting | |
| hypothesis. | |
| -/ | |
| namespace TalagrandThreshold | |
| open scoped BigOperators | |
| /-- The number of positions of each color in a word on a finite domain. -/ | |
| def wordProfile {D H : Type*} [Fintype D] [DecidableEq H] (f : D β H) (h : H) : β := | |
| (Finset.univ.filter fun i => f i = h).card | |
| /-- All words on a fixed finite domain having the specified profile. -/ | |
| def wordFiber (D : Type*) {H : Type*} [Fintype D] [DecidableEq D] | |
| [Fintype H] [DecidableEq H] (n : H β β) : Finset (D β H) := | |
| Finset.univ.filter fun f => wordProfile f = n | |
| /-- The concrete multinomial coefficient, defined as a finite fiber cardinality. -/ | |
| def wordCount {H : Type*} [Fintype H] [DecidableEq H] (t : β) (n : H β β) : β := | |
| (wordFiber (Fin t) n).card | |
| /-- The finite set of profiles attained by words of length `t`. -/ | |
| def wordProfiles (H : Type*) [Fintype H] [DecidableEq H] (t : β) : Finset (H β β) := | |
| Finset.univ.image (fun f : Fin t β H => wordProfile f) | |
| variable {H : Type*} [Fintype H] [DecidableEq H] | |
| @[simp] theorem mem_wordFiber (D : Type*) [Fintype D] [DecidableEq D] | |
| (n : H β β) (f : D β H) : f β wordFiber D n β wordProfile f = n := by | |
| simp only [wordFiber, Finset.mem_filter, Finset.mem_univ, true_and] | |
| theorem mem_wordProfiles_iff (t : β) (n : H β β) : | |
| n β wordProfiles H t β β f : Fin t β H, wordProfile f = n := by | |
| simp only [wordProfiles, Finset.mem_image, Finset.mem_univ, true_and] | |
| theorem sum_wordProfile {D : Type*} [Fintype D] (f : D β H) : | |
| (β h, wordProfile f h) = Fintype.card D := by | |
| simpa only [wordProfile, Finset.mem_univ, Finset.filter_true, Finset.card_univ] using | |
| (Finset.sum_card_fiberwise_eq_card_filter (Finset.univ : Finset D) Finset.univ f) | |
| theorem wordCount_eq_zero_of_not_mem_wordProfiles (t : β) (n : H β β) | |
| (hn : n β wordProfiles H t) : wordCount t n = 0 := by | |
| unfold wordCount wordFiber | |
| apply Finset.card_eq_zero.mpr | |
| apply Finset.filter_eq_empty_iff.mpr | |
| intro f _ hf | |
| exact hn ((mem_wordProfiles_iff t n).mpr β¨f, hfβ©) | |
| /-- The weight from a profile equals the product of the individual letter weights. -/ | |
| theorem prod_weight_wordProfile {D : Type*} [Fintype D] | |
| (f : D β H) (Ο : H β β) : | |
| (β h, Ο h ^ wordProfile f h) = β i, Ο (f i) := by | |
| simpa only [wordProfile, Finset.prod_const] using | |
| (Finset.prod_fiberwise' (Finset.univ : Finset D) f Ο) | |
| /-- The multinomial identity obtained by grouping actual words by their profile. -/ | |
| theorem sum_wordCount_weight (t : β) (Ο : H β β) : | |
| (β n β wordProfiles H t, (wordCount t n : β) * β h, Ο h ^ n h) = | |
| (β h, Ο h) ^ t := by | |
| have hgroup : (β f : Fin t β H, β h, Ο h ^ wordProfile f h) = | |
| β n β wordProfiles H t, (wordCount t n : β) * β h, Ο h ^ n h := by | |
| simpa only [wordProfiles, wordCount, wordFiber, nsmul_eq_mul] using | |
| (Finset.sum_comp (s := (Finset.univ : Finset (Fin t β H))) | |
| (fun n : H β β => β h, Ο h ^ n h) (fun f : Fin t β H => wordProfile f)) | |
| calc | |
| _ = β f : Fin t β H, β h, Ο h ^ wordProfile f h := hgroup.symm | |
| _ = β f : Fin t β H, β i, Ο (f i) := by | |
| apply Finset.sum_congr rfl | |
| intro f _ | |
| exact prod_weight_wordProfile f Ο | |
| _ = (β h, Ο h) ^ t := (Fintype.sum_pow Ο t).symm | |
| theorem wordCount_weight_nonneg (t : β) (Ο : H β β) (hΟ : β h, 0 β€ Ο h) | |
| (n : H β β) : 0 β€ (wordCount t n : β) * β h, Ο h ^ n h := | |
| mul_nonneg (Nat.cast_nonneg _) (Finset.prod_nonneg fun h _ => pow_nonneg (hΟ h) _) | |
| theorem sum_wordCount_weight_le_one (t : β) (Ο : H β β) (hΟ : β h, 0 β€ Ο h) | |
| (hΟsum : (β h, Ο h) β€ 1) : | |
| (β n β wordProfiles H t, (wordCount t n : β) * β h, Ο h ^ n h) β€ 1 := by | |
| rw [sum_wordCount_weight] | |
| exact pow_le_oneβ (Finset.sum_nonneg fun h _ => hΟ h) hΟsum | |
| /-- Any finite collection of profiles has total weight at most one, including | |
| profiles not attained by a word: their fiber counts are zero. -/ | |
| theorem sum_wordCount_weight_finset_le_one (t : β) (E : Finset (H β β)) | |
| (Ο : H β β) (hΟ : β h, 0 β€ Ο h) (hΟsum : (β h, Ο h) β€ 1) : | |
| (β n β E, (wordCount t n : β) * β h, Ο h ^ n h) β€ 1 := by | |
| classical | |
| have hrestrict : | |
| (β n β E β© wordProfiles H t, (wordCount t n : β) * β h, Ο h ^ n h) = | |
| β n β E, (wordCount t n : β) * β h, Ο h ^ n h := by | |
| apply Finset.sum_subset Finset.inter_subset_left | |
| intro n hn hnot | |
| have hout : n β wordProfiles H t := by | |
| intro hp | |
| exact hnot (Finset.mem_inter.mpr β¨hn, hpβ©) | |
| rw [wordCount_eq_zero_of_not_mem_wordProfiles t n hout] | |
| simp only [Nat.cast_zero, zero_mul] | |
| rw [β hrestrict] | |
| calc | |
| _ β€ β n β wordProfiles H t, (wordCount t n : β) * β h, Ο h ^ n h := | |
| Finset.sum_le_sum_of_subset_of_nonneg Finset.inter_subset_right | |
| (fun n _ _ => wordCount_weight_nonneg t Ο hΟ n) | |
| _ β€ 1 := sum_wordCount_weight_le_one t Ο hΟ hΟsum | |
| end TalagrandThreshold | |
| end OAI | |