# Primal Stream

It’s obvious when you think about: an even number can never be the sum of two consecutive integers. Conversely, an odd number (except 1) is always the sum of two consecutive integers: 3 = 1 + 2; 5 = 2 + 3; 7 = 3 + 4; 9 = 4 + 5; and so on. The sum of three consecutive integers can be either odd or even: 6 = 1 + 2 + 3; 9 = 2 + 3 + 4. The sum of four consecutive integers must always be even: 1 + 2 + 3 + 4 = 10; 2 + 3 + 4 + 5 = 14. And so on.

But notice that 9 is the sum of consecutive integers in two different ways: 9 = 4 + 5 = 2 + 3 + 4. Having spotted that, I decided to look for numbers that were the sums of consecutive integers in the most different ways. These are the first few:

3 = 1 + 2 (number of sums = 1)
9 = 2 + 3 + 4 = 4 + 5 (s = 2)
15 = 1 + 2 + 3 + 4 + 5 = 4 + 5 + 6 = 8 + 7 = (s = 3)
45 (s = 5)
105 (s = 7)
225 (s = 8)
315 (s = 11)
945 (s = 15)
1575 (s = 17)
2835 (s = 19)
3465 (s = 23)
10395 (s = 31)

It was interesting that the number of different consecutive-integer sums for n was most often a prime number. Next I looked for the sequence at the Online Encyclopedia of Integer Sequences and discovered something that I hadn’t suspected:

A053624 Highly composite odd numbers: where d(n) increases to a record.

1, 3, 9, 15, 45, 105, 225, 315, 945, 1575, 2835, 3465, 10395, 17325, 31185, 45045, 121275, 135135, 225225, 405405, 675675, 1576575, 2027025, 2297295, 3828825, 6891885, 11486475, 26801775, 34459425, 43648605, 72747675, 130945815 — A053624 at OEIS

The notes add that the sequence is “Also least number k such that the number of partitions of k into consecutive integers is a record. For example, 45 = 22+23 = 14+15+16 = 7+8+9+10+11 = 5+6+7+8+9+10 = 1+2+3+4+5+6+7+8+9, six such partitions, but all smaller terms have fewer such partitions (15 has four).” When you don’t count the number n itself as a partition of n, you get 3 partitions for 15, i.e. consecutive integers sum to 15 in 3 different ways, so s = 3. I looked at more values for s and found that the stream of primes continued to flow:

3 → s = 1
9 = 3^2 → s = 2 (prime)
15 = 3 * 5 → s = 3 (prime)
45 = 3^2 * 5 → s = 5 (prime)
105 = 3 * 5 * 7 → s = 7 (prime)
225 = 3^2 * 5^2 → s = 8 = 2^3
315 = 3^2 * 5 * 7 → s = 11 (prime)
945 = 3^3 * 5 * 7 → s = 15 = 3 * 5
1575 = 3^2 * 5^2 * 7 → s = 17 (prime)
2835 = 3^4 * 5 * 7 → s = 19 (prime)
3465 = 3^2 * 5 * 7 * 11 → s = 23 (prime)
10395 = 3^3 * 5 * 7 * 11 → s = 31 (prime)
17325 = 3^2 * 5^2 * 7 * 11 → s = 35 = 5 * 7
31185 = 3^4 * 5 * 7 * 11 → s = 39 = 3 * 13
45045 = 3^2 * 5 * 7 * 11 * 13 → s = 47 (prime)
121275 = 3^2 * 5^2 * 7^2 * 11 → s = 53 (prime)
135135 = 3^3 * 5 * 7 * 11 * 13 → s = 63 = 3^2 * 7
225225 = 3^2 * 5^2 * 7 * 11 * 13 → s = 71 (prime)
405405 = 3^4 * 5 * 7 * 11 * 13 → s = 79 (prime)
675675 = 3^3 * 5^2 * 7 * 11 * 13 → s = 95 = 5 * 19
1576575 = 3^2 * 5^2 * 7^2 * 11 * 13 → s = 107 (prime)
2027025 = 3^4 * 5^2 * 7 * 11 * 13 → s = 119 = 7 * 17
2297295 = 3^3 * 5 * 7 * 11 * 13 * 17 → s = 127 (prime)
3828825 = 3^2 * 5^2 * 7 * 11 * 13 * 17 → s = 143 = 11 * 13
6891885 = 3^4 * 5 * 7 * 11 * 13 * 17 → s = 159 = 3 * 53
11486475 = 3^3 * 5^2 * 7 * 11 * 13 * 17 → s = 191 (prime)
26801775 = 3^2 * 5^2 * 7^2 * 11 * 13 * 17 → s = 215 = 5 * 43
34459425 = 3^4 * 5^2 * 7 * 11 * 13 * 17 → s = 239 (prime)
43648605 = 3^3 * 5 * 7 * 11 * 13 * 17 * 19 → s = 255 = 3 * 5 * 17
72747675 = 3^2 * 5^2 * 7 * 11 * 13 * 17 * 19 → s = 287 = 7 * 41
130945815 = 3^4 * 5 * 7 * 11 * 13 * 17 * 19 → s = 319 = 11 * 29

