NLA-lib Explorer

Subsampled randomized Hadamard transform

Combine randomized signs, a structured orthogonal transform, and sampling.

Definition

Definition (Subsampled randomized Hadamard transform). For a dimension admitting a normalized Hadamard matrix \mathbf{H}, form \mathbf{S}=\sqrt{n/s}\,\mathbf{R}\mathbf{H}\mathbf{D}, where \mathbf{D} contains independent random signs and \mathbf{R} selects s rows. Sampling without replacement requires 1\le s\le n. The library's more general structured-transform definition also accepts a supplied orthogonal transform; sampling with replacement is a separate law.

Lean statement and details
NLAlib.srhtMatrix.{u_2, u_3, u_4} {𝕜 : Type u_2} [RCLike 𝕜] {k : Type u_3} {n : Type u_4}
  [Fintype k] [Fintype n] [DecidableEq n] (F : Matrix n n 𝕜) (ξ : n → ℝ) (ι : k → n) : Matrix k n 𝕜

Full source on GitHub

Copy link

Mathematical guarantees

Theorem (Flattening the leverage scores). Let \mathbf{F} be an n\times n unitary transform satisfying n|\mathbf{F}_{ij}|^2\le\beta, and let \mathbf{D} contain independent Rademacher signs. For an input subspace of dimension d and t\ge0, with failure probability at most ne^{-t}, every leverage score after applying \mathbf{F}\mathbf{D} is at most

\frac{\beta(d+2\sqrt{dt}+2t)}{n}.

Random signs and the bounded orthogonal transform spread the subspace across coordinates before row sampling.

Lean statement and details

General form: sizes are index types

NLAlib.measureReal_exists_leverageScore_mul_diagonal_gt_le_of_hasLaw_rademacherVector.{u_1, u_2,
    u_4, u_5}
  {Ω : Type u_1} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {𝕜 : Type u_2} [RCLike 𝕜] {n : Type u_4}
  {r : Type u_5} [Fintype n] [Fintype r] [DecidableEq n] {F : Matrix n n 𝕜} {ξ : Ω → n → ℝ}
  {β t : ℝ} (hF : IsBoundedOrthonormal F β) (hξ : HasLaw ξ (rademacherVector n) μ)
  (U : Matrix n r 𝕜) (ht : 0 ≤ t) :
  μ.real
      {ω |
        ∃ i,
          β * (↑U.rank + 2 * √(↑U.rank * t) + 2 * t) * (↑(Fintype.card n))⁻¹ <
            leverageScore ((F * diagonal fun l ↦ ↑(ξ ω l)) * U) i} ≤
    ↑(Fintype.card n) * rexp (-t)

Full source on GitHub

Copy link

Further results

Theorem (Approximate matrix multiplication in the spectral norm by the SRHT).

for a bounded orthonormal \mathbf{F} with constant \beta, the SRHT \mathbf{S} built from it (independent random signs and an independent uniform choice of \lvert k\rvert distinct rows), r nonempty, \mathbf{A} \in \Bbbk^{n \times q}, \mathbf{B} \in \Bbbk^{n \times r} and s, t \ge 0, \mathbb{P}\bigl[t \le \|\mathbf{A}^{\mathsf{H}}\mathbf{S}^{\mathsf{H}}\mathbf{S}\mathbf{B} - \mathbf{A}^{\mathsf{H}}\mathbf{B}\|_2\bigr] \le (\lvert q\rvert + \lvert r\rvert) \exp\Bigl(-\frac{\lvert k\rvert t^2/2}{\max(\beta R_{\mathbf{B}}\|\mathbf{A}\|_2^2, \beta R_{\mathbf{A}}\|\mathbf{B}\|_2^2) + 2\beta\sqrt{R_{\mathbf{A}}R_{\mathbf{B}}}\,t/3}\Bigr) + 2\lvert n\rvert e^{-s}\,, with the flattened row-norm bounds R_{\mathbf{A}} = \|\mathbf{A}\|_{\mathsf{F}}^2 + 2\|\mathbf{A}\|_{\mathsf{F}}\|\mathbf{A}\|_2\sqrt{s} + 2\|\mathbf{A}\|_2^2 s (NLAlib.srhtRowNormBound A s) and R_{\mathbf{B}} likewise (srhtRowNormBound B s): condition on the signs, flatten both factors, then sample without replacement (measureReal_specNorm_conjTranspose_mul_sub_ge_le_of_hasLaw_samplingSketchWithoutReplacement). For \mathbf{A} = \mathbf{B} with \|\mathbf{A}\|_2 = 1 and stable rank r_s this is \lvert k\rvert = O(\beta(r_s + \log(n/\delta))\log((q + r)/\delta)/\varepsilon^2). [Tropp2011a, Lemma 3.3] for flattening; the bound is this proof's (no printed source in hand). Any field.

