TITLE: Prime square offsets: Why is +7 more frequent than -7?
QUESTION [25 upvotes]: For a prime $p$, define $\delta(p)$ to be the smallest offset $d$ 
from which $p$ differs from a square:
$p = r^2 \pm d$, for $d,r \in \mathbb{N}$. 
For example,
\begin{eqnarray}
\delta(151) & = & +7 \;:\; 151 = 12^2 + 7 \\
\delta(191) & = & -5 \;:\; 191 = 14^2 - 5 \\
\delta(2748971) & = & +7 \;:\; 2748971= 1658^2 + 7
\end{eqnarray}
For a particular $\delta=d$ value, define $\Delta(n,d)$ to be the number
of primes $p$ at most $n$ with $\delta(p) = +d$, minus the number with $\delta(p) = -d$. In other words, $\Delta$ records the cumulative prevalence of $+d$ offsets over $-d$. For example, $\Delta(139,5)=-2$ because there are two more $-5$'s than $+5$'s up to
$n=139$:
$$
\delta(31)=-5 \;,\; \delta(41)=+5 \;,\; \delta(59)=-5\;,\; \delta(139) =-5  \;.
$$
The figure below shows $\Delta(p,5)$ and $\Delta(p,7)$ out to the $200000$-th
prime $2750159$.
The offset $+7$ occurs $161$ times more than the offset $-7$, and
the reverse occurs for $|\delta|=5$: $-5$ is more common than $+5$.

      



Q. Is there a simple explanation for the different behaviors of offsets 
  $5$ and $7$?

Obviously the question can be generalized to explaining the growth for
any $|\delta|$.
I previously asked a version of this question on MSE, 
using somewhat different notation conventions
and with less focused questions.

REPLY [42 votes]: Consider $n^2+7$ and $n^2-7$ modulo $3$.   If these are to be prime they must be non-zero $\pmod 3$, and in the first case $n$ can be anything mod $3$, whereas in the second case $n$ must be $0 \pmod 3$.  If you consider $n^2+5$ and $n^2-5$, you see that the pattern reverses.  This is already a huge bias for one offset to be preferred over the other.  
The Hardy-Littlewood conjectures make this precise.  One expects that (for a number $k$ not minus a square) the number of primes of the form $n^2+k$ with $n\le N$ (say) is 
$$ 
\sim \frac 12 \prod_{p\ge 3} \Big(1 -\frac{(\frac{-k}{p})}{p-1} \Big) \frac{N}{\log N},
$$ 
where in the numerator of the product above is the Legendre symbol. The constants in front of the $N/\log N$ explain these biases.  
You don't have to worry about a smaller offset than $\pm 5$ or $\pm 7$, since an application of the sieve shows that the numbers $n^2+a$ and $n^2+b$ (for fixed $a$, $b$) are both prime only $\le CN/(\log N)^2$ of the time for a constant $C$.

REPLY [9 votes]: Modulo 6 the squares are 0,1,4,3,4,1 and the squares+7 (or -5) can only be 1,2,5,4,5,2, of which 3/6 can at all be prime. The squares-7 (or +5) are 5,0,3,2,3,0 of which only 1/6 can be prime. Obviously this not a proof, but there is clearly no first order surprise in the observed offsets.
UPDATE I checked offsets modulo different numbers (such as (mod 2*3*5*7*11*13*17*...)) and I found that mod(3*7*11*19*23) we get 64638/25806 for +7/-7 and 21945/73899 for +5/-5, while primes 2, 5, 13, 17, 29  don't affect the ratio. I imagine that exploring more primes will further refine the ratios, with primes $\equiv 3$ (mod 4) affecting them and others not. WHAT IS GOING ON HERE?