I can’t spot any way of predicting when n will yield a primal s, but I like the way that a simple question took an unexpected turn. When a number sets a record for the number of different ways it can be the sum of consecutive integers, that number will also be a highly composite odd number.

# Primal Stream

• 3, 7, 31, 127, 8191, 131071, 524287, 2147483647, 2305843009213693951, 618970019642690137449562111, 162259276829213363391578010288127, 170141183460469231731687303715884105727 — A000668, Mersenne primes (primes of the form 2^n – 1), at the Online Encyclopedia of Integer Sequences

• 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011, 24036583, 25964951, 30402457, 32582657, 37156667, 42643801, 43112609, 57885161, 74207281, 77232917, 82589933 — A000043, Mersenne exponents: primes p such that 2^p – 1 is prime. Then 2^p – 1 is called a Mersenne prime. […] It is believed (but unproved) that this sequence is infinite. The data suggest that the number of terms up to exponent N is roughly K log N for some constant K.

• The largest known prime number (as of May 2022) is 282,589,933 − 1, a number which has 24,862,048 digits when written in base 10. It was found via a computer volunteered by Patrick Laroche of the Great Internet Mersenne Prime Search (GIMPS) in 2018. — Largest known prime number

# Magiciprocal

A021023 Decimal expansion of 1/19.

0, 5, 2, 6, 3, 1, 5, 7, 8, 9, 4, 7, 3, 6, 8, 4, 2, 1, 0, 5, 2, 6, 3, 1, 5, 7, 8, 9, 4, 7, 3, 6, 8, 4, 2, 1, 0, 5, 2, 6, 3, 1, 5, 7, 8, 9, 4, 7, 3, 6, 8, 4, 2, 1, 0, 5, 2, 6, 3, 1, 5, 7, 8, 9, 4, 7, 3, 6, 8, 4, 2, 1, 0, 5, 2, 6, 3, 1, 5, 7, 8, 9, 4, 7, 3, 6, 8, 4, 2, 1, 0, 5, 2, 6, 3, 1, 5, 7, 8 [...] The magic square that uses the decimals of 1/19 is fully magic. — A021023 at the Online Encyclopedia of Integer Sequences

# Prime Times

The factorial of an integer is equal to that that integer multiplied by all the integers smaller than it. For example, this is factorial(7) or 7!:

7! = 7 * 6 * 5 * 4 * 3 * 2 * 1 = 5040

The primorial of a prime is equal to that that prime multiplied by all the primes smaller than it. For example, this is primorial(7):

primorial(7) = 7 * 5 * 3 * 2 = 210 = 4# (the product of the first four primes)

Here’s an interesting set of primorials incremented-by-one:

