taocp

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

Volume P2 · Concrete mathematics

Fibonacci numbers

Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.

Read first
Contents
  1. Identities of the Fibonacci numbers
  2. Divisibility of the Fibonacci numbers
  3. The golden ratio and Zeckendorf's theorem

Identities of the Fibonacci numbers

Statement

The Fibonacci numbers satisfy a large number of identities. Most have a short proof by induction on the recurrence, and most have a second proof from the matrix form. This section proves the main ones and ends with a fast algorithm.

Definition P2.10.1 (the Fibonacci numbers, TAOCP eqs. 1.2.8(1) and 1.2.8(2)). The Fibonacci numbers are given by F0=0F_0 = 0, F1=1F_1 = 1 and Fn+2=Fn+1+FnF_{n+2} = F_{n+1} + F_n for n≥0n \ge 0.

Example P2.10.2. The first values are n012345678910Fn011235813213455\begin{array}{c|ccccccccccc} n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ \hline F_n & 0 & 1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 34 & 55 \end{array} and F11,…,F20F_{11}, \dots, F_{20} are 8989, 144144, 233233, 377377, 610610, 987987, 15971597, 25842584, 41814181, 67656765. Also F30=832040F_{30} = 832040.

Example P2.10.3. The numbers count the compositions of nn into 11s and 22s. For n=4n = 4 the compositions are 1+1+1+11+1+1+1, 1+1+21+1+2, 1+2+11+2+1, 2+1+12+1+1 and 2+22+2, so there are 5=F55 = F_5. The last part of a composition of nn is 11 or 22, so the count cnc_n satisfies cn=cn−1+cn−2c_n = c_{n-1} + c_{n-2}, with c0=1c_0 = 1 and c1=1c_1 = 1. Hence cn=Fn+1c_n = F_{n+1}.

Theorem P2.10.4 (sums of the first terms). For every n≥0n \ge 0, ∑k=0nFk=Fn+2−1,∑k=1nFk2=FnFn+1.\sum_{k=0}^{n}F_k = F_{n+2} - 1, \qquad \sum_{k=1}^{n}F_k^2 = F_nF_{n+1}.

Lean: not stated.

Proof. Both are proved by induction on nn. For the first sum, n=0n = 0 gives 0=F2−10 = F_2 - 1. If the claim holds for nn, then ∑k=0n+1Fk=Fn+2−1+Fn+1=Fn+3−1\sum_{k=0}^{n+1}F_k = F_{n+2} - 1 + F_{n+1} = F_{n+3} - 1. For the second, n=0n = 0 gives 0=F0F10 = F_0F_1. If the claim holds for nn, then ∑k=1n+1Fk2=FnFn+1+Fn+12=Fn+1(Fn+Fn+1)=Fn+1Fn+2\sum_{k=1}^{n+1}F_k^2 = F_nF_{n+1} + F_{n+1}^2 = F_{n+1}(F_n + F_{n+1}) = F_{n+1}F_{n+2}. □\square

Example P2.10.5. For n=6n = 6: 0+1+1+2+3+5+8=20=F8−10 + 1 + 1 + 2 + 3 + 5 + 8 = 20 = F_8 - 1, and 1+1+4+9+25+64=104=8⋅13=F6F71 + 1 + 4 + 9 + 25 + 64 = 104 = 8 \cdot 13 = F_6F_7. The second identity says that a Fn×Fn+1F_n \times F_{n+1} rectangle is the union of squares of the sides F1,…,FnF_1, \dots, F_n.

Theorem P2.10.6 (the matrix form, TAOCP eq. 1.2.8(5)). Let QQ be the matrix with the rows (1,1)(1, 1) and (1,0)(1, 0). For every n≥1n \ge 1, Qn=(Fn+1FnFnFn−1).Q^n = \begin{pmatrix}F_{n+1} & F_n \\ F_n & F_{n-1}\end{pmatrix}.

Lean: not stated.

Proof. For n=1n = 1 the right side is (1110)=Q\begin{pmatrix}1 & 1\\1 & 0\end{pmatrix} = Q. Suppose the formula holds for nn. Then Qn+1=Qn Q=(Fn+1FnFnFn−1)(1110)=(Fn+1+FnFn+1Fn+Fn−1Fn)=(Fn+2Fn+1Fn+1Fn). □Q^{n+1} = Q^n\,Q = \begin{pmatrix}F_{n+1} & F_n \\ F_n & F_{n-1}\end{pmatrix}\begin{pmatrix}1 & 1 \\ 1 & 0\end{pmatrix} = \begin{pmatrix}F_{n+1} + F_n & F_{n+1} \\ F_n + F_{n-1} & F_n\end{pmatrix} = \begin{pmatrix}F_{n+2} & F_{n+1} \\ F_{n+1} & F_n\end{pmatrix}. \ \square

Example P2.10.7. Q5=(8553)Q^5 = \begin{pmatrix}8 & 5 \\ 5 & 3\end{pmatrix}. The product Q3Q2Q^3Q^2 is (3221)(2111)=(8553)\begin{pmatrix}3 & 2\\2 & 1\end{pmatrix}\begin{pmatrix}2 & 1\\1 & 1\end{pmatrix} = \begin{pmatrix}8 & 5\\5 & 3\end{pmatrix}.

Theorem P2.10.8 (Cassini's identity, TAOCP eq. 1.2.8(4)). For every n≥1n \ge 1, Fn+1Fn−1−Fn2=(−1)n.F_{n+1}F_{n-1} - F_n^2 = (-1)^n.

Lean: Mathlib Int.fib_succ_mul_fib_pred_sub_fib_sq for the integer-indexed Fibonacci numbers (proved in Mathlib).

Proof. Take the determinant of QnQ^n. The determinant of QQ is −1-1, and the determinant of a product is the product of the determinants. So det⁡Qn=(−1)n\det Q^n = (-1)^n, and det⁡Qn=Fn+1Fn−1−Fn2\det Q^n = F_{n+1}F_{n-1} - F_n^2 by the last theorem. □\square

Example P2.10.9. For n=6n = 6: F7F5−F62=13⋅5−64=1=(−1)6F_7F_5 - F_6^2 = 13 \cdot 5 - 64 = 1 = (-1)^6. For n=7n = 7: 21⋅8−169=−121 \cdot 8 - 169 = -1. The identity gives a puzzle of area: cut an 8×88 \times 8 square along the lines of the Fibonacci numbers and put the pieces together as a 5×135 \times 13 rectangle. The areas are 6464 and 6565, which differ by 1=∣F62−F7F5∣1 = |F_6^2 - F_7F_5|.

Theorem P2.10.10 (the addition law, TAOCP eq. 1.2.8(6)). For all integers m≥1m \ge 1 and n≥0n \ge 0, Fm+n=FmFn+1+Fm−1Fn.F_{m+n} = F_mF_{n+1} + F_{m-1}F_n.

Lean: Mathlib Nat.fib_add, in the equivalent form fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) (proved in Mathlib).

