Documentation

CslibFrontier.Foundations.Combinatorics.Additive.BkSequence

Explicit finite B_k-sequences #

A subset B of a commutative additive monoid is a B_k-set (or B_k-sequence, also called a Sidon set at k = 2) when every k-fold sum of elements of B determines its multiset of summands (Cslib.IsBkSet). Any B_k-subset B of a finite commutative additive monoid M satisfies (|B| + k - 1).choose k ≤ |M| (Cslib.IsBkSet.choose_le_card), giving (|B| + k - 1).choose k ≤ N in ZMod N.

Following [Ser23], we construct an explicit size-n B_k-sequence H[n, k] (Cslib.sergeevBkSequence) whose elements are bounded by ((n + 2) * (2 * ⌊log₂(n + 2)⌋ + 4)) ^ k (= n ^ (k + o(k))) and whose entries can be computed in time (n + k) ^ O(1) (certified in CslibFrontier.Computability.Complexity.BkSequencePolyTime):

  1. 2-adic unit decomposition and bit-by-bit discrete logarithm (pp. 2–3): for r ≥ 3, every odd integer x has a unique representation x ≡ (-1) ^ j · 5 ^ h (mod 2 ^ r) with j ∈ Fin 2 and h < 2 ^ (r - 2) (Cslib.existsUnique_neg_one_pow_mul_five_pow_eq). After normalizing x modulo 4, the r - 2 binary digits of h are extracted sequentially in the order-2 subgroup ⟨5 ^ (2 ^ (r - 3))⟩ = {1, 2 ^ (r - 1) + 1} (Cslib.dlogFiveModTwoPow, Cslib.zmod_eq_neg_one_pow_mul_five_pow_dlogFiveModTwoPow).
  2. Prime factor base and B_k correctness (p. 2): taking p₁ < ⋯ < pₙ to be the first n odd primes (Cslib.firstOddPrimes, found below Cslib.primeSearchBound n via Nat.le_card_primesLE_mul_log) and r = max 3 (1 + ⌈log₂(pₙ ^ k)⌉) (Cslib.sergeevModulusExp), distinct k-multisets of odd primes have distinct products strictly below 2 ^ (r - 1). Hence any collision of k-sums modulo 2 ^ (r - 2) would force P ≡ ±Q (mod 2 ^ r) with 0 < P, Q < 2 ^ (r - 1), forcing P = Q in ℕ and identical prime multisets (Cslib.isBkSequence_map_zmod_sergeevBkSequence, Cslib.isBkSequence_sergeevBkSequence).

Main definitions #

Main results #

References #

B_k-sets and B_k-sequences #

def Cslib.IsBkSet {M : Type u_1} [AddCommMonoid M] (k : ℕ) (B : Set M) :

A subset B of a commutative additive monoid is a B_k-set (or B_k-sequence; a Sidon set when k = 2) if k-element sums from B uniquely determine their multiset of summands ([Ser23], p. 1).

def Cslib.IsBkSequence {M : Type u_1} [AddCommMonoid M] (k : ℕ) (L : List M) :

A list L in a commutative additive monoid is a finite B_k-sequence if its entries are pairwise distinct and form a B_k-set ([Ser23], p. 1).

theorem Cslib.IsBkSet.choose_le_card {M : Type u_1} [AddCommMonoid M] [Fintype M] {k : ℕ} {B : Finset M} (hB : IsBkSet k ↑B) :

Counting lower bound for finite B_k-sets ([Ser23], p. 1): the k-element multisets drawn from B have pairwise distinct sums in M, so (#B + k - 1).choose k ≤ |M|. Specializing M = ZMod N ([NeZero N]) gives (#B + k - 1).choose k ≤ N.

theorem Cslib.IsBkSet.of_injOn_map {M : Type u_1} {N : Type u_2} [AddCommMonoid M] [AddCommMonoid N] (φ : M →+ N) {k : ℕ} {B : Set M} (hinj : Set.InjOn (⇑φ) B) (hB : IsBkSet k (⇑φ '' B)) :

Pulling back a B_k-set along an additive monoid homomorphism that is injective on B yields a B_k-set.

theorem Cslib.IsBkSequence.of_map {M : Type u_1} {N : Type u_2} [AddCommMonoid M] [AddCommMonoid N] (φ : M →+ N) {k : ℕ} {L : List M} (hL : IsBkSequence k (List.map (⇑φ) L)) :

If the homomorphic image L.map φ is a B_k-sequence, then L itself is a B_k-sequence (since (L.map φ).Nodup already forces φ to be injective on the entries of L).

2-adic unit decomposition and bit-by-bit discrete logarithm #

def Cslib.dlogFiveStep (r x' a i : ℕ) :

One bit-extraction step of Sergeev's base-5 discrete logarithm modulo 2 ^ r ([Ser23], p. 3): given (r, x'), accumulator a < 2 ^ i with x' ≡ 5 ^ a (mod 2 ^ (i + 2)), and bit index i < r - 2, test whether (5 ^ (-a) * x') ^ (2 ^ (r - 3 - i)) ≡ 2 ^ (r - 1) + 1 (mod 2 ^ r) in the order-2 subgroup.

