# What is the error term in Mertens' first theorem for arithmetic progressions?

I am asking this question here, since my comment on this post on Math Overflow got no responses.

I need an explicit (computable) bound on the $$O(1)$$ term in the following asymptotic formula: $$\sum_{\substack{p\le x \\p\equiv a\;(\text{mod} \; q)}}\frac{\log(p)}{p}=\frac{\log(x)}{\phi(q)}+O(1),$$ where $$\gcd(a,q)=1$$. Specifically for the cases $$q=4$$ and $$a\in\{1,2\}$$. However, using the prime number theorem for arithmetic progressions, I have not been able to get the error better than $$O(\log(\log(n)))$$. This is what I have done so far:

let $$\pi(x;q,a)$$ denote the number of primes less than or equal to $$x$$ that are congruent to $$a$$ modulo $$q$$. By Abel's summation formula, we have $$$$\sum_{\substack{p\le x \\ p\equiv a (\text{mod}\; q)}}\frac{\log(p)}{p}=\frac{\log(x)}{x}\pi(x;q,a)+\int_{2}^{x}\frac{\log(t)-1}{t^2}\pi(t;q,a)dt \hspace{8mm}(1)$$$$ Let $$\theta(x;q,a):=\sum_{\substack{p\le x \\ p\equiv a (\text{mod}\; q)}}\log(p)$$. Then \begin{align*} \pi(x;q,a)=\frac{\theta(x;q,a)}{\log(x)}+\int_{2}^{x}\frac{\theta(t;q,a)}{t\log^2(t)}dt \end{align*} by the result on page 142 here. Therefore: \begin{align*} \frac{\log(x)}{x}\pi(x;q,a)=\frac{\theta(x;q,a)}{x}+\frac{\log(x)}{x}\int_{2}^{x}\frac{\theta(t;q,a)}{t\log^2(t)}dt. \end{align*} The term $$\tfrac{\theta(x;q,a)}{x}=\frac{1}{\phi(q)}+o(1)$$, while $$\frac{\log(x)}{x}\int_{2}^{x}\frac{\theta(t;q,a)}{t\log^2(t)}dt=\frac{\log(x)}{x}O(\frac{x}{\log^2(x)})=O(\frac{1}{\log(x)})=o(1).$$ Thus, it remains to consider the integral in $$(1)$$. We have \begin{align*} \int_{2}^{x}\frac{\log(t)-1}{t^2}&\pi(t;q,a)dt=\int_{2}^{x}\frac{\log(t)}{t^2}\pi(t;q,a)dt-\int_{2}^{x}\frac{\pi(t;q,a)}{t^2}dt. \hspace{6mm} (2) \end{align*} Let $$\varepsilon$$ be defined by $$\tfrac{\log(t)\pi(t;q,a)}{t}=\frac{1}{\phi(q)}+\varepsilon(t)$$. Then the first integral in the right hand side of $$(2)$$ can be written as \begin{align*} \int_{2}^{x}\frac{\log(t)\pi(t;q,a)}{t^2}dt=&\int_{2}^{x}\frac{1}{t}\cdot \frac{\log(t)\pi(t;q,a)}{t}dt=\int_{2}^{x}\frac{1}{t}\cdot (\frac{1}{\phi(q)}+\varepsilon(t))dt\1mm] =&\frac{\log(x/2)}{\phi(q)}+\int_{2}^x\frac{\varepsilon(t)}{t}dt. \end{align*} The second integral in the right hand side of $$(2)$$ can be written as \begin{align*} \int_{2}^{x}\frac{\pi(t;q,a)}{t^2}dt=&\int_{2}^{x}\frac{1}{t\log(t)}\cdot \frac{\log(t)\pi(t;q,a)}{t}dt\\ =& \int_{2}^{x}\frac{1}{t\log(t)}\cdot (\frac{1}{\phi(q)}+\varepsilon(t))dt\\ =&\frac{\log(\log(x))-\log(\log(2))}{\phi(q)}+\int_{2}^x\frac{\varepsilon(t)}{t\log(t)}dt. \end{align*} Thus, we have: \begin{align*} \sum_{\substack{p\le x \\ p\equiv q (\text{mod}\; q)}}\frac{\log(p)}{p}=\frac{1}{\phi(q)}+\frac{\log(x/2)}{\phi(q)}-\frac{\log(\tfrac{\log(x)}{\log(2)})}{\phi(q)}+\int_{2}^x\frac{\varepsilon(t)}{t}dt-\int_{2}^x\frac{\varepsilon(t)}{t\log(t)}dt+o(1) \end{align*} Thanks to the result on page 6 here, if $$1\le q\le 1200$$ is an integer, and $$a$$ is coprime to $$q$$, then $$\frac{x}{\phi(q)\log(x)}<\pi(x;q,a)<\frac{x}{\phi(q)\log(x)}(1+\frac{5}{3\log(x)})$$ for all $$x\ge 50q^2$$. Consequently, $$0<\varepsilon(x)<\frac{5}{2\phi(q)\log(x)}$$ for $$x \ge 50q^2$$. For our purposes we have $$q=4$$, so the bound holds for $$x\ge 800$$. Assuming $$x\ge 800$$, we then have \begin{align*} \int_{2}^x\frac{\varepsilon(t)}{t}dt=\int_{2}^{800}\frac{\varepsilon(t)}{t}dt+\int_{800}^x\frac{\varepsilon(t)}{t}dt, \end{align*} where \begin{align*} 0<\int_{800}^x\frac{\varepsilon(t)}{t}dt<\frac{5}{2\phi(q)}\int_{800}^x\frac{1}{t\log(t)}dt=\tfrac{5}{2\phi(q)}\log(\log(x))-\tfrac{5}{2\phi(q)}\log(\log(800)). \end{align*} Moreover, \begin{align*} \int_{2}^x\frac{\varepsilon(t)}{t\log(t)}dt=&\int_{2}^{800}\frac{\varepsilon(t)}{t\log(t)}dt+\int_{800}^x\frac{\varepsilon(t)}{t\log(t)}dt, \end{align*} where \begin{align*} 0<\int_{800}^x\frac{\varepsilon(t)dt}{t\log(t)}<\frac{5}{2\phi(q)}\int_{800}^x\frac{dt}{t\log^2(t)}=\frac{5}{1600\phi(q)\log(800)}-\frac{5}{2\phi(q)\log(x)}. \end{align*} As a conclusion, I get that \begin{align*} \sum_{\substack{p\le x \\ p\equiv a (\text{mod}\; q)}}\frac{\log(p)}{p}=const.-\frac{\log(\frac{\log(x)}{\log(2)})}{\phi(q)}+\frac{\log(x)}{\phi(q)}+\int_{800}^x\frac{\varepsilon(t)}{t}dt-\int_{800}^x\frac{\varepsilon(t)}{t\log(t)}dt+o(1). \end{align*} However, for the error term(the stuff between $$conts.$$ and $$o(1)$$, call it $$r(x)$$), the best I get is \begin{align*}\frac{5}{2\phi(q)\log(x)}-\frac{5}{1600\phi(q)\log(800)}-\frac{\log(\frac{\log(x)}{\log(2)})}{\phi(q)} which I cannot see is better than $$O(\log(\log(x)))$$. It have tried using the Siegel–Walfisz theorem, but so far been unsuccessful. I know the constant in the theorem is not effectively computable, so I don't see how I can get the bound explicit using the theorem. • Note that the left side is constant for at least k consecutive values of x, while the right side isn't, so some error on the order of (\log(x+k)-\log x)/\phi(k) is unavoidable. Commented Dec 12, 2021 at 22:04 • If k = \mathcal{O}(\log ^\alpha x), then the Siegel–Walfisz theorem implies  \sum_{\substack{p\le x \\p\equiv \ell\;(\text{mod} \; k)}}\frac{\log(p)}{p} = \frac{{\log x}}{{\phi (k)}} + \frac{1}{{\phi (k)}} + \int_1^{ + \infty } {\frac{1}{{t^2 }}\left[ {\theta (t;k,\ell ) - \frac{t}{{\phi (k)}}} \right]dt} + o(1),  as x\to +\infty. – Gary Commented Dec 13, 2021 at 2:00 • Improving the O(1) term to C+o(1) is the PNT for the arithmetic progression \ell\bmod k. Commented Dec 13, 2021 at 2:14 • Note that we subtract the leading term of the asymptotics of \theta inside the integral and so it is no longer \mathcal{O}(t). – Gary Commented Dec 17, 2021 at 23:39 ## 3 Answers If $$k=\mathcal{O}(\log^\alpha x)$$, then by the Siegel–Walfisz theorem $$\theta (x;k,\ell ) = \frac{x}{{\phi (k)}} + \mathcal{O}(xe^{ - c(\alpha )\sqrt {\log x} } ).$$ Thus, by partial summation, \begin{align*} \sum_{\substack{p\le x \\p\equiv \ell \,(\text{mod} \, k)}}\frac{\log p }{p} & = \frac{{\theta (x;k,\ell )}}{x} + \int_1^x {\frac{{\theta (t;k,\ell )}}{{t^2 }}dt} \\ & = \frac{{\theta (x;k,\ell )}}{x} + \frac{1}{{\phi (k)}}\int_1^x {\frac{{dt}}{t}} + \int_1^{ + \infty } {\frac{1}{{t^2 }}\left[ {\theta (t;k,\ell ) - \frac{t}{{\phi (k)}}} \right]dt} \\ &\quad\; - \int_x^{ + \infty } {\frac{1}{{t^2 }}\left[ {\theta (t;k,\ell ) - \frac{t}{{\phi (k)}}} \right]dt} \\ & = \frac{{\log x}}{{\phi (k)}} + \frac{1}{{\phi (k)}} + \int_1^{ + \infty } {\frac{1}{{t^2 }}\left[ {\theta (t;k,\ell ) - \frac{t}{{\phi (k)}}} \right]dt} \\ & \quad\; - \mathcal{O}(1)\int_x^{ + \infty } {\frac{1}{t}e^{ - c(\alpha )\sqrt {\log t} } dt} + \mathcal{O}(e^{ - c(\alpha )\sqrt {\log x} } ) \\ & = \frac{{\log x}}{{\phi (k)}} + \frac{1}{{\phi (k)}} + \int_1^{ + \infty } {\frac{1}{{t^2 }}\left[ {\theta (t;k,\ell ) - \frac{t}{{\phi (k)}}} \right]dt} + o(1). \end{align*} The error term may be improved from $$o(1)$$ to $$\mathcal{O}(\sqrt {\log x} \,e^{ - c(\alpha )\sqrt {\log x} } )=\mathcal{O}(e^{ - d(\alpha )\sqrt {\log x} } ).$$ • Thanks a Lot for the answer. I have gone through it in great detail, and see what I could have done differently. For one, I could have applied the Abel summation with 1/t instead of \log(t)/t. Commented Dec 18, 2021 at 13:37 We have \[ \text { something you know }=\sum _{n\leq x}\log n=\sum _{d\leq x}\Lambda (d)\sum _{n\leq x\atop {d|n}}1=\text { main term }-\sum _{d\leq x}\Lambda (d)\left \{ \frac {x}{d}\right \} \approx ...-\sum _{p\leq x}\log p\left \{ \frac {x}{p}\right \}

