Freivalds' Matrix-Product Verification #
Freivalds' algorithm ([Freivalds1977], [Freivalds1979]; [MitzenmacherUpfal2017], Section 1.3;
[MotwaniRaghavan95], Section 7.1) checks a claimed product A * B = C without multiplying
matrices. It draws random vectors x and accepts when A *ᵥ (B *ᵥ x) = C *ᵥ x for every
drawn vector, evaluating three matrix-vector products and one vector comparison per trial.
This module defines the single-vector check check and the randomized verifier verify as a
ProbComp program that samples k vectors uniformly and tests check on each. Entries of x are
drawn from a finite set S and encoded in the ring by e : S → R. The soundness analysis needs
only that every nonzero d makes s ↦ d * e s injective (see
Cslib.Probability.card_filter_mulVec_eq_mul_card_le). A machine-level implementation on the
randomized word RAM with explicit instruction and rand-call bounds lives in
CslibFrontier.Algorithms.WordRAM.Freivalds.
Source Conventions #
- Matrices:
A : Matrix (Fin l) (Fin m) R,B : Matrix (Fin m) (Fin n) RandC : Matrix (Fin l) (Fin n) Rare rectangular over any ringRwith decidable equality, rather than the square matrices over the integers modulo2of[MitzenmacherUpfal2017], Section 1.3. - Random vectors:
verify e kdraws allkvectorsFin k → Fin n → Sfrom one uniform law. This is the product ofkindependent uniform vectors. - Error: one-sided. A correct product is accepted with probability
1(eval_verify_of_mul_eq). An incorrect product is accepted with probability at most(1/|S|)^k(eval_verify_true_le):(1/2)^kfor0/1vectors over any ring (eval_verify_bool_true_lewithCslib.Probability.bit, the casek = 1being[MitzenmacherUpfal2017], Theorem 1.4), and(1/|F|)^kfor uniform vectors over a finite field (eval_verify_field_true_le).
Main definitions #
Cslib.Algorithms.Lean.Freivalds.check: one deterministic checkA *ᵥ (B *ᵥ x) = C *ᵥ x.Cslib.Algorithms.Lean.Freivalds.verify: the randomized verifier withkuniform vectors.
Main results #
check_eq_decide: associativity identitycheck A B C x = decide ((A * B) *ᵥ x = C *ᵥ x).eval_verify: exact output distribution ofverify.eval_verify_of_mul_eq: perfect completeness.eval_verify_true_le: soundness error at most(1/|S|)^kfor any admissible encoding.eval_verify_bool_true_le: soundness error at most(1/2)^kfor0/1vectors.eval_verify_field_true_le: soundness error at most(1/|F|)^kover a finite fieldF.
References #
One deterministic Freivalds check: compute B *ᵥ x, A *ᵥ (B *ᵥ x) and C *ᵥ x, and
compare A *ᵥ (B *ᵥ x) with C *ᵥ x.
By associativity of matrix-vector multiplication, check tests (A * B) *ᵥ x = C *ᵥ x.
Freivalds' randomized verifier: draw k independent uniform vectors in Fin n → S, encode
their entries with e, and accept when every vector passes check A B C.
The law of the verifier: the indicator that all k checks pass, pushed forward from the
uniform law on Fin k → Fin n → S.
Perfect completeness: a correct product is always accepted.
Soundness: if A * B ≠ C, the verifier accepts with probability at most (1/|S|)^k.
Freivalds' verifier with 0/1 vectors accepts an incorrect product with probability at
most (1/2)^k. The case k = 1 is [MitzenmacherUpfal2017], Theorem 1.4.
Over a finite field with uniform vectors, Freivalds' verifier accepts an incorrect product
with probability at most (1/|F|)^k.