Section 12.1 Finding More Primes
Subsection 12.1.1 Fermat primes
Here is an interesting historical example. Recall (Subsection 11.5.1) that our friend Pierre de Fermat thought that numbers of the form 22n+1 would always be prime – numbers such as 5, 17, and 257.Definition 12.1.1.
We call numbers of the form Fn=22n+1 Fermat numbers.
xxxxxxxxxx
for n in [0..7]:
pretty_print(html("If $n=%s$, then $2^{2^n}+1=2^{2^%s}+1=%s$ factors as $%s$"%(n,n,2^(2^n)+1,factor(2^(2^n)+1))))
Subsection 12.1.2 Primes from Fermat numbers
However, we can at least prove what seems obvious in the computation after Definition 12.1.1 – namely, that lots of primes arise as factors of Fermat numbers, even when Fn isn't itself prime. First, we need a lemma.Lemma 12.1.2.
Suppose ℓ=jk is even, and k is an even factor. Then 2ℓ−1 factors as
Proof.
Multiply and/or apply a little induction. (See Exercise 12.7.1.)
Example 12.1.3.
For instance, 26−1=63 factors as
which corresponds to the factorization 9⋅7.
Similarly, 212−1=4095 factors as
which corresponds to the factorization 9⋅455.
Proposition 12.1.4. Fermat numbers are coprime.
Fn=22n+1 and Fm=22m+1 are coprime if m≠n.
Proof.
First, notice that any two Fermat numbers are very closely related to each other; if \(n<m\text{,}\) then \(F_n-1\) divides \(F_m-1\text{.}\) In fact, one is a power of the other:
Because of this, using Lemma 12.1.2 with \(j=2^n\) and \(k=2^{m-n}\) (which is certainly even), we get
This implies the divisibility relationship
so any number \(d\) that divides \(F_n\) also divides \(F_m-2\text{.}\) Now we do a standard trick (see also Exercise 2.5.6). Combine all of the above facts to see that any divisor of \(F_n\) which also divides \(F_m\) must divide \(F_m-(F_m-2)=2\text{,}\) so a common divisor of \(F_n\) and \(F_m\) could only be two or one.
But both Fermat numbers are odd, so the gcd must be 1.
Subsection 12.1.3 Mersenne primes
Another early attempt at finding big primes was an idea of Marin Mersenne.Historical remark 12.1.5. Marin Mersenne.
Mersenne was a Minim monk who not only acted as a clearinghouse for scientific knowledge in early 17th century France (particularly between Pascal, Fermat, Descartes,, Roberval, and their friends) but also wrote major theological and music theoretical treatises of his own. See Figure 19.4.7.
Definition 12.1.6.
In general, numbers of the form Mn=2n−1 are called Mersenne numbers. If they are prime, they are called Mersenne primes.
xxxxxxxxxx
for p in prime_range(100):
pretty_print(html("If $p=%s$, then $2^p-1=2^{%s}-1=%s$ factors as $%s$"%(p,p,2^p-1,factor(2^p-1))))
Historical remark 12.1.7. GIMPS.
You can help the world search for more Mersenne primes if you leave your personal computer on and connected to the Internet, via the Great Internet Mersenne Prime Search (GIMPS). Random computers in labs at the University of Central Missouri and UCLA have found some of the largest known primes this way.
The most recent one (as of this writing in January 2021) was found in December 2018! The largest known such primes are very large; this one has nearly twenty-five million digits, and the folks at Numberphile made a very amusing video unwrapping a book containing a previous record holder of ‘only’ twenty-two million digits. GIMPS even won a monetary prize for finding these huge primes; they shared it with many of the people who made it possible.
Historical remark 12.1.8. The Skylake bug.
These primes are far too large, and are not common enough, to use for most serious applications 2 , but nonetheless they help us investigate ideas about primes. A less obvious but interesting application is that searching for very large primes can also help more mundane hardware testing.
A good example of this is that computing the GIMPS program uncovered a bug in a major Intel chip. Number theory can push our hardware (and software!) beyond our imagination. (See also Historical remark 22.3.9.)
Algorithm 12.1.9. Lucas-Lehmer test.
Let x0=4 and let p be prime (greater than 2). To test whether 2p−1 is prime, create the list of numbers
Do this p−2 times; if the result xp−2 is divisible by 2p−1 (i.e., is zero modulo 2p−1), then 2p−1 is in fact prime.
Example 12.1.10.
With p=5 and 2p−1=31, we would start with x0=4; doing it 5−2=3 times gives:
42−2=14 modulo 31 is 14
142−2=194 modulo 31 is 8
82−2=62 modulo 31 is 0
And of course 31 is indeed prime.
xxxxxxxxxx
def _(p=(71,prime_range(100))):
test = 4
num = 2^p-1
for i in range(p-2):
test=(test^2-2)%num
pretty_print(html("The test says "+str(bool(test==0))))
pretty_print(html("And in fact $2^{%s}-1=%s$ primality is "%(p,num)+str(is_prime(num))))
Subsection 12.1.4 Primes from Mersenne numbers
We can prove the lesser result that Mersenne numbers are coprime, which (just as with the Fermat numbers) can give us a lot of interesting prime factors.Proposition 12.1.11. Mersenne numbers are coprime.
Mersenne numbers 2p−1 and 2q−1 with coprime exponents are themselves coprime.
Proof.
By way of contradiction, let \(d>1\) be the gcd of the two numbers \(2^p-1\) and \(2^q-1\text{.}\) Let's investigate the order of \(2\neq 1\) in \(U_{d}\text{.}\) (Before reading more, think about why \(2\) is even in this group.)
By definition of divisibility,
By group theory (use Theorem 8.3.12) we know that \(2^k\equiv 1\) means that \(k\) is a multiple of the order \(|2|\) of the element \(2\text{.}\) Thus \(p\) and \(q\) both are multiples of \(|2|\text{.}\)
Since \(p\) and \(q\) are coprime, though, the only possibility for \(|2|\) is that \(|2|=1\text{.}\) This is a contradiction, so our assumption that \(d>1\) was wrong.