Phrock and Roll

What does a fractal phallus look like?

Millions of people have axed this corely key question.

The Overlord of the Über-Feral can answer it — keyly, corely and comprehensively dot dot dot

And here is the answer: Phrallic Frolics

Tright Treeing

Here is a very simple tree with two branches:

Two-branch tree


These are the steps that a simple computer program follows to draw the tree, with a red arrow indicating where the computer’s focus is at each stage:

Two-branch tree stage 1


2-Tree stage 2


2-Tree stage 3


2-Tree stage 4


2-Tree (animated)


If you had to give the computer an explicit instruction at each stage, the instructions might look something like this:

1. Start at node 1, draw a left branch to node 2 and colour the node green.
2. Return to node 1.
3. Draw a right branch to node 3 and colour the node green.
4. Finish.

Now try a slightly less simple tree with branches that fork twice:

Four-branch tree (static)


These are the steps that a simple computer program follows to draw the tree, with a red arrow indicating where the computer’s focus is at each stage:

4-Tree #1


4-Tree #2


4-Tree #3


4-Tree #4


4-Tree #5


4-Tree #6


4-Tree #7


4-Tree #8


4-Tree #9


4-Tree #10


4-Tree #11


4-Tree (animated)


If you had to give the computer an explicit instruction at each stage, the instructions might look something like this:

1. Start at node 1 and draw a left branch to node 2.
2. Draw a left branch to node 3 and colour it green.
3. Return to node 2.
4. Draw a right branch to node 4 and colour it green.
5. Return to node 2.
6. Return to node 1.
7. Draw a right branch to node 5.
8. Draw a left branch to node 6.
9. Draw a left branch to node 7 and colour it green.
10. Return to node 6.
11. Draw a left branch to node 8 and colour it green.
12. Finish.

It’s easy to see that the list of instructions would be much bigger for a tree with branches that fork three times, let alone four times or you. But you don’t need to give a full set of explicit instructions: you can use a program, or a list of instructions using variables. Suppose the tree has branches that fork f times. If f = 4, you will need an array variable level() with four values, level(1), level(2), level(3) and level(4). Now follow these instructions:

1. li = 1, level(1) = 0, level(2) = 0, ... level(f+1) = 0
2. level(li) = level(li) + 1
3. If level(li) = 1, draw a branch to the left and jump to step 7
4. If level(li) = 2, draw a branch to the right and jump to step 7
5. li = li - 1 (note that this line is reached if the tests fail in lines 3 and 4)
6. If li > 0, jump to step 2, otherwise jump to step 11
7. If li = f, draw a green node and jump to step 5
9. li = li + 1
10. Jump to step 2
11. Finish.

By changing the value of f, a computer can use those eleven basic instructions to draw any size of tree (I’ve left out details like changes in the length of branches and so on). When f = 4, the tree will look like this:

16-Tree (static)


16-Tree (animated)


With simple adjustments, the program can be used for other shapes whose underlying structure can be represented symbolically as a tree. The program is in fact a fractalizer, that is, it draws a fractal. So if you use a version of the program to draw fractals based on right-triangles, you can say you are “tright treeing” (tright = triangle-that-is-right).

Here is some tright treeing. Start with a simple isoceles right-triangle. It can be divided into smaller isoceles right-triangles by finding the midpoint of the hypotenuse, then repeating:

Right-triangle rep-2 stage 1


Right-triangle #2


Tright #3


Tright #4


Tright #5


Tright #6


Tright #7


Tright #7 (no internal lines)


You can distort the isoceles right-triangle in interesting ways by finding the midpoint of a side other than the hypotenuse, like this:

Right-triangle (distorted) #1


Distorted tright #2


Distorted tright #3


Distorted tright #4


Distorted tright #5


Distorted tright #6


Distorted tright #7


Distorted tright #8


Distorted tright #9


Distorted tright #10


Distorted tright #11


Distorted tright #12


Distorted tright #13


Distorted tright (animated)


Here’s a different right-triangle. When you divide it regularly, it looks like this:

Right-triangle rep-3 stage 1


Rep-3 Tright #2


3-Tright #3


3-Tright #4


3-Tright #5


3-Tright #6


3-Tright #7


3-Tright #8


3-Tright #9


3-Tright (one colour)


When you distort the divisions, you can create interesting fractals (click on images for larger versions):

Distorted 3-Tright


Distorted 3-Tright


Distorted 3-Tright


Distorted 3-Tright


Distorted 3-Tright


Distorted 3-Tright


Distorted 3-Tright (animated)


And when four of the distorted right-triangles (rep-2 or rep-3) are joined in a diamond, you can create shapes like these:

Creating a diamond #1


Creating a diamond #2


Creating a diamond #3


Creating a diamond #4


Creating a diamond (animated)


Rep-3 right-triangle diamond (divided)


Rep-3 right-triangle diamond (single colour)


Distorted rep-3 right-triangle diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond


Distorted 3-tright diamond (animated)


Distorted rep-2 right-triangle


Distorted 2-tright diamond


Distorted 2-tright diamond


Distorted 2-tright diamond


Distorted 2-tright diamond


Distorted 2-tright diamond (animated)


Tutelary Trinity

“There are three golden rules to ensure computer security. They are: do not own a computer; do not power it on; do not use it.” — Robert H. Morris (1932-2011), computer scientist and once head of the NSA.

Square Routes Re-Re-Re-Revisited