and an asymptotic for this last sum is classical, although I don't know a reference. I assume it amounts to the PNT.

Perhaps you could look for a reference and see what changes you need to do when looking at arithmetic progressions. I believe it would be as reuns says above that it's the PNT for AP.

Thanks to the answer by Gary, we have $$\sum_{\substack{p\le x \\ p\equiv \ell (\text{mod}\; k)}}=\frac{\log(x)}{\phi(k)}+\beta(k,\ell)+O \left(e^{-d\sqrt{\log(x)}} \right ),$$ for some positive constant $$d$$, where $$\beta(k,\ell)=\frac{1}{\phi(k)}+\int_1^{+\infty}\frac{1}{{t^2 }}\left[ {\theta (t;k,\ell ) - \frac{t}{{\phi (k)}}} \right]dt.$$ If $$q_1,q_2,\ldots$$ denote the primes $$\equiv l\; (\text{mod}\; k)$$ in order and $$q_0:=1$$, then $$\theta(t;k,\ell)$$ is constant and equal to $$\theta(q_n;k,\ell)$$ on the interval $$[q_n, q_{n+1})$$, and so \begin{align*} \beta(k,\ell)\;=&\;\frac{1}{\phi(k)}+\sum_{n=0}^{\infty}\int_{q_n}^{q_{n+1}}\frac{\theta(q_n;k,\ell)}{t^2}-\frac{1}{\phi(k)t}dt\\[1.5mm] =\;&\frac{1}{\phi(k)}+\sum_{n=0}^{\infty}\left( \theta(q_n;k,\ell)\frac{q_{n+1}-q_n}{q_nq_{n+1}}-\frac{\log(q_{n+1})}{\phi(k)}+\frac{\log(q_n)}{\phi(k)}\right ). \end{align*} Including only $$N$$ terms of the sum, we get \begin{align*} \beta_N(k,\ell)=&\frac{1}{\phi(k)}+\sum_{n=0}^{N}\left( \theta(q_n;k,\ell)\frac{q_{n+1}-q_n}{q_nq_{n+1}}-\frac{\log(q_{n+1})}{\phi(k)}+\frac{\log(q_n)}{\phi(k)}\right )\\ =&\;\frac{1}{\phi(k)}-\frac{\log(q_{N+1})}{\phi(k)}+\sum_{n=0}^{N} \theta(q_n;k,\ell)\frac{q_{n+1}-q_n}{q_nq_{n+1}}, \end{align*} since all the logarithms except $$\log(q_{N+1})$$ vanish. Running the following function in python:

import sympy
import math
def series(k,l,N):
phi = sympy.ntheory.totient(k)
temp = 1 / phi
theta = 0
previous = 1
for p in sympy.primerange(1, N+1):
if p % k == l:
temp += theta * (p-previous)/(p*previous)
theta += math.log(p)
previous = p
temp -= math.log(previous)/phi
return temp


gives $$\beta_{10^{10}}(k=4,l=1)=-1.112398254781386\;$$ and $$\beta_{10^{10}}(k=4,l=3)=-0.5667372304981679$$.