Approximation to the prime counting function

The best analytic built-in approximation is the Riemann Prime Counting Function; it is implemented in Mathematica as RiemannR. So far we know exact values of $\pi$ prime counting function for n < 10^25, however in Mathematica its counterpart PrimePi[n] can be computed exactly to much lower values i.e. up to 25 10^13 -1, see e.g. What is so special about Prime? for more details.

RiemannR[10^1000] // N
4.344832576401197453*10^996

See e.g. Prime-counting function, it claims that the best estimator is $ \operatorname{R}(x) - \frac1{\ln x} + \frac1\pi \arctan \frac\pi{\ln x}$

let's define it as APi:

APi[x_] := RiemannR[x] - 1/Log[x] + 1/Pi ArcTan[ Pi/Log[x]]

it provides the same approximation as RiemannR, at least IntegerPart does, in fact

Grid[ Table[ IntegerPart @ { 5 10^k, RiemannR[5 10^k] - PrimePi[5 10^k], 
                             APi[5 10^k] - PrimePi[5 10^k]}, {k, 3, 13}],
      Frame -> All, Alignment -> Left]

enter image description here

We can realize how good RiemanR is plotting related errors of interesting approximations where we know exact values of the prime counting function (see e.g. "Mathematica in Action" by Stan Wagon):

Plot[{ LogIntegral[x] - PrimePi[x], RiemannR[x] - PrimePi[x], 
        x/(Log[x] - 1) - PrimePi[x]},  {x, 2, 3 10^5}, MaxRecursion -> 3, 
      Frame -> True, PlotStyle -> {{Thick, Red}, {Thick, Darker @ Green}, 
                                  {Thick, Darker @ Cyan}}, 
      PlotLegends -> Placed["Expressions", {Left, Bottom}], 
      ImageSize -> 800, AxesStyle -> Thick]

enter image description here

Plot[{ LogIntegral[x] - PrimePi[x], RiemannR[x] - PrimePi[x], 
       x/(Log[x] - 1) - PrimePi[x]}, {x, 10^6, 10^7}, MaxRecursion -> 3, 
       Frame -> True, PlotStyle -> {{Thick, Red}, {Thick, Darker @ Green}, 
                                    {Thick, Darker @ Cyan}}, 
       PlotLegends -> Placed["Expressions", {Left, Bottom}], 
       Axes -> {True, False}, AxesStyle -> Thick, ImageSize -> 800]

enter image description here


RiemannR seems to be a better choice than LogIntegral based on this plot:

Plot[{PrimePi[n], LogIntegral[n], RiemannR[n]}, {n, 1, 5000}, PlotStyle -> {Black, Blue, Red}]

primePiPlot

RiemannR[1.*10^1000]
4.344832576401197453*10^996