3

The prime counting function $ \pi (x) \approx \dfrac {x} {\ln(x-1)} $. This function returns the number of primes less than $x$.

Note: $x-1$ gives a better estimate than $x$.

How to find $x$ given $ \pi(x) $ ?

lapin
  • 459
  • 5
    There are multiple $x$ which have the same value of $\pi(x)$ so there is really no hope of an inverse. You can get an interval for which $x$ would come from: if $\pi(x)=n$ then $p_{n}\leq x<p_{n+1}$. But maybe you mean given $\frac{x}{\ln(x-1)}$ how does one solve for $x$? – Eoin Jul 03 '15 at 15:04
  • 2
    As @Eoin said there is no an inverse for the counting function because it's not bijective, but we can find an asymptotic inverse, we know that $\pi(p_n)=n$ so we can say the easiest way: the inverse of $n\to \pi(n)$ is the n-th prime $n\to p_n$ which has the asymptotic formula $n\ln(n)$ – Elaqqad Jul 03 '15 at 15:09
  • I don't mean the exxact value of x, just an upper bound or an estimate, i.e. How far do I have to check to get $\pi(x)$ primes ? @Eoin. – lapin Jul 03 '15 at 15:10
  • 1
    And we know that if $n=\pi(x)$ then $$n(\ln n+\ln \ln n-1) \leq x\leq (n+1)(\ln (n+1) +\ln \ln (n+1))$$ – Elaqqad Jul 03 '15 at 15:13
  • 2
    A quite good approximation is $R^{-1}(x)$ (where R=Riemann R function, x = your $\pi(x)$, binary search can find the inverse). Easier but not as good is a truncated Cipolla (1902) series, e.g. m=2 with a 3rd order correction. Exact answers can be had using a good estimate followed by a fast prime count (e.g. LMO) followed by sieving the difference (which is small if your estimator is good). Good bounds are shown in Dusart 2010 and Axler 2013, or can be done with inverse prime count bounds (again Dusart 1999/2010 and Axler 2013/2014). – DanaJ Jul 03 '15 at 16:01
  • One might construe this question as "What is the inverse of $x\mapsto\dfrac x{\ln(x-1)}$. ${}\qquad{}$ – Michael Hardy Jul 03 '15 at 17:10
  • @MichaelHardy, yet the final sentence is "How to find x given π(x) ?" – DanaJ Jul 04 '15 at 03:12

2 Answers2

1

Instead of an analytical Expression or 1-Step Approximation use a Fixed Point Iteration that converges relatively fast to the Inverse of x/ln(x).

8 Iterations yield the Result e.g. x = 4_210_563_857 for y = 190_000_000:

    public static double PI_INVERSE(double y) {
        double xOld = 0;
        double x = y*Math.Log(y);
        const double maxDiff = 0.5;
        for (; x - xOld > maxDiff;) { //strictly monotonous
            xOld = x;
            x = y*Math.Log(x);
        }
        return x;
    }
Spoc
  • 111
  • 4
-4

Look up Meissel's prime-counting function.

One reference is here:

https://en.wikipedia.org/wiki/Prime-counting_function

marty cohen
  • 107,799