taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.8-36

Exercise 1.2.8-36

not stated yet in Lean solution written

RatingM32
MarkersM (mathematical)
KindInformal: the exercise has no formal statement, so Lean does not state it from the written solution
SectionSection 1.2.8 of Volume 1. Companion chapter: Fibonacci numbers

The task

Find properties of the Fibonacci strings S1=aS_1 = a, S2=bS_2 = b, Sn+2=Sn+1SnS_{n+2} = S_{n+1}S_n: where double letters occur, what the kkth letter is, and the density of the letters bb.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

Write out S3,…,S8S_3, \ldots, S_8 and look at them. Count letters.

Hint 2

Find a rule that turns SnS_n into Sn+1S_{n+1} letter by letter.

Solution

Show the solution

The first strings are S3=baS_3 = ba, S4=babS_4 = bab, S5=babbaS_5 = babba, S6=babbababS_6 = babbabab, S7=babbababbabbaS_7 = babbababbabba. Facts, with proofs where they are short:

Length and counts. SnS_n has FnF_n letters. For n≥2n \ge 2 it has Fn−1F_{n-1} letters bb and Fn−2F_{n-2} letters aa: the pairs of counts for n=2,…,8n = 2, \ldots, 8 are (1,0),(1,1),(2,1),(3,2),(5,3),(8,5),(13,8)(1,0), (1,1), (2,1), (3,2), (5,3), (8,5), (13,8) as (#b,#a)(\#b, \#a), and the rule Sn+2=Sn+1SnS_{n+2} = S_{n+1}S_n makes both counts follow the Fibonacci rule.

A substitution. Let σ\sigma replace each aa by bb and each bb by baba. Then Sn+1=σ(Sn)S_{n+1} = \sigma(S_n) for n≥1n \ge 1. Indeed σ(S1)=b=S2\sigma(S_1) = b = S_2 and σ(S2)=ba=S3\sigma(S_2) = ba = S_3. If it holds for nn and n+1n + 1, then σ(Sn+2)=σ(Sn+1)σ(Sn)=Sn+2Sn+1=Sn+3\sigma(S_{n+2}) = \sigma(S_{n+1})\sigma(S_n) = S_{n+2}S_{n+1} = S_{n+3}.

Double letters. The string aaaa never occurs, and bbbbbb never occurs. In Sn+1=σ(Sn)S_{n+1} = \sigma(S_n) the string is made of the blocks bb and baba, so every aa is preceded by bb, and aaaa never appears. A factor bbbbbb would need two blocks bb followed by a block that starts with bb, that is, a factor aaaa in SnS_n. By induction neither occurs. The letters bbbb do occur, for example in S5S_5.

The infinite string. Since Sn+1=SnSn−1S_{n+1} = S_nS_{n-1}, each SnS_n is a prefix of Sn+1S_{n+1} for n≥2n \ge 2. So there is an infinite string S∞S_\infty with SnS_n as the prefix of length FnF_n. Its first letters are babbababbabbababbababbabbababbabba…babbababbabbababbababbabbababbabba\ldots.

The kkth letter. Write kk in the Fibonacci number system of Exercise 1.2.8-34 and let FsF_s be its smallest term. Then the kkth letter is bb if ss is even and aa if ss is odd. Proof by induction on kk. For Fn+1<k<Fn+2F_{n+1} < k < F_{n+2} the letter at kk is the letter at k−Fn+1k - F_{n+1}, because Sn+2=Sn+1SnS_{n+2} = S_{n+1}S_n and SnS_n is a prefix of S∞S_\infty (here k−Fn+1<Fnk - F_{n+1} < F_n). The Fibonacci representation of kk is Fn+1F_{n+1} plus that of k−Fn+1k - F_{n+1}, with the same smallest term. For k=Fn+1k = F_{n+1} the letter is the last letter of Sn+1S_{n+1}. The last letter of SmS_m is the last letter of Sm−2S_{m-2}, so it is bb for even mm and aa for odd mm. This matches the rule, since the smallest term of Fn+1F_{n+1} is Fn+1F_{n+1} itself.

Counting the letters bb. Let B(k)B(k) be the number of letters bb among the first kk. Take k=Fk1+⋯+Fkrk = F_{k_1} + \cdots + F_{k_r} in the Fibonacci system. The prefix of length kk is Sk1S_{k_1} followed by a prefix of length k−Fk1k - F_{k_1} (since Sk1+1=Sk1Sk1−1S_{k_1+1} = S_{k_1}S_{k_1-1}, and Sk1−1S_{k_1-1} is a prefix of S∞S_\infty). So B(k)=Fk1−1+B(k−Fk1)B(k) = F_{k_1-1} + B(k - F_{k_1}), and B(k)=∑iFki−1B(k) = \sum_iF_{k_i-1}. By Exercise 1.2.8-41 this is ⌊(k+1)/ϕ⌋\lfloor(k+1)/\phi\rfloor. So the number of bb among the first kk letters is ⌊(k+1)/ϕ⌋\lfloor(k+1)/\phi\rfloor, and the density of the letters bb tends to 1/ϕ=0.6180…1/\phi = 0.6180\ldots. The density of the letters aa is 1/ϕ2=0.3820…1/\phi^2 = 0.3820\ldots.

Where the letters are. The kkth letter is bb if and only if ⌊(k+1)/ϕ⌋−⌊k/ϕ⌋=1\lfloor(k+1)/\phi\rfloor - \lfloor k/\phi\rfloor = 1. The jjth letter bb is at the least kk with (k+1)/ϕ≥j(k+1)/\phi \ge j, that is k=⌈jϕ⌉−1=⌊jϕ⌋k = \lceil j\phi\rceil - 1 = \lfloor j\phi\rfloor. So the letters bb are at the places ⌊jϕ⌋=1,3,4,6,8,9,…\lfloor j\phi\rfloor = 1, 3, 4, 6, 8, 9, \ldots. The sequences ⌊jϕ⌋\lfloor j\phi\rfloor and ⌊jϕ2⌋\lfloor j\phi^2\rfloor are complementary (Beatty), because 1/ϕ+1/ϕ2=11/\phi + 1/\phi^2 = 1. So the letters aa are at the places ⌊jϕ2⌋=2,5,7,10,13,…\lfloor j\phi^2\rfloor = 2, 5, 7, 10, 13, \ldots. A python test confirms the rule for the smallest term, the formula ⌊jϕ⌋\lfloor j\phi\rfloor and ⌊jϕ2⌋\lfloor j\phi^2\rfloor for the first 5000 letters.

Two more facts. SnSn+1S_nS_{n+1} and Sn+1SnS_{n+1}S_n differ only in the last two letters, which are abab in one and baba in the other, for 2≤n≤132 \le n \le 13 (python), and in general by induction from Sn+2=Sn+1SnS_{n+2} = S_{n+1}S_n. The string SnS_n without its last two letters is a palindrome for 3≤n≤153 \le n \le 15 (python).

Remarks

The infinite string is the Fibonacci word. It is a Sturmian sequence: the count of bb in each window of fixed length takes at most two values. The places ⌊jϕ⌋\lfloor j\phi\rfloor of the letters bb form the lower Wythoff sequence.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.