Discovering something that’s new to you in recreational maths is good. But so is re-discovering it by a different route. I’ve long been passionate about what happens when a point is allowed to jump repeatedly halfway towards the randomly chosen vertices of a square. If the point can choose any vertex any number of times, the interior of the square fills slowly and completely with points, like this:

Point jumping at random halfway towards vertices of a square


However, if the point is banned from jumping towards the same vertex twice or more in a row, an interesting fractal appears:

Fractal #1 — ban on jumping towards vertex vi twice or more


If the point can’t jump towards the vertex one place clockwise of the vertex it’s just jumped towards, this fractal appears:

Fractal #2 — ban on jumping towards vertex vi+1


If the point can’t jump towards the vertex two places clockwise of the vertex it’s just jumped towards, this fractal appears (two places clockwise is also two places anticlockwise, i.e. the banned vertex is diagonally opposite):

Fractal #3 — ban on jumping towards vertex vi+2


Now I’ve discovered a new way to create these fractals. You take a filled square, divide it into smaller squares, then remove some of them in a systematic way. Then you do the same to the smaller squares that remain. For fractal #1, you do this:

Fractal #1, stage #1


Stage #2


Stage #3


Stage #4


Stage #5


Stage #6


Stage #7


Stage #8


Fractal #1 (animated)


For fractal #2, you do this:

Fractal #2, stage #1


Stage #2


Stage #3


Stage #4


Stage #5


Stage #6


Stage #7


Stage #8


Fractal #2 (animated)


For fractal #3, you do this:

Fractal #3, stage #1


Stage #2


Stage #3


Stage #4


Stage #5


Stage #6


Stage #7


Stage #8


Fractal #3 (animated)


If the sub-squares are coloured, it’s easier to understand how, say, fractal #1 is created:

Fractal #1 (coloured), stage #1


Stage #2


Stage #3


Stage #4


Stage #5


Stage #6


Stage #7


Stage #8


Fractal #1 (coloured and animated)


The fractal is actually being created in quarters, with one quarter rotated to form the second, third and fourth quarters:

Fractal #1, quarter









Here’s an animation of the same process for fractal #3:

Fractal #3 (coloured and animated)


So you can create these fractals either with a jumping point or by subdividing a square. But in fact I discovered the subdivided-square route by looking at a variant of the jumping-point route. I wondered what would happen if you took a point inside a square, allowed it to trace all possible routes towards the vertices without marking its position, then imposed the restriction for Fractal #1 on its final jump, namely, that it couldn’t jump towards the vertex it jumped towards on its previous jump. If the point is marked after its final jump, this is what appears (if the routes chosen had been truly random, the image would be similar but messier):

Fractal #1, restriction on final jump


Then I imposed the same restriction on the point’s final two jumps:

Fractal #1, restriction on final 2 jumps


And final three jumps:

Fractal #1, restriction on final 3 jumps


And so on:

Fractal #1, restriction on final 4 jumps


Fractal #1, restriction on final 5 jumps


Fractal #1, restriction on final 6 jumps


Fractal #1, restriction on final 7 jumps


Here are animations of the same process applied to fractals #2 and #3:

Fractal #2, restrictions on final 1, 2, 3… jumps


Fractal #3, restrictions on final 1, 2, 3… jumps


The longer the points are allowed to jump before the final restriction is imposed on their n final jumps, the more densely packed the marked points will be:

Fractal #1, packed points #1


Packed points #2


Packed points #3


Eventually, the individual points will form a solid mass, like this:

Fractal #1, solid mass of points


Fractal #1, packed points (animated)


Previously pre-posted (please peruse):

Square Routes
Square Routes Revisited
Square Routes Re-Revisited
Square Routes Re-Re-Revisited

An N-Finity

10111 in base 2
212 in base 3
113 in base 4
43 in base 5
35 in base 6
32 in base 7
27 in base 8
25 in base 9
23 in base 10
21 in base 11
1B in base 12
1A in base 13
19 in base 14
18 in base 15
17 in base 16
16 in base 17
15 in base 18
14 in base 19
13 in base 20
12 in base 21
11 in base 22
10 in base 23
N in all bases >= 24

√23 = 4.79583152331…

Gyp Cip

Abundance often overwhelms, but restriction reaps riches. That’s true in mathematics and science, where you can often understand the whole better by looking at only a part of it first — restriction reaps riches. Egyptian fractions are one example in maths. In ancient Egypt, you could have any kind of fraction you liked so long as it was a reciprocal like 1/2, 1/3, 1/4 or 1/5 (well, there were two exceptions: 2/3 and 3/4 were also allowed).

So when mathematicians speak of “Egyptian fractions”, they mean those fractions that can be represented as a sum of reciprocals. Egyptian fractions are restricted and that reaps riches. Here’s one example: how many ways can you add n distinct reciprocals to make 1? When n = 1, there’s one way to do it: 1/1. When n = 2, there’s no way to do it, because 1 – 1/2 = 1/2. Therefore the summed reciprocals aren’t distinct: 1/2 + 1/2 = 1. After that, 1 – 1/3 = 2/3, 1 – 1/4 = 3/4, and so on. By the modern meaning of “Egyptian fraction”, there’s no solution for n = 2.

However, when n = 3, there is a way to do it:

• 1/2 + 1/3 + 1/6 = 1

But that’s the only way. When n = 4, things get better:

