Download data/lean/OAI/Computability/MinUncut/Encoding/Decoder.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.8 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Encoding/Decoder.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MinUncut/Encoding/Decoder.lean
-
curl -L -o Decoder.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MinUncut/Encoding/Decoder.lean
12.8 kB
| import Mathlib | |
| import OAI.Computability.MinUncut.PCP.Folding | |
| namespace OAI | |
| section | |
| noncomputable section | |
| namespace MinUncutGames.Foundations.Hastad | |
| open scoped BigOperators | |
| open Finset | |
| variable {I J : Type*} [Fintype I] [DecidableEq I] [Fintype J] [DecidableEq J] | |
| def parityProjection (Ο : J β I) (s : Cube J) : Cube I := fun i => | |
| decide (Odd ((support s).filter fun y => Ο y = i).card) | |
| theorem walsh_support (s x : Cube I) : | |
| walsh s x = β i β support s, bitSign (x i) := by | |
| unfold walsh support | |
| rw [Finset.prod_filter] | |
| apply Finset.prod_congr rfl | |
| intro i _ | |
| cases s i <;> simp [bitSign] | |
| theorem sign_power_parity (b : Bool) (n : Nat) : | |
| bitSign b ^ n = bitSign (decide (Odd n) && b) := by | |
| cases b | |
| Β· simp [bitSign] | |
| Β· simp only [Bool.and_true, bitSign, ite_true, decide_eq_true_eq] | |
| rw [neg_one_pow_eq_ite] | |
| by_cases h : Even n | |
| Β· simp [h, Nat.not_odd_iff_even.mpr h] | |
| Β· simp [h, Nat.not_even_iff_odd.mp h] | |
| theorem walsh_pullback (Ο : J β I) (s : Cube J) (f : Cube I) : | |
| walsh s (fun y => f (Ο y)) = walsh (parityProjection Ο s) f := by | |
| rw [walsh_support] | |
| rw [β Finset.prod_fiberwise' (support s) Ο (fun i => bitSign (f i))] | |
| unfold walsh parityProjection | |
| apply Finset.prod_congr rfl | |
| intro i _ | |
| simp only [Finset.prod_const] | |
| exact sign_power_parity (f i) _ | |
| theorem projectedCoefficient_eq (Ο : J β I) (A : Cube I β β) (s : Cube J) : | |
| projectedCoefficient Ο A s = coefficient A (parityProjection Ο s) := by | |
| simp only [projectedCoefficient, coefficient, walsh_pullback] | |
| omit [DecidableEq J] in | |
| theorem projection_has_preimage (Ο : J β I) (s : Cube J) (i : I) | |
| (hi : i β support (parityProjection Ο s)) : | |
| β y β support s, Ο y = i := by | |
| have hodd : Odd ((support s).filter fun y => Ο y = i).card := by | |
| have hbit := (Finset.mem_filter.mp hi).2 | |
| simpa only [parityProjection, decide_eq_true_eq] using hbit | |
| have hp : 0 < ((support s).filter fun y => Ο y = i).card := by | |
| obtain β¨n, hnβ© := hodd | |
| omega | |
| obtain β¨y, hyβ© := Finset.card_pos.mp hp | |
| exact β¨y, (Finset.mem_filter.mp hy).1, (Finset.mem_filter.mp hy).2β© | |
| theorem scaled_geometric_power_le_one {t : β} (ht : 0 β€ t) (ht' : t β€ 1) (n : Nat) : | |
| (n : β) * (1 - t) * t ^ n β€ 1 := by | |
| have hsum : (n : β) * t ^ n β€ β j β Finset.range n, t ^ j := by | |
| calc | |
| (n : β) * t ^ n = β _j β Finset.range n, t ^ n := by simp | |
| _ β€ β j β Finset.range n, t ^ j := by | |
| apply Finset.sum_le_sum | |
| intro j hj | |
| exact pow_le_pow_of_le_one ht ht' (Nat.le_of_lt (Finset.mem_range.mp hj)) | |
| have hm := mul_le_mul_of_nonneg_right hsum (sub_nonneg.mpr ht') | |
| rw [geom_sum_mul_neg] at hm | |
| have hp : 0 β€ t ^ n := pow_nonneg ht _ | |
| nlinarith | |
| theorem noise_decay_bound {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ β€ 1 / 2) | |
| {k : Nat} (hk : 0 < k) : | |
| 4 * Ξ΅ * ((1 - 2 * Ξ΅) ^ k) ^ 2 β€ 1 / (k : β) := by | |
| have h := scaled_geometric_power_le_one (t := 1 - 2 * Ξ΅) | |
| (by linarith) (by linarith) (2 * k) | |
| have hkp : (0 : β) < k := Nat.cast_pos.mpr hk | |
| apply (le_div_iffβ hkp).mpr | |
| have hpow : (1 - 2 * Ξ΅) ^ (2 * k) = ((1 - 2 * Ξ΅) ^ k) ^ 2 := by | |
| rw [Nat.mul_comm, pow_mul] | |
| rw [hpow] at h | |
| norm_num only [Nat.cast_mul, Nat.cast_ofNat] at h | |
| nlinarith | |
| def zeroMask : Cube I := fun _ => false | |
| omit [DecidableEq I] in | |
| theorem support_eq_empty_iff (s : Cube I) : support s = β β s = zeroMask := by | |
| constructor | |
| Β· intro h | |
| funext i | |
| have hi : i β support s := by rw [h]; simp | |
| have : s i β true := by simpa [support] using hi | |
| cases hs : s i <;> simp_all [zeroMask] | |
| Β· intro h | |
| subst s | |
| simp [zeroMask, support] | |
| omit [Fintype I] [DecidableEq J] in | |
| theorem parityProjection_zero (Ο : J β I) : | |
| parityProjection Ο (zeroMask : Cube J) = zeroMask := by | |
| funext i | |
| simp [parityProjection, support, zeroMask] | |
| def agreementProbability (Ο : J β I) (a : Cube I) (b : Cube J) : β := | |
| (β i β support a, (((support b).filter fun y => Ο y = i).card : β)) / | |
| ((support a).card * (support b).card : β) | |
| omit [DecidableEq J] in | |
| theorem agreementProbability_nonneg (Ο : J β I) (a : Cube I) (b : Cube J) : | |
| 0 β€ agreementProbability Ο a b := by | |
| unfold agreementProbability | |
| apply div_nonneg | |
| Β· exact Finset.sum_nonneg (fun _ _ => Nat.cast_nonneg _) | |
| Β· exact mul_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) | |
| omit [DecidableEq J] in | |
| theorem agreementProbability_projection (Ο : J β I) (b : Cube J) | |
| (ha : (support (parityProjection Ο b)).Nonempty) : | |
| 1 / ((support b).card : β) β€ agreementProbability Ο (parityProjection Ο b) b := by | |
| have hca : (0 : β) < (support (parityProjection Ο b)).card := | |
| Nat.cast_pos.mpr (Finset.card_pos.mpr ha) | |
| have hb : (support b).Nonempty := by | |
| obtain β¨i, hiβ© := ha | |
| obtain β¨y, hy, _β© := projection_has_preimage Ο b i hi | |
| exact β¨y, hyβ© | |
| have hcb : (0 : β) < (support b).card := Nat.cast_pos.mpr (Finset.card_pos.mpr hb) | |
| have hsum : ((support (parityProjection Ο b)).card : β) β€ | |
| β i β support (parityProjection Ο b), | |
| (((support b).filter fun y => Ο y = i).card : β) := by | |
| calc | |
| _ = β _i β support (parityProjection Ο b), (1 : β) := by simp | |
| _ β€ _ := by | |
| apply Finset.sum_le_sum | |
| intro i hi | |
| obtain β¨y, hy, hΟβ© := projection_has_preimage Ο b i hi | |
| have hp : 0 < ((support b).filter fun y => Ο y = i).card := | |
| Finset.card_pos.mpr β¨y, Finset.mem_filter.mpr β¨hy, hΟβ©β© | |
| exact_mod_cast hp | |
| unfold agreementProbability | |
| apply (div_le_div_iffβ hcb (mul_pos hca hcb)).mpr | |
| nlinarith | |
| def decoderSuccess (Ο : J β I) (A : Cube I β Bool) (B : Cube J β Bool) : β := | |
| β b, coefficient (fun g => bitSign (B g)) b ^ 2 * | |
| (β a, coefficient (fun f => bitSign (A f)) a ^ 2 * agreementProbability Ο a b) | |
| def decodingEnergy (Ο : J β I) (A : Cube I β β) (B : Cube J β β) : β := | |
| β b, projectedCoefficient Ο A b ^ 2 * coefficient B b ^ 2 / (support b).card | |
| theorem decodingEnergy_le_success (Ο : J β I) (A : Cube I β Bool) (B : Cube J β Bool) | |
| (hzero : coefficient (fun f => bitSign (A f)) zeroMask = 0) : | |
| decodingEnergy Ο (fun f => bitSign (A f)) (fun g => bitSign (B g)) β€ | |
| decoderSuccess Ο A B := by | |
| unfold decodingEnergy decoderSuccess | |
| apply Finset.sum_le_sum | |
| intro b _ | |
| rw [projectedCoefficient_eq] | |
| have hsum : | |
| coefficient (fun f => bitSign (A f)) (parityProjection Ο b) ^ 2 * | |
| agreementProbability Ο (parityProjection Ο b) b β€ | |
| β a, coefficient (fun f => bitSign (A f)) a ^ 2 * agreementProbability Ο a b := by | |
| apply Finset.single_le_sum (s := Finset.univ) | |
| (f := fun a => coefficient (fun f => bitSign (A f)) a ^ 2 * agreementProbability Ο a b) | |
| Β· intro a _ | |
| exact mul_nonneg (sq_nonneg _) (agreementProbability_nonneg Ο a b) | |
| Β· exact Finset.mem_univ _ | |
| have hm := mul_le_mul_of_nonneg_left hsum | |
| (sq_nonneg (coefficient (fun g => bitSign (B g)) b)) | |
| by_cases ha : (support (parityProjection Ο b)).Nonempty | |
| Β· have hagree := agreementProbability_projection Ο b ha | |
| have ht := mul_le_mul_of_nonneg_left hagree | |
| (mul_nonneg (sq_nonneg (coefficient (fun f => bitSign (A f)) | |
| (parityProjection Ο b))) (sq_nonneg (coefficient (fun g => bitSign (B g)) b))) | |
| have heq : coefficient (fun f => bitSign (A f)) (parityProjection Ο b) ^ 2 * | |
| coefficient (fun g => bitSign (B g)) b ^ 2 / (support b).card = | |
| (coefficient (fun f => bitSign (A f)) (parityProjection Ο b) ^ 2 * | |
| coefficient (fun g => bitSign (B g)) b ^ 2) * (1 / (support b).card) := by ring | |
| rw [heq] | |
| exact ht.trans (by convert hm using 1; ring) | |
| Β· have hempty : support (parityProjection Ο b) = β := Finset.not_nonempty_iff_eq_empty.mp ha | |
| have hz := (support_eq_empty_iff _).mp hempty | |
| simpa [hz, hzero] using hm | |
| theorem bias_sq_le_weighted_energy (Ξ΅ : β) (Ο : J β I) | |
| (A : Cube I β β) (B : Cube J β Bool) : | |
| testBias Ξ΅ Ο A (fun g => bitSign (B g)) ^ 2 β€ | |
| β b, (projectedCoefficient Ο A b * coefficient (fun g => bitSign (B g)) b * | |
| (1 - 2 * Ξ΅) ^ (support b).card) ^ 2 := by | |
| rw [testBias_fourier] | |
| have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ | |
| (fun b => projectedCoefficient Ο A b * coefficient (fun g => bitSign (B g)) b * | |
| (1 - 2 * Ξ΅) ^ (support b).card) | |
| (fun b => coefficient (fun g => bitSign (B g)) b) | |
| rw [sign_parseval, mul_one] at h | |
| convert h using 1 | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro b _ | |
| ring | |
| theorem decoder_four_epsilon_bias_sq (Ξ΅ : β) (Ο : J β I) | |
| (A : Cube I β Bool) (B : Cube J β Bool) | |
| (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ β€ 1 / 2) | |
| (hzero : coefficient (fun f => bitSign (A f)) zeroMask = 0) : | |
| 4 * Ξ΅ * testBias Ξ΅ Ο (fun f => bitSign (A f)) (fun g => bitSign (B g)) ^ 2 β€ | |
| decoderSuccess Ο A B := by | |
| apply le_trans _ (decodingEnergy_le_success Ο A B hzero) | |
| have hcs := mul_le_mul_of_nonneg_left | |
| (bias_sq_le_weighted_energy Ξ΅ Ο (fun f => bitSign (A f)) B) | |
| (by linarith : 0 β€ 4 * Ξ΅) | |
| apply hcs.trans | |
| rw [Finset.mul_sum] | |
| unfold decodingEnergy | |
| apply Finset.sum_le_sum | |
| intro b _ | |
| by_cases hk : 0 < (support b).card | |
| Β· have hd := noise_decay_bound hΞ΅ hΞ΅' hk | |
| have hm := mul_le_mul_of_nonneg_left hd | |
| (mul_nonneg (sq_nonneg (projectedCoefficient Ο (fun f => bitSign (A f)) b)) | |
| (sq_nonneg (coefficient (fun g => bitSign (B g)) b))) | |
| convert hm using 1 <;> ring | |
| Β· have hb : support b = β := Finset.card_eq_zero.mp (by omega) | |
| have hbzero := (support_eq_empty_iff b).mp hb | |
| subst b | |
| simp [projectedCoefficient_eq, parityProjection_zero, hzero, support, zeroMask] | |
| theorem folded_decoder_bound (Ξ΅ : β) (Ο : J β I) | |
| (iβ : I) (table : HalfCube iβ β Bool) (B : Cube J β Bool) | |
| (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ β€ 1 / 2) : | |
| 4 * Ξ΅ * testBias Ξ΅ Ο (fun f => bitSign (foldedAnswer iβ table f)) | |
| (fun g => bitSign (B g)) ^ 2 β€ decoderSuccess Ο (foldedAnswer iβ table) B := by | |
| exact decoder_four_epsilon_bias_sq Ξ΅ Ο (foldedAnswer iβ table) B hΞ΅ hΞ΅' | |
| (foldedAnswer_zero_coefficient iβ table) | |
| def validAgreementProbability (valid : J β Bool) (Ο : J β I) | |
| (a : Cube I) (b : Cube J) : β := | |
| (β i β support a, | |
| (((support b).filter fun y => Ο y = i β§ valid y = true).card : β)) / | |
| ((support a).card * (support b).card : β) | |
| omit [DecidableEq J] in | |
| theorem validAgreementProbability_eq (valid : J β Bool) (Ο : J β I) | |
| (a : Cube I) (b : Cube J) (hb : β y β support b, valid y = true) : | |
| validAgreementProbability valid Ο a b = agreementProbability Ο a b := by | |
| unfold validAgreementProbability agreementProbability | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| congr 1 | |
| apply congrArg Finset.card | |
| apply Finset.filter_congr | |
| intro y hy | |
| simp [hb y hy] | |
| def validDecoderSuccess (valid : J β Bool) (Ο : J β I) | |
| (A : Cube I β Bool) (B : Cube J β Bool) : β := | |
| β b, coefficient (fun g => bitSign (B g)) b ^ 2 * | |
| (β a, coefficient (fun f => bitSign (A f)) a ^ 2 * | |
| validAgreementProbability valid Ο a b) | |
| theorem conditioned_validDecoderSuccess (valid : J β Bool) (Ο : J β I) | |
| (A : Cube I β Bool) (jβ : {j : J // valid j = true}) | |
| (table : HalfCube jβ β Bool) : | |
| validDecoderSuccess valid Ο A (conditionedFoldedAnswer valid jβ table) = | |
| decoderSuccess Ο A (conditionedFoldedAnswer valid jβ table) := by | |
| unfold validDecoderSuccess decoderSuccess | |
| apply Finset.sum_congr rfl | |
| intro b _ | |
| by_cases hc : coefficient (fun g => bitSign (conditionedFoldedAnswer valid jβ table g)) b = 0 | |
| Β· simp [hc] | |
| Β· have hb : β y β support b, valid y = true := by | |
| apply conditioned_coefficient_support valid (fun g => bitSign (foldedAnswer jβ table g)) b | |
| exact hc | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [validAgreementProbability_eq valid Ο a b hb] | |
| theorem conditioned_folded_decoder_bound (Ξ΅ : β) (Ο : J β I) (valid : J β Bool) | |
| (iβ : I) (tableA : HalfCube iβ β Bool) | |
| (jβ : {j : J // valid j = true}) (tableB : HalfCube jβ β Bool) | |
| (hΞ΅ : 0 < Ξ΅) (hΞ΅' : Ξ΅ β€ 1 / 2) : | |
| 4 * Ξ΅ * testBias Ξ΅ Ο (fun f => bitSign (foldedAnswer iβ tableA f)) | |
| (fun g => bitSign (conditionedFoldedAnswer valid jβ tableB g)) ^ 2 β€ | |
| validDecoderSuccess valid Ο (foldedAnswer iβ tableA) | |
| (conditionedFoldedAnswer valid jβ tableB) := by | |
| rw [conditioned_validDecoderSuccess] | |
| exact folded_decoder_bound Ξ΅ Ο iβ tableA | |
| (conditionedFoldedAnswer valid jβ tableB) hΞ΅ hΞ΅' | |
| end MinUncutGames.Foundations.Hastad | |
| end | |
| end | |
| end OAI | |