The Fibonacci Repequence

Start with 0 and 1, then add the previous two numbers, then repeat. What do you get? You get the Fibonacci sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155,…

Apart from the two 1s, every number in the Fibonacci sequence is unique. But what about the leftmost digits of the Fibonacci numbers? If you think about it, you’ll see that they have to fall into a repeating pattern, like this:

0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, 7, 4, 1, 5, 6, 1, 7, 8, 5, 3, 8, 1, 9, 0, 9, 9, 8, 7, 5, 2, 7, 9, 6, 5, 1, 6, 7, 3, 0, 3, 3, 6, 9, 5, 4, 9, 3, 2, 5, 7, 2, 9, 1, 0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, 7, 4, 1, 5, 6, 1, 7, 8, 5, 3, 8, 1, 9, 0, 9, 9, 8, 7, 5, 2, 7, 9, 6, 5,

But that’s in base 10. Here’s the Fibonacci sequence in some other bases:

b02: 1, 1, 10, 11, 101, 1000, 1101, 10101, 100010, 110111, 1011001, 10010000, 11101001, 101111001, 1001100010,…
b03: 1, 1, 2, 10, 12, 22, 111, 210, 1021, 2001, 10022, 12100, 22122, 111222, 211121,…
b04: 1, 1, 2, 3, 11, 20, 31, 111, 202, 313, 1121, 2100, 3221, 11321, 21202,…
b05: 1, 1, 2, 3, 10, 13, 23, 41, 114, 210, 324, 1034, 1413, 3002, 4420,…
b06: 1, 1, 2, 3, 5, 12, 21, 33, 54, 131, 225, 400, 1025, 1425, 2454,…
b07: 1, 1, 2, 3, 5, 11, 16, 30, 46, 106, 155, 264, 452, 1046, 1531,…
b08: 1, 1, 2, 3, 5, 10, 15, 25, 42, 67, 131, 220, 351, 571, 1142,…
b09: 1, 1, 2, 3, 5, 8, 14, 23, 37, 61, 108, 170, 278, 458, 747,…
b10: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610,…

And here are the trailing digits in the other bases:

b02: 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0,…
b03: 0, 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2, 1, 0, 1, 1, 2, 0, 2, 2,…
b04: 0, 1, 1, 2, 3, 1, 0, 1, 1, 2, 3, 1, 0, 1, 1, 2, 3, 1, 0, 1, 1, 2, 3, 1, 0, 1, 1, 2, 3, 1, 0,…
b05: 0, 1, 1, 2, 3, 0, 3, 3, 1, 4, 0, 4, 4, 3, 2, 0, 2, 2, 4, 1, 0, 1, 1, 2, 3, 0, 3, 3, 1, 4, 0,…
b06: 0, 1, 1, 2, 3, 5, 2, 1, 3, 4, 1, 5, 0, 5, 5, 4, 3, 1, 4, 5, 3, 2, 5, 1, 0, 1, 1, 2, 3, 5, 2,…
b07: 0, 1, 1, 2, 3, 5, 1, 6, 0, 6, 6, 5, 4, 2, 6, 1, 0, 1, 1, 2, 3, 5, 1, 6, 0, 6, 6, 5, 4, 2, 6,…
b08: 0, 1, 1, 2, 3, 5, 0, 5, 5, 2, 7, 1, 0, 1, 1, 2, 3, 5, 0, 5, 5, 2, 7, 1, 0, 1, 1, 2, 3, 5, 0,…
b09: 0, 1, 1, 2, 3, 5, 8, 4, 3, 7, 1, 8, 0, 8, 8, 7, 6, 4, 1, 5, 6, 2, 8, 1, 0, 1, 1, 2, 3, 5, 8,…
b10: 0, 1, 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, 7, 4, 1, 5, 6, 1, 7, 8, 5, 3, 8, 1, 9, 0,…

But what are the relative counts for those trailing digits? You can show them on a graph. Here’s the graph for the relative counts of trailing digits in base 10:

Count of trailing fib-digits in base 10 = 2*5


The blue dot marks the count for the digit 1, with the count for the digit 0 to its left. The green dot marks the digit 5 and the red dot marks the digit 10. Of course, there is no single digit for 10 in base 10, but to make the graph symmetrical I’ve reproduced the column for 0. However, it’s impossible to make a digit-count graph symmetrical for all base b, as you can see here:

Relative count of trailing fib-digits in base 2 (prime)


Relative count of trailing fib-digits in base 3 (prime)


Fibdig-counts in base 4 = 2^2


Fibdig-counts in base 5 (prime)


Fibdig-counts in base 6 = 2.3


Fibdig-counts in base 7 (prime)


Fibdig-counts in base 8 = 2^3


Fibdig-counts in base 9 = 3^2


Count of trailing fib-digits in base 10 = 2*5


Some graphs are symmetrical, some are not; some digits occur for fibnum(i) mod base, some don’t. Here are some more of the symmetrical graphs in higher bases:

Fibdig-counts in base 23 (prime)


Fibdig-counts in base 30 = 2.3.5


Fibdig-counts in base 70 = 2.5.7


Fibdig-counts in base 98 = 2.7^2


Fibdig-counts in base 104 = 2^3.13


It’s also interesting to see the behavior of bases that are themselves Fibonacci numbers. The lower trailing digits of fibnum(i) match the Fibonacci numbers themselves — 0, 1, 2, 3, 5, 8, 13, 21, … — skipping those numbers that aren’t Fibonacci numbers. And symmetrical graphs are interspersed with asymmetrical ones:

Fibdig-counts in base 34 = 2.17


Fibdig-counts in base 55 = 5.11


Fibdig-counts in base 89 (prime)


Fibdig-counts in base 144 = 2^4.3^2

