CountSketch
Library · Source module
CountSketch
For a hash h : n \to k and signs \sigma : n \to \mathbb{R}, the CountSketch matrix NLAlib.countSketchMatrix h σ \in \Bbbk^{k \times n} has a single nonzero entry per column: column i is \sigma_i \mathbf{e}_{h(i)}. Its law NLAlib.countSketch k n takes i.i.d. uniform hash values and independent Rademacher signs; it is the pushforward of the primitive hash and signs with ⊤ on k inside the definition, NLAlib.countSketch_eq_map restates it under any measurable space on k with measurable singletons, and NLAlib.hasLaw_countSketchMatrix takes a user's own hash and signs. The entries are 0 and \pm 1 in any RCLike field.
Everything rests on one computation. For signs with \sigma_i^2 = 1 the Gram error \mathbf{H} = \mathbf{S}^{\mathsf{H}}\mathbf{S} - \mathbf{I} is hollow, with entry \sigma_i \sigma_j where i \ne j collide, and averaging the second moment of a hollow Rademacher quadratic form over collisions of probability 1/\lvert k \rvert gives, for every \mathbf{M}, \mathbb{E}\lvert \operatorname{tr}(\mathbf{M}\mathbf{H})\rvert^2 = \frac{\|\mathbf{M}\|_{\mathsf{F}}^2 + \langle \mathbf{M}, \mathbf{M}^{\mathsf{T}} \rangle_{\mathsf{F}} - 2 \sum_i \lvert \mathbf{M}_{i,i} \rvert^2}{\lvert k \rvert}\,. Its instances are the exact second moment of approximate matrix multiplication, here, and the exact mean of the squared Gram error of an orthonormal \mathbf{U} and the JL moment, in NLAlib/Sketching/Sparse/CountSketchEmbedding.lean, which derives from them the trace moment at q = 1 with bound (d^2 + d)/\lvert k \rvert, the oblivious subspace embedding and injection with failure probability (d^2 + d)/(\lvert k \rvert \varepsilon^2), and the sizes. The transpose terms (\langle \mathbf{M}, \mathbf{M}^{\mathsf{T}} \rangle_{\mathsf{F}}, \|\mathbf{A}^{\mathsf{T}}\mathbf{B}\|_{\mathsf{F}}^2, \|\mathbf{U}^{\mathsf{T}}\mathbf{U}\|_{\mathsf{F}}^2) are at most their Cauchy–Schwarz values, which is all the bounds use, so every bound is the same over \mathbb{R} and \mathbb{C}.
Degenerate cases. Empty k and nonempty n: there is no hash, the law is the zero measure, HasLaw forces \mu = 0, every identity reads 0 = 0 (each right side divides by \lvert k \rvert = 0) and every tail holds; the sketch is not isotropic, hence [Nonempty k] on isotropy, on the OSI and on the probability instance, and nowhere else. Empty k and empty n: the law is the Dirac mass at the empty matrix, a probability measure that NLAlib.isProbabilityMeasure_countSketch leaves out. Empty n: every Gram product is \mathbf{0} and no unit vector exists. Dimension d = 0: every bound is 0 and every embedding event is empty; for d > \lvert n \rvert the OSE at d is the one at \lvert n \rvert, so no d \le \lvert n \rvert is assumed. Signs off \{\pm 1\} form a null set. For \varepsilon \ge 1 the injection is vacuous and the bound is still true. Split at the boundary "The Gram error and the embedding" into this file and NLAlib/Sketching/Sparse/CountSketchEmbedding.lean (2026-10-16).
Main definitions
* NLAlib.countSketchMatrix: the sketch built from a given hash and signs. * NLAlib.countSketch: its law for a uniform hash and Rademacher signs.
Main results
* NLAlib.countSketch_eq_map, NLAlib.hasLaw_countSketchMatrix: the law as a pushforward, and the bridge from a user's own hash and signs. * NLAlib.conjTranspose_countSketchMatrix_mul_self_apply, NLAlib.conjTranspose_countSketchMatrix_mul_self_sub_one: the Gram matrix, and the hollow Gram identity. * NLAlib.isIsotropicSketch_of_hasLaw_countSketch: isotropy. * NLAlib.integral_norm_trace_mul_conjTranspose_mul_self_sub_one_sq_of_hasLaw_countSketch: the exact second moment. * NLAlib.integral_frobNorm_conjTranspose_mul_sub_sq_of_hasLaw_countSketch, NLAlib.integral_frobNorm_conjTranspose_mul_sub_sq_le_of_hasLaw_countSketch, NLAlib.measureReal_frobNorm_conjTranspose_mul_sub_ge_le_of_hasLaw_countSketch: approximate matrix multiplication.
Declarations
- NLAlib.conjTranspose_countSketchMatrix_mul_self_apply
- NLAlib.conjTranspose_countSketchMatrix_mul_self_sub_one
- NLAlib.countSketch
- NLAlib.countSketchMatrix
- NLAlib.countSketch_eq_map
- NLAlib.hasLaw_countSketchMatrix
- NLAlib.integrable_frobNorm_conjTranspose_mul_sub_sq_of_hasLaw_countSketch
- NLAlib.integrable_norm_trace_mul_conjTranspose_mul_self_sub_one_sq_of_hasLaw_countSketch
- NLAlib.integral_frobNorm_conjTranspose_mul_sub_sq_le_of_hasLaw_countSketch
- NLAlib.integral_frobNorm_conjTranspose_mul_sub_sq_of_hasLaw_countSketch
- NLAlib.integral_norm_trace_mul_conjTranspose_mul_self_sub_one_sq_of_hasLaw_countSketch
- NLAlib.isFiniteMeasure_countSketch
- NLAlib.isIsotropicSketch_of_hasLaw_countSketch
- NLAlib.isProbabilityMeasure_countSketch
- NLAlib.measureReal_frobNorm_conjTranspose_mul_sub_ge_le_of_hasLaw_countSketch