<s>
The	O
Baillie	B-Algorithm
–	I-Algorithm
PSW	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
is	O
a	O
probabilistic	B-General_Concept
or	O
possibly	O
deterministic	O
primality	B-Algorithm
testing	I-Algorithm
algorithm	O
that	O
determines	O
whether	O
a	O
number	O
is	O
composite	O
or	O
is	O
a	O
probable	B-Algorithm
prime	I-Algorithm
.	O
</s>
<s>
The	O
Baillie	O
–	O
PSW	O
test	O
is	O
a	O
combination	O
of	O
a	O
strong	B-Algorithm
Fermat	I-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
(	O
that	O
means	O
Miller-Rabin	B-Algorithm
)	O
to	O
base	O
2	O
and	O
a	O
standard	O
or	O
strong	O
Lucas	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
.	O
</s>
<s>
For	O
example	O
,	O
Fermat	O
pseudoprimes	O
to	O
base	O
2	O
tend	O
to	O
fall	O
into	O
the	O
residue	O
class	O
1	O
(	O
mod	O
m	O
)	O
for	O
many	O
small	O
m	O
,	O
whereas	O
Lucas	B-Algorithm
pseudoprimes	I-Algorithm
tend	O
to	O
fall	O
into	O
the	O
residue	O
class	O
−1	O
(	O
mod	O
m	O
)	O
.	O
</s>
<s>
For	O
example	O
,	O
n	O
=	O
5777	O
is	O
a	O
strong	O
psp	O
base	O
76	O
,	O
and	O
is	O
also	O
a	O
strong	O
Lucas	B-Algorithm
pseudoprime	I-Algorithm
.	O
</s>
<s>
Consequently	O
,	O
this	O
test	O
is	O
a	O
deterministic	O
primality	B-Algorithm
test	I-Algorithm
on	O
numbers	O
below	O
that	O
bound	O
.	O
</s>
<s>
Richard	O
Guy	O
incorrectly	O
stated	O
that	O
the	O
value	O
of	O
this	O
prize	O
had	O
been	O
raised	O
to	O
$620	O
,	O
but	O
he	O
was	O
confusing	O
the	O
Lucas	B-Algorithm
sequence	I-Algorithm
with	O
the	O
Fibonacci	B-Algorithm
sequence	I-Algorithm
,	O
and	O
his	O
remarks	O
really	O
apply	O
only	O
to	O
a	O
Conjecture	O
of	O
Selfridge	O
's	O
.	O
</s>
<s>
Optionally	O
,	O
perform	O
trial	B-Algorithm
division	I-Algorithm
to	O
check	O
if	O
n	O
is	O
divisible	O
by	O
a	O
small	O
prime	O
number	O
less	O
than	O
some	O
convenient	O
limit	O
.	O
</s>
<s>
Perform	O
a	O
base	O
2	O
strong	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
.	O
</s>
<s>
If	O
n	O
is	O
not	O
a	O
strong	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
base	O
2	O
,	O
then	O
n	O
is	O
composite	O
;	O
quit	O
.	O
</s>
<s>
Perform	O
a	O
strong	O
Lucas	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
on	O
n	O
using	O
parameters	O
D	O
,	O
P	O
,	O
and	O
Q	O
.	O
</s>
<s>
If	O
n	O
is	O
not	O
a	O
strong	O
Lucas	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
,	O
then	O
n	O
is	O
composite	O
.	O
</s>
<s>
The	O
Baillie	O
–	O
PSW	O
test	O
works	O
without	O
this	O
step	O
,	O
but	O
if	O
n	O
has	O
small	O
prime	O
factors	O
,	O
then	O
the	O
quickest	O
way	O
to	O
show	O
that	O
n	O
is	O
composite	O
is	O
to	O
find	O
a	O
factor	O
by	O
trial	B-Algorithm
division	I-Algorithm
.	O
</s>
<s>
Step	O
2	O
is	O
,	O
in	O
effect	O
,	O
a	O
single	O
application	O
of	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
,	O
but	O
using	O
the	O
fixed	O
base	O
2	O
.	O
</s>
<s>
However	O
,	O
much	O
work	O
has	O
been	O
done	O
(	O
see	O
above	O
)	O
to	O
verify	O
that	O
the	O
combination	O
of	O
the	O
base	O
2	O
strong	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
and	O
a	O
strong	O
Lucas	O
test	O
does	O
a	O
good	O
job	O
of	O
distinguishing	O
primes	O
from	O
composites	O
.	O
</s>
<s>
Bressoud	O
and	O
Wagon	O
explain	O
why	O
we	O
want	O
the	O
Jacobi	O
symbol	O
to	O
be	O
−1	O
,	O
as	O
well	O
as	O
why	O
one	O
gets	O
more	O
powerful	O
primality	B-Algorithm
tests	I-Algorithm
if	O
Q	O
≠	O
±1	O
.	O
</s>
<s>
Section	O
6	O
of	O
recommends	O
that	O
if	O
Q	O
≠	O
±1	O
,	O
a	O
good	O
primality	B-Algorithm
test	I-Algorithm
should	O
also	O
check	O
two	O
additional	O
congruence	O
conditions	O
.	O
</s>
<s>
See	O
Selfridge	O
's	O
conjecture	O
about	O
primality	B-Algorithm
testing	I-Algorithm
.	O
</s>
<s>
The	O
authors	O
of	O
suggest	O
a	O
stronger	O
version	O
of	O
the	O
Baillie	B-Algorithm
–	I-Algorithm
PSW	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
that	O
includes	O
this	O
congruence	O
;	O
the	O
authors	O
offer	O
a	O
$2000	O
reward	O
for	O
a	O
composite	O
number	O
that	O
passes	O
this	O
stronger	O
test	O
.	O
</s>
<s>
This	O
version	O
of	O
the	O
algorithm	O
is	O
already	O
used	O
in	O
Mathematica	B-Language
.	O
</s>
<s>
All	O
of	O
this	O
suggests	O
that	O
probable	B-Algorithm
prime	I-Algorithm
tests	O
to	O
different	O
bases	O
are	O
not	O
independent	O
of	O
each	O
other	O
,	O
so	O
that	O
performing	O
Fermat	O
probable	B-Algorithm
prime	I-Algorithm
tests	O
to	O
more	O
and	O
more	O
bases	O
will	O
give	O
diminishing	O
returns	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
the	O
calculations	O
in	O
and	O
the	O
calculations	O
up	O
to	O
264	O
mentioned	O
above	O
suggest	O
that	O
Fermat	O
and	O
Lucas	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
tests	O
are	O
independent	O
,	O
so	O
that	O
a	O
combination	O
of	O
these	O
types	O
of	O
tests	O
would	O
make	O
a	O
powerful	O
primality	B-Algorithm
test	I-Algorithm
,	O
especially	O
if	O
the	O
strong	O
forms	O
of	O
the	O
tests	O
are	O
used	O
.	O
</s>
<s>
There	O
is	O
also	O
overlap	O
among	O
strong	B-Algorithm
pseudoprimes	I-Algorithm
to	O
different	O
bases	O
.	O
</s>
<s>
For	O
example	O
,	O
1373653	O
is	O
the	O
smallest	O
strong	B-Algorithm
pseudoprime	I-Algorithm
to	O
bases	O
2	O
through	O
4	O
,	O
and	O
3215031751	O
is	O
the	O
smallest	O
strong	B-Algorithm
pseudoprime	I-Algorithm
to	O
bases	O
2	O
through	O
10	O
.	O
</s>
<s>
gives	O
a	O
397-digit	O
Carmichael	O
number	O
N	O
that	O
is	O
a	O
strong	B-Algorithm
pseudoprime	I-Algorithm
to	O
all	O
prime	O
bases	O
less	O
than	O
307	O
.	O
</s>
<s>
Because	O
this	O
N	O
is	O
a	O
Carmichael	O
number	O
,	O
N	O
is	O
also	O
a	O
(	O
not	O
necessarily	O
strong	O
)	O
pseudoprime	O
to	O
all	O
bases	O
less	O
than	O
p	O
,	O
where	O
p	O
is	O
the	O
131-digit	O
smallest	O
prime	O
factor	O
of	O
N	O
.	O
A	O
quick	O
calculation	O
shows	O
that	O
N	O
is	O
not	O
a	O
Lucas	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
when	O
D	O
,	O
P	O
,	O
and	O
Q	O
are	O
chosen	O
by	O
the	O
method	O
described	O
above	O
,	O
so	O
this	O
number	O
would	O
be	O
correctly	O
determined	O
by	O
the	O
Baillie	O
–	O
PSW	O
test	O
to	O
be	O
composite	O
.	O
</s>
<s>
The	O
following	O
computer	O
algebra	O
systems	O
and	O
software	O
packages	O
use	O
some	O
version	O
of	O
the	O
Baillie	B-Algorithm
–	I-Algorithm
PSW	I-Algorithm
primality	I-Algorithm
test	I-Algorithm
.	O
</s>
<s>
Maple	B-Language
's	O
isprime	B-Algorithm
function	O
,	O
Mathematica	B-Language
's	O
PrimeQ	O
function	O
(	O
that	O
already	O
uses	O
2020	O
's	O
version	O
of	O
Baillie	O
–	O
PSW	O
)	O
,	O
PARI/GP	B-Language
'	O
s	O
isprime	B-Algorithm
and	O
ispseudoprime	O
functions	O
,	O
and	O
SageMath	B-Application
's	O
is_pseudoprime	O
function	O
all	O
use	O
a	O
combination	O
of	O
a	O
Fermat	O
strong	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
and	O
a	O
Lucas	O
test	O
.	O
</s>
<s>
Maxima	B-Language
's	O
primep	O
function	O
uses	O
such	O
a	O
test	O
for	O
numbers	O
greater	O
than	O
341550071728321	O
.	O
</s>
<s>
The	O
FLINT	B-Language
library	O
has	O
functions	O
n_is_probabprime	O
and	O
n_is_probabprime_BPSW	O
that	O
use	O
a	O
combined	O
test	O
,	O
as	O
well	O
as	O
other	O
functions	O
that	O
perform	O
Fermat	O
and	O
Lucas	O
tests	O
separately	O
.	O
</s>
<s>
This	O
method	O
does	O
one	O
or	O
more	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
tests	I-Algorithm
with	O
random	O
bases	O
.	O
</s>
<s>
The	O
use	O
of	O
random	O
bases	O
in	O
the	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
tests	I-Algorithm
has	O
an	O
advantage	O
and	O
a	O
drawback	O
compared	O
to	O
doing	O
a	O
single	O
base	O
2	O
test	O
as	O
specified	O
in	O
the	O
Baillie	O
–	O
PSW	O
test	O
.	O
</s>
<s>
In	O
Perl	B-Language
,	O
the	O
Math::Primality	O
and	O
Math::Prime::Util	O
modules	O
have	O
functions	O
to	O
perform	O
the	O
strong	O
Baillie	O
–	O
PSW	O
test	O
as	O
well	O
as	O
separate	O
functions	O
for	O
strong	B-Algorithm
pseudoprime	I-Algorithm
and	O
strong	O
Lucas	O
tests	O
.	O
</s>
<s>
In	O
Python	B-Language
,	O
the	O
NZMATH	O
library	O
has	O
the	O
strong	B-Algorithm
pseudoprime	I-Algorithm
and	O
Lucas	O
tests	O
,	O
but	O
does	O
not	O
have	O
a	O
combined	O
function	O
.	O
</s>
<s>
The	O
SymPy	B-Application
library	O
does	O
implement	O
this	O
.	O
</s>
<s>
As	O
of	O
6.2.0	O
,	O
GNU	B-Application
Multiple	I-Application
Precision	I-Application
Arithmetic	I-Application
Library	I-Application
's	O
mpz_probab_prime_p	O
function	O
uses	O
a	O
strong	O
Lucas	O
test	O
and	O
a	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
test	I-Algorithm
;	O
previous	O
versions	O
did	O
not	O
make	O
use	O
of	O
Baillie	O
–	O
PSW	O
.	O
</s>
<s>
Magma	B-General_Concept
's	O
IsProbablePrime	O
and	O
IsProbablyPrime	O
functions	O
use	O
20	O
Miller	B-Algorithm
–	I-Algorithm
Rabin	I-Algorithm
tests	I-Algorithm
for	O
numbers	O
>	O
34·1013	O
,	O
but	O
do	O
not	O
combine	O
them	O
with	O
a	O
Lucas	B-Algorithm
probable	I-Algorithm
prime	I-Algorithm
test	O
.	O
</s>