Fibdig-counts in base 233 (prime)


Fibdig-counts in base 377 = 13.29


Fibdig-counts in base 610 = 2.5.61


The patterns for bases that are Fibonacci numbers are echoed by the patterns for bases that are Lucas numbers, which are formed in the same way as Fibonacci numbers but are seeded with (2, 1) rather than (0, 1):

2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521, 843, 1364, 2207, 3571, 5778, 9349, 15127, 24476, 39603, 64079, 103682, 167761, 271443, 439204, 710647, 1149851, 1860498, 3010349, 4870847, 7881196, 12752043, 20633239, 33385282, 54018521, 87403803, … — Lucas numbers, A000032 at the Online Encyclopedia of Integer Sequences

Here are some graphs in bases that are Lucas numbers:

Fibdig-counts in base 47 (prime)


Fibdig-counts in base 76 = 2.23


Fibdig-counts in base 123 = 3.41


Performativizing Palindromicity

Geometry is a jack-in-the-box. Things jump out at you from a graph or other image that don’t jump out from raw numbers. But geometry applies to raw numbers too. And to letters. A palindrome is defined geometrically: it’s a number or word that reads the same forwards and backwards:

232, 7143417, 80108, 969

pip, sees, Malayalam
A man, a plan, a canal — Panama!
Satan, oscillate my metallic sonatas!

But how fast can you spot the ever-lengthening palindromes here?

1, 1, 1, 2, 2, 1, 2, 3, 3, 2, 1, 2, 4, 2, 3, 4, 4, 3, 2, 4, 2, 1, 2, 3, 6, 4, 2, 4, 6, 3, 4, 5, 5, 4, 3, 6, 4, 2, 4, 6, 3, 2, 1, 2, 4, 2, 3, 4, 8, 6, 4, 8, 4, 2, 4, 6, 9, 6, 3, 6, 8, 4, 5, 6, 6, 5, 4, 8, 6, 3, 6, 9, 6, 4, 2, 4, 8, 4, 6, 8, 4, 3, 2, 4, 2, 1, 2, 3, 6, 4, 2, 4, 6, 3, 4, 5, 10, 8, 6, 12, 8, 4, 8

As the palindromes get longer, the eye gets lazier:

1
1, 1
1, 1, 1
1, 2, 2, 1
2, 1, 2, 3, 3, 2, 1, 2
3, 2, 1, 2, 4, 2, 3, 4, 4, 3, 2, 4, 2, 1, 2, 3
4, 3, 2, 4, 2, 1, 2, 3, 6, 4, 2, 4, 6, 3, 4, 5, 5, 4, 3, 6, 4, 2, 4, 6, 3, 2, 1, 2, 4, 2, 3, 4

What is that sequence of numbers? It’s sequence A167489 at the Online Encyclopedia of Integer Sequences (OEIS), where it’s defined as the “Product of run lengths in binary representation of n”. That is, you find the lengths of the runs of 1 and 0 in a binary number and multiply the lengths like this:

4 in base 10 = 100 in base 2 → one 1, two 0s -> 1 * 2 = 2
5 in b10 = 101 in b2 → one 1, one 0, one 1 -> 1 * 1 * 1 = 1
6 in b10 = 110 in b2 → two 1s, one 0 -> 2 * 1 = 2
7 = 111 → 3
8 = 1000 → 1 * 3 = 3
9 = 1001 → 1 * 2 * 1 = 2
10 = 1010 → 1 * 1 * 1 * 1 = 1
11 = 1011 → 1 * 1 * 2 = 2

The products are palindromic: 2, 1, 2, 3, 3, 2, 1, 2. But it’s much easier to spot those palindromic products in a graph:

Product of run lengths in binary representation of n = 1..1833, A167489 at the OEIS
(click for larger)


Some marked palindromes in run-length products of binary n (white dots mark the center of the red and purple palindromes)


Because the lines in each row are adjusted to fit the same maximum height, the palindromes that extend over two rows start higher than they end, as it were:

Palindrome for n = 10000000..101111111 in base 2 = 128..383 in base 10


Palindrome for n = 100000000..1011111111 in b2 = 256..767


Palindrome for n = 1000000000..10111111111 in b2 = 512..1535


As you can see, each palindrome starts at a power of two, 2^p, but ends beyond the next power of two, 2^(p+1), so the palindromes overlap:

Overlapping palindromes in the first row


Here’s an animation of the overlapping palindromes (note again that the longer ones start higher than they end):

Overlapping palindromes, n = 1..1833 (animated at ezGif)


When the palindromes are represented individually, they grow like this:

Palindrome for n = 10..101 in base 2 = 2..5 in base 10


Palindrome for n = 100..1011 in b2 = 4..11 in b10


Palindrome for n = 1000..10111 in b2 = 8..23 in b10


Palindrome for n = 10000..101111 in b2 = 16..47


Palindrome for n = 100000..1011111 in b2 = 32..95


Palindrome for n = 1000000..10111111 in b264..191


Palindrome for n = 10000000..101111111 in b2 = 128..383


Palindrome for n = 100000000..1011111111 in b2 = 256..767


And related palindromes occur in other bases. In base 3, where you find the run-lengths of 0, 1 and 2, they’re related to powers of 3 (inter alia):

Palindrome for n = 10..212 in b3 = 3..23 in b10


Palindrome for n = 100..2122 in b3 = 9..71 in b10


And in bases 4 and 5, where you find the run-lengths of 0, 1, 2, 3, (4), they’re related to powers of 4 and 5:

Palindrome for n = 10..323 in b4 = 4..59 in b10


Palindrome for n = 100.. in b4 = 16..3233 in b10


Palindrome for n = 10..434 in b5 = 5..119 in b10


Palindrome for n = 100..4344 in b5 = 25..599 in b10