primorial(2) + 1 = 2 + 1 = 3 (prime)
primorial(3) + 1 = 2*3 + 1 = 7 (prime)
primorial(5) + 1 = 2*3*5 + 1 = 31 (prime)
primorial(7) + 1 = 2*3*5*7 + 1 = 211 (prime)
primorial(11) + 1 = 2*3*5*7*11 + 1 = 2311 (prime)
primorial(31) + 1 = 2*3*5*7*11*13*17*19*23*29*31 + 1 = 200560490131 (prime)
primorial(379) + 1 = 1,719,620,105,458,406,433,483,340,568,317,543,019,584,575,635,895,742,560,438,771,105,058,321,655,238,562,613,083,979,651,479,555,788,009,994,557,822,024,565,226,932,906,295,208,262,756,822,275,663,694,111 (prime)
primorial(1019) + 1 = 20,404,068,993,016,374,194,542,464,172,774,607,695,659,797,117,423,121,913,227,131,032,339,026,169,175,929,902,244,453,757,410,468,728,842,929,862,271,605,567,818,821,685,490,676,661,985,389,839,958,622,802,465,986,881,376,139,404,138,376,153,096,103,140,834,665,563,646,740,160,279,755,212,317,501,356,863,003,638,612,390,661,668,406,235,422,311,783,742,390,510,526,587,257,026,500,302,696,834,793,248,526,734,305,801,634,165,948,702,506,367,176,701,233,298,064,616,663,553,716,975,429,048,751,575,597,150,417,381,063,934,255,689,124,486,029,492,908,966,644,747,931 (prime)
primorial(1021) + 1 = 20,832,554,441,869,718,052,627,855,920,402,874,457,268,652,856,889,007,473,404,900,784,018,145,718,728,624,430,191,587,286,316,088,572,148,631,389,379,309,284,743,016,940,885,980,871,887,083,026,597,753,881,317,772,605,885,038,331,625,282,052,311,121,306,792,193,540,483,321,703,645,630,071,776,168,885,357,126,715,023,250,865,563,442,766,366,180,331,200,980,711,247,645,589,424,056,809,053,468,323,906,745,795,726,223,468,483,433,625,259,000,887,411,959,197,323,973,613,488,345,031,913,058,775,358,684,690,576,146,066,276,875,058,596,100,236,112,260,054,944,287,636,531 (prime)
primorial(2657) + 1 = 78,244,737,296,323,701,708,091,142,569,062,680,832,012,147,734,404,650,078,590,391,114,054,859,290,061,421,837,516,998,655,549,776,972,299,461,276,876,623,748,922,539,131,984,799,803,433,363,562,299,977,701,808,549,255,204,262,920,151,723,624,296,938,777,341,738,751,806,450,993,015,446,712,522,509,989,316,673,420,506,749,359,414,629,957,842,716,112,900,306,643,009,542,215,969,000,431,330,219,583,111,410,996,807,066,475,261,560,303,182,609,636,056,108,367,412,324,508,444,341,178,028,289,201,803,518,093,842,982,877,662,621,552,756,279,669,241,303,362,152,895,160,479,720,040,128,335,518,247,125,849,521,099,841,272,983,588,935,580,888,630,036,283,712,163,901,558,436,498,481,482,160,712,530,124,868,714,141,094,634,892,999,056,865,426,200,254,647,241,979,548,935,087,621,308,526,547,138,125,987,102,062,688,568,486,250,939,447,065,798,353,626,745,169,380,579,442,233,006,898
,444,700,264,240,321,482,823,859,842,044,524,114,576,784,795,294,818,755,525,169,192,652,108,755,230,262,128,210,258,672,754,900,845,837,728,345,782,457,465,793,874,408,469,588,052,577,208,643,754,019,053,756,394,151,041,512,099,598,925,557,724,343,099,264,685,155,934,891,439,161,866,250,113,047,185,553,511,797,406,764,115,907,248,713,405,817,594,729,550,600,082,808,324,331,387,143,679,800,355,356,811,873,430,669,962,333,651,282,822,030,473,702,042,073,141,618,450,021,084,993,659,382,646,598,194,115,178,864,433,545,186,250,667,775,794,249,961,932,761,063,071,117,967,553,887,984,011,652,643,245,393,971 (prime)
primorial(3229) + 1 = 689,481,240,122,180,255,681,227,812,346,871,771,457,221,628,238,467,511,261,402,638,443,056,696,165,896,544,725,098,860,107,293,247,422,610,010,824,870,599,655,026,129,367,004,672,337,297,193,288,816,463,520,704,235,722,580,204,218,943,598,425,089,855,869,341,564,771,022,924,163,236,141,415,235,947,085,902,422,536,824,665,765,244,189,167,643,048,218,572,769,125,400,511,177,245,717,452,516,267,205,786,258,497,574,258,715,214,994,129,786,103,824,740,384,634,788,909,041,221,747,073,062,941,769,355,745,272,170,421,584,636,198,911,899,164,272,930,590,704,655,882,680,817,754,473,306,122,122,423,384,160,639,995,940,152,584,830,810,911,265,680,382,263,051,658,031,509,463,010,733,595,465,426,943,956,643,445,876,702,680,730,987,739,513,538,299,069,540,636,616,098,525,527,546,435,002,783,615,353,417,794,625,251,129,892,373,849,727,119,530,335,366,131,575,986,221,685,088,118,143,088,371,896,087,248,659,669,154,564,925,048,225,211,644,681,303,874,490,648,860,319,990,785,185,350,796,853,298,548,942,407,689,617,641,587,755,314,125,485,345,107,782,298,938,892,240,282,038,605,672,241,010,302,874,153,509,795,545,077,305,234,459,038,983,235,361,138,814,897,166,376,363,090,128,647,084,552,385,969,054,439,430,382,421,762,883,708,894,899,853,286,109,068,224,980,793,075,241,538,872,287,253,835,877,394,821,667,363,465,425,187,353,453,157,415,169,810,167,271,517,665,273,484,442,461,468,031,313,956,356,871,467,191,959,110,440,864,194,544,244,079,053,955,897,287,010,339,385,419,923,838,571,256,564,818,350,769,518,898,003,780,557,167,344,272,499,224,580,817,920,441,512,610,104,625,622,872,289,967,615,843,092,782,763,554,732,404,239,287,463,466,833,602,966,629,613,502,579,134,371,295,289,680,374,088,987,611,189,907,873,072,122,808,833,765,972,650,050,982,877,578,244,899,073,193,043,546,490,795,625,023,568,563,926,988,371 (prime)

