Two Representations of the Prime Counting Function

Before answering to your question in the comment :

" Is it possible to write $\ \#\{\text{primes}\ 4n+3 \le x\}\,- \,\#\{\text{primes}\ 4n+1 \le x\}$ (form here) in terms like $\,\operatorname{R}(x^1) - \sum_{\rho}\operatorname{R}(x^{\rho})$ ? "

let's start with a sketch using von Mangoldt's derivation to obtain your equation $(1)$ that will be used for inspiration (for proofs see for example Edwards' chapter 3) :


Riemann's Explicit Formulas

The Euler product formula gives us : $$\tag{1}\boxed{\displaystyle\zeta(s)=\prod_{p\ \text{prime}}\frac 1{1-p^{-s}}}\quad\text{for}\ \ \Re(s)>1$$ so that $$\log \zeta(s)=-\sum_{p\ \text{prime}}\log(1-p^{-s})=\sum_p\sum_{k=1}^\infty \frac{p^{-ks}}k$$ minus the derivative will be : $$\tag{2}f(s):=-\frac{\zeta'(s)}{\zeta(s)}=\sum_p\sum_{k=1}^\infty \frac{\log\,p}{p^{ks}}=\sum_{n=1}^\infty \frac{\Lambda(n)}{n^s}\quad\text{for}\ \ \Re(s)>1$$ with $\Lambda$ the von Mangoldt function defined by $\ \Lambda(n):=\begin{cases} \log\, p & \text{if}\ n=p^k\ \text{and}\ k>0\\ 0 & \text{else} \end{cases}$

Let's use the definition of the second Chebyshev function : $\displaystyle \psi(x)=\sum_{n\leq x}\Lambda(n)$ and Abel's sum formula applied to $a(n):=\Lambda(n)$ and $\phi(n):=n^{-s}$ : $$\sum_{n=1}^\infty \frac{\Lambda(n)}{n^s}=s\int_1^\infty \frac {\sum_{n\leq x}\Lambda(n)}{x^{s+1}}\;dx$$ to rewrite $f(s)$ as (the lower bound became $0$ since $\phi(x)=0$ for $x<1$) : $$\tag{2.1}f(s)=s\int_0^{\infty}\frac{\psi(x)}{x^{s+1}}dx$$

But this is a Mellin transform which may be reverted to get Perron's formula (let's observe that the Dirichlet series $\displaystyle f(s)=\sum_{n=1}^\infty \frac{\Lambda(n)}{n^s}$ is absolutely convergent for $\Re(s)>1$ and suppose $c>1$) : $$\tag{3}\psi^*(x):=\frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}f(s)\frac{x^s}s\,ds=\sum_{n=1}^\infty \Lambda(n) \frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}\left(\frac xn\right)^s\frac{ds}s$$ This last integral may be evaluated using Fourier's theorem : $$\ \displaystyle\frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}\frac{y^s}s ds= \begin{cases} \ \ 0 & 0<y<1\\ 1/2 & \quad y=1\\ \ \ 1 & \quad y>1\\ \end{cases}$$ and we obtain (as wished) that : $\displaystyle \tag{4}\psi^*(x)=\sum_{n\le x}^{*}\Lambda(n)$

with $\psi^*$ the second Chebyshev function except when $x$ is an integer because in this case the last term of the sum has to be divided by $2$. This will be the meaning of the $^*$ symbols in this article : at a first order discontinuity point (i.e. a jump) the result is the mean value of the limit at the left and the right.