• 1/2 + 1/4 + 1/6 + 1/12 = 1
• 1/2 + 1/3 + 1/10 + 1/15 = 1
• 1/2 + 1/3 + 1/9 + 1/18 = 1
• 1/2 + 1/4 + 1/5 + 1/20 = 1
• 1/2 + 1/3 + 1/8 + 1/24 = 1
• 1/2 + 1/3 + 1/7 + 1/42 = 1

What about n = 5, n = 6 and so on? You can find the answer at the Online Encyclopedia of Integer Sequences (OEIS), where sequence A006585 is described as “Egyptian fractions: number of solutions to 1 = 1/x1 + … + 1/xn in positive integers x1 < … < xn”. The sequence is one of the shortest and strangest at the OEIS:

• 1, 0, 1, 6, 72, 2320, 245765, 151182379

When n = 1, there’s one solution: 1/1. When n = 2, there’s no solution, as I showed above. When n = 3, there’s one solution again. When n = 4, there are six solutions. And the OEIS tells you how many solutions there are for n = 5, 6, 7, 8. But n >= 9 remains unknown at the time of writing.

To understand the problem, consider the three reciprocals, 1/2, 1/3 and 1/5. How do you sum them? They have different denominators, 2, 3 and 5, so you have to create a new denominator, 30 = 2 * 3 * 5. Then you have to adjust the numerators (the numbers above the fraction bar) so that the new fractions have the same value as the old:

• 1/2 = 15/30 = (2*3*5 / 2) / 30
• 1/3 = 10/30 = (2*3*5 / 3) / 30
• 1/5 = 06/30 = (2*3*5 / 5) / 30
• 15/30 + 10/30 + 06/30 = (15+10+6) / 30 = 31/30 = 1 + 1/30

Those three reciprocals don’t sum to 1. Now try 1/2, 1/3 and 1/6:

• 1/2 = 18/36 = (2*3*6 / 2) / 36
• 1/3 = 12/36 = (2*3*6 / 3) / 36
• 1/6 = 06/36 = (2*3*6 / 6) / 36
• 18/36 + 12/36 + 06/36 = (18+12+6) / 36 = 36/36 = 1

So when n = 3, the problem consists of finding three reciprocals, 1/a, 1/b and 1/c, such that for a, b, and c:

• a*b*c = a*b + a*c + b*c

There is only one solution: a = 2, b = 3 and c = 6. When n = 4, the problem consists of finding four reciprocals, 1/a, 1/b, 1/c and 1/d, such that for a, b, c and d:

• a*b*c*d = a*b*c + a*b*d + a*c*d + b*c*d

For example:

• 2*4*6*12 = 576
• 2*4*6 + 2*4*12 + 2*6*12 + 4*6*12 = 48 + 96 + 144 + 288 = 576
• 2*4*6*12 = 2*4*6 + 2*4*12 + 2*6*12 + 4*6*12 = 576

Therefore:

• 1/2 + 1/4 + 1/6 + 1/12 = 1

When n = 5, the problem consists of finding five reciprocals, 1/a, 1/b, 1/c, 1/d and 1/e, such that for a, b, c, d and e:

• a*b*c*d*e = a*b*c*d + a*b*c*e + a*b*d*e + a*c*d*e + b*c*d*e

There are 72 solutions and here they are:

