# WhirlpUlam

Stanislaw Ulam (pronounced OO-lam) was an American mathematician who was doodling one day in 1963 and created what is now called the Ulam spiral. It’s a spiral of integers on a square grid with the prime squares filled in and the composite squares left empty. At the beginning it looks like this (the blue square is the integer 1, with 2 to the east, 3 to the north-east, 4 to the north, 5 to the north-west, 6 to the west, and so on):

Ulam spiral

And here’s an Ulam spiral with more integers:

Ulam spiral at higher resolution

The primes aren’t scattered at random over the spiral: they often fall into lines that are related to what are called polynomial functions, such as n2 + n + 1. To understand polynomial functions better, let’s look at how the Ulam spiral is made. Here is a text version with the primes underlined:

Here’s an animated version:

Here’s the true spiral again with 1 marked as a blue square:

Ulam spiral centred on 1

What happens when you try other numbers at the centre? Here’s 2 at the centre as a purple square, because it’s prime:

Ulam spiral centred on 2

And 3 at the centre, also purple because it’s also prime:

Ulam spiral centred on 3

And 4 at the centre, blue again because 4 = 2^2:

Ulam spiral centred on 4

And 5 at the centre, prime and purple:

Ulam spiral centred on 5

Each time the central number changes, the spiral shifts fractionally. Here’s an animation of the central number shifting from 1 to 41. If you watch, you’ll see patterns remaining stable, then breaking up as the numbers shift towards the center and disappear (the central number is purple if prime, blue if composite):

Ulam whirlpool, or WhirlpUlam

I think the animation looks like a whirlpool or whirlpUlam (prounced whirlpool-am), as numbers spiral towards the centre and disappear. You can see the whirlpUlam more clearly here:

WhirlpUlam again

Note that something interesting happens when the central number is 41. The spiral is bisected by a long line of prime squares, like this:

Ulam spiral centred on 41

The line is actually a visual representation of something David Wells wrote about in The Penguin Dictionary of Curious and Interesting Numbers (1986):

Euler discovered the excellent and famous formula x2 + x + 41, which gives prime values for x = 0 to 39.

Here are the primes generated by the formula:

41, 43, 47, 53, 61, 71, 83, 97, 113, 131, 151, 173, 197, 223, 251, 281, 313, 347, 383, 421, 461, 503, 547, 593, 641, 691, 743, 797, 853, 911, 971, 1033, 1097, 1163, 1231, 1301, 1373, 1447, 1523, 1601

You’ll see other lines appear and disappear as the whirlpUlam whirls:

Ulam spiral centred on 17

Primes in line: 17, 19, 23, 29, 37, 47, 59, 73, 89, 107, 127, 149, 173, 199, 227, 257 (n=0..15)

Ulam spiral centred on 59

Primes in line: 59, 67, 83, 107, 139, 179, 227, 283, 347, 419, 499, 587, 683, 787 (n=0..13)

Ulam spiral centred on 163

Primes in line: 163, 167, 179, 199, 227, 263, 307, 359, 419, 487, 563, 647, 739, 839, 947, 1063, 1187, 1319, 1459, 1607 (n=0..19)

Ulam spiral centred on 233

