Pattern “inside” prime numbers

Update (2020)

I’ve observed a possible characterization and a possible parametrization of the pattern, and I’ve additionally rewritten the entire post with more details and better definitions.

It remains to prove the observed possible characterization, and then complete it by finding the sequences for locations of the “parabolic shapes” that live in the characterized regions.

Table of contents:

  • Visualization of factorizations

  • Inside prime visualizations

  • The pattern and the question

  • Pattern parametrization

Visualization of factorizations

Here I will explain how we can visualize positive integers in an interesting way which also has the property that the factorization of n is encoded into it in the form of a fractal-like pattern.

2-digit palindromes represent factorizations

We say that a positive integer is palindromic in some integer number base (number-system) b2 if when written in that number base, its digits are read the same forward and backwards.

The 2-digit palindrome is an integer n=(a,a)b=ab1+ab0=a(b+1),a<b,a1, where in the (n1,n2,)b notation, n1,n2, stand for digits of n in the integer base b2.

Factorizations of positive integers n are related to 2-digit palindromes. That is, if n can be factorized as n=pq where p<q1, this means that n is a 2-digit palindrome in the number base q1, which we write as:


where (p,p) are digits of n=pq in the number base q1.

Representing nN as a sum of n×n images (matrices)

First we define a "matrix of point", then we define the "sum" of these matrices.

Let x0,y0 be nonnegative integers. Let Pn(x0,y0) be a n by n matrix "of point (x0,y0)" whose top left entry is denoted with Pn(x0,y0)(0,0) and whose bottom right entry is denoted with Pn(x0,y0)(n1,n1). It is defined for x,y[0,n) as:

