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:

An animated Ulam Spiral pausing at n=11, 17, 41


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

Magistra Rules the Waves

One of my favourite integer sequences has the simple formula n(i) = n(i-1) + digitsum(n(i-1)). If it’s seeded with 1, its first few terms go like this:

n(1) = 1
n(2) = n(1) + digitsum(n(1)) = 1 + digitsum(1) = 2
n(3) = 2 + digitsum(2) = 4
n(4) = 4 + digitsum(4) = 8
n(5) = 8 + digitsum(8) = 16
n(6) = 16 + digitsum(16) = 16 + 1+6 = 16 + 7 = 23
n(7) = 23 + digitsum(23) = 23 + 2+3 = 23 + 5 = 28
n(8) = 28 + digitsum(28) = 28 + 2+8 = 28 + 10 = 38

As a sequence, it looks like this:

1, 2, 4, 8, 16, 23, 28, 38, 49, 62, 70, 77, 91, 101, 103, 107, 115, 122, 127, 137, 148, 161, 169, 185, 199, 218, 229, 242, 250, 257, 271, 281, 292, 305, 313, 320, 325, 335, 346, 359, 376, 392, 406, 416, 427, 440, 448, 464, 478, 497, 517, 530, 538, 554, 568, 587, 607, 620, 628, 644, 658, 677, 697, 719, 736, 752, 766, 785, 805, 818, 835, 851, 865, 884, 904, 917, 934, 950, 964, 983, 1003…

Given a number at random, is there a quick way to say whether it appears in the sequence seeded with 1? Not that I know, with one exception. If the number is divisible by 3, it doesn’t appear, at least in base 10. In base 2, that rule doesn’t apply:

n(1) = 1
n(2) = 1 + digitsum(1) = 10 = 1 + 1 = 2
n(3) = 10 + digitsum(10) = 10 + 1 = 11 = 2 + 1 = 3
n(4) = 11 + digitsum(11) = 11 + 1+1 = 101 = 3 + 2 = 5
n(5) = 101 + digitsum(101) = 101 + 1+0+1 = 111 = 5 + 2 = 7
n(6) = 111 + digitsum(111) = 111 + 11 = 1010 = 7 + 3 = 10
n(7) = 1010 + digitsum(1010) = 1010 + 10 = 1100 = 10 + 2 = 12
n(8) = 1100 + digitsum(1100) = 1100 + 10 = 1110 = 12 + 2 = 14

1, 2, 3, 5, 7, 10, 12, 14, 17, 19, 22, 25, 28, 31, 36, 38, 41, 44, 47, 52, 55, 60, 64, 65, 67, 70, 73, 76, 79, 84, 87, 92, 96, 98, 101, 105, 109, 114, 118, 123, 129, 131, 134, 137, 140, 143, 148, 151, 156, 160, 162, 165, 169, 173, 178, 182, 187, 193, 196, 199, 204, 208, 211, 216, 220, 225, 229, 234, 239, 246, 252, 258, 260, 262, 265, 268, 271, 276, 279, 284, 288, 290, 293, 297, 301, 306, 310, 315, 321, 324, 327, 332, 336, 339, 344, 348, 353, 357, 362, 367, 374…

What patterns are there in these sequences? It’s easier to check when they’re represented graphically, so I converted them into patterns à la the Ulam spiral, where n is represented as a dot on a spiral of integers. This is the spiral for base 10:

ulambase10Base 10


And these are the spirals for bases 2 and 3:

ulambase2

Base 2


ulambase3

Base 3


These sequences look fairly random to me: there are no obvious patterns in the jumps from n(i) to n(i+1), i.e. in the values for digitsum(n(i)). Now try the spirals for bases 9 and 33:

ulambase9

Base 9


ulambase33

Base 33


Patterns have appeared: there is some regularity in the jumps. You can see these regularities more clearly if you represent digitsum(n(i)) as a graph, with n(i) on the x axis and digitsum(n(i)) on the y axis. If the graph starts with n(i) = 1 on the lower left and proceeds left-right, left-right up the screen, it looks like this in base 10:

base10

Base 10 (click to enlarge)


Here are bases 2 and 3:

base2

Base 2


base3

Base 3


The jumps seem fairly random. Now try bases 9, 13, 16, 17, 25, 33 and 49:

base9

Base 9


base13

Base 13


base16

Base 16


base17

Base 17


base25

Base 25


base33

Base 33


base49

Base 49


In some bases, the formula n(i) = n(i-1) + digitsum(n(i-1)) generates mild randomness. In others, it generates strong regularity, like waves rolling ashore under a steady wind. I don’t understand why, but regularity seems to occur in bases that are one more than a power of 2 and also in some bases that are primes or squares.


Elsewhere other-posted:

Mathematica Magistra Mundi
8200_idf_insignia

Spiral Archipelago

Incomplete map of Earthsea

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←140139←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 001002 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):

Ulam spiral

Ulam spiral (animated)

(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:

island1

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:

island2

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


island3

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)


island4

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)


island5

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


island6

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


island7

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


island8

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