math / data /lean /OAI /Combinatorics /LowSpaceSubsetSum /Representation /RepresentationExtraPrime.lean
Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationExtraPrime.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.97 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationExtraPrime.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationExtraPrime.lean
-
curl -L -o RepresentationExtraPrime.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Representation/RepresentationExtraPrime.lean
9.97 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Representation.RepresentationChosenStreams | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.FixedBuckets | |
| namespace OAI | |
| /-! # The concrete extra-prime parameter and its hashing bounds -/ | |
| noncomputable section | |
| namespace LowSpaceSubsetSum.RepresentationSetup | |
| open scoped BigOperators | |
| variable {n : β} (R : RepresentationSetup n) | |
| theorem filterDeficit_mono (z : Layout n) : Monotone (R.filterDeficit z) := by | |
| intro i j hij | |
| have h := R.lowExponent_antitone z hij | |
| rw [R.lowExponent_eq_half_sub, R.lowExponent_eq_half_sub] at h | |
| linarith | |
| theorem filterDeficit_nonneg (z : Layout n) (i : Fin 3) : 0 β€ R.filterDeficit z i := | |
| le_min (by positivity) (div_nonneg (deficiency_nonneg _ _) (by norm_num)) | |
| /-- This is the manuscript's maximum over the three ordered mixers. -/ | |
| def extraPrimeRate (z : Layout n) : β := | |
| extraPrimeExponent n (mixerSize n) (R.filterDeficit z 2) | |
| theorem extraPrimeRate_max (z : Layout n) : | |
| R.extraPrimeRate z = extraPrimeExponent n (mixerSize n) | |
| (max (R.filterDeficit z 0) (max (R.filterDeficit z 1) (R.filterDeficit z 2))) := by | |
| rw [max_eq_right (R.filterDeficit_mono z (by decide : (1 : Fin 3) β€ 2)), | |
| max_eq_right (R.filterDeficit_mono z (by decide : (0 : Fin 3) β€ 2))] | |
| rfl | |
| /-- The actual integer sampling parameter, including both floors. -/ | |
| def extraPrimeParameter (z : Layout n) : β := | |
| β(n : β) / 4 + (4 / 125 : β) * mixerSize n - (mixerSize n : β) / 2 + | |
| (min βR.lowExponent z 0ββ (min βR.lowExponent z 1ββ βR.lowExponent z 2ββ) : β)ββ | |
| theorem extraPrimeParameter_eq (z : Layout n) : | |
| R.extraPrimeParameter z = | |
| β(n : β) / 4 + (4 / 125 : β) * mixerSize n - (mixerSize n : β) / 2 + | |
| (βR.lowExponent z 2ββ : β)ββ := by | |
| have h12 := Nat.floor_mono (R.lowExponent_antitone z (by decide : (1 : Fin 3) β€ 2)) | |
| have h02 := Nat.floor_mono (R.lowExponent_antitone z (by decide : (0 : Fin 3) β€ 2)) | |
| simp only [extraPrimeParameter, min_eq_right h12, min_eq_right h02] | |
| theorem extraPrimeRate_bounds (z : Layout n) : | |
| (1211 / 5000 : β) * n β€ R.extraPrimeRate z β§ | |
| R.extraPrimeRate z β€ (3221 / 12500 : β) * n := by | |
| have hf := R.filterDeficit_le_tau z 2 | |
| have hf0 := R.filterDeficit_nonneg z 2 | |
| have hm0 : (0 : β) β€ mixerSize n := Nat.cast_nonneg _ | |
| have hm := (mixerSize_bounds n).2 | |
| dsimp only [extraPrimeRate, extraPrimeExponent] | |
| constructor <;> linarith | |
| theorem extraPrimeParameter_bounds (z : Layout n) (hn : 100 β€ n) : | |
| R.extraPrimeRate z - 2 < (R.extraPrimeParameter z : β) β§ | |
| (R.extraPrimeParameter z : β) β€ R.extraPrimeRate z := by | |
| rw [R.extraPrimeParameter_eq] | |
| have hl := Nat.lt_floor_add_one (R.lowExponent z 2) | |
| have hu := Nat.floor_le (R.lowExponent_nonneg z 2) | |
| have he := R.lowExponent_eq_half_sub z 2 | |
| have hx := (R.extraPrimeRate_bounds z).1 | |
| have hnR : (100 : β) β€ n := by exact_mod_cast hn | |
| let y := (n : β) / 4 + (4 / 125 : β) * mixerSize n - (mixerSize n : β) / 2 + | |
| (βR.lowExponent z 2ββ : β) | |
| have hylo : R.extraPrimeRate z - 1 < y := by | |
| dsimp only [extraPrimeRate, extraPrimeExponent, y] at * | |
| linarith | |
| have hyhi : y β€ R.extraPrimeRate z := by | |
| dsimp only [extraPrimeRate, extraPrimeExponent, y] at * | |
| linarith | |
| have hy0 : 0 β€ y := by linarith | |
| have hyl := Nat.lt_floor_add_one y | |
| have hyu := Nat.floor_le hy0 | |
| change R.extraPrimeRate z - 2 < (βyββ : β) β§ (βyββ : β) β€ R.extraPrimeRate z | |
| constructor <;> linarith | |
| theorem extraPrimeParameter_range (z : Layout n) (hn : 100 β€ n) : | |
| 4 β€ R.extraPrimeParameter z β§ R.extraPrimeParameter z β€ n := by | |
| have h := R.extraPrimeParameter_bounds z hn | |
| have hx := R.extraPrimeRate_bounds z | |
| have hnR : (100 : β) β€ n := by exact_mod_cast hn | |
| constructor | |
| Β· have hl : (4 : β) β€ R.extraPrimeParameter z := by linarith | |
| exact_mod_cast hl | |
| Β· have hu : (R.extraPrimeParameter z : β) β€ n := by linarith | |
| exact_mod_cast hu | |
| /-- Rejection sampling in the full bit range has inverse-polynomial density. -/ | |
| theorem extraPrime_density (z : Layout n) (hn : 100 β€ n) : | |
| 1 / (4 * (n : β)) β€ | |
| ((primeRange (R.extraPrimeParameter z)).card : β) / | |
| (2 : β) ^ R.extraPrimeParameter z := by | |
| have hr := R.extraPrimeParameter_range z hn | |
| have hc : (2 : β) ^ R.extraPrimeParameter z β€ | |
| 4 * R.extraPrimeParameter z * (primeRange (R.extraPrimeParameter z)).card := by | |
| exact_mod_cast primeRange_card_lower hr.1 | |
| have he : (R.extraPrimeParameter z : β) β€ n := by exact_mod_cast hr.2 | |
| have hnR : (100 : β) β€ n := by exact_mod_cast hn | |
| have hm := mul_le_mul_of_nonneg_right he | |
| (show 0 β€ (primeRange (R.extraPrimeParameter z)).card * (4 : β) by positivity) | |
| apply (div_le_div_iffβ (by positivity) (by positivity)).mpr | |
| nlinarith | |
| /-- Every sampled extra prime has the manuscript's actual size bounds. -/ | |
| theorem extraPrime_size (z : Layout n) (hn : 100 β€ n) {q : β} | |
| (hq : q β primeRange (R.extraPrimeParameter z)) : | |
| (2 : β) ^ R.extraPrimeRate z / (inputScale R.input : β) ^ 2 β€ q β§ | |
| (q : β) β€ (2 : β) ^ R.extraPrimeRate z := by | |
| have hr := R.extraPrimeParameter_range z hn | |
| have hf := R.extraPrimeParameter_bounds z hn | |
| have hu : (100 : β) β€ inputScale R.input := by | |
| exact_mod_cast (show 100 β€ inputScale R.input by unfold inputScale; omega) | |
| have hellu : (R.extraPrimeParameter z : β) β€ inputScale R.input := by | |
| exact_mod_cast (show R.extraPrimeParameter z β€ inputScale R.input by | |
| exact hr.2.trans (by unfold inputScale; omega)) | |
| have hqlo : (2 : β) ^ R.extraPrimeParameter z β€ | |
| 4 * R.extraPrimeParameter z * (q : β) := by | |
| exact_mod_cast (Finset.mem_filter.mp hq).2 | |
| have hq0 : (0 : β) β€ q := Nat.cast_nonneg _ | |
| have hp : (2 : β) ^ R.extraPrimeRate z β€ | |
| 4 * (2 : β) ^ R.extraPrimeParameter z := by | |
| calc | |
| _ β€ (2 : β) ^ ((R.extraPrimeParameter z : β) + 2) := | |
| Real.rpow_le_rpow_of_exponent_le (by norm_num) (by linarith) | |
| _ = _ := by rw [Real.rpow_add (by norm_num), Real.rpow_natCast]; norm_num; ring | |
| constructor | |
| Β· apply (div_le_iffβ (by positivity : (0 : β) < (inputScale R.input : β) ^ 2)).mpr | |
| have hku := mul_le_mul_of_nonneg_right hellu hq0 | |
| have hu2 : 16 * (inputScale R.input : β) β€ (inputScale R.input : β) ^ 2 := by nlinarith | |
| have huu := mul_le_mul_of_nonneg_right hu2 hq0 | |
| nlinarith | |
| Β· have hqhi : (q : β) β€ (2 : β) ^ R.extraPrimeParameter z := by | |
| exact_mod_cast (primeRange_lt hr.1 hq).le | |
| apply hqhi.trans | |
| simpa only [Real.rpow_natCast] using | |
| Real.rpow_le_rpow_of_exponent_le (by norm_num : (1 : β) β€ 2) hf.2 | |
| /-- Prime hashing bound with the paper's simplified cubic input-scale factor. -/ | |
| theorem extraPrime_collision (z : Layout n) (hn : 100 β€ n) (X : Finset β€) | |
| (hbits : β x β X, β y β X, (x - y).natAbs < 2 ^ (2 * inputScale R.input)) : | |
| PairwiseCollisionBound (primeRange (R.extraPrimeParameter z)) | |
| (primeProbability (R.extraPrimeParameter z)) X | |
| (fun q x => x % (q : β€)) | |
| ((inputScale R.input : β) ^ 3 / (2 : β) ^ R.extraPrimeRate z) := by | |
| have hr := R.extraPrimeParameter_range z hn | |
| have hellu : R.extraPrimeParameter z β€ inputScale R.input := | |
| hr.2.trans (by unfold inputScale; omega) | |
| have hcol := prime_pairwise_collision_bound X hr.1 hellu hbits | |
| have hu : (100 : β) β€ inputScale R.input := by | |
| exact_mod_cast (show 100 β€ inputScale R.input by unfold inputScale; omega) | |
| have hpow : (2 : β) ^ R.extraPrimeRate z β€ | |
| 4 * (2 : β) ^ R.extraPrimeParameter z := by | |
| calc | |
| _ β€ (2 : β) ^ ((R.extraPrimeParameter z : β) + 2) := | |
| Real.rpow_le_rpow_of_exponent_le (by norm_num) | |
| (by linarith [(R.extraPrimeParameter_bounds z hn).1]) | |
| _ = _ := by rw [Real.rpow_add (by norm_num), Real.rpow_natCast]; norm_num; ring | |
| have hdelta : 8 * (inputScale R.input : β) ^ 2 / | |
| (2 : β) ^ R.extraPrimeParameter z β€ | |
| (inputScale R.input : β) ^ 3 / (2 : β) ^ R.extraPrimeRate z := by | |
| apply (div_le_div_iffβ (by positivity) (by positivity)).mpr | |
| have hu3 : 32 * (inputScale R.input : β) ^ 2 β€ (inputScale R.input : β) ^ 3 := by | |
| nlinarith [mul_nonneg (show 0 β€ (inputScale R.input : β) - 32 by linarith) | |
| (sq_nonneg (inputScale R.input : β))] | |
| have he3 := mul_le_mul_of_nonneg_right hu3 | |
| (show 0 β€ (2 : β) ^ R.extraPrimeParameter z by positivity) | |
| nlinarith [mul_le_mul_of_nonneg_left hpow | |
| (show 0 β€ 8 * (inputScale R.input : β) ^ 2 by positivity)] | |
| intro x hx y hy hxy | |
| exact (hcol x hx y hy hxy).trans hdelta | |
| /-- Using the full parent modulus adds no coprimality assumption: a collision | |
| modulo its product with `q` is in particular a collision modulo `q`. -/ | |
| theorem extraPrime_product_collision (z : Layout n) (hn : 100 β€ n) | |
| (p0 : β) (X : Finset β€) | |
| (hbits : β x β X, β y β X, (x - y).natAbs < 2 ^ (2 * inputScale R.input)) : | |
| PairwiseCollisionBound (primeRange (R.extraPrimeParameter z)) | |
| (primeProbability (R.extraPrimeParameter z)) X | |
| (fun q x => x % ((p0 : β€) * q)) | |
| ((inputScale R.input : β) ^ 3 / (2 : β) ^ R.extraPrimeRate z) := by | |
| have hc := R.extraPrime_collision z hn X hbits | |
| intro x hx y hy hxy | |
| apply le_trans _ (hc x hx y hy hxy) | |
| apply Finset.sum_le_sum | |
| intro q _ | |
| have hprob : 0 β€ primeProbability (R.extraPrimeParameter z) q := by | |
| unfold primeProbability | |
| positivity | |
| by_cases hp : x % ((p0 : β€) * q) = y % ((p0 : β€) * q) | |
| Β· have hq : x % (q : β€) = y % (q : β€) := | |
| (show Int.ModEq ((p0 : β€) * q) x y from hp).of_dvd | |
| (show (q : β€) β£ (p0 : β€) * q from β¨p0, by ringβ©) | |
| simp only [hp, hq, βreduceIte, le_refl] | |
| Β· simp only [hp, βreduceIte, mul_zero] | |
| split_ifs <;> positivity | |
| end LowSpaceSubsetSum.RepresentationSetup | |
| end | |
| end OAI | |