Base-5 discrete logarithm of ±x modulo 2 ^ r ([Ser23], pp. 2–3): normalizes x modulo 4 so that odd inputs satisfy x' ≡ 1 (mod 4), then extracts the r - 2 binary digits of h < 2 ^ (r - 2) sequentially.

theorem Cslib.foldl_dlogFiveStep_take_lt (r x' m j : ℕ) (hj : j ≤ m) :

After j ≤ m bit-extraction steps over List.range m, the base-5 discrete-logarithm accumulator is strictly less than 2 ^ j.

theorem Cslib.dlogFiveModTwoPow_lt (r x : ℕ) :
dlogFiveModTwoPow r x < 2 ^ (r - 2)

dlogFiveModTwoPow r x always lies strictly below 2 ^ (r - 2).

theorem Cslib.zmod_eq_neg_one_pow_mul_five_pow_dlogFiveModTwoPow {r x : ℕ} (hr : 3 ≤ r) (hx : Odd x) :
↑x = ((-1) ^ if x % 4 = 1 then 0 else 1) * 5 ^ dlogFiveModTwoPow r x

Correctness of Sergeev's bit-by-bit discrete logarithm ([Ser23], pp. 2–3): for r ≥ 3 and odd x, x ≡ (-1) ^ j · 5 ^ (dlogFiveModTwoPow r x) (mod 2 ^ r) where j = 0 when x % 4 = 1 and j = 1 when x % 4 = 3.

theorem Cslib.existsUnique_neg_one_pow_mul_five_pow_eq {r x : ℕ} (hr : 3 ≤ r) (hx : Odd x) :
∃! p : Fin 2 × Fin (2 ^ (r - 2)), ↑x = (-1) ^ ↑p.1 * 5 ^ ↑p.2

Unique (-1) ^ j · 5 ^ h representation of odd residues modulo 2 ^ r for r ≥ 3 ([Ser23], p. 2): every odd integer x has a unique pair (j, h) : Fin 2 × Fin (2 ^ (r - 2)) with x ≡ (-1) ^ j · 5 ^ h (mod 2 ^ r).

Prime factor base #

Upper bound (n + 2) * (2 * ⌊log₂(n + 2)⌋ + 4) guaranteed by Nat.le_card_primesLE_mul_log to exceed at least n + 1 primes (and hence at least n odd primes).

The first n odd prime numbers in strictly increasing order.

@[simp]

firstOddPrimes n has length n for every n.

theorem Cslib.pairwise_lt_firstOddPrimes (n : ℕ) :
List.Pairwise (fun (x1 x2 : ℕ) => x1 < x2) (firstOddPrimes n)

firstOddPrimes n is strictly increasing.

Every entry of firstOddPrimes n is an odd prime (p.Prime ∧ 2 < p).

Sergeev's H[n, k] construction, correctness, and density #

Modulus exponent r = max 3 (1 + ⌈log₂(pₙ ^ k)⌉) of Sergeev's construction ([Ser23], p. 2), using default base 3 when n = 0.

Sergeev's explicit B_k-sequence H[n, k] ([Ser23], p. 2): the base-5 discrete logarithms modulo 2 ^ r of the first n odd primes.

@[simp]

sergeevBkSequence n k has length n.

theorem Cslib.mem_sergeevBkSequence_lt_two_pow (n k : ℕ) {h : ℕ} (hh : h ∈ sergeevBkSequence n k) :
h < 2 ^ (sergeevModulusExp n k - 2)

Every element of sergeevBkSequence n k is strictly less than 2 ^ (sergeevModulusExp n k - 2).

theorem Cslib.two_pow_sergeevModulusExp_sub_two_lt (n : ℕ) {k : ℕ} (hk : 1 ≤ k) :
2 ^ (sergeevModulusExp n k - 2) < ((n + 2) * (2 * Nat.log 2 (n + 2) + 4)) ^ k

Explicit upper bound on the modulus 2 ^ (r - 2) of Sergeev's B_k-sequence ([Ser23], p. 2): 2 ^ (r - 2) < pₙ ^ k ≤ ((n + 2) * (2 * ⌊log₂(n + 2)⌋ + 4)) ^ k for all n and 1 ≤ k.

theorem Cslib.mem_sergeevBkSequence_lt (n : ℕ) {k : ℕ} (hk : 1 ≤ k) {h : ℕ} (hh : h ∈ sergeevBkSequence n k) :
h < ((n + 2) * (2 * Nat.log 2 (n + 2) + 4)) ^ k

Every element of sergeevBkSequence n k (1 ≤ k) is strictly bounded by ((n + 2) * (2 * Nat.log 2 (n + 2) + 4)) ^ k (= n ^ (k + o(k)), [Ser23], Abstract and p. 2).

Sergeev's modular B_k-sequence theorem ([Ser23], p. 2): for every n and 1 ≤ k, the residues of sergeevBkSequence n k form a size-n B_k-sequence in ZMod (2 ^ (sergeevModulusExp n k - 2)).

Sergeev's integer B_k-sequence theorem ([Ser23], Abstract and p. 2): for every n and 1 ≤ k, sergeevBkSequence n k is a size-n B_k-sequence in ℕ.