Limit involving prime counting function

limitsnumber theoryreal-analysis

Recently I came across this problem:
$$\lim_{n\rightarrow \infty} \frac{n}{\pi(n)} -H_{n} $$ Where $\pi(n)$ is prime counting function which counts number of primes $\le n$. & $$H_{n}=\sum_{k=1}^{n} \frac{1}{k}$$

I would attempt the problem as follows.
By using prime number theorem which states:
$$\lim_{n \rightarrow \infty} \frac{\pi(n)}{\frac{n}{\ln(n)}}=1 $$
So will subtitute $\pi(n)$ with $\frac{n}{\ln(n)}$ as both are asymptotically equal , in limit will get:
$$\lim_{n\rightarrow \infty} \frac{n}{\pi(n)} -H_{n}= \lim_{n\rightarrow \infty} \frac{n}{\frac{n}{\ln(n)}} -H_{n}= \lim_{n\rightarrow \infty} \ln(n) -H_{n}=-\gamma$$
Where $\gamma$ is euler macheroni constant.
However, when I input this limit in wolfram alpha I get:
$$\lim_{n\rightarrow \infty} \frac{n}{\pi(n)} -H_{n}=-1-\gamma$$
https://www.wolframalpha.com/input/?i=limit+calculator&assumption=%7B%22F%22%2C+%22Limit%22%2C+%22limitfunction%22%7D+-%3E%22x%2Fpi%28x%29-H_x%22&assumption=%7B%22F%22%2C+%22Limit%22%2C+%22limit%22%7D+-%3E%22infinity%22

So how is this the case? Is there an asymptotic equation/series expansion of the prime counting function that can help prove that this is the case?

Best Answer

The first part of the Non-asymptotic bounds on the prime-counting function section of Wikipedia's "Prime number theorem article" states

The prime number theorem is an asymptotic result. It gives an ineffective bound on $\pi(x)$ as a direct consequence of the definition of the limit: for all $\varepsilon \gt 0$, there is an $S$ such that for all $x \gt S$, $$(1 - \varepsilon )\frac{x}{\log x} \lt \pi(x) \lt (1 + \varepsilon)\frac{x}{\log x}.$$

Thus, when dividing $\pi(n)$ into $n$ using just the result of the prime number theorem, we can't be sure of what the asymptotic result will specifically be. However, note the last part of the article's section states

The proof by de la Vallée Poussin implies the following. For every $\varepsilon \gt 0$, there is an $S$ such that for all $x \gt S$, $$\frac{x}{\log x - (1 - \varepsilon)} \lt \pi(x) \lt {\frac {x}{\log x - (1 + \varepsilon)}}.$$

Choose any $\delta \gt 0$ and set $\varepsilon = \frac{\delta}{2}$. The left side inequality gives

$$\begin{equation}\begin{aligned} \frac{n}{\ln(n) - (1 - \varepsilon)} & \lt \pi(n) \\ \frac{\ln(n) - 1 + \varepsilon}{n} & \gt \frac{1}{\pi(n)} \\ \ln(n) - 1 + \varepsilon & \gt \frac{n}{\pi(n)} \\ \varepsilon & \gt \frac{n}{\pi(n)} - \ln(n) + 1 \end{aligned}\end{equation}\tag{1}\label{eq1A}$$

Similarly, the right side inequality gives

$$\begin{equation}\begin{aligned} \pi(n) & \lt \frac{n}{\ln(n) - (1 + \varepsilon)} \\ \frac{1}{\pi(n)} & \gt \frac{\ln(n) - 1 - \varepsilon}{n} \\ \frac{n}{\pi(n)} & \gt \ln(n) - 1 - \varepsilon \\ -\varepsilon & \lt \frac{n}{\pi(n)} - \ln(n) + 1 \end{aligned}\end{equation}\tag{2}\label{eq2A}$$

Putting \eqref{eq1A} and \eqref{eq2A} together gives

$$\left|\frac{n}{\pi(n)} - \ln(n) + 1 \right| \lt \varepsilon \tag{3}\label{eq3A}$$

Next, as given in the Rate of divergence section of Wikipedia's "Harmonic series" article,

$$\lim_{n \to \infty}(H_n - \ln(n)) = \gamma \implies \lim_{n \to \infty}(-H_n + \ln(n)) = -\gamma \tag{4}\label{eq4A}$$

Thus, there's an $S_1$ where for all $n \gt S_1$ gives that

$$\left| -H_n + \ln(n) + \gamma \right| \lt \varepsilon \tag{5}\label{eq5A}$$

Let $S_2 = \max(S, S_1)$. Thus, for all $n \gt S_2$, using \eqref{eq3A} and \eqref{eq5A}, plus the triangle inequality, we get

$$\begin{equation}\begin{aligned} \left|\left(\frac{n}{\pi(n)} - \ln(n) + 1 \right) + (-H_n + \ln(n) + \gamma)\right| & \lt \varepsilon + \varepsilon \\ \left|\frac{n}{\pi(n)} - H_n + (1 + \gamma) \right| & \lt \delta \end{aligned}\end{equation}\tag{6}\label{eq6A}$$

As stated earlier, since for any $\delta \gt 0$ there exists an $S_2$ such that for all $n \gt S_2$ means that \eqref{eq6A} is true, this gives by the basic definition of a limit that

$$\lim_{n \to \infty}\left(\frac{n}{\pi(n)} - H_n + (1 + \gamma)\right) = 0 \implies \lim_{n \to \infty}\left(\frac{n}{\pi(n)} - H_n\right) = -1 - \gamma \tag{7}\label{eq7A}$$

This matches what you stated WolframAlpha returns.