• 1/2 + 1/4 + 1/10 + 1/12 + 1/15 = 1 (#1)
• 1/2 + 1/4 + 1/9 + 1/12 + 1/18 = 1 (#2)
• 1/2 + 1/5 + 1/6 + 1/12 + 1/20 = 1 (#3)
• 1/3 + 1/4 + 1/5 + 1/6 + 1/20 = 1 (#4)
• 1/2 + 1/4 + 1/8 + 1/12 + 1/24 = 1 (#5)
• 1/2 + 1/3 + 1/12 + 1/21 + 1/28 = 1 (#6)
• 1/2 + 1/4 + 1/6 + 1/21 + 1/28 = 1 (#7)
• 1/2 + 1/4 + 1/7 + 1/14 + 1/28 = 1 (#8)
• 1/2 + 1/3 + 1/12 + 1/20 + 1/30 = 1 (#9)
• 1/2 + 1/4 + 1/6 + 1/20 + 1/30 = 1 (#10)
• 1/2 + 1/5 + 1/6 + 1/10 + 1/30 = 1 (#11)
• 1/2 + 1/3 + 1/11 + 1/22 + 1/33 = 1 (#12)
• 1/2 + 1/3 + 1/14 + 1/15 + 1/35 = 1 (#13)
• 1/2 + 1/3 + 1/12 + 1/18 + 1/36 = 1 (#14)
• 1/2 + 1/4 + 1/6 + 1/18 + 1/36 = 1 (#15)
• 1/2 + 1/3 + 1/10 + 1/24 + 1/40 = 1 (#16)
• 1/2 + 1/4 + 1/8 + 1/10 + 1/40 = 1 (#17)
• 1/2 + 1/4 + 1/7 + 1/12 + 1/42 = 1 (#18)
• 1/2 + 1/3 + 1/9 + 1/30 + 1/45 = 1 (#19)
• 1/2 + 1/4 + 1/5 + 1/36 + 1/45 = 1 (#20)
• 1/2 + 1/5 + 1/6 + 1/9 + 1/45 = 1 (#21)
• 1/2 + 1/3 + 1/12 + 1/16 + 1/48 = 1 (#22)
• 1/2 + 1/4 + 1/6 + 1/16 + 1/48 = 1 (#23)
• 1/2 + 1/3 + 1/9 + 1/27 + 1/54 = 1 (#24)
• 1/2 + 1/3 + 1/8 + 1/42 + 1/56 = 1 (#25)
• 1/2 + 1/3 + 1/8 + 1/40 + 1/60 = 1 (#26)
• 1/2 + 1/3 + 1/10 + 1/20 + 1/60 = 1 (#27)
• 1/2 + 1/3 + 1/12 + 1/15 + 1/60 = 1 (#28)
• 1/2 + 1/4 + 1/5 + 1/30 + 1/60 = 1 (#29)
• 1/2 + 1/4 + 1/6 + 1/15 + 1/60 = 1 (#30)
• 1/2 + 1/4 + 1/5 + 1/28 + 1/70 = 1 (#31)
• 1/2 + 1/3 + 1/8 + 1/36 + 1/72 = 1 (#32)
• 1/2 + 1/3 + 1/9 + 1/24 + 1/72 = 1 (#33)
• 1/2 + 1/4 + 1/8 + 1/9 + 1/72 = 1 (#34)
• 1/2 + 1/3 + 1/12 + 1/14 + 1/84 = 1 (#35)
• 1/2 + 1/4 + 1/6 + 1/14 + 1/84 = 1 (#36)
• 1/2 + 1/3 + 1/8 + 1/33 + 1/88 = 1 (#37)
• 1/2 + 1/3 + 1/10 + 1/18 + 1/90 = 1 (#38)
• 1/2 + 1/3 + 1/7 + 1/78 + 1/91 = 1 (#39)
• 1/2 + 1/3 + 1/8 + 1/32 + 1/96 = 1 (#40)
• 1/2 + 1/3 + 1/9 + 1/22 + 1/99 = 1 (#41)
• 1/2 + 1/4 + 1/5 + 1/25 + 1/100 = 1 (#42)
• 1/2 + 1/3 + 1/7 + 1/70 + 1/105 = 1 (#43)
• 1/2 + 1/3 + 1/11 + 1/15 + 1/110 = 1 (#44)
• 1/2 + 1/3 + 1/8 + 1/30 + 1/120 = 1 (#45)
• 1/2 + 1/4 + 1/5 + 1/24 + 1/120 = 1 (#46)
• 1/2 + 1/5 + 1/6 + 1/8 + 1/120 = 1 (#47)
• 1/2 + 1/3 + 1/7 + 1/63 + 1/126 = 1 (#48)
• 1/2 + 1/3 + 1/9 + 1/21 + 1/126 = 1 (#49)
• 1/2 + 1/3 + 1/7 + 1/60 + 1/140 = 1 (#50)
• 1/2 + 1/4 + 1/7 + 1/10 + 1/140 = 1 (#51)
• 1/2 + 1/3 + 1/12 + 1/13 + 1/156 = 1 (#52)
• 1/2 + 1/4 + 1/6 + 1/13 + 1/156 = 1 (#53)
• 1/2 + 1/3 + 1/7 + 1/56 + 1/168 = 1 (#54)
• 1/2 + 1/3 + 1/8 + 1/28 + 1/168 = 1 (#55)
• 1/2 + 1/3 + 1/9 + 1/20 + 1/180 = 1 (#56)
• 1/2 + 1/3 + 1/7 + 1/54 + 1/189 = 1 (#57)
• 1/2 + 1/3 + 1/8 + 1/27 + 1/216 = 1 (#58)
• 1/2 + 1/4 + 1/5 + 1/22 + 1/220 = 1 (#59)
• 1/2 + 1/3 + 1/11 + 1/14 + 1/231 = 1 (#60)
• 1/2 + 1/3 + 1/7 + 1/51 + 1/238 = 1 (#61)
• 1/2 + 1/3 + 1/10 + 1/16 + 1/240 = 1 (#62)
• 1/2 + 1/3 + 1/7 + 1/49 + 1/294 = 1 (#63)
• 1/2 + 1/3 + 1/8 + 1/26 + 1/312 = 1 (#64)
• 1/2 + 1/3 + 1/7 + 1/48 + 1/336 = 1 (#65)
• 1/2 + 1/3 + 1/9 + 1/19 + 1/342 = 1 (#66)
• 1/2 + 1/4 + 1/5 + 1/21 + 1/420 = 1 (#67)
• 1/2 + 1/3 + 1/7 + 1/46 + 1/483 = 1 (#68)
• 1/2 + 1/3 + 1/8 + 1/25 + 1/600 = 1 (#69)
• 1/2 + 1/3 + 1/7 + 1/45 + 1/630 = 1 (#70)
• 1/2 + 1/3 + 1/7 + 1/44 + 1/924 = 1 (#71)
• 1/2 + 1/3 + 1/7 + 1/43 + 1/1806 = 1 (#72)

All the sums start with 1/2 except for one:

• 1/2 + 1/5 + 1/6 + 1/12 + 1/20 = 1 (#3)
• 1/3 + 1/4 + 1/5 + 1/6 + 1/20 = 1 (#4)

Here are the solutions in another format:

(2,4,10,12,15), (2,4,9,12,18), (2,5,6,12,20), (3,4,5,6,20), (2,4,8,12,24), (2,3,12,21,28), (2,4,6,21,28), (2,4,7,14,28), (2,3,12,20,30), (2,4,6,20,30), (2,5,6,10,30), (2,3,11,22,33), (2,3,14,15,35), (2,3,12,18,36), (2,4,6,18,36), (2,3,10,24,40), (2,4,8,10,40), (2,4,7,12,42), (2,3,9,30,45), (2,4,5,36,45), (2,5,6,9,45), (2,3,12,16,48), (2,4,6,16,48), (2,3,9,27,54), (2,3,8,42,56), (2,3,8,40,60), (2,3,10,20,60), (2,3,12,15,60), (2,4,5,30,60), (2,4,6,15,60), (2,4,5,28,70), (2,3,8,36,72), (2,3,9,24,72), (2,4,8,9,72), (2,3,12,14,84), (2,4,6,14,84), (2,3,8,33,88), (2,3,10,18,90), (2,3,7,78,91), (2,3,8,32,96), (2,3,9,22,99), (2,4,5,25,100), (2,3,7,70,105), (2,3,11,15,110), (2,3,8,30,120), (2,4,5,24,120), (2,5,6,8,120), (2,3,7,63,126), (2,3,9,21,126), (2,3,7,60,140), (2,4,7,10,140), (2,3,12,13,156), (2,4,6,13,156), (2,3,7,56,168), (2,3,8,28,168), (2,3,9,20,180), (2,3,7,54,189), (2,3,8,27,216), (2,4,5,22,220), (2,3,11,14,231), (2,3,7,51,238), (2,3,10,16,240), (2,3,7,49,294), (2,3,8,26,312), (2,3,7,48,336), (2,3,9,19,342), (2,4,5,21,420), (2,3,7,46,483), (2,3,8,25,600), (2,3,7,45,630), (2,3,7,44,924), (2,3,7,43,1806)


Note

Strictly speaking, there are two solutions for n = 2 in genuine Egyptian fractions, because 1/3 + 2/3 = 1 and 1/4 + 3/4 = 1. As noted above, 2/3 and 3/4 were permitted as fractions in ancient Egypt.

Block’n’Role

How low can you go? When it comes to standard bases in mathematics, you can’t go lower than 2. But base 2, or binary, is unsurpassable for simplicity and beauty. With only two digits, 1 and 0, you can capture any integer you like:

• 0, 1, 2, 3, 4, 5... -> 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 101110, 101111, 110000, 110001, 110010, 110011, 110100, 110101, 110110, 110111, 111000, 111001, 111010, 111011, 111100, 111101, 111110, 111111...


Here are a few famous decimal numbers in binary:

• 23 = 10111 in binary
• 666 = 1010011010 in binary
• 1492 = 10111010100 in binary
• 2001 = 11111010001 in binary

As you can see, there’s a problem with binary for human beings. It takes up a lot of space and doesn’t look very distinctive. But that’s easy to solve by converting binary into octal (base 8) or hexadecimal (base 16). One digit in octal is worth three digits in binary and one digit in hexadecimal is worth four digits in binary. So the conversion back and forth is very easy:

• 23 = 10111 → (010,111) → 27 in octal
• 23 = 10111 → (0001,0111) → 17 in hexadecimal
• 666 = 1010011010 → (001,010,011,010) → 1232 in octal
• 666 = 1010011010 → (0010,1001,1010) → 29A in hexademical
• 1492 = 10111010100 → (010,111,010,100) → 2724 in octal
• 1492 = 10111010100 → (0101,1101,0100) → 5D4 in hexademical
• 2001 = 11111010001 → (011,111,010,001) → 3721 in octal
• 2001 = 11111010001 → (0111,1101,0001) → 7D1 in hexademical

But there’s another way to compress a binary number: count the lengths of the runs of 1 and 0. For example, 23 = 10111 and 10111 → one 1, one 0, three 1s → (1,1,3) → 113. That’s not much of a compression, but it usually gets better as the numbers get bigger:

• 2001 = 11111010001 → (5,1,1,3,1) → 51131

From the compressed form you can easily re-create the binary number:

• 51131 → (5,1,1,3,1) → (11111,0,1,000,1) → 11111010001

This block-compression doesn’t work with any other standard base. For example, the compressed form (1,2) in ternary, or base 3, is ambiguous:

• (1,2) → (1,00) → 100 in base 3 = 09 in decimal
• (1,2) → (1,22) → 122 in base 3 = 17 in decimal
• (1,2) → (2,00) → 200 in base 3 = 18 in decimal
• (1,2) → (2,11) → 211 in base 3 = 22 in decimal

The higher the base, the bigger the ambiguity. But ambiguity exists with binary block-compressions too. Look at 51131 ← 11111010001 = 2001 in decimal. Out of context, 51131 is infinitely ambiguous. It could represent a number in any base higher than 5:

• 51131 in base 06 = 006751 in base 10
• 51131 in base 07 = 012419 in base 10
• 51131 in base 08 = 021081 in base 10
• 51131 in base 09 = 033643 in base 10
• 51131 in base 10 = 051131 in base 10
• 51131 in base 11 = 074691 in base 10
• 51131 in base 12 = 105589 in base 10
• 51131 in base 13 = 145211 in base 10
• 51131 in base 14 = 195063 in base 10
• 51131 in base 15 = 256771 in base 10
• 51131 in base 16 = 332081 in base 10
• 51131 in base 17 = 422859 in base 10
• 51131 in base 18 = 531091 in base 10
• 51131 in base 19 = 658883 in base 10
• 51131 in base 20 = 808461 in base 10...

But that ambiguity raises an interesting question. Does the binary block-compression of n ever match the digits of n in another base? Yes, it does:

• 23 = 10111 in base 2 → (1,1,3) and 113 in base 4 = 10111 in base 2 = 23 in base 10

113 in base 4 = 1*4^2 + 1*4 + 3*4^0 = 16+4+3 = 23. You could call this “Block’n’Role”, because the blocks of 1 and 0 allow a binary number to retain its identity but take on a different role, that is, represent a number in a different base. Here’s a list of binary block-numbers that match the digits of n in another base:

• 10111 → (1,1,3) = 113 in base 4 (n=23)
• 11001 → (2,2,1) = 221 in base 3 (n=25)
• 101100 → (1,1,2,2) = 1122 in base 3 (n=44)
• 111001 → (3,2,1) = 321 in base 4 (n=57)
• 1011111 → (1,1,5) = 115 in base 9 (n=95)
• 1100001 → (2,4,1) = 241 in base 6 (n=97)
• 11100001 → (3,4,1) = 341 in base 8 (n=225)
• 100110000 → (1,2,2,4) = 1224 in base 6 (n=304)
• 101110111 → (1,1,3,1,3) = 11313 in base 4 (n=375)
• 111111001 → (6,2,1) = 621 in base 9 (n=505)
• 1110010111 → (3,2,1,1,3) = 32113 in base 4 (n=919)
• 10000011111 → (1,5,5) = 155 in base 30 (n=1055)
• 11111100001 → (6,4,1) = 641 in base 18 (n=2017)
• 1011101110111 → (1,1,3,1,3,1,3) = 1131313 in base 4 (n=6007)
• 11100101110111 → (3,2,1,1,3,1,3) = 3211313 in base 4 (n=14711)
• 10111011101110111 → (1,1,3,1,3,1,3,1,3) = 113131313 in base 4 (n=96119)
• 111001011101110111 → (3,2,1,1,3,1,3,1,3) = 321131313 in base 4 (n=235383)
• 100000111111111000001 → (1,5,9,5,1) = 15951 in base 31 (n=1081281)
• 101110111011101110111 → 11313131313 in b4 = 1537911
• 1110010111011101110111 → 32113131313 in b4 = 3766135
• 1011101110111011101110111 → 1131313131313 in b4 = 24606583
• 11100101110111011101110111 → 3211313131313 in b4 = 60258167
• 10111011101110111011101110111 → 113131313131313 in b4 = 393705335
• 111001011101110111011101110111 → 321131313131313 in b4 = 964130679

The list of block-nums is incomplete, because I’ve skipped some trivial examples where, for all powers 2^p > 2^2, the block-num is “1P” in base b = (2^p – p). For example:

• 2^3 = 08 = 1000 in base 2 → (1,3) and 13 in base 5 = 8, where 5 = 2^3-3 = 8-3
• 2^4 = 16 = 10000 in base 2 → (1,4) and 14 in base 12 = 16, where 12 = 2^4-4 = 16-4
• 2^5 = 32 = 100000 in base 2 → (1,5) and 15 in base 27 = 32, where 27 = 2^5-5 = 32-5
• 2^6 = 64 = 1000000 in base 2 → (1,6) and 16 in base 58 = 64, where 58 = 2^6-6 = 64-6

And note that the block-num matches in base 4 continue for ever, because the pairs 113… and 321… generate their successors using simple formulae in base 4:

• 113... * 100 + 13
• 321... * 100 + 13

For example, 113 and 321 are the first pair of matches:

• 10111 → (1,1,3) = 113 in base 4 (n=23)
• 111001 → (3,2,1) = 321 in base 4 (n=57)

In base 4, 113 * 100 + 13 = 11313 and 321 * 100 + 13 = 32113:

• 101110111 → (1,1,3,1,3) = 11313 in base 4 (n=375)
• 1110010111 → (3,2,1,1,3) = 32113 in base 4 (n=919)

Next, 11313 * 100 + 13 = 1131313 and 32113 * 100 + 13 = 3211313:

• 1011101110111 → (1,1,3,1,3,1,3) = 1131313 in base 4 (n=6007)
• 11100101110111 → (3,2,1,1,3,1,3) = 3211313 in base 4 (n=14711)

And so on.

Weight-Botchers

Suppose you have a balance scale and four weights of 1 unit, 2 units, 4 units and 8 units. How many different weights can you match? If you know binary arithmetic, it’s easy to see that you can match any weight up to fifteen units inclusive. With the object in the left-hand pan of the scale and the weights in the right-hand pan, these are the matches:

01 = 1
02 = 2
03 = 2+1
04 = 4
05 = 4+1
06 = 4+2
07 = 4+2+1
08 = 8
09 = 8+1
10 = 8+2
11 = 8+2+1
12 = 8+4
13 = 8+4+1
14 = 8+4+2
15 = 8+4+2+1

Balance scale


The weights that sum to n match the 1s in the digits of n in binary.

01 = 0001 in binary
02 = 0010 = 2
03 = 0011 = 2+1
04 = 0100 = 4
05 = 0101 = 4+1
06 = 0110 = 4+2
07 = 0111 = 4+2+1
08 = 1000 = 8
09 = 1001 = 8+1
10 = 1010 = 8+2
11 = 1011 = 8+2+1
12 = 1100 = 8+4
13 = 1101 = 8+4+1
14 = 1110 = 8+4+2
15 = 1111 = 8+4+2+1

But there’s another set of four weights that will match anything from 1 unit to 40 units. Instead of using powers of 2, you use powers of 3: 1, 3, 9, 27. But how would you match an object weighing 2 units using these weights? Simple. You put the object in the left-hand scale, the 3-weight in the right-hand scale, and then add the 1-weight to the left-hand scale. In other words, 2 = 3-1. Similarly, 5 = 9-3-1, 6 = 9-3 and 7 = 9-3+1. When the power of 3 is positive, it’s in the right-hand pan; when it’s negative, it’s in the left-hand pan.

This system is actually based on base 3 or ternary, which uses three digits, 0, 1 and 2. However, the relationship between ternary numbers and the sums of positive and negative powers of 3 is more complicated than the relationship between binary numbers and sums of purely positive powers of 2. See if you can work out how to derive the sums in the middle from the ternary numbers on the right:

01 = 1 = 1 in ternary
02 = 3-1 = 2
03 = 3 = 10
04 = 3+1 = 11
05 = 9-3-1 = 12
06 = 9-3 = 20
07 = 9-3+1 = 21
08 = 9-1 = 22
09 = 9 = 100
10 = 9+1 = 101
11 = 9+3-1 = 102
12 = 9+3 = 110
13 = 9+3+1 = 111
14 = 27-9-3-1 = 112
15 = 27-9-3 = 120
16 = 27-9-3+1 = 121
17 = 27-9-1 = 122
18 = 27-9 = 200
19 = 27-9+1 = 201
20 = 27-9+3-1 = 202
21 = 27-9+3 = 210
22 = 27-9+3+1 = 211
23 = 27-3-1 = 212
24 = 27-3 = 220
25 = 27-3+1 = 221
26 = 27-1 = 222
27 = 27 = 1000
28 = 27+1 = 1001
29 = 27+3-1 = 1002
30 = 27+3 = 1010
31 = 27+3+1 = 1011
32 = 27+9-3-1 = 1012
33 = 27+9-3 = 1020
34 = 27+9-3+1 = 1021
35 = 27+9-1 = 1022
36 = 27+9 = 1100
37 = 27+9+1 = 1101
38 = 27+9+3-1 = 1102
39 = 27+9+3 = 1110
40 = 27+9+3+1 = 1111

To begin understanding the sums, consider those ternary numbers containing only 1s and 0s, like n = 1011[3], which equals 31 in decimal. The sum of powers is straightforward, because all of them are positive and they’re easy to work out from the digits of n in ternary: 1011 = 1*3^3 + 0*3^2 + 1*3^1 + 1*3^0 = 27+3+1. Now consider n = 222[3] = 26 in decimal. Just as a decimal number consisting entirely of 9s is always 1 less than a power of 10, so a ternary number consisting entirely of 2s is always 1 less than a power of three:

999 = 1000 - 1 = 10^3 - 1 (decimal)
222 = 1000[3] - 1 (ternary) = 26 = 27-1 = 3^3 - 1 (decimal)

If a ternary number contains only 2s and is d digits long, it will be equal to 3^d – 1. But what about numbers containing a mixture of 2s, 1s and 0s? Well, all ternary numbers containing at least one 2 will have a negative power of 3 in the sum. You can work out the sum by using the following algorithm. Suppose the number is five digits long and the rightmost digit is digit #1 and the leftmost is digit #5:

01. i = 1, sum = 0, extra = 0, posi = true.
02. if posi = false, goto step 07.
03. if digit #i = 0, sum = sum + 0.
04. if digit #i = 1, sum = sum + 3^(i-1).
05. if digit #i = 2, sum = sum - 3^(i-1), extra = 3^5, posi = false.
06. goto step 10.
07. if digit #i = 0, sum = sum + 3^(i-1), extra = 0, posi = true.
08. if digit #i = 1, sum = sum - 3^(i-1).
09. if digit #i = 2, sum = sum + 0.
10. i = i+1. if i <= 5, goto step 2.
11. print sum + extra.

As the number of weights grows, the advantages of base 3 get bigger:

With 02 weights, base 3 reaches 04 and base 2 reaches 3: 04-3 = 1.
With 03 weights, base 3 reaches 13 and base 2 reaches 7: 13-7 = 6.
With 04 weights, 000040 - 0015 = 000025
With 05 weights, 000121 - 0031 = 000090
With 06 weights, 000364 - 0063 = 000301
With 07 weights, 001093 - 0127 = 000966
With 08 weights, 003280 - 0255 = 003025
With 09 weights, 009841 - 0511 = 009330
With 10 weights, 029524 - 1023 = 028501
With 11 weights, 088573 - 2047 = 086526
With 12 weights, 265720 - 4095 = 261625...

But what about base 4, or quaternary? With four weights of 1, 4, 16 and 64, representing powers of 4 from 4^0 to 4^3, you should be able to weigh objects from 1 to 85 units using sums of positive and negative powers. In fact, some weights can’t be matched. As you can see below, if n in base 4 contains a 2, it can’t be represented as a sum of positive and negative powers of 4. Nor can certain other numbers:

1 = 1 ← 1
2 has no sum = 2
3 = 4-1 ← 3
4 = 4 ← 10 in base 4
5 = 4+1 ← 11 in base 4
6 has no sum = 12 in base 4
7 has no sum = 13
8 has no sum = 20
9 has no sum = 21
10 has no sum = 22
11 = 16-4-1 ← 23
12 = 16-4 ← 30
13 = 16-4+1 ← 31
14 has no sum = 32
15 = 16-1 ← 33
16 = 16 ← 100
17 = 16+1 ← 101
18 has no sum = 102
19 = 16+4-1 ← 103
20 = 16+4 ← 110
21 = 16+4+1 ← 111
22 has no sum = 112
23 has no sum = 113
24 has no sum = 120
25 has no sum = 121
26 has no sum = 122
27 has no sum = 123
[...]

With a more complicated balance scale, it’s possible to use weights representing powers of base 4 and base 5 (use two pans on each arm of the scale instead of one, placing the extra pan at the midpoint of the arm). But with a standard balance scale, base 3 is the champion. However, there is a way to do slightly better than standard base 3. You do it by botching the weights. Suppose you have four weights of 1, 4, 10 and 28 (representing 1, 3+1, 9+1 and 27+1). There are some weights n you can’t match, but because you can match n-1 and n+1, you know what these unmatchable weights are. Accordingly, while weights of 1, 3, 9 and 27 can measure objects up to 40 units, weights of 1, 4, 10 and 28 can measure objects up to 43 units:

1 = 1 ← 1
2 has no sum = 2
3 = 4-1 ← 10 in base 3
4 = 4 ← 11 in base 3
5 = 4+1 ← 12 in base 3
6 = 10-4 ← 20
7 = 10-4+1 ← 21
8 has no sum = 22
9 = 10-1 ← 100
10 = 10 ← 101
11 = 10+1 ← 102
12 has no sum = 110
13 = 10+4-1 ← 111
14 = 10+4 ← 112
15 = 10+4+1 ← 120
16 has no sum = 121
17 = 28-10-1 ← 122
18 = 28-10 ← 200
19 = 28-10+1 ← 201
20 has no sum = 202
21 = 28-10+4-1 ← 210
22 = 28-10+4 ← 211
23 = 28-4-1 ← 212
24 = 28-4 ← 220
25 = 28-4+1 ← 221
26 has no sum = 222
27 = 28-1 ← 1000
28 = 28 ← 1001
29 = 28+1 ← 1002
30 has no sum = 1010
31 = 28+4-1 ← 1011
32 = 28+4 ← 1012
33 = 28+4+1 ← 1020
34 = 28+10-4 ← 1021
35 = 28+10-4+1 ← 1022
36 has no sum = 1100
37 = 28+10-1 ← 1101
38 = 28+10 ← 1102
39 = 28+10+1 ← 1110
40 = has no sum = 1111*
41 = 28+10+4-1 ← 1112
42 = 28+10+4 ← 1120
43 = 28+10+4+1 ← 1121


*N.B. 40 = 82-28-10-4, i.e. has a sum when another botched weight, 82 = 3^4+1, is used.

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

Mice Thrice

Twice before on Overlord-in-terms-of-Core-Issues-around-Maximal-Engagement-with-Key-Notions-of-the-Über-Feral, I’ve interrogated issues around pursuit curves. Imagine four mice or four beetles each sitting on one corner of a square and looking towards the centre of the square. If each mouse or beetle begins to run towards the mouse or beetle to its left, it will follow a curving path that takes it to the centre of the square, like this:

vertices = 4, pursuit = +1


The paths followed by the mice or beetles are pursuit curves. If you arrange eight mice clockwise around a square, with a mouse on each corner and a mouse midway along each side, you get a different set of pursuit curves:

v = 4 + 1 on the side, p = +1


Here each mouse is pursuing the mouse two places to its left:

v = 4+s1, p = +2


And here each mouse is pursuing the mouse three places to its left:

v = 4+s1, p = +3


Now try a different arrangement of the mice. In the square below, the mice are arranged clockwise in rows from the bottom right-hand corner. That is, mouse #1 begins on the bottom left-hand corner, mouse #2 begins between that corner and the centre, mouse #3 begins on the bottom left-hand corner, and so on. When each mice runs towards the mouse three places away, these pursuit curves appear:

v = 4 + 1 internally, p = +3


Here are some more:

v = 4 + i1, p = +5


v = 4 + i2, p = +1


v = 4 + i2, p = +2


So far, all the mice have eventually run to the centre of the square, but that doesn’t happen here:

v = 4 + i2, p = 4


Here are more pursuit curves for the v4+i2 mice, using an animated gif:

v = 4 + i2, p = various (animated — open in new tab for clearer image)


And here are more pursuit curves that don’t end in the centre of the square:

v = 4 + i4, p = 4


v = 4 + i4, p = 8


v = 4 + i4, p = 12


v = 4 + i4, p = 16


But the v4+i4 pursuit curves more usually look like this:

v = 4 + i4, p = 7


Now try adapting the rules so that mice don’t run directly towards another mouse, but towards the point midway between two other mice. In this square, the odd- and even-numbered mice follow different rules. Mice #1, #3, #5 and #7 run towards the point midway between the mice one and two places away, while ice #2, #4, #6 and #8 run towards the point midway between the mice two and seven places away:

v = 4 + s1, p(1,3,5,7) = 1,2, p(2,4,6,8) = 2,7


I think the curves are very elegant. Here’s a slight variation:

v = 4 + s1, p1 = 1,3, p2 = 2,7


Now try solid curves:

v = 4 + s1, p1 = 1,3, p2 = 2,7 (red)


v = 4 + s1, p1 = 1,3, p2 = 2,7 (yellow-and-blue)


And some variants:

v = 4 + s1, p1 = 1,7, p2 = 1,2


v = 4 + s1, p1 = 2,3, p2 = 2,5


v = 4 + s1, p1 = 5,6, p2 = 1,3


v = 4 + s1, p1 = 5,6, p2 = 1,4


v = 4 + s1, p1 = 5,6, p2 = 1,6


Elsewhere other-posted:

Polymorphous Pursuit
Persecution Complex