# The pattern of $n$-th prime minus its reversal in even and odd bases

I recently saw the sequence A265326 on OEIS and also in Brady's Numberphile video Amazing Graphs ft. Neil Sloane

The sequence is such:

Start from $$2$$, given the $$x$$-th prime number and convert it into its binary representation. Then, reverse all the digits of the binary number and subtract it from the original binary number after converting both of them into decimals. The difference would be the $$y$$-coordinate.

Here is a chart for clarification: $$\begin{array}{|c|c|c|c|} \hline x& \text{Prime} & \text{Binary} & \text{Binary Reversal} & \text{Difference}(y) \\ \hline 1&2 &10 &01 &1\\ \hline 2&3 &11 &11 &0\\ \hline 3&5 &101 &101 &0\\ \hline 4&7 &111 &111 &0\\ \hline 5&11 &1011 &1101 &-2\\ \hline 6&13 &1101 &1011 &2\\ \hline 7&17 &10001 &10001 &0\\ \hline \vdots&\vdots &\vdots &\vdots &\vdots\\ \hline \end{array}$$ I then decided to represent the primes in different bases and plot the graph of $$x$$ vs $$y$$. The charts and graphs are as following: $$\begin{array}{|c|c|c|c|} \hline x& \text{Prime} & \text{Ternary} & \text{Ternary Reversal} & \text{Difference}(y) \\ \hline 1&2 &2 &2 &0\\ \hline 2&3 &10 &01 &2\\ \hline 3&5 &12 &21 &-2\\ \hline 4&7 &21 &12 &2\\ \hline 5&11 &102 &201 &-8\\ \hline 6&13 &111 &111 &0\\ \hline 7&17 &122 &221 &-8\\ \hline \vdots&\vdots &\vdots &\vdots &\vdots\\ \hline \end{array}$$ $$\begin{array}{|c|c|c|c|} \hline x& \text{Prime} & \text{Quaternary} & \text{Quaternary Reversal} & \text{Difference}(y) \\ \hline 1&2 &2 &2 &0\\ \hline 2&3 &3 &3 &0\\ \hline 3&5 &11 &11 &0\\ \hline 4&7 &13 &31 &-6\\ \hline 5&11 &23 &32 &-3\\ \hline 6&13 &31 &13 &6\\ \hline 7&17 &101 &101 &0\\ \hline \vdots&\vdots &\vdots &\vdots &\vdots\\ \hline \end{array}$$ Binary:

Ternary:

Quaternary:

Quinary:

Senary:

Question: Could anyone provide an explanation of why there is a blank gap in each parallelogram when the primes are represented in even bases, except for binary representation?

I am not sure how to tackle this question. Actually, I don't see any reason why there should be a gap in the parallelogram, which is really weird. I am pretty sure I got the code right, and the graphs should also be right.

If you are interested in the java code to generate the graphs, please see here.

• odd numbers having an odd number of odd digits in odd bases might play a role in non separation. or that most primes are 1 or 5 mod 6, or 1 or 3 mod 4, etc.
– user645636
Sep 1, 2019 at 23:50

Here is another look at the data. A single parallelogram in one of these pictures corresponds to a particular number of digits. So I've plotted just one parallelogram of the same points below, but for all numbers, not just primes; I've marked the primes in red and all other numbers in blue.

From left to right, we have: the parallelogram of $$14$$-digit numbers in base $$2$$; of $$9$$-digit numbers in base $$3$$; and of $$7$$-digit numbers in base $$4$$. (But approximately the same pictures would be visible for any number of digits.)

Actually, the reason it's a parallelogram and not a rectangle is because we are plotting $$y = x - \text{reverse}(x)$$, and the $$x$$ term tilts the picture. Instead, we could plot $$y = -\text{reverse}(x)$$, and get rectangles:

(Similar pictures would occur for $$y = \text{reverse}(x)$$, actually, just flipped vertically.)

So what are the stripes in these pictures? They are determined by the first digit of $$\text{reverse}(x)$$, which is the last digit of $$x$$. And in any base, the last digit of $$x$$ has a lot to do with whether $$x$$ is prime:

• In base $$2$$, the last digit of a prime must be $$1$$, because the number must be odd.
• In base $$3$$, the last digit of a prime must be $$1$$ or $$2$$, because the number must not be a multiple of $$3$$.
• In base $$4$$, the last digit of a prime must be $$1$$ or $$3$$, because the number must be odd.
• In general, in base $$b$$, the last digit of a prime must be relatively prime to $$b$$.

As a result, if we divide the base-$$b$$ parallelogram into $$b$$ equal stripes, the primes can only appear in a subset of those stripes. This is true for any base. But if $$b$$ is a prime base, we eliminate the top stripe (corresponding to $$x$$ ending in $$0$$) and we're still left with a smaller parallelogram. If $$b$$ is a composite base, the last digit of $$x$$ tells us divisibility of $$x$$ by every factor of $$b$$, and we can also eliminate some stripes inside the parallelogram.