math / data /lean /OAI /Computability /PerfectCompleteness /Sampling /BoundedListSamplingLemmas.lean
Download data/lean/OAI/Computability/PerfectCompleteness/Sampling/BoundedListSamplingLemmas.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/BoundedListSamplingLemmas.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Sampling/BoundedListSamplingLemmas.lean
-
curl -L -o BoundedListSamplingLemmas.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/BoundedListSamplingLemmas.lean
11.7 kB
| import Mathlib.Data.Rat.Cast.Order | |
| import OAI.Computability.PerfectCompleteness.Reduction.CompletionSoundness | |
| import OAI.Computability.PerfectCompleteness.Reduction.TargetGameLemmas | |
| import OAI.Computability.PerfectCompleteness.Repetition.CleanConditioning | |
| import OAI.Computability.PerfectCompleteness.Sampling.FiniteListSampling | |
| import OAI.Computability.UniqueGames.Foundations.SamplingLemmas | |
| namespace OAI | |
| namespace PerfectCompleteness.BoundedListSampling | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open UniqueGamesTheorem.Foundations.Games | |
| variable {Index A : Type*} [Fintype A] | |
| def listLaw (L : Finset A) (default : A) : FiniteDistribution A := | |
| if h : L.Nonempty then FiniteListSampling.uniformList L h | |
| else FiniteListSampling.uniformList {default} (Finset.singleton_nonempty default) | |
| theorem listLaw_of_nonempty (L : Finset A) (default : A) (h : L.Nonempty) : | |
| listLaw L default = FiniteListSampling.uniformList L h := by | |
| simp [listLaw, h] | |
| @[simp] theorem listLaw_empty_weight (default a : A) : | |
| (listLaw β default).weight a = if a = default then 1 else 0 := by | |
| simp [listLaw, FiniteListSampling.uniformList] | |
| theorem listLaw_weight_mem (L : Finset A) (default a : A) (ha : a β L) : | |
| (listLaw L default).weight a = 1 / (L.card : β) := by | |
| rw [listLaw_of_nonempty L default β¨a, haβ©] | |
| exact FiniteListSampling.uniformList_weight_mem L β¨a, haβ© a ha | |
| theorem listLaw_weight_lower (L : Finset A) (default : A) (M : β) | |
| (hM : 0 < M) (hcard : (L.card : β) β€ M) (a : A) (ha : a β L) : | |
| 1 / M β€ (listLaw L default).weight a := by | |
| rw [listLaw_weight_mem L default a ha] | |
| have hcardPos : 0 < (L.card : β) := Nat.cast_pos.mpr (Finset.Nonempty.card_pos β¨a, haβ©) | |
| apply (div_le_div_iffβ hM hcardPos).mpr | |
| simpa only [one_mul] using hcard | |
| theorem list_success_lower (L : Finset A) (default : A) (M : β) | |
| (hM : 0 < M) (hcard : (L.card : β) β€ M) (event : A β Bool) | |
| (witness : β a β L, event a = true) : | |
| 1 / M β€ (listLaw L default).probability event := by | |
| obtain β¨a, ha, heventβ© := witness | |
| exact (listLaw_weight_lower L default M hM hcard a ha).trans | |
| (FiniteListSampling.probability_ge_weight (listLaw L default) event a hevent) | |
| variable [Fintype Index] [Nonempty Index] | |
| def jointLaw (L : Index β Finset A) (default : A) : FiniteDistribution (Index Γ A) := | |
| CleanConditioning.kernelJoint (FiniteDistribution.uniform Index) (fun Ο => listLaw (L Ο) default) | |
| @[simp] theorem jointLaw_weight (L : Index β Finset A) (default : A) (Ο : Index) (a : A) : | |
| (jointLaw L default).weight (Ο, a) = | |
| (1 / (Fintype.card Index : β)) * (listLaw (L Ο) default).weight a := rfl | |
| theorem jointLaw_probability (L : Index β Finset A) (default : A) (event : Index Γ A β Bool) : | |
| (jointLaw L default).probability event = | |
| β Ο, (1 / (Fintype.card Index : β)) * | |
| (listLaw (L Ο) default).probability (fun a => event (Ο, a)) := | |
| CleanConditioning.probability_kernelJoint _ _ _ | |
| theorem jointLaw_index_law (L : Index β Finset A) (default : A) : | |
| (jointLaw L default).pushforward Prod.fst = FiniteDistribution.uniform Index := by | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro Ο | |
| change (β p : Index Γ A, if p.1 = Ο then | |
| (FiniteDistribution.uniform Index).weight p.1 * (listLaw (L p.1) default).weight p.2 else 0) = | |
| (FiniteDistribution.uniform Index).weight Ο | |
| rw [Fintype.sum_prod_type] | |
| calc | |
| _ = β Ο, if Ο = Ο then (FiniteDistribution.uniform Index).weight Ο else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro Ο _ | |
| by_cases hΟ : Ο = Ο | |
| Β· simp only [ite_eq_left hΟ, β Finset.mul_sum, FiniteDistribution.normalized, mul_one] | |
| Β· simp only [ite_eq_right hΟ, Finset.sum_const_zero] | |
| _ = _ := by simp | |
| theorem jointLaw_weight_ge_of_mem (L : Index β Finset A) (default : A) (M : β) | |
| (hM : 0 < M) (hcard : β Ο, ((L Ο).card : β) β€ M) | |
| (Ο : Index) (a : A) (ha : a β L Ο) : | |
| 1 / ((Fintype.card Index : β) * M) β€ (jointLaw L default).weight (Ο, a) := by | |
| rw [jointLaw_weight, β one_div_mul_one_div] | |
| exact mul_le_mul_of_nonneg_left (listLaw_weight_lower (L Ο) default M hM (hcard Ο) a ha) | |
| (one_div_nonneg.mpr (Nat.cast_nonneg _)) | |
| theorem joint_success_lower (L : Index β Finset A) (default : A) (M : β) | |
| (hM : 0 < M) (hcard : β Ο, ((L Ο).card : β) β€ M) | |
| (event : Index Γ A β Bool) (witness : β Ο a, a β L Ο β§ event (Ο, a) = true) : | |
| 1 / ((Fintype.card Index : β) * M) β€ (jointLaw L default).probability event := by | |
| obtain β¨Ο, a, ha, heventβ© := witness | |
| exact (jointLaw_weight_ge_of_mem L default M hM hcard Ο a ha).trans | |
| (FiniteListSampling.probability_ge_weight (jointLaw L default) event (Ο, a) hevent) | |
| theorem joint_success_lower_of_indices (L : Index β Finset A) (default : A) (M : β) | |
| (hM : 0 < M) (hcard : β Ο, ((L Ο).card : β) β€ M) | |
| (event : Index Γ A β Bool) (good : Index β Bool) | |
| (witness : β Ο, good Ο = true β β a β L Ο, event (Ο, a) = true) : | |
| (FiniteDistribution.uniform Index).probability good / M β€ | |
| (jointLaw L default).probability event := by | |
| have hstep : β Ο, (if good Ο then 1 / M else 0) β€ | |
| (listLaw (L Ο) default).probability (fun a => event (Ο, a)) := by | |
| intro Ο | |
| by_cases hgood : good Ο = true | |
| Β· simpa only [hgood, ite_true] using | |
| list_success_lower (L Ο) default M hM (hcard Ο) _ (witness Ο hgood) | |
| Β· simpa [hgood] using | |
| (listLaw (L Ο) default).probability_nonnegative (fun a => event (Ο, a)) | |
| calc | |
| _ = β Ο, (FiniteDistribution.uniform Index).weight Ο * (if good Ο then 1 / M else 0) := by | |
| simp only [FiniteDistribution.probability, Finset.sum_div, ite_div, zero_div, | |
| mul_ite, mul_one_div, mul_zero] | |
| _ β€ β Ο, (FiniteDistribution.uniform Index).weight Ο * | |
| (listLaw (L Ο) default).probability (fun a => event (Ο, a)) := | |
| Finset.sum_le_sum (fun Ο _ => mul_le_mul_of_nonneg_left (hstep Ο) | |
| ((FiniteDistribution.uniform Index).nonnegative Ο)) | |
| _ = _ := (jointLaw_probability L default event).symm | |
| def outputLaw {B : Type*} [Fintype B] (L : Index β Finset A) (default : A) | |
| (decode : Index β A β B) : FiniteDistribution B := | |
| (jointLaw L default).pushforward (fun p => decode p.1 p.2) | |
| theorem outputLaw_probability {B : Type*} [Fintype B] | |
| (L : Index β Finset A) (default : A) (decode : Index β A β B) (event : B β Bool) : | |
| (outputLaw L default decode).probability event = | |
| (jointLaw L default).probability (fun p => event (decode p.1 p.2)) := | |
| FiniteDistribution.probability_pushforward _ _ _ | |
| theorem output_success_lower {B : Type*} [Fintype B] | |
| (L : Index β Finset A) (default : A) (decode : Index β A β B) | |
| (M : β) (hM : 0 < M) (hcard : β Ο, ((L Ο).card : β) β€ M) | |
| (event : B β Bool) | |
| (witness : β Ο a, a β L Ο β§ event (decode Ο a) = true) : | |
| 1 / ((Fintype.card Index : β) * M) β€ (outputLaw L default decode).probability event := by | |
| rw [outputLaw_probability] | |
| exact joint_success_lower L default M hM hcard _ witness | |
| theorem output_weight_ge_of_mem {B : Type*} [Fintype B] | |
| (L : Index β Finset A) (default : A) (decode : Index β A β B) | |
| (M : β) (hM : 0 < M) (hcard : β Ο, ((L Ο).card : β) β€ M) | |
| (Ο : Index) (a : A) (ha : a β L Ο) : | |
| 1 / ((Fintype.card Index : β) * M) β€ (outputLaw L default decode).weight (decode Ο a) := by | |
| have h := output_success_lower L default decode M hM hcard | |
| (fun b => decide (b = decode Ο a)) β¨Ο, a, ha, by simpβ© | |
| simpa [FiniteDistribution.probability] using h | |
| theorem independent_match_lower {B C : Type*} [Fintype B] [Fintype C] [Nonempty C] | |
| (L : Index β Finset A) (default : A) (decode : Index β A β B) | |
| (M : β) (hM : 0 < M) (hcard : β Ο, ((L Ο).card : β) β€ M) | |
| (accepts : C β B β Bool) | |
| (witness : β Ο a, a β L Ο β§ β c, accepts c (decode Ο a) = true) : | |
| 1 / ((Fintype.card C : β) * (Fintype.card Index : β) * M) β€ | |
| ((FiniteDistribution.uniform C).product (outputLaw L default decode)).probability | |
| (fun p => accepts p.1 p.2) := by | |
| obtain β¨Ο, a, ha, c, hacceptβ© := witness | |
| have hright := output_weight_ge_of_mem L default decode M hM hcard Ο a ha | |
| calc | |
| _ = (1 / (Fintype.card C : β)) * (1 / ((Fintype.card Index : β) * M)) := by | |
| simp only [one_div_mul_one_div, mul_assoc] | |
| _ β€ ((FiniteDistribution.uniform C).product (outputLaw L default decode)).weight | |
| (c, decode Ο a) := | |
| mul_le_mul_of_nonneg_left hright ((FiniteDistribution.uniform C).nonnegative c) | |
| _ β€ _ := FiniteListSampling.probability_ge_weight _ _ (c, decode Ο a) haccept | |
| end | |
| end PerfectCompleteness.BoundedListSampling | |
| namespace PerfectCompleteness.LegalUniform | |
| open scoped BigOperators Classical | |
| open UniqueGamesTheorem.Foundations.Games | |
| open WeightRounding | |
| noncomputable section | |
| def enumeratedWeights {E : Type*} [Fintype E] | |
| (f : E β β) (hpositive : β e, 0 < f e) (htotal : β e, f e = 1) | |
| (enum : E β Fin (Fintype.card E)) : PositiveWeights (Fintype.card E) where | |
| weight i := f (enum.symm i) | |
| positive i := hpositive (enum.symm i) | |
| total := (enum.symm.sum_comp f).trans htotal | |
| theorem transport_weight_eq_enumerated {E : Type*} [Fintype E] | |
| (ΞΌ : FiniteDistribution E) (f : E β β) | |
| (hpositive : β e, 0 < f e) (htotal : β e, f e = 1) | |
| (hweights : β e, ΞΌ.weight e = (f e : β)) | |
| (enum : E β Fin (Fintype.card E)) (i : Fin (Fintype.card E)) : | |
| (ΞΌ.transport enum).weight i = | |
| ((enumeratedWeights f hpositive htotal enum).weight i : β) := | |
| hweights (enum.symm i) | |
| def uniformWeights (E : Type*) [Fintype E] [Nonempty E] : | |
| PositiveWeights (Fintype.card E) where | |
| weight _ := 1 / (Fintype.card E : β) | |
| positive _ := by | |
| have hcard : (0 : β) < Fintype.card E := by | |
| exact_mod_cast (Fintype.card_pos : 0 < Fintype.card E) | |
| exact div_pos zero_lt_one hcard | |
| total := by | |
| have hcard : (Fintype.card E : β) β 0 := | |
| Nat.cast_ne_zero.mpr Fintype.card_ne_zero | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, | |
| nsmul_eq_mul, one_div] | |
| exact mul_inv_cancelβ hcard | |
| @[simp] theorem uniformWeights_weight (E : Type*) [Fintype E] [Nonempty E] | |
| (i : Fin (Fintype.card E)) : | |
| (uniformWeights E).weight i = 1 / (Fintype.card E : β) := rfl | |
| theorem transport_uniform_weight {E : Type*} [Fintype E] [Nonempty E] | |
| (ΞΌ : FiniteDistribution E) (huniform : ΞΌ = FiniteDistribution.uniform E) | |
| (enum : E β Fin (Fintype.card E)) (i : Fin (Fintype.card E)) : | |
| (ΞΌ.transport enum).weight i = ((uniformWeights E).weight i : β) := by | |
| rw [huniform] | |
| change (1 / (Fintype.card E : β)) = ((1 / (Fintype.card E : β) : β) : β) | |
| simp only [Rat.cast_div, Rat.cast_one, Rat.cast_natCast] | |
| theorem equivFin_uniform_weight {E : Type*} [Fintype E] [Nonempty E] | |
| (ΞΌ : FiniteDistribution E) (huniform : ΞΌ = FiniteDistribution.uniform E) | |
| (i : Fin (Fintype.card E)) : | |
| (ΞΌ.transport (Fintype.equivFin E)).weight i = | |
| ((uniformWeights E).weight i : β) := | |
| transport_uniform_weight ΞΌ huniform (Fintype.equivFin E) i | |
| theorem exists_uniform_weights {E : Type*} [Fintype E] [Nonempty E] | |
| (ΞΌ : FiniteDistribution E) (huniform : ΞΌ = FiniteDistribution.uniform E) : | |
| β w : PositiveWeights (Fintype.card E), | |
| (β i, w.weight i = 1 / (Fintype.card E : β)) β§ | |
| β i, (ΞΌ.transport (Fintype.equivFin E)).weight i = (w.weight i : β) := by | |
| exact β¨uniformWeights E, uniformWeights_weight E, equivFin_uniform_weight ΞΌ huniformβ© | |
| end | |
| end PerfectCompleteness.LegalUniform | |
| end OAI | |