Proof. For n≥1n \ge 1 compare the entries of Qm+n=QmQnQ^{m+n} = Q^mQ^n in the first row and the second column. The first row of QmQ^m is (Fm+1,Fm)(F_{m+1}, F_m) and the second column of QnQ^n is (Fn,Fn−1)T(F_n, F_{n-1})^T, so Fm+n=Fm+1Fn+FmFn−1F_{m+n} = F_{m+1}F_n + F_mF_{n-1}. Exchange the roles of mm and nn to get Fm+n=Fn+1Fm+FnFm−1F_{m+n} = F_{n+1}F_m + F_nF_{m-1}. This is the claim. For n=0n = 0 the claim reads Fm=FmF1+Fm−1F0=FmF_m = F_mF_1 + F_{m-1}F_0 = F_m. □\square

Example P2.10.11. For m=5m = 5 and n=4n = 4: F9=F5F5+F4F4=25+9=34F_9 = F_5F_5 + F_4F_4 = 25 + 9 = 34. For m=7m = 7 and n=6n = 6: F13=F7F7+F6F6=169+64=233F_{13} = F_7F_7 + F_6F_6 = 169 + 64 = 233.

Corollary P2.10.12 (doubling formulas). For every n≥1n \ge 1, F2n=Fn(2Fn+1−Fn),F2n+1=Fn2+Fn+12.F_{2n} = F_n(2F_{n+1} - F_n), \qquad F_{2n+1} = F_n^2 + F_{n+1}^2.

Lean: Mathlib Nat.fib_two_mul and Nat.fib_two_mul_add_one (proved in Mathlib).

Proof. Put m=nm = n in the addition law: F2n=FnFn+1+Fn−1FnF_{2n} = F_nF_{n+1} + F_{n-1}F_n, and Fn−1=Fn+1−FnF_{n-1} = F_{n+1} - F_n gives the first formula. Put m=n+1m = n + 1: F2n+1=Fn+1Fn+1+FnFnF_{2n+1} = F_{n+1}F_{n+1} + F_nF_n. □\square

Example P2.10.13. For n=6n = 6: F12=8⋅(26−8)=144F_{12} = 8 \cdot (26 - 8) = 144 and F13=64+169=233F_{13} = 64 + 169 = 233.

