Limb-Aligned Arithmetic and Bit-Packed Table Bounds for Reduced k-Wise Hashing #
This module develops the pure arithmetic and polynomial-limb identities underlying the Word-RAM
implementation of the two-stage universe-reduced k-wise independent hash family
(Cslib.DataStructure.HashFamily.WordRAM.ReducedKWise):
- Overflow-free full-word multiply-shift (
halfMulMod,oddMulModWord): computes(2 * α + 1) * x % 2 ^ w₀ / 2 ^ (w₀ - R)for any0 < w₀ ≤ w. Whenα < 2 ^ (w₀ - 1)andx < 2 ^ w₀, every intermediate product and sum is< 2 ^ w₀, avoiding any2 * w₀ ≤ wrestriction. - Exact limb factorization of
2 * 3 ^ t(reducedChunkBits,reducedHalfLimbs,reducedLimbCount): decomposes any2 * 3 ^ t-bit element ofTrinomialField tintoreducedLimbCount t = 2 * 3 ^ min t 3 ≤ 54limbs ofreducedChunkBits t = 3 ^ (t - 3)bits each, with2 * reducedChunkBits t ≤ wunconditionally wheneverw₀ ≤ w,b' ≤ w, and2 ≤ w, and bit-packed Four-Russians table sizereducedTableBits t ≤ max 8 (2 ^ (b / 2)) = o(2 ^ b)bits (reducedTableWords t w ≤ 2 * reducedTableBits t / w + 1words) wheneverb' ≤ 3 * b. - Bit-packed word slices (
getLimb) and limb-level polynomial multiplication / 4-block trinomial reduction (packLimbs,truncLimbs): proves that limb-by-limb carryless multiplication followed by limb-aligned 4-block XOR reduction computes exact multiplication and addition inTrinomialField t.
Main definitions #
Cslib.Probability.halfMulMod,Cslib.Probability.oddMulModWord: overflow-free full-word odd-multiplier modular product(2 * α + 1) * x % 2 ^ w₀.Cslib.Probability.reducedChunkBits,Cslib.Probability.reducedHalfLimbs,Cslib.Probability.reducedLimbCount: limb bit-width3 ^ (t - 3)and limb counts3 ^ min t 3 ≤ 27,2 * 3 ^ min t 3 ≤ 54.Cslib.Probability.reducedTableBits,Cslib.Probability.reducedPackShift,Cslib.Probability.reducedTableWords: bit-packed Four-Russians table size in bits and words.Cslib.Probability.getLimb,Cslib.Probability.packLimbs,Cslib.Probability.truncLimbs: conversion between natural numbers< 2 ^ (L * c)andLlimbs ofcbits.
Main results #
Cslib.Probability.oddMulModWord_parts_lt: every intermediate product, shift, and sum inhalfMulMod (w₀ - 1)andoddMulModWord w₀is strictly< 2 ^ w₀when0 < w₀,α < 2 ^ (w₀ - 1), andx < 2 ^ w₀.Cslib.Probability.oddMulModWord_shiftRight_eq_multiplyShiftReduced:oddMulModWordshifted right byw₀ - RequalsmultiplyShiftReduced.Cslib.Probability.two_mul_reducedChunkBits_le:2 * reducedChunkBits t ≤ wwheneverw₀ ≤ w,b' ≤ w, and2 ≤ w.Cslib.Probability.reducedTableBits_le:reducedTableBits t ≤ max 8 (2 ^ (b / 2))wheneverb' ≤ 3 * b.Cslib.Probability.reducedTableWords_le:reducedTableWords t w ≤ 2 * reducedTableBits t / w + 1.
Section 1: Overflow-free full-word multiplyShiftReduced arithmetic #
Computes (α * (x' % 2 ^ m)) % 2 ^ m by splitting m at h = m / 2. Whenever α < 2 ^ m and
x' < 2 ^ m, every intermediate product and sum is < 2 ^ (m + 1).
Computes (2 * α + 1) * x % 2 ^ w₀ using halfMulMod (w₀ - 1) so that every intermediate
quantity is strictly less than 2 ^ w₀ whenever α < 2 ^ (w₀ - 1) and x < 2 ^ w₀.
Every intermediate product, shift, and sum in halfMulMod (w₀ - 1) α_val (u_val &&& ...) and
oddMulModWord w₀ α_val u_val is strictly < 2 ^ w₀ whenever 0 < w₀, α_val < 2 ^ (w₀ - 1),
and u_val < 2 ^ w₀.
Exact modular correctness of halfMulMod: for all m α x' : ℕ, halfMulMod m α x' equals
(α * x') % 2 ^ m.
Exact modular correctness of oddMulModWord: for all 0 < w₀,
oddMulModWord w₀ α x = (2 * α + 1) * x % 2 ^ w₀.
Shifting oddMulModWord w₀ α.val u.val right by w₀ - R computes
(multiplyShiftReduced U w₀ R α u).val.
Section 2: Limb parameters and bit-packed Four-Russians table bounds #
Limb bit-width c = 3 ^ (t - 3) for trinomial parameter t.
Half-field limb count L₀ = 3 ^ min t 3 ≤ 27, so L₀ * c = 3 ^ t.
Full-field limb count L = 2 * L₀ = 2 * 3 ^ min t 3 ≤ 54, so L * c = 2 * 3 ^ t.
Whenever w₀ ≤ w, b' ≤ w, and 2 ≤ w, 2 * reducedChunkBits (reducedTrinomialStep w₀ b b')
fits in a single w-bit word (≤ w) unconditionally for all b : ℕ.
Total number of bits (2 * c) * 2 ^ (2 * c) in the Four-Russians carryless multiplication
table for trinomial step t.
Whenever b' ≤ 3 * b, the Four-Russians table bit count satisfies
reducedTableBits (reducedTrinomialStep w₀ b b') ≤ max 8 (2 ^ (b / 2)) = o(2 ^ b).
Log₂ of the number of 2 * c-bit entries packed into each w-bit word:
p = min (2 * c) ⌊log₂ (w / (2 * c))⌋.
Number of w-bit words 2 ^ (2 * c - p) occupied by the bit-packed Four-Russians table.
The bit-packed Four-Russians table uses at most 2 * reducedTableBits t / w + 1 words.
Section 3: Limb extraction, packing, and 4-block trinomial reduction on limbs #
Extract the m-th c-bit limb (a >>> (m * c)) &&& (2 ^ c - 1) of a natural number a.
Low-half limb formula (m < L₀) for reduceTrinomialCode t P.
High-half limb formula (m < L₀, limb index L₀ + m) for reduceTrinomialCode t P.
Low n limbs a &&& (2 ^ (n * c) - 1) of a natural number a.
Mask 2 ^ min c (b' - m * c) - 1 for extracting the < b' bits of limb m.
Shift if m * c < b' then m * c else 0 for placing limb m into the < b' output word.
Ascending Horner prefix over TrinomialField t, processing coefficients from k - 1 down to
k - n as n goes from 0 to k.