Elsewhere Other-Accessible

A005234 at the Online Encylopedia of Integer Sequences — “Primorial plus 1 primes: primes p such that 1 + product of primes up to p is prime”.

# Period Panes

In The Penguin Dictionary of Curious and Interesting Numbers (1987), David Wells remarks that 142857 is “a number beloved of all recreational mathematicians”. He then explains that it’s “the decimal period of 1/7: 1/7 = 0·142857142857142…” and “the first decimal reciprocal to have maximum period, that is, the length of its period is only one less than the number itself.”

Why does this happen? Because when you’re calculating 1/n, the remainders can only be less than n. In the case of 1/7, you get remainders for all integers less than 7, i.e. there are 6 distinct remainders and 6 = 7-1:

(1*10) / 7 = 1 remainder 3, therefore 1/7 = 0·1...
(3*10) / 7 = 4 remainder 2, therefore 1/7 = 0·14...
(2*10) / 7 = 2 remainder 6, therefore 1/7 = 0·142...
(6*10) / 7 = 8 remainder 4, therefore 1/7 = 0·1428...
(4*10) / 7 = 5 remainder 5, therefore 1/7 = 0·14285...
(5*10) / 7 = 7 remainder 1, therefore 1/7 = 0·142857...
(1*10) / 7 = 1 remainder 3, therefore 1/7 = 0·1428571...
(3*10) / 7 = 4 remainder 2, therefore 1/7 = 0·14285714...
(2*10) / 7 = 2 remainder 6, therefore 1/7 = 0·142857142...

Mathematicians know that reciprocals with maximum period can only be prime reciprocals and with a little effort you can work out whether a prime will yield a maximum period in a particular base. For example, 1/7 has maximum period in bases 3, 5, 10, 12 and 17:

1/21 = 0·010212010212010212... in base 3
1/12 = 0·032412032412032412... in base 5
1/7 =  0·142857142857142857... in base 10
1/7 =  0·186A35186A35186A35... in base 12
1/7 =  0·274E9C274E9C274E9C... in base 17

To see where else 1/7 has maximum period, have a look at this graph:

Period pane for primes 3..251 and bases 2..39

I call it a “period pane”, because it’s a kind of window into the behavior of prime reciprocals. But what is it, exactly? It’s a graph where the x-axis represents primes from 3 upward and the y-axis represents bases from 2 upward. The red squares along the bottom aren’t part of the graph proper, but indicate primes that first occur after a power of two: 5 after 4=2^2; 11 after 8=2^3; 17 after 16=2^4; 37 after 32=2^5; 67 after 64=2^6; and so on.

