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.Remark 12.1.5.
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.
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))))
Algorithm 12.1.7. Lucas-Lehmer test.
Let x0=4 and let p be prime. 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.8.
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.9. 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.