Riemann Zeta function - number of zeros
I want to write a program that calculates the number of zeros (It is not necessary to identify them, just the number of them) between 0 and x for the Riemann Zeta function, being x the imaginary part of z: 1/2 + ix
Is there an algorithm out there for doing what I need?
I modelled the Riemann-siegel function because I saw that I need it for doing what I want, but I don't know how to go on.
Sorry for my poor english :/
You may appreciate the following '$\zeta$ zeros counting function' if $t$ is the imaginary part : $$f(t) = \frac{1}{\pi} \Im\left(\ln(\Gamma\left(\frac 14 + \frac{i\,t}2\right)\right) - \frac{t}{2\pi}\ln(\pi) + \frac{1}{\pi} \Im\left(\ln\left(\zeta\left(\frac 12 + i\,t\right)\right)\right) + 1$$ Explication : if we multiply this by $\pi$ we note that the first imaginary term combined to the next term returns the actual argument of $\zeta$ (this is the well known Riemann–Siegel theta function) that grows with high regularity while the imaginary term at the right gives the argument of $\zeta$ modulo $2\pi$ which will change sign for every multiple of $\pi$ (that is at every zero of $\zeta$ !).
More about the way this formula was obtained here.
Illustration using the pari/gp code at the end (zoom possible) :
The first step is between $14.1$ and $14.2$, the second between $21$ and $21.1$ and so on so that we are really counting the zeros of $\zeta$...
The picture is not always so nice and, from time to time (starting after $t=415$ I think), there will be a non-propagating error of $\,\pm 2\,$ when $\,\displaystyle\frac 1{\pi}\rm{Arg}\;\zeta(1/2+it)\;$ crosses the upper bound $+1$ or lower bound $-1$ (so that this appears rather when two consecutive zeros are distant i.e. for large loops as displayed in the other answer).
This formula was in this MO thread with further references to Guinand's article : 'A summation formula in the theory of prime numbers'.
pari/gp code used for the picture :
f(t)=imag(lngamma(1/4+I*t/2))/Pi-t/(2*Pi)*log(Pi)+imag(log(zeta(1/2+I*t)))/Pi+1
Check out Andrew Odlyzko's work.His main page is here:
http://www.dtc.umn.edu/~odlyzko/doc/zeta.html
Here is a table of zeros:
http://www.dtc.umn.edu/~odlyzko/zeta_tables/
Check out this paper for algorithms:
http://www.dtc.umn.edu/~odlyzko/doc/arch/zeta.fn.supercomp.pdf
And for large zeros, this one:
http://www.dtc.umn.edu/~odlyzko/doc/zeta.10to22.pdf
Assuming you mean the number n of roots $\rho$ whose imaginary parts lie between 0 and T, Riemann conjectured and von Mangoldt verified that the number is
$$n \approx\frac{T}{2\pi}\log\frac{T}{2\pi} -\frac{T}{2\pi} $$ with relative error of $O(\log T).$
There are no doubt better estimates but this is a rule-of-thumb.
In the spirit of Raymond Manzoni's answer in combination with the Franca-LeClair asymptotic of the zeta zeros here, one can arrive at the following almost identical zeta zero counting function:
$$f(t)=\left\lfloor \frac{t \log \left(\frac{t}{2 e \pi }\right)}{2 \pi }+\frac{7}{8}\right\rfloor +\frac{1}{2} \left(-1+\text{sgn}\left(\Im\left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)\right)$$
where only the singularities are different.
The plot looks like this:
Mathematica 8 code for the plot:
(*Mathematica 8*)
Plot[(Sign[Im[Zeta[1/2 + I*t]]] - 1)/2 +
Floor[t/(2*Pi)*Log[t/(2*Pi*Exp[1])] + 7/8], {t, 0, 60},
Filling -> 0]
Just like Raymonds version also this counting function can be made symmetrical:
Plot[Re[(Sign[Im[Zeta[1/2 + I*t]]] - 1)/2 +
Floor[t/(2*Pi)*Log[t/(2*Pi*Exp[1])] + Sign[t]*7/8 +
If[t < 0, 2, 0]]], {t, -60, 60}, Filling -> 0]
Update 13.5.2017:
$f(t)=\frac{\Im\left(\text{log$\Gamma $}\left(\frac{1}{4}+\frac{i t}{2}\right)\right)}{\pi }+\frac{\Im\left(\log \left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)}{\pi }-\frac{t \log (\pi )}{2 \pi }+1$
$f(t)=\left\lfloor \frac{\Im\left(\text{log$\Gamma $}\left(\frac{1}{4}+\frac{i t}{2}\right)\right)}{\pi }-\frac{t \log (\pi )}{2 \pi }+1\right\rfloor +\frac{1}{2} \left(-1+\text{sgn}\left(\Im\left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)\right)+1$
$f(t)=\frac{\vartheta (t)+\Im\left(\log \left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)}{\pi }+1$
$f(t)=\left\lfloor \frac{\vartheta (t)}{\pi }+1\right\rfloor +\frac{1}{2} \left(-1+\text{sgn}\left(\Im\left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)\right)+1$
$f(t)=\left\lfloor \frac{t \log \left(\frac{t}{2 \pi \exp (1)}\right)}{2 \pi }+\frac{7}{8}\right\rfloor +\frac{1}{2} \left(-1+\text{sgn}\left(\Im\left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)\right)+1$
$f(t)=\frac{t \log \left(\frac{t}{2 \pi \exp (1)}\right)}{2 \pi }+\frac{\Im\left(\log \left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)}{\pi }+\frac{7}{8}$
Update 25.5.2017:
In the formulas above:
$\Im\left(\log \left(\zeta \left(i t+\frac{1}{2}\right)\right)\right)=\arg \left(\zeta \left(i t+\frac{1}{2}\right)\right)$
I am not sure all of the formulas are correct but they agree for the first few values I have computed.