Our next plan is to discuss pseudoprime tests for compositeness.
See the book [5], Chapters 3 and 6.
Note especially the definition at the top of page 33 and the definition of a Carmichael
number: A number
is a Carmichael number if
for all
relatively prime to
.
Recall modular exponentiation using repeated squaring; to compute
:
A sample computation:
.
| n | a | b |
| 1 | 2 | 1370 |
| 1 | 4 | 685 |
| 4 | 16 | 342 |
| 4 | 256 | 171 |
| 1024 | 1099 | 85 |
| 1156 | 1321 | 42 |
| 1156 | 1129 | 21 |
| 1303 | 982 | 10 |
| 1303 | 511 | 5 |
| 898 | 631 | 2 |
| 898 | 571 | 1 |
| 4 | 0 |
The answer is four, obtained in 12 steps involving numbers modulo 1371.
The number 561 is a Carmichael number because 561=(3)(11)(17). 561-1 is divisible
by 2, by 10, and by 16. Consequently, if a isn't divisible by 3, 11, or 17,
then
is congruent to 1 mod 2, mod 11, and mod 17.
By the chinese remainder theorem it is then congruent to 1 mod 561.
A number
is a (Fermat) pseudoprime base
if it is
composite and
. Psuedoprimes are (relatively)
rare. The psuedoprimes base
less than 10,000 are shown below,
see [6].
| Factors | |
| 341 | 11 31 |
| 561 | 3 11 17 |
| 645 | 3 5 43 |
| 1105 | 5 13 17 |
| 1387 | 19 73 |
| 1729 | 7 13 19 |
| 1905 | 3 5 127 |
| 2047 | 23 89 |
| 2465 | 5 17 29 |
| 2701 | 37 73 |
| 2821 | 7 13 31 |
| 3277 | 29 113 |
| 4033 | 37 109 |
| 4369 | 17 257 |
| 4371 | 3 31 47 |
| 4681 | 31 151 |
| 5461 | 43 127 |
| 6601 | 7 23 41 |
| 7957 | 73 109 |
| 8321 | 53 157 |
| 8481 | 3 11 257 |
| 8911 | 7 19 67 |
The strong pseudoprime test is much better at detecting composite numbers than the traditional Fermat pseudoprime test. The test is given on page 77 of Bressoud.
The principle is: if
is prime,
is even,
and
, then
.
If we write
, and
is prime, then
either
, or the sequence of powers
must contain first a -1,
followed by a 1.
Here is a sample computation of the strong pseudoprime test for 341, using base 2.
| 1 | 2 | 85 |
| 2 | 4 | 42 |
| 2 | 16 | 21 |
| 32 | 256 | 10 |
| 32 | 64 | 5 |
| 2 | 4 | 2 |
| 2 | 16 | 1 |
| 32 | 0 |
Note that it is still the case that
,
so
is a Fermat pseudoprime.
To illustrate the power of this method in detecting composites, we have the following facts, confirmed by computer search in [7]:
This gives a very quick test for primality for numbers less than 25 billion.
Recall from our discussion above that a Carmichael number is a composite
number
such that
for all
relatively prime to
.
We will make repeated use of the following assertion.
Proof: Because
, we know that
has a multiplicative inverse
mod
.
Write
for integers
. Then
.
Now we prove the proposition, following [5, Theorem 6.5], though expressing it differently. Also we treat even numbers and prime powers together.
Suppose that
is even and composite. Then
is odd, so
.
Thus
is a base for which
is not a pseudoprime.
The following is new and different, and is a much simpler approach than I was using in class.
Suppose that
is odd and composite. Suppose that
is the prime factorization of
. Find
such that
,
but
for
. Write
, with
odd.
Then
, but
and
for
. Therefore
. Thus
is a base such that
is not a strong pseudoprime base
.
This is my version of Bressoud's proof, which is much more complicated. Why does he do it this way, and why did I listen to him?
Now suppose that
is an odd prime power, say
, with
. Suppose that
. As always,
.
Then by the lemma we must have
where
because
does not divide
.
Let
be a primitive root mod
. (See [1, Theorem 2.41])
Since
, we see that
,
so we've found an
so that
is not a strong pseudoprime base
.
Now suppose that
is odd and has at least two different prime factors
and
.
Suppose that
,
, and
, with
,
,
and
odd, and with
.
Choose
so that
Now let
be the smallest integer so that
.
We always have
, so
that
where
. Now if
were
smaller than
, it would follow that
(why?)
but that isn't so. Therefore
.
We now know that
, so that
.
Now return to the sequence
. Let
be the smallest
power such that
. Then
,
so that
. But if
is a pseudoprime base
, and
, then
, and in particular it is NOT equivalent to
mod
, hence not
mod
. Thus we must have
. But then
, which is a
contradiction. Thus
is not a pseudoprime base
, which is what we wanted to show.
Efficiency of psuedoprime testing
Let us consider the time required to perform a pseudoprime
test. For simplicity, we will talk about the Fermat test.
We know from our discussion of arithmetic that multiplication
of two numbers of size
takes time
if we use
traditional multiplication, and less time if we use Karatsuba.
Although we did not prove this, we will further use the fact
that computing quotients and remainders of numbers of size
also requires time
.
Carrying out a Fermat pseudoprime test requires us to compute
. The repeated squaring algorithm requires
at most one squaring and one multiplication modulo
for each step
of the algorithm. These steps need to be done until repeated division
of
by
yields a number smaller than one. This, in turn, requires
steps at most. Therefore the number of steps required
to do a Fermat test is
.
This should be contrasted with the ``Trial Division'' method of
determining if a number is prime. In this method, we divide
successively by every (prime) number smaller than
.
If we find a factor, then
is composite; if not, then
is prime.
The number of steps here is at worst (the number of primes less than
)
times (the time for each division), which is
at most
, or
.
To see the significance of this difference, suppose that we can apply
trial division to a 10 digit number
in five seconds (this is how long
it takes, roughly, on my current computer using Maple - admittedly we could
do a lot better). The time to do trial division, being
,
grows proportionally like
as
gets bigger. For a twenty
digit number, the factor
is
, or
. Thus to do a twenty digit number would take
a million seconds (5*200000), or something like two weeks. To do a fifty
digit number would take
seconds. This number is greater
than the age of the universe.
By comparison, if a pseudoprime test on a 10 digit number takes 1 second (it really takes much less time) doing a pseudoprime test on a 50 digit number takes about 125 times as long - about two minutes.
This illustrates the difference between algorithms whose running
time is polynomial in
, and algorithms whose running
time depends on a power of
.