If a prime reciprocal has maximum period in a particular base, the graph has a solid colored square. Accordingly, the purple square at the bottom left represents 1/7 in base 10. And as though to signal the approval of the goddess of mathematics, the graph contains a lower-case b-for-base, which I’ve marked in green. Here are more period panes in higher resolution (open the images in a new window to see them more clearly):

Period pane for primes 3..587 and bases 2..77

Period pane for primes 3..1303 and bases 2..152

An interesting pattern has begun to appear: note the empty lanes, free of reciprocals with maximum period, that stretch horizontally across the period panes. These lanes are empty because there are no prime reciprocals with maximum period in square bases, that is, bases like 4, 9, 25 and 36, where 4 = 2*2, 9 = 3*3, 25 = 5*5 and 36 = 6*6. I don’t know why square bases don’t have max-period prime reciprocals, but it’s probably obvious to anyone with more mathematical nous than me.

Period pane for primes 3..2939 and bases 2..302

Period pane for primes 3..6553 and bases 2..602

Like the Ulam spiral, other and more mysterious patterns appear in the period panes, hinting at the hidden regularities in the primes.

# Total Score

The number 23 is always (and trivially) equal to some running total of the digits of its roots in base 2. In other bases, that’s not always true (n.b. numbers inside square brackets represent single digits in that base):

√23 = 23^(1/2) = 100.1100101110111011100111010101110111000001000... in base 2
23 = digsum(100.110010111011101110011101010111011)
23^(1/2) = 11.21011101110011111122022101121121... in base 3
23 = digsum(11.2101110111001111112202)
23^(1/2) = 4.8832850[10]89028... in base 11
23 = digsum(4.883)
23^(1/2) = 4.[14]5[15]53[14]0[12]0[14]5[13]... in base 18
23 = digsum(4.[14]5)
23^(1/2) = 4.[19]29[13][19]4[11][23][19][11][20]... in base 24
23 = digsum(4.[19])
23^(1/2) = 4.[19][22]9[21][17]5[12][10]456... in base 25
23 = digsum(4.[19])

23^(1/3) = 10.11011000000001111010101010011000101000110000001100000010010000101011... in base 2
23 = digsum(10.1101100000000111101010101001100010100011000000110000001001)
23^(1/3) = 2.21121001121111121022212100220... in base 3
23 = digsum(2.2112100112111112102)
23^(1/3) = 2.312000132222212022030003... in base 4
23 = digsum(2.31200013222221)
23^(1/3) = 2.6600365246121403... in base 8
23 = digsum(2.660036)
23^(1/3) = 2.753154453877080... in base 9
23 = digsum(2.75315)
23^(1/3) = 2.93120691571[10]001[10]... in base 11
23 = digsum(2.931206)
23^(1/3) = 2.[12]9[13]0[11]74[11]61[14]2... in base 15
23 = digsum(2.[12]9)
23^(1/3) = 2.[13]807[10][10]98[10]303... in base 16
23 = digsum(2.[13]8)
23^(1/3) = 2.[21]2[10][10][13][11][21][23][15][24][21]... in base 25
23 = digsum(2.[21])
23^(1/3) = 2.[21][24][11][20][24][22][23][25]0[11][11]... in base 26
23 = digsum(2.[21])

23^(1/4) = 10.0011000010011111110100101010011000001001011110001110101... in base 2
23 = digsum(10.001100001001111111010010101001100000100101111)
23^(1/4) = 2.1411772251404570... in base 8
23 = digsum(2.141177)
23^(1/4) = 2.1634161832077814... in base 9
23 = digsum(2.163416)
23^(1/4) = 2.33[15]2[14][13]967[10]6[12]5... in base 17
23 = digsum(2.33[15])
23^(1/4) = 2.6[15][19][11][31][17][10][18][21]30[27]... in base 34
23 = digsum(2.6[15])
23^(1/4) = 2.[12]9[63][18][41][32][37][56][58][60]1[17]... in base 64
23 = digsum(2.[12]9)
23^(1/4) = 2.[21]9[26]6[54][21][20]3[64][86][110]... in base 111
23 = digsum(2.[21])
23^(1/4) = 2.[21][30][66][22][73][19]3[15][51][24]8... in base 112
23 = digsum(2.[21])
23^(1/4) = 2.[21][52][36][111][32][104][66][40][95][33]5... in base 113
23 = digsum(2.[21])
23^(1/4) = 2.[21][74][50][62][27]19[100][70][48][89]... in base 114
23 = digsum(2.[21])
23^(1/4) = 2.[21][96][108]2[101][62][43][18][71][113][37]... in base 115
23 = digsum(2.[21])

