# Has anyone found a “pattern” in prime numbers?

Yesterday I was having some fun trying to look for some patterns in primes; and I think I found something interesting.

The idea is to start with an array of primes {p1, p2, p3, ... }, print it, then set the value at index i = abs( [i] - [i-1] ) or put more formally, set the value at i equal to the "prime gap"; then repeat this, but use the prime gaps and find their gaps. And so on.

screenshot.

You can see at the top row we start with the primes, then their gaps, then their gaps, and so on. It starts to produce that triangle pattern

Here is the code to produce the pattern I've found. If you run the code you can see the pattern, it's actually pretty fascinating!

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.Arrays;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class PrimeSandbox
{

public static void main(String[] args)
{
JTextArea screen = new JTextArea(5, 20);
Font font = new Font("Times New Roman", Font.BOLD, 8);
screen.setFont(font);
screen.setForeground(Color.BLUE);
JScrollPane scrollPane = new JScrollPane(screen);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
//frame.pack();
frame.setLocation(0, 0);
frame.setSize(1000, 1000);
frame.setVisible(true);
frame.setAlwaysOnTop(true);

int arrsize = 150;
int[] parrOrig = {  2,      3,      5,      7,     11,     13,     17,     19,     23,     29,
31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
73,     79,     83,     89,     97,    101,    103,    107,    109,    113,
127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
179,    181,    191,    193,    197,    199,    211,    223,    227,    229,
233,    239,    241,    251,    257,    263,    269,    271,    277,    281,
283,    293,    307,    311,    313,    317,    331,    337,    347,    349,
353,    359,    367,    373,    379,    383,    389,    397,    401,    409,
419,    421,    431,    433,    439,    443,    449,    457,    461,    463,
467,    479,    487,    491,    499,    503,    509,    521,    523,    541,
547,    557,    563,    569,    571,    577,    587,    593,    599,    601,
607,    613,    617,    619,    631,    641,    643,    647,    653,    659,
661,    673,    677,    683,    691,    701,    709,    719,    727,    733,
739,    743,    751,    757,    761,    769,    773,    787,    797,    809,
811,    821,    823,    827,    829,    839,    853,    857,    859,    863,
877,    881,    883,    887,    907,    911,    919,    929,    937,    941,
947,    953,    967,    971,    977,    983,    991,    997,   1009,   1013 };
int [] parr = Arrays.copyOf(parrOrig, arrsize);
int lines = 0;
while(lines < 1000)
{
int[] oldarr = Arrays.copyOf(parr,arrsize);

for(int i = 0; i < arrsize; i++)
screen.append(" " + oldarr[i]);
screen.append("\n");
screen.setCaretPosition(screen.getText().length());

for(int i = 0; i < arrsize; i++)
{
if(i == 0)
parr[i] = 0;
else
parr[i] = Math.abs(oldarr[i] - oldarr[i-1]);
}
lines++;
try {
} catch(InterruptedException ex) {
}
}

}
}

• Sierpinski triangles? – Eleven-Eleven Apr 24 '13 at 12:41
• The question in the title, "has anyone found a pattern in prime numbers," the answer depends on what you call a pattern. Indeed, there is a very simple pattern --- all of them are prime. The other question you ask, whether anyone has done the calculations you have done, I'm sure the answer is yes. I think the relevant search term is Andrica's conjecture. No, wait, I just checked it, that's the wrong one. I'll come back if I find the right one. Ah, Gilbreath's conjecture, en.wikipedia.org/wiki/Gilbreath%27s_conjecture – Gerry Myerson Apr 24 '13 at 12:46
• What you're doing is called "recursive forward differencing". If some generation of the forward differnces turn out to be nice and simple, then you can often work backwards and get a reasonably simple function that generates the original values. For example, if the n-th generation of forward differences are all zero, you can work backwards to get a polynomial. – bubba Apr 24 '13 at 13:14
• .ps is postscript. If you're on a Mac, Preview should open it for you. If you're on Windows, I'm sure there's something that will open it, but I don't know what. – Gerry Myerson Apr 24 '13 at 13:30
• @BumSkeeter: your evolution is not the same as the one in Gilbreaths Conjecture. You are taking differences with the element on the left, while the Gilbreaths Conjecture deal with differences with element on the right. This makes a huge difference. His first column is in fact your diagonal. – Willie Wong Apr 24 '13 at 14:37

Note that we can write your iteration scheme as, for $i \geq 0$ \begin{align} x(0,i) & = \text{given sequence of nonnegative integers}\\ x(n+1,i) & = \begin{cases} 0 & i = 0 \\ \left|x(n, i) - x(n,i-1)\right| & i > 0\end{cases}\end{align}

The first implication of this definition is that

Property 1 the value of $x(n,i)$ is determined completely by the values $x(0,0), x(0,1), \ldots, x(0,i)$.

Let us define $M(n,i) = \max_{0 \leq j \leq i} x(n,j)$.

Lemma 2 For any initial distribution of nonnegative integers, $M(n,i)$ is nondecreasing in $i$ and nonincreasing in $n$.

