I was reading a paper on the Chebyshev bias and they defined $$\psi(x,q,a) = \sum_{\substack{n\leq x \\ n \equiv a \mod{q}}} \Lambda(n)$$ where $\Lambda$ is the von Mangoldt function. They also defined $$\theta(x,q,a) = \sum_{\substack{ p \leq x \\ p \equiv a \mod{q} }} \log(p)$$ where the sum is over the primes less than $x$.
They then say that from Dirichlet's theorem we get $$\psi(x,q,a) = \theta(x,q,a) + \left(\sum_{b^2\equiv a \mod{q}} 1 \right)\frac{\sqrt{x}}{\phi(q)} + O \left(\frac{\sqrt{x}}{\log x}\right)$$
I'm not sure how you prove this and my searches for this online have been fruitless. I know that $$\psi(x,q,a) = \sum_{\substack{p \leq x \\ p \equiv a \mod{q}}} \lfloor\frac{\log(x)}{\log(p)}\rfloor \log(p) = \theta(x,q,a) + \sum_{\substack{p \leq \sqrt{x} \\ p \equiv a \mod{q}}} \left(\lfloor\frac{\log(x)}{\log(p)}\rfloor-1\right)\log(p)$$ $$ = \theta(x,q,a) + \sum_{\substack{p \leq \sqrt{x} \\ p \equiv a \mod{q}}} \left(\lfloor\frac{\log(\sqrt{x})}{\log(\sqrt{p})}\rfloor-1\right)\log(p)$$
My general idea now was to "replace" $\sqrt{p}$ with $n$. Then $n$ would satisfy $n^2 \equiv a \mod{q}$ and we would have a sum that would look something like $$\sum_{\substack{n\leq \sqrt{x} \\ n^2 \equiv a \mod{p}}} \left(\lfloor\frac{\log(\sqrt{x})}{\log(n)}\rfloor\right)\log(n) $$ And then Dirichlet's thereom would imply that this is $$\left(\sum_{b^2\equiv a \mod{q}} 1 \right)\frac{\sqrt{x}}{\phi(q)} + O \left(\frac{\sqrt{x}}{\log x}\right)$$
However, obviously, "replacing" $\sqrt{p}$ by $n$ doesn't really make sense. As well, we run into trouble with the range at which $n$ will run over $\sqrt[4]{x}$ and not $\sqrt{x}$.
What is the correct reasoning for this? Any solution or reference would be greatly appreciated.
The assertion holds only if $\gcd(a,q) = 1$, I assume that condition. We can write
$$\psi(x,q,a) = \sum_{k = 1}^\infty \left(\sum_{\substack{p^k \leqslant x \\ p^k \equiv a \pmod{q}}} \log p\right) = \theta(x,q,a) + \sum_{\substack{p^2 \leqslant x \\ p^2 \equiv a \pmod{q}}} \log p + \sum_{k = 3}^\infty (\dotsc).$$
We can throw a brutal estimate at the last sum and bound it by (a constant times) $\sqrt[3]{x}\cdot \log x$, that's well below the error bound we want in the end.
So we need to look at the sum
$$\sum_{\substack{p^2 \leqslant x \\ p^2 \equiv a \pmod{q}}} \log p.$$
We can rewrite that as
$$\sum_{b^2 \equiv a \pmod{q}} \sum_{\substack{p \leqslant \sqrt{x} \\ p \equiv b \pmod{q}}} \log p = \sum_{b^2 \equiv a \pmod{q}} \theta(\sqrt{x},q,b).$$
The prime number theorem for arithmetic progressions - without error bounds - tells us that
$$\pi_{q,r}(y) = \sum_{\substack{p \leqslant y \\ p \equiv r \pmod{q}}} 1 \sim \frac{1}{\phi(q)} \operatorname{Li}(y)$$
for every $r$ coprime to $q$. This is not sufficient for our purposes, however. We need
$$\pi_{q,r}(y) = \frac{1}{\phi(q)} \frac{y}{\log y} + O\left(\frac{y}{(\log y)^2}\right),\tag{$\ast$}$$
which hopefully comes out of a proof of a quantitative version of Dirichlet's theorem (note that Dirichlet's theorem about primes in arithmetic progressions only says that each such progression $\{r + k\cdot q : k \in \mathbb{N}\}$ with $\gcd(r,q) = 1$ contains infinitely many primes). If not, it follows for example from the Siegel-Walfisz theorem, but that's a too big hammer, probably.
From $(\ast)$, we obtain
$$\theta(y,q,b) = \frac{y}{\phi(q)} + O\biggl(\frac{y}{\log y}\biggr)\tag{$\ast{\ast}$}$$
using the upper bound $\theta(y,q,b) \leqslant (\log y)\pi_{q,b}(y)$ and the lower bound
$$\theta(y,q,b) \geqslant \sum_{\substack{y/(\log y)^2 < p \leqslant y \\ p \equiv b \pmod{q}}} \log p \geqslant \log \frac{y}{(\log y)^2} \bigl(\pi_{q,b}(y) - \pi_{q,b}(y/(\log y)^2)\bigr).$$
Using $(\ast{\ast})$ for each $\theta(\sqrt{x},q,b)$ such that $b^2 \equiv a \pmod{q}$ we obtain
$$\sum_{\substack{p \leqslant \sqrt{x} \\ p^2 \equiv a \pmod{q}}} \log p = \left(\sum_{b^2 \equiv a \pmod{q}} 1\right) \frac{\sqrt{x}}{\phi(q)} + O\biggl(\frac{\sqrt{x}}{\log x}\biggr),$$
which is what we desired.
Without $(\ast)$, with only the prime number theorem for arithmetic progressions, we can only get
$$\psi(x,q,a) = \theta(x,q,a) + \left(\sum_{b^2 \equiv a \pmod{q}} 1\right)\frac{\sqrt{x}}{\phi(q)} + o(\sqrt{x}),$$
which might already suffice.