23^(1/5) = 1.110111110100011010011101000111111011111011000... in base 2
23 = digsum(1.11011111010001101001110100011111101)
23^(1/5) = 1.313310122131013323323010... in base 4
23 = digsum(1.31331012213101)
23^(1/5) = 1.[10]5714140[10][11][11]61... in base 12
23 = digsum(1.[10]57)
23^(1/5) = 1.[11]45210[12]3974[12]0[11]... in base 13
23 = digsum(1.[11]452)
23^(1/5) = 1.[22][17][15]788[12][20][10][16]5... in base 26
23 = digsum(1.[22])

And in base 10:

23^(1/7) = 1.565065607960239...
23 = digsum(1.56506)

23^(1/11) = 1.32982177397055...
23 = digsum(1.3298)

23^(1/25) = 1.133624213096260543...
23 = digsum(1.13362421)

23^(1/43) = 1.075642836327515...
23 = digsum(1.07564)

23^(1/51) = 1.0634095245502272...
23 = digsum(1.063409)

23^(1/59) = 1.054581462032154...
23 = digsum(1.05458)

23^(1/74) = 1.043282031364111825...
23 = digsum(1.04328203)

23^(1/78) = 1.041017545329593513...
23 = digsum(1.04101754)

23^(1/81) = 1.039468791371841...
23 = digsum(1.03946)

23^(1/85) = 1.037576979258809...
23 = digsum(1.03757)

23^(1/86) = 1.0371320245405187874...
23 = digsum(1.037132024)

23^(1/101) = 1.031531403111493041428...
23 = digsum(1.03153140311)

# Year and Square

The simplest and in some ways greatest magic square is this:

```6 1 8
7 5 3
2 9 4 (Magic total = 15)
```

All rows and columns sum to 15 and so do both diagonals. Using other sets of numbers, you can create an infinite number of further 3×3 magic squares. Here’s one using only prime numbers and 1:

```43 01 67
61 37 13
07 73 31 (Magic=111)
```

The magic total is 111, which is 3 x 37, just as 15 = 3 x 5. It’s an interesting but untaxing exercise to prove that, for all 3×3 magic squares, the magic total is three times the central number. So you can use only prime numbers in a 3×3 square, but you can’t have a prime number as the magic total (unless you use fractions and so on).

And guess what? 2019 = 3 x 667, the first prime number after 666. So I decided to see if I could find an all-prime magic squares whose magic total was 2019. I found nine of them (and 9 = 3 x 3).

```1117 0019 0883
0439 0673 0907
0463 1327 0229 (Magic=2019)

1069 0067 0883
0487 0673 0859
0463 1279 0277 (Magic=2019)

1063 0229 0727
0337 0673 1009
0619 1117 0283 (Magic=2019)

0883 0313 0823
0613 0673 0733
0523 1033 0463 (Magic=2019)

0619 0337 1063
1117 0673 0229
0283 1009 0727 (Magic=2019)

0463 0439 1117
1327 0673 0019
0229 0907 0883 (Magic=2019)

0463 0487 1069
1279 0673 0067
0277 0859 0883 (Magic=2019)

0379 0607 1033
1327 0673 0019
0313 0739 0967 (Magic=2019)

0523 0613 0883
1033 0673 0313
0463 0733 0823 (Magic=2019)
```

# 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

# Fract-Hills

The Farey sequence is a fascinating sequence of fractions that divides the interval between 0/1 and 1/1 into smaller and smaller parts. To find the Farey fraction a[i] / b[i], you simply find the mediant of the Farey fractions on either side:

• a[i] / b[i] = (a[i-1] + a[i+1]) / (b[i-1] + b[i+1])

Then, if necessary, you reduce the numerator and denominator to their simplest possible terms. So the sequence starts like this:

• 0/1, 1/1

To create the next stage, find the mediant of the two fractions above: (0+1) / (1+1) = 1/2

• 0/1, 1/2, 1/1

For the next stage, there are two mediants to find: (0+1) / (1+2) = 1/3, (1+1) / (2+3) = 2/3

• 0/1, 1/3, 1/2, 2/3, 1/1

