File size: 6,895 Bytes
5d5048e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.NumberTheory.Chebyshev
import Mathlib.Tactic
namespace OAI
/-!
# The bit-length dependence in prime hashing
The prime range has an explicit cardinality lower bound. Counting distinct
prime divisors of a nonzero weight difference then gives the manuscript's
`lem:prime`, with the full dependence on the bit-length parameter.
-/
namespace LowSpaceSubsetSum
open scoped BigOperators
/-- The finite prime range used by all modular filters. -/
def primeRange (ell : ℕ) : Finset ℕ :=
(Nat.primesLE (2 ^ ell)).filter fun p => 2 ^ ell ≤ 4 * ell * p
theorem primeRange_prime {ell p : ℕ} (hp : p ∈ primeRange ell) : p.Prime :=
Nat.prime_of_mem_primesLE (Finset.mem_filter.mp hp).1
theorem primeRange_lt {ell p : ℕ} (hell : 4 ≤ ell) (hp : p ∈ primeRange ell) :
p < 2 ^ ell := by
have hle := Nat.le_of_mem_primesLE (Finset.mem_filter.mp hp).1
have hne : p ≠ 2 ^ ell := by
intro h
exact Nat.Prime.not_prime_pow (by omega : 2 ≤ ell) (h ▸ primeRange_prime hp)
exact lt_of_le_of_ne hle hne
private theorem two_mul_succ_le_pow {ell : ℕ} (hell : 4 ≤ ell) :
2 * (ell + 1) ≤ 2 ^ ell := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hell
induction k with
| zero => norm_num
| succ k ih =>
have ih' := ih (by omega)
rw [show 4 + (k + 1) = (4 + k) + 1 by omega, pow_succ]
nlinarith
/-- The elementary prime-counting lower bound needed for the sampling range. -/
theorem primeCounting_power_two_lower {ell : ℕ} (hell : 4 ≤ ell) :
2 ^ ell ≤ 2 * ell * (2 ^ ell).primeCounting := by
have htwo : (0 : ℝ) < Real.log 2 := Real.log_pos (by norm_num)
have hX1 : (1 : ℝ) < (2 ^ ell : ℕ) := by
exact_mod_cast (one_lt_pow₀ (by decide : (1 : ℕ) < 2) (by omega : ell ≠ 0))
have hlog : Real.log (2 ^ ell : ℕ) = (ell : ℝ) * Real.log 2 := by
rw [Nat.cast_pow, Nat.cast_ofNat, Real.log_pow]
have hXpos : (0 : ℝ) < (2 ^ ell : ℕ) := lt_trans (by norm_num) hX1
have hlogs : Real.log ((2 ^ ell : ℕ) + 1) ≤ (ell + 1 : ℝ) * Real.log 2 := by
have hle : ((2 ^ ell : ℕ) : ℝ) + 1 ≤ 2 * (2 ^ ell : ℕ) := by linarith
have h := Real.log_le_log (by positivity : (0 : ℝ) < (2 ^ ell : ℕ) + 1) hle
rw [Real.log_mul (by norm_num : (2 : ℝ) ≠ 0) hXpos.ne', hlog] at h
nlinarith
have hs : (ell + 1 : ℝ) ≤ (2 ^ ell : ℕ) / 2 := by
have h := two_mul_succ_le_pow hell
have hr : (2 : ℝ) * (ell + 1) ≤ (2 ^ ell : ℕ) := by exact_mod_cast h
linarith
have hpi := Chebyshev.pi_ge (2 ^ ell)
have hpi' := (div_le_iff₀ (Real.log_pos hX1)).mp hpi
rw [hlog] at hpi'
have hbound : ((2 ^ ell : ℕ) : ℝ) / 2 * Real.log 2 ≤
(ell : ℝ) * (2 ^ ell).primeCounting * Real.log 2 := by
nlinarith [mul_le_mul_of_nonneg_right hs htwo.le]
have hbound' := (mul_le_mul_iff_left₀ htwo).mp hbound
have hr : ((2 ^ ell : ℕ) : ℝ) ≤ 2 * ell * (2 ^ ell).primeCounting := by
linarith
exact_mod_cast hr
/-- At least `2^ell/(4 ell)` primes lie in the manuscript's finite range. -/
theorem primeRange_card_lower {ell : ℕ} (hell : 4 ≤ ell) :
2 ^ ell ≤ 4 * ell * (primeRange ell).card := by
let bad := (Nat.primesLE (2 ^ ell)).filter fun p => 4 * ell * p < 2 ^ ell
have hbadsub : bad ⊆ Finset.Icc 1 (2 ^ ell / (4 * ell)) := by
intro p hp
obtain ⟨hpp, hplt⟩ := Finset.mem_filter.mp hp
apply Finset.mem_Icc.mpr
refine ⟨(Nat.prime_of_mem_primesLE hpp).one_le, ?_⟩
apply (Nat.le_div_iff_mul_le (by omega : 0 < 4 * ell)).mpr
simpa only [mul_comm] using hplt.le
have hbadcard : bad.card ≤ 2 ^ ell / (4 * ell) := by
simpa using Finset.card_le_card hbadsub
have hbad : 4 * ell * bad.card ≤ 2 ^ ell :=
(Nat.mul_le_mul_left (4 * ell) hbadcard).trans (Nat.mul_div_le _ _)
have hpartition : (primeRange ell).card + bad.card = (2 ^ ell).primeCounting := by
have h := Finset.card_filter_add_card_filter_not
(s := Nat.primesLE (2 ^ ell)) (p := fun p => 2 ^ ell ≤ 4 * ell * p)
simpa only [primeRange, bad, not_le, Nat.primesLE_card_eq_primeCounting] using h
have hpi := primeCounting_power_two_lower hell
nlinarith
theorem two_pow_card_primeFactors_le {d : ℕ} (hd : 0 < d) :
2 ^ d.primeFactors.card ≤ d := by
calc
2 ^ d.primeFactors.card = ∏ _p ∈ d.primeFactors, 2 := by simp
_ ≤ ∏ p ∈ d.primeFactors, p := by
apply Finset.prod_le_prod
intro p hp
exact (Nat.prime_of_mem_primeFactors hp).two_le
_ ≤ d := Nat.le_of_dvd hd (Nat.prod_primeFactors_dvd d)
/-- A nonzero `K`-bit integer has fewer than `K` distinct prime divisors. -/
theorem card_primeFactors_lt {d K : ℕ} (hd : 0 < d) (hbits : d < 2 ^ K) :
d.primeFactors.card < K := by
have hp := (two_pow_card_primeFactors_le hd).trans_lt hbits
exact (Nat.pow_lt_pow_iff_right (by decide : 1 < 2)).mp hp
/-- All sampled divisors are among the distinct prime factors of the difference. -/
theorem card_sampled_prime_divisors_le (P : Finset ℕ)
(hP : ∀ p ∈ P, p.Prime) {d K : ℕ} (hd : 0 < d) (hbits : d < 2 ^ K) :
(P.filter fun p => p ∣ d).card ≤ K := by
have hsub : (P.filter fun p => p ∣ d) ⊆ d.primeFactors := by
intro p hp
obtain ⟨hpP, hpd⟩ := Finset.mem_filter.mp hp
exact Nat.mem_primeFactors.mpr ⟨hP p hpP, hpd, by omega⟩
exact (Finset.card_le_card hsub).trans (card_primeFactors_lt hd hbits).le
/-- Uniform prime hashing with its explicit polynomial-bit loss. -/
theorem prime_divisor_probability_le {ell u d : ℕ}
(hell : 4 ≤ ell) (hellu : ell ≤ u) (hd : 0 < d) (hbits : d < 2 ^ (2 * u)) :
(((primeRange ell).filter fun p => p ∣ d).card : ℝ) / (primeRange ell).card ≤
8 * (u : ℝ) ^ 2 / (2 : ℝ) ^ ell := by
have hcard := primeRange_card_lower hell
have hpos : 0 < (primeRange ell).card := by
have hpow : 0 < 2 ^ ell := pow_pos (by decide) _
nlinarith
have hposR : (0 : ℝ) < (primeRange ell).card := by exact_mod_cast hpos
have hpowR : (0 : ℝ) < (2 : ℝ) ^ ell := pow_pos (by norm_num) _
have hC : (((primeRange ell).filter fun p => p ∣ d).card : ℝ) ≤ 2 * u := by
exact_mod_cast card_sampled_prime_divisors_le (primeRange ell)
(fun _ hp => primeRange_prime hp) hd hbits
have hD : (2 : ℝ) ^ ell ≤ 4 * ell * (primeRange ell).card := by
exact_mod_cast hcard
have helluR : (ell : ℝ) ≤ u := by exact_mod_cast hellu
apply (div_le_div_iff₀ hposR hpowR).mpr
calc
_ ≤ (2 * u : ℝ) * (2 : ℝ) ^ ell :=
mul_le_mul_of_nonneg_right hC hpowR.le
_ ≤ (2 * u : ℝ) * (4 * ell * (primeRange ell).card) :=
mul_le_mul_of_nonneg_left hD (by positivity)
_ ≤ 8 * (u : ℝ) ^ 2 * (primeRange ell).card := by
nlinarith [mul_nonneg (sub_nonneg.mpr helluR)
(show 0 ≤ (u : ℝ) * (primeRange ell).card by positivity)]
end LowSpaceSubsetSum
end OAI
|