I did recently also a tool for prime numbers visualization:
https://ilmenit.github.io/prime-fold/
It's not only for visualization but also discovering of mathematical functions that generate or embed prime numbers using evolutionary algorithms and fitness functions. It has two modes:
PrimeFold Mode (2D Embedding): Enter or evolve two functions, f_x(n) and f_y(n), to map numbers to 2D points. Primes and composites are visualized differently. This mode helps you discover spatial patterns and structures unique to primes. Example: f_x(n) = n, f_y(n) = n^2 or simply n, n^2.
PrimeGen Mode (1D Generation): Enter or evolve a single function, f(n), to generate numbers. The app visualizes which outputs are prime and how many unique primes are produced. Example: f(n) = 2*n + 1.
mg · 46m ago
Here is a strange one:
You look at integers in "packs" of 100. If a pack contains a prime number, you color it black, otherwise you color it red.
The first pack contains 100 consecutive integers. The second every second integer. The third every third integer and so on.
Every pack starts where the last one stopped.
On the first row, you draw 1 pack, on the second 2, on the third 3 and so on:
If you want to compare it to a random distribution, you can change this line:
if (isPrime(myNum)) return 1;
To this:
if (Math.random()>0.99) return 1;
Very different. I wonder where the symmetry and all the other properties of the pattern come from when using primes.
BobbyTables2 · 21m ago
Almost looks like Klingon!
susam · 4h ago
Hello! I wrote this simple prime number grid visualiser last night, just for fun. It is inspired by the "Show HN" post https://news.ycombinator.com/item?id=44888548 that I stumbled upon a few days ago.
My tool uses the Miller-Rabin primality test with prime bases drawn from https://oeis.org/A014233 to determine whether a number is prime. This allows it to handle numbers up to 3317044064679887385961980.
Great visualization! Can you please add a on-mouse-over so when i hover my mouse over a dot i can see the prime number it represents?
Would we see new patterns emerge if the number of columns increases per row by X (X being constant or perhaps prime numbers ;-) )?
susam · 2h ago
Adding mouseover text to every prime number slows down rendering on large grids (say, with a million or more numbers). So mouseover text is available as an optional feature. You can toggle it using the 't' button at the top: click once to enable the text, and click again to disable it.
Given that it's a preformatted text with a known number of columns, the number below the mouse pointer can be computed using the mouse position, character width and line height.
davedx · 2h ago
I think another interesting feature would be if you could change the number base to 16 or some other base, I'm really curious if the pattern would change.
teytra · 45m ago
Set columns to 6, and the pattern is changed in an "interesting" way.
All primes are n*6 +/- 1 (after the primes 2 and 3 that are "special").
lblume · 2h ago
Numbers are prime irrespective of base.
xandrius · 2h ago
So it's already supported!
camillomiller · 4h ago
It's so cool actually!
You actually sent me on a rabbit hole trying to visually look for patterns :D
But I guess the discretionality with which you can organize in rows and columns makes mine quite a pointless excercise :D
jona-f · 4h ago
If you select 30, 60 or 90 columns you get the clearest patterns. It kinda seems that the more divisors the number of columns has, the clearer the vertical clusters are. And somehow 30, 60 and 90 stand out. Number theory is so weird. I expected more randomness.
dgacmu · 50m ago
If you can do 210 you'll see even more.
Any primorial will give you the strongest patterns. (Primorials are the products of the first N primes, so 2, 6, 30, 210, etc.)
susam · 4h ago
The reason vertical clusters appear in these examples is that all your chosen numbers are multiples of 6. A prime number greater than 3 leaves a remainder of either 1 or 5 when divided by 6. In other words:
For all primes p greater than 3, p ≡ ±1 (mod 6).
Therefore, when the total number of columns is a multiple of 6, all primes except 2 fall into the same columns, namely 1, 5, 7, 11, 13, 17 and so on.
jacobtomlinson · 3h ago
I just set the column width to 6 to verify this for myself. What a neat tool!
Daub · 2h ago
Very cool. Go from 30 to 31 to see this ‘pattern’ twist in on itself.
Of course the pressing question is, if this is the start field for a Conway game-of-life, do any interesting patterns evolve?
It would be fun to brute-force a few starting grid sizes and seeing how long the game continues. Games that last more than a few steps can be set aside for human evaluation.
Because if it turns out that some particular smallish grid or spiral of primes causes something interesting to happen in game-of-life, then you can imagine HN melting down!?
Seconding the Ulam spiral. My first thought was "why can't I see the diagonals?" because I expected it to be the Ulam spiral.
haar · 7m ago
Setting it to 1, 7, 100 looks like a ticker tape of constellations (like Stargate Chevrons) :D
rmrfchik · 4h ago
Nice patterns are reveals when cols is prime.
ethan_smith · 4h ago
This happens because when columns = p (prime), numbers in each column share the same remainder mod p, creating visible diagonal patterns as multiples of p are eliminated from primality.
spongebobism · 1h ago
When the col is seven, there are a lot of diagonals going from top right to bottom left. When col is five, from top left to bottom right. Are runs of consecutive sexy primes also this frequent for larger numbers, or does that pattern break down at some point?
madcaptenor · 1h ago
Not so much that cols is prime as that cols+1 or cols-1 has lots of factors - see for example 25 or 91 or 119. But it does seem like numbers adjacent to primes have a lot of factors.
amne · 1h ago
I find the patterns from cols % 30 == 0 very interesting (30,60,90,120, etc.) .. just straight vertical lines.
And if you go up or down by one (119 or 121) they appear to "rotate" left or right.
Very cool viz tool.
scotty79 · 3h ago
Almost all of these patterns that you see don't really come from primes. If you display numbers not divisible by first 100 natural numbers you get pretty much the same picture.
In fact, according to the celebrated prime number theorem, the number of primes less than or equal to n is asymptotic to n/log n, which means the density of primes near n is asymptotic to 1/log n.
> In fact, according to the celebrated prime number theorem, the number of primes less than or equal to n is asymptotic to n/log n, which means the density of primes near n is asymptotic to 1/log n.
When written down as a string of digits, log n is another way to say 'proportional to the number of digits'.
The number of digits grows fairly slowly, thus also the 'probability' of a number being prime drops very slowly.
That’s what ‘everybody’ thinks. I think that’s from reading so much about them being hard to find. They aren’t hard to find, though, it’s (as far as we know) hard to recognize integers as being primes.
There are more prime numbers than there are squares of integers.
knome · 22s ago
>There are more prime numbers than there are squares of integers.
all integers have a square, while not all integers are prime.
in any given span, you'll see more primes than squares, however.
more dense?
throw310822 · 3h ago
> I think that’s from reading so much about them being hard to find
More from the fact that each prime number makes all its multiples non-prime, so you'd expect this would accumulate quickly in making primes an increasingly rare find. Which is the case, but slower than intuition suggests.
eru · 3h ago
> They aren’t hard to find, though, it’s (as far as we know) hard to recognize integers as being primes.
Depends on what you mean by 'hard'. It's easy in the sense that we have algorithms to decide whether a number is prime or composite that take time polynomial in the space it takes to write down your number (ie polynomial in log n).
vintermann · 3h ago
Fun to see that prime numbers of columns causes stripy patterns, and some stripe to the left and some stripe to the right. Probably some deep number theoretic reason for that.
aldonius · 10m ago
You'll find that when the number of columns is a multiple of 6 you'll get obvious columns in the dots, and if it's +1 or -1 modulo 6 the columns become diagonal stripes (the process sort of continues for ±2 and at ±3 it's pretty broken down).
It's a fairly straightforward number theory result that every prime > 3 is congruent to ±1 modulo 6 so that's probably what you're seeing.
(Can't be +2 or +4 because that's divisible by 2, can't be +3 because that's divisible by 3, leaving +1 and +5 aka -1.)
dirkc · 1h ago
Nice visualization! 2 suggestions if I can nitpick :)
1. Make the grid render as a square when rows == columns
2. Default to the largest number of rows and columns that would still avoid page scrolling
cuber_messenger · 2h ago
Decreasing the number of columns looks like rotating some noisy parallel lines counterclockwise. Very fun.
courtcircuits · 1h ago
Gonna make API calls to that next time I need to generate an Elgamal key pair
martinclayton · 3h ago
Hours of fun (stimulation?) to be had...
Try these shapes: 100x113, then 100x114, then 100x115, the "patterns" swing from slant down, to vertical, to slant up.
I'd love this (even more) with some animation and colo(u)r options.
susam · 3h ago
This was just a quick experiment I put together last night in my free time, so the tool is quite bare bones. If you're on a desktop browser and don't mind opening the developer tools console, you can run this little snippet to animate the grid:
Really interesting, stepping up and down the "cols" number, seeing the dots align at certain key points, especially at multiples of 30.
krige · 3h ago
There's also a cool effect where incrementing columns by one has the dots align diagonally, and then vertically multiple times.
fendy3002 · 2h ago
it's interesting that for 6 cols only the 1st and 5th column has value, ignoring first row.
seanalltogether · 1h ago
Yeah I was gonna say the same thing. So in a base-6 counting system primes must be very intuitive to spot. Although also expanding it out to base-12 shows the primes always fall into 4 specific rows.
mickeyp · 4h ago
I really love susam's blog posts and curiosity. I highly recommend that people check out his site for more of his insights.
nyc111 · 2h ago
I tried but his pages do not have links to a home page or other posts
This works surprisingly well for logo design. Cool concept
agnishom · 4h ago
Since this is in a grid, how about visualizing Gaussian primes instead?
quijoteuniv · 3h ago
Wow! I see the pattern now! ;) … nice work
anthk · 2h ago
I'd love this but in SDL+GL allowing to scale up and down an image.
Or better, a command to write an XBM/XPM image and then I'd convert it to any format I like.
wmanley · 2h ago
Scaling is already supported - try Ctrl+Mouse Wheel or pinch to zoom on mobile. It also supports writing an image with the keyboard shortcut "Print Screen".
dev0p · 3h ago
Editable size pls? I wonder if this could be visualized in 3 dimensions...
You look at integers in "packs" of 100. If a pack contains a prime number, you color it black, otherwise you color it red.
The first pack contains 100 consecutive integers. The second every second integer. The third every third integer and so on.
Every pack starts where the last one stopped.
On the first row, you draw 1 pack, on the second 2, on the third 3 and so on:
https://www.gibney.org/parallax_primes
It looks like hieroglyphs from another universe.
I'm still not sure why it looks the way it looks.
If you want to compare it to a random distribution, you can change this line:
To this: Very different. I wonder where the symmetry and all the other properties of the pattern come from when using primes.My tool uses the Miller-Rabin primality test with prime bases drawn from https://oeis.org/A014233 to determine whether a number is prime. This allows it to handle numbers up to 3317044064679887385961980.
For example, https://susam.net/primegrid.html#3317044064679887385961781-2... shows the upper limit of the numbers this tool can check. The three circles displayed there represent the following prime numbers:
I hope this is fun for you too!Would we see new patterns emerge if the number of columns increases per row by X (X being constant or perhaps prime numbers ;-) )?
Here's an idea on how to implement it without the slowdown: https://jsfiddle.net/qpswztj8/
Given that it's a preformatted text with a known number of columns, the number below the mouse pointer can be computed using the mouse position, character width and line height.
All primes are n*6 +/- 1 (after the primes 2 and 3 that are "special").
You actually sent me on a rabbit hole trying to visually look for patterns :D But I guess the discretionality with which you can organize in rows and columns makes mine quite a pointless excercise :D
Any primorial will give you the strongest patterns. (Primorials are the products of the first N primes, so 2, 6, 30, 210, etc.)
For all primes p greater than 3, p ≡ ±1 (mod 6).
Therefore, when the total number of columns is a multiple of 6, all primes except 2 fall into the same columns, namely 1, 5, 7, 11, 13, 17 and so on.
Of course the pressing question is, if this is the start field for a Conway game-of-life, do any interesting patterns evolve?
It would be fun to brute-force a few starting grid sizes and seeing how long the game continues. Games that last more than a few steps can be set aside for human evaluation.
Because if it turns out that some particular smallish grid or spiral of primes causes something interesting to happen in game-of-life, then you can imagine HN melting down!?
And if you go up or down by one (119 or 121) they appear to "rotate" left or right.
Very cool viz tool.
zoom out, then play around with cols +/-1 and observe the pattern change. I observe the pattern from -7 to +5; same on #1-200-420
In fact, according to the celebrated prime number theorem, the number of primes less than or equal to n is asymptotic to n/log n, which means the density of primes near n is asymptotic to 1/log n.
I have a small section about this at https://susam.net/journey-to-prime-number-theorem.html#prime... if you want to read more about this.
See also: https://en.wikipedia.org/wiki/Prime_number_theorem
> In fact, according to the celebrated prime number theorem, the number of primes less than or equal to n is asymptotic to n/log n, which means the density of primes near n is asymptotic to 1/log n.
When written down as a string of digits, log n is another way to say 'proportional to the number of digits'.
The number of digits grows fairly slowly, thus also the 'probability' of a number being prime drops very slowly.
https://en.m.wikipedia.org/wiki/Prime_number_theorem
There are more prime numbers than there are squares of integers.
all integers have a square, while not all integers are prime.
in any given span, you'll see more primes than squares, however.
more dense?
More from the fact that each prime number makes all its multiples non-prime, so you'd expect this would accumulate quickly in making primes an increasingly rare find. Which is the case, but slower than intuition suggests.
Depends on what you mean by 'hard'. It's easy in the sense that we have algorithms to decide whether a number is prime or composite that take time polynomial in the space it takes to write down your number (ie polynomial in log n).
It's a fairly straightforward number theory result that every prime > 3 is congruent to ±1 modulo 6 so that's probably what you're seeing. (Can't be +2 or +4 because that's divisible by 2, can't be +3 because that's divisible by 3, leaving +1 and +5 aka -1.)
1. Make the grid render as a square when rows == columns
2. Default to the largest number of rows and columns that would still avoid page scrolling
Try these shapes: 100x113, then 100x114, then 100x115, the "patterns" swing from slant down, to vertical, to slant up.
I'd love this (even more) with some animation and colo(u)r options.