TITLE: Is Li(x) the best possible approximation to the prime-counting function?
QUESTION [42 upvotes]: The Prime Number Theorem says that $\lim_{n \to \infty} \frac{\pi(n)}{\mathrm{Li}(n)} = 1$, where $\mathrm{Li}(x)$ is the Logarithm integral function $\mathrm{Li}(x) = \int_2^x \frac{1}{\log(x)}dx$. It is also the case that $\lim_{n \to \infty} \frac{\pi(n)}{n/\log(n)} = 1$, as $\mathrm{Li}(x)$ and $\log(x)$ are asymptotically equivalent. However it seems that $\mathrm{Li}(n)$ is a better approximation to $\pi(n)$ (the Mathworld article states that this has been proven, I don't know in what precise sense).
There are also results for the absolute difference between $\pi(n)$ and $\mathrm{Li}(n)$; for instance $\pi(n) - \mathrm{Li}(n)$ is known to change sign infinitely often. We also know that the Riemann Hypothesis is equivalent to
$$ \pi(n) - \mathrm{Li}(n) \in O \left (\sqrt{n} \log(n) \right ).$$
In addition, Riemann showed that we have
$$\pi(n) = \mathrm{Li}(n) - \frac{1}{2} \mathrm{Li}\left ( \sqrt{n} \right ) - \sum_{\rho} \mathrm{Li}(x^\rho) + \text{lower order terms}$$ where $\rho$ runs over all the nontrivial zeroes of the Riemann zeta function.
Question: Is there a sense in which $\mathrm{Li}(n)$ is the best possible approximation to $\pi(n)$? Ideally, there would be some Bohr-Mollerup type theorem: $\mathrm{Li}(n)$ is uniquely characterized as being a good approximation to $\pi(n)$ which has some properties, such as analyticity and negative second derivative. Probably $\mathrm{Li}(n)$ isn't the best possible, for instance $\mathrm{Li}(n) - \frac{1}{2} \mathrm{Li}\left ( \sqrt{n} \right )$ might be better? Riemann also suggested
$$\sum_{n \geqslant 1} \frac{\mu(n)}{n} \mathrm{Li} \left (x^\frac{1}{n}\right ),$$ where $\mu(n)$ is the Möbius function.

REPLY [10 votes]: Whether for a finite set $\mathcal{R}$ of roots the approximation
$$
\pi(x)\approx\mathrm{Li}(x)-\frac{1}{2}\mathrm{Li}(x^{1/2})-\sum_{\rho\in\mathcal{R}}\mathrm{Li}(x^\rho)
$$
is "on average" better then $\pi(x)\approx\mathrm{Li}(x)-\frac{1}{2}\mathrm{Li}(x^{1/2})$ depends on the precise notion of average. Since $x^\rho=x^\sigma e^{i\gamma\log x}$, it might appear more natural to consider $\pi(e^t)$ instead of $\pi(x)$. Things are somewhat easier for $\Psi$, and there we get under RH
$$
\lim_{T\rightarrow\infty}\frac{1}{T}\int_2^T\left(\Psi(e^t)-\Big(e^t-\sum_{\rho\in\mathcal{R}}\frac{e^{t\rho}}{\rho}\Big)\right)^2\frac{dt}{e^{t/2}} = \sum_{\rho\not\in\mathcal{R}}\frac{1}{|\rho|^2}
$$
(insert explicit formula, throw away terms of small order, square out, interchange integral and summation). So after the proper rescaling including some roots actually does reduce the mean error.