
The Ulam spiral: hidden structure among the prime numbers - ctkrohn
https://bitbucket.org/ctkrohn/ulam/wiki/Home
======
Groxx
Every time I see that thing, I want to take a huge chunk of prime numbers and
write code to visualize them in different ways as quickly as possible. How do
they look if you put them in, say, a hexagonal grid instead of a square one?
Do patterns emerge if you draw them on a Hilbert curve? A 3D Hilbert curve?
4D? Has anyone tried these? Am I crazy for wanting to? Why are the ducks
watching me?

~~~
ctkrohn
No! Do it! Fork my trivial program and put up your results.

The square is a pretty interesting place to start, though, since we already
know there's a relationship between quadratic polynomials over the naturals
and the distribution of primes. These polynomials describe lines that
(eventually) become straight.

This is definitely amateur math hour for me. I was a math major a few years
ago, but I did not study any number theory.

~~~
Groxx
I'm leaning towards making something in Ruby, as I'm more familiar with it.
Then I can throw a few dozen (hundred?) million pre-calculated primes at it,
and look for macro-scale patterns, without having to do much calculation at
all. Just plotting points.

Maybe it's time to dive deeper into Objective C and / or OpenGL. I've got a
few ideas that would be fun to try in real-time, but most of the more "fun"
programming languages have poor / slow graphics libraries, and something low
level lets you handle millions of entries without breaking a sweat.

~~~
fredoliveira
Regarding diving deeper into Obj-C/OpenGL, you could also consider prototyping
your ideas quickly using something like Quartz Composer. I don't know any
specifics on whether it'd deal properly with a large data-set, but the
learning curve is not steep at all and it might get you going quickly.

~~~
Groxx
I've seen QC, poked at it a couple times, but never in depth. Any
recommendations for resources?

Usually I'm struck by how _unbelievably awesome_ the UI is, and how scores of
similar attempts have been incomprehensibly awful. Meanwhile, Apple comes out
with QC, a fast, elegant, simple version that goes almost totally unnoticed.
Weird.

------
primodemus
Arthur C. Clarke described the prime spiral seven years before it was
discovered by Ulam in his 1956 novel 'The City and the Stars': "Jeserac sat
motionless within a whirlpool of numbers. The first thousand primes, expressed
in the binary scale that had been used for all arithmetical operations since
electronic computers were invented, marched in order before him. Endless ranks
of 1's and 0's paraded past, bringing before Jeserac's eyes the complete
sequences of all those numbers that possessed no factors except themselves and
unity. There was a mystery about the primes that had always fascinated Man,
and they held his imagination still. Jeserac was no mathematician, though
sometimes he liked to believe he was. All he could do was to search among the
infinite array of primes for special relationships and rules which more
talented men might incorporate in general laws. He could find how numbers
behaved, but he could not explain why. It was his pleasure to hack his way
through the arithmetical jungle and sometimes he discovered wonders that more
skilful explorers had missed.

He set up the matrix of all possible integers, and started his computer
stringing the primes across its surface as beads might be arranged at the
intersections of a mesh. Jeserac had done this a hundred times before and it
had never taught him anything. But he was fascinated by the way in which the
numbers he was studying were scattered, apparently according to no laws,
across the spectrum of the integers. He knew the laws of distribution that had
already been discovered, but always hoped to discover more."

~~~
rbanffy
I love the fact Clarke used the term "hack" in 1956.

~~~
mootothemax
I'd just like to double-check that you and others realise that there are
multiple definitions for the word "hack," some originating from far before the
1950s ;)

 _chop: cut with a hacking tool_

 _cut away; "he hacked his way through the forest"_

 _a mediocre and disdained writer_

etc.

[http://www.google.com/search?sourceid=chrome&ie=UTF-8...](http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=define:hack)

------
fredoliveira
I'm one of those guys who didn't necessarily pay a lot of attention to maths
in college - not that I don't see the value in it, but it is certainly not a
core interest. However, I've been slowly getting more and more into maths and
the science of primes. So this post (and the questions the Ulam spiral _asks_
) strike me at the worst of times and the best of times.

If you're at least a bit like me (no deep knowledge of maths, but growing
curiosity) I recommend checking out BBC's recent documentary on primes, called
_'The Music of the Primes'_. It'll spark your interest, and it'll make you
want to dig a little deeper.

~~~
localhost3000
if you've ever prepared for a standardized quant test like the GMAT it
immediately becomes apparent how useful even a basic understanding of primes
can be. being able to manipulate primes at even the superficial level required
(to do well) by these exams gives great insight and appreciation for the
power/beauty of prime numbers. it really opened my eyes to mathematics in
general, and i wish it were an education/perspective i'd been given as a child
rather than a young adult. (I realize the GMAT is likely anathema to this
forum so i hesitate in mentioning it, but the result of my preparation was
some surprisingly useful insight in these regards...)

------
michael_dorfman
Vi Hart has a great video which takes the Ulam spiral as its starting point:
<http://www.youtube.com/profile?user=Vihart#p/u/0/Yhlv5Aeuo_k>

If you don't know her work, you should. She's so much fun...

------
po
Any time I see research or visualizations of primes, I get nervous. I fear
that all of our online security is based on encryption and all of that is
based on the one-way nature of prime functions.