General form: sizes are index types

Lean statement and details
NLAlib.measureReal_specNorm_conjTranspose_mul_sub_ge_le_of_hasLaw_srht.{u_1, u_2, u_3, u_4, u_5,
    u_6}
  {Ω : Type u_1} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {𝕜 : Type u_2} [RCLike 𝕜] {k : Type u_3}
  {n : Type u_4} [Fintype k] [Fintype n] [DecidableEq n] {β : ℝ} {q : Type u_5} {r : Type u_6}
  [Fintype q] [Fintype r] {S : Ω → Matrix k n 𝕜} {F : Matrix n n 𝕜} [Nonempty r]
  (hF : IsBoundedOrthonormal F β) (hS : HasLaw S (srht k F) μ) (A : Matrix n q 𝕜) (B : Matrix n r 𝕜)
  {s t : ℝ} (hs : 0 ≤ s) (ht : 0 ≤ t) :
  μ.real {ω | t ≤ specNorm (Aᴴ * (S ω)ᴴ * S ω * B - Aᴴ * B)} ≤
    (↑(Fintype.card q) + ↑(Fintype.card r)) *
        rexp
          (-(↑(Fintype.card k) * t ^ 2 / 2) /
            (max (β * srhtRowNormBound B s * specNorm A ^ 2)
                (β * srhtRowNormBound A s * specNorm B ^ 2) +
              2 * β * √(srhtRowNormBound A s * srhtRowNormBound B s) * t / 3)) +
      2 * ↑(Fintype.card n) * rexp (-s)

Full source on GitHub

Copy link

Theorem (Distributional JL for the SRHT, asymptotic form).

O(\beta(1 + \log(\lvert n\rvert/\delta))\log(1/\delta)/\varepsilon^2) rows suffice for the SRHT of a bounded orthonormal \mathbf{F} with constant \beta to have the JL property with distortion \varepsilon and failure probability \delta, for \varepsilon and \delta below absolute constants; the constants come before every dimension and before \beta, and the \log\lvert n\rvert of the flattening stays in the threshold. Proved from NLAlib.hasJLProperty_of_hasLaw_srht_of_samplingEmbeddingDim_le with \varepsilon_0 = 1 and \delta \le 1/2. [Woodruff2014, Theorem 7]. Asymptotic: NLAlib.hasJLProperty_of_hasLaw_srht_of_samplingEmbeddingDim_le

General form: sizes are index types

Lean statement and details
NLAlib.exists_forall_hasJLProperty_of_hasLaw_srht :
  ∃ C ε₀,
    0 < C ∧
      0 < ε₀ ∧
        ∀ {Ω 𝕜 k n : Type} [inst : MeasurableSpace Ω] [inst_1 : RCLike 𝕜] [inst_2 : Fintype k]
          [inst_3 : Fintype n] [inst_4 : DecidableEq n] (μ : Measure Ω) (S : Ω → Matrix k n 𝕜)
          (F : Matrix n n 𝕜) (β ε δ : ℝ),
          IsBoundedOrthonormal F β →
            HasLaw S (srht k F) μ →
              0 < ε →
                ε ≤ ε₀ →
                  0 < δ →
                    δ ≤ 1 / 2 →
                      C * (β * (1 + Real.log (↑(Fintype.card n) / δ)) * Real.log (1 / δ) / ε ^ 2) ≤
                          ↑(Fintype.card k) →
                        HasJLProperty S ε δ μ

Full source on GitHub

Copy link

Theorem (The SRHT OSE).

for a bounded orthonormal \mathbf{F} with constant \beta, 0 \le \varepsilon \le 1 and t \ge 0, the SRHT is an oblivious subspace embedding for dimension d with constants 1 \mp \varepsilon and failure probability 2 d \exp\Bigl(-\frac{\varepsilon^2 \lvert k \rvert}{3 \beta (d + 2\sqrt{d t} + 2t)}\Bigr) + \lvert n \rvert e^{-t}\,. [Woodruff2014, Theorem 7] (there r = \Omega(\varepsilon^{-2} \log d\, (\sqrt{d} + \sqrt{\log n})^2) rows, probability 0.99, real Walsh, n a power of two); [MartinssonTropp2020, §9.3] (d = O(k \log k), any SRTT); [HalkoMartinssonTropp2011, Theorem 11.1] (the SRFT with complex signs, 0.40 \le \sigma_{\min}, \sigma_{\max} \le 1.48, failure O(1/k)); [Tropp2011a, Theorems 1.3 and 3.1] (Walsh–Hadamard, orthonormal columns: the same constants at 4(\sqrt{d} + \sqrt{8 \log(d \lvert n \rvert)})^2 \log d rows, and 1/\sqrt{6} \le \sigma_{\min}, \sigma_{\max} \le \sqrt{13/6} outside probability 3/d). Here any field, any \mathbf{F} with entry bound \beta, the tail in natural parameters. For \lvert n \rvert < \lvert k \rvert the law is 0, so \mu = 0.

General form: sizes are index types

Lean statement and details
NLAlib.isObliviousSubspaceEmbedding_of_hasLaw_srht.{u_1, u_2, u_3, u_4} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {𝕜 : Type u_2} [RCLike 𝕜] {k : Type u_3} {n : Type u_4}
  [Fintype k] [Fintype n] [DecidableEq n] {S : Ω → Matrix k n 𝕜} {F : Matrix n n 𝕜} {β ε t : ℝ}
  (hF : IsBoundedOrthonormal F β) (hS : HasLaw S (srht k F) μ) (d : ℕ) (hε : 0 ≤ ε) (hε1 : ε ≤ 1)
  (ht : 0 ≤ t) :
  IsObliviousSubspaceEmbedding S d (1 - ε) (1 + ε)
    (2 * ↑d * rexp (-ε ^ 2 * ↑(Fintype.card k) / (3 * (β * (↑d + 2 * √(↑d * t) + 2 * t)))) +
      ↑(Fintype.card n) * rexp (-t))
    μ

Full source on GitHub

Copy link

Theorem (The SRHT OSI).

for a bounded orthonormal \mathbf{F} with constant \beta, nonempty k, \lvert k \rvert \le \lvert n \rvert, \varepsilon \ge 0 and t \ge 0, the SRHT is an oblivious subspace injection for dimension d with constant 1 - \varepsilon and failure probability d \exp\Bigl(-\frac{\varepsilon^2 \lvert k \rvert}{2 \beta (d + 2\sqrt{d t} + 2t)}\Bigr) + \lvert n \rvert e^{-t}\,: the lower matrix Chernoff half after flattening. [CamanoEpperlyMeyerTropp2025, §1.5.2] (the OSI view; k = \Omega(d \log d) is necessary, their citation of Tropp 2011a); [Tropp2011a, Theorem 3.1] (Walsh–Hadamard, orthonormal columns: \sigma_{\min} \ge 1/\sqrt{6} at 4(\sqrt{d} + \sqrt{8 \log(d \lvert n \rvert)})^2 \log d rows, outside probability 3/d for both halves). Flattening (NLAlib.measureReal_exists_leverageScore_mul_diagonal_gt_le_of_hasLaw_rademacherVector), then NLAlib.hasSubspaceInjection_of_hasLaw_samplingSketchWithoutReplacement through NLAlib.hasSubspaceInjection_mul_of_indepFun_of_leverageScore_le.