Note that 1/2 is the mediant of 1/3 and 2/3, that is, 1/2 = (1+2) / (3+3) = 3/6 = 1/2. The next stage is this:

• 0/1, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 1/1

Now 1/2 is the mediant of 2/5 and 3/5, that is, 1/2 = (2+3) / (5+5) = 5/10 = 1/2. Further stages go like this:

• 0/1, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 1/1

• 0/1, 1/6, 1/5, 2/9, 1/4, 3/11, 2/7, 3/10, 1/3, 4/11, 3/8, 5/13, 2/5, 5/12, 3/7, 4/9, 1/2, 5/9, 4/7, 7/12, 3/5, 8/13, 5/8, 7/11, 2/3, 7/10, 5/7, 8/11, 3/4, 7/9, 4/5, 5/6, 1/1

• 0/1, 1/7, 1/6, 2/11, 1/5, 3/14, 2/9, 3/13, 1/4, 4/15, 3/11, 5/18, 2/7, 5/17, 3/10, 4/13, 1/3, 5/14, 4/11, 7/19, 3/8, 8/21, 5/13, 7/18, 2/5, 7/17, 5/12, 8/19, 3/7, 7/16, 4/9, 5/11, 1/2, 6/11, 5/9, 9/16, 4/7, 11/19, 7/12, 10/17, 3/5, 11/18, 8/13, 13/21, 5/8, 12/19, 7/11, 9/14, 2/3, 9/13, 7/10, 12/17, 5/7, 13/18, 8/11, 11/15, 3/4, 10/13, 7/9, 11/14, 4/5, 9/11, 5/6, 6/7, 1/1

The Farey sequence is actually a fractal, as you can see more easily when it’s represented as an image:

Farey fractal stage #1, representing 0/1, 1/2, 1/1

Farey fractal stage #2, representing 0/1, 1/3, 1/2, 2/3, 1/1

Farey fractal stage #3, representing 0/1, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 1/1

Farey fractal stage #4, representing 0/1, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 1/1

Farey fractal stage #5

Farey fractal stage #6

Farey fractal stage #7

Farey fractal stage #8

Farey fractal stage #9

Farey fractal stage #10

Farey fractal (animated)

That looks like the slope of a hill to me, so you could call it a Farey fract-hill. But Farey fract-hills or Farey fractals aren’t confined to the unit interval, 0/1 to 1/1. Here are Farey fractals for the intervals 0/1 to n/1, n = 1..10:

Farey fractal for interval 0/1 to 1/1

Farey fractal for interval 0/1 to 2/1, beginning 0/1, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 1/1, 5/4, 4/3, 7/5, 3/2, 8/5, 5/3, 7/4, 2/1

Farey fractal for interval 0/1 to 3/1, beginning 0/1, 1/3, 1/2, 2/3, 1/1, 5/4, 4/3, 7/5, 3/2, 8/5, 5/3, 7/4, 2/1, 7/3, 5/2, 8/3, 3/1

Farey fractal for interval 0/1 to 4/1, beginning
0/1, 1/3, 1/2, 2/3, 1/1, 4/3, 3/2, 5/3, 2/1, 7/3, 5/2, 8/3, 3/1, 10/3, 7/2, 11/3, 4/1

Farey fractal for interval 0/1 to 5/1, beginning 0/1, 1/1, 5/4, 10/7, 5/3, 7/4, 2/1, 7/3, 5/2, 8/3, 3/1, 13/4, 10/3, 25/7, 15/4, 4/1, 5/1

Farey fractal for interval 0/1 to 6/1, beginning 0/1, 1/2, 1/1, 4/3, 3/2, 5/3, 2/1, 5/2, 3/1, 7/2, 4/1, 13/3, 9/2, 14/3, 5/1, 11/2, 6/1

Farey fractal for interval 0/1 to 7/1, beginning 0/1, 7/5, 7/4, 2/1, 7/3, 21/8, 14/5, 3/1, 7/2, 4/1, 21/5, 35/8, 14/3, 5/1, 21/4, 28/5, 7/1

Farey fractal for interval 0/1 to 8/1, beginning 0/1, 1/2, 1/1, 3/2, 2/1, 5/2, 3/1, 7/2, 4/1, 9/2, 5/1, 11/2, 6/1, 13/2, 7/1, 15/2, 8/1