Can you imagine a world where someone discovers a way to trivially decode
every https or ssh session on the internet? I fear we are building a city on
top of the fog.

~~~
yycom
Clearly number theory research is a prohibited circumvention activity and
should be prosecuted to the fullest extent of the law.

~~~
po
You laugh today…

~~~
zitterbewegung
Yea, but number theory also allows us to devise new crypto systems... for
example take a look at curve 25519

------
guyr
Another interesting site concerning visualization of patterns in prime
numbers:

<http://www.divisorplot.com/>

<http://www.divisorplot.com/6.html> \-- the Ulam spiral

------
caf
Sidenote: This is the same Ulam of "Ulam-Teller Design" fame, the basis for
thermonuclear weapons.

~~~
zandor
On another sidenote; his autobiography "Adventures of a Mathematician", is
really worth reading.

[http://www.amazon.com/Adventures-Mathematician-S-M-
Ulam/dp/0...](http://www.amazon.com/Adventures-Mathematician-S-M-
Ulam/dp/0520071549/ref=sr_1_1?ie=UTF8&s=books&qid=1293638406&sr=1-1-catcorr)

------
CallMeV
One of my mathematics teachers used to regard prime numbers with considerable
irritation. She tried to explain to the class why there was no simple formula
to determine which numbers were primes. In the end, she gave up and moved on
to the next part of the syllabus, leaving the question unanswered. I almost
felt sorry for asking her in the first place. Almost.

If this mathematics teacher had had access to the diagram of the Ulam spiral,
however, I imagine that this alone could have provided the impetus for at
least one student - me - to have made an academic career out of mathematics.
As it is, she committed many other crimes against education, including her
infamous catchphrase "Don't bother studying any kind of pointless mathematics
that you'll never need to use at work." A catchphrase whose validity has been
refuted many times over the years, not the least with the discovery of this
diagram.

------
fendrak
Something that's always struck me as odd is the "importance" of prime numbers.
It seems so trivial that a number having only 1 and itself as common divisors
would be useful or special. Nevertheless, they're important indeed.

In other words, I'm struck by the ability of mathematics to generate such
apparent complexity from simple principles :)

~~~
alf
.. and it's only with their (relatively recent) use in cryptography that prime
numbers became "important". G.H. Hardy, one of the leading number theorist in
his era claimed that none of his work was useful, and therefore never could be
applied to good or evil. Makes you wonder what applications the future holds
for what is considered purely theoretical today.

~~~
Daniel_Newby
> .. and it's only with their (relatively recent) use in cryptography that
> prime numbers became "important".

A pair of mechanical gears with relatively prime numbers of teeth have a
longer service life: a given tooth rubs the same amount against every tooth in
the partner gear. If they are not relatively prime, the hardest tooth would
hit only a few teeth on the partner gear, wearing them out many times faster.

~~~
whatwhat
Nice example. Here's another:
<https://secure.wikimedia.org/wikipedia/en/wiki/Magicicada>

[http://www.baltimoresun.com/bal-
te.ms.cicada10may10,0,563814...](http://www.baltimoresun.com/bal-
te.ms.cicada10may10,0,5638148.story)

------
Luc
"It is a visual representation of just how little we know about the structure
of the primes"

Come on, really? It's an intriguing visualization, but the patterns (in so far
as they are real, and not an artefact of the limited size of the spiral) can
be explained with some high school math.

~~~
Panoramix
If you can explain them please enlighten us all. You will have to show that
Hardy-Littlewood's Conjecture F is true.
<http://en.wikipedia.org/wiki/Bateman%E2%80%93Horn_conjecture>

~~~
Luc
I'm not a mathematician, but I don't think you can deduce that conjecture from
the Ulam Spiral. On the other hand, you don't need this conjecture to show
e.g. 4x^2-2x+41 is rich in primes (within the limits of the picture). If I
recall, you can show the clumping arises from rewriting the primes in base 6.

EDIT: To hurry along the conversation a bit - it's entirely possible I've been
misled into thinking things are more simple than they really are. Wouldn't be
the first time...

~~~
Panoramix
Sorry if I was a bit snarky in my first reply. As far as I understand this,
you can't explain the structure of the Ulam spiral in a trivial way. You are
correct that there is a trivial part to the spiral: diagonal lines alternate
between odd and even numbers, therefore all the primes lie along diagonal
lines. However, the structure is much richer than that.

The question is why certain lines have lots of primes and not others? why is a
given polynomial so rich in primes, while other similar ones are not? That's
what some of these conjectures are trying to prove.

~~~
Someone
_diagonal lines alternate between odd and even numbers, therefore all the
primes lie along diagonal lines_

Huh? If you draw the Ulam spiral on a checkerboard, all odd numbers end up on
squares of one color and all even numbers of squares of the other color, but
that is neither necessary nor sufficient to get those diagonal streaks in the
picture.

------
jsmorph
Similar visualizations here:

    
    
      http://blog.morphism.com/2010/05/building-numbers.html
      http://blog.morphism.com/2010/07/pdfs-from-building-numbers.html
    

That stuff was generated using Mathematica.

------
mudil
What if prime numbers can actually plotted as a fractal, i.e. they have
fractal geometry? I bet they do, since fractals showing up in more and more
unexpected places in nature, physics, and math.

