= Miller-Rabin primality test
{c}
{wiki=Miller–Rabin_primality_test}
= Miller–Rabin primality testing
{c}
{synonym}
= Miller–Rabin test
{c}
{synonym}
= Miller-Rabin
{c}
{synonym}
For an odd <integer> $n>3$, write $n-1=2^s d$ with $d$ odd. Choose a base $a$ uniformly from $\{2,\ldots,n-2\}$. It passes the <Miller–Rabin test> when
$$
a^d\equiv1\pmod n\quad\text{or}\quad a^{2^jd}\equiv-1\pmod n\text{ for some }0\leq j<s.
$$
A nontrivial <greatest common divisor> of $a,n$ or failure certifies compositeness. <Exponentiation by squaring> computes $a^d$; at most $s-1$ further squarings test the other possibilities.
Every <prime number> passes: <arithmetic> <modulo> a <prime number> is a <field>, whose only <square roots> of one are $1$ and $-1$. The squaring chain ends at one by the <Fermat little theorem>; its first one is either the initial value or follows minus one.
For an odd <composite number>, at most one quarter of bases in the stated range pass. Thus $r$ independently sampled bases give false probable-prime <probability> at most $4^{-r}$, for each fixed <composite> input. A passing <composite> is a <strong pseudoprime> to that base.<Probabilistic Algorithm for Testing Primality by Michael O. Rabin>[sections 1–2]{ref}
Back to article page