Riemann Prime Counting Function:

$$f(x)=\operatorname{li}(x)-\sum_\rho\operatorname{li}(x^\rho)-\ln 2+\int_x^\infty \frac{\mathrm dt}{t(t^2-1)\ln t}$$

The second correction/paring terms:


I tried to use Mathematica function LogIntegral to plot this second correction/paring terms, for example, when I only include the first 2 non-trivial zeros, and plot with range x from 1 to 5:


Plot[Sum[LogIntegral[x^ZetaZero[k]] + LogIntegral[x^(1 - ZetaZero[k])],
     {k, 1, 2}], {x, 1, 5}]

However, I got very large value instead of small correction:

bad plot

I can also use simplified equation provided by reference 1:

$$\operatorname{li}(x^\rho)=\operatorname{li}(e^{\rho \log x})\sim \frac{e^{\rho \log x}}{\rho \log x}$$


Plot[Sum[Exp[ZetaZero[k]*Log[x]]/(ZetaZero[k]*Log[x]), {k, 1, 2}] +
     Sum[Exp[(1 -ZetaZero[k])*Log[x]]/((1 - ZetaZero[k])*Log[x]),
         {k, 1, 2}], {x, 1, 5}]

Then I got the correct result:

good plot

Anyone knows what is wrong for the LogIntegral one?

Thank you!

1: H. Riesel and G Gohl, "Some Calculations Related to Riemann's Prime Number Formula," Mathematics of Computation, 24(112), 1970 pp. 969–983.

  • $\begingroup$ RiemannR is built in so you could always use that. One reason your correction is bad is because $\mathrm{Li}(x)$ is not the same as $\mathrm{li}(x)$. You should code $\mathrm{li}(x)$ as LogIntegral[x], but $\mathrm{Li}(x)$ as LogIntegral[x]-LogIntegral[2] , however there is still something else wrong as the correction is still too large. $\endgroup$
    – flinty
    Commented Jul 26, 2020 at 12:55
  • $\begingroup$ Thanks. yeah, by adding - LogIntegral[2] doesn't give the correct answer. It just shift the trend a little bit down. RiemannR only gives the mobius function of first major prime counting term. It does not contain the correction terms. therefore if you plot RiemannR, only a smooth counting curve could be generated, instead of a "zigzag" curve following the real prime number distribution. $\endgroup$
    – jasontower
    Commented Jul 26, 2020 at 20:58

1 Answer 1


Please see the explanation in this question.

         ExpIntegralEi[ZetaZero[k]*Log[x]] + 
         ExpIntegralEi[(1 - ZetaZero[k])*Log[x]],
     {k, 1, 2}], {x, 1, 5},
Frame -> True]

The corresponding plot matches the one you showed from the "simplified equation".

Riemann plot

  • $\begingroup$ Thank you for the explanation! $\endgroup$
    – jasontower
    Commented Jul 28, 2020 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.