Was exploring successive differences of primes and noticed an interesting pattern of the histogram of counts for the sixth and ninth difference. The ninth is more pronounced, code and image below.

Mathematica code:

n = 5000000; (* First n primes *)
p = Prime[Range[2, n]]; (* Excluding first prime *)
d = Differences[p, 9];  (* 9th difference, diff(diff(diff...)) *)
min = Min[d];
max = Max[d];
values = Range[min, max, 2];
counts = BinCounts[d, {min, max + 2, 2}];
ListPlot[Transpose[{values, counts}], PlotRange -> All]

enter image description here

  • $\begingroup$ Nice question, this is neat! $\endgroup$ May 26 at 17:03

1 Answer 1


The pattern you are noticing is that $9^{\text{th}}$ differences modulo $6$ are congruent to $0$ about twice as often as $2$ or $4$. So you get a bell curve of the values divisible by $6$ above the bell curve of the values not divisible by $6$.

A typical $9^{\text{th}}$ difference looks like $$ p_{i+9} - 9 p_{i+8} + 36 p_{i+7} - 84 p_{i+6} + 126 p_{i+5} - 126 p_{i+4} + 84 p_{i+3} - 36 p_{i+2} + 9 p_{i+1} - p_i. $$ Taken modulo $6$, we first end up with $p_{i+9} - 3p_{i+8} + 3p_{i+1} - p_i$. But in fact $3p_{i+8}$ and $3p_{i+1}$ are both congruent to $3$ modulo $6$, because all primes except $2$ are odd, so the $9^{\text{th}}$ difference is just congruent to $p_{i+9} - p_i$ modulo $6$.

Primes larger than $3$ come in two kinds: $p_i \bmod 6$ can be either $1$ or $5$. These are known to be equally common in the long run: we can think of it as a coin flip. They are not quite independent coin flips, but as $i$ gets large, $p_i$ and $p_{i+9}$ become pretty far apart and so we don't expect much correlation between $p_i \bmod 6$ and $p_{i+9} \bmod 6$. (But I'm not sure if this is proven or just expected heuristically.)

In the heuristical model where $p_i \bmod 6$ and $p_{i+9} \bmod 6$ are each independently randomly chosen from $\{1,5\}$, their difference $p_{i+9} - p_i$ is:

  • $0 \bmod 6$ half the time: when we take $1-1$ or $5-5$.
  • $2 \bmod 6$ a quarter of the time: when we take $1-5$.
  • $4 \bmod 6$ a quarter of the time: when we take $5-1$.

The frequencies of $2 \bmod 6$ and $4 \bmod 6$ are about the same, so they form the lower bell curve together. (It looks thicker, because there are about twice as many points there.) Since $0\bmod 6$ has a frequency about twice as high, it forms a separate bell curve scaled up from the first.

In general, for any $k^{\text{th}}$ difference, we expect some effect, because if $(p_i, \dots, p_{i+k}) \bmod 6$ were evenly distributed on $\{1,5\}^{k+1}$, we can't evenly divide the $2^{k+1}$ possibilities between the three results $0$, $2$, or $4$. The difference is strongest when many of the coefficients in the $k^{\text{th}}$ difference are divisible by $3$; $k=1$ or $k=3$ actually have as strong an effect as $k=9$, and $k=2$ should be about as good as $k=6$.

The difference is also easier to see for larger $k$, simply because the interesting parts of the bell curves have more points! This explains why you might not have seen anything for $k=1$ or $k=3$. If we go up to $n = 50\,000\,000$, I can make out the two bell curves for $3^{\text{rd}}$ differences, but they don't look as nice as for $9^{\text{th}}$ differences.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.