Study started since 2011年10月17日 素性测试算法,素性测定(11Y11) primality testing



Yüklə 1,18 Mb.
səhifə7/13
tarix22.07.2018
ölçüsü1,18 Mb.
#58231
1   2   3   4   5   6   7   8   9   10   ...   13

13.13.Lucas-Lehmer测试

Lucas–Lehmer



http://calistamusic.dreab.com/p-Lucas%E2%80%93Lehmer_primality_test

Der Lucas-Lehmer Test ist ein deterministischer Primzahltest, der entscheidet, ob eine Mersenne-Zahl Mn = 2n − 1 f¨ur ein vorgelegtes n > 2 prim ist oder nicht.



13.13.1.梅森素数判定算法Lucas-Lehmer测试

2010-03-14 13:14:20| 分类: 默认分类 |字号 订阅


梅森素数判定法的算法设计
法国数学家Lucas在研究著名的斐波那契数列时" 惊人地发现它与梅森素数的联系"他由此提出了一个用以判别Mp是否为素数的重要定理!!!卢卡斯定理"为梅森素数的研究提供了有利工具。1930年,"美国数学家Lehmer改进了Lucas,的工作" 给出一个针对Mp的新的素性测试方法" 即Lucas-Lehmer测试:对于所有大于1的奇数p,Mp是素数当且仅当Mp整除S(p-1),其中S(n)由S(n)=S(n-1)^2-2,S(1)=4 递归定义。
这个方法尤其适合于计算机运算,因为除以Mp的运算在二进制下可以简单地用计算机特别擅长的移位和加法操作来实现。
以下是用C语言实现的可实际使用的Lucas-Lehmer测试:
Lucas-Lehmer_test(int p)
{
int s,i,s1;
for(i=0,s1=1;i
s1--;
for(i=3,s=4;i<=p;i++) (s=s*s-2)%s1;
return s==0?1:0;
}
This article is about the Lucas–Lehmer test that only applies to Mersenne numbers. For the Lucas–Lehmer test that applies to a natural number n, see Lucas primality test. For the Lucas–Lehmer–Riesel test, see Lucas–Lehmer–Riesel test.

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


13.13.2.Contents


  • 1 The test

  • 2 Time complexity

  • 3 Examples

  • 4 Proof of correctness

    • 4.1 Sufficiency

    • 4.2 Necessity

  • 5 Applications

  • 6 See also

  • 7 References

  • 8 External links

13.13.3.The test


The Lucas–Lehmer test works as follows. Let Mp = 2p − 1 be the Mersenne number to test with p an odd prime (because p is exponentially smaller than Mp, we can use a simple algorithm like trial division for establishing its primality). Define a sequence {s i } for all i ≥ 0 by

The first few terms of this sequence are 4, 14, 194, 37634, ... (sequence  A003010). Then Mp is prime iff



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



// Determine if Mp = 2p 1 is prime

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

By performing the mod M at each iteration, we ensure that all intermediate results are at most p bits (otherwise the number of bits would double each iteration). It is exactly the same strategy employed in modular exponentiation.


13.13.4.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 the following simple property:

In other words, if we take the least significant n bits of k, and add the remaining bits of k, and then do this repeatedly until at most n bits remain, we can compute the remainder after dividing k by the Mersenne number 2n−1 without using division. For example:



916 mod 25−1

=

11100101002 mod 25−1




=

111002 + 101002 mod 25−1




=

1100002 mod 25−1




=

12 + 100002 mod 25−1




=

100012 mod 25−1




=

100012




=

17.

Moreover, since s × s will never exceed M2 < 22p, this simple technique converges in at most 2 p-bit additions, which can be done in linear time. As a small exceptional case, the above algorithm may produce 2n−1 for a multiple of the modulus, rather than the correct value of zero; this should be accounted for.

With the modulus out of the way, the asymptotic complexity of the algorithm depends only on the multiplication algorithm used to square s at each step. The simple "grade-school" algorithm for multiplication requires O(p2) bit-level or word-level operations to square a p-bit number, and since we do this O(p) times, the total time complexity is O(p3). A more efficient multiplication method, the Schönhage–Strassen algorithm based on the Fast Fourier transform, requires O(p log p log log p) time to square a p-bit number, reducing the complexity to O(p2 log p log log p) or Õ(p2).. Currently the most efficient known multiplication algorithm, Fürer's algorithm, needs time to multiply two p-bit numbers.

By comparison, the most efficient randomized primality test for general integers, the Miller–Rabin primality test, takes O(k p2 log p log log p) bit operations using FFT multiplication for a p-digit number (here p can be any natural number, not necessarily a prime), where k is the number of iterations and is related to the error rate. So it is in the same complexity class as the Lucas-Lehmer test for constant k. But in practice the cost of doing many iterations and other differences leads to worse performance for Miller–Rabin. The most efficient deterministic primality test for general integers, the AKS primality test, requires Õ(p6) bit operations in its best known variant and is dramatically slower in practice.

13.13.5.Examples


Suppose we wish to verify that M3 = 7 is prime using the Lucas–Lehmer test. We start out with s set to 4 and then update it 3−2 = 1 time, taking the results mod 7:

  • s ← ((4 × 4) − 2) mod 7 = 0

Because we end with s set to zero, M3 is prime.

On the other hand, M11 = 2047 = 23 × 89 is not prime. To show this, we start with s set to 4 and update it 11−2 = 9 times, taking the results mod 2047:



  • s ← ((4 × 4) − 2) mod 2047 = 14

  • s ← ((14 × 14) − 2) mod 2047 = 194

  • s ← ((194 × 194) − 2) mod 2047 = 788

  • s ← ((788 × 788) − 2) mod 2047 = 701

  • s ← ((701 × 701) − 2) mod 2047 = 119

  • s ← ((119 × 119) − 2) mod 2047 = 1877

  • s ← ((1877 × 1877) − 2) mod 2047 = 240

  • s ← ((240 × 240) − 2) mod 2047 = 282

  • s ← ((282 × 282) − 2) mod 2047 = 1736

Because s is not zero, M11=2047 is not prime. Notice that we learn nothing about the factors of 2047, only its Lucas–Lehmer residue, 1736.

13.13.6.Proof of correctness


Lehmer's original proof of the correctness of this test is complex, so we'll depend upon more recent refinements. Recall the definition:

Then our theorem is that Mp is prime iff

We begin by noting that is a recurrence relation with a closed-form solution. Define and ; then we can verify by induction that for all i:



where the last step follows from . We will use this in both parts.


13.13.6.1.Sufficiency


In this direction we wish to show that implies that Mp is prime. We relate a straightforward proof exploiting elementary group theory given by J. W. Bruce as related by Jason Wojciechowski.

Suppose . Then for some integer k, and:



Now suppose Mp is composite, and let q be the smallest prime factor of Mp. Since Mersenne numbers are odd, we have q > 2. Define the set with q2 elements, where is the integers mod q, a finite field (in the language of ring theory X is the quotient of the univariate polynomial ring by the ideal generated by (T2 − 3)). The multiplication operation in X is defined by:



Since q > 2, and are in X (in fact are in X, but by abuse of language we identify and with their images in X under the natural ring homomorphism from to X which sends the square root of 3 to T). Any product of two numbers in X is in X, but it's not a group under multiplication because not every element x has an inverse y such that xy = 1 (in fact X is a ring and the set of non-zero elements of X is a group if and only if does not contain a square root of 3). If we consider only the elements that have inverses, we get a group X* of size at most q2 − 1 (since 0 has no inverse).

Now, since , and , we have in X, which by equation (1) gives . Squaring both sides gives , showing that ω is invertible with inverse and so lies in X*, and moreover has an order dividing 2p. In fact the order must equal 2p, since and so the order does not divide 2p 1. Since the order of an element is at most the order (size) of the group, we conclude that . But since q is the smallest prime factor of the composite Mp, we must have , yielding the contradiction 2p < 2p − 1. So Mp is prime.

13.13.6.2.Necessity


In the other direction, we suppose Mp is prime and show . We rely on a simplification of a proof by Öystein J. R. Ödseth. First, notice that 3 is a quadratic non-residue mod Mp, since 2 p − 1 for odd p > 1 only takes on the value 7 mod 12, and so the Legendre symbol properties tell us (3 | Mp) is −1. Euler's criterion then gives us:

On the other hand, 2 is a quadratic residue mod Mp, since and so . Euler's criterion again gives:



Next, define , and define X* similarly as before as the multiplicative group of . We will use the following lemmas:



(from Proofs of Fermat's little theorem#Proof_using_the_binomial_theorem)



for every integer a (Fermat's little theorem)

Then, in the group X* we have:

We chose σ such that ω = (6 + σ)2 / 24. Consequently, we can use this to compute in the group X*:



where we use the fact that



Since , all that remains is to multiply both sides of this equation by and use :



Since sp2 is an integer and is zero in X*, it is also zero mod Mp.


13.13.7.Applications


The Lucas–Lehmer test is the primality test used by the Great Internet Mersenne Prime Search to locate large primes, and has been successful in locating many of the largest primes known to date. The test is considered valuable because it can provably test a very large number for primality within affordable time and, in contrast to the equivalently fast Pépin's test for any Fermat number, can be tried on a large search space of numbers with the required form before reaching computational limits.

13.13.8.See also


  • Mersenne's conjecture

  • Lucas–Lehmer–Riesel test

  • GIMPS


Yüklə 1,18 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   10   ...   13




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə