6 ms·
Prime Number Grid
- kitd 1y agoReally interesting, stepping up and down the "cols" number, seeing the dots align at certain key points, especially at multiples of 30.
- krige 1y agoThere's also a cool effect where incrementing columns by one has the dots align diagonally, and then vertically multiple times.
- susam 1y agoHello! 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 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 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-20-10 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!
- camillomiller 1y agoIt'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 1y agoIf 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.
- susam 1y agoThe 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 1y agoI just set the column width to 6 to verify this for myself. What a neat tool!
- jona-f 1y agoOh yes, thanks!
- ainiriand 1y agoGo for 258 and be ready to get your mind blown.
- calrain 1y ago210 columns is stripes
- Daub 1y agoVery cool. Go from 30 to 31 to see this ‘pattern’ twist in on itself.
- dgacmu 1y agoIf 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.)
- Tepix 1y agoGreat 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 1y agoAdding 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.
- Tepix 1y agoThanks, that was fast! Here's an idea on how to implement it without the slowdown: https://jsfiddle.net/qpswztj8/ 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.
- davedx 1y agoI 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.
- lblume 1y agoNumbers are prime irrespective of base.
- xandrius 1y agoSo it's already supported!
- ForOldHack 1y agoSince I seriously doubt that these numbers were checked in decimal, I would be led to believe base-2 is working and working well, as well as all other even bases. Ood bases would be fun,but much slower. I tried odd number of rows and prime number of rows. All very interesting.
- teytra 1y agoSet 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").
- jalk 1y agoSet cols to anything divisible by 6, to get the same kind of "stacks" with more cols (i.e. 90)
- susam 1y 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. Whether a number is prime has nothing to do with the base we use to write it. Changing the base wouldn't affect the visualisation at all. A number is either prime or not regardless of base. Since this grid only marks prime positions with circles, the pattern would look exactly the same. In fact, you can already imagine the numbers in any base you like while looking at the visualisation.
- reb 1y agoThank you for making and sharing this! It's fun to quickly increment the column counter and spot repeating patterns over time — little spiral movements, big swinging lines. Growing up I loved math's logic puzzle elements, but it got tough when presentation of the subject became more abstract in late high school and college. Visualization tools like this would have gone a long way toward making the concepts concrete and keeping me curious about the relationships behind the symbols.
- rmrfchik 1y agoNice patterns are reveals when cols is prime.
- ethan_smith 1y agoThis 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.
- scotty79 1y agoAlmost 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.
- spongebobism 1y agoWhen 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?
- amne 1y agoI 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.
- madcaptenor 1y agoNot 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.
- Sharlin 1y agoThe more factors an (even) number n has, the more likely it is that n+-1 is prime because those numbers cannot have any of the factors of n as factors. At the same time it is impossible that n+-2 or 4 are prime and unlikely that n+-3 is prime because 3 is likely to be a factor of n. And if additionally 5 is a factor, the primeless gap is even wider. So the primes stand out.
- agnishom 1y agoSince this is in a grid, how about visualizing Gaussian primes instead?
- throw310822 1y agoKind of surprising, my intuitive idea of primes is that they become rarer much faster, while there's really a ton of them.
- leric 1y ago[dead]
- susam 1y agoThey indeed do become rarer. Plotting all the primes in a single row makes this apparent, like so: https://susam.net/primegrid.html#1-1-1000000 https://susam.net/primegrid.html#1-1-1000000 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-number-theorem 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 https://en.wikipedia.org/wiki/Prime_number_theorem
- eru 1y agoYes. > 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.
- kristopolous 1y agoThis is a very well researched topic https://en.m.wikipedia.org/wiki/Prime_number_theorem https://en.m.wikipedia.org/wiki/Prime_number_theorem
- Someone 1y agoThat’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.
- mickeyp 1y agoI really love susam's blog posts and curiosity. I highly recommend that people check out his site for more of his insights.
- nyc111 1y agoI tried but his pages do not have links to a home page or other posts
- genezeta 1y agoThere's this https://susam.net/pages.html https://susam.net/pages.html for your convenience. (Also this https://susam.net/links.html https://susam.net/links.html maybe a bit more organised.)
- susam 1y agoThank you for the kind words, Mickey! Your website too is a treasure trove of excellent information, especially for Emacs users like me!
- vim-guru 1y agoThis works surprisingly well for logo design. Cool concept
- martinclayton 1y agoHours 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 1y agoThis 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: cols.value = 1n; setInterval(() => {cols.value++; readInput()}, 250);
- AnotherGoodName 1y agoThis is also basically the most trivial proof that primes are infinite. If you think you've discovered all the primes, just multiply all those primes together and add or subtract 1. You now have a new number that shares no factors with those primes.
- quijoteuniv 1y agoWow! I see the pattern now! ;) … nice work
- dev0p 1y agoEditable size pls? I wonder if this could be visualized in 3 dimensions...
- vintermann 1y agoFun 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 1y agoYou'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.)
- fendy3002 1y agoit's interesting that for 6 cols only the 1st and 5th column has value, ignoring first row.
- seanalltogether 1y agoYeah 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.
- madcaptenor 1y agoIt's similar to how in base 10 all primes must have last digit 1, 3, 7, or 9. But it woks slightly better in base 6 because fewer numbers are candidates (2/6 ~ 33% instead of 4/10 = 40%)
- AnotherGoodName 1y agoYep and you can also just keep going with this to get to the Prime Number Theorem. If you just consider odd numbers you know that at best only half of numbers can be prime. We've ruled out 1/2 of numbers. If you then multiply 2 x 3 to get 6 you can state all prime numbers above 6 are of the form 6n + [1 or 5], everything else is a multiple of 2 or 3. We've now ruled out 1/3 more numbers in that remaining half we already ruled out above. Leaving 1/2 x 2/3 = 1/3 numbers possibly being prime (you could write this in a non-simplified form as 2/6 to match the count above). If you then multiply 2 x 3 x 5 to get 30 you can state that all numbers above 30 are of the form 30n + [1,7,11,13,17,19,23,29]. The rest are multiples of 2,3 or 5. You've now ruled out another 1/5 of numbers from that remaining 1/3 above. Leaving 1/3 x 4/5 = 4/15 numbers possibly being prime (or 8/30 if you don't simplify the fraction to more clearly match what we counted above). If you continue this you have a series that's multiplicative_sum( 1 - 1/p) of all primes so far. This function is called Euler's product formula and is the inverse of the famous Riemann Zeta Function (1/ζ(s)). This series converges to the Prime counting function https://en.wikipedia.org/wiki/Prime_number_theorem#Non-vanishing_on_Re(s)_=_1 https://en.wikipedia.org/wiki/Prime_number_theorem#Non-vanis... which you can intuitively understand from what i've written above. Fwiw these patterns in prime numbers, or more specifically the gaps where numbers can't possibly be prime, are extremely well understood. They were first documented by Erasthosenes in BC times who used the above to quickly find new large prime numbers. While it's fun to look at patterns in primes and any enthusiasm should be encouraged i will take a moment to point out that mathematicians occasionally deal with lay people who think they've stumbled on some revelatory new thing by observing these well known patterns in primes. There's a myth that 'there's no patterns in primes'. But... that isn't true at all. We know there's patterns. It's the basis for prime number theory. It's been known for a few thousand years now.
- anthk 1y agoI'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 1y agoScaling 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".
- willvarfar 1y agoPerhaps explore plotting the Ulam spiral too? https://en.wikipedia.org/wiki/Ulam_spiral 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!?
- vincnetas 1y agohttps://www.alpertron.com.ar/ULAM.HTM https://www.alpertron.com.ar/ULAM.HTM
- okokwhatever 1y agoThe good old internet. I miss it.
- madcaptenor 1y agoSeconding the Ulam spiral. My first thought was "why can't I see the diagonals?" because I expected it to be the Ulam spiral.
- BrainBacon 1y agoNot exactly the same, but I made this Ulam spiral generator more than a decade ago. https://embed.plnkr.co/mdZX6C/ https://embed.plnkr.co/mdZX6C/ It isn't just doing primes though, instead the size of the dot generated is dependent on the number of even divisors for the number at that position.
- cuber_messenger 1y agoDecreasing the number of columns looks like rotating some noisy parallel lines counterclockwise. Very fun.
- courtcircuits 1y agoGonna make API calls to that next time I need to generate an Elgamal key pair
- dirkc 1y agoNice 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
- elitegolfhub 1y ago[dead]
- AmazingTurtle 1y agohttps://susam.net/primegrid.html#1-200-330 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
- mg 1y agoHere 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 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.
- BobbyTables2 1y agoAlmost looks like Klingon!
- pinoy420 1y agoIt looks the way it does because we like to see patterns even where there are none. E.g. you see a number 696969 and this seems more significant than 482649 for whatever reason
- polivier 1y agoAre you talking about the patterns found in the linked website of the parent comment? Because there clear patterns there.
- rbongers 1y agoPrime numbers are a pattern; take the natural numbers - starting after 2, exclude every number that isn't 2, starting after 3, exclude every number that isn't 3, etc. It repeats like this predictably. Even though it changes, the way in which it changes is also predictable. Their repetition and predictability make prime numbers a pattern. Out of the fundamental pattern of prime numbers, higher-level patterns also appear, and studying these patterns is a whole branch of math. You can find all kinds of visualizations of these patterns, including ones linked in this thread. It's not that you're seeing a pattern that's not there, it's that you're seeing a pattern that gradually becomes infinitely complex.
- haar 1y agoSetting it to 1, 7, 100 looks like a ticker tape of constellations (like Stargate Chevrons) :D
- ilmenit 1y agoI did recently also a tool for prime numbers visualization: https://ilmenit.github.io/prime-fold/ 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.
- y42 1y agoshameless plug https://primes.nickyreinert.de https://primes.nickyreinert.de (desktop recommended)
- GistNoesis 1y agoThe 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) 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_theory) 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 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 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_factorization 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_multiplication https://en.wikipedia.org/wiki/Montgomery_modular_multiplicat... a nice trick around division.
- deleted 1y ago[deleted]
- dfee 1y agoMy 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 https://en.wikipedia.org/wiki/Prime_number_theorem
- physix 1y agohttps://news.ycombinator.com/item?id=44888548 https://news.ycombinator.com/item?id=44888548
- butlike 1y agoWonder what this would output if run through a FORTRAN system with a few punch cards.
- ragmondo 1y agoHere'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.
- themafia 1y agoI'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.
- stillthat 1y agono 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?