Download data/lean/OAI/Combinatorics/BalancedRyser/Profiles/ProfileCompactness.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.54 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BalancedRyser/Profiles/ProfileCompactness.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/BalancedRyser/Profiles/ProfileCompactness.lean
-
curl -L -o ProfileCompactness.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BalancedRyser/Profiles/ProfileCompactness.lean
8.54 kB
| import Mathlib.Analysis.Normed.Group.Tannery | |
| import Mathlib.Analysis.Normed.Module.FiniteDimension | |
| import Mathlib.Tactic | |
| import Mathlib.Topology.Instances.Real.Lemmas | |
| import Mathlib.Topology.Sequences | |
| namespace OAI | |
| open Filter Finset | |
| open scoped Topology | |
| namespace Balanced | |
| open scoped _root_.Balanced | |
| theorem tendsto_tsum_abs_sub_of_probability_mass | |
| {ΞΉ Ξ± : Type*} {l : Filter Ξ±} {p : Ξ± β ΞΉ β β} {q : ΞΉ β β} | |
| (hp_nonneg : β n i, 0 β€ p n i) (hq_nonneg : β i, 0 β€ q i) | |
| (hp_sum : β n, HasSum (p n) 1) (hq_sum : HasSum q 1) | |
| (hpoint : β i, Tendsto (fun n => p n i) l (π (q i))) : | |
| Tendsto (fun n => β' i, |p n i - q i|) l (π 0) := by | |
| have hmin_summable (n : Ξ±) : Summable (fun i => min (p n i) (q i)) := by | |
| apply hq_sum.summable.of_nonneg_of_le | |
| Β· intro i | |
| exact le_min (hp_nonneg n i) (hq_nonneg i) | |
| Β· intro i | |
| exact min_le_right _ _ | |
| have hmin : Tendsto (fun n => β' i, min (p n i) (q i)) l (π 1) := by | |
| rw [β hq_sum.tsum_eq] | |
| apply tendsto_tsum_of_dominated_convergence hq_sum.summable | |
| Β· intro i | |
| simpa using (hpoint i).min (tendsto_const_nhds (x := q i)) | |
| Β· exact Filter.Eventually.of_forall fun n i => by | |
| rw [Real.norm_eq_abs, abs_of_nonneg (le_min (hp_nonneg n i) (hq_nonneg i))] | |
| exact min_le_right _ _ | |
| have hid (n : Ξ±) : (β' i, |p n i - q i|) = 2 - 2 * β' i, min (p n i) (q i) := by | |
| calc | |
| (β' i, |p n i - q i|) = β' i, (p n i + q i - 2 * min (p n i) (q i)) := by | |
| apply tsum_congr | |
| intro i | |
| rcases le_total (p n i) (q i) with h | h | |
| Β· rw [min_eq_left h, abs_of_nonpos (sub_nonpos.mpr h)] | |
| ring | |
| Β· rw [min_eq_right h, abs_of_nonneg (sub_nonneg.mpr h)] | |
| ring | |
| _ = 2 - 2 * β' i, min (p n i) (q i) := by | |
| rw [((hp_sum n).summable.add hq_sum.summable).tsum_sub | |
| ((hmin_summable n).mul_left 2), | |
| (hp_sum n).summable.tsum_add hq_sum.summable, tsum_mul_left, | |
| (hp_sum n).tsum_eq, hq_sum.tsum_eq] | |
| norm_num | |
| simp_rw [hid] | |
| have hlim := (tendsto_const_nhds (x := (2 : β))).sub | |
| ((tendsto_const_nhds (x := (2 : β))).mul hmin) | |
| simpa using hlim | |
| theorem tendsto_totalVariation_of_probability_mass | |
| {ΞΉ Ξ± : Type*} {l : Filter Ξ±} {p : Ξ± β ΞΉ β β} {q : ΞΉ β β} | |
| (hp_nonneg : β n i, 0 β€ p n i) (hq_nonneg : β i, 0 β€ q i) | |
| (hp_sum : β n, HasSum (p n) 1) (hq_sum : HasSum q 1) | |
| (hpoint : β i, Tendsto (fun n => p n i) l (π (q i))) : | |
| Tendsto (fun n => (1 / 2 : β) * β' i, |p n i - q i|) l (π 0) := by | |
| simpa using tendsto_const_nhds.mul | |
| (tendsto_tsum_abs_sub_of_probability_mass hp_nonneg hq_nonneg hp_sum hq_sum hpoint) | |
| theorem profile_tail_le_of_moment | |
| {ΞΉ : Type*} (w : ΞΉ β β) (p : ΞΉ β β) (M : β) (B : β) | |
| (hp : β i, 0 β€ p i) (hs : Summable p) | |
| (hws : Summable (fun i => (w i : β) * p i)) | |
| (hM : (β' i, (w i : β) * p i) β€ M) : | |
| (β' i : {i // B < w i}, p i) β€ M / (B + 1 : β) := by | |
| have hB : (0 : β) < B + 1 := by positivity | |
| apply (le_div_iffβ hB).2 | |
| rw [β tsum_mul_right] | |
| calc | |
| (β' i : {i // B < w i}, p i * (B + 1 : β)) β€ | |
| β' i : {i // B < w i}, (w i : β) * p i := by | |
| apply Summable.tsum_le_tsum | |
| Β· intro i | |
| have hi : (B + 1 : β) β€ (w i : β) := by exact_mod_cast i.property | |
| nlinarith [hp i] | |
| Β· exact (hs.subtype _).mul_right _ | |
| Β· exact hws.subtype _ | |
| _ β€ β' i, (w i : β) * p i := by | |
| exact Summable.tsum_subtype_le _ _ (fun i => mul_nonneg (Nat.cast_nonneg _) (hp i)) hws | |
| _ β€ M := hM | |
| theorem hasSum_one_of_tendsto_of_tight | |
| {ΞΉ Ξ± : Type*} {l : Filter Ξ±} [l.NeBot] | |
| {p : Ξ± β ΞΉ β β} {q : ΞΉ β β} | |
| (hp_nonneg : β n i, 0 β€ p n i) (hp_sum : β n, HasSum (p n) 1) | |
| (hpoint : β i, Tendsto (fun n => p n i) l (π (q i))) | |
| (htight : β Ξ΅ : β, 0 < Ξ΅ β β s : Finset ΞΉ, β n, 1 - Ξ΅ β€ β i β s, p n i) : | |
| HasSum q 1 := by | |
| have hq_nonneg (i : ΞΉ) : 0 β€ q i := | |
| ge_of_tendsto (hpoint i) (Filter.Eventually.of_forall fun n => hp_nonneg n i) | |
| have hfinite (s : Finset ΞΉ) : β i β s, q i β€ 1 := by | |
| apply le_of_tendsto (tendsto_finsetSum s fun i _ => hpoint i) | |
| exact Filter.Eventually.of_forall fun n => by | |
| simpa only [(hp_sum n).tsum_eq] using | |
| (hp_sum n).summable.sum_le_tsum s (fun i _ => hp_nonneg n i) | |
| have hq_summable : Summable q := summable_of_sum_le hq_nonneg hfinite | |
| have hq_le : (β' i, q i) β€ 1 := hq_summable.tsum_le_of_sum_le hfinite | |
| have hq_ge : 1 β€ β' i, q i := by | |
| apply le_of_forall_pos_le_add | |
| intro Ξ΅ hΞ΅ | |
| obtain β¨s, hsβ© := htight Ξ΅ hΞ΅ | |
| have hlim : 1 - Ξ΅ β€ β i β s, q i := | |
| ge_of_tendsto (tendsto_finsetSum s fun i _ => hpoint i) | |
| (Filter.Eventually.of_forall hs) | |
| have hsum := hq_summable.sum_le_tsum s (fun i _ => hq_nonneg i) | |
| linarith | |
| simpa only [le_antisymm hq_le hq_ge] using hq_summable.hasSum | |
| theorem profile_tight_of_moment | |
| {ΞΉ Ξ± : Type*} (w : ΞΉ β β) | |
| (hfinite : β B, Set.Finite {i | w i β€ B}) | |
| {p : Ξ± β ΞΉ β β} {M : β} | |
| (hp : β n i, 0 β€ p n i) (hs : β n, HasSum (p n) 1) | |
| (hws : β n, Summable (fun i => (w i : β) * p n i)) | |
| (hM : β n, (β' i, (w i : β) * p n i) β€ M) : | |
| β Ξ΅ : β, 0 < Ξ΅ β β s : Finset ΞΉ, β n, 1 - Ξ΅ β€ β i β s, p n i := by | |
| classical | |
| intro Ξ΅ hΞ΅ | |
| obtain β¨B, hBβ© := exists_nat_gt (M / Ξ΅) | |
| let s := (hfinite B).toFinset | |
| have hset : (βs : Set ΞΉ)αΆ = {i | B < w i} := by | |
| ext i | |
| simp [s, not_le] | |
| have hratio : M / (B + 1 : β) β€ Ξ΅ := by | |
| apply (div_le_iffβ (by positivity : (0 : β) < B + 1)).2 | |
| have haux := (div_lt_iffβ hΞ΅).1 hB | |
| nlinarith | |
| refine β¨s, fun n => ?_β© | |
| have htail := profile_tail_le_of_moment w (p n) M B (hp n) | |
| (hs n).summable (hws n) (hM n) | |
| have hsum := (hs n).summable.sum_add_tsum_compl (s := s) | |
| rw [hset, (hs n).tsum_eq] at hsum | |
| change (β i β s, p n i) + (β' i : {i // B < w i}, p n i) = 1 at hsum | |
| linarith | |
| theorem profile_moment_le_of_tendsto | |
| {ΞΉ Ξ± : Type*} {l : Filter Ξ±} [l.NeBot] (w : ΞΉ β β) | |
| {p : Ξ± β ΞΉ β β} {q : ΞΉ β β} {M : β} | |
| (hp : β n i, 0 β€ p n i) | |
| (hws : β n, Summable (fun i => (w i : β) * p n i)) | |
| (hM : β n, (β' i, (w i : β) * p n i) β€ M) | |
| (hpoint : β i, Tendsto (fun n => p n i) l (π (q i))) : | |
| Summable (fun i => (w i : β) * q i) β§ | |
| (β' i, (w i : β) * q i) β€ M := by | |
| have hq (i : ΞΉ) : 0 β€ q i := | |
| ge_of_tendsto (hpoint i) (Filter.Eventually.of_forall fun n => hp n i) | |
| have hpartial (s : Finset ΞΉ) : β i β s, (w i : β) * q i β€ M := by | |
| apply le_of_tendsto (tendsto_finsetSum s fun i _ => | |
| (tendsto_const_nhds (x := (w i : β))).mul (hpoint i)) | |
| exact Filter.Eventually.of_forall fun n => | |
| ((hws n).sum_le_tsum s (fun i _ => mul_nonneg (Nat.cast_nonneg _) (hp n i))).trans (hM n) | |
| have hnonneg : β i, 0 β€ (w i : β) * q i := | |
| fun i => mul_nonneg (Nat.cast_nonneg _) (hq i) | |
| exact β¨summable_of_sum_le hnonneg hpartial, | |
| Real.tsum_le_of_sum_le hnonneg hpartialβ© | |
| theorem tendsto_selected_mass_of_probability_mass | |
| {ΞΉ Ξ± : Type*} {l : Filter Ξ±} {p : Ξ± β ΞΉ β β} {q : ΞΉ β β} | |
| (S : Set ΞΉ) | |
| (hp_nonneg : β n i, 0 β€ p n i) (hq_nonneg : β i, 0 β€ q i) | |
| (hp_sum : β n, HasSum (p n) 1) (hq_sum : HasSum q 1) | |
| (hpoint : β i, Tendsto (fun n => p n i) l (π (q i))) : | |
| Tendsto (fun n => β' i : S, p n i) l (π (β' i : S, q i)) := by | |
| have hbound (n : Ξ±) : | |
| β(β' i : S, p n i) - β' i : S, q iβ β€ β' i, |p n i - q i| := by | |
| have hsub := (hp_sum n).summable.sub hq_sum.summable | |
| have hdiff := ((hp_sum n).summable.subtype S).tsum_sub (hq_sum.summable.subtype S) | |
| simp only [Function.comp_apply] at hdiff | |
| calc | |
| β(β' i : S, p n i) - β' i : S, q iβ = | |
| ββ' i : Subtype S, (p n i.val - q i.val)β := congrArg norm hdiff.symm | |
| _ β€ β' i : Subtype S, βp n i.val - q i.valβ := | |
| norm_tsum_le_tsum_norm ((hsub.subtype S).norm) | |
| _ β€ β' i, |p n i - q i| := by | |
| convert! Summable.tsum_subtype_le (fun i => βp n i - q iβ) S | |
| (fun i => norm_nonneg _) hsub.norm using 1 | |
| rw [tendsto_iff_norm_sub_tendsto_zero] | |
| exact squeeze_zero (fun n => norm_nonneg _) hbound | |
| (tendsto_tsum_abs_sub_of_probability_mass hp_nonneg hq_nonneg hp_sum hq_sum hpoint) | |
| end Balanced | |
| end OAI | |