Theorem P2.10.14 (the shallow diagonals of Pascal's triangle). For every n≥0n \ge 0, Fn+1=∑k≥0(n−kk).F_{n+1} = \sum_{k \ge 0}\binom{n-k}{k}.

Lean: Mathlib Nat.fib_succ_eq_sum_choose (proved in Mathlib).

Proof. Let sns_n be the right side. Then s0=1s_0 = 1 and s1=1s_1 = 1. For n≥2n \ge 2, Pascal's rule gives (n−kk)=(n−1−kk)+(n−1−kk−1)\binom{n-k}{k} = \binom{n-1-k}{k} + \binom{n-1-k}{k-1}. The first terms add to sn−1s_{n-1}. In the second terms put j=k−1j = k - 1: (n−2−jj)\binom{n-2-j}{j}, which add to sn−2s_{n-2}. So sn=sn−1+sn−2s_n = s_{n-1} + s_{n-2}, and the sequences sns_n and Fn+1F_{n+1} have the same start and the same rule. □\square

Example P2.10.15. For n=6n = 6: (60)+(51)+(42)+(33)=1+5+6+1=13=F7\binom60 + \binom51 + \binom42 + \binom33 = 1 + 5 + 6 + 1 = 13 = F_7. For n=9n = 9: 1+8+21+20+5=55=F101 + 8 + 21 + 20 + 5 = 55 = F_{10}.

Method (fast doubling). Given an integer n≥0n \ge 0, it computes the pair (Fn,Fn+1)(F_n, F_{n+1}) with O(log⁡n)O(\log n) multiplications.

The idea is to read the bits of nn from the left and to keep the pair (a,b)=(Fk,Fk+1)(a, b) = (F_k, F_{k+1}), where kk is the number that the bits read so far form. Reading one more bit turns kk into 2k2k or 2k+12k+1, and the doubling formulas give the new pair.

fast_doubling(n):
    a <- 0; b <- 1                      # (F_0, F_1), k = 0
    for each bit t of n, from the leading bit to the last:
        c <- a * (2*b - a)              # F_{2k}
        d <- a*a + b*b                  # F_{2k+1}
        if t = 0: (a, b) <- (c, d)      # k <- 2k
        else:     (a, b) <- (d, c + d)  # k <- 2k + 1
    return (a, b)

Run for n=13=11012n = 13 = 1101_2. bitcd(a,b) after the bitkstart(0,1)0101(1,1)1112(2,3)302⋅(6−2)=84+9=13(8,13)618⋅(26−8)=14464+169=233(233,377)13\begin{array}{c|c|c|c|c} \text{bit} & c & d & (a, b) \text{ after the bit} & k \\ \hline \text{start} & & & (0, 1) & 0 \\ 1 & 0 & 1 & (1, 1) & 1 \\ 1 & 1 & 2 & (2, 3) & 3 \\ 0 & 2\cdot(6 - 2) = 8 & 4 + 9 = 13 & (8, 13) & 6 \\ 1 & 8\cdot(26 - 8) = 144 & 64 + 169 = 233 & (233, 377) & 13 \end{array} The result is F13=233F_{13} = 233 and F14=377F_{14} = 377.

Proof of correctness. The invariant is that, before each bit, (a,b)=(Fk,Fk+1)(a, b) = (F_k, F_{k+1}) with kk the number formed by the bits already read. At the start k=0k = 0 and (a,b)=(F0,F1)(a, b) = (F_0, F_1). The values cc and dd are F2kF_{2k} and F2k+1F_{2k+1} by the corollary. For the bit 00 the new number is 2k2k and the new pair is (F2k,F2k+1)=(c,d)(F_{2k}, F_{2k+1}) = (c, d). For the bit 11 the new number is 2k+12k+1 and the new pair is (F2k+1,F2k+2)=(d,c+d)(F_{2k+1}, F_{2k+2}) = (d, c + d). After the last bit, k=nk = n. The loop runs ⌊log⁡2n⌋+1\lfloor\log_2n\rfloor + 1 times, and it stops. (The formula for cc also holds for k=0k = 0, where it gives 00.) □\square

Cost. Each pass has 33 multiplications, so the cost is 3(⌊log⁡2n⌋+1)3(\lfloor\log_2n\rfloor + 1) multiplications. For n=13n = 13 this is 1212. Computing FnF_n by the recurrence takes n−1n - 1 additions. The numbers have about 0.69n0.69n bits, so on large nn the cost of a multiplication dominates the cost.

Proof

The identities all follow from two facts: the recurrence Fn+2=Fn+1+FnF_{n+2} = F_{n+1} + F_n and the matrix QQ with Q2=Q+IQ^2 = Q + I. The identities by induction use the first fact, and the identities for QnQ^n use the second. The shallow diagonal identity connects the sequence to the triangle of Chapter 6.

Examples

Example P2.10.16. Cassini's identity gives a fast check of a table. In the table of the first values, F10F8−F92=55⋅21−342=1155−1156=−1=(−1)9F_{10}F_8 - F_9^2 = 55 \cdot 21 - 34^2 = 1155 - 1156 = -1 = (-1)^9.

Example P2.10.17. The matrix QnQ^n has the first Fibonacci numbers as entries. For n=8n = 8: Q8=(34212113)Q^8 = \begin{pmatrix}34 & 21 \\ 21 & 13\end{pmatrix}, and its square is Q16=(342+21234⋅21+21⋅13⋅212+132)=(1597987987610)Q^{16} = \begin{pmatrix}34^2 + 21^2 & 34 \cdot 21 + 21 \cdot 13 \\ \cdot & 21^2 + 13^2\end{pmatrix} = \begin{pmatrix}1597 & 987 \\ 987 & 610\end{pmatrix}, so F17=1597F_{17} = 1597, F16=987F_{16} = 987 and F15=610F_{15} = 610.

Exercises

  1. [10] Compute F21,…,F25F_{21}, \dots, F_{25} with the recurrence and check F25F_{25} with the addition law.
  2. [M15] Prove that F1+F3+⋯+F2n−1=F2nF_1 + F_3 + \cdots + F_{2n-1} = F_{2n} and that F2+F4+⋯+F2n=F2n+1−1F_2 + F_4 + \cdots + F_{2n} = F_{2n+1} - 1.
  3. [M15] Run the recurrence backwards to define F−nF_{-n}, and prove that F−n=(−1)n+1FnF_{-n} = (-1)^{n+1}F_n.
  4. [M15] Prove that Fn+12−Fn−12=F2nF_{n+1}^2 - F_{n-1}^2 = F_{2n} for n≥1n \ge 1.
  5. [M25] Prove that F3n=Fn+13+Fn3−Fn−13F_{3n} = F_{n+1}^3 + F_n^3 - F_{n-1}^3 for n≥1n \ge 1.
  6. [M20] Prove that ∑k(nk)Fk=F2n\sum_k\binom nkF_k = F_{2n} with the matrix QQ.
  7. [M22] Prove that FmFn+1−Fm+1Fn=(−1)nFm−nF_mF_{n+1} - F_{m+1}F_n = (-1)^nF_{m-n} for m≥n≥0m \ge n \ge 0.
  8. [M20] Prove that the number of compositions of nn into 11s and 22s with exactly kk parts equal to 22 is (n−kk)\binom{n-k}{k}, and use it to give a second proof of the theorem on the shallow diagonals.
  9. [10] Run the algorithm of fast doubling for n=10n = 10 and list the pairs (a,b)(a, b).
  10. [M20] Prove that ∑k=1nkFk=nFn+2−Fn+3+2\sum_{k=1}^nkF_k = nF_{n+2} - F_{n+3} + 2.

Lean

Mathlib defines Nat.fib and has Nat.fib_add_two for the recurrence, Nat.fib_add for the addition law, Nat.fib_two_mul and Nat.fib_two_mul_add_one for the doubling formulas, Nat.fib_succ_eq_sum_choose for the shallow diagonals, and Int.fib_succ_mul_fib_pred_sub_fib_sq for Cassini's identity with integer indices. The matrix form and the sums of the first terms are not stated by name. The algorithm of fast doubling has no Lean definition in this volume.

Notes and history

Leonardo of Pisa, called Fibonacci, put the rabbit problem in his Liber abaci (1202), and the numbers carry his name since Edouard Lucas used it in the 1870s. Indian prosodists knew the sequence earlier, as the count of rhythms with short and long beats, which is the composition count of the second example. Robert Simson noted the identity of Cassini's type in 1753, and Giovanni Cassini found it in 1680. Lucas gave most of the identities of this section in the 1870s.

TAOCP gives the definition in eqs. 1.2.8(1) and 1.2.8(2), Cassini's identity in eq. 1.2.8(4), the matrix form in eq. 1.2.8(5) and the addition law in eq. 1.2.8(6). The proofs here are by induction and by the matrix. The method of fast doubling is a standard trick, and Section 4.6.3 of TAOCP, Volume 2, treats the related problem of fast powers.

Divisibility of the Fibonacci numbers

Statement

The index of a Fibonacci number controls its divisors. The main theorem of the section says that the gcd of two Fibonacci numbers is the Fibonacci number of the gcd of the indices. Two further results, the periodicity modulo mm and the theorem of Lamé on Euclid's algorithm, use the same tools.

Lemma P2.10.18 (consecutive numbers are coprime). For every n≥0n \ge 0, gcd⁡(Fn,Fn+1)=1\gcd(F_n, F_{n+1}) = 1.

Lean: Mathlib Nat.fib_coprime_fib_succ (proved in Mathlib).

Proof. Cassini's identity gives Fn+1Fn−1−Fn2=±1F_{n+1}F_{n-1} - F_n^2 = \pm1 for n≥1n \ge 1, so a common divisor of FnF_n and Fn+1F_{n+1} divides 11. For n=0n = 0, gcd⁡(0,1)=1\gcd(0, 1) = 1. □\square

Lemma P2.10.19 (multiples of the index). For all integers m≥1m \ge 1 and k≥0k \ge 0, FmF_m divides FkmF_{km}.

Lean: Mathlib Int.fib_dvd for integer indices (proved in Mathlib).

Proof. The claim holds for k=0k = 0, since F0=0F_0 = 0, and for k=1k = 1. Let k≥1k \ge 1 and suppose Fm∣FkmF_m \mid F_{km}. The addition law with kmkm and mm in the places of mm and nn gives F(k+1)m=FkmFm+1+Fkm−1FmF_{(k+1)m} = F_{km}F_{m+1} + F_{km-1}F_m. Both terms are divisible by FmF_m. □\square

Example P2.10.20. F4=3F_4 = 3 divides F8=21F_8 = 21 and F12=144F_{12} = 144, and F6=8F_6 = 8 divides F12=144F_{12} = 144 and F18=2584=8⋅323F_{18} = 2584 = 8 \cdot 323.

Theorem P2.10.21 (the gcd law, TAOCP eq. 1.2.8(7)). For all integers m,n≥0m, n \ge 0, gcd⁡(Fm,Fn)=Fgcd⁡(m,n).\gcd(F_m, F_n) = F_{\gcd(m, n)}.

Lean: Mathlib Nat.fib_gcd (proved in Mathlib).

Proof. If one index is 00, say n=0n = 0, both sides are FmF_m, because gcd⁡(Fm,0)=Fm\gcd(F_m, 0) = F_m and gcd⁡(m,0)=m\gcd(m, 0) = m. Let m,n≥1m, n \ge 1. The proof follows the steps of Euclid's algorithm and shows that gcd⁡(Fm,Fn)\gcd(F_m, F_n) does not change when (m,n)(m, n) is replaced by (n,m mod n)(n, m \bmod n). Let m=qn+rm = qn + r with 0≤r<n0 \le r < n. If q=0q = 0 there is nothing to show, so let q≥1q \ge 1. By the addition law, Fm=Fqn+r=FqnFr+1+Fqn−1FrF_m = F_{qn + r} = F_{qn}F_{r+1} + F_{qn-1}F_r. By the lemma, Fn∣FqnF_n \mid F_{qn}. So gcd⁡(Fm,Fn)=gcd⁡(Fqn−1Fr,Fn),\gcd(F_m, F_n) = \gcd(F_{qn-1}F_r, F_n), since FmF_m differs from Fqn−1FrF_{qn-1}F_r by a multiple of FnF_n. Now Fqn−1F_{qn-1} is coprime to FqnF_{qn} by the first lemma, and FnF_n divides FqnF_{qn}, so Fqn−1F_{qn-1} is coprime to FnF_n. A factor that is coprime to FnF_n does not change the gcd with FnF_n, so gcd⁡(Fqn−1Fr,Fn)=gcd⁡(Fr,Fn)\gcd(F_{qn-1}F_r, F_n) = \gcd(F_r, F_n). So gcd⁡(Fm,Fn)=gcd⁡(Fn,Fr)\gcd(F_m, F_n) = \gcd(F_n, F_r) with r=m mod nr = m \bmod n. By induction on the sum of the indices, which falls, this equals Fgcd⁡(n,r)=Fgcd⁡(m,n)F_{\gcd(n, r)} = F_{\gcd(m, n)}, where the last step uses the base case r=0r = 0: gcd⁡(Fn,F0)=Fn=Fgcd⁡(n,0)\gcd(F_n, F_0) = F_n = F_{\gcd(n, 0)}. □\square

Example P2.10.22. gcd⁡(F12,F18)=gcd⁡(144,2584)=8=F6\gcd(F_{12}, F_{18}) = \gcd(144, 2584) = 8 = F_6, and gcd⁡(12,18)=6\gcd(12, 18) = 6. Also gcd⁡(F24,F36)=gcd⁡(46368,14930352)=144=F12\gcd(F_{24}, F_{36}) = \gcd(46368, 14930352) = 144 = F_{12}.

Corollary P2.10.23 (divisibility). For m≥3m \ge 3 and n≥1n \ge 1, Fm∣FnF_m \mid F_n if and only if m∣nm \mid n. For every n≥1n \ge 1, gcd⁡(Fn,Fn+2)=1\gcd(F_n, F_{n+2}) = 1. If FnF_n is prime with n≥5n \ge 5, then nn is prime. So FnF_n is composite for every composite n≠4n \ne 4 with n≥5n \ge 5.

Lean: not stated.

Proof. If m∣nm \mid n then Fm∣FnF_m \mid F_n by the lemma. If Fm∣FnF_m \mid F_n, then gcd⁡(Fm,Fn)=Fm\gcd(F_m, F_n) = F_m, so Fgcd⁡(m,n)=FmF_{\gcd(m, n)} = F_m. For m≥3m \ge 3 the sequence is strictly increasing from F2F_2 on, so Fg=FmF_g = F_m with g≤mg \le m implies g=mg = m, and g=gcd⁡(m,n)g = \gcd(m, n) gives m∣nm \mid n. For the second claim, gcd⁡(n,n+2)\gcd(n, n+2) is 11 or 22 and F1=F2=1F_1 = F_2 = 1. For the third, let n≥5n \ge 5 be composite, n≠4n \ne 4. Then nn has a divisor dd with 3≤d<n3 \le d < n: write n=abn = ab with 2≤a≤b2 \le a \le b, and take d=bd = b, which is at least 33 since n≥5n \ge 5. By the lemma Fd∣FnF_d \mid F_n, and 2≤Fd<Fn2 \le F_d < F_n. So FnF_n is composite. Only n=4n = 4 has no such divisor, and F4=3F_4 = 3 is prime. □\square

Example P2.10.24. The index n=19n = 19 is prime and F19=4181=37⋅113F_{19} = 4181 = 37 \cdot 113 is not. So the converse fails. The first primes among the Fibonacci numbers are F3=2F_3 = 2, F4=3F_4 = 3, F5=5F_5 = 5, F7=13F_7 = 13, F11=89F_{11} = 89 and F13=233F_{13} = 233.

Theorem P2.10.25 (periodicity modulo mm). Let m≥1m \ge 1. The sequence Fn mod mF_n \bmod m is purely periodic. Let π(m)\pi(m) be its least period. For m≥2m \ge 2 there is a least index α(m)≥1\alpha(m) \ge 1 with m∣Fα(m)m \mid F_{\alpha(m)}, and m∣Fnm \mid F_n if and only if α(m)∣n\alpha(m) \mid n. Also α(m)∣π(m)\alpha(m) \mid \pi(m).

Lean: not stated.

Proof. Look at the pairs (Fn mod m,Fn+1 mod m)(F_n \bmod m, F_{n+1} \bmod m). There are m2m^2 possible pairs. The map (a,b)↦(b,a+b)(a, b) \mapsto (b, a + b) on pairs modulo mm is a bijection, with inverse (b,c)↦(c−b,b)(b, c) \mapsto (c - b, b). A bijection on a finite set has no pre-period: the orbit of (0,1)(0, 1) returns to (0,1)(0, 1). So the sequence is purely periodic with a period at most m2m^2. In the period, F0≡0F_0 \equiv 0 comes back, so m∣Fπ(m)m \mid F_{\pi(m)} and α(m)≤π(m)\alpha(m) \le \pi(m) exists. If m∣Fnm \mid F_n and m∣Fαm \mid F_{\alpha} with α=α(m)\alpha = \alpha(m), then m∣gcd⁡(Fn,Fα)=Fgcd⁡(n,α)m \mid \gcd(F_n, F_\alpha) = F_{\gcd(n, \alpha)} by the gcd law. By the minimality of α\alpha, gcd⁡(n,α)≥α\gcd(n, \alpha) \ge \alpha, so α∣n\alpha \mid n. The other direction follows from the lemma on multiples. With n=π(m)n = \pi(m) it gives α∣π(m)\alpha \mid \pi(m). □\square

Example P2.10.26. The values for 2≤m≤122 \le m \le 12 are m23456789101112α(m)3465128612151012π(m)3862024161224601024\begin{array}{c|ccccccccccc} m & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ \hline \alpha(m) & 3 & 4 & 6 & 5 & 12 & 8 & 6 & 12 & 15 & 10 & 12 \\ \pi(m) & 3 & 8 & 6 & 20 & 24 & 16 & 12 & 24 & 60 & 10 & 24 \end{array} For m=5m = 5 the sequence Fn mod 5F_n \bmod 5 is 0,1,1,2,3,0,3,3,1,4,0,4,4,3,2,0,2,2,4,10, 1, 1, 2, 3, 0, 3, 3, 1, 4, 0, 4, 4, 3, 2, 0, 2, 2, 4, 1 and then it repeats, with the period 2020 and the zeros at the multiples of 55. For m=10m = 10 the period is 6060, which is why the last digits of the Fibonacci numbers repeat every 6060 terms.

Theorem P2.10.27 (Lamé). Let a>b≥1a > b \ge 1 be integers, and suppose that Euclid's algorithm on (a,b)(a, b) makes exactly nn divisions, the last one with remainder 00. Then b≥Fn+1b \ge F_{n+1} and a≥Fn+2a \ge F_{n+2}.

Lean: not stated.

Proof. Induction on nn. For n=1n = 1, b∣ab \mid a and a>b≥1a > b \ge 1, so b≥1=F2b \ge 1 = F_2 and a≥2=F3a \ge 2 = F_3. Let n≥2n \ge 2. The first division gives a=qb+ra = qb + r with q≥1q \ge 1 and 0<r<b0 < r < b, since n≥2n \ge 2 means the first remainder is not 00. The algorithm on (b,r)(b, r) makes n−1n - 1 divisions. By the induction hypothesis r≥Fnr \ge F_n and b≥Fn+1b \ge F_{n+1}. Then a=qb+r≥b+r≥Fn+1+Fn=Fn+2a = qb + r \ge b + r \ge F_{n+1} + F_n = F_{n+2}. □\square

Example P2.10.28. Euclid's algorithm on (Fn+2,Fn+1)(F_{n+2}, F_{n+1}) takes exactly nn divisions for n≥1n \ge 1, so the bound is sharp. For (89,55)(89, 55) the divisions are 89=1⋅55+3489 = 1 \cdot 55 + 34, 55=1⋅34+2155 = 1 \cdot 34 + 21, 34=1⋅21+1334 = 1 \cdot 21 + 13, 21=1⋅13+821 = 1 \cdot 13 + 8, 13=1⋅8+513 = 1 \cdot 8 + 5, 8=1⋅5+38 = 1 \cdot 5 + 3, 5=1⋅3+25 = 1 \cdot 3 + 2, 3=1⋅2+13 = 1 \cdot 2 + 1 and 2=2⋅1+02 = 2 \cdot 1 + 0. That is 99 divisions, and F11=89F_{11} = 89 gives n=9n = 9.

Proof

The proofs use Cassini's identity for the coprimality, the addition law for the multiples, and the steps of Euclid's algorithm for the gcd law. The gcd law is Euclid's algorithm on the indices, run in parallel with Euclid's algorithm on the values. The periodicity uses that the pair map is a bijection, which kills the pre-period. Lamé's theorem is the same idea as the gcd law: Euclid's algorithm shrinks the pair as slowly as possible when all quotients equal 11, and then the pair is a pair of Fibonacci numbers.

Examples

Example P2.10.29. Is F100F_{100} divisible by F20F_{20}? Yes, since 20∣10020 \mid 100. And gcd⁡(F100,F75)=F25=75025\gcd(F_{100}, F_{75}) = F_{25} = 75025.

Example P2.10.30. Every FnF_n with 3∣n3 \mid n is even, since F3=2F_3 = 2 divides it. The even Fibonacci numbers are F0,F3,F6,⋯=0,2,8,34,144,…F_0, F_3, F_6, \dots = 0, 2, 8, 34, 144, \dots. Likewise FnF_n is divisible by 55 exactly when 5∣n5 \mid n, and FnF_n is divisible by 1313 exactly when 7∣n7 \mid n, since F7=13F_7 = 13.

Exercises

  1. [10] Find gcd⁡(F24,F36)\gcd(F_{24}, F_{36}) with the gcd law, and check it by the values F24=46368F_{24} = 46368 and F36=14930352F_{36} = 14930352.
  2. [M15] Prove that FnF_n is even if and only if 3∣n3 \mid n, and that FnF_n is divisible by 44 if and only if 6∣n6 \mid n.
  3. [M20] Prove that Fm∣FnF_m \mid F_n implies m∣nm \mid n for m≥3m \ge 3 with a direct argument on the least positive residue of nn modulo mm, without the gcd law.
  4. [M20] Prove that gcd⁡(Fn,Fn−1+Fn+1)\gcd(F_n, F_{n-1} + F_{n+1}) is 22 if 3∣n3 \mid n and 11 otherwise.
  5. [M20] Show that Euclid's algorithm on (Fn+1,Fn)(F_{n+1}, F_n), with n≥2n \ge 2, makes n−1n - 1 divisions.
  6. [15] Find the period of Fn mod mF_n \bmod m for m=2,3,4m = 2, 3, 4 and 1010, and show that it is a multiple of α(m)\alpha(m) in each case.
  7. [M15] Prove that 5∣Fn5 \mid F_n if and only if 5∣n5 \mid n.
  8. [10] Find gcd⁡(Fn,Fn+2)\gcd(F_n, F_{n+2}) for all n≥1n \ge 1.
  9. [M25] Prove Catalan's identity Fn2−Fn−rFn+r=(−1)n−rFr2F_n^2 - F_{n-r}F_{n+r} = (-1)^{n-r}F_r^2 for 0≤r≤n0 \le r \le n.

Lean

Mathlib has Nat.fib_coprime_fib_succ and Nat.fib_gcd, which is the gcd law with Nat.gcd, and Int.fib_dvd for the divisibility of the integer-indexed numbers. The periodicity modulo mm and Lamé's theorem are not stated in Mathlib in this form. The doc comment of Nat.fib_gcd calls the Fibonacci numbers a strong divisibility sequence.

Notes and history

Lucas proved the gcd law in 1876, and the theorem of Lamé is from 1844, the first use of the Fibonacci numbers in the analysis of an algorithm. Lagrange noted in 1774 that the Fibonacci numbers repeat modulo mm, and the period carries the name of Leonardo of Pisa in the later literature. The question whether infinitely many Fibonacci numbers are prime is open.

TAOCP states the gcd law as eq. 1.2.8(7), and it proves it in Theorem 1.2.8A with two lemmas, eqs. 1.2.8(8) and 1.2.8(9). The proof here follows the steps of Euclid's algorithm and does not use the steps of the book. The exercises of 1.2.8 on Lamé's theorem and on the period are in X1.

The golden ratio and Zeckendorf's theorem

Statement

The recurrence x2=x+1x^2 = x + 1 has two real roots, and every Fibonacci number is a combination of their powers. This gives a closed form, an easy estimate of FnF_n and the rule that FnF_n is a rounded power. The section ends with Zeckendorf's numeral system, in which each positive integer is a sum of Fibonacci numbers in exactly one way.

Definition P2.10.31 (the golden ratio and its conjugate, TAOCP eqs. 1.2.8(3) and 1.2.8(13)). Let ϕ=1+52,ϕ^=1−52.\phi = \frac{1 + \sqrt5}{2}, \qquad \hat\phi = \frac{1 - \sqrt5}{2}. They are the two roots of x2=x+1x^2 = x + 1, and ϕ+ϕ^=1\phi + \hat\phi = 1, ϕϕ^=−1\phi\hat\phi = -1 and ϕ−ϕ^=5\phi - \hat\phi = \sqrt5.

Lean: Mathlib Real.goldenRatio and Real.goldenConj, with Real.goldenRatio_sq : φ ^ 2 = φ + 1, Real.goldenRatio_mul_goldenConj and Real.goldenRatio_sub_goldenConj (proved in Mathlib).

Example P2.10.32. ϕ=1.6180339887…\phi = 1.6180339887\ldots and ϕ^=−0.6180339887…=−1ϕ\hat\phi = -0.6180339887\ldots = -\frac1\phi. Also ϕ2=ϕ+1=2.6180339887…\phi^2 = \phi + 1 = 2.6180339887\ldots and ϕ3=2ϕ+1=4.2360679775…\phi^3 = 2\phi + 1 = 4.2360679775\ldots. The check of the roots: ϕ2−ϕ−1=(1+5)24−1+52−1=6+25−2−25−44=0\phi^2 - \phi - 1 = \frac{(1 + \sqrt5)^2}{4} - \frac{1 + \sqrt5}{2} - 1 = \frac{6 + 2\sqrt5 - 2 - 2\sqrt5 - 4}{4} = 0.

Lemma P2.10.33 (powers of ϕ\phi). For every n≥1n \ge 1, ϕn=Fnϕ+Fn−1\phi^n = F_n\phi + F_{n-1} and ϕ^n=Fnϕ^+Fn−1\hat\phi^n = F_n\hat\phi + F_{n-1}.

Lean: Mathlib Real.fib_succ_sub_goldenRatio_mul_fib, which says Fn+1−ϕFn=ϕ^nF_{n+1} - \phi F_n = \hat\phi^n and is an equivalent form (proved in Mathlib).

Proof. For n=1n = 1 the claim is ϕ=1⋅ϕ+0\phi = 1 \cdot \phi + 0. If ϕn=Fnϕ+Fn−1\phi^n = F_n\phi + F_{n-1}, then ϕn+1=Fnϕ2+Fn−1ϕ=Fn(ϕ+1)+Fn−1ϕ=(Fn+Fn−1)ϕ+Fn=Fn+1ϕ+Fn\phi^{n+1} = F_n\phi^2 + F_{n-1}\phi = F_n(\phi + 1) + F_{n-1}\phi = (F_n + F_{n-1})\phi + F_n = F_{n+1}\phi + F_n. The same steps hold for ϕ^\hat\phi, since it is a root of the same equation. □\square

Example P2.10.34. ϕ5=5ϕ+3=11.0902…\phi^5 = 5\phi + 3 = 11.0902\ldots, and ϕ6=8ϕ+5=17.9443…\phi^6 = 8\phi + 5 = 17.9443\ldots.

Theorem P2.10.35 (Binet's formula, TAOCP eq. 1.2.8(14)). For every n≥0n \ge 0, Fn=ϕn−ϕ^n5.F_n = \frac{\phi^n - \hat\phi^n}{\sqrt5}.

Lean: Mathlib Real.coe_fib_eq (proved in Mathlib).

Proof. For n≥1n \ge 1 subtract the two equations of the lemma: ϕn−ϕ^n=Fn(ϕ−ϕ^)=Fn5\phi^n - \hat\phi^n = F_n(\phi - \hat\phi) = F_n\sqrt5. For n=0n = 0 both sides are 00. □\square

Second proof. Both sides satisfy xn+2=xn+1+xnx_{n+2} = x_{n+1} + x_n since ϕn\phi^n and ϕ^n\hat\phi^n do, and both give 00 at n=0n = 0 and 11 at n=1n = 1, since ϕ−ϕ^5=1\frac{\phi - \hat\phi}{\sqrt5} = 1. This is the method of linear recurrences of Chapter 2. □\square

Example P2.10.36. F10=ϕ10−ϕ^105F_{10} = \frac{\phi^{10} - \hat\phi^{10}}{\sqrt5}. With ϕ10=122.9918…\phi^{10} = 122.9918\ldots and ϕ^10=0.0081…\hat\phi^{10} = 0.0081\ldots the difference is 122.9837…122.9837\ldots, and division by 5=2.2360…\sqrt5 = 2.2360\ldots gives 55.0000…55.0000\ldots.

Theorem P2.10.37 (the nearest integer, TAOCP eq. 1.2.8(15)). For every n≥0n \ge 0, FnF_n is the integer nearest to ϕn/5\phi^n/\sqrt5. More exactly, ϕn/5−Fn=ϕ^n/5\phi^n/\sqrt5 - F_n = \hat\phi^n/\sqrt5, which has absolute value less than 12\frac12, and it tends to 00 with alternating sign.

Lean: not stated; Binet's formula is in Mathlib.

Proof. Binet's formula gives ϕn5−Fn=ϕ^n5\frac{\phi^n}{\sqrt5} - F_n = \frac{\hat\phi^n}{\sqrt5}. Since ∣ϕ^∣<1|\hat\phi| < 1, ∣ϕ^n∣≤1|\hat\phi^n| \le 1 for n≥0n \ge 0, and 15=0.447…<12\frac{1}{\sqrt5} = 0.447\ldots < \frac12. So the difference is less than 12\frac12 in absolute value, and the integer nearest to ϕn/5\phi^n/\sqrt5 is FnF_n. □\square

Example P2.10.38. The table lists ϕn/5\phi^n/\sqrt5 and the error ϕ^n/5\hat\phi^n/\sqrt5: n45678910Fn35813213455ϕn/53.06524.95978.024912.984621.009533.994155.0036ϕ^n/50.0652−0.04030.0249−0.01540.0095−0.00590.0036\begin{array}{c|ccccccc} n & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ \hline F_n & 3 & 5 & 8 & 13 & 21 & 34 & 55 \\ \phi^n/\sqrt5 & 3.0652 & 4.9597 & 8.0249 & 12.9846 & 21.0095 & 33.9941 & 55.0036 \\ \hat\phi^n/\sqrt5 & 0.0652 & -0.0403 & 0.0249 & -0.0154 & 0.0095 & -0.0059 & 0.0036 \end{array}

Theorem P2.10.39 (the ratios). For every n≥1n \ge 1, Fn+1−ϕFn=ϕ^nF_{n+1} - \phi F_n = \hat\phi^n. So Fn+1/Fn→ϕF_{n+1}/F_n \to \phi, and the quotients are alternately above and below ϕ\phi.

Lean: Mathlib Real.fib_succ_sub_goldenRatio_mul_fib (proved in Mathlib).

Proof. The proof is by induction. For n=1n = 1: F2−ϕF1=1−ϕ=ϕ^F_2 - \phi F_1 = 1 - \phi = \hat\phi. Assume Fn+1−ϕFn=ϕ^nF_{n+1} - \phi F_n = \hat\phi^n. Then Fn+2−ϕFn+1=(1−ϕ)Fn+1+Fn=ϕ^Fn+1+FnF_{n+2} - \phi F_{n+1} = (1 - \phi)F_{n+1} + F_n = \hat\phi F_{n+1} + F_n. Since ϕϕ^=−1\phi\hat\phi = -1, Fn=−ϕϕ^FnF_n = -\phi\hat\phi F_n, so this is ϕ^(Fn+1−ϕFn)=ϕ^n+1\hat\phi(F_{n+1} - \phi F_n) = \hat\phi^{n+1}. Dividing by FnF_n gives Fn+1Fn−ϕ=ϕ^nFn\frac{F_{n+1}}{F_n} - \phi = \frac{\hat\phi^n}{F_n}. This tends to 00 and has the sign (−1)n(-1)^n. □\square

Example P2.10.40. The quotients 21,32,53,85,138,2113\frac21, \frac32, \frac53, \frac85, \frac{13}{8}, \frac{21}{13} are 2,1.5,1.6667,1.6,1.625,1.61542, 1.5, 1.6667, 1.6, 1.625, 1.6154. They alternate around ϕ=1.6180\phi = 1.6180, and the error after n=9n = 9 is F10/F9−ϕ=5534−ϕ=−0.00039F_{10}/F_9 - \phi = \frac{55}{34} - \phi = -0.00039.

Example P2.10.41 (the number of digits). The number of decimal digits of FnF_n is ⌊log⁡10Fn⌋+1\lfloor\log_{10}F_n\rfloor + 1, and log⁡10Fn=nlog⁡10ϕ−log⁡105+ϵ\log_{10}F_n = n\log_{10}\phi - \log_{10}\sqrt5 + \epsilon with a tiny ϵ\epsilon. With log⁡10ϕ=0.20898764…\log_{10}\phi = 0.20898764\ldots and log⁡105=0.34948500…\log_{10}\sqrt5 = 0.34948500\ldots: for n=100n = 100 the value is 20.54920.549, so F100F_{100} has 2121 digits, and F100=354224848179261915075F_{100} = 354224848179261915075. For n=1000n = 1000 the value is 208.638…208.638\ldots, so F1000F_{1000} has 209209 digits, and the leading digits are given by 100.638=4.3510^{0.638} = 4.35. The first digits of F1000F_{1000} are 43466557684346655768.

Definition P2.10.42 (the Lucas numbers). The Lucas numbers are given by L0=2L_0 = 2, L1=1L_1 = 1 and Ln+2=Ln+1+LnL_{n+2} = L_{n+1} + L_n.

Lean: not stated.

Example P2.10.43. L0,…,L11L_0, \dots, L_{11} are 2,1,3,4,7,11,18,29,47,76,123,1992, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199.

Theorem P2.10.44 (Lucas numbers and Fibonacci numbers). For every n≥0n \ge 0, Ln=ϕn+ϕ^n=Fn−1+Fn+1L_n = \phi^n + \hat\phi^n = F_{n-1} + F_{n+1} (for n≥1n \ge 1), F2n=FnLnF_{2n} = F_nL_n and Ln2−5Fn2=4(−1)nL_n^2 - 5F_n^2 = 4(-1)^n.

Lean: not stated.

Proof. The sequence ϕn+ϕ^n\phi^n + \hat\phi^n has the values 22 and 11 at n=0n = 0 and n=1n = 1 and follows the Fibonacci rule, so it is LnL_n. For n≥1n \ge 1 the sum Fn−1+Fn+1F_{n-1} + F_{n+1} also follows the rule, and it is F0+F2=1F_0 + F_2 = 1 at n=1n = 1 and F1+F3=3F_1 + F_3 = 3 at n=2n = 2, which are L1L_1 and L2L_2. By Binet, F2n=ϕ2n−ϕ^2n5=(ϕn−ϕ^n)(ϕn+ϕ^n)5=FnLnF_{2n} = \frac{\phi^{2n} - \hat\phi^{2n}}{\sqrt5} = \frac{(\phi^n - \hat\phi^n)(\phi^n + \hat\phi^n)}{\sqrt5} = F_nL_n. Finally Ln2−5Fn2=(ϕn+ϕ^n)2−(ϕn−ϕ^n)2=4(ϕϕ^)n=4(−1)nL_n^2 - 5F_n^2 = (\phi^n + \hat\phi^n)^2 - (\phi^n - \hat\phi^n)^2 = 4(\phi\hat\phi)^n = 4(-1)^n. □\square

Example P2.10.45. F12=F6L6=8⋅18=144F_{12} = F_6L_6 = 8 \cdot 18 = 144. And L52−5F52=121−125=−4L_5^2 - 5F_5^2 = 121 - 125 = -4.

Theorem P2.10.46 (Zeckendorf's representation). Every integer n≥1n \ge 1 is a sum of Fibonacci numbers Fk1+Fk2+⋯+FkrF_{k_1} + F_{k_2} + \cdots + F_{k_r} with k1≥k2+2k_1 \ge k_2 + 2, k2≥k3+2k_2 \ge k_3 + 2, …\dots, kr≥2k_r \ge 2, and this representation is unique.

Lean: Mathlib Nat.zeckendorf, Nat.zeckendorf_sum_fib and Nat.zeckendorfEquiv (proved in Mathlib).

Proof. The sum of a representation with k1≥⋯k_1 \ge \cdots at distance 22 is less than Fk1+1F_{k_1+1}. Prove this first by induction on rr. For r=1r = 1 the sum is Fk1<Fk1+1F_{k_1} < F_{k_1+1} if k1≥2k_1 \ge 2. For r>1r > 1 the sum of the last r−1r - 1 terms is less than Fk2+1≤Fk1−1F_{k_2+1} \le F_{k_1-1}, so the whole sum is less than Fk1+Fk1−1=Fk1+1F_{k_1} + F_{k_1-1} = F_{k_1+1}.

Existence is by strong induction on nn. Let FkF_k be the largest Fibonacci number with k≥2k \ge 2 and Fk≤nF_k \le n. Then n<Fk+1n < F_{k+1}, so n−Fk<Fk+1−Fk=Fk−1n - F_k < F_{k+1} - F_k = F_{k-1}. If n−Fk=0n - F_k = 0 the representation is FkF_k. Otherwise it has, by induction, a representation whose largest index jj has Fj≤n−Fk<Fk−1F_j \le n - F_k < F_{k-1}, so j≤k−2j \le k - 2. Adding FkF_k gives a representation of nn.

Uniqueness follows from the bound. A representation of nn with the largest index k1k_1 has Fk1≤n<Fk1+1F_{k_1} \le n < F_{k_1+1}, so k1k_1 is the index of the largest Fibonacci number that does not exceed nn. This index is determined by nn. Remove it: the remaining terms represent n−Fk1<nn - F_{k_1} < n with the same rule, and by induction this representation is unique. □\square

Method (the greedy method). To find the representation of n≥1n \ge 1, repeat: find the largest Fk≤nF_k \le n with k≥2k \ge 2, record kk, replace nn by n−Fkn - F_k, and stop when n=0n = 0. The proof of the theorem shows that the recorded indices differ by at least 22, and the loop stops since nn falls.

Run for n=100n = 100. The Fibonacci numbers up to 100100 are 1,2,3,5,8,13,21,34,55,891, 2, 3, 5, 8, 13, 21, 34, 55, 89. The largest one at most 100100 is 89=F1189 = F_{11}, and 100−89=11100 - 89 = 11. The largest one at most 1111 is 8=F68 = F_6, and 11−8=311 - 8 = 3. Then 3=F43 = F_4. So 100=F11+F6+F4=89+8+3100 = F_{11} + F_6 + F_4 = 89 + 8 + 3. The indices 11,6,411, 6, 4 differ by 55 and 22.

Example P2.10.48. Written as strings of digits at the places Fk,Fk−1,…,F2F_k, F_{k-1}, \dots, F_2, the numbers 1,…,121, \dots, 12 are n123456789101112digits1101001011000100110101000010001100101010010101\begin{array}{c|cccccccccccc} n & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\ \hline \text{digits} & 1 & 10 & 100 & 101 & 1000 & 1001 & 1010 & 10000 & 10001 & 10010 & 10100 & 10101 \end{array} No string has two adjacent 11s. Also 50=34+13+350 = 34 + 13 + 3, 17=13+3+117 = 13 + 3 + 1 and 1000=987+131000 = 987 + 13.

Remark P2.10.49 (the generating function). The series ∑nFnzn\sum_nF_nz^n equals z1−z−z2\frac{z}{1 - z - z^2}, and partial fractions turn this into Binet's formula. TAOCP gives this as eqs. 1.2.8(10) to 1.2.8(12), and it gives the square of the series as eqs. 1.2.8(16) and 1.2.8(17). P3 proves them, with the rules for formal power series. The sum ∑kFk/2k=2\sum_kF_k/2^k = 2 of Exercise 9 is the value of the series at z=12z = \frac12.

Proof

Binet's formula is the lemma on powers of ϕ\phi, subtracted. The estimate of the error uses only that ∣ϕ^∣<1|\hat\phi| < 1. The Zeckendorf theorem uses the Fibonacci numbers as the numerals of a system in which each place is worth the sum of the two places below. The bound on the sum of a sparse representation plays the role that the bound ∑k<j2k<2j\sum_{k<j}2^k < 2^j plays for binary numerals.

Examples

Example P2.10.50. Compute F20F_{20} by Binet's formula. ϕ20=15127.0000…\phi^{20} = 15127.0000\ldots gives ϕ20/5=6765.0000…\phi^{20}/\sqrt5 = 6765.0000\ldots. The nearest integer is 6765=F206765 = F_{20}.

Example P2.10.51. The number of binary strings of length nn with no two adjacent 11s is Fn+2F_{n+2}. For n=3n = 3 they are 000000, 001001, 010010, 100100 and 101101, which is 5=F55 = F_5. The Zeckendorf strings of the integers 0,…,Fn+2−10, \dots, F_{n+2} - 1 are exactly these.

Exercises

  1. [10] Find F10F_{10} from ϕ10/5\phi^{10}/\sqrt5 to four decimal places and round it.
  2. [M15] Prove that ϕ^n=Fnϕ^+Fn−1\hat\phi^n = F_n\hat\phi + F_{n-1} for n≥1n \ge 1.
  3. [M20] Prove that Ln=Fn−1+Fn+1L_n = F_{n-1} + F_{n+1} and Ln2−5Fn2=4(−1)nL_n^2 - 5F_n^2 = 4(-1)^n by Binet's formula, and compute L12L_{12}.
  4. [M20] Prove that F2n=FnLnF_{2n} = F_nL_n and F2n+1=Fn+1Ln−(−1)nF_{2n+1} = F_{n+1}L_n - (-1)^n.
  5. [15] Find the Zeckendorf representations of 5050, 6464 and 200200.
  6. [M20] Prove that the quotients Fn+1/FnF_{n+1}/F_n tend to ϕ\phi and that ∣Fn+1Fn−ϕ∣<1FnFn+1\left|\frac{F_{n+1}}{F_n} - \phi\right| < \frac{1}{F_nF_{n+1}}.
  7. [M25] Find the number of digits and the leading digit of F2000F_{2000}.
  8. [M20] Prove that the number of binary strings of length nn with no two adjacent 11s is Fn+2F_{n+2}, and that the number of integers mm with 0≤m<Fn+20 \le m < F_{n+2} is the same.
  9. [M20] Prove that ∑k≥1Fk/2k=2\sum_{k \ge 1}F_k/2^k = 2.

Lean

Mathlib has Real.goldenRatio and Real.goldenConj with the notation φ\varphi and ψ\psi, the facts Real.goldenRatio_sq, Real.goldenRatio_mul_goldenConj, Real.goldenRatio_add_goldenConj and Real.goldenRatio_sub_goldenConj, and Binet's formula Real.coe_fib_eq : (Nat.fib n : ℝ) = (φ ^ n - ψ ^ n) / √5. The rule Fn+1−ϕFn=ϕ^nF_{n+1} - \phi F_n = \hat\phi^n is Real.fib_succ_sub_goldenRatio_mul_fib. The Zeckendorf representation is Nat.zeckendorf : ℕ → List ℕ, with Nat.zeckendorf_sum_fib and the bijection Nat.zeckendorfEquiv. The Lucas numbers are not in Mathlib, and the nearest-integer rule is not stated by name.

Notes and history

Abraham de Moivre found Binet's formula in the 1720s, Euler gave it in 1765, and Jacques Binet published it in 1843. The golden ratio has been studied since the Greeks, and the numbers LnL_n carry the name of Lucas, who studied them in 1878. Edouard Zeckendorf proved the representation theorem in 1939 and published it in 1972, and earlier Lekkerkerker had it in 1952.

TAOCP defines ϕ\phi in eq. 1.2.8(3), ϕ^\hat\phi in eq. 1.2.8(13), Binet's formula in eq. 1.2.8(14) and the nearest-integer rule in eq. 1.2.8(15). Zeckendorf's theorem is an exercise there, and the numeral system comes back in Section 6.2.1 of Volume 3 as the basis of Fibonacci search. The table maps the equations of Section 1.2.8 to this chapter.

TAOCP 1.2.8 Result of P2
eqs. (1), (2) Definition (the Fibonacci numbers), Example (the first values), Section 10.1
eq. (3) Definition (the golden ratio and its conjugate)
eq. (4) Theorem (Cassini's identity), Section 10.1
eq. (5) Theorem (the matrix form), Section 10.1
eq. (6) Theorem (the addition law), Section 10.1
eqs. (7) to (9) Theorem (the gcd law) and its proof, Section 10.2
eqs. (10) to (12) Remark (the generating function), proved in P3
eq. (13) Definition (the golden ratio and its conjugate)
eq. (14) Theorem (Binet's formula)
eq. (15) Theorem (the nearest integer)
eqs. (16), (17) Remark (the generating function), proved in P3

The Fibonacci numbers 0,1,1,2,3,5,8,13,…0, 1, 1, 2, 3, 5, 8, 13, \dots are the simplest sequence defined by a recurrence of order two. They appear in the worst case of Euclid's algorithm, in the analysis of search by Fibonacci numbers, in the number of ways to tile a strip and in the shape of many natural patterns. They are also the standard example of a sequence that has a recurrence, a matrix form, a closed form, a divisibility law and a numeral system.

Section 10.1 defines FnF_n and proves the basic identities: the sums of the first terms, Cassini's identity, the matrix form, the addition law, the formulas for F2nF_{2n} and F2n+1F_{2n+1} and the sum along a shallow diagonal of Pascal's triangle. It gives an algorithm that computes FnF_n with O(log⁡n)O(\log n) multiplications, with a run by hand. Section 10.2 proves that gcd⁡(Fm,Fn)=Fgcd⁡(m,n)\gcd(F_m, F_n) = F_{\gcd(m, n)}, derives the divisibility of FnF_n and the periodicity of FnF_n modulo mm, and proves Lamé's theorem on the worst case of Euclid's algorithm. Section 10.3 solves the recurrence by the golden ratio ϕ\phi, proves Binet's formula and the rule that FnF_n is the integer nearest to ϕn/5\phi^n/\sqrt5, introduces the Lucas numbers and proves Zeckendorf's theorem on the representation of integers as sums of Fibonacci numbers.

TAOCP treats the Fibonacci numbers in Section 1.2.8, in the equations 1.2.8(1) to 1.2.8(17). The table at the end of Section 10.3 maps these equations to the items of this chapter. The generating function ∑Fnzn=z/(1−z−z2)\sum F_nz^n = z/(1 - z - z^2) and the square of this function (eqs. 1.2.8(10) to 1.2.8(12), 1.2.8(16) and 1.2.8(17)) belong to P3, and this chapter gives pointers only. The solution of linear recurrences in Chapter 2 gives a second proof of Binet's formula.

The chapter needs induction (P1), matrices of order two, the gcd and the Euclidean algorithm of Section 5.1, congruences of Section 5.3, and the binomial coefficients of Chapter 6. The companion section is C1 Section 1.2.8, and X1 has the solutions of the exercises of TAOCP 1.2.8. Continuants in Chapter 12 generalize the matrix form of Section 10.1.

The source of this page. Something is wrong? Report it.