We define a function to output Fermat numbers:
A table of the first few Fermat numbers:
Factorization of F5:
The procedure below will compute appropriate powers of 3 mod F3 to allow us to apply Peppin's test:
Thus, Peppin's test implies F3 is prime. Now we try it for F7:
In this case, Peppin's test tell us that F7 is composite.
We now define a function to implement Peppin's test:
Using the function we defined, we can produce a table summarizing what goes on for the first 8 Fermat numbers.
The built-in factor command can't factor F10 in a reasonable amount of time. Try it:
However, our Peppin's test function can tell us instantly that F10 is composite:
We define a function to output Mersenne numbers:
The procedure below will find the Mersenne primes with exponent less than 258:
Using Fermat's Little Theorem we can sometimes show a Mersenne number is composite.
Thus M7 is composite.
Thus M67 is composite.
Thus M7 is prime.
The following function implements the Lucas-Lehmer test:
We now use our function to find the Mersenee primes with exponent less than 500.
The command Primes() will produce the set of primes, and if we apply the command unrank(n) to it, we obtain the n-th prime.
We look for a witness to the primality of 104729:
Thus 12 is a witness to the primality of 104729.
The following function will return the list of prime divisors of a number:
The following function will produce a prime certificate when a prime number is given as input.
We begin by modifying out prime_certificate command to make it into a prime testing procedure. The input is a number n to be testes and prime divisor p of n-1.
We use this function to test the primality of numbers of the form kp+1 for random values of k.
We now build a function which automates the steps above to produce a prime with more than d digits.