Algorithm
- Let be matrices where and is prime. Frievalds' algorithm will enable us to probabilistically prove that in time.
- Reading a single matrix is already an operation
- Multiplying an matrix by a vector is an operation since each entry in the output vector is a sum of terms, and there are total entries
- Pick a random element and let
- We can probabilistically compare the product matrix with by multiplying both by and checking the resulting vectors for equality.
- Instead of having to calculate , which would take more than time, we can calculate and then calculate which can be done in .
- If then they represent the same linear transformation so they will always map the same input vectors to the same output vector
- If , it could be the case that and are linear transformations which happen to behave in the same way for the input vector . There is no guarantee that .
- Division by a vector is not defined, so we can't cancel the on each side.
- If then they represent the same linear transformation so they will always map the same input vectors to the same output vector
- Let .
- Each entry in is the Reed-Solomon fingerprint of the corresponding row of , evaluated at . The th entry of is a linear combination of the standard monomial basis, where the coefficients are given by the entries of the th row of , evaluated at :
- Each entry in is the Reed-Solomon fingerprint of the corresponding row of , evaluated at . The th entry of is a linear combination of the standard monomial basis, where the coefficients are given by the entries of the th row of , evaluated at :
- Let .
- To compute , first calculate , which results in an -dimensional vector, and then multiply it by . Both steps take time.
- We'll represent the product of as for convenience. Since
- The entries in are Reed-Solomon fingerprints of the corresponding rows of the product matrix evaluated at
- Now we have two -dimensional vectors, and , containing Reed-Solomon fingerprints of the rows of their corresponding matrices and in each entry. We can probabilistically check equality of row of and row of by checking that .
- If for all , it is likely that
- If for all , it is likely that
Error Probability
- If , the error probability is the probability that , causing the algorithm to output EQUAL.
- If , then there is at least one pair such that . Then row . Since and are Reed-Solomon fingerprints of the -dimensional vectors and , the probability that they are the same for different vectors is bound by the vector length divided by the size of the field:
- Since we picked we can bound the error probability to
- The probability that the full vectors and are equal is at least as low as the probability that they are equal at the th entry, so the error probability is
Analysis With a Fully Random Vector
Instead of using , we can use a totally random vector of elements in , . In this algorithm we'll verify that by creating a new vector and checking that each of its entries is 0.
If then so the algorithm will output EQUAL. If , the algorithm outputs NOT-EQUAL.
1. If C = AB, the error probability is zero
If , the error probability is the probability that , causing the algorithm to return NOT-EQUAL. If , then . Then
, causing the algorithm to output EQUAL.
Since was any vector in , we can conclude that if , for all , the algorithm outputs EQUAL, therefore the error probability is zero.
2. If , the error probability is
If , the error probability is the probability that , which causes the algorithm to output EQUAL. Let . Then . Since , is not the zero matrix and thus has at least one nonzero entry. Let be a pair such that . Then . The entry in is the inner product of row of and :
We can express this sum in terms of the nonzero entry of , times its corresponding entry in , plus a constant representing the remaining terms in the sum.
Then . Since is a random element of , and contains elements
So the probability that the th entry of is zero even though the th row of contains a nonzero entry is
and the probability that the entire vector is 0 is at least as low as the probability that the th entry is 0.
Therefore, if there is even one such that then the probability that the algorithm outputs NOT-EQUAL is .