Farey fractal for interval 0/1 to 9/1, beginning 0/1, 1/1, 3/2, 2/1, 3/1, 7/2, 4/1, 13/3, 9/2, 14/3, 5/1, 11/2, 6/1, 7/1, 15/2, 8/1, 9/1

Farey fractal for interval 0/1 to 10/1, beginning 0/1, 5/4, 5/3, 2/1, 5/2, 3/1, 10/3, 15/4, 5/1, 25/4, 20/3, 7/1, 15/2, 8/1, 25/3, 35/4, 10/1

The shape of the slope is determined by the factorization of n:

n = 12 = 2^2 * 3

n = 16 = 2^4

n = 18 = 2 * 3^2

n = 20 = 2^2 * 5

n = 25 = 5^2

n = 27 = 3^3

n = 32 = 2^5

n = 33 = 3 * 11

n = 42 = 2 * 3 * 7

n = 64 = 2^6

n = 65 = 5 * 13

n = 70 = 2 * 5 * 7

n = 77 = 7 * 11

n = 81 = 3^4

n = 96 = 2^5 * 3

n = 99 = 3^2 * 11

n = 100 = 2^2 * 5^2

Farey fractal-hills, n = various

Boustrophedon (pronounced “bough-stra-FEE-dun” or “boo-stra-FEE-dun”) is an ancient Greek word literally meaning “as the ox turns (in ploughing)”, that is, moving left-right, right-left, and so on. The word is used of writing that runs down the page in the same way. To see what that means, examine two versions of the first paragraph of Clark Ashton Smith’s story “The Demon of the Flower” (1933). The first is written in the usual way, the second is written boustrophedon:

Not as the plants and flowers of Earth, growing peacefully beneath a simple sun, were the blossoms of the planet Lophai. Coiling and uncoiling in double dawns; tossing tumultuously under vast suns of jade green and balas-ruby orange; swaying and weltering in rich twilights, in aurora-curtained nights, they resembled fields of rooted servants that dance eternally to an other-worldly music.

Not as the plants and flowers of Earth, growing peacefully
.iahpoL tenalp eht fo smossolb eht erew ,nus elpmis a htaeneb
Coiling and uncoiling in double dawns; tossing tumultuously
;egnaro ybur-salab dna neerg edaj fo snus tsav rednu
swaying and weltering in rich twilights, in aurora-curtained
ecnad taht stnavres detoor fo sdleif delbmeser yeht ,sthgin
eternally to an other-worldly music.

Boustrophedon writing was once common and sometimes the left-right lines would also be mirror-reversed, like this:

You could also use the term “boustrophedon” to describe the way this table of numbers is filled:

The table begins with “1” in the top left-hand corner, then moves right for “2”, then down for “3”, then right-and-up for “4”, “5” and “6”, then right for “7”, then left-and-down for “8”, “9” and “10”, and so on. You could also say that the numbers snake through the table. I’ve marked the primes among them, because I was interested in the patterns made by the primes when the numbers were represented as blocks on a grid, like this:

Primes are in solid white (compare the Ulam spiral). Here’s the boustrophedon prime-grid on a finer scale:

(click for full image)

And what about other number-tests? Here are the even numbers marked on the grid (i.e. n mod 2 = 0):

n mod 2 = 0

And here are some more examples of a modulus test:

n mod 3 = 0

n mod 5 = 0

n mod 9 = 0

n mod 15 = 0

n mod various = 0 (animated gif)

Next I looked at reciprocals (numbers divided into 1) marked on the grid, with the digits of a reciprocal marking the number of blank squares before a square is filled in (if the digit is “0”, the square is filled immediately). For example, in base ten 1/7 = 0.142857142857142857…, where the block “142857” repeats for ever. When represented on the grid, 1/7 has 1 blank square, then a filled square, then 4 blank squares, then a filled square, then 2 blank squares, then a filled square, and so on:

1/7 in base 10

And here are some more reciprocals (click for full images):

1/9 in base 2

1/13 in base 10

1/27 in base 10

1/41 in base 10

1/63 in base 10

1/82 in base 10

1/101 in base 10

1/104 in base 10

1/124 in base 10

1/143 in base 10

1/175 in base 10

1/604 in base 8

1/n in various bases (animated gif)