Concept

# Miller–Rabin primality test

Summary
The Miller–Rabin primality test or Rabin–Miller primality test is a probabilistic primality test: an algorithm which determines whether a given number is likely to be prime, similar to the Fermat primality test and the Solovay–Strassen primality test. It is of historical significance in the search for a polynomial-time deterministic primality test. Its probabilistic variant remains widely used in practice, as one of the simplest and fastest tests known. Gary L. Miller discovered the test in 1976; Miller's version of the test is deterministic, but its correctness relies on the unproven extended Riemann hypothesis. Michael O. Rabin modified it to obtain an unconditional probabilistic algorithm in 1980. Similarly to the Fermat and Solovay–Strassen tests, the Miller–Rabin primality test checks whether a specific property, which is known to hold for prime values, holds for the number under testing. The property is the following. For a given odd integer n > 2, let’s write n − 1 as 2sd where s is a positive integer and d is an odd positive integer. Let’s consider an integer a, called a base, which is coprime to n. Then, n is said to be a strong probable prime to base a if one of these congruence relations holds: for some 0 ≤ r < s. The idea beneath this test is that when n is an odd prime, it passes the test because of two facts: by Fermat's little theorem, (this property alone defines the weaker notion of probable prime to base a, on which the Fermat test is based); the only square roots of 1 modulo n are 1 and −1. Hence, by contraposition, if n is not a strong probable prime to base a, then n is definitely composite, and a is called a witness for the compositeness of n. However, this property is not an exact characterization of prime numbers. If n is composite, it may nonetheless be a strong probable prime to base a, in which case it is called a strong pseudoprime, and a is a strong liar. Thankfully, no composite number is a strong pseudoprime to all bases at the same time (contrary to the Fermat primality test for which Fermat pseudoprimes to all bases exist: the Carmichael numbers).