<s>
The	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
or	O
Rabin	O
–	O
Miller	O
primality	B-Algorithm
test	I-Algorithm
is	O
a	O
probabilistic	O
primality	B-Algorithm
test	I-Algorithm
:	O
an	O
algorithm	O
which	O
determines	O
whether	O
a	O
given	O
number	O
is	O
likely	B-Algorithm
to	I-Algorithm
be	I-Algorithm
prime	I-Algorithm
,	O
similar	O
to	O
the	O
Fermat	B-Algorithm
primality	I-Algorithm
test	I-Algorithm
and	O
the	O
Solovay	O
–	O
Strassen	O
primality	B-Algorithm
test	I-Algorithm
.	O
</s>
<s>
It	O
is	O
of	O
historical	O
significance	O
in	O
the	O
search	O
for	O
a	O
polynomial-time	O
deterministic	B-General_Concept
primality	B-Algorithm
test	I-Algorithm
.	O
</s>
<s>
Gary	O
L	O
.	O
Miller	O
discovered	O
the	O
test	O
in	O
1976	O
;	O
Miller	O
's	O
version	O
of	O
the	O
test	O
is	O
deterministic	B-General_Concept
,	O
but	O
its	O
correctness	O
relies	O
on	O
the	O
unproven	O
extended	O
Riemann	O
hypothesis	O
.	O
</s>
<s>
Michael	O
O	O
.	O
Rabin	O
modified	O
it	O
to	O
obtain	O
an	O
unconditional	O
probabilistic	B-General_Concept
algorithm	I-General_Concept
in	O
1980	O
.	O
</s>
<s>
Similarly	O
to	O
the	O
Fermat	O
and	O
Solovay	O
–	O
Strassen	O
tests	O
,	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
checks	O
whether	O
a	O
specific	O
property	O
,	O
which	O
is	O
known	O
to	O
hold	O
for	O
prime	O
values	O
,	O
holds	O
for	O
the	O
number	O
under	O
testing	O
.	O
</s>
<s>
Then	O
,	O
n	O
is	O
said	O
to	O
be	O
a	O
strong	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
if	O
one	O
of	O
these	O
congruence	O
relations	O
holds	O
:	O
</s>
<s>
by	O
Fermat	O
's	O
little	O
theorem	O
,	O
(	O
this	O
property	O
alone	O
defines	O
the	O
weaker	O
notion	O
of	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
,	O
on	O
which	O
the	O
Fermat	B-Algorithm
test	I-Algorithm
is	O
based	O
)	O
;	O
</s>
<s>
Hence	O
,	O
by	O
contraposition	O
,	O
if	O
n	O
is	O
not	O
a	O
strong	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
,	O
then	O
n	O
is	O
definitely	O
composite	O
,	O
and	O
a	O
is	O
called	O
a	O
witness	O
for	O
the	O
compositeness	O
of	O
n	O
(	O
sometimes	O
misleadingly	O
called	O
a	O
strong	B-Algorithm
witness	I-Algorithm
)	O
.	O
</s>
<s>
If	O
n	O
is	O
composite	O
,	O
it	O
may	O
nonetheless	O
be	O
a	O
strong	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
,	O
in	O
which	O
case	O
it	O
is	O
called	O
a	O
strong	B-Algorithm
pseudoprime	I-Algorithm
,	O
and	O
a	O
is	O
a	O
strong	B-Algorithm
liar	I-Algorithm
.	O
</s>
<s>
Thankfully	O
,	O
no	O
composite	O
number	O
is	O
a	O
strong	B-Algorithm
pseudoprime	I-Algorithm
to	O
all	O
bases	O
at	O
the	O
same	O
time	O
(	O
contrary	O
to	O
the	O
Fermat	B-Algorithm
primality	I-Algorithm
test	I-Algorithm
for	O
which	O
Fermat	O
pseudoprimes	O
to	O
all	O
bases	O
exist	O
:	O
the	O
Carmichael	O
numbers	O
)	O
.	O
</s>
<s>
A	O
naïve	O
solution	O
is	O
to	O
try	O
all	O
possible	O
bases	O
,	O
which	O
yields	O
an	O
inefficient	O
deterministic	B-General_Concept
algorithm	I-General_Concept
.	O
</s>
<s>
This	O
is	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
.	O
</s>
<s>
For	O
testing	O
arbitrarily	O
large	O
,	O
choosing	O
bases	O
at	O
random	O
is	O
essential	O
,	O
as	O
we	O
do	O
n't	O
know	O
the	O
distribution	O
of	O
witnesses	O
and	O
strong	B-Algorithm
liars	I-Algorithm
among	O
the	O
numbers	O
2	O
,	O
3	O
,	O
…,	O
.	O
</s>
<s>
This	O
gives	O
very	O
fast	O
deterministic	B-General_Concept
tests	O
for	O
small	O
enough	O
n	O
(	O
see	O
section	O
Testing	O
against	O
small	O
sets	O
of	O
bases	O
below	O
)	O
.	O
</s>
<s>
Here	O
is	O
a	O
proof	O
that	O
,	O
if	O
n	O
is	O
an	O
odd	O
prime	O
,	O
then	O
it	O
is	O
a	O
strong	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
.	O
</s>
<s>
Since	O
,	O
either	O
221	O
is	O
prime	O
,	O
or	O
174	O
is	O
a	O
strong	B-Algorithm
liar	I-Algorithm
for	O
221	O
.	O
</s>
<s>
Hence	O
137	O
is	O
a	O
witness	O
for	O
the	O
compositeness	O
of	O
221	O
,	O
and	O
174	O
was	O
in	O
fact	O
a	O
strong	B-Algorithm
liar	I-Algorithm
.	O
</s>
<s>
The	O
algorithm	O
can	O
be	O
written	O
in	O
pseudocode	B-Language
as	O
follows	O
.	O
</s>
<s>
Using	O
repeated	B-Algorithm
squaring	I-Algorithm
,	O
the	O
running	O
time	O
of	O
this	O
algorithm	O
is	O
,	O
where	O
n	O
is	O
the	O
number	O
tested	O
for	O
primality	O
,	O
and	O
k	O
is	O
the	O
number	O
of	O
rounds	O
performed	O
;	O
thus	O
this	O
is	O
an	O
efficient	O
,	O
polynomial-time	O
algorithm	O
.	O
</s>
<s>
The	O
error	O
made	O
by	O
the	O
primality	B-Algorithm
test	I-Algorithm
is	O
measured	O
by	O
the	O
probability	O
that	O
a	O
composite	O
number	O
is	O
declared	O
probably	O
prime	O
.	O
</s>
<s>
It	O
can	O
be	O
shown	O
that	O
if	O
n	O
is	O
composite	O
,	O
then	O
at	O
most	O
of	O
the	O
bases	O
a	O
are	O
strong	B-Algorithm
liars	I-Algorithm
for	O
n	O
.	O
As	O
a	O
consequence	O
,	O
if	O
n	O
is	O
composite	O
then	O
running	O
k	O
iterations	O
of	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
will	O
declare	O
n	O
probably	O
prime	O
with	O
a	O
probability	O
at	O
most	O
4−k	O
.	O
</s>
<s>
Moreover	O
,	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
is	O
strictly	O
stronger	O
than	O
the	O
Solovay	O
–	O
Strassen	O
test	O
in	O
the	O
sense	O
that	O
for	O
every	O
composite	O
n	O
,	O
the	O
set	O
of	O
strong	B-Algorithm
liars	I-Algorithm
for	O
n	O
is	O
a	O
subset	O
of	O
the	O
set	O
of	O
Euler	O
liars	O
for	O
n	O
,	O
and	O
for	O
many	O
n	O
,	O
the	O
subset	O
is	O
proper	O
.	O
</s>
<s>
For	O
instance	O
,	O
for	O
most	O
numbers	O
n	O
,	O
this	O
probability	O
is	O
bounded	O
by	O
8−k	O
;	O
the	O
proportion	O
of	O
numbers	O
n	O
which	O
invalidate	O
this	O
upper	O
bound	O
vanishes	O
as	O
we	O
consider	O
larger	O
values	O
of	O
n	O
.	O
Hence	O
the	O
average	O
case	O
has	O
a	O
much	O
better	O
accuracy	O
than	O
4−k	O
,	O
a	O
fact	O
which	O
can	O
be	O
exploited	O
for	O
generating	O
probable	B-Algorithm
primes	I-Algorithm
(	O
see	O
below	O
)	O
.	O
</s>
<s>
However	O
,	O
such	O
improved	O
error	O
bounds	O
should	O
not	O
be	O
relied	O
upon	O
to	O
verify	O
primes	O
whose	O
probability	O
distribution	O
is	O
not	O
controlled	O
,	O
since	O
a	O
cryptographic	O
adversary	O
might	O
send	O
a	O
carefully	O
chosen	O
pseudoprime	O
in	O
order	O
to	O
defeat	O
the	O
primality	B-Algorithm
test	I-Algorithm
.	O
</s>
<s>
where	O
P	O
is	O
the	O
event	O
that	O
the	O
number	O
being	O
tested	O
is	O
prime	O
,	O
and	O
MRk	O
is	O
the	O
event	O
that	O
it	O
passes	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
with	O
k	O
rounds	O
.	O
</s>
<s>
We	O
are	O
often	O
interested	O
instead	O
in	O
the	O
inverse	O
conditional	O
probability	O
:	O
the	O
probability	O
that	O
a	O
number	O
which	O
has	O
been	O
declared	O
as	O
a	O
strong	O
probable	B-Algorithm
prime	I-Algorithm
is	O
in	O
fact	O
composite	O
.	O
</s>
<s>
In	O
the	O
last	O
equation	O
,	O
we	O
simplified	O
the	O
expression	O
using	O
the	O
fact	O
that	O
all	O
prime	O
numbers	O
are	O
correctly	O
reported	O
as	O
strong	O
probable	B-Algorithm
primes	I-Algorithm
(	O
the	O
test	O
has	O
no	O
false	O
negative	O
)	O
.	O
</s>
<s>
However	O
,	O
in	O
the	O
case	O
when	O
we	O
use	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
to	O
generate	O
primes	O
(	O
see	O
below	O
)	O
,	O
the	O
distribution	O
is	O
chosen	O
by	O
the	O
generator	O
itself	O
,	O
so	O
we	O
can	O
exploit	O
this	O
result	O
.	O
</s>
<s>
The	O
Miller	O
–	O
Rabin	O
algorithm	O
can	O
be	O
made	O
deterministic	B-General_Concept
by	O
trying	O
all	O
possible	O
a	O
below	O
a	O
certain	O
limit	O
.	O
</s>
<s>
If	O
the	O
tested	O
number	O
n	O
is	O
composite	O
,	O
the	O
strong	B-Algorithm
liars	I-Algorithm
a	O
coprime	O
to	O
n	O
are	O
contained	O
in	O
a	O
proper	O
subgroup	O
of	O
the	O
group	O
(	O
Z/nZ	O
)	O
*	O
,	O
which	O
means	O
that	O
if	O
we	O
test	O
all	O
a	O
from	O
a	O
set	O
which	O
generates	O
(	O
Z/nZ	O
)	O
*	O
,	O
one	O
of	O
them	O
must	O
lie	O
outside	O
the	O
said	O
subgroup	O
,	O
hence	O
must	O
be	O
a	O
witness	O
for	O
the	O
compositeness	O
of	O
n	O
.	O
Assuming	O
the	O
truth	O
of	O
the	O
generalized	O
Riemann	O
hypothesis	O
(	O
GRH	O
)	O
,	O
it	O
is	O
known	O
that	O
the	O
group	O
is	O
generated	O
by	O
its	O
elements	O
smaller	O
than	O
,	O
which	O
was	O
already	O
noted	O
by	O
Miller	O
.	O
</s>
<s>
This	O
leads	O
to	O
the	O
following	O
deterministic	B-General_Concept
primality	B-Algorithm
testing	I-Algorithm
algorithm	O
,	O
known	O
as	O
the	O
Miller	O
test	O
:	O
</s>
<s>
For	O
most	O
purposes	O
,	O
proper	O
use	O
of	O
the	O
probabilistic	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
or	O
the	O
Baillie	B-Algorithm
–	I-Algorithm
PSW	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
gives	O
sufficient	O
confidence	O
while	O
running	O
much	O
faster	O
.	O
</s>
<s>
It	O
is	O
also	O
slower	O
in	O
practice	O
than	O
commonly	O
used	O
proof	O
methods	O
such	O
as	O
APR-CL	B-Algorithm
and	O
ECPP	B-Algorithm
which	O
give	O
results	O
that	O
do	O
not	O
rely	O
on	O
unproven	O
assumptions	O
.	O
</s>
<s>
For	O
theoretical	O
purposes	O
requiring	O
a	O
deterministic	B-General_Concept
polynomial	O
time	O
algorithm	O
,	O
it	O
was	O
superseded	O
by	O
the	O
AKS	B-Algorithm
primality	I-Algorithm
test	I-Algorithm
,	O
which	O
also	O
does	O
not	O
rely	O
on	O
unproven	O
assumptions	O
.	O
</s>
<s>
They	O
give	O
very	O
fast	O
deterministic	B-General_Concept
primality	B-Algorithm
tests	I-Algorithm
for	O
numbers	O
in	O
the	O
appropriate	O
range	O
,	O
without	O
any	O
assumptions	O
.	O
</s>
<s>
This	O
occurs	O
for	O
example	O
when	O
n	O
is	O
a	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
but	O
not	O
a	O
strong	O
probable	B-Algorithm
prime	I-Algorithm
to	O
base	O
a	O
.	O
</s>
<s>
This	O
leads	O
to	O
the	O
following	O
pseudocode	B-Language
,	O
where	O
the	O
added	O
or	O
changed	O
code	O
is	O
highlighted	O
:	O
</s>
<s>
This	O
tells	O
us	O
that	O
n	O
is	O
a	O
pseudoprime	O
base	O
2	O
,	O
but	O
not	O
a	O
strong	B-Algorithm
pseudoprime	I-Algorithm
base	O
2	O
.	O
</s>
<s>
This	O
strategy	O
can	O
be	O
implemented	O
by	O
exploiting	O
knowledge	O
from	O
previous	O
rounds	O
of	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
.	O
</s>
<s>
The	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
can	O
be	O
used	O
to	O
generate	O
strong	O
probable	B-Algorithm
primes	I-Algorithm
,	O
simply	O
by	O
drawing	O
integers	O
at	O
random	O
until	O
one	O
passes	O
the	O
test	O
.	O
</s>
<s>
The	O
pseudocode	B-Language
for	O
generating	O
b‐bit	O
strong	O
probable	B-Algorithm
primes	I-Algorithm
(	O
with	O
the	O
most	O
significant	O
bit	O
set	O
)	O
is	O
as	O
follows	O
:	O
</s>
<s>
Of	O
course	O
the	O
worst-case	B-General_Concept
running	I-General_Concept
time	I-General_Concept
is	O
infinite	O
,	O
since	O
the	O
outer	O
loop	O
may	O
never	O
terminate	O
,	O
but	O
that	O
happens	O
with	O
probability	O
zero	O
.	O
</s>
<s>
Hence	O
we	O
can	O
expect	O
the	O
generator	O
to	O
run	O
no	O
more	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
tests	I-Algorithm
than	O
a	O
number	O
proportional	O
to	O
b	O
.	O
</s>
<s>
Taking	O
into	O
account	O
the	O
worst-case	B-General_Concept
complexity	I-General_Concept
of	O
each	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
(	O
see	O
earlier	O
)	O
,	O
the	O
expected	O
running	O
time	O
of	O
the	O
generator	O
with	O
inputs	O
b	O
and	O
k	O
is	O
then	O
bounded	O
by	O
(	O
or	O
using	O
FFT-based	O
multiplication	O
)	O
.	O
</s>
<s>
Using	O
the	O
fact	O
that	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
itself	O
often	O
has	O
an	O
error	O
bound	O
much	O
smaller	O
than	O
4−k	O
(	O
see	O
earlier	O
)	O
,	O
Damgård	O
,	O
Landrock	O
and	O
Pomerance	O
derived	O
several	O
error	O
bounds	O
for	O
the	O
generator	O
,	O
with	O
various	O
classes	O
of	O
parameters	O
b	O
and	O
k	O
.	O
These	O
error	O
bounds	O
allow	O
an	O
implementor	O
to	O
choose	O
a	O
reasonable	O
k	O
for	O
a	O
desired	O
accuracy	O
.	O
</s>