Pn(x0,y0)(x,y)={1,if x+nx0 is a two digit palindrome in base y+ny00,else

We can visualize these "point" matrices as images by coloring different entries with different colors. For example, "P100(x0,y0)"'s for (x0,x0)=(0,0),(1,0),(2,0),(3,0) are:

enter image description here

Where the green pixels represent the matrix entries that are 1.

Notice that Pn(x0,y0) in point (x0,y0)=(0,0) contains "dotted lines" Lt of points from


and that if we look at Pn(x0,y0) in some other point, we get continuations of these lines.

Visualization of the "image of n" matrix

We define Nn(y0)=k=0Pn(k,y0) as "entry-wise sum of Pn's along the x-axis at level y0". Notice that this sum always sums finitely many matrices because for large enough k=x0, all entries of the matrix are 0.

To visualize Nn(y0) we will color all 0 entries white, and all other entries blue. This visualization remains the same for all y01 except in the top left entry which is zero only for y0=1. If we choose y0=0, then the visualization is "degenerated".

This motivates us to write Nn=f(Nn(1)) and call Nn the "image of n", where f returns the same matrix but all nonzero entries are set to "blue" and all zero entries are set to "white".

For example, below is the image showing the Nn's for n=7,,31. Notice that the prime numbers are solid blue squares with no additional details, and that other numbers have visualizations that correspond to their factorizations.

enter image description here

Patterns in Nn based on factorizations of n

For example, notice that even semi-primes n=2p where p is prime, all have the following look:

enter image description here

Or for example, notice that squares of primes n=p2 have the least details:

enter image description here

On the other hand, numbers with a lot of factors such as factorials like 4!=234=24 or primorials like p3#=235=30 have much more details (factors), and numbers such as powers of primes like 27=33 and 32=25 have regular fractal-like patterns.

enter image description here

One might ask if we can for n in general compute the matrix Nn more efficiently than calculating and summing up all those Pn's. That is, is there an efficient test to get a Nn(x,y) entry directly? This question does not need to be answered, it's just my thought on the current chapter.

Inside prime visualizations

The Np where p is a prime number resembles a solid blue square and looks boring. But, we can "look inside" this solid blue square by replacing our f function.

Recall that we are WLOG observing y0=1 because all y01 yield equivalent images.

"Heat-image" matrix of prime number p

We will write ¯Np=h(Np(1)) and call ¯Np the "heat-image of prime p", where h assigns distinct colors to distinct values of entries of Np(1) and returns such matrix. Let the zero value be "black", the smallest nonzero value be "red" and the second-smallest nonzero value be "yellow". Other values can be "white" or represented in shades of "grey".

For example, here are ¯Np's of primes p=101,103,109:

enter image description here

At first glance these appear to be different sizes of the same image, but this is not the case.

Within different Mp's we find different patterns in certain regions of the image. Thanks to Hyperplane's comment, we can "enhance" these regions by removing the needless details.

That is, if we ignore the last row then these ¯Np's appear to be symmetric along the central horizontal line. In other words, if an entry (x,y) is red then the mirrored entry (x,|py2|) is yellow, and vice versa. However, this is not true for all entries.

This motivates us to observe the "non-mirrored" entries, and set the other ones to 0.

The pattern inside prime number p

We will observe the irregularities in the "heat-image". That is, we define a new matrix Mp:

Mp(x,y)={1,if Np(1)(x,y)=Np(1)(x,|py2|)0,else

We will represent these entries by coloring 1's and 0's with white and black, respectively.

For example, here are Mp's of primes p=101,103,109:

enter image description here

Observe the white pixels near the central horizontal line. Notice that there we can distinguish between a "thick dotted parabola" and a "thin dotted parabola".

For example, zooming into the central horizontal line of 109 shows

enter image description here

that the "thick dotted parabola" one is on the left side, and that the "thin dotted parabola" one is on the right side. It is the same for the prime 101, but not for the prime 103 which has it the other way around.

It turns out that primes of the form p=4k+1 are "left-handed" (have the "thick" parabola on the left side) and that the primes of the form p=4k1 are "right-handed" (have the "thick" parabola on the right side).

It also turns out that these are not the only "parabolic" groups of pixels that exist. I've tried tracing the prime p=101 from different groups of pixels and found a set of three distinct parabolas. Observe the last (fourth) image below.

enter image description here

These have one of the following "shapes" of pixels at their "head":

  • The first ("green parabola") has I2 - "I shape of height of 2 pixels"
  • The second ("blue parabola") has J2,1 - "J shape of height of 2+1 pixels"
  • The third ("red parabola") has I3 - "I shape of height of 3 pixels"

Note that these "shapes" are mirrored below/above the central horizontal line.

All 6 permutations of these "shapes" can appear in some prime number p (in some Mp). Depending on the permutation that appears in the image (the matrix), we can determine if the prime number is of form p=18k+m where m{1,1,5,7,11,13}.

For example, all primes of the form p=18k+11 have the same (I2,J2,1,I3) permutation of these parabolic patterns as the prime 101=185+11, in that region of Mp.

The larger the prime p, the more of these regions we can find.

For example, in primes as large as p=997 I've highlighted four of these regions. Some regions repeat multiple times. For example, notice that there are four instances of the yellow region highlighted.

enter image description here

If the picture above isn't clear, we can alternatively color (highlight) the regions by connecting the pixels (entries) that represent ("belong to") corresponding "parabolic" shapes:

enter image description here

In every region R, we can observe a set of "parabolic" shapes. Different permutations of those shapes will appear in different primes p (in different Mp's), depending on the remainder m from division of p by some constant cR.

The question is now, can we characterize every such region and its shapes?

The pattern and the question

I think I'm having a hard time characterizing all these regions, because I'm actually not sure how to properly define them.

Essentially, it appears Mp contains "regions Rs" and within those regions we can find one of the possible permutations P=(p(s)1,p(s)2,,p(s)s) of s "parabolic shapes".

It seems that region Rs contains some permutation Pm if and only if p\equiv m\pmod{c_s} where c_s is some constant related to the sth region.

Question. 1. Can we characterize all regions R_s and their P_m's and c_s ?

The "pattern inside a prime p" would be the collection of all regions R_s of the matrix M_p.

Note that this is related to Moiré pattern's, as this user pointed out.

Below are the regions I've observed so far.

Characterization of regions R_s for small s

I will be using P=(1,2,\dots,s) as a shortened notation for P=(p^{(s)}_1,p^{(s)}_2,\dots,p^{(s)}_s). Also, the interpretation of this notation is that p^{(s)}_1 is in the leftmost part of the region, and that p^{(s)}_s is in the rightmost part of the region.


In every M_p, if you look either at the very top or at the very bottom, you will find the same "half-parabola" shape p^{(1)}_1. This gives the trivial region:

R_1 : P=(1) \iff p \equiv 1\pmod{2}

That is, there is only one possible permutation within R_1, and every prime p has it.


Given a M_p and looking around the central horizontal line we can find 2 distinct parabolic shapes. These are the "thick parabola" p^{(2)}_1 and the "thin parabola" p^{(2)}_2. I've observed that:

R_2 : P=(1,2) &\iff p \equiv 1\pmod{4} \\
R_2 : P=(2,1) &\iff p \equiv 3\pmod{4} \\

This region splits the primes into two sets.


In the previous chapter we've observed R_3 to contain parabolic shapes characterized by a "short I shape" = p^{(3)}_1, a "long I shape" = p^{(3)}_2 and a "J shape" = p^{(3)}_3. It appears that:

R_3 : P=(1,2,3) &\iff p \equiv 1\pmod{18} \\
R_3 : P=(2,1,3) &\iff p \equiv 5\pmod{18} \\
R_3 : P=(2,3,1) &\iff p \equiv 7\pmod{18} \\
R_3 : P=(1,3,2) &\iff p \equiv 11\pmod{18} \\
R_3 : P=(3,1,2) &\iff p \equiv 13\pmod{18} \\
R_3 : P=(3,2,1) &\iff p \equiv 17\pmod{18} \\

This region splits the primes into six sets. Unlike R_2 that appears only once, this R_3 region appears twice in the image: above and (mirrored) below the central horizontal line.


The region R_4 is similar to R_3 but of course has more permutations. This region contains parabolic shapes characterized by following shapes (groups of pixels): "3 long pixels" = p^{(4)}_1, "2 short pixels" = p^{(4)}_2, "2 long pixels" = p^{(4)}_3 and "3 short pixels" = p^{(4)}_4. The corresponding congurences are:

R_4 : P=(1,2,3,4) &\iff p \equiv 1\pmod{16} \\
R_4 : P=(1,4,3,2) &\iff p \equiv 3\pmod{16} \\
R_4 : P=(4,1,2,3) &\iff p \equiv 5\pmod{16} \\
R_4 : P=(2,1,4,3) &\iff p \equiv 7\pmod{16} \\
R_4 : P=(3,4,1,2) &\iff p \equiv 9\pmod{16} \\
R_4 : P=(3,2,1,4) &\iff p \equiv 11\pmod{16} \\
R_4 : P=(2,3,4,1) &\iff p \equiv 13\pmod{16} \\
R_4 : P=(4,3,2,1) &\iff p \equiv 15\pmod{16} \\

Interestingly, not all permutations of four shapes are possible to appear in this region. That is, we can see that only 8 out of theoretical 24=4! appear. Also notice that we alternate even and odd numbers ("short" and "long" shapes) in all of these permutations.

(s\ge 5)

Unexpectedly, unlike R_3 and R_4 that appear only once (on each mirrored side), we can say that the R_5 appears twice (on each mirrored side). But, in each of those two mirrored pairs we have different parabolic shapes. Therefore, we can also say that there are two different R_5 regions.

So far, I've been manually tracing pixels in many consecutive primes to observe these regions and their permutations. Can we characterize these regions more efficiently?

I've examined the R_5 region(s) and found that c_5=50, which gives 20 possible permutations. I've also examined R_6 and found c_6=36, which gives 12 possible permutations.

Notice that a pattern emerges here. The c_s appears to follow the sequence:

c_s=2, 4, 18, 16, 50, 36,\dots

Which corresponds to only one OEIS sequence, namely the A137933(s) = c_s = \DeclareMathOperator{\lcm}{lcm}\lcm(s^2,2). If this is true, then the number of possible permutations is s\phi(s), which is A002618.

In other words, it appears that only the permutations (of "parabolic" shapes \{1, 2, 3, \dots, s\}) that are "in arithmetic progressions modulo s" can exist within the R_s region!

Can we prove that this holds for all s?

Beside finding how the individual parabolic shapes permute within corresponding regions, we also need to find their exact locations within those regions, to complete the characterization.

Partition of pixels (entries) into regions R_s

An interesting question that we can ask is, can we color every pixel (entry) (x,y) such that it belongs to exactly one (or two neighbouring) regions R_s?

That is, (x,y) should belong to a region if it is a part of a shape that is being permuted in that region, or if it "extends" one of those shapes up to the border of a neighbouring region.

I've decided to color R_1,R_2,R_3,R_4 with \color{purple}{\text{purple}},\color{red}{\text{red}},\color{green}{\text{green}},\color{blue}{\text{blue}}, respectively. I'll use white to color pixels that "overlap" (could be in either region) or those that "are forming next region".

Prime numbers p=2,3,5 seem too small so we can start with p=7,11,13,17,19,23.

enter image description here

The first three regions are already visible in these small primes.

Observing the next few primes p=29,31,37,41, we see that the fourth region emerges too, but still intersects the third region at some parts.

enter image description here

It is at primes p=43,47,53 when the fourth region should be clearly visible for the first time.

enter image description here

The fifth region and beyond will appear at a bit larger primes.

If we want to be able to color larger examples, we need to first characterize the regions (answer my first question) and then we need to be able to additionally determine their exact locations within the corresponding region.

Question. 2. Can we determine locations for the parabolic shapes for given R_s region?

I've looked at R_2 (first nontrivial region), and it is not hard to see where exactly the two corresponding parabolic shapes will appear. This allowed me to come up with the parametrization of the entire pattern (matrix M_p) and is presented in the following chapter.

Pattern parametrization

The central region R_2 can be used to generate the entire matrix M_p. This is much more efficient than computing it and might shed some light on the pattern.

That is, all regions R_s emerge from the following parametrization.

Parametrization of M_p

To start, we locate the start (the "head") of the "thin" and the "thick" parabola. The starting y will be given by y=y_P for both, where the starting x=x_L of the leftmost one and the starting x=x_R of the rightmost one are:


where the "mod" takes values in \{-1,1\} as noted. To generate M_p, we start with a matrix of 0's and fill in the 1's with the following sequences, where the "mod" now takes nonnegative values:

\right), i\in\{1,2\},\\
\right), i\in\{3,4\},\\

where the starting conditions are:


where x_a,x_b\in\{x_L,x_R\} are the x's of the "head"'s of "thick","thin" parabolas, respectively.

A sequence terminates after its y coordinate leaves the [0,p) interval.

The only correction that needs to be done is that M_p(0,0)=M_p(0,p-2)=M_p(0,p-1)=0 and that M_p(0,y)=1 for y=1,2,\dots,p-3. The rest of entries M_p(x^{(i)}_n,y^{(i)}_n)=1 are correctly generated by sequences i=1,2,3,4,5,6 and n's up until the y escapes [0,p).

These sequences represent extensions of the "thick" and "thin" parabolas from R_2, that loop around the right and left edges of the image (matrix) up until the top (bottom).

As these sequences intertwine, they will produce all other regions R_s,s\ne 2. That is, all regions emerge from these sequences of pixels (entries).

Can we use this to help us predict the characterizations of regions R_s?


I would put this in the comments, but I don't have enough points.

The patterns you are seeing are Moiré patterns. From wikipedia:

In mathematics, physics, and art, a moiré pattern (/mwɑːrˈeɪ/; French: [mwaʁe]) or moiré fringes are large scale interference patterns that can be produced when an opaque ruled pattern with transparent gaps is overlaid on another similar pattern. For the moiré interference pattern to appear, the two patterns must not be completely identical in that they must be displaced, rotated, etc., or have different but similar pitch.

This is a broad topic with lots of different approaches and applications, so I encourage you to research it.

In terms of finding equations to the patterns you are seeing, Mathematica is great for this. If you don't have Mathematica, you can use Wolfram Alpha. Here is an example with a list of numbers using findsequencefunction. You can also provide a list of points (generally, wolfram alpha needs five or more points to find a sequence):

findsequencefunction[{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}, n]

Hope this helps!

Source : Link , Question Author : Vepir , Answer Author : Community

Leave a Comment