ArticleslgStudy

science

Lucas–Lehmer primality test

Lucas–Lehmer primality test is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Lucas–Lehmer primality test rather than just read about it. In short: In mathematics, the Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers. The test was originally developed by Édouard Lucas in 1878 and subsequently proved by Derrick Henry Lehmer in 1930.

Lucas–Lehmer primality test — main illustration
Lucas–Lehmer primality test — illustration

Key takeaways

  • Lucas–Lehmer primality test belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Lucas–Lehmer primality test to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Lucas–Lehmer primality test from memory before moving on to harder problems.

Reference excerpt

In mathematics, the Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers. The test was originally developed by Édouard Lucas in 1878 and subsequently proved by Derrick Henry Lehmer in 1930.

The test The Lucas–Lehmer test works as follows. Let Mp = 2p − 1 be the Mersenne number to test with p an odd prime. The primality of p can be efficiently checked with a simple algorithm like trial division since p is exponentially smaller than Mp. Define a sequence { s i } {\displaystyle \{s_{i}\}} for all i ≥ 0 by

s i = { 4 if i = 0 ; s i − 1 2 − 2 otherwise. {\displaystyle s_{i}={\begin{cases}4&{\text{if }}i=0;\\s_{i-1}^{2}-2&{\text{otherwise.}}\end{cases}}}

The first few terms of this sequence are 4, 14, 194, 37634, ... (sequence A003010 in the OEIS). Then Mp is prime if and only if

s p − 2 ≡ 0 ( mod M p ) . {\displaystyle s_{p-2}\equiv 0{\pmod {M_{p}}}.}

The number sp − 2 mod Mp is called the Lucas–Lehmer residue of p. (Some authors equivalently set s1 = 4 and test sp−1 mod Mp). In pseudocode, the test might be written as

// Determine if Mp = 2p − 1 is prime for p > 2 Lucas–Lehmer(p) var s = 4 var M = 2p − 1 repeat p − 2 times: s = ((s × s) − 2) mod M if s == 0 return PRIME else return COMPOSITE

Performing the mod M at each iteration ensures that all intermediate results are at most p bits (otherwise the number of bits would double each iteration). The same strategy is used in modular exponentiation.

Alternative starting values Starting values s0 other than 4 are possible, for instance 10, 52, and others (sequence A018844 in the OEIS). The Lucas–Lehmer residue calculated with these alternative starting values will still be zero if Mp is a Mersenne prime. However, the terms of the sequence will be different and a non-zero Lucas-Lehmer residue for non-prime Mp will have a different numerical value from the non-zero value calculated when s0 = 4. It is also possible to use the starting value (2 mod Mp)(3 mod Mp)−1, usually denoted by 2/3 for short. This starting value equals (2p + 1) /3, the Wagstaff number with exponent p. Starting values like 4, 10, and 2/3 are universal, that is, they are valid for all (or nearly all) p. There are infinitely many additional universal starting values. However, some other starting values are only valid for a subset of all possible p, for example s0 = 3 can be used if p = 3 (mod 4). This starting value was often used where suitable in the era of hand computation, including by Lucas in proving M127 prime. The first few terms of the sequence are 3, 7, 47, ... (sequence A001566 in the OEIS).

Sign of penultimate term If sp−2 = 0 mod Mp then the penultimate term is sp−3 = ± 2(p+1)/2 mod Mp. The sign of this penultimate term is called the Lehmer symbol ϵ(s0, p). In 2000 S.Y. Gebre-Egziabher proved that for the starting value 2/3 and for p ≠ 5 the sign is:

ϵ ( 2 3 , p ) = ( − 1 ) p − 1 2 {\displaystyle \epsilon ({2 \over 3},\ p)=(-1)^{p-1 \over 2}}

That is, ϵ(2/3, p) = +1 if p = 1 (mod 4) and p ≠ 5. The same author also proved Woltman's conjecture that the Lehmer symbols for starting values 4 and 10 when p is not 2 or 5 are related by:

ϵ ( 10 , p ) = ϵ ( 4 , p ) × ( − 1 ) ( p + 1 ) ( p + 3 ) 8 {\displaystyle \epsilon (10,\ p)=\epsilon (4,\ p)\ \times \ (-1)^{{(p+1)(p+3)} \over 8}}

That is, ϵ(4, p) × ϵ(10, p) = 1 if p = 5 or 7 (mod 8) and p ≠ 2, 5. OEIS sequence A123271 shows ϵ(4, p) for each Mersenne prime Mp.

Time complexity In the algorithm as written above, there are two expensive operations during each iteration: the multiplication s × s, and the mod M operation. The mod M operation can be made particularly efficient on standard binary computers by observing that

k ≡ ( k mod 2 n ) + ⌊ k / 2 n ⌋ ( mod 2 n − 1 ) . {\displaystyle k\equiv (k\,{\bmod {\,}}2^{n})+\lfloor k/2^{n}\rfloor {\pmod {2^{n}-1}}.}

… excerpt ends here. Continue reading the full article.

Illustrations

Lucas–Lehmer primality test illustration

Worked examples

Example 1 — a first encounter with Lucas–Lehmer primality test

Start with the simplest possible case. Write down what Lucas–Lehmer primality test claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Lucas–Lehmer primality test before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Lucas–Lehmer primality test ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Lucas–Lehmer primality test

In research
Lucas–Lehmer primality test appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Lucas–Lehmer primality test in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Lucas–Lehmer primality test is common in secondary-school and first-year university syllabi. It links to neighbouring topics Mersenne primes, Primality tests, so understanding it makes those chapters shorter.
In everyday life
Look for Lucas–Lehmer primality test outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Lucas–Lehmer primality test” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Lucas–Lehmer primality test in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Lucas–Lehmer primality test means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Lucas–Lehmer primality test out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Lucas–Lehmer primality test in simple terms?

In mathematics, the Lucas–Lehmer test (LLT) is a primality test for Mersenne numbers. The test was originally developed by Édouard Lucas in 1878 and subsequently proved by Derrick Henry Lehmer in 1930.

Why does Lucas–Lehmer primality test matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Lucas–Lehmer primality test?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Lucas–Lehmer primality test.

Tags

  • Mersenne primes
  • Primality tests

Keep exploring