top of page

Prime pattern ?!

  • Writer: Carlos 青木 Thomaz
    Carlos 青木 Thomaz
  • Apr 21, 2020
  • 3 min read

After watching some videos and reading some nice articles, I've bumped into a set of curiosities regarding prime numbers, Pi, golden ratio and others. I've been coding few examples and other stuff (nothing of them anything that you won't find at least few hundreds other samples on internet), but for sake of my understanding and fun I've decided to do it myself. OK, I have to be honest, there are more than just do it for sake of killing time. Couple months ago I've realized that even very simple coding would provide a lot of variants and insights, so I've decided to give a try with interesting problems.

OK, what this is about? Primes has no form or shape any pattern that could describe them, such as a sequence or magic formula. It is a definition of a number that is only divisible for 1 and for itself. Well, this is what we know...

Back into the 30s a polish mathematician called Stanislaw Ulam migrated to US. One of his line of research was about number theory while working for the Manhattan project as well, apparently at Los Alamos. He then invented something called Ulam's Spiral which doesn't seem to be in his biggest achievement, by the way. He worked with famous names such as von Newmann and Fermi on different nuclear projects and different computers since ENIAC. He taught at different universities including the School of Mathematic at University of Colorado in Boulder - CO.

Anyways, the Ulam's spiral is nothing less than a quadratic matrix with a sequence of positive integers in the following schema:


UlamMatrix =     [17    16    15    14   13                   
                  18    5     4     3    12                   
                  19    6     1     2    11                   
                  20    7     8     9    10]...

The matrix, of course, can be as big as it needs. This is only a 4x4 representation.

Ulam found out that marking the prime numbers using this spiral matrix would produce a semi-random patter. Different from what is trivial to think of, the prime numbers on Ulam's spiral seem to be somehow organized.


UlamMatrix =     [17    16    15    14   13                   
                  18    5     4     3    12                   
                  19    6     1     2    11                   
                  20    7     8     9    10]...

This is difficult to observe in a small matrix, but if you code a program (what I did) that shows a large grid with Ulam's spiral, you may notice some sort of organization along some diagonals or lines.


Then, if you manage to count the the number of primes per diagonal or lines, you may realize there are lines with a lot heavier density in terms of prime numbers than others. This still a conjecture because it has never been proved.

I thought this to be very interesting. For several reasons. Back to my first point, this simple exercise, if done well, would make you think about:

- How to code the spiral itself that requires a bit of thinking

- Best algorithm to find if a number is prime or not

- Efficient plot algorithm (which I really didn't think because was too late)



One thing I realized this is extremely easy to parallelize, since there's no mathematical boundaries that prevents you to. I've decided to write in Python, but if I have done in GO (golang) I think I'd be able to use concurrency pretty well in this exercise. One variant I'm thinking is, instead to check if each number is prime or not, I was wondering if I could create a Sieve of Eratosthenes (which I've implemented) to create a bitmap matrix. I think this would be a lot better, efficiency wise. Anyways, we let this discussion to another quarantine night..


Comments


  • facebook
  • linkedin
  • instagram

©2020 by Carlos A. 青木 Thomaz.

bottom of page