Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionSurvival.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 24.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionSurvival.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionSurvival.lean
-
curl -L -o CompressionSurvival.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionSurvival.lean
24.5 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Compression.CompressionConcentration | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.FixedBuckets | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.FiniteKernels | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.Magnitudes | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Representation.RepresentationResidues | |
| namespace OAI | |
| /-! | |
| # The compressed-block trial's actual solution bucket | |
| The seven compacted blocks and three raw domains are consecutive intervals | |
| of one uniform permutation. The only subsequent random draw is a prime. | |
| The residue of the fixed solution is enumerated by the program, not sampled. | |
| -/ | |
| noncomputable section | |
| namespace LowSpaceSubsetSum | |
| open scoped BigOperators | |
| attribute [local instance] Classical.propDecidable | |
| def compressionHalfSize (n : β) : β := mixerSize n / 2 | |
| def compressionRightRawSize (n : β) : β := n / 20 | |
| def compressionLeftRawSize (n : β) : β := n - 7 * compressionHalfSize n - compressionRightRawSize n | |
| def compressionPrimeExponent (n : β) : β := 249 * n / 1000 | |
| def compressionDictionaryCapacity (n : β) : β := 2 ^ (199 * n / 1000) | |
| def indexInterval (n start len : β) : Finset (Fin n) := | |
| Finset.univ.filter (fun i => start β€ i.val β§ i.val < start + len) | |
| theorem indexInterval_card {n start len : β} (h : start + len β€ n) : | |
| (indexInterval n start len).card = len := by | |
| let e : β₯(indexInterval n start len) β Fin len := | |
| { toFun := fun x => β¨x.val.val - start, by | |
| have hx := (Finset.mem_filter.mp x.property).2 | |
| omegaβ© | |
| invFun := fun x => β¨β¨start + x.val, by omegaβ©, by | |
| simp only [indexInterval, Finset.mem_filter, Finset.mem_univ, true_and] | |
| omegaβ© | |
| left_inv := by | |
| intro x | |
| apply Subtype.ext | |
| apply Fin.ext | |
| have hx := (Finset.mem_filter.mp x.property).2 | |
| dsimp | |
| omega | |
| right_inv := by intro x; apply Fin.ext; dsimp; omega } | |
| exact (Fintype.card_coe _).symm.trans ((Fintype.card_congr e).trans (Fintype.card_fin _)) | |
| def compressionBlock (n : β) (i : Fin 7) : Finset (Fin n) := | |
| indexInterval n (i.val * compressionHalfSize n) (compressionHalfSize n) | |
| def compressionLeftRaw (n : β) : Finset (Fin n) := | |
| indexInterval n (7 * compressionHalfSize n) (compressionLeftRawSize n) | |
| def compressionRightRaw (n : β) (i : Fin 2) : Finset (Fin n) := | |
| if i = 0 then | |
| indexInterval n (n - compressionRightRawSize n) (compressionRightRawSize n / 2) | |
| else indexInterval n (n - compressionRightRawSize n + compressionRightRawSize n / 2) | |
| (compressionRightRawSize n - compressionRightRawSize n / 2) | |
| theorem compressionHalfSize_eq (n : β) : compressionHalfSize n = 4 * (3 * n / 100) := by | |
| simp only [compressionHalfSize, mixerSize] | |
| omega | |
| theorem compression_layout_feasible (n : β) : | |
| 7 * compressionHalfSize n + compressionRightRawSize n β€ n := by | |
| rw [compressionHalfSize_eq] | |
| dsimp only [compressionRightRawSize] | |
| omega | |
| theorem compressionBlock_card (n : β) (i : Fin 7) : | |
| (compressionBlock n i).card = compressionHalfSize n := by | |
| apply indexInterval_card | |
| have hi := i.isLt | |
| have hf := compression_layout_feasible n | |
| nlinarith | |
| theorem compressionLeftRaw_card (n : β) : | |
| (compressionLeftRaw n).card = compressionLeftRawSize n := by | |
| apply indexInterval_card | |
| unfold compressionLeftRawSize | |
| have h := compression_layout_feasible n | |
| omega | |
| theorem compressionBlock_disjoint (n : β) {i j : Fin 7} (hij : i β j) : | |
| Disjoint (compressionBlock n i) (compressionBlock n j) := by | |
| apply Finset.disjoint_left.mpr | |
| intro x hx hy | |
| have hxi := (Finset.mem_filter.mp hx).2 | |
| have hxj := (Finset.mem_filter.mp hy).2 | |
| have hne : i.val β j.val := fun h => hij (Fin.ext h) | |
| rcases lt_or_gt_of_ne hne with hlt | hgt | |
| Β· have hm := Nat.mul_le_mul_right (compressionHalfSize n) | |
| (show i.val + 1 β€ j.val by omega) | |
| simp only [Nat.add_mul, one_mul] at hm | |
| omega | |
| Β· have hm := Nat.mul_le_mul_right (compressionHalfSize n) | |
| (show j.val + 1 β€ i.val by omega) | |
| simp only [Nat.add_mul, one_mul] at hm | |
| omega | |
| theorem compressionBlock_leftRaw_disjoint (n : β) (i : Fin 7) : | |
| Disjoint (compressionBlock n i) (compressionLeftRaw n) := by | |
| apply Finset.disjoint_left.mpr | |
| intro x hx hy | |
| have hxi := (Finset.mem_filter.mp hx).2 | |
| have hxy := (Finset.mem_filter.mp hy).2 | |
| have hi := i.isLt | |
| have hm := Nat.mul_le_mul_right (compressionHalfSize n) | |
| (show i.val + 1 β€ 7 by omega) | |
| simp only [Nat.add_mul, one_mul] at hm | |
| omega | |
| def compressionBaseLeft (n : β) : Finset (Fin n) := | |
| ((compressionBlock n 4 βͺ compressionBlock n 5) βͺ compressionBlock n 6) βͺ compressionLeftRaw n | |
| def compressionBaseRight (n : β) : Finset (Fin n) := | |
| ((compressionBlock n 0 βͺ compressionBlock n 1) βͺ compressionRightRaw n 0) βͺ | |
| ((compressionBlock n 2 βͺ compressionBlock n 3) βͺ compressionRightRaw n 1) | |
| theorem compressionBaseLeft_interval (n : β) : | |
| compressionBaseLeft n = indexInterval n (4 * compressionHalfSize n) | |
| (n - compressionRightRawSize n - 4 * compressionHalfSize n) := by | |
| ext x | |
| have hf := compression_layout_feasible n | |
| simp only [compressionBaseLeft, compressionBlock, compressionLeftRaw, indexInterval, | |
| Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and] | |
| unfold compressionLeftRawSize | |
| omega | |
| theorem compressionBaseRight_intervals (n : β) : | |
| compressionBaseRight n = indexInterval n 0 (4 * compressionHalfSize n) βͺ | |
| indexInterval n (n - compressionRightRawSize n) (compressionRightRawSize n) := by | |
| ext x | |
| have hx := x.isLt | |
| have hf := compression_layout_feasible n | |
| simp only [compressionBaseRight, compressionBlock, compressionRightRaw, indexInterval, | |
| Finset.mem_union, Finset.mem_filter, Finset.mem_univ, true_and, βreduceIte] | |
| norm_num only [Fin.zero_eta, Fin.isValue, Fin.reduceEq, βreduceIte, | |
| Finset.mem_filter, Finset.mem_univ, true_and] | |
| omega | |
| theorem compressionBaseRight_complement (n : β) : | |
| compressionBaseRight n = Finset.univ \ compressionBaseLeft n := by | |
| ext x | |
| have hx := x.isLt | |
| have hf := compression_layout_feasible n | |
| have hbound : 4 * compressionHalfSize n + | |
| (n - compressionRightRawSize n - 4 * compressionHalfSize n) = | |
| n - compressionRightRawSize n := by omega | |
| rw [compressionBaseRight_intervals, compressionBaseLeft_interval] | |
| simp only [indexInterval, | |
| Finset.mem_union, Finset.mem_filter, Finset.mem_sdiff, Finset.mem_univ, true_and, | |
| zero_le, zero_add, hbound] | |
| omega | |
| theorem compression_left_exponent {n : β} (hn : 40 β€ n) : | |
| ((3 * compressionCapExponent n + compressionLeftRawSize n : β) : β) < | |
| (179 / 400 : β) * n + 17 := by | |
| have hsize := mixerSize_bounds n | |
| have hh : mixerSize n = 2 * compressionHalfSize n := by | |
| rw [compressionHalfSize_eq] | |
| simp only [mixerSize] | |
| omega | |
| rw [hh, Nat.cast_mul, Nat.cast_ofNat] at hsize | |
| have hnR : (40 : β) β€ n := by exact_mod_cast hn | |
| have hslo : (3 / 25 : β) * n - 4 < compressionHalfSize n := by linarith [hsize.1] | |
| have hshi : (compressionHalfSize n : β) β€ (3 / 25 : β) * n := by linarith [hsize.2] | |
| have hapos : 0 β€ (compressionHalfSize n : β) - (3 / 400 : β) * n := by linarith | |
| have ha : (compressionCapExponent n : β) β€ | |
| compressionHalfSize n - (3 / 400 : β) * n := Nat.floor_le hapos | |
| have hRlo : (1 / 20 : β) * n - 1 < compressionRightRawSize n := by | |
| have hnat : n < 20 * (n / 20 + 1) := by omega | |
| have hr : (n : β) < 20 * ((n / 20 : β) + 1 : β) := by exact_mod_cast hnat | |
| dsimp only [compressionRightRawSize] | |
| linarith | |
| have hf := compression_layout_feasible n | |
| have hsum : compressionLeftRawSize n + 7 * compressionHalfSize n + | |
| compressionRightRawSize n = n := by unfold compressionLeftRawSize; omega | |
| have hsumR : (compressionLeftRawSize n : β) + 7 * compressionHalfSize n + | |
| compressionRightRawSize n = n := by exact_mod_cast hsum | |
| push_cast | |
| linarith | |
| theorem compression_prime_floor (n : β) : | |
| (249 / 1000 : β) * n - 1 < compressionPrimeExponent n := by | |
| have hnat : 249 * n < 1000 * (249 * n / 1000 + 1) := by omega | |
| have hr : (249 : β) * n < 1000 * ((249 * n / 1000 : β) + 1 : β) := by | |
| exact_mod_cast hnat | |
| dsimp only [compressionPrimeExponent] | |
| linarith | |
| theorem compression_capacity_lower (n : β) : | |
| (2 : β) ^ ((199 / 1000 : β) * n - 1) β€ compressionDictionaryCapacity n := by | |
| have hnat : 199 * n < 1000 * (199 * n / 1000 + 1) := by omega | |
| have hr : (199 : β) * n < 1000 * ((199 * n / 1000 : β) + 1 : β) := by | |
| exact_mod_cast hnat | |
| have he : (199 / 1000 : β) * n - 1 β€ (199 * n / 1000 : β) := by linarith | |
| have hp := Real.rpow_le_rpow_of_exponent_le (by norm_num : (1 : β) β€ 2) he | |
| simpa only [compressionDictionaryCapacity, Real.rpow_natCast, Nat.cast_pow, Nat.cast_ofNat] | |
| using hp | |
| theorem compression_bucket_loss_le_half {n : β} (hn : 100000 β€ n) {u : β} | |
| (hu : 0 < u) (hlog : Real.logb 2 u β€ (n : β) / 1000000000) : | |
| 16 * u ^ 2 * (2 : β) ^ (3 * compressionCapExponent n + compressionLeftRawSize n) / | |
| ((compressionDictionaryCapacity n : β) * (2 : β) ^ compressionPrimeExponent n) β€ 1 / 2 := by | |
| have hu2 : u ^ 2 = (2 : β) ^ (2 * Real.logb 2 u) := by | |
| have h := Real.rpow_mul_natCast (by norm_num : (0 : β) β€ 2) (Real.logb 2 u) 2 | |
| rw [Real.rpow_logb (by norm_num) (by norm_num) hu] at h | |
| simpa only [Nat.cast_ofNat, mul_comm] using h.symm | |
| have hnR : (100000 : β) β€ n := by exact_mod_cast hn | |
| have he := compression_left_exponent (by omega : 40 β€ n) | |
| have hnum : 16 * u ^ 2 * (2 : β) ^ (3 * compressionCapExponent n + compressionLeftRawSize n) β€ | |
| (2 : β) ^ ((56 / 125 : β) * n - 3) := by | |
| have hid : 16 * u ^ 2 * (2 : β) ^ (3 * compressionCapExponent n + compressionLeftRawSize n) = | |
| (2 : β) ^ (4 + 2 * Real.logb 2 u + | |
| ((3 * compressionCapExponent n + compressionLeftRawSize n : β) : β)) := by | |
| rw [Real.rpow_add (by norm_num), Real.rpow_add (by norm_num), β hu2, | |
| Real.rpow_natCast] | |
| norm_num | |
| rw [hid] | |
| apply Real.rpow_le_rpow_of_exponent_le (by norm_num) | |
| linarith | |
| have hp : (2 : β) ^ ((249 / 1000 : β) * n - 1) β€ | |
| (2 : β) ^ compressionPrimeExponent n := by | |
| have h := Real.rpow_le_rpow_of_exponent_le (by norm_num : (1 : β) β€ 2) | |
| (compression_prime_floor n).le | |
| simpa only [Real.rpow_natCast] using h | |
| have hden : (2 : β) ^ ((56 / 125 : β) * n - 2) β€ | |
| (compressionDictionaryCapacity n : β) * (2 : β) ^ compressionPrimeExponent n := by | |
| calc | |
| _ = (2 : β) ^ ((199 / 1000 : β) * n - 1) * | |
| (2 : β) ^ ((249 / 1000 : β) * n - 1) := by | |
| rw [β Real.rpow_add (by norm_num)] | |
| congr 1 | |
| ring | |
| _ β€ _ := mul_le_mul (compression_capacity_lower n) hp (by positivity) (by positivity) | |
| have hrel : 2 * (2 : β) ^ ((56 / 125 : β) * n - 3) = | |
| (2 : β) ^ ((56 / 125 : β) * n - 2) := by | |
| rw [show (56 / 125 : β) * n - 2 = 1 + ((56 / 125 : β) * n - 3) by ring, | |
| Real.rpow_add (by norm_num), Real.rpow_one] | |
| have hcap : (0 : β) < compressionDictionaryCapacity n := by | |
| exact_mod_cast (pow_pos (by decide : 0 < (2 : β)) (199 * n / 1000)) | |
| apply (div_le_iffβ (mul_pos hcap (by positivity))).mpr | |
| nlinarith | |
| structure CompressionSetup (n : β) where | |
| input : Instance n | |
| solution : Finset (Fin n) | |
| solution_weight : weight (fun i => (input.values i : β€)) solution = input.target | |
| namespace CompressionSetup | |
| variable {n : β} (R : CompressionSetup n) | |
| def weights : Fin n β β€ := fun i => R.input.values i | |
| def block (_R : CompressionSetup n) (e : Equiv.Perm (Fin n)) (i : Fin 7) : Finset (Fin n) := | |
| permuteSubset e (compressionBlock n i) | |
| def leftRaw (_R : CompressionSetup n) (e : Equiv.Perm (Fin n)) : Finset (Fin n) := | |
| permuteSubset e (compressionLeftRaw n) | |
| def leftDomain (e : Equiv.Perm (Fin n)) : Finset (Fin n) := | |
| ((R.block e 4 βͺ R.block e 5) βͺ R.block e 6) βͺ R.leftRaw e | |
| def rightDomain (e : Equiv.Perm (Fin n)) : Finset (Fin n) := | |
| Finset.univ \ R.leftDomain e | |
| def rightRaw (e : Equiv.Perm (Fin n)) (i : Fin 2) : Finset (Fin n) := | |
| permuteSubset e (compressionRightRaw n i) | |
| /-- The four rows in the compression table, with their actual index domains. -/ | |
| def groupDomain (e : Equiv.Perm (Fin n)) : Fin 4 β Finset (Fin n) := | |
| ![R.block e 4 βͺ R.block e 5, R.block e 6 βͺ R.leftRaw e, | |
| (R.block e 0 βͺ R.block e 1) βͺ rightRaw e 0, | |
| (R.block e 2 βͺ R.block e 3) βͺ rightRaw e 1] | |
| def groupWeights (e : Equiv.Perm (Fin n)) (i : Fin 4) : Finset β€ := | |
| distinctSums R.weights (R.groupDomain e i) | |
| theorem leftDomain_eq_groups (e : Equiv.Perm (Fin n)) : | |
| R.leftDomain e = R.groupDomain e 0 βͺ R.groupDomain e 1 := by | |
| change ((_ βͺ _) βͺ _) βͺ _ = (_ βͺ _) βͺ (_ βͺ _) | |
| rw [Finset.union_assoc] | |
| theorem rightDomain_eq_groups (e : Equiv.Perm (Fin n)) : | |
| R.rightDomain e = R.groupDomain e 2 βͺ R.groupDomain e 3 := by | |
| have hl : R.leftDomain e = permuteSubset e (compressionBaseLeft n) := by | |
| simp only [leftDomain, block, leftRaw, compressionBaseLeft, permuteSubset, Finset.map_union] | |
| have hr : R.groupDomain e 2 βͺ R.groupDomain e 3 = | |
| permuteSubset e (compressionBaseRight n) := by | |
| change ((R.block e 0 βͺ R.block e 1) βͺ rightRaw e 0) βͺ | |
| ((R.block e 2 βͺ R.block e 3) βͺ rightRaw e 1) = _ | |
| simp only [block, rightRaw, compressionBaseRight, permuteSubset, Finset.map_union] | |
| rw [rightDomain, hl, hr, compressionBaseRight_complement, permuteSubset_sdiff] | |
| congr 1 | |
| exact (Finset.map_univ_equiv e).symm | |
| def blockWeights (e : Equiv.Perm (Fin n)) (i : Fin 7) : Finset β€ := | |
| distinctSums R.weights (R.block e i) | |
| def leftWeights (e : Equiv.Perm (Fin n)) : Finset β€ := | |
| distinctSums R.weights (R.leftDomain e) | |
| def rightWeights (e : Equiv.Perm (Fin n)) : Finset β€ := | |
| distinctSums R.weights (R.rightDomain e) | |
| def solutionLeft (e : Equiv.Perm (Fin n)) : Finset (Fin n) := R.solution β© R.leftDomain e | |
| def solutionRight (e : Equiv.Perm (Fin n)) : Finset (Fin n) := R.solution \ R.leftDomain e | |
| def leftWeight (e : Equiv.Perm (Fin n)) : β€ := weight R.weights (R.solutionLeft e) | |
| def rightWeight (e : Equiv.Perm (Fin n)) : β€ := weight R.weights (R.solutionRight e) | |
| def Passing (e : Equiv.Perm (Fin n)) : Prop := | |
| β i, (R.blockWeights e i).card β€ 2 ^ compressionCapExponent n | |
| theorem leftWeight_mem (e : Equiv.Perm (Fin n)) : R.leftWeight e β R.leftWeights e := | |
| (mem_distinctSums _ _ _).mpr β¨_, Finset.inter_subset_right, rflβ© | |
| theorem rightWeight_mem (e : Equiv.Perm (Fin n)) : R.rightWeight e β R.rightWeights e := | |
| (mem_distinctSums _ _ _).mpr β¨_, fun _ hx => Finset.mem_sdiff.mpr | |
| β¨Finset.mem_univ _, (Finset.mem_sdiff.mp hx).2β©, rflβ© | |
| theorem solution_split (e : Equiv.Perm (Fin n)) : | |
| R.leftWeight e + R.rightWeight e = R.input.target := by | |
| have hd : Disjoint (R.solutionLeft e) (R.solutionRight e) := | |
| Finset.disjoint_sdiff_inter _ _ |>.symm | |
| have hcover : R.solutionLeft e βͺ R.solutionRight e = R.solution := by | |
| ext x | |
| simp only [solutionLeft, solutionRight, Finset.mem_union, Finset.mem_inter, Finset.mem_sdiff] | |
| tauto | |
| rw [leftWeight, rightWeight, β weight_union _ hd, hcover] | |
| exact R.solution_weight | |
| theorem four_group_solution (e : Equiv.Perm (Fin n)) : | |
| β x : Fin 4 β β€, (β i, x i β R.groupWeights e i) β§ | |
| x 0 + x 1 = R.leftWeight e β§ x 2 + x 3 = R.rightWeight e := by | |
| have hl := R.leftWeight_mem e | |
| have hr := R.rightWeight_mem e | |
| rw [leftWeights, R.leftDomain_eq_groups e] at hl | |
| rw [rightWeights, R.rightDomain_eq_groups e] at hr | |
| obtain β¨l, hl, hwlβ© := Finset.mem_image.mp | |
| (distinctSums_union_subset R.weights (R.groupDomain e 0) (R.groupDomain e 1) hl) | |
| obtain β¨r, hr, hwrβ© := Finset.mem_image.mp | |
| (distinctSums_union_subset R.weights (R.groupDomain e 2) (R.groupDomain e 3) hr) | |
| obtain β¨hl0, hl1β© := Finset.mem_product.mp hl | |
| obtain β¨hr0, hr1β© := Finset.mem_product.mp hr | |
| refine β¨![l.1, l.2, r.1, r.2], ?_, hwl, hwrβ© | |
| intro i | |
| fin_cases i | |
| Β· exact hl0 | |
| Β· exact hl1 | |
| Β· exact hr0 | |
| Β· exact hr1 | |
| theorem passing_probability (hn : 168000000 β€ n) | |
| (hmean : (153 / 20000 : β) * n β€ | |
| meanDeficiency R.weights Finset.univ (compressionHalfSize n)) : | |
| (1 / 2 : β) β€ finiteUniformProbability R.Passing := | |
| compression_size_tests_probability hn R.weights (compressionBlock n) | |
| (compressionBlock_card n) hmean | |
| theorem leftWeights_card (e : Equiv.Perm (Fin n)) (he : R.Passing e) : | |
| (R.leftWeights e).card β€ 2 ^ (3 * compressionCapExponent n + compressionLeftRawSize n) := by | |
| have h4 := he 4 | |
| have h5 := he 5 | |
| have h6 := he 6 | |
| have hr : distinctSumCount R.weights (R.leftRaw e) β€ 2 ^ compressionLeftRawSize n := by | |
| simpa only [leftRaw, permuteSubset_card, compressionLeftRaw_card] using | |
| distinctSumCount_le_pow R.weights (R.leftRaw e) | |
| apply (distinctSumCount_union_le _ _ _).trans | |
| apply (Nat.mul_le_mul (distinctSumCount_union_le _ _ _) (le_refl _)).trans | |
| apply (Nat.mul_le_mul (Nat.mul_le_mul (distinctSumCount_union_le _ _ _) | |
| (le_refl _)) (le_refl _)).trans | |
| have hp := Nat.mul_le_mul (Nat.mul_le_mul (Nat.mul_le_mul h4 h5) h6) hr | |
| have heq : compressionCapExponent n + compressionCapExponent n + compressionCapExponent n + | |
| compressionLeftRawSize n = 3 * compressionCapExponent n + compressionLeftRawSize n := by omega | |
| simpa only [β pow_add, heq, blockWeights, distinctSumCount] using hp | |
| abbrev PrimeSpace (n : β) := β₯(primeRange (compressionPrimeExponent n)) | |
| def BucketFits (e : Equiv.Perm (Fin n)) (q : PrimeSpace n) : Prop := | |
| (hashBucket (R.leftWeights e) id (fun w => w % (q.val : β€)) (R.leftWeight e)).card β€ | |
| compressionDictionaryCapacity n | |
| theorem leftWeights_magnitude (e : Equiv.Perm (Fin n)) {x : β€} | |
| (hx : x β R.leftWeights e) : x.natAbs β€ n * 2 ^ inputBits R.input := by | |
| obtain β¨S, _, rflβ© := (mem_distinctSums R.weights (R.leftDomain e) x).mp hx | |
| simpa only [Fintype.card_fin] using weight_natAbs_le R.weights S | |
| (M := 2 ^ inputBits R.input) (fun i => by | |
| simpa only [weights, Int.natAbs_natCast] using (value_lt_two_pow_bits R.input i).le) | |
| theorem bucketFits_probability (hn : 168000000 β€ n) | |
| (hlog : Real.logb 2 (inputScale R.input) β€ (n : β) / 1000000000) | |
| (e : Equiv.Perm (Fin n)) (he : R.Passing e) : | |
| (1 / 2 : β) β€ finiteUniformProbability (R.BucketFits e) := by | |
| have hell : 4 β€ compressionPrimeExponent n := by unfold compressionPrimeExponent; omega | |
| have hellu : compressionPrimeExponent n β€ inputScale R.input := by | |
| unfold compressionPrimeExponent inputScale | |
| omega | |
| have hcap : 2 β€ compressionDictionaryCapacity n := by | |
| have hpow := Nat.pow_le_pow_right (by decide : 0 < (2 : β)) | |
| (show 1 β€ 199 * n / 1000 by omega) | |
| simpa only [pow_one, compressionDictionaryCapacity] using hpow | |
| have hx := R.leftWeight_mem e | |
| have hequal : sameWeightKeys (R.leftWeights e) id (R.leftWeight e) = {R.leftWeight e} := by | |
| ext y | |
| simp only [sameWeightKeys, Finset.mem_filter, id_eq, Finset.mem_singleton] | |
| exact β¨fun h => h.2, fun h => β¨h.symm βΈ hx, hβ©β© | |
| have hp := prime_fixed_bucket_fits_probability (R.leftWeights e) id hx hell hellu | |
| (by omega : 0 < compressionDictionaryCapacity n) | |
| (by | |
| rw [hequal, Finset.card_singleton] | |
| have hcR : (2 : β) β€ compressionDictionaryCapacity n := by exact_mod_cast hcap | |
| push_cast | |
| linarith) | |
| (fun x hx y hy => relevant_difference_bits R.input | |
| ((R.leftWeights_magnitude e hx).trans (by gcongr; omega)) | |
| ((R.leftWeights_magnitude e hy).trans (by gcongr; omega))) | |
| have hcount : ((R.leftWeights e).card : β) β€ | |
| (2 : β) ^ (3 * compressionCapExponent n + compressionLeftRawSize n) := by | |
| exact_mod_cast R.leftWeights_card e he | |
| have hu : (0 : β) < inputScale R.input := by unfold inputScale; positivity | |
| have hden : (0 : β) < (compressionDictionaryCapacity n : β) * | |
| (2 : β) ^ compressionPrimeExponent n := by positivity | |
| have hloss : 16 * (inputScale R.input : β) ^ 2 * (R.leftWeights e).card / | |
| ((compressionDictionaryCapacity n : β) * (2 : β) ^ compressionPrimeExponent n) β€ 1 / 2 := by | |
| apply le_trans _ (compression_bucket_loss_le_half (by omega) hu hlog) | |
| exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hcount (by positivity)) hden.le | |
| have hprob : finiteUniformProbability (R.BucketFits e) = | |
| β p β (primeRange (compressionPrimeExponent n)).filter (fun (p : β) => | |
| (hashBucket (R.leftWeights e) id (fun w => w % (p : β€)) (R.leftWeight e)).card β€ | |
| compressionDictionaryCapacity n), primeProbability (compressionPrimeExponent n) p := by | |
| unfold BucketFits | |
| rw [finiteUniformProbability_finset (primeRange (compressionPrimeExponent n)) | |
| (fun p : β => (hashBucket (R.leftWeights e) id (fun w => w % (p : β€)) | |
| (R.leftWeight e)).card β€ compressionDictionaryCapacity n)] | |
| simp [primeProbability, div_eq_mul_inv, mul_comm] | |
| rw [hprob] | |
| linarith | |
| abbrev TrialHistory (n : β) := Ξ£ _e : Equiv.Perm (Fin n), PrimeSpace n | |
| def primeLaw (hn : 168000000 β€ n) : FiniteLaw (PrimeSpace n) := by | |
| have hell : 4 β€ compressionPrimeExponent n := by unfold compressionPrimeExponent; omega | |
| let : Nonempty (PrimeSpace n) := | |
| β¨β¨(primeRange_nonempty hell).choose, (primeRange_nonempty hell).choose_specβ©β© | |
| exact FiniteLaw.uniform | |
| def trialLaw (_R : CompressionSetup n) (hn : 168000000 β€ n) : FiniteLaw (TrialHistory n) := | |
| (FiniteLaw.uniform : FiniteLaw (Equiv.Perm (Fin n))).bind (fun _ => PrimeSpace n) | |
| (fun _ => primeLaw hn) | |
| def Successful (h : TrialHistory n) : Prop := R.Passing h.1 β§ R.BucketFits h.1 h.2 | |
| /-- A passing partition has probability at least one half, and conditional | |
| on every such actual partition its fixed solution bucket fits with probability | |
| at least one half. No uniform residue guess appears in this experiment. -/ | |
| theorem successful_probability (hn : 168000000 β€ n) | |
| (hmean : (153 / 20000 : β) * n β€ | |
| meanDeficiency R.weights Finset.univ (compressionHalfSize n)) | |
| (hlog : Real.logb 2 (inputScale R.input) β€ (n : β) / 1000000000) : | |
| (1 / 4 : β) β€ (R.trialLaw hn).probability R.Successful := by | |
| have hp : (1 / 2 : β) β€ (FiniteLaw.uniform : FiniteLaw (Equiv.Perm (Fin n))).probability | |
| R.Passing := by rw [FiniteLaw.uniform_probability]; exact R.passing_probability hn hmean | |
| have h := FiniteLaw.bind_good_lower (FiniteLaw.uniform : FiniteLaw (Equiv.Perm (Fin n))) | |
| (fun _ => PrimeSpace n) (fun _ => primeLaw hn) R.Passing R.BucketFits | |
| (by norm_num : (0 : β) β€ 1 / 2) hp (fun e he => by | |
| have hell : 4 β€ compressionPrimeExponent n := by unfold compressionPrimeExponent; omega | |
| let : Nonempty (PrimeSpace n) := | |
| β¨β¨(primeRange_nonempty hell).choose, (primeRange_nonempty hell).choose_specβ©β© | |
| rw [primeLaw, FiniteLaw.uniform_probability] | |
| exact R.bucketFits_probability hn hlog e he) | |
| norm_num at h β’ | |
| exact h | |
| /-- The loop scans this residue among all `0,β¦,qβ1`. Its dictionary is | |
| small enough and contains the fixed solution's left weight. -/ | |
| theorem designated_bucket_witness (e : Equiv.Perm (Fin n)) (q : PrimeSpace n) | |
| (hq : R.BucketFits e q) : | |
| β z : Fin q.val, β x : Fin 4 β β€, | |
| (β i, x i β R.groupWeights e i) β§ | |
| x 0 + x 1 + (x 2 + x 3) = R.input.target β§ | |
| x 0 + x 1 β‘ (z.val : β€) [ZMOD (q.val : β€)] β§ | |
| x 2 + x 3 β‘ (R.input.target : β€) - z.val [ZMOD (q.val : β€)] β§ | |
| (R.leftWeights e |>.filter (fun w => w % (q.val : β€) = z.val)).card β€ | |
| compressionDictionaryCapacity n := by | |
| have hpos := (primeRange_prime q.property).pos | |
| let z := normalizedResidue hpos (R.leftWeight e) | |
| obtain β¨x, hx, hl, hrβ© := R.four_group_solution e | |
| have hmod : R.leftWeight e β‘ (z.val : β€) [ZMOD (q.val : β€)] := | |
| normalizedResidue_eq_modEq hpos _ z rfl | |
| have hright : R.rightWeight e = (R.input.target : β€) - R.leftWeight e := by | |
| have hs := R.solution_split e | |
| omega | |
| refine β¨z, x, hx, ?_, ?_, ?_, ?_β© | |
| Β· rw [hl, hr] | |
| exact R.solution_split e | |
| Β· rwa [hl] | |
| Β· rw [hr, hright] | |
| exact (Int.ModEq.refl (R.input.target : β€)).sub hmod | |
| Β· have hz : (z.val : β€) = R.leftWeight e % (q.val : β€) := normalizedResidue_cast hpos _ | |
| simpa only [BucketFits, hashBucket, id_eq, hz] using hq | |
| end CompressionSetup | |
| end LowSpaceSubsetSum | |
| end | |
| end OAI | |