Download data/lean/OAI/Computability/PerfectCompleteness/Repetition/RepetitionRateLemmas.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Repetition/RepetitionRateLemmas.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Repetition/RepetitionRateLemmas.lean
-
curl -L -o RepetitionRateLemmas.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Repetition/RepetitionRateLemmas.lean
12.1 kB
| import OAI.Computability.PerfectCompleteness.Foundations.FiniteProduct | |
| import OAI.Computability.PerfectCompleteness.Reduction.OccurrenceGame | |
| import OAI.Computability.UniqueGames.Foundations.SamplingLemmas | |
| import OAI.Computability.UniqueGames.Games.CompletedSamplingLemmas | |
| import OAI.Computability.UniqueGames.Soundness.PartnerLinearLemmas | |
| namespace OAI | |
| namespace PerfectCompleteness.RepetitionRate | |
| open scoped BigOperators | |
| open UniqueGamesTheorem.Foundations Games | |
| def halfRate (L : Nat) : β := 1 - 1 / (48000 * (L : β)) | |
| theorem halfRate_bounds {L : Nat} (hL : 0 < L) : | |
| 0 < halfRate L β§ halfRate L < 1 := by | |
| have hLq : (1 : β) β€ L := by exact_mod_cast hL | |
| have hden : (0 : β) < 48000 * L := by positivity | |
| have hpos : (0 : β) < 1 / (48000 * L) := div_pos zero_lt_one hden | |
| have hlt : (1 : β) / (48000 * L) < 1 := | |
| (div_lt_one hden).2 (by linarith) | |
| constructor <;> unfold halfRate <;> linarith | |
| theorem halfRate_cast (L : Nat) : | |
| (halfRate L : β) = 1 - 1 / (48000 * (L : β)) := by | |
| simp only [halfRate, Rat.cast_sub, Rat.cast_one, Rat.cast_div, | |
| Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] | |
| theorem halfRate_power_comparison {L : Nat} (hL : 0 < L) : | |
| (1 - 1 / 48000 : β) β€ (halfRate L : β) ^ L := by | |
| have hLr : (1 : β) β€ L := by exact_mod_cast hL | |
| have hLpos : (0 : β) < L := by exact_mod_cast hL | |
| have hden : (0 : β) < 48000 * L := by positivity | |
| have hfrac : (1 : β) / (48000 * L) β€ 1 := | |
| (div_le_one hden).2 (by linarith) | |
| have h := one_add_mul_le_pow | |
| (a := -((1 : β) / (48000 * L))) (by linarith : | |
| (-2 : β) β€ -((1 : β) / (48000 * L))) L | |
| rw [halfRate_cast] | |
| calc | |
| (1 - 1 / 48000 : β) = | |
| 1 + (L : β) * (-((1 : β) / (48000 * L))) := by | |
| field_simp [ne_of_gt hLpos] | |
| ring | |
| _ β€ (1 + -((1 : β) / (48000 * L))) ^ L := h | |
| _ = (1 - 1 / (48000 * (L : β))) ^ L := by rw [sub_eq_add_neg] | |
| theorem halfRate_rpow_comparison {L : Nat} (hL : 0 < L) (n : Nat) : | |
| (1 - 1 / 48000 : β) ^ ((n : β) / L) β€ (halfRate L : β) ^ n := by | |
| have hLpos : (0 : β) < L := by exact_mod_cast hL | |
| have hr : (0 : β) β€ halfRate L := by | |
| exact_mod_cast (halfRate_bounds hL).1.le | |
| calc | |
| _ β€ ((halfRate L : β) ^ L) ^ ((n : β) / L) := | |
| Real.rpow_le_rpow (by norm_num) (halfRate_power_comparison hL) (by positivity) | |
| _ = (halfRate L : β) ^ ((L : β) * ((n : β) / L)) := | |
| (Real.rpow_natCast_mul hr L ((n : β) / L)).symm | |
| _ = (halfRate L : β) ^ (n : β) := by | |
| congr 1 | |
| field_simp [ne_of_gt hLpos] | |
| _ = (halfRate L : β) ^ n := Real.rpow_natCast _ _ | |
| theorem game_repetition_halfRate {Qβ Qβ Aβ Aβ : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] | |
| [Nonempty Aβ] [Nonempty Aβ] [DecidableEq Qβ] [DecidableEq Qβ] | |
| (G : Game Qβ Qβ Aβ Aβ) {L : Nat} (hL : 0 < L) | |
| (halphabet : Repetition.logTwo | |
| ((Fintype.card Aβ : β) * (Fintype.card Aβ : β)) β€ L) | |
| (hvalue : G.value β€ 1 / 2) (n : Nat) : | |
| (G.repetition n).value β€ (halfRate L : β) ^ n := by | |
| have hell : (1 : β) β€ L := by exact_mod_cast hL | |
| have h := Repetition.holenstein_repetition_value G n hvalue | |
| (by norm_num : (1 / 2 : β) < 1) hell halphabet | |
| have hbase : (1 - (1 - (1 / 2 : β)) ^ 3 / 6000) = 1 - 1 / 48000 := by | |
| norm_num | |
| rw [hbase] at h | |
| exact h.trans (halfRate_rpow_comparison hL n) | |
| theorem occurrence_repetition_halfRate {E Qβ Qβ Aβ Aβ : Type*} | |
| [Fintype E] [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] | |
| [Nonempty Aβ] [Nonempty Aβ] [DecidableEq Qβ] [DecidableEq Qβ] | |
| (G : OccurrenceGame E Qβ Qβ Aβ Aβ) (p : G.EndpointPresentation) | |
| {L : Nat} (hL : 0 < L) | |
| (halphabet : Repetition.logTwo | |
| ((Fintype.card Aβ : β) * (Fintype.card Aβ : β)) β€ L) | |
| (hvalue : G.value β€ 1 / 2) (n : Nat) : | |
| (G.repetition n).value β€ (halfRate L : β) ^ n := by | |
| have hv : (G.toGame p).value β€ 1 / 2 := by | |
| simpa only [G.toGame_value p] using hvalue | |
| have h := game_repetition_halfRate (G.toGame p) hL halphabet hv n | |
| simpa only [G.toGame_repetition_value p n] using h | |
| noncomputable section | |
| def bernoulli (p : β) (hp : 0 β€ p) (hp' : p β€ 1) : FiniteDistribution Bool where | |
| weight b := if b = true then p else 1 - p | |
| nonnegative b := by | |
| cases b | |
| Β· simpa using sub_nonneg.mpr hp' | |
| Β· simpa using hp | |
| normalized := by simp | |
| def cleanCount {n : Nat} (mask : Fin n β Bool) : Nat := | |
| (Finset.univ.filter fun i => mask i = true).card | |
| theorem pow_cleanCount_eq_prod {n : Nat} (a : β) (mask : Fin n β Bool) : | |
| a ^ cleanCount mask = β i, if mask i = true then a else 1 := by | |
| rw [β Finset.prod_filter] | |
| simp [cleanCount] | |
| theorem cleanMask_moment (p : β) (hp : 0 β€ p) (hp' : p β€ 1) | |
| (a : β) (n : Nat) : | |
| ((bernoulli p hp hp').iid n).expectation (fun mask => a ^ cleanCount mask) = | |
| (1 - p * (1 - a)) ^ n := by | |
| unfold FiniteDistribution.expectation FiniteDistribution.iid | |
| simp_rw [pow_cleanCount_eq_prod, β Finset.prod_mul_distrib] | |
| rw [β Fintype.sum_pow | |
| (fun b : Bool => (bernoulli p hp hp').weight b * (if b = true then a else 1)) n] | |
| congr 1 | |
| simp [bernoulli] | |
| ring | |
| end | |
| theorem cube_decay_bound {c : β} (hc : 0 β€ c) (hc' : c β€ 1) | |
| {m : Nat} (hm : 0 < m) : | |
| (1 - c / (m : β) ^ 2) ^ (m ^ 3) β€ 1 / (1 + c * m) := by | |
| have hmone : (1 : β) β€ m := by exact_mod_cast hm | |
| have hmpos : (0 : β) < m := by exact_mod_cast hm | |
| have hmsq : (1 : β) β€ (m : β) ^ 2 := by nlinarith | |
| have hsqpos : (0 : β) < (m : β) ^ 2 := pow_pos hmpos _ | |
| have hfrac0 : (0 : β) β€ c / (m : β) ^ 2 := div_nonneg hc hsqpos.le | |
| have hfrac1 : c / (m : β) ^ 2 β€ 1 := (div_le_one hsqpos).2 (hc'.trans hmsq) | |
| have h := UniqueGamesTheorem.Soundness.RepetitionUpper.power_mul_growth_le_one | |
| (1 - c / (m : β) ^ 2) (by linarith) (by linarith) (m ^ 3) | |
| have hfactor : 1 + ((m ^ 3 : Nat) : β) * (1 - (1 - c / (m : β) ^ 2)) = | |
| 1 + c * m := by | |
| push_cast | |
| field_simp [ne_of_gt hmpos] | |
| ring | |
| rw [hfactor] at h | |
| have hden : (0 : β) < 1 + c * m := by positivity | |
| exact (le_div_iffβ hden).2 h | |
| theorem exists_cube_decay_lt {c threshold : β} | |
| (hc : 0 < c) (hc' : c β€ 1) (hthreshold : 0 < threshold) : | |
| β m : Nat, 0 < m β§ | |
| (1 - c / (m : β) ^ 2) ^ (m ^ 3) < threshold := by | |
| obtain β¨m, hm, hlargeβ© := | |
| UniqueGamesTheorem.Soundness.RepetitionUpper.exists_pos_nat_gt (1 / (c * threshold)) | |
| refine β¨m, hm, (cube_decay_bound hc.le hc' hm).trans_lt ?_β© | |
| have hlarge' : (1 : β) < (m : β) * (c * threshold) := | |
| (div_lt_iffβ (mul_pos hc hthreshold)).1 hlarge | |
| have hden : (0 : β) < 1 + c * m := by positivity | |
| apply (div_lt_iffβ hden).2 | |
| nlinarith | |
| theorem exists_clean_branching {L : Nat} (hL : 0 < L) {p0 threshold : β} | |
| (hp0 : 0 < p0) (hp0' : p0 β€ 1) (hthreshold : 0 < threshold) : | |
| β m : Nat, 0 < m β§ | |
| (1 - ((1 - halfRate L) * p0) / (m : β) ^ 2) ^ (m ^ 3) < threshold := by | |
| have hr := halfRate_bounds hL | |
| have hc : (0 : β) < (1 - halfRate L) * p0 := | |
| mul_pos (sub_pos.mpr hr.2) hp0 | |
| have hc' : (1 - halfRate L) * p0 β€ 1 := by | |
| have h := mul_le_mul_of_nonneg_left hp0' (sub_nonneg.mpr hr.2.le) | |
| nlinarith | |
| exact exists_cube_decay_lt hc hc' hthreshold | |
| end PerfectCompleteness.RepetitionRate | |
| namespace PerfectCompleteness.IndexedRepetition | |
| open UniqueGamesTheorem.Foundations.Games | |
| open FiniteProduct | |
| noncomputable section | |
| variable {E Qβ Qβ Aβ Aβ : Type*} | |
| [Fintype E] [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] | |
| def game (G : OccurrenceGame E Qβ Qβ Aβ Aβ) (I : Type*) | |
| [Fintype I] [DecidableEq I] : | |
| OccurrenceGame (I β E) (I β Qβ) (I β Qβ) (I β Aβ) (I β Aβ) := by | |
| classical | |
| exact | |
| { occurrences := law (fun _ : I => G.occurrences) | |
| left := fun x i => G.left (x i) | |
| right := fun x i => G.right (x i) | |
| accepts := fun x a b => decide (β i, G.accepts (x i) (a i) (b i) = true) } | |
| def reindexStrategy {I J : Type*} (e : J β I) | |
| (s : Strategy (I β Qβ) (I β Qβ) (I β Aβ) (I β Aβ)) : | |
| Strategy (J β Qβ) (J β Qβ) (J β Aβ) (J β Aβ) := | |
| (fun x j => s.1 (x β e.symm) (e j), | |
| fun y j => s.2 (y β e.symm) (e j)) | |
| theorem law_const_fin (ΞΌ : FiniteDistribution E) (n : Nat) : | |
| law (fun _ : Fin n => ΞΌ) = ΞΌ.iid n := by | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro x | |
| rfl | |
| theorem game_fin (G : OccurrenceGame E Qβ Qβ Aβ Aβ) (n : Nat) : | |
| game G (Fin n) = G.repetition n := by | |
| unfold game OccurrenceGame.repetition | |
| simp only [law_const_fin] | |
| congr 1 | |
| funext x a b | |
| by_cases h : β i : Fin n, G.accepts (x i) (a i) (b i) = true <;> | |
| simp only [h, decide_false] | |
| theorem reindex_law {I J : Type*} [Fintype I] [Fintype J] | |
| [DecidableEq I] [DecidableEq J] | |
| (ΞΌ : FiniteDistribution E) (e : J β I) : | |
| (law (fun _ : I => ΞΌ)).pushforward (fun x => x β e) = | |
| law (fun _ : J => ΞΌ) := | |
| FiniteDistribution.table_const_reindex ΞΌ e | |
| theorem reindex_success {I J : Type*} [Fintype I] [Fintype J] | |
| [DecidableEq I] [DecidableEq J] | |
| (G : OccurrenceGame E Qβ Qβ Aβ Aβ) (e : J β I) | |
| (s : Strategy (I β Qβ) (I β Qβ) (I β Aβ) (I β Aβ)) : | |
| (game G J).success (reindexStrategy e s) = (game G I).success s := by | |
| classical | |
| change (law (fun _ : J => G.occurrences)).probability _ = | |
| (law (fun _ : I => G.occurrences)).probability _ | |
| rw [β reindex_law G.occurrences e, FiniteDistribution.probability_pushforward] | |
| apply congrArg (law (fun _ : I => G.occurrences)).probability | |
| funext x | |
| have hl : (fun j => G.left ((x β e) j)) β e.symm = fun i => G.left (x i) := by | |
| funext i | |
| simp only [Function.comp_apply, e.apply_symm_apply] | |
| have hr : (fun j => G.right ((x β e) j)) β e.symm = fun i => G.right (x i) := by | |
| funext i | |
| simp only [Function.comp_apply, e.apply_symm_apply] | |
| change decide (β j, G.accepts ((x β e) j) | |
| (s.1 ((fun j => G.left ((x β e) j)) β e.symm) (e j)) | |
| (s.2 ((fun j => G.right ((x β e) j)) β e.symm) (e j)) = true) = | |
| decide (β i, G.accepts (x i) | |
| (s.1 (fun i => G.left (x i)) i) (s.2 (fun i => G.right (x i)) i) = true) | |
| rw [hl, hr] | |
| congr 1 | |
| apply propext | |
| constructor | |
| Β· intro h i | |
| simpa only [Function.comp_apply, e.apply_symm_apply] using h (e.symm i) | |
| Β· intro h j | |
| exact h (e j) | |
| theorem success_le_repetition_value {I : Type*} [Fintype I] [DecidableEq I] | |
| [Nonempty Aβ] [Nonempty Aβ] | |
| (G : OccurrenceGame E Qβ Qβ Aβ Aβ) | |
| (s : Strategy (I β Qβ) (I β Qβ) (I β Aβ) (I β Aβ)) : | |
| (game G I).success s β€ (G.repetition (Fintype.card I)).value := by | |
| rw [β reindex_success G (Fintype.equivFin I).symm s, game_fin] | |
| exact (G.repetition (Fintype.card I)).success_le_value _ | |
| theorem value_eq_repetition {I : Type*} [Fintype I] [DecidableEq I] | |
| [Nonempty Aβ] [Nonempty Aβ] (G : OccurrenceGame E Qβ Qβ Aβ Aβ) : | |
| (game G I).value = (G.repetition (Fintype.card I)).value := by | |
| apply le_antisymm | |
| Β· exact ((game G I).value_le_iff _).2 (success_le_repetition_value G) | |
| Β· apply ((G.repetition (Fintype.card I)).value_le_iff _).2 | |
| intro s | |
| have h := reindex_success G (Fintype.equivFin I) s | |
| rw [game_fin] at h | |
| rw [β h] | |
| exact (game G I).success_le_value (reindexStrategy (Fintype.equivFin I) s) | |
| theorem halfRate {I : Type*} [Fintype I] [DecidableEq I] | |
| [Nonempty Aβ] [Nonempty Aβ] [DecidableEq Qβ] [DecidableEq Qβ] | |
| (G : OccurrenceGame E Qβ Qβ Aβ Aβ) (p : G.EndpointPresentation) | |
| {L : Nat} (hL : 0 < L) | |
| (alphabet : UniqueGamesTheorem.Foundations.Repetition.logTwo | |
| ((Fintype.card Aβ : β) * (Fintype.card Aβ : β)) β€ L) | |
| (gap : G.value β€ 1 / 2) : | |
| (game G I).value β€ (RepetitionRate.halfRate L : β) ^ Fintype.card I := by | |
| rw [value_eq_repetition] | |
| exact RepetitionRate.occurrence_repetition_halfRate G p hL alphabet gap _ | |
| end | |
| end PerfectCompleteness.IndexedRepetition | |
| end OAI | |