Primes in line: 233, 241, 257, 281, 313, 353, 401, 457, 521, 593, 673, 761, 857 ((n=0..12)

Ulam spiral centred on 653

Primes in line: 653, 661, 677, 701, 733, 773, 821, 877, 941, 1013, 1093, 1181, 1277, 1381, 1493, 1613, 1741, 1877 (n=0..17)

Ulam spiral centred on 409,333

Primes in line: 409,333, 409337, 409349, 409369, 409397, 409433, 409477, 409529, 409589, 409657, 409733, 409817, 409909, 410009, 410117, 410233 (n=0..15)

Some bisect the centre, some don’t, because you could say that the Ulam spiral has six diagonals, two that bisect the centre (top-left-to-bottom-right and bottom-left-to-top-right) and four that don’t. You could also call them spokes:

If you look at the integers in the spokes, you can see that they’re generated by polynomial functions in which c stands for the central number:

North-west spoke: 1, 5, 17, 37, 65, 101, 145, 197, 257, 325, 401, 485, 577, 677, 785, 901, 1025, 1157, 1297, 1445, 1601, 1765, 1937, 2117, 2305, 2501, 2705, 2917... = c + (2n)^2

South-east spoke: 1, 9, 25, 49, 81, 121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961, 1089, 1225, 1369, 1521, 1681, 1849, 2025, 2209, 2401, 2601, 2809, 3025, 3249, 3481, 3721, 3969, 4225, 4489, 4761, 5041, 5329, 5625... = c+(2n+1)^2-1

NW-SE diagonal: 1, 5, 9, 17, 25, 37, 49, 65, 81, 101, 121, 145, 169, 197, 225, 257, 289, 325, 361, 401, 441, 485, 529, 577, 625, 677, 729, 785, 841, 901, 961, 1025, 1089, 1157, 1225, 1297, 1369, 1445, 1521, 1601, 1681 = c + n^2 + 1 - (n mod 2)

North-east spoke: 1, 3, 13, 31, 57, 91, 133, 183, 241, 307, 381, 463, 553, 651, 757, 871, 993, 1123, 1261, 1407, 1561, 1723, 1893, 2071... = c + (n+1)^2 - n - 1

South-west spoke: 1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813, 931, 1057, 1191, 1333, 1483, 1641, 1807, 1981, 2163... = c + (2n)^2 + 2n

SW-NE diagonal: 1, 3, 7, 13, 21, 31, 43, 57, 73, 91, 111, 133, 157, 183, 211, 241, 273, 307, 343, 381, 421, 463, 507, 553, 601, 651, 703, 757, 813, 871, 931, 993, 1057, 1123, 1191, 1261, 1333, 1407, 1483, 1561, 1641... = c + n^2 + n

Elsewhere other-engageable:

All posts interrogating issues around the Ulam spiral

Advertisements

# Spijit

The only two digits found in all standard bases are 1 and 0. But they behave quite differently. Suppose you take the integers 1 to 100 and compare the number of 1s and 0s in the representation of each integer, n, in bases 2 to n-1. For example, 10 would look like this:

1010 in base 2
101 in base 3
22 in base 4
20 in base 5
14 in base 6
13 in base 7
12 in base 8
11 in base 9

So there are nine 1s and four 0s. If you check 1 to 100 using this all-base function, the count of 1s goes like this:

1, 1, 2, 3, 5, 5, 8, 5, 9, 9, 11, 10, 15, 12, 14, 13, 15, 12, 17, 14, 20, 19, 20, 15, 23, 19, 22, 22, 25, 24, 31, 21, 25, 24, 24, 27, 33, 27, 31, 29, 34, 29, 36, 30, 34, 35, 34, 30, 40, 33, 36, 35, 38, 34, 42, 37, 43, 40, 41, 37, 48, 39, 42, 42, 44, 43, 48, 43, 47, 46, 51, 42, 53, 44, 48, 50, 51, 50, 55, 48, 59, 55, 55, 54, 64, 57, 57, 55, 60, 57, 68, 60, 64, 63, 64, 59, 68, 58, 61, 63.

And the count of 0s goes like this:

0, 1, 0, 2, 1, 2, 0, 4, 4, 4, 2, 5, 1, 2, 2, 7, 4, 8, 4, 7, 4, 3, 1, 8, 4, 4, 6, 8, 4, 7, 1, 10, 8, 7, 7, 12, 5, 6, 5, 10, 4, 8, 2, 6, 7, 4, 2, 12, 6, 9, 7, 8, 4, 11, 6, 10, 5, 4, 2, 12, 2, 3, 5, 14, 11, 13, 7, 10, 8, 11, 5, 17, 7, 8, 10, 10, 8, 10, 4, 13, 12, 10, 8, 16, 8, 7, 7, 12, 6, 14, 6, 8, 5, 4, 4, 16, 6, 10, 11, 15.

The bigger the numbers get, the bigger the discrepancies get. Sometimes the discrepancy is dramatic. For example, suppose you represented the prime 1014719 in bases 2 to 1014718. How 0s would there be? And how many 1s? There are exactly nine zeroes:

1014719 = 11110111101110111111 in base 2 = 1220112221012 in base 3 = 40B27B in base 12 = 1509CE in base 15 = 10[670] in base 1007.

But there are 507723 ones. The same procedure applied to the next integer, 1014720, yields 126 zeroes and 507713 ones. However, there is a way to see that 1s and 0s in the all-base representation are behaving in a similar way. To do this, imagine listing the individual digits of n in bases 2 to n-1 (or just base 2, if n <= 3). When the digits aren’t individual they look like this:

1 = 1 in base 2
2 = 10 in base 2
3 = 11 in base 2
4 = 100 in base 2; 11 in base 3
5 = 101 in base 2; 12 in base 3; 11 in base 4
6 = 110 in base 2; 20 in base 3; 12 in base 4; 11 in base 5
7 = 111 in base 2; 21 in base 3; 13 in base 4; 12 in base 5; 11 in base 6
8 = 1000 in base 2; 22 in base 3; 20 in base 4; 13 in base 5; 12 in base 6; 11 in base 7
9 = 1001 in base 2; 100 in base 3; 21 in base 4; 14 in base 5; 13 in base 6; 12 in base 7; 11 in base 8
10 = 1010 in base 2; 101 in base 3; 22 in base 4; 20 in base 5; 14 in base 6; 13 in base 7; 12 in base 8; 11 in base 9

So the list would look like this:

1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 2, 1, 1, 1, 1, 0, 2, 0, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 3, 1, 2, 1, 1, 1, 0, 0, 0, 2, 2, 2, 0, 1, 3, 1, 2, 1, 1, 1, 0, 0, 1, 1, 0, 0, 2, 1, 1, 4, 1, 3, 1, 2, 1, 1, 1, 0, 1, 0, 1, 0, 1, 2, 2, 2, 0, 1, 4, 1, 3, 1, 2, 1, 1

Suppose that these digits are compared against the squares of a counter-clockwise spiral on a rectangular grid. If the spiral digit is equal to 1, the square is filled in; if the spijit is not equal to 1, the square is left blank. The 1-spiral looks like this:

Now try zero. If the spijit is equal to 0, the square is filled in; if not, the square is left blank. The 0-spiral looks like this:

And here’s an animated gif of the n-spiral for n = 0..9:

# Spiral Archipelago

Incomplete map of Earthsea

Ursula K. Le Guin, creatrix of Earthsea, is a much better writer than J.R.R. Tolkien, creator of Middle-earth: much more subtle, skilful and sophisticated. But for me Middle-earth has one big advantage over Earthsea: I can imagine Middle-earth really existing. I can’t say that for Earthsea, an archipelago-world of fishermen, goatherds and wizards. There’s something dead and disconnected about Earthsea. I’m not sure what it is, but it may have something to do with Le Guin’s dedicated political correctness.

For example, despite the northern European climate and culture on Earthsea, a sea-faring world with lots of rain, mist, snow and mountains, most of the people are supposed to have dark skins. The ones that don’t – the white-skinned, blond-haired Kargs – are the bloodthirsty baddies of A Wizard of Earthsea (1968), the first book in the series. Balls to biology, in other words: there’s propaganda to propagate. So it’s not surprising that Le Guin’s father was a famous and respected figure in the mostly disreputable discipline of anthropology. Earthsea is fantasy for Guardian-readers, in short.

But I still like the idea of an archipelago-world: sea and islands, islands and sea. As Le Guin herself says: “We all have archipelagos in our minds.” That’s one of the reasons I like the Ulam spiral: it reminds me of Earthsea. Unlike Earthsea, however, the sea and islands go on for ever. In the Ulam spiral, the islands are the prime numbers and the sea is the composite numbers. It’s based on a counter-clockwise spiral of integers, like this:

```145←144←143←142←141←140←139←138←137←136←135←134←133
↓                                               ↑
146 101←100←099←098←097←096←095←094←093←092←091 132
↓   ↓                                       ↑   ↑
147 102 065←064←063←062←061←060←059←058←057 090 131
↓   ↓   ↓                               ↑   ↑   ↑
148 103 066 037←036←035←034←033←032←031 056 089 130
↓   ↓   ↓   ↓                       ↑   ↑   ↑   ↑
149 104 067 038 017←016←015←014←013 030 055 088 129
↓   ↓   ↓   ↓   ↓               ↑   ↑   ↑   ↑   ↑
150 105 068 039 018 005←004←003 012 029 054 087 128
↓   ↓   ↓   ↓   ↓   ↓       ↑   ↑   ↑   ↑   ↑   ↑
151 106 069 040 019 006 001→002 011 028 053 086 127
↓   ↓   ↓   ↓   ↓   ↓           ↑   ↑   ↑   ↑   ↑
152 107 070 041 020 007→008→009→010 027 052 085 126
↓   ↓   ↓   ↓   ↓                   ↑   ↑   ↑   ↑
153 108 071 042 021→022→023→024→025→026 051 084 125
↓   ↓   ↓   ↓                           ↑   ↑   ↑
154 109 072 043→044→045→046→047→048→049→050 083 124
↓   ↓   ↓                                   ↑   ↑
155 110 073→074→075→076→077→078→079→080→081→082 123
↓   ↓                                           ↑
156 111→112→113→114→115→116→117→118→119→120→121→122
↓                                                   ↑
157→158→159→160→161→162→163→164→165→166→167→168→169→170
```

The spiral is named after Stanislaw Ulam (1909-84), a Polish mathematician who invented it while doodling during a boring meeting. When numbers are represented as pixels and 1 is green, the spiral looks like this – note the unique “knee” formed by 2, 3 (directly above 2) and 11 (to the right of 2):

(If the image above does not animate, please try opening it in a new window.)

Some prime-pixels are isolated, like eyots or aits (small islands) in the number-sea, but some touch corner-to-corner and form larger units, larger islands. There are also prime-diamonds, like islands with lakes on them. The largest island, with 19 primes, may come very near the centre of the spiral:

Island 1 = (5, 7, 17, 19, 23, 37, 41, 43, 47, 67, 71, 73, 79, 103, 107, 109, 113, 149, 151) (i=19) (x=-3, y=3, n=37) (n=1 at x=0, y=0)

Here are some more prime-islands – prIslands or priminsulas – in the Ulam-sea that I find interesting or attractive for one reason or other:

Island 2 = (281, 283, 353, 431, 433, 521, 523, 617, 619, 719, 827, 829, 947) (i=13) (x=6, y=-12, n=619)

Island 3 = (20347, 20921, 21499, 21503, 22091, 22093, 22691, 23293, 23297, 23909, 23911, 24533, 25163, 25801, 26449, 27103, 27767, 28439) (i=18) (x=-39, y=-81, n=26449)

Island 4 = (537347, 540283, 543227, 546179, 549139, 552107, 555083, 558067, 561059, 561061, 564059, 564061, 567067, 570083, 573107, 573109) (i=16) (x=375, y=-315, n=561061)

Island 5 = (1259047, 1263539, 1263541, 1268039, 1272547, 1277063, 1281587, 1286119, 1290659, 1295207, 1299763) (i=11) (x=-561, y=399, n=1259047)

Island 6 = (1341841, 1346479, 1351123, 1355777, 1360439, 1360441, 1365107, 1365109, 1369783, 1369787, 1369789, 1374473, 1379167) (i=13) (x=-585, y=-297, n=1369783)

Island 7 = (2419799, 2419801, 2426027, 2426033, 2432263, 2432267, 2438507, 2438509, 2444759, 2451017, 2457283, 2463557) (i=12) (x=558, y=780, n=2432263)

Island 8 = (3189833, 3196979, 3196981, 3204137, 3204139, 3211301, 3211303, 3218471, 3218473, 3218477, 3225653) (i=11) (x=-894, y=858, n=3196981)

# La Spirale è Mobile

nn2 + 41 is prime for all values of n for 0 to 40.

Elsewhere other-posted: