Documentation

CslibFrontier.Probability.Freivalds

Random-vector fingerprints of matrices #

Freivalds' technique compares two matrices M and N through M *ᵥ x and N *ᵥ x for a random vector x. This module proves the counting bound behind it. The coordinates of x are drawn uniformly from a finite set S and encoded in the ring by e : S → R. If every nonzero d : R makes s ↦ d * e s injective, distinct matrices agree on at most a 1/|S| fraction of the vectors, and on k independent vectors simultaneously with probability at most 1/|S|^k.

The encoding hypothesis covers the two standard instances. S = Bool with e = bit works over every ring, giving the bound 1/2 of [MitzenmacherUpfal2017], Theorem 1.4; Section 1.3 there works with square matrices over the integers modulo 2 for convenience. Over a finite field, e = id gives 1/|F|. [MotwaniRaghavan95], Section 7.1, presents this technique as fingerprinting.

The proof fixes an entry (i, j) with (M - N) i j ≠ 0. Once the coordinates of x other than j are fixed, at most one value of x j satisfies row i of (M - N) *ᵥ x = 0. This is the argument of [MitzenmacherUpfal2017], Theorem 1.4, stated here for rectangular matrices, arbitrary encodings and an arbitrary non-unital ring.

Main definitions #

Main results #

References #

theorem Cslib.Probability.card_filter_mulVec_eq_mul_card_le {m : Type u_1} {n : Type u_2} {S : Type u_4} {R : Type u_5} [Fintype n] [Fintype S] [DecidableEq n] [Fintype m] [NonUnitalNonAssocRing R] [DecidableEq R] {e : S → R} (he : ∀ (d : R), d ≠ 0 → Function.Injective fun (s : S) => d * e s) {M N : Matrix m n R} (hMN : M ≠ N) :
{x : n → S | M.mulVec (e ∘ x) = N.mulVec (e ∘ x)}.card * Fintype.card S ≤ Fintype.card S ^ Fintype.card n

Distinct matrices agree on at most a 1/|S| fraction of the encoded vectors.

theorem Cslib.Probability.card_filter_forall_mulVec_eq_le {m : Type u_1} {n : Type u_2} {κ : Type u_3} {S : Type u_4} {R : Type u_5} [Fintype n] [Fintype κ] [Fintype S] [DecidableEq n] [DecidableEq κ] [Fintype m] [NonUnitalNonAssocRing R] [DecidableEq R] {e : S → R} (he : ∀ (d : R), d ≠ 0 → Function.Injective fun (s : S) => d * e s) {M N : Matrix m n R} (hMN : M ≠ N) :
{xs : κ → n → S | ∀ (t : κ), M.mulVec (e ∘ xs t) = N.mulVec (e ∘ xs t)}.card * Fintype.card S ^ Fintype.card κ ≤ Fintype.card S ^ (Fintype.card n * Fintype.card κ)

Distinct matrices agree on card κ independent encoded vectors for at most a 1/|S|^(card κ) fraction of the tuples.

theorem Cslib.Probability.toOuterMeasure_mulVec_eq_le {m : Type u_1} {n : Type u_2} {S : Type u_4} {R : Type u_5} [Fintype n] [Fintype S] [DecidableEq n] [Finite m] [Nonempty S] [NonUnitalNonAssocRing R] {e : S → R} (he : ∀ (d : R), d ≠ 0 → Function.Injective fun (s : S) => d * e s) {M N : Matrix m n R} (hMN : M ≠ N) :
(PMF.uniformOfFintype (n → S)).toOuterMeasure {x : n → S | M.mulVec (e ∘ x) = N.mulVec (e ∘ x)} ≤ (↑(Fintype.card S))⁻¹

Distinct matrices agree on a uniform encoded vector with probability at most 1/|S| ([MitzenmacherUpfal2017], Theorem 1.4, for S = Bool).

theorem Cslib.Probability.toOuterMeasure_forall_mulVec_eq_le {m : Type u_1} {n : Type u_2} {κ : Type u_3} {S : Type u_4} {R : Type u_5} [Fintype n] [Fintype κ] [Fintype S] [DecidableEq n] [DecidableEq κ] [Finite m] [Nonempty S] [NonUnitalNonAssocRing R] {e : S → R} (he : ∀ (d : R), d ≠ 0 → Function.Injective fun (s : S) => d * e s) {M N : Matrix m n R} (hMN : M ≠ N) :
(PMF.uniformOfFintype (κ → n → S)).toOuterMeasure {xs : κ → n → S | ∀ (t : κ), M.mulVec (e ∘ xs t) = N.mulVec (e ∘ xs t)} ≤ (↑(Fintype.card S))⁻¹ ^ Fintype.card κ

Distinct matrices agree on all of card κ independent uniform encoded vectors with probability at most 1/|S|^(card κ).

theorem Cslib.Probability.isUniversalHash_mulVec {m : Type u_1} {n : Type u_2} {S : Type u_4} {R : Type u_5} [Fintype n] [Fintype S] [DecidableEq n] [Finite m] [Nonempty S] [NonUnitalNonAssocRing R] {e : S → R} (he : ∀ (d : R), d ≠ 0 → Function.Injective fun (s : S) => d * e s) :
IsUniversalHash (PMF.uniformOfFintype (n → S)) (fun (x : n → S) (M : Matrix m n R) => M.mulVec (e ∘ x)) (↑(Fintype.card S))⁻¹

Random-vector fingerprints form a 1/|S|-universal hash family on matrices. This swaps the roles in isDeltaUniversalHash_mulVec (Probability.HashFamily.Matrix), where a uniform matrix is the seed and the vector is the hashed input: here the vector is the seed and the matrix the input.

def Cslib.Probability.bit {R : Type u_5} [Zero R] [One R] (b : Bool) :
R

The 0/1 encoding of a bit in a ring.

@[simp]
theorem Cslib.Probability.bit_true {R : Type u_5} [Zero R] [One R] :
@[simp]
theorem Cslib.Probability.bit_false {R : Type u_5} [Zero R] [One R] :
theorem Cslib.Probability.injective_mul_bit {R : Type u_5} [NonAssocRing R] (d : R) (hd : d ≠ 0) :
Function.Injective fun (b : Bool) => d * bit b

The 0/1 encoding of bits satisfies the encoding hypothesis over every ring.