# Estimate for $n$th prime

A good approximation I have found for $p_{n}$ is

\begin{align} \int_{2}^{n}\log (x \log (x \log (x)))\ dx\\ \end{align}

and seems to be a better estimate than $n \log (n)$.

The error term seems to agree with the asymptotic expansion of Cipolla:

$$p_n=n\log n+n\log\log n-n+n\frac{\log\log n}{\log n}+O(n(\log\log n/\log n)^2)$$

(from this MO thread) where the $O$ term is replaced for a constant (in this case, $-e$).

Perhaps more interestingly, it seems that applying successive $\log$ terms to the integral

\begin{align} &\int_{2}^{n}\log (x)\ dx&\tag{1}\\ &\int_{2}^{n}\log (x \log (x))\ dx &\tag{2}\\ &\int_{2}^{n}\log (x \log (x \log (x)))\ dx &\tag{3}\\ &\int_{2}^{n}\log (x \log (x \dots \log (x)))\ dx &\tag{4}\\ \end{align}

seems to move very slowly towards a better asymptotic. Is this the case?

Numerical results at @RghtHndSd's request:

Firstly comparing $\color{blue}{n \log (n)},\ \color{green}{\int_{2}^{n}\log (x \log (x \log (x)))\ dx}$ and $\color{red}{p_{n}}$ at successive powers of $10$ with

p[x_] := Round@(x Log[x])
p3[x_] := Round@NIntegrate[Log[n Log[n Log[n]]], {n, 2, x}]
Grid[tab2 = Table[{Style[p[n], FontColor -> Blue],
Style[p3[n], FontColor -> Darker@Green],
Style[Prime[n], FontColor -> Red]}, {n, Table[10^j, {j, 1, 12}]}],
ItemSize -> All, Alignment -> Left]


and then comparing successive $\log$ terms with

p1[x_] := Round@NIntegrate[Log[n], {n, 2, x}]
p2[x_] := Round@NIntegrate[Log[n Log[n]], {n, 2, x}]
p3[x_] := Round@NIntegrate[Log[n Log[n Log[n]]], {n, 2, x}]
p4[x_] := Round@Re@NIntegrate[Log[n Log[n Log[n Log[n]]]], {n, 2, x}]
p5[x_] := Round@Re@NIntegrate[Log[n Log[n Log[n Log[n Log[n]]]]], {n, 2, x}]
Grid[tab2 = Table[{p1[n], p2[n], p3[n], p4[n], p5[n]},
{n, Table[10^j, {j, 1, 12}]}], ItemSize -> All, Alignment -> Left]


which, although p5[n] exceeds $p_{n}$ at $10^{12}$, the successive log terms added to the integral clearly approach a limit near to the asymptote of $p_{n}$. This is not as good, I think, as $\operatorname{li}^{-1}(n)$, but this is difficult to compute for large $n$.

# Improved results

It may be that

\begin{align} &\int_{2}^{n}\log (x \log (x \log (x)/e))\ dx\\ \end{align}

is better. \begin{align} && \text{left hand column}&\quad\left|1-n \dfrac{\log(n)}{p_{n}}\right|&\\ \\ && \text{middle column}&\quad\left|1-\dfrac{\int_{2}^{n}\log (x \log (x \log (x)))\ dx}{p_{n}}\right|&\\ \\ && \text{right hand column}&\quad\left|1-\dfrac{\int_{2}^{n}\log (x \log (x \log (x)/e))\ dx+\frac{9}{2}\sqrt{n}}{p_{n}}\right|&\\ \end{align}

running from $10^{1}$ to $10^{12}$.

# Minor improvements

As daniel says, it is likely there are a lot of trailing terms. The best I have been able to manage so far is

\begin{align} &\int_{2}^{n}\log (x \log (x \log (x)/e))\ dx+4 \sqrt{x}+\frac{x}{23 \log ^2(x)}+\frac{x}{23 \log (x)}+\frac{\sqrt{x}}{23 \log (x)}\\ \end{align}

but it is only really accurate up to $10^{11}$  which can be seen to tail off just after $10^{11}$.

pbs[x_] :=  Re@NIntegrate[Log[n Log[n Log[E^E, n]]], {n, 2, x}]
+ 4 Sqrt[x] + Sqrt[x]/(23 Log[x]) + x/(23 Log[x]) + x/(23 Log[x]^2)

GraphicsGrid[{
Table[ListLinePlot[Transpose@Table[{(pbs[n] - Prime[n])
/(30 Sqrt[n]/Log[n])}, {n, 2, 10^k, 10^(k - 1)/2}]], {k, 2, 4}],
Table[ListLinePlot[Transpose@Table[{(pbs[n] - Prime[n])
/(30 Sqrt[n]/Log[n])}, {n, 2, 10^k, 10^(k - 1)/2}]], {k, 5, 7}],
Table[ListLinePlot[Transpose@Table[{(pbs[n] - Prime[n])
/(30 Sqrt[n]/Log[n])}, {n, 2, 10^k, 10^(k - 1)/2}]], {k, 8, 10}],
Table[ListLinePlot[Transpose@Table[{(pbs[n] - Prime[n])
/(30 Sqrt[n]/Log[n])}, {n, 2, 10^k, 10^(k - 1)/2}]], {k, 11, 12}]}, ImageSize -> 1000]]

• I see no reason to think that each additional log in your integrals improves the accuracy of the estimate - unless the estimates are all underestimates, say, and slightly increasing the function gets closer just for size reasons (without approaching the true size), having nothing to do with the suitability of the complicated integrals to the task. Nov 25, 2014 at 5:35
• Iterating the logs indefinitely, I believe, gives $$\log(x \log(x \ldots)) = -W_{-1}(-1/x)$$ where $W_{-1}$ is one of the branches of the Lambert W function.
– user14972
Nov 30, 2014 at 8:52
• @martin: Wolframalpha. Alternatively, if $y$ is the iterated log, then $y = \log(xy)$ and $-1/x = -y e^{-y}$
– user14972
Dec 2, 2014 at 19:52
• @martin: WA does give the answer, just in a different form: see wolframalpha.com/input/…
– user14972
Dec 3, 2014 at 4:22
• I suppose I should point out that I found WA much less satisfactory than usual in this derivation.
– user14972
Dec 3, 2014 at 4:46