Proof: nondecrease in $i$ is clear from the definition of $M$. Nonincrease in $n$ follows from the recursive relation and the fact that all numbers involved are non-positive, so $|x(n,i) - x(n,i-1)| \leq \max( x(n,i), x(n,i-1)) \leq M(n,i)$. q.e.d.

Lemma 3 For any initial distribution of nonnegative integers, if there exists a $i_0 \geq 0$ and $n_0 \geq 0$ such that $M(n_0,i_0) = 0$, then the first $i_0 + 1$ numbers in the data are all the same.

Proof: By the recursion rule we easily see that if $n_0 > 1$, then $M(n_0, i_0) = 0 \iff M(n_0 - 1, i_0) = 0$. (We start from $x(n_0 - 1, 0) = 0$ and solve increasing in $i$.) If $M(1,i_0) = 0$ then necessarily the first $i_0 + 1$ numbers in the data are all equal. q.e.d.

Corollary 4 If for some $i_0,n_0 > 0$ we have that $M(n_0,i_0) \neq 0$, then for any $n \geq n_0$ we also have $M(n, i_0) \neq 0$.

The corollary can be used to show

Proposition 5 Let $n_0 > 0$ and $i_0 > 0$ be fixed. Suppose $M(n_0, i_0) \neq 0$. Then $x(n,i_0+1)$ will eventually, as $n$ increases, decay to be at most $M(n_0,i_0)$.

Proof (sketch): We argue by contradiction. Suppose always $x(n,i_0+1) = M(n,i_0+1) > M(n_0,i_0) > 0$. Since $M(n,i_0+1)$ is nonincreasing in $n$, we have that $x(n,i_0+1)$ converges to some $x_0 > M(n_0, i_0)$ in finite time. Suppose $x(n,i_0+1) = x_0$ for all $N \leq n \leq N + 2i_0$ as guaranteed by the convergence. This requires that $x(n,i_0) = 0$ for all $N \leq n \leq N + 2i_0 - 1$, and iterating by induction we see that this implies for all $N \leq n \leq N + i_0 - 2$ and all $0 \leq i \leq i_0$ that $x(n,i) = 0$, thus showing $M(n,i_0) = 0$, which gives a contradiction. q.e.d.

Corollary 6 for any initial data such that $|x(0,0) - x(0,1)| = 1$ (The list of prime numbers, for example), we have that for any $i_0 > 0$ we can find some $n_0 > 0$ such that for all $n > n_0$, $M(n,i_0) = 1$.

Proof: We know that $M(1,1) = 1$. The previous proposition implies that for sufficiently large $n$, $x(n,2) \leq 1$, hence $M(n,2) = 1$. By induction this holds true for all $i_0$.

Notice that Property 1 implies that once we have an initial segment that looks like a line from the Sierpinski gasket, the rectangular region below it will be exactly the Sierpinski gasket type evolution.

Now, also note that your system is taking differences with the element "to the left". If you take differences with the element "to the right" you end up in the situation in Gilbreath's Conjecture. The previous paragraph in fact shows:

Gilbreath's Conjecture is equivalent to the statement that "the Sierpinski gasket pattern below the diagonal that you observed continues indefinitely."

• This says what I found converges to a Sierpinski gasket? (I really wish I could read it, I mean I can somewhat follow it, but I cant pull the reasoning out of it, and I do not know enough about Sierpinski to correlate) Give me a few days and I'll get it :) And thank you Willie for the time you've spent for me! Shoot me a PM with your email and I will send you the visualizer I am trying to make for the pattern! – KDecker Apr 24 '13 at 14:58
• No, it doesn't say that (unfortunately). What I showed is that the statement "what you found actually converges to a Sierpinski gasket" is equivalent to Gilbreath's conjecture; if you prove one, you prove the other. What we know is that for the first $10^13$ columns in your diagram, as you scroll down you will converge to Sierpinski gasket (since Odlyzko checked that far). For larger numbers I don't know. – Willie Wong Apr 24 '13 at 15:02
• Roughly speaking, what I showed is that if you fix your eyes on a column and wait sufficiently long, the numbers in the column will eventually decrease to just 0s and 1s. Whether they actually form the Sierpinski pattern requires much more detailed analysis. – Willie Wong Apr 24 '13 at 15:08
• You put more formally, that the absolute value of the difference of two numbers can never be negative? (Weird weird way to look at it; doesn't encompass it all either; faster conclusion I can draw though) – KDecker Apr 24 '13 at 15:12
• Also if your'e interested thread about the visualizer codereview.stackexchange.com/questions/25436/… – KDecker Apr 24 '13 at 19:22

Given any sequence starting with $2$ and then containing only even numbers will produce Sierpinski-like patterns emerging and growing from the left.

If the triangle meets a $0$ or $2$ at its right end, it continues to grow. Otherwise, it starts afresh while decreasing the number at the right end it will meet the next time, until it has decayed enough to allow the triangle to grow further to the right.

• Consider initial data 0222002, Next row is 0200202, then 0220222, then 0202200, then 0222020, then 0200222, then 0220200, then 0202220, then 0222002 which is what we started with. This never actually converges to the Sierpinski pattern. – Willie Wong Apr 24 '13 at 14:47

## protected by Community♦Feb 6 '14 at 1:27

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).