Lucas-Lehmer Test

DOWNLOAD Mathematica Notebook

The Lucas-Lehmer test is an efficient deterministic primality test for determining if a Mersenne number M_n is prime. Since it is known that Mersenne numbers can only be prime for prime subscripts, attention can be restricted to Mersenne numbers of the form M_p=2^p-1, where p is an odd prime.

Consider the recurrence equation

 s_n=s_(n-1)^2-2 (mod M_p)
(1)

with s_0=4. For example, ignoring the congruence, the first few terms of this iteration are 4, 14, 194, 37634, 1416317954, ... (OEIS A003010).

It turns out that M_p is prime iff s_(p-2)=0 (mod M_p), and the value s_(p-2) (mod M_p) is called the Lucas-Lehmer residue for p.

For example, the sequence obtained for p=7 is given by 4, 14, 67, 42, 111, 0, so M_7=127 is prime.

For prime p, the first few Lucas-Lehmer residues are 1, 0, 0, 0, 1736, 0, 0, 0, 6107895, 458738443, 0, 117093979072, ... (OEIS A095847).

This test can also be extended to arbitrary integers. Prior to the work of Pratt (1975), the Lucas-Lehmer test had been regarded purely as a heuristic that worked a lot of the time (Knuth 1969). Pratt (1975) showed that Lehmer's primality heuristic could be made a nondeterministic procedure by applying it recursively to the factors of n-1, resulting in a certification of primality that has come to be known as the Pratt certificate.

A generalized version of the Lucas-Lehmer test lets

 N+1=product_(j=1)^nq_j^(beta_j),
(2)

with q_j the distinct prime factors, and beta_j their respective powers. If there exists a Lucas sequence U_nu such that

 GCD(U_((N+1)/q_j),N)=1
(3)

for j=1, ..., n and

 U_(N+1)=0 (mod N),
(4)

then N is a prime. This reduces to the conventional Lucas-Lehmer test for Mersenne numbers.

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.