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 rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
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 ''x''. It is denoted by (''x'') (unrelated to the number ). History Of great interest in number theory is t ...
.


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 (i.e., not prime) the multiples of each prime, starting with the first prime n ...
that : \pi (x) - \pi (x^) + 1 = \lfloor x \rfloor - \sum_ \lfloor x/p_i \rfloor + \sum_ \lfloor x/p_ip_j \rfloor - \ldots where \lfloor x \rfloor is the floor function, which denotes the greatest integer less than or equal to x and the p_i run over all primes \leq x^. Since the evaluation of this sum formula is becoming more and more complex and confusing for large x, Meissel tried to simplify the counting of the numbers in the Sieve of Eratosthenes. He and Lehmer introduced therefore certain sieve functions, which are detailed below.


Key functions

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


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

For ''k'' = 2, we get the following formula for P_k(x,a): :\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 ''k'' ≥ 3, the identities for P_k(x,a) can be derived similarly.


Expanding ''𝜑''(''x'', ''a'')

Using the recurrence : \varphi(x, a) = \varphi(x, a-1) - \varphi\left(\frac x , a-1 \right), \varphi(x,a) may be expanded. Each summand, in turn, may be expanded in the same way.


Combining the terms

The only thing that remains to be done is evaluating \varphi(x, a) and P_k(x, a) for ''k'' ≥ 2, for certain values of ''x'' and ''a''. This can be done by direct sieving and using the above formulas.


History

Meissel already found that for ''k'' ≥ 3, P_k(x,a) = 0 if a = \pi(x^). He used the resulting equation for calculations of \pi(x) for big values of x. Meissel calculated \pi(x) for values of ''x'' up to 10^, but he narrowly missed the correct result for the biggest value of ''x''. 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 ...
, Lehmer was able to compute the correct value of \pi\left(10^\right) and missed the correct value of \pi\left(10^\right) by 1.


Extended algorithm

Jeffrey Lagarias, Victor Miller and Andrew Odlyzko published a realisation of the algorithm which computes \pi(x) in time O(x^) and space O(x^) for any \varepsilon > 0. Upon setting a = \pi(x^), the tree of \varphi(x, a) has O(x^) leaf nodes. This extended Meissel-Lehmer algorithm needs less computing time than the algorithm developed by Meissel and Lehmer, especially for big values of ''x''. Further improvements of the algorithm are given by M. Deleglise and J. Rivat in 1996.


References

{{DEFAULTSORT:Meissel-Lehmer algorithm Number theoretic algorithms