The Miller-Rabin primality test or Rabin-Miller primality test is a primality test: an algorithm which determines whether a given number is prime, similar to the Fermat primality test and the Solovay-Strassen primality test. Its original version, due to Gary L. Miller, is deterministic, but it relies on the unproven generalized Riemann hypothesis; Michael O. Rabin modified it to obtain an unconditional probabilistic algorithm.
First, we'll need a lemma about square roots of unity in the finite field . We know that 1 and -1 always yield 1 when squared mod p; we call these trivial square roots of 1. We assert that there are no nontrivial square roots of 1. To show this, suppose that x is a square root of 1 mod p. Then:
Now, let n be an odd prime, then we can write n − 1 as , where s is an integer and d is odd -- this is the same as factoring out 2 from n − 1 repeatedly. Then, one of the following must be true for all :
To show that one of these must be true, recall Fermat's little theorem (which only applies for prime moduli):
By the lemma above, if we keep taking square roots of an − 1, we will either get 1 or −1. If we get −1 then the second equality holds and we are done.
In the case when we've taken out every power of 2 and the second equality never held, we are left with the first equality which also must be equal to 1 or −1, as it too is a square root. However, if the second equality never held, then it couldn't have held for r = 0, meaning that
Thus in the case the second equality doesn't hold, the first equality must.
The Miller-Rabin primality test is based on the contrapositive of the above claim. That is, if we can find an a such that
then a is a witness for the compositeness of n (sometimes misleadingly called a strong witness, although it is a certain proof of this fact). Otherwise a is called a strong liar, and n is a strong probable prime to base a. The term "strong liar" refers to the case where n is composite but nevertheless the equations hold as they would for a prime.
For every composite n, there are many witnesses a. However, no simple way of generating such an a is known. The solution is to make the test probabilistic: we choose randomly, and check whether or not it is a witness for the compositeness of n. If n is composite, most of the as are witnesses, thus the test will detect n as composite with high probability. There is nevertheless a small chance that we are unlucky and hit an a which is a strong liar for n. We may reduce the probability of such error by repeating the test for several independently chosen a.
Using modular exponentiation by repeated squaring, the running time of this algorithm is O(k × log3 n), where k is the number of different values of a we test; thus this is an efficient, polynomial-time algorithm. Fast FFT-based multiplication can push the running time down to Õ(k × log2 n).
On average the probability that a composite number is declared probable prime is significantly smaller than . Damgård, Landrock and Pomerance compute some explicit bounds. Such bounds can for example be used to generate primes, but should not be used to verify primes with unknown origin. Especially in cryptographic application an adversary might try to send you a pseudoprime in a place where a prime number is required. Then only the bound is valid.
If the tested number n is composite, the strong liars a coprime to n are contained in a proper subgroup of the group , which means that if we test all a from a set which generates , one of them must be a witness for the compositeness of n. Assuming the truth of the generalized Riemann hypothesis (GRH), it is known that the group is generated by its elements smaller than O((ln n)2), which was already noted by Miller. The constant involved in the big O-notation was reduced to 2 by Bach (1990). This leads to the following conditional primality testing algorithm:
This algorithm is not used in practice, as it is much slower than the randomized version of the Miller-Rabin test. For theoretical purposes, it was superseded by the AKS primality test, which does not rely on unproven assumptions.
When the number n we want to test is small, trying all a < 2(ln n)2 is not necessary, as much smaller sets of potential witnesses are known to suffice. For example, Jaeschke (1993) has verified that
However, no finite set of bases is sufficient for all composite numbers. Alford, Granville and Pomerance have shown that there exist infinitely many composite numbers n whose smallest compositeness witness is at least . They also argue heuristically that the smallest number w such that every composite number below n has a compositeness witness less than w should be of order .
Miller-Rabin-Test | Test de primalidad de Miller-Rabin | Test de primalité de Miller-Rabin | 밀러-라빈 소수판별법 | האלגוריתם של מילר-רבין | Teste de primitividade de Miller-Rabin | Тест Миллера — Рабина | 米勒-拉宾检验
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Miller-Rabin primality test".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world