It is well known that there is a little bias in the distribution of prime residues modulo 4. But the bias eventually vanishes. I looked at the first million primes, and the counts are as follows:
- 499798 have residue 1
- 500201 have residue 3
A much more striking bias is about the autocorrelation, and successive runs in the value of the residue. They appear to not be distributed as if produced via a random sequence.
Question
I am wondering if this bias also vanishes when considering much longer sequences, whether it has a simple explanation, or if there is any literature on the subject. I've found this article, but not sure it addresses this issue.
Results of my computations
Let $x_k = \bmod(p_k, 4)$ where $p_k$ is the $k$-th prime. Let $y_k=x_{k+1}$. The empirical correlation between $(x_k)$ and $(y_k)$ is around $-1/8$ for the first million primes. Higher auto-correlations (lag-2, lag-3 and so on) are closer to zero. Also the bias seems stronger for smaller primes.
If you look at runs of length 1, 2, and so on in the sequence $(x_k)$, it is skewed in favor of shorter runs. For instance, $56.26\%$ are of length 1, a significant departure from the expected value $50\%$, and much stronger than the bias mentioned above for raw counts of $x_k=1$ versus $x_k=3$. It means that $x_k$, more often than not, is different from $x_{k-1}$.
Finally Let $z_k=(x_k-2)+z_{k-1}$ the random walk associated with the sequence $(x_k)$. Its graph is plotted below, with $k$ on the X-axis and $z_k$ on the Y-axis:
I conjecture this kind of Brownian motion crosses the X-axis infinitely many times.