Section 12.2 Primes β Probably
ΒΆSubsection 12.2.1 Pseudoprimes
ΒΆWe start this discussion with our visual representation of powers (see Subsection 8.2.1).
xxxxxxxxxx
import matplotlib.pyplot as plt
from matplotlib.ticker import IndexLocator, FuncFormatter
def power_table_plot(p=(11,prime_range(100))):
mycmap = plt.get_cmap('gist_earth',p-1)
myloc = IndexLocator(floor(p/5),.5)
myform = FuncFormatter(lambda x,y: int(x+1))
cbaropts = { 'ticks':myloc, 'drawedges':True, 'boundaries':srange(.5,p+.5,1)}
P=matrix_plot(matrix(p-1,[mod(a,p)^b for a in range(1,p) for b in srange(p+1)]),cmap=mycmap, colorbar=True, colorbar_options=cbaropts, ticks=[myloc,myloc], tick_formatter=[None,myform])
show(P,figsize=6)
Fact 12.2.2.
If there is an a such that anβ’a (mod n), then n must be composite.
Definition 12.2.3.
If anβ‘a (mod n), we say n passes the base a test.
xxxxxxxxxx
def _(n=100):
pretty_print(html("Here are the numbers through $%s$ that pass the base 2 test"%n))
pretty_print(html("along with whether they are actually prime"))
for i in [2..n]:
if mod(2^i,i)==2:
pretty_print(html(r"$2^{%s}\equiv 2\text{ (mod }%s)$ and the primality of $%s$ is %s"%(i,i,i,is_prime(i))))
Question 12.2.4.
Are there any numbers which satisfy the base a test and are not prime?
xxxxxxxxxx
print("We factor 341 and get %s"%factor(341))
print("We factor 561 and get %s"%factor(561))
print("We factor 645 and get %s"%factor(645))
Definition 12.2.5. Pseudoprimes.
If anβ‘a (mod n) but n is not prime, we say it is a pseudoprime base a.
Fact 12.2.6.
If n is a pseudoprime (base 2), then so is 2nβ1.
Subsection 12.2.2 Prime impostors, and how to avoid them
ΒΆIf we want to check things out more carefully, we can try to test for primality with a different base. In the next cell, we choose a=3.xxxxxxxxxx
for n in [341,561,645]:
pretty_print(html(r"$3^{%s}\equiv %s\text{ (mod }%s)"%(n,mod(3,n)^n,n)))
xxxxxxxxxx
def _(p=(5,prime_range(50))):
for pr in prime_range(next_prime(p)):
pretty_print(html(r"$%s^{561}\equiv %s\text{ (mod }561)"%(pr,mod(pr,561)^561)))
xxxxxxxxxx
def _(p=(5,prime_range(1000))):
pretty_print(html("The primes up to $%s$ for which $561$ fails the base $p$ test:"%p))
for pr in prime_range(next_prime(p)):
if mod(pr,561)^561!=pr:
pretty_print(html(r"$%s^{561}\equiv %s\\text{ (mod }561)$"%(pr,mod(pr,561)^561)))
Fact 12.2.7.
The number 561 is a pseudoprime for every integer base a.
Proof.
We know that
so by the Chinese Remainder Theorem
if and only if \(a^{561}\equiv a\) holds for the prime power factors \(3,11,17\text{;}\) so we will check them.
Remember, the exponents for these congruences live in the (mod \(\phi(p)\)) world, so we just need to check what \(561\) is in each of those worlds. We get:
\(561\equiv 1\text{ (mod }16=17-1)\) so \(a^{561}\equiv a^1\text{ (mod }17)\)
\(561\equiv 1\text{ (mod }2=3-1)\) so \(a^{561}\equiv a^1\text{ (mod }3)\)
\(561\equiv 1\text{ (mod }10=11-1)\) so \(a^{561}\equiv a^1\text{ (mod }11)\)
That is, for \(p=3,11,17\) we see
Using Proposition 5.4.4, this congruence is always true!
By the way, we note that \(a^{560}\) is not congruent to \(1\text{,}\) which explains why we use \(a^n\equiv a\) for these definitions.
Definition 12.2.8.
We call a number which is pseudoprime to every base a, but is not a prime number a Carmichael number, in honor of the first person to actually produce such numbers, Robert Carmichael (in 1912).
xxxxxxxxxx
factor(561)
Proposition 12.2.9. Korselt's Theorem.
Carmichael numbers are precisely those composite n for which n is a product of at least two distinct primes pi (no squares)
such that
for all the prime factors.
Proof.
Prime numbers satisfy almost all the conditions trivially. To show that \(561\) is a Carmichael number we used this idea in the form \(n\equiv 1\) (mod \(\phi(p_i)\)) for all three prime factors, and essentially the same argument applied to any number satisfying the hypotheses is a Carmichael number.
We will not prove the other half of this theorem (that all Carmichael numbers have this form). It is not hard, however, using a slight variant on the Euler \(\phi\) function one can acquire from investigating \(U_n\) for composite \(n\text{.}\)
Example 12.2.10.
Evaluate this Sage cell to see the previous result applied to identify another Carmichael number.
xxxxxxxxxx
n=29341
pretty_print(html("$%s$ is composite with factorization $%s$, but"%(n,factor(n))))
for fact,pow in factor(n):
pretty_print(html(r"$%s^{%s}\equiv %s\text{ (mod }%s)$"%(fact,n,mod(fact,n)^n,n)))
pretty_print(html("and"))
for fact,pow in factor(n):
pretty_print(html(r"$%s\equiv %s\text{ (mod }\phi(%s)=%s)$"%(n, mod(n,euler_phi(fact)), fact, euler_phi(fact))))