10

Freivald's algorithm (see the wiki) is a randomized algorithm for verifying whether the product of two $n \times n$-matrices $A$ and $B$ yields a given matrix $C$ (i.e. $AB = C$). The way this task is accomplished is to introduce a random vector $\vec{v} \in \mathbb{R}^{n}$ and evaluate whether $$A(Bv) = Cv$$ The claim is that if $AB \neq C$, then $AB v = Cv$ with probability at most $1/2$, and they provide a justification. Their argument for why 1/2 works makes some sense to me. What I don't understand is why this bound can't be improved further by the following argument:

Claim: Suppose that $AB \neq C$. Then for almost all choices of $v$ (i.e. with probability $1$), $AB v \neq Cv$.

Proof of Claim: Note that $AB v = Cv$ if and only if $(AB-C)v =0$. Let $D = AB-C$. Then $ABv = Cv$ if and only if $v \in \ker(D)$. Since $AB \neq C$, $D$ is not the $0$-matrix meaning that $\dim(\ker(D)) < n$. Hence, $\ker(D)$ is a proper linear subspace of $\mathbb{R}^{n}$ and therefore has measure $0$. Thus, for almost all choices of $v$, $D v \neq 0$ meaning that $ABv \neq Cv$ with probability $1$.

Q.E.D.

Hence, if $AB v = Cv$, then $AB = C$ with probability $1$. Shouldn't this mean that the probability of failure in Freivald's algorithm is $0$ instead of $2^{-k}$?

Thanks.

Alex B.
  • 103
  • 6

1 Answers1

12

Algorithms can't work over $\mathbb{R}^n$, as you can't represent real numbers in finite space. Also, you can't pick a number uniformly at random from $\mathbb{R}$. Instead, usually we work over a finite field.

Then we can't do any better. Suppose we are working in the finite field with two elements, $GF(2)$. Suppose that

$$AB - C = \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}.$$

Then it is easy to verify that Frievald's algorithm is wrong with probability $1/2$, as $(AB-C)v = 0$ holds with probability $1/2$ when we select $v$ uniformly at random. You can generalize this to a $n\times n$ matrix that is all zeros except for a single entry, and then the probability of false positive is $1/2$.

If you are working over $\mathbb{Q}$, then the same matrix $AB-C$ also provides a similar counterexample. As Greg Martin explains, Freivald's algorithm by definition chooses vectors uniformly at random from $\{0,1\}^n$, and then when $v$ is selected from this distribution, $(AB-C)v=0$ holds with probability $1/2$. (And if you are wondering whether it is possible to do better by choosing $v$ differently, there is no way to choose a number uniformly at random from $\mathbb{Q}$, so it's not clear what distribution you would use.)

D.W.
  • 167,959
  • 22
  • 232
  • 500