See the Mathematica notebook, which correctly renders it for any value.
Https://GitHub.com/shaunxcode/a-pattern-in-the-primes
However, for odd values of n, it does not match GCD. So it's not simply a drawing of the GCD pattern.
And when n is even, there's also a heuristic argument that there are only finitely many counterexamples; i.e. you should expect to find the pattern from your process exactly match that from just the gcd, beyond a few counterexamples: https://news.ycombinator.com/item?id=17106648
Meaning that the chance of finding a prime in these sequences of N numbers approaches one, after eliminating the cases that make primes impossible (n odd and r=2 mod 4, gcd(r,c) > 1).
Is there any deeper meaning to that, or is it simply that the probability of finding a prime in any sequence of n numbers approaches one as n increases, excluding sequences in which primes are impossible?
Thanks to comments from readers we have found that the pattern does not exactly match the GCD triangle for some values of the number of cells and rows.
This possibly makes it a more interesting finding. But it also means we can’t use GCD to render it quickly for all values.
In the code on Observable we were using GCD as a shortcut to render it because it saved time compared the earlier approach. However readers correctly pointed out that the rendering was not always correct using GCD.
Now that we know GCD doesn’t apply to all values of n, we are reverting to the original code, which generates the correct renderings for all values - but is slower - and there will be an update on Observable soon.
Meanwhile - to see the original code at work, and test it out for any value yourself, here is the Mathematica notebook code:
Https://GitHub.com/shaunxcode/a-pattern-in-the-primes
The Observable JavaScript code is being updated soon to account for this.
Join the discussion in the Telegram group as well - details below.
T = (n, k) => { return (GCD(n, k) == 1) ? 1 : 0; }
The given code doesn’t use primes, primesSet, or isPrime at all.
n = 14: fails on row 13, col 3
n = 20: fails on row 17, col 8
n = 30: fails on row 17, col 7
n = 38: fails on row 37, col 8
n = 44: fails on row 31, col 2
n = 50: fails on row 43, col 13
…
He's not claiming it holds for _all_ n, just for _many_ n.
[1095, 1108, 1121, 1134, 1147, 1160, 1173, 1186, 1199, 1212, 1225, 1238, 1251, 1264]
none of which are prime. cellToTerms(13, 14, binomialCoEfficient2, 3) in the observable gives the same list (though no such calls are made when generating the picture).
Https://GitHub.com/shaunxcode/a-pattern-in-the-primes
row 1, col 1: [1, 2, 3, …, 75], has primes
row 2, col 1: [76, 78, 80, …, 224], no primes
row 2, col 2: [77, 79, 81, …, 225], has primes
Then their claim that this pattern holds isn't even true; as pointed out elsewhere, and is obvious when you write out the sequence items explicitly in terms of their coordinates, any gcd!=1 cell will be red. But a gcd=1 cell need not be black, for many n.
The drawing has been updated on the blog post cited above; there was an error in the description of it, this has been clarified and the code has been updated as well
Join the Telegram group to discuss: https://t.me/joinchat/G8AnchIna2q8yn1lGHirkA
Note that Even and Odd Values of N have a very different pattern.
For example try using the values 99 and 99, and then 100 and 100, in this HTML PREVIEW VERSION:
https://htmlpreview.github.io/?https://github.com/acmegeek/p...
CODE TO TRY:
Javascript https://beta.observablehq.com/@montyxcantsin/unwinding-the-u...
Mathematica https://github.com/shaunxcode/a-pattern-in-the-primes
Perl https://www.dropbox.com/s/z5tfub5geyuctex/prime-draw.pl?dl=0
EXPLANATION:
In short, actually there are some curious patterns in this, and they are not simply equivalent to OEIS A054521 (as we, and others, initially thought they were).
For even values of n, they seem to approach the OEIS A054521 sequence as n increases. But for odd values the pattern is different and OEIS A054521 doesn't describe it at all. More discussion of this on the Telegram group...
For the benefit of others who may be similarly mystified, here's an elaboration. First, in vague terms, there are two things going on here:
1. If you colour a triangular grid according to the gcd of the coordinates, then you get a pretty picture (this is itself interesting IMO), and
2. If you colour a triangular grid according to a particular function involving prime numbers, then the picture will often (NOT ALWAYS!), and in many places (NOT EVERYWHERE!) resemble the pretty picture of (1) above.
Less vaguely, here are precise definitions:
--------------------
Draw a triangle (triangular grid) where row R (for R = 1, 2, 3, ...) has R cells or "columns" (C = 1, 2, 3, ..., R). Suppose we colour the cell at co-ordinates (R, C) to be
- black, if gcd(R, C) = 1 (that is, R and C have no common factors except of course 1), and
- red, if gcd(R, C) > 1 (that is, there is some number > 1 that divides both R and C).
(This is the sequence http://oeis.org/A054521.) Then, the triangle has a pretty and regular pattern, as shown in the post. This is not too hard to prove, but is IMO itself interesting, and a nice discovery for someone playing with numbers and visualizations. So congratulations to the authors for coming up with this.
Call this Drawing 1.
--------------------
Next, fix an even integer N, and for each pair of coordinates (R, C) with 1 ≤ C ≤ R, let S(R, C) be a particular set of N integers, to be defined precisely shortly. (Roughly, in row R, we take RN numbers and assign them to the C cells in a round-robin fashion.)
For example, for N = 10, the first 3 rows have 6 cells so 60 numbers, so in row 4, the numbers 61 to 100 are distributed as follows:
S(4, 1) = {61, 65, 69, 73, 77, 81, 85, 89, 93, 97}
S(4, 2) = {62, 66, 70, 74, 78, 82, 86, 90, 94, 98}
S(4, 3) = {63, 67, 71, 75, 79, 83, 87, 91, 95, 99}
S(4, 4) = {64, 68, 72, 76, 80, 84, 88, 92, 96, 100}
In general, to define the elements of the set S(R, C), start with (R(R-1)N/2 + C), and increase by R each time, until there are N integers. In Python notation, S[(R, C)] = range(R*(R-1)*N/2 + C, R*(R+1)*N/2 + C, R)
Then, colour the cell with coordinates (R, C) with:- black, if any of the numbers in the set S(R, C) are prime, and - red, if none of the numbers in the set S(R, C) is prime.
Call this Drawing 2 (for a particular value of N).
--------------------
Now, note the following:
- when cell (R, C) in Drawing 1 is red, i.e. when gcd(R, C) > 1, then in Drawing 2, whatever the value of N, all the numbers in the set S(R, C) are divisible by that gcd, so none of them can be prime.
- when cell (R, C) in Drawing 1 is black, i.e. when gcd(R, C) = 1, then in Drawing 2, especially for larger values of N, you have a set of N integers that have no particularly forced reason to be composite, so it's rather likely that at least one of them may be a prime. (This can be made somewhat more precise using standard number-theory heuristics like the Cramer random model, but nothing that reaches the level of proof.)
So Drawing 2, which depends on the primes, is likely to resemble Drawing 1 (red in all the places where Drawing 1 has red), but with occasional additional red dots (where Drawing 1 has black) that break the nice, regular pattern. Some of these counterexamples are listed in this comment: https://news.ycombinator.com/item?id=17104624
(I haven't worked out the details but I think we can prove things like that there will be infinitely many of these counterexamples if we extend the triangle far enough, but also that the ratio (asymptotic density) of these counterexamples will be small. So "the pattern will kind of hold" is about all we can say.)
--------------------
What does all this tell us about primes? Unfortunately, not much it appears. To the extent that there is a nice pattern in the picture, it comes from the regular properties of the gcd function. And if one considers the deviations from the regular pattern as what's interesting, then it tells us things only in a diffuse way: whereas with Ulam's spiral one sees individual primes, here what one sees visually is cases where in a particular set of N numbers none of them happened to be prime.
Still, the pictures are pretty to look at, and that counts for something. :-)
More specifically, it’s a drawing of OEIS A054521 (black if gcd(row, col) == 1, red otherwise), not of the parallax compressed primes. The two drawings do not match as claimed. The first place where they differ is row 9, column 1, which is drawn as black even though none of 217, 226, 235, 244, 253, 262 are prime.
It’s clear that gcd(row, col) == 1 is a necessary condition for there to be any primes in that cell (which consists of the numbers col + 3row² − 3row, col + 3row² − 2row, col + 3row² − row, col + 3row², col + 3row² + row, col + 3row² + 2row), but it’s not sufficient. There’s no way it could be sufficient, because there are only constantly many (six) numbers tested in every cell, but the asymptotic density of the primes goes to 0 and the asymptotic density of A054521 goes to 6/π².