Prime Number Grid

susam.net

291 points by todsacerdoti 2 days ago


susam - 2 days 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.

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:

  3317044064679887385961783
  3317044064679887385961801
  3317044064679887385961813
I hope this is fun for you too!
mg - 2 days 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:

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:

    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.
willvarfar - 2 days ago

Perhaps explore plotting the Ulam spiral too? https://en.wikipedia.org/wiki/Ulam_spiral

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!?

throw310822 - 2 days ago

Kind of surprising, my intuitive idea of primes is that they become rarer much faster, while there's really a ton of them.

rmrfchik - 2 days ago

Nice patterns are reveals when cols is prime.

ilmenit - 2 days ago

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.

haar - 2 days ago

Setting it to 1, 7, 100 looks like a ticker tape of constellations (like Stargate Chevrons) :D

AmazingTurtle - 2 days ago

https://susam.net/primegrid.html#1-200-330

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

ragmondo - 2 days ago

Here's a weird relationship between consecutive primes that I discovered while bored trying some python...

Take the last digit (in base 10) of consecutive primes. Now ignore 2 and 5 as .. well they only occur once, and look at the mapping between 1->3, 1->5, 1->7, 1->9 ... 3->1 etc etc..

You would think that they would pretty much all be equal, I mean primes are "random" right?

WRONG!

There are statistically significant differences in those edges, and no-one knows why.

dfee - 2 days ago

My intuition was that there were even fewer primes and there was a greater rate of decrease as the numbers got bigger – but it looks like there are so many! Even at [1, 10,000, 10,000] it seems pretty dense near the bottom, though perhaps less dense.

Apparently the average gap between primes is `log(n)`: https://en.wikipedia.org/wiki/Prime_number_theorem

vintermann - 2 days 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.

themafia - 2 days ago

I'd like it if I could set "columns" to be an expression. That expression could be something like "1.1415 * row". That'd be neat.

martinclayton - 2 days 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.

dirkc - 2 days 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

physix - 2 days ago

https://news.ycombinator.com/item?id=44888548

kitd - 2 days ago

Really interesting, stepping up and down the "cols" number, seeing the dots align at certain key points, especially at multiples of 30.

mickeyp - 2 days ago

I really love susam's blog posts and curiosity. I highly recommend that people check out his site for more of his insights.

cuber_messenger - 2 days ago

Decreasing the number of columns looks like rotating some noisy parallel lines counterclockwise. Very fun.

butlike - 2 days ago

Wonder what this would output if run through a FORTRAN system with a few punch cards.

stillthat - a day ago

no idea why or how, but are there attempts at implementing all that crazy math stuff like golden ratio, prime grids, fractals and what not into the game of life, Lenia?

fendy3002 - 2 days ago

it's interesting that for 6 cols only the 1st and 5th column has value, ignoring first row.

courtcircuits - 2 days ago

Gonna make API calls to that next time I need to generate an Elgamal key pair

agnishom - 2 days ago

Since this is in a grid, how about visualizing Gaussian primes instead?

vim-guru - 2 days ago

This works surprisingly well for logo design. Cool concept

y42 - 2 days ago

shameless plug

https://primes.nickyreinert.de

(desktop recommended)

quijoteuniv - 2 days ago

Wow! I see the pattern now! ;) … nice work

anthk - 2 days 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.

dev0p - 2 days ago

Editable size pls? I wonder if this could be visualized in 3 dimensions...

GistNoesis - 2 days ago

The problem with this visualization is that the pattern we see are meaningless.

It's making me thing of sieving, like in Sieve of Eratosthenes. But we have progressed a lot since.

What's nice about primes are the abstract ideas they generate, and the properties they have.

Primes connect numbers together. It allows you to form "groups" ( https://en.wikipedia.org/wiki/Group_(mathematics) ) of elements which don't have "subgroups". They are the sizes of the groups which don't have subgroups. (https://en.wikipedia.org/wiki/Cauchy%27s_theorem_(group_theo... )

If you want to know more about primes, you can look at the factorization of numbers problem.

You need to wrap your head around Euclid's algorithm (300 BC but it still matters a lot), this guy stumbled onto something very deep.

Prime numbers color other numbers. Once you pick a prime, number smaller that it can be colored as either "square" or "not square" (in the cyclic group defined by the prime). That's something figured Euler with https://en.wikipedia.org/wiki/Euler%27s_criterion .

It's one angle of attack to the factorization problem. This breaking of symmetry has been exploited in https://en.wikipedia.org/wiki/Quadratic_sieve .

But that's not the algorithm, I want to speak of today. I'd rather speak of https://en.wikipedia.org/wiki/Lenstra_elliptic-curve_factori... . The principle is simple, build a mathematical construct (elliptic curve) using the number which is not a prime and you want to factorize, and treat it as if it was a prime. Then you watch the construct crumble, trace the bug, and you have your factors.

If you are more mathematically proficient, you can also have a look at the General Number Field Sieve, but it's much harder.

To conclude I'd like to give a final nugget for the road : https://en.wikipedia.org/wiki/Montgomery_modular_multiplicat... a nice trick around division.

- 2 days ago
[deleted]
elitegolfhub - 2 days ago

[dead]