General form: sizes are index types

Lean statement and details
NLAlib.isObliviousSubspaceInjection_of_hasLaw_srht.{u_1, u_2, u_3, u_4} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {𝕜 : Type u_2} [RCLike 𝕜] {k : Type u_3} {n : Type u_4}
  [Fintype k] [Fintype n] [DecidableEq n] {S : Ω → Matrix k n 𝕜} {F : Matrix n n 𝕜} {β ε t : ℝ}
  [Nonempty k] (hF : IsBoundedOrthonormal F β) (hS : HasLaw S (srht k F) μ)
  (hk : Fintype.card k ≤ Fintype.card n) (d : ℕ) (hε : 0 ≤ ε) (ht : 0 ≤ t) :
  IsObliviousSubspaceInjection S d (1 - ε)
    (↑d * rexp (-ε ^ 2 * ↑(Fintype.card k) / (2 * (β * (↑d + 2 * √(↑d * t) + 2 * t)))) +
      ↑(Fintype.card n) * rexp (-t))
    μ

Full source on GitHub

Copy link

Theorem (SRHT rows suffice for a rank-d projection-cost-preserving sketch).

O(\beta(d + \log(\lvert n\rvert/\delta))\log(d/\delta)/\varepsilon^2 + \beta^2(d+1)/(\varepsilon^2\delta)) rows give one: for a real bounded orthonormal \mathbf{F} with constant \beta and its SRHT \mathbf{S}, \mathbf{A}\mathbf{S}^{\mathsf{H}} is a rank-d projection-cost-preserving sketch of \mathbf{A} with constants 1 \mp \varepsilon and failure probability \delta, for \varepsilon and \delta below absolute constants; the constants come before every dimension and before \beta. Proved from NLAlib.hasProjectionCostPreserving_of_hasLaw_srht_of_le_card with \varepsilon_0 = 1 and \delta \le 1/2. [CohenElderMuscoMuscoPersu2015, proof of Theorem 12]. Asymptotic: NLAlib.hasProjectionCostPreserving_of_hasLaw_srht_of_le_card

General form: sizes are index types

Lean statement and details
NLAlib.exists_forall_hasProjectionCostPreserving_of_hasLaw_srht :
  ∃ C ε₀,
    0 < C ∧
      0 < ε₀ ∧
        ∀ {Ω k m n : Type} [inst : MeasurableSpace Ω] [inst_1 : Fintype k] [inst_2 : Fintype m]
          [inst_3 : Fintype n] [inst_4 : DecidableEq n] (μ : Measure Ω) (S : Ω → Matrix k n ℝ)
          (F : Matrix n n ℝ) (β : ℝ) (A : Matrix m n ℝ) (d : ℕ) (ε δ : ℝ),
          IsBoundedOrthonormal F β →
            HasLaw S (srht k F) μ →
              0 < ε →
                ε ≤ ε₀ →
                  0 < δ →
                    δ ≤ 1 / 2 →
                      C *
                            (β * (↑d + Real.log (↑(Fintype.card n) / δ)) * Real.log (↑d / δ) /
                                ε ^ 2 +
                              β ^ 2 * (↑d + 1) / (ε ^ 2 * δ)) ≤
                          ↑(Fintype.card k) →
                        HasProjectionCostPreserving S A d (1 - ε) (1 + ε) δ μ

Full source on GitHub

Copy link

Mathematical background

Appears under these tasks