Meissel–Lehmer algorithm
   HOME

TheInfoList



OR:

The Meissel–Lehmer algorithm (after Ernst Meissel and Derrick Henry Lehmer) is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
that computes exact values of the
prime-counting function In mathematics, the prime-counting function is the function counting the number of prime numbers less than or equal to some real number . It is denoted by (unrelated to the number ). A symmetric variant seen sometimes is , which is equal ...
.


Description

The problem of counting the exact number of primes less than or equal to ''x'', without actually listing them all, dates from Legendre. He observed from the
Sieve of Eratosthenes In mathematics, the sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite number, composite (i.e., not prime) the multiples of each prime, starting with ...
that : \pi (x) - \pi (x^) + 1 = \lfloor x \rfloor - \sum_ \lfloor x/p_i \rfloor + \sum_ \lfloor x/p_ip_j \rfloor - \ldots where is the floor function, which denotes the greatest integer less than or equal to and the run over all primes . Since the evaluation of this sum formula becomes more and more complex and confusing for large ', Meissel tried to simplify the counting of the numbers in the Sieve of Eratosthenes. He and Lehmer therefore introduced certain sieve functions, which are detailed below.


Key functions

Let be the first primes. For a natural number , define : \varphi(x, a) := \left, \left \ \, which counts natural numbers no greater than ' with all prime factors greater than . Also define for a natural number , : P_k(x, a) := \left, \left \ \, which counts natural numbers no greater than ' with exactly ' prime factors, all greater than . With these, we have :\varphi(x, a) = \sum_^\infty P_k(x, a), where the sum only has finitely many nonzero terms because when . Using the fact that and , we get :\pi(x) = \varphi(x,a) + a - 1 - \sum_^\infty P_k(x,a), which proves that one may compute by computing and for . This is what the Meissel–Lehmer algorithm does.


Formula for ''P''''k''(''x'', ''a'')

For , we get the following formula for : :\begin P_2(x, a) & =\left, \left\ \ \\ & = \sum_^ \left, \left\ \ \\ & = \sum_^ \left( \pi\left( \frac \right) - (b-1) \right) \\ & = \binom - \binom + \sum_^ \pi\left( \frac \right). \end For , the identities for can be derived similarly.


Expanding

With the starting condition : \varphi(x, 0) = \lfloor x \rfloor, and the recurrence : \varphi(x, a) = \varphi(x, a-1) - \varphi\left(\frac x , a-1 \right), each value for can be calculated recursively.


Combining the terms

The only thing that remains to be done is evaluating and for , for certain values of and . This can be done by direct sieving and using the above formulas.


History

Meissel already found that for , if . He used the resulting equation for calculations of for big values of . Meissel calculated for values of ' up to , but he narrowly missed the correct result for the biggest value of '. Using his method and an
IBM 701 The IBM 701 Electronic Data Processing Machine, known as the Defense Calculator while in development, was IBM’s first commercial scientific computer and its first series production mainframe computer, which was announced to the public on May 2 ...
, Lehmer was able to compute the correct value of and missed the correct value of by 1.


Extended algorithm

Jeffrey Lagarias, Victor Miller and
Andrew Odlyzko Andrew Michael Odlyzko (Andrzej Odłyżko) (born 23 July 1949) is a Polish- American mathematician and a former head of the University of Minnesota's Digital Technology Center and of the Minnesota Supercomputing Institute. He began his career i ...
published a realisation of the algorithm which computes in time and space for any . Upon setting , the tree of has leaf nodes. This extended Meissel-Lehmer algorithm needs less computing time than the algorithm developed by Meissel and Lehmer, especially for big values of '. Further improvements of the algorithm are given by M. Deleglise and J. Rivat in 1996.


References

{{DEFAULTSORT:Meissel-Lehmer algorithm Number theoretic algorithms