Now $\psi^*(x)$ may also be written as : $$\tag{5}\psi^*(x)=-\frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}\frac{\zeta'(s)}{\zeta(s)}\frac{x^s}s\,ds$$ Here the idea is simply to sum the residues of (all) the poles at the left of the vertical line of integration ($c>1$) at least if $x>1$ (for $0<x<1$ we would have to take the poles at the right and obtain $0$). These poles come from the denominator $s$, the pole of $\zeta$ at $1$ and the zeros with the correspondence : $0\mapsto -\frac{\zeta'(0)}{\zeta(0)},\ 1\mapsto x^1,\ \rho\mapsto -\frac{x^\rho}{\rho}$ for $\rho$ any zero of $\zeta\,$ (from the Weierstrass factorization of the Hadamard product) so that : $$\tag{6}\boxed{\displaystyle\psi^*(x)=x-\sum_{\rho} \frac {x^{\rho}}{\rho}-\frac{\zeta'(0)}{\zeta(0)}},\quad(x>1)$$ (in this post we won't distinguish the trivial from the non-trivial zeros $\rho$ ; for convergence the non-trivial roots should be grouped by pairs and sorted by increasing $|\Im(\rho)|$)

The Riemann prime-counting function is defined by : \begin{align} \tag{7}\Pi^*(x):&=\sum_{p^k\le x}^{*}\frac 1k=\sum_{n\le x}^{*}\frac {\Lambda(n)}{\log\,n}\\ &=\sum_{n\le x}^{*} \Lambda(n)\left(\int_n^x \frac{dt}{t\,\log^2 t}+\frac 1{\log\,x}\right)\\ &=\int_2^x\frac{\psi^*(t)\ dt}{t\,\log^2 t}+\frac{\psi^*(x)}{\log \,x}\\ &\tag{8}=\int_2^x\frac{\psi^{*'}(t)\ dt}{\log\,t}\\ \end{align} But $\ \displaystyle\operatorname{li}(x)=\int_2^x \frac{dt}{\log\,t}\,$ (Riemann's variant of the logarithmic integral) verifies $\ \displaystyle\operatorname{li}(x^r)'=\frac{r\,x^{r-1}}{\log\ x^r}=\frac{x^{r-1}}{\log\,x}$ so that from $(6)$ : $$\tag{9}\boxed{\displaystyle\Pi^*(x)=\operatorname{li}(x)-\sum_{\rho} \operatorname{li}(x^{\rho})},\quad(x>1)$$

The prime-counting function is defined by $\ \displaystyle\pi^*(x):=\sum_{p\le x}^{*}1\ $ while $\ \displaystyle\Pi^*(x):=\sum_{p^k\le x}^{*}\frac 1k$ will be : $$\tag{10}\Pi^*(x)=\sum_{k>0} \frac{\pi^{*}\bigl(x^{1/k}\bigr)}k$$ Applying the Möbius inversion formula $\ \displaystyle\pi^{*}(x):=\sum_{n=1}^{\infty} \frac{\mu(k)}k \Pi^*\bigl(x^{1/k}\bigr)\ $ to $(9)$ we get (with questionable convergence...) : $$\tag{11}\boxed{\displaystyle\pi^*(x)=R(x)-\sum_{\rho} R(x^{\rho})},\quad(x>1)$$ Where Riemann's $\,\displaystyle R(x):=\sum_{n=1}^{\infty} \frac{\mu(k)}k \operatorname{li}\bigl(x^{1/k}\bigr)\,$ may be written as a Gram series.


Dirichlet's L-functions

We will try to repeat the previous derivations but with $\zeta$ replaced by the Dirichlet L-function $$L(s,\chi)=\sum_{k=1}^\infty\frac{\chi(k)}{k^s}$$

With $\chi$ a Dirichlet character we get following Euler product : $$\tag{1'}\boxed{\displaystyle L(s,\chi)=\prod_{p\ \text{prime}}\frac 1{1-\chi(p)p^{-s}}}\quad\text{for}\ \ \Re(s)>1$$ so that ($\chi$ is multiplicative implying $\chi(p)^k=\chi(p^k)$) : $$\log L(s,\chi)=-\sum_{p\ \text{prime}}\log(1-\chi(p)p^{-s})=\sum_p\sum_{k=1}^\infty \frac{\chi(p^k)p^{-ks}}k$$ minus the derivative relatively to $s$ will be : $$\tag{2'}f(s,\chi):=-\frac{L'(s,\chi)}{L(s,\chi)}=\sum_p\sum_{k=1}^\infty \frac{\chi(p^k)\log\,p}{p^{ks}}=\sum_{n=1}^\infty \frac{\chi(n)\Lambda(n)}{n^s}\quad\text{for}\ \ \Re(s)>1$$

The Perron formula applied to $f(s,\chi)$ gives : $$\tag{3'}\psi^*(x,\chi):=\frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}f(s,\chi)\frac{x^s}s\,ds=\sum_{n=1}^\infty \chi(n)\Lambda(n) \frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}\left(\frac xn\right)^s\frac{ds}s$$ $$\tag{4'}\psi^*(x,\chi)=\sum_{n\le x}^{*}\chi(n)\Lambda(n)$$

But $\psi^*(x,\chi)$ may also be written as : $$\tag{5'}\psi^*(x,\chi)=-\frac1{2\pi i}\int_{c-i\infty}^{c+i\infty}\frac{L'(s,\chi)}{L(s,\chi)}\frac{x^s}s\,ds$$ Again we compute the sum of the residues at (all) the poles to the left of the vertical line of integration (for $c>1$). The contributions from the different poles will be : $0\mapsto -\frac{L'(0,\chi)}{L(0,\chi)},\ \rho\mapsto -\frac{x^\rho}{\rho}$ for $\rho$ any zero of $L(s,\chi)\,$ (from Weierstrass factorization) so that : $$\tag{6'}\boxed{\displaystyle\psi^*(x,\chi)=-\sum_{\rho} \frac {x^{\rho}}{\rho}-\frac{L'(0,\chi)}{L(0,\chi)}},\quad(x>1)$$ (the sum over $\rho$ combines the trivial and the non-trivial zeros and we will suppose that $\chi$ is a non principal character so that $\,L(s,\chi)\,$ is regular everywhere, for a principal character we should add a $x$ contribution from the pole at $1$)

An analogue to the Riemann prime-counting function will be : \begin{align} \tag{7'}\Pi^*(x,\chi):&=\sum_{p^k\le x}^{*}\frac {\chi(p^k)}k=\sum_{n\le x}^{*}\frac {\chi(n)\Lambda(n)}{\log\,n}\\ &=\sum_{n\le x}^{*} \chi(n)\Lambda(n)\left(\int_n^x \frac{dt}{t\,\log^2 t}+\frac 1{\log\,x}\right)\\ &=\int_2^x\frac{\psi^*(t,\chi)\ dt}{t\,\log^2 t}+\frac{\psi^*(x,\chi)}{\log \,x}\\ &\tag{8'}=\int_2^x\frac{\psi^{*'}(t,\chi)\ dt}{\log\,t}\\ \end{align} From $\ \displaystyle\operatorname{li}(x^r)'=\frac{x^{r-1}}{\log\,x}$ and $(6')$ we get : $$\tag{9'}\boxed{\displaystyle\Pi^*(x,\chi)=-\sum_{\rho} \operatorname{li}(x^{\rho})},\quad(x>1)$$ (for $\chi$ a principal character there is an additional $\,\operatorname{li}(x)$ term)

The $\chi$-prime-counting function is $\ \displaystyle\pi^*(x,\chi):=\sum_{p\le x}^{*}\chi(p) $ while $\ \displaystyle\Pi^*(x,\chi):=\sum_{p^k\le x}^{*}\frac {\chi(p^k)}k$ so that : $$\tag{10'}\Pi^*(x,\chi)=\sum_{k>0} \frac{\pi^{*}\bigl(x^{1/k},\chi^k\bigr)}k,\quad(x>1)$$

Broken analogy...

The problem here is that we have $\,\pi^{*}\bigl(x^{1/k},\chi^k\bigr)$ in the sum and not $\,\pi^{*}\bigl(x^{1/k},\chi\bigr)$.
For principal characters (when $\,\chi(p)=0$ or $1$ so that $\,\chi^k(p)=\chi(p)\,$ for $k$ positive) we may apply the Möbius inversion formula to $(9')$ and get : $$\tag{11'}\displaystyle\pi^*(x,\chi)=[R(x)]-\sum_{\rho} R(x^{\rho})$$ (since $\chi$ is a principal character we must add the $R(x)$ term from the pole at $1$)

but this doesn't work in general and the equality becomes questionable after the first prime $p$ such that $\,\chi^k(p)\not =\chi(p)\,$ as we will see by considering your specific question.

We want $\chi$ to be the Dirichlet character modulo $4$ ($\chi_2$ in the link) defined by $\ \displaystyle\chi(0)=0,\ \chi(1)=1,\ \chi(2)=0,\ \chi(3)=-1\ $ and get : $$\tag{12'}L(s,\chi)=\sum_{n=0}^\infty\frac {(-1)^n}{(2n+1)^s}=\beta(s)$$ with $\beta$ the Dirichlet beta function we could hope that : $$\pi^*(x,\chi)=\displaystyle\pi_{4,1}^*(x)-\pi_{4,3}^*(x)\approx -\sum_{\rho} R(x^{\rho})$$ with $\pi_{q,a}(x)=\#\{p:p\ \text{is prime and}\ \,p\le x\,\ \text{and}\ \,p\equiv a\pmod q\}$

But, from $(10')$ and $(9')$, we have in fact : \begin{align} \Pi^*(x,\chi)&=\sum_{k>0} \frac{\pi_{4,1}^{*}\bigl(x^{1/k}\bigr)+(-1)^k\,\pi_{4,3}^{*}\bigl(x^{1/k}\bigr)}k=-\sum_{\rho} \operatorname{li}(x^{\rho})\\ &=\sum_{k>0} \frac{\pi_{4,1}^{*}\bigl(x^{1/k}\bigr)-\,\pi_{4,3}^{*}\bigl(x^{1/k}\bigr)}k+2\sum_{j>0} \frac{\pi_{4,3}^{*}\left(\sqrt{x}^{1/j}\right)}{2j}\\ \end{align} so that the Möbius transformation will return the exact (with $\rho$ any zero of $\beta$) : $$\tag{13'}\boxed{\displaystyle\pi_{4,1}^{*}(x)-\pi_{4,3}^{*}(x)+\pi_{4,3}^{*}\left(\sqrt{x}\right)=-\sum_{\rho} R(x^{\rho})}$$

To show the effect of the $\,\pi_{4,3}^{*}\left(\sqrt{x}\right)\,$ term let's exhibit an approximation of the expression at the right (taking the $40$ first terms of the sum $R$ and the $300$ first non-trivial zeros of the Dirichlet-beta function) that we compare to the exact (dark) result for $\,\pi^*(x,\chi)=\displaystyle\pi_{4,1}^*(x)-\pi_{4,3}^*(x)\,$ in the interval $\,[5,80]$ :

Interval 5-80

The initial behavior seems right : $-1$ at $3$ followed by $+1$ at $5$ and $-1$ at $7$ but just after that there is a first 'irregularity' at $9=3^2$ because $\chi(3^2)=1$ while $\chi(3)=-1$. After that the behavior is correct (shifted $+1$ of course) until another irregularity at $49=7^2$ again because $\chi(7^2)=1$. The next one will be at $121=11^2$ and at all the following squares of primes of gender $4n+3$...


ADDITION: Draks telescoping

The situation was blocked at this point until draks, using a suggestion of Greg Martin, proposed in february his powerful telescoping method to obtain (the $\rho_\zeta$ and $\rho_\beta$ are respectively all the zeros of the $\zeta$ and $\beta$ function) : $$\tag{14'}\pi_{4,3}(x):=\sum_{k=0}^\infty\;2^{-k-1}\left( R\left(x^{1/2^{k}}\right)-\sum_{\rho_\zeta} R\left(x^{\rho_\zeta/2^k}\right) +\sum_{\rho_\beta} R\left(x^{\rho_\beta/2^k}\right) \right)$$

We may obtain this result too (with a minor correction) by rewriting $(11)$ as (for $x>2$) : $$\pi^*(x)=1+\pi_{4,1}^{*}(x)+\pi_{4,3}^{*}(x)=R(x)-\sum_{\rho_\zeta} R(x^{\rho_\zeta})$$ ($1$ was added since all primes except $2$ are equal to $1$ or $3\bmod{4}$) and using $(13')$ : $$\pi_{4,1}^{*}(x)-\pi_{4,3}^{*}(x)+\pi_{4,3}^{*}\left(\sqrt{x}\right)=-\sum_{\rho_\beta} R(x^{\rho_\beta})$$ Subtracting these equations gives : $$2\pi_{4,3}^{*}(x)-\pi_{4,3}^{*}\left(\sqrt{x}\right)=R(x)-1-\sum_{\rho_\zeta} R(x^{\rho_\zeta})+\sum_{\rho_\beta} R(x^{\rho_\beta})$$ while draks' telescoping sum $\ \displaystyle\frac 12\sum_{k=0}^\infty \frac{f\left(x^{1/2^{k}}\right)}{2^k}$ is : $$\sum_{k=0}^\infty \frac {2\,\pi_{4,3}^{*}(x^{1/2^{k}})-\pi_{4,3}^{*}\bigl(x^{1/2^{k+1}}\bigr)}{2^{k+1}}=\sum_{k=0}^\infty \frac {R\left(x^{1/2^{k}}\right)-1-\sum_{\rho_\zeta} R\left(x^{\rho_\zeta/2^k}\right)+\sum_{\rho_\beta} R\left(x^{\rho_\beta/2^k}\right)}{2^{k+1}}$$ producing draks' formula : $$\tag{15'}\boxed{\displaystyle\pi_{4,3}^{*}(x)=\sum_{k=0}^\infty \frac {R\left(x^{1/2^{k}}\right)-\sum_{\rho_\zeta} R\left(x^{\rho_\zeta/2^k}\right)+\sum_{\rho_\beta} R\left(x^{\rho_\beta/2^k}\right)}{2^{k+1}}-1}$$ A similar formula may be written for $\pi_{4,1}$ and this answers positively the initial question !

Let's finish with a plot of $\pi_{4,3}^{*}(x)$ from $4$ to $100$ (more details here with the pari/gp scripts used)

plot of pi_4,3


Let's start with the nice paper 'Prime Number Races' of Granville and Martin from your comments. It contains the sentence :

"The precise formula he (Riemann) proposed is a bit too technical for this article, but we can get a good sense of it from the following approximation when x is large. This formula, while widely believed to be correct, has not yet been proved."

$$ \tag{1}\boxed{\displaystyle\frac{\int\limits_2^x{\frac{dt}{\ln t}}-\pi(x)}{\sqrt x/\ln x} \approx 1 + 2\sum_{\gamma} \ \ \frac{\sin(\gamma\ln x)}{\gamma}} $$

I can only conjecture that the formula referenced in their last sentence is your formula $(1)$ (I don't know a proof of convergence of this formula either) derived from Riemann's explicit formula (proved by von Mangoldt) and not the approximate formula I reproduce above equivalent to your $(2)$ . Note that they add that this approximation is valid 'when $x$ is large'.

Let's add that this approximation doesn't include the trivial zeros from your other thread.
Concerning the $\displaystyle \frac{\sin(\gamma\ln x)}{\gamma}$ term it is a good approximation of Riesel's approximation $(2.30)$ from his fine book 'Prime Numbers and Computer Methods for Factorization' : $$\tag{2}\frac{\cos(\gamma\ln x-\arg \rho)}{|\rho|},\quad\text{with}\ \ \rho=\frac 12+i\gamma$$ since $\ \gamma\gg 1 $ we have indeed $\ |\rho|\approx \gamma\ $ and $\ \arg\,\rho\approx \frac{\pi}2$
(note that $\gamma > 14.13\ $ so that $\ 1<\frac {|\rho|}{\gamma}<1.00063$)

Riesel's method is to approximate the oscillating term (see the next page from Riesel's book) : $$\tag{3}\operatorname{R}(x^{\rho}) = \sum_{n=1}^{\infty} \frac{ \mu (n)}{n}\operatorname{li}(x^{\rho/n})$$ with the first term : $$\tag{4}\operatorname{R}(x^{\rho}) \approx\left[\operatorname{li}(x^{\rho})=\operatorname{li}(e^{\rho\;\ln x})=\operatorname{Ei}(\rho\;\ln x)\right]$$ and to use the asymptotic expansion for $\operatorname{Ei}$ : $$\tag{5}\operatorname{Ei}(z)\sim \frac{e^z}{z}\left(1+\frac {1!}z+\frac{2!}{z^2}+\cdots\right)$$ to get : $$\operatorname{Ei}\left(\left(\frac 12+i\gamma\right)\;\ln x\right)\approx \frac{x^{1/2+i\gamma}}{(1/2+i\gamma)\;\ln x}$$ so that combining the two 'mirror' zeros : $$\operatorname{Ei}\left(\left(\frac 12+i\gamma\right)+\;\ln x\right)+\operatorname{Ei}\left(\left(\frac 12-i\gamma\right)+\;\ln x\right)\approx \frac{\sqrt{x}}{\ln x}\left(\frac{e^{i\gamma\ln x}}{1/2+i\gamma}+\frac{e^{-i\gamma\ln x}}{1/2-i\gamma}\right)$$ $$\approx\frac{\sqrt{x}}{\ln x}\frac{e^{i\gamma\ln x-i\arg{\rho}}+e^{-i\gamma\ln x+i\arg{\rho}}}{|\rho|}\quad\text{since}\ \ \rho=\frac 12+i\gamma$$ we get Riesel's approximation : $$\tag{6}\operatorname{R}(x^{\rho})+\operatorname{R}(x^{\overline{\rho}})\approx\frac{2\;\sqrt{x}\;\cos(\gamma\ln x-\arg{\rho})}{|\rho|\;\ln x}$$ while $\operatorname{R}(x)$ was approximated by (using $(3), (4), (5)$) : $$\tag{7}\operatorname{R}(x)\approx \operatorname{li}(x)-\frac 12\operatorname{li}\bigl(x^{1/2}\bigr)\quad \text{with}\ \operatorname{li}\bigl(x^{1/2}\bigr)\approx \frac{2\sqrt{x}}{\ln x}$$ this allows too to get better approximations if wished ($\operatorname{R}(x)\approx \operatorname{li}(x)-\frac 12\operatorname{li}\bigl(x^{1/2}\bigr)-\frac 13\operatorname{li}\bigl(x^{1/3}\bigr) $ for example, adding the trivial zeros contribution and so on...)

Now to answer your questions :

  1. We have to suppose the R.H. to be able to write $\rho=\frac 12+i\gamma\ $ for any root $\rho$ so that the simplifications proposed apply (in practice we don't need R.H. since $(2)$ requires precomputed zeros and since all the zeros known satisfy the R.H. ... to this date...)
  2. The implication from $(1)\to (2)$ was provided without using the Gram series

Hoping this clarified things,


You probably know that $$ \Pi^*(x;q,a) = \sum^*_{\substack{n\le x \\ n\equiv a\pmod q}} \frac{\Lambda(n)}{\log n} = \frac1{\phi(q)} \sum_{\chi\pmod q} \overline{\chi(a)}\Pi^*(x,\chi). $$ I find that the easiest way to convert from counting prime powers (with weights) to counting only primes is to use the fact that \begin{align*} \Pi^*(x;q,a) &= \sum^*_{\substack{p\le x \\ p\equiv a\pmod q}} 1 + \sum^*_{\substack{p^2\le x \\ p^2\equiv a\pmod q}} \tfrac12 + \sum^*_{\substack{p^3\le x \\ p^3\equiv a\pmod q}} \tfrac13 + \cdots \\ &= \pi^*(x;q,a) + \tfrac12 \sum_{\substack{b\pmod q \\ b^2\equiv a\pmod q}} \pi^*(x^{1/2};q,b) + \tfrac13 \sum_{\substack{c\pmod q \\ c^3\equiv a\pmod q}} \pi^*(x^{1/3};q,c) + \cdots \end{align*} and solving for $\pi^*(x;q,a)$ in terms of all $\Pi^*$ functions (tedious but possible).