taocp

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

Volume C1 · Basic concepts · TAOCP Section 1.2.8

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 it next to Section 1.2.8 of the book. The nodes and the exercises of the section.

Contents
  1. Fibonacci numbers, their identities and their closed form

Fibonacci numbers, their identities and their closed form

Overview

Section 1.2.8 of TAOCP introduces the Fibonacci numbers FnF_n by the rule that each number is the sum of the two before it. It tells their history, and it proves the main facts that the rest of the book uses: Cassini's identity, the addition formula, the matrix form, and Lucas's theorem that gcd⁡(Fm,Fn)=Fgcd⁡(m,n)\gcd(F_m, F_n) = F_{\gcd(m,n)}. The proof of Lucas's theorem follows the steps of Euclid's algorithm. Then the section builds the generating function G(z)=z/(1−z−z2)G(z) = z/(1 - z - z^2) of the sequence, expands it in partial fractions, and reads off the closed form Fn=(ϕn−ϕ^n)/5F_n = (\phi^n - \hat\phi^n)/\sqrt5 with the golden ratio ϕ\phi and its conjugate ϕ^\hat\phi. Two more results come from the same function: FnF_n is the integer nearest to ϕn/5\phi^n/\sqrt5, and the sum ∑kFkFn−k\sum_k F_k F_{n-k} has a closed form. The section uses induction (Section 1.2.1), the greatest common divisor (Section 1.1) and the binomial coefficients (Section 1.2.6). It looks forward to Section 1.2.9, which treats generating functions in general.

The ideas

Each fact has a short proof by induction, and also a second proof. The identities of the section are of two kinds. Some compare a term with the earlier terms: Cassini's identity and the addition formula. Their proofs are inductions on nn with the rule Fn+2=Fn+1+FnF_{n+2} = F_{n+1} + F_n. The other proof uses a matrix. The 2×22 \times 2 matrix with rows (1,1)(1, 1) and (1,0)(1, 0) has the Fibonacci numbers as the entries of its powers. The determinant of the power gives Cassini's identity, and the rule Am+n=AmAnA^{m+n} = A^m A^n gives the addition formula.

The gcd theorem is Euclid's algorithm in disguise. The addition formula shows that a number that divides FmF_m and FnF_n divides Fm+nF_{m+n}. Together with the fact that FnF_n and Fn+1F_{n+1} have no common factor, this gives the converse. So the pair (Fm,Fn)(F_m, F_n) and the pair (Fm+n,Fn)(F_{m+n}, F_n) have the same common divisors. Subtract nn from mm as often as possible, and the pair becomes (Fr,Fn)(F_r, F_n) with r=m mod nr = m \bmod n. This is one step of Euclid's algorithm on the indices, and the common divisors are not changed. At the end the pair is (Fg,F0)(F_g, F_0) with g=gcd⁡(m,n)g = \gcd(m, n).

A generating function packs the whole sequence into one object. Let G(z)=∑FnznG(z) = \sum F_n z^n. Multiply by zz and by z2z^2, and subtract from G(z)G(z). By the rule of the sequence, all terms vanish except one, and (1−z−z2)G(z)=z(1 - z - z^2) G(z) = z. This is a closed form. The step "if G(z)G(z) exists" in the book is made exact by working with formal power series: the series is an object of algebra, and the division by 1−z−z21 - z - z^2 is allowed since the constant term of this polynomial is 11.

Partial fractions turn the closed form into the formula of Binet. The polynomial 1−z−z21 - z - z^2 is a product (1−ϕz)(1−ϕ^z)(1 - \phi z)(1 - \hat\phi z). The fraction z/(1−z−z2)z/(1 - z - z^2) is the difference of two fractions with one factor each, and each of them is a geometric series. The coefficient of znz^n is then a difference of two powers. The second power is small, and so FnF_n is near ϕn/5\phi^n/\sqrt5.

C1 proves the identities of the section in the order of the book, but it adds a proof with the matrix and a lemma ϕn=Fnϕ+Fn−1\phi^n = F_n \phi + F_{n-1}, which the last result needs. For Lucas's theorem C1 proves the full statement of the book (the common divisors) and then the form with gcd⁡\gcd. The book gives the closed form by the generating function, and C1 also proves it by induction, as a check of the derivation.

Definitions, results and proofs

Example (the first Fibonacci numbers, TAOCP eq. 1.2.8(1)). The sequence of the Fibonacci numbers begins

0,1,1,2,3,5,8,13,21,34,…0, 1, 1, 2, 3, 5, 8, 13, 21, 34, \ldots

Node: TA1E5QGY2H · status: not stated yet

Explanation. Each number after the first two is the sum of the two before it. The list is the first picture of the sequence, and it is the reader's first test for each formula: put in small values and compare. The sequence starts at index 00 with the value 00. The values F1=F2=1F_1 = F_2 = 1 are equal, so the sequence is not strictly increasing until F2F_2.

Example. The first 25 values, from F0F_0 to F24F_{24}, are 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,463680, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368. Each is the sum of the two before it: 17711=10946+676517711 = 10946 + 6765. Some later values are F30=832040F_{30} = 832040 and F40=102334155F_{40} = 102334155.

Proof. The statement is a list of values, and the next definition gives the rule that produces them. Check the list with the rule: F2=1+0=1F_2 = 1 + 0 = 1, F3=1+1=2F_3 = 1 + 1 = 2, F4=2+1=3F_4 = 2 + 1 = 3, F5=3+2=5F_5 = 3 + 2 = 5, F6=5+3=8F_6 = 5 + 3 = 8, F7=13F_7 = 13, F8=21F_8 = 21, F9=34F_9 = 34. □\square

Definition (the Fibonacci numbers, TAOCP eq. 1.2.8(2)). The Fibonacci numbers are the integers given by

F0=0,F1=1,Fn+2=Fn+1+Fn(n≥0).F_0 = 0, \qquad F_1 = 1, \qquad F_{n+2} = F_{n+1} + F_n \quad (n \ge 0).

Node: TA3CRES79K · status: not stated yet

Explanation. This is a recursion of order two, so it needs two starting values. It defines one integer for each n≥0n \ge 0. The numbers get the name of Leonardo of Pisa, called Fibonacci, who put them in a problem on the growth of a population of rabbits in 1202. In the problem, a pair gives birth to a pair each month from the age of one month, and no rabbit dies. Start with one newborn pair. The number of pairs after nn months is Fn+2F_{n+2}, because each month's total is the previous total plus one new pair for each pair that was alive two months before. The same recursion counts the ways to write nn as an ordered sum of 11s and 22s, which is Fn+1F_{n+1} (exercise 1.2.8-16 is the related sum of binomial coefficients). The rule Fn+2=Fn+1+FnF_{n+2} = F_{n+1} + F_n can be run backwards, as Fn=Fn+2−Fn+1F_n = F_{n+2} - F_{n+1}, and this defines FnF_n for negative nn: F−1=1F_{-1} = 1, F−2=−1F_{-2} = -1, and in general F−n=(−1)n+1FnF_{-n} = (-1)^{n+1} F_n (exercise 1.2.8-8). In Lean, Nat.fib is the sequence on the natural numbers, Int.fib of Mathlib is the extension to all integers, and TAOCP.fibInt of the project is the same extension. The recursion is Nat.fib_add_two.

Example. In the rabbit problem the count of pairs at the end of month nn is Fn+2F_{n+2}, that is 1,2,3,5,8,…1, 2, 3, 5, 8, \ldots for n=0,1,2,3,4,…n = 0, 1, 2, 3, 4, \ldots. After 1212 months the count is F14=377F_{14} = 377. For the rule run backwards: F1=F3−F2=2−1=1F_1 = F_3 - F_2 = 2 - 1 = 1, F0=F2−F1=0F_0 = F_2 - F_1 = 0, F−1=F1−F0=1F_{-1} = F_1 - F_0 = 1, F−2=F0−F−1=−1F_{-2} = F_0 - F_{-1} = -1, F−3=F−1−F−2=2F_{-3} = F_{-1} - F_{-2} = 2.

Proof that the rule has one solution. The two starting values and the rule fix FnF_n for n=2,3,…n = 2, 3, \ldots in turn, so there is at most one sequence. A sequence exists, since the rule gives the next value from the two before it. By induction on nn, each FnF_n is a nonnegative integer, and Fn≥1F_n \ge 1 for n≥1n \ge 1, since Fn+2=Fn+1+Fn≥1+0F_{n+2} = F_{n+1} + F_n \ge 1 + 0 when n≥0n \ge 0. □\square

Definition (the golden ratio, TAOCP eq. 1.2.8(3)). The golden ratio is the number

ϕ=1+52=1.6180339887…\phi = \frac{1 + \sqrt5}{2} = 1.6180339887\ldots

Node: TAPK7STDZ5 · status: not stated yet

Explanation. The number ϕ\phi is the positive root of x2=x+1x^2 = x + 1 (eq. 1.2.1(5)). Dividing by xx gives x=1+1/xx = 1 + 1/x, so 1/ϕ=ϕ−1=0.6180339887…1/\phi = \phi - 1 = 0.6180339887\ldots. The old Greek name is the "extreme and mean ratio": a segment is cut in two parts AA and BB with A>BA > B, so that the ratio of the whole to the larger part is the ratio of the larger part to the smaller part. This ratio is ϕ\phi. The reason that ϕ\phi is in a section on the Fibonacci numbers is that the ratios Fn+1/FnF_{n+1}/F_n tend to ϕ\phi and that FnF_n is close to ϕn/5\phi^n/\sqrt5. In Mathlib, Real.goldenRatio is this number and Real.goldenRatio_sq is the equation ϕ2=ϕ+1\phi^2 = \phi + 1.

Example. The ratios Fn+1/FnF_{n+1}/F_n for n=1,…,10n = 1, \ldots, 10 are 1,2,1.5,1.667,1.6,1.625,1.615,1.619,1.6176,1.61811, 2, 1.5, 1.667, 1.6, 1.625, 1.615, 1.619, 1.6176, 1.6181. The last is 89/55=1.6181889/55 = 1.61818, and ϕ=1.61803\phi = 1.61803. The ratios are alternately above and below ϕ\phi. As a check of the equation, ϕ2=2.6180340\phi^2 = 2.6180340 and ϕ+1=2.6180340\phi + 1 = 2.6180340.

Proof that ϕ2=ϕ+1\phi^2 = \phi + 1. By the square, ϕ2=(1+25+5)/4=(3+5)/2=1+(1+5)/2\phi^2 = (1 + 2\sqrt5 + 5)/4 = (3 + \sqrt5)/2 = 1 + (1 + \sqrt5)/2. □\square

Theorem (Cassini's identity, TAOCP eq. 1.2.8(4)). For each integer n≥1n \ge 1,

Fn+1Fn−1−Fn2=(−1)n.F_{n+1} F_{n-1} - F_n^2 = (-1)^n.

Node: TA6QETC2S6 · status: not stated yet

Explanation. The product of the two neighbors of FnF_n differs from Fn2F_n^2 by only 11, with the sign alternating. So the ratio Fn+1/FnF_{n+1}/F_n is nearly equal to Fn/Fn−1F_n/F_{n-1}, which is another way to see that the ratios have a limit. The identity has a consequence that the book uses at once: FnF_n and Fn+1F_{n+1} have no common factor greater than 11, since a common divisor divides (−1)n(-1)^n. It was noticed by Kepler (1608) and published by Cassini (1680). The proof is by induction, and the book also gives a proof with a matrix (see eq. 1.2.8(5)). In Mathlib the identity is Int.fib_succ_mul_fib_pred_sub_fib_sq for the integer-indexed sequence Int.fib, with the sign (-1) ^ |n|, and Nat.fib_coprime_fib_succ is the consequence on common factors.

Example. For n=5n = 5: F6F4−F52=8⋅3−25=−1=(−1)5F_6 F_4 - F_5^2 = 8 \cdot 3 - 25 = -1 = (-1)^5. For n=10n = 10: F11F9−F102=89⋅34−552=3026−3025=1=(−1)10F_{11} F_9 - F_{10}^2 = 89 \cdot 34 - 55^2 = 3026 - 3025 = 1 = (-1)^{10}. The sequence of the differences for n=1,…,8n = 1, \ldots, 8 is −1,1,−1,1,−1,1,−1,1-1, 1, -1, 1, -1, 1, -1, 1.

Proof by induction on nn. For n=1n = 1: F2F0−F12=0−1=−1=(−1)1F_2 F_0 - F_1^2 = 0 - 1 = -1 = (-1)^1. Suppose that the identity holds for an n≥1n \ge 1. Write Dn=Fn+1Fn−1−Fn2D_n = F_{n+1} F_{n-1} - F_n^2. Replace Fn+2F_{n+2} by Fn+1+FnF_{n+1} + F_n in Dn+1D_{n+1}:

Dn+1=Fn+2Fn−Fn+12=(Fn+1+Fn)Fn−Fn+12=Fn+1(Fn−Fn+1)+Fn2.D_{n+1} = F_{n+2} F_n - F_{n+1}^2 = (F_{n+1} + F_n) F_n - F_{n+1}^2 = F_{n+1}(F_n - F_{n+1}) + F_n^2.

Since Fn−Fn+1=−Fn−1F_n - F_{n+1} = -F_{n-1}, this is −Fn+1Fn−1+Fn2=−Dn-F_{n+1}F_{n-1} + F_n^2 = -D_n. By the hypothesis Dn=(−1)nD_n = (-1)^n, so Dn+1=(−1)n+1D_{n+1} = (-1)^{n+1}. □\square

Proof of the consequence. Let dd be a positive common divisor of FnF_n and Fn+1F_{n+1}. It divides Fn+1Fn−1−Fn2=(−1)nF_{n+1}F_{n-1} - F_n^2 = (-1)^n, so d=1d = 1. □\square

Theorem (the matrix form, TAOCP eq. 1.2.8(5)). For each integer n≥1n \ge 1,

(Fn+1FnFnFn−1)=(1110)n.\begin{pmatrix} F_{n+1} & F_n \\ F_n & F_{n-1} \end{pmatrix} = \begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}^n.

Node: TASB15C6AK · status: not stated yet

Explanation. Multiplying a column (Fn+1,Fn)T(F_{n+1}, F_n)^T by the matrix AA with rows (1,1)(1, 1) and (1,0)(1, 0) gives (Fn+1+Fn,Fn+1)T=(Fn+2,Fn+1)T(F_{n+1} + F_n, F_{n+1})^T = (F_{n+2}, F_{n+1})^T. So AA is a machine that makes the next pair of Fibonacci numbers, and the power AnA^n makes the nn-th. The theorem has two uses in the book. The determinant of AA is −1-1, and the determinant of the power is (−1)n(-1)^n, which is Cassini's identity. The rule Am+n=AmAnA^{m+n} = A^m A^n gives the addition formula, eq. 1.2.8(6). It also gives a fast way to compute FnF_n with about lg⁡n\lg n matrix multiplications, by repeated squaring. This is the method that Mathlib's Nat.fastFib uses with F2nF_{2n} and F2n+1F_{2n+1}.

Example. For n=7n = 7 the matrix is (2113138)\begin{pmatrix} 21 & 13 \\ 13 & 8 \end{pmatrix}, with F8=21F_8 = 21, F7=13F_7 = 13 and F6=8F_6 = 8. The determinant is 21⋅8−132=168−169=−1=(−1)721 \cdot 8 - 13^2 = 168 - 169 = -1 = (-1)^7. For n=1n = 1 the matrix is AA itself, (F2F1F1F0)\begin{pmatrix} F_2 & F_1 \\ F_1 & F_0 \end{pmatrix}.

Proof by induction on nn. The case n=1n = 1 is A=(F2F1F1F0)A = \begin{pmatrix} F_2 & F_1 \\ F_1 & F_0 \end{pmatrix}, which is (1110)\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}. Suppose that AnA^n has the form of the theorem. Then

An+1=AnA=(Fn+1FnFnFn−1)(1110)=(Fn+1+FnFn+1Fn+Fn−1Fn)=(Fn+2Fn+1Fn+1Fn),A^{n+1} = A^n A = \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},

by the rule of the sequence. □\square

Second proof of eq. 1.2.8(4). The determinant of a product of square matrices is the product of the determinants. So det⁡An=(det⁡A)n=(−1)n\det A^n = (\det A)^n = (-1)^n. The determinant of the matrix of the theorem is Fn+1Fn−1−Fn2F_{n+1}F_{n-1} - F_n^2. □\square

Theorem (the addition formula, TAOCP eq. 1.2.8(6)). For each integer m≥1m \ge 1 and each integer n≥0n \ge 0,

Fn+m=FmFn+1+Fm−1Fn.F_{n+m} = F_m F_{n+1} + F_{m-1} F_n.

Node: TAV7KXZ6R3 · status: not stated yet

Explanation. The formula says that a Fibonacci number with a large index is a combination of two with smaller indices, and the coefficients are Fibonacci numbers again. It is the sequence's version of the addition formula for the sine. The first cases are Fn+3=2Fn+1+FnF_{n+3} = 2F_{n+1} + F_n and Fn+4=3Fn+1+2FnF_{n+4} = 3F_{n+1} + 2F_n. An induction on kk with m=knm = kn gives Fn∣FknF_n \mid F_{kn}. For example, F3=2F_3 = 2 divides F6=8F_6 = 8 and F9=34F_9 = 34, F4=3F_4 = 3 divides F8=21F_8 = 21 and F12=144F_{12} = 144, and F5=5F_5 = 5 divides F10=55F_{10} = 55 and F15=610F_{15} = 610. This is the start of the theory of the divisibility of the sequence. In Mathlib the formula is Nat.fib_add, which has the form Fm+n+1=FmFn+Fm+1Fn+1F_{m+n+1} = F_m F_n + F_{m+1} F_{n+1}, and the version for integer indices is Int.fib_add.

Example. With n=5n = 5 and m=7m = 7: F12=F7F6+F6F5=13⋅8+8⋅5=104+40=144F_{12} = F_7 F_6 + F_6 F_5 = 13 \cdot 8 + 8 \cdot 5 = 104 + 40 = 144. With m=3m = 3: Fn+3=F3Fn+1+F2Fn=2Fn+1+FnF_{n+3} = F_3 F_{n+1} + F_2 F_n = 2F_{n+1} + F_n, and for n=6n = 6 this is 2⋅13+8=34=F92 \cdot 13 + 8 = 34 = F_9.

Proof by induction on mm. Fix n≥0n \ge 0. For m=1m = 1 the formula is Fn+1=F1Fn+1+F0Fn=Fn+1F_{n+1} = F_1 F_{n+1} + F_0 F_n = F_{n+1}. For m=2m = 2 it is Fn+2=F2Fn+1+F1Fn=Fn+1+FnF_{n+2} = F_2 F_{n+1} + F_1 F_n = F_{n+1} + F_n, which is the rule of the sequence. Let m≥2m \ge 2 and suppose that the formula holds for mm and for m−1m - 1. Add the two instances:

Fn+m+1=Fn+m+Fn+m−1=(Fm+Fm−1)Fn+1+(Fm−1+Fm−2)Fn=Fm+1Fn+1+FmFn.F_{n+m+1} = F_{n+m} + F_{n+m-1} = (F_m + F_{m-1}) F_{n+1} + (F_{m-1} + F_{m-2}) F_n = F_{m+1} F_{n+1} + F_m F_n.

This is the formula for m+1m + 1. □\square

Second proof, by the matrix. For n≥1n \ge 1 and m≥1m \ge 1, the entry at the top right of Am+n=AmAnA^{m+n} = A^m A^n is Fm+n=Fm+1Fn+FmFn−1F_{m+n} = F_{m+1} F_n + F_m F_{n-1} (the top row of AmA^m times the right column of AnA^n). Exchange the names mm and nn to get the formula of the theorem. For n=0n = 0 the formula is trivial. □\square

Theorem (the gcd of two Fibonacci numbers, 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)}.

Node: TATXFT35X5 · status: not stated yet

Explanation. The greatest common divisor of two Fibonacci numbers is a Fibonacci number, and the index is the gcd of the indices. The case gcd⁡(m,n)=1\gcd(m, n) = 1 shows that FmF_m and FnF_n have no common factor when mm and nn have none. Another case: FmF_m divides FnF_n when mm divides nn, as in the explanation of the addition formula, and for m≥3m \ge 3 the converse is true. Indeed Fm∣FnF_m \mid F_n gives Fm=gcd⁡(Fm,Fn)=FgF_m = \gcd(F_m, F_n) = F_g with g=gcd⁡(m,n)≤mg = \gcd(m, n) \le m. For m≥3m \ge 3 and g<mg < m the value Fg≤Fm−1F_g \le F_{m-1} is less than FmF_m, so g=mg = m and m∣nm \mid n. The condition m≥3m \ge 3 is needed: F2=1F_2 = 1 divides every FnF_n. In Mathlib this is Nat.fib_gcd, and the version on the integers is Int.gcd_fib. The equation is stated here with the proof of Theorem 1.2.8A, which is the stronger statement of the book: the set of the common divisors is the set of the divisors of Fgcd⁡(m,n)F_{\gcd(m,n)}.

Example. 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⁡(F15,F20)=gcd⁡(610,6765)=5=F5\gcd(F_{15}, F_{20}) = \gcd(610, 6765) = 5 = F_5. For coprime indices, gcd⁡(F8,F9)=gcd⁡(21,34)=1=F1\gcd(F_8, F_9) = \gcd(21, 34) = 1 = F_1.

Proof. See the proof of Theorem 1.2.8A below. The equation is its last sentence. □\square

Theorem (Lucas, TAOCP Theorem 1.2.8A). Let m,n≥0m, n \ge 0 and g=gcd⁡(m,n)g = \gcd(m, n). A positive integer dd divides both FmF_m and FnF_n if and only if dd divides FgF_g. In particular gcd⁡(Fm,Fn)=Fg\gcd(F_m, F_n) = F_g.

Node: TA1TWRTPFK · status: not stated yet

Explanation. This is the strong form of the gcd theorem, and it is a statement about all common divisors, not only the greatest. The proof runs Euclid's algorithm on the indices. The two lemmas, eq. 1.2.8(8) and (9), say that the common divisors of (Fm,Fn)(F_m, F_n) do not change when mm is replaced by m+nm + n (the first lemma) or by m mod nm \bmod n (the second). Euclid's algorithm on (m,n)(m, n) ends with the pair (g,0)(g, 0), and the common divisors of (Fg,F0)=(Fg,0)(F_g, F_0) = (F_g, 0) are the divisors of FgF_g. The theorem is by Édouard Lucas (1876).

Example. Take m=12m = 12 and n=18n = 18. The common divisors of 144144 and 25842584 are 1,2,4,81, 2, 4, 8, which are the divisors of F6=8F_6 = 8. The steps of Euclid's algorithm on the indices are (12,18)→(18,12)→(12,6)→(6,0)(12, 18) \to (18, 12) \to (12, 6) \to (6, 0). At each step the pair of Fibonacci numbers has the same common divisors: (F12,F18)=(144,2584)(F_{12}, F_{18}) = (144, 2584), then (F18,F12)=(2584,144)(F_{18}, F_{12}) = (2584, 144), then (F12,F6)=(144,8)(F_{12}, F_6) = (144, 8), then (F6,F0)=(8,0)(F_6, F_0) = (8, 0). The common divisors of (144,8)(144, 8) are again 1,2,4,81, 2, 4, 8.

Proof. For a pair (m,n)(m, n) of nonnegative integers, let D(m,n)D(m, n) be the set of the positive integers that divide both FmF_m and FnF_n. By eq. 1.2.8(9), if n≥1n \ge 1 then D(m,n)=D(m mod n,n)D(m, n) = D(m \bmod n, n). The claim is D(m,n)=D(gcd⁡(m,n),0)D(m, n) = D(\gcd(m, n), 0). The proof is by strong induction on nn (the smaller of the pair after one step). If n=0n = 0, then gcd⁡(m,0)=m\gcd(m, 0) = m, and the claim is trivial. If n≥1n \ge 1, then D(m,n)=D(n,m mod n)D(m, n) = D(n, m \bmod n) by the lemma and the symmetry of DD, and gcd⁡(m,n)=gcd⁡(n,m mod n)\gcd(m, n) = \gcd(n, m \bmod n) by the lemma of Algorithm 1.1E. Since m mod n<nm \bmod n < n, the hypothesis gives D(n,m mod n)=D(gcd⁡(n,m mod n),0)D(n, m \bmod n) = D(\gcd(n, m \bmod n), 0). So D(m,n)=D(g,0)D(m, n) = D(g, 0).

Now D(g,0)D(g, 0) is the set of the positive divisors of FgF_g, since each integer divides F0=0F_0 = 0. This is the first statement. For the second, FgF_g is one of the common divisors. If g≥1g \ge 1, then Fg≥1F_g \ge 1, and every positive divisor of FgF_g is at most FgF_g. So the greatest common divisor is FgF_g. If g=0g = 0 then m=n=0m = n = 0, and gcd⁡(0,0)=0=F0\gcd(0, 0) = 0 = F_0. □\square

Lemma (the first step of Theorem 1.2.8A, TAOCP eq. 1.2.8(8)). For all integers m,n≥0m, n \ge 0 and each positive integer dd,

d∣Fm and d∣Fn  ⟺  d∣Fm+n and d∣Fn.d \mid F_m \text{ and } d \mid F_n \iff d \mid F_{m+n} \text{ and } d \mid F_n.

Node: TAKVSF4GGN · status: not stated yet

Explanation. Adding nn to mm does not change the common divisors with FnF_n. The direction from left to right follows from the addition formula: if dd divides FmF_m and FnF_n, then dd divides Fm+nF_{m+n}. The other direction needs that FnF_n and Fn+1F_{n+1} have no common factor, which is Cassini's identity. The reason is as follows. From the addition formula, a common divisor of Fm+nF_{m+n} and FnF_n divides FmFn+1F_m F_{n+1}. The common divisor is a divisor of FnF_n, so it has no factor in common with Fn+1F_{n+1}, and so it divides FmF_m.

Example. Let n=6n = 6 and m=4m = 4, so Fn=8F_n = 8 and Fm=3F_m = 3, Fm+n=F10=55F_{m+n} = F_{10} = 55. The common divisors of (3,8)(3, 8) are {1}\{1\}, and the common divisors of (55,8)(55, 8) are {1}\{1\}. With m=3m = 3, n=6n = 6: F3=2F_3 = 2, F6=8F_6 = 8, F9=34F_9 = 34. The common divisors of (2,8)(2, 8) are 1,21, 2, and of (34,8)(34, 8) they are 1,21, 2.

Proof. If m=0m = 0, then Fm=0F_m = 0 and both sides say "d∣Fnd \mid F_n". Let m≥1m \ge 1. By the addition formula with mm and nn,

Fm+n=FmFn+1+Fm−1Fn.F_{m+n} = F_m F_{n+1} + F_{m-1} F_n.

(⇒\Rightarrow) If d∣Fmd \mid F_m and d∣Fnd \mid F_n, then dd divides each of the two products on the right, so d∣Fm+nd \mid F_{m+n}. (⇐\Leftarrow) Let d∣Fm+nd \mid F_{m+n} and d∣Fnd \mid F_n. Then dd divides Fm+n−Fm−1Fn=FmFn+1F_{m+n} - F_{m-1}F_n = F_m F_{n+1}. By Cassini's identity, gcd⁡(Fn,Fn+1)=1\gcd(F_n, F_{n+1}) = 1. Since d∣Fnd \mid F_n, gcd⁡(d,Fn+1)\gcd(d, F_{n+1}) divides gcd⁡(Fn,Fn+1)=1\gcd(F_n, F_{n+1}) = 1. A number that divides a product and has no factor in common with one of the factors divides the other factor, so d∣Fmd \mid F_m. □\square

Lemma (the second step of Theorem 1.2.8A, TAOCP eq. 1.2.8(9)). For integers m≥0m \ge 0 and n≥1n \ge 1 and each positive integer dd,

d∣Fm and d∣Fn  ⟺  d∣Fm mod n and d∣Fn.d \mid F_m \text{ and } d \mid F_n \iff d \mid F_{m \bmod n} \text{ and } d \mid F_n.

Node: TA1FRXMQ74 · status: not stated yet

Explanation. This is the version of the first lemma that corresponds to a whole run of subtractions. Write m=kn+rm = kn + r with r=m mod nr = m \bmod n. The first lemma says that the common divisors with FnF_n are the same for the indices rr, r+nr + n, r+2nr + 2n, and so on up to r+kn=mr + kn = m. The lemma is the reason why the proof of Theorem 1.2.8A can use the remainder, as Euclid's algorithm does.

Example. Take m=17m = 17 and n=5n = 5, so r=2r = 2. The values are F17=1597F_{17} = 1597, F5=5F_5 = 5, F2=1F_2 = 1. The common divisors of (1597,5)(1597, 5) are {1}\{1\}, and of (1,5)(1, 5) also {1}\{1\}. With m=20m = 20 and n=5n = 5: r=0r = 0, F20=6765F_{20} = 6765 and F5=5F_5 = 5. The common divisors of (6765,5)(6765, 5) are 1,51, 5, and of (F0,F5)=(0,5)(F_0, F_5) = (0, 5) also 1,51, 5.

Proof. For an integer j≥0j \ge 0 let P(j)P(j) be the statement "d∣Fjd \mid F_j and d∣Fnd \mid F_n". The first lemma, with mm replaced by jj, says that P(j)  ⟺  P(j+n)P(j) \iff P(j + n). By induction on kk, P(r)  ⟺  P(r+kn)P(r) \iff P(r + kn) for each k≥0k \ge 0. With m=r+knm = r + kn this is the claim. □\square

Definition (the generating function of the Fibonacci numbers, TAOCP eq. 1.2.8(10)). The generating function of the Fibonacci numbers is the formal power series

G(z)=F0+F1z+F2z2+F3z3+⋯=z+z2+2z3+3z4+5z5+⋯G(z) = F_0 + F_1 z + F_2 z^2 + F_3 z^3 + \cdots = z + z^2 + 2z^3 + 3z^4 + 5z^5 + \cdots

Node: TAJ026XQAQ · status: not stated yet

Explanation. A generating function holds a whole sequence in one object. The coefficient of znz^n is the nn-th term, and algebra on the function is algebra on the sequence. A formal power series is an infinite sum that is never evaluated: two such series are equal if they have the same coefficients, and they are added and multiplied by the rules of polynomials. This is the setting where the question "does G(z)G(z) exist?" of the book has the answer yes at once. For the real or complex value of zz the series converges when ∣z∣<1/ϕ=0.618…|z| < 1/\phi = 0.618\ldots, since Fn≤ϕn−1F_n \le \phi^{n-1} (eq. 1.2.1(3)) and a geometric series with ratio ϕ∣z∣<1\phi |z| < 1 converges. Section 1.2.9 builds a theory of the formal series. The project has TAOCP.ogf, with TAOCP.coeff_ogf for the coefficient, in PowerSeries of Mathlib.

Example. The first six terms are 0+z+z2+2z3+3z4+5z50 + z + z^2 + 2z^3 + 3z^4 + 5z^5. At z=13z = \frac13 the sum is ∑Fn3−n=0.6\sum F_n 3^{-n} = 0.6 to the precision of the first 80 terms. This is the value that the closed form of the next theorem gives, 13/(1−13−19)=13⋅95=35\frac13 / (1 - \frac13 - \frac19) = \frac13 \cdot \frac95 = \frac35.

Proof. The statement is a definition, so there is no proof. The only fact to check is that the series makes sense, and for this it is enough that the coefficients FnF_n are integers, which holds by the definition of the sequence. □\square

Theorem (the closed form of the generating function, TAOCP eq. 1.2.8(11)). The generating function satisfies

G(z)=z1−z−z2.G(z) = \frac{z}{1 - z - z^2}.

Node: TAG6CC9W9B · status: not stated yet

Explanation. The quotient is a rational function, and so the whole sequence F0,F1,F2,…F_0, F_1, F_2, \ldots is described by one fraction with a quadratic denominator. The denominator 1−z−z21 - z - z^2 is the rule Fn+2−Fn+1−Fn=0F_{n+2} - F_{n+1} - F_n = 0 written as a polynomial. The numerator zz comes from the starting values. Any sequence with a linear recursion with constant coefficients has a generating function of this form, a polynomial divided by a polynomial. This is the general method of Section 1.2.9, and it is the method of de Moivre (1722).

Example. Expand z/(1−z−z2)z/(1 - z - z^2) as a power series by long division: z/(1−z−z2)=z(1+(z+z2)+(z+z2)2+⋯ )z/(1 - z - z^2) = z(1 + (z + z^2) + (z + z^2)^2 + \cdots). The terms with z1z^1 to z5z^5 are zz, then z⋅z=z2z \cdot z = z^2, then z(z2+z2)=2z3z(z^2 + z^2) = 2z^3, then z(z3+2z3)=3z4z(z^3 + 2z^3) = 3z^4, then 5z55z^5. These are F1,…,F5F_1, \ldots, F_5.

Proof. Compute the product of G(z)G(z) with 1−z−z21 - z - z^2 in the ring of formal power series. The coefficient of znz^n in (1−z−z2)G(z)(1 - z - z^2)G(z) is Fn−Fn−1−Fn−2F_n - F_{n-1} - F_{n-2}, where terms with a negative index are 00. For n=0n = 0 it is F0=0F_0 = 0. For n=1n = 1 it is F1−F0=1F_1 - F_0 = 1. For n≥2n \ge 2 it is Fn−Fn−1−Fn−2=0F_n - F_{n-1} - F_{n-2} = 0. So (1−z−z2)G(z)=z(1 - z - z^2)G(z) = z. The polynomial 1−z−z21 - z - z^2 has constant term 11, so it has an inverse in the ring of formal power series, and G(z)=z/(1−z−z2)G(z) = z/(1 - z - z^2). □\square

Theorem (the partial fractions of the generating function, TAOCP eq. 1.2.8(12)). With ϕ^=(1−5)/2\hat\phi = (1 - \sqrt5)/2,

G(z)=15(11−ϕz−11−ϕ^z).G(z) = \frac1{\sqrt5} \Bigl( \frac1{1 - \phi z} - \frac1{1 - \hat\phi z} \Bigr).

Node: TANX9HQRXX · status: not stated yet

Explanation. The denominator of GG is a product of two factors with one root each, and this is the reason for the partial fractions. The two fractions on the right are geometric series, and a geometric series has a power of a fixed number as its coefficient. So this form leads to the closed form of FnF_n. The book says that the partial fractions come "after a little calculation". The calculation is the check below, with the two facts that ϕ+ϕ^=1\phi + \hat\phi = 1 and ϕϕ^=−1\phi \hat\phi = -1.

Example. At z=13z = \frac13: 11−ϕ/3=2.1708\frac1{1 - \phi/3} = 2.1708 and 11−ϕ^/3=0.8292\frac1{1 - \hat\phi/3} = 0.8292 to four digits. The difference is 1.34161.3416 and 1.3416/5=0.61.3416/\sqrt5 = 0.6. This is 35\frac35, the value of the closed form at z=13z = \frac13.

Proof. The product of the two denominators is (1−ϕz)(1−ϕ^z)=1−(ϕ+ϕ^)z+ϕϕ^z2=1−z−z2(1 - \phi z)(1 - \hat\phi z) = 1 - (\phi + \hat\phi) z + \phi\hat\phi z^2 = 1 - z - z^2, by the next definition. Put the two fractions over this common denominator:

11−ϕz−11−ϕ^z=(1−ϕ^z)−(1−ϕz)(1−ϕz)(1−ϕ^z)=(ϕ−ϕ^)z1−z−z2.\frac1{1 - \phi z} - \frac1{1 - \hat\phi z} = \frac{(1 - \hat\phi z) - (1 - \phi z)}{(1 - \phi z)(1 - \hat\phi z)} = \frac{(\phi - \hat\phi) z}{1 - z - z^2}.

Since ϕ−ϕ^=5\phi - \hat\phi = \sqrt5, the factor 1/51/\sqrt5 cancels it, and the result is z/(1−z−z2)=G(z)z/(1 - z - z^2) = G(z). □\square

Definition (the conjugate of the golden ratio, TAOCP eq. 1.2.8(13)). The conjugate of ϕ\phi is the number

ϕ^=1−ϕ=1−52=−0.6180339887…\hat\phi = 1 - \phi = \frac{1 - \sqrt5}{2} = -0.6180339887\ldots

Node: TAQ5FQ0YDD · status: not stated yet

Explanation. The number ϕ^\hat\phi is the other root of x2=x+1x^2 = x + 1. The two roots satisfy ϕ+ϕ^=1\phi + \hat\phi = 1 and ϕϕ^=−1\phi\hat\phi = -1, as the sum and the product of the roots of x2−x−1x^2 - x - 1. So ϕ^=−1/ϕ\hat\phi = -1/\phi, and ∣ϕ^∣<1|\hat\phi| < 1. This last fact is why ϕ^n\hat\phi^n is small for large nn. In Mathlib, Real.goldenConj is this number, with Real.goldenRatio_add_goldenConj, Real.goldenRatio_mul_goldenConj, Real.goldenConj_sq and Real.goldenConj_neg.

Example. With ϕ=1.6180340\phi = 1.6180340: ϕ^=−0.6180340\hat\phi = -0.6180340, ϕ+ϕ^=1\phi + \hat\phi = 1, and ϕϕ^=−1.0000000\phi\hat\phi = -1.0000000. The powers are ϕ^2=0.3819660\hat\phi^2 = 0.3819660, ϕ^3=−0.2360680\hat\phi^3 = -0.2360680 and ϕ^4=0.1458980\hat\phi^4 = 0.1458980, which get small. The check of the equation: ϕ^2=0.3819660=ϕ^+1\hat\phi^2 = 0.3819660 = \hat\phi + 1.

Proof of the sum and the product. ϕ+ϕ^=(1+5+1−5)/2=1\phi + \hat\phi = (1 + \sqrt5 + 1 - \sqrt5)/2 = 1. ϕϕ^=(1−5)/4=−1\phi\hat\phi = (1 - 5)/4 = -1. For the equation, ϕ^2=ϕ^⋅ϕ^=ϕ^(1−ϕ)=ϕ^−ϕ^ϕ=ϕ^+1\hat\phi^2 = \hat\phi \cdot \hat\phi = \hat\phi (1 - \phi) = \hat\phi - \hat\phi\phi = \hat\phi + 1. □\square

Theorem (Binet's formula, TAOCP eq. 1.2.8(14)). For each integer n≥0n \ge 0,

Fn=15(ϕn−ϕ^n).F_n = \frac{1}{\sqrt5} (\phi^n - \hat\phi^n).

Node: TA1S39F0N4 · status: not stated yet

Explanation. The Fibonacci numbers are an explicit expression in two powers. The numbers inside are irrational, but the difference is an integer. The formula was found in the early 18th century, by Daniel Bernoulli (1728), and Abraham de Moivre (1722) solved general linear recurrences in the same way. In Mathlib the formula is Real.coe_fib_eq.

Example. For n=10n = 10: ϕ10=122.99187\phi^{10} = 122.99187 and ϕ^10=0.00813\hat\phi^{10} = 0.00813. The difference is 122.98374122.98374, and 122.98374/5=55.00000122.98374/\sqrt5 = 55.00000. This is F10F_{10}. For n=5n = 5: ϕ5=11.09017\phi^5 = 11.09017, ϕ^5=−0.09017\hat\phi^5 = -0.09017, and (11.09017+0.09017)/2.23607=5.00000(11.09017 + 0.09017)/2.23607 = 5.00000.

Proof from the generating function. By eq. 1.2.8(12), G(z)G(z) is the difference of two geometric series. The series 1/(1−ϕz)1/(1 - \phi z) is ∑ϕnzn\sum \phi^n z^n (check by multiplication by 1−ϕz1 - \phi z), and the same holds for ϕ^\hat\phi. So G(z)=15∑n(ϕn−ϕ^n)znG(z) = \frac1{\sqrt5}\sum_n (\phi^n - \hat\phi^n) z^n. Two formal series are equal exactly when they have the same coefficients, and by the definition of GG the coefficient of znz^n is FnF_n. □\square

Second proof, by induction. The formula holds for n=0n = 0: (1−1)/5=0(1 - 1)/\sqrt5 = 0. It holds for n=1n = 1: (ϕ−ϕ^)/5=1(\phi - \hat\phi)/\sqrt5 = 1. Let n≥0n \ge 0 and suppose that it holds for nn and n+1n + 1. Both ϕ\phi and ϕ^\hat\phi satisfy x2=x+1x^2 = x + 1, so xn+2=xn+1+xnx^{n+2} = x^{n+1} + x^n for x=ϕx = \phi and x=ϕ^x = \hat\phi. Subtracting the two equations and dividing by 5\sqrt5 shows that the sequence of the right sides satisfies the rule of the Fibonacci numbers. So it equals Fn+2F_{n+2}. □\square

Theorem (the nearest integer, TAOCP eq. 1.2.8(15)). For each integer 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 the sign (−1)n(-1)^n.

Node: TAQBM3B4M9 · status: not stated yet

Explanation. The second term of Binet's formula is small. Since ∣ϕ^∣<1|\hat\phi| < 1, the quantity ∣ϕ^n/5∣|\hat\phi^n/\sqrt5| is at most 1/5=0.4471/\sqrt5 = 0.447, and it tends to 00 as nn grows. So a computer can find FnF_n by one power and a rounding. The error is of the size ϕ−n/5\phi^{-n}/\sqrt5, and for n=30n = 30 the number ϕ30/5\phi^{30}/\sqrt5 differs from F30F_{30} by only 2.4×10−72.4 \times 10^{-7}. The sign shows that ϕn/5\phi^n/\sqrt5 is above FnF_n for even nn and below it for odd nn (exercise 1.2.8-10).

Example.

nn FnF_n ϕn/5\phi^n/\sqrt5 ϕ^n/5\hat\phi^n/\sqrt5
0 0 0.4472136 0.4472136
1 1 0.7236068 −0.2763932-0.2763932
2 1 1.1708204 0.1708204
5 5 4.9596748 −0.0403252-0.0403252
10 55 55.0036361 0.0036361
11 89 88.9977528 −0.0022472-0.0022472
20 6765 6765.0000296 0.0000296

For n=0n = 0 the rounding gives 00, since 0.447<120.447 < \frac12.

Proof. By Binet's formula, ϕn/5−Fn=ϕ^n/5\phi^n/\sqrt5 - F_n = \hat\phi^n/\sqrt5. For n≥0n \ge 0 the bound 0<∣ϕ^∣n≤10 < |\hat\phi|^n \le 1 holds, so ∣ϕ^n/5∣≤1/5<12|\hat\phi^n/\sqrt5| \le 1/\sqrt5 < \frac12, since 5>2\sqrt5 > 2. An integer that differs from a real number xx by less than 12\frac12 is the integer nearest to xx. The sign of ϕ^n\hat\phi^n is the sign of ϕ^\hat\phi to the nn, which is (−1)n(-1)^n since ϕ^<0\hat\phi < 0. □\square

Theorem (the square of the generating function, TAOCP eq. 1.2.8(16)). In the ring of formal power series,

G(z)2=15(1(1−ϕz)2+1(1−ϕ^z)2−21−z−z2).G(z)^2 = \frac15 \Bigl( \frac1{(1 - \phi z)^2} + \frac1{(1 - \hat\phi z)^2} - \frac2{1 - z - z^2} \Bigr).

Node: TAXSMB21MZ · status: not stated yet

Explanation. The square of a sum of two terms has the two squares and the cross term, and the cross term here has the product of the two fractions, which is 1/(1−z−z2)1/(1 - z - z^2). The right side has three terms, each with a simple series, so the coefficients of G(z)2G(z)^2 can be read off. This is the use of the closed form: a product of two sequences, in the sense of convolution, is turned into a sum of three simple sequences. The convolution of two series is explained in Section 1.2.9.

Example. At z=13z = \frac13: G(z)2=0.36G(z)^2 = 0.36. On the right: 1(1−ϕ/3)2=4.7125\frac1{(1 - \phi/3)^2} = 4.7125, 1(1−ϕ^/3)2=0.6875\frac1{(1 - \hat\phi/3)^2} = 0.6875, 21−z−z2=3.6\frac2{1 - z - z^2} = 3.6. The sum of the first two minus the third is 4.7125+0.6875−3.6=1.80004.7125 + 0.6875 - 3.6 = 1.8000, and 15⋅1.8=0.36\frac15 \cdot 1.8 = 0.36.

Proof. Square the partial fractions of eq. 1.2.8(12): with a=1/(1−ϕz)a = 1/(1 - \phi z) and b=1/(1−ϕ^z)b = 1/(1 - \hat\phi z), the square is G2=15(a−b)2=15(a2+b2−2ab)G^2 = \frac15 (a - b)^2 = \frac15 (a^2 + b^2 - 2ab). The product is ab=1/((1−ϕz)(1−ϕ^z))=1/(1−z−z2)ab = 1/((1 - \phi z)(1 - \hat\phi z)) = 1/(1 - z - z^2), as in the proof of the partial fractions. □\square

Lemma (a power of ϕ\phi in the basis ϕ\phi, 11). For each integer n≥1n \ge 1, ϕn=Fnϕ+Fn−1\phi^n = F_n \phi + F_{n-1}, and the same holds for ϕ^\hat\phi. Consequently ϕn+ϕ^n=Fn+2Fn−1\phi^n + \hat\phi^n = F_n + 2F_{n-1}.

Node: none · Lean: not yet stated

Explanation. Each power of ϕ\phi is a combination of ϕ\phi and 11 with integer coefficients, and the coefficients are Fibonacci numbers (this is exercise 1.2.8-11). The lemma is needed to put the sum ϕn+ϕ^n\phi^n + \hat\phi^n, which appears after the use of eq. 1.2.8(16), in the form of Fibonacci numbers.

Example. For n=4n = 4: ϕ4=3ϕ+2=6.8541\phi^4 = 3\phi + 2 = 6.8541, and F4ϕ+F3=3⋅1.6180340+2=6.8541020F_4 \phi + F_3 = 3 \cdot 1.6180340 + 2 = 6.8541020. The sum ϕ4+ϕ^4=6.8541020+0.1458980=7=F4+2F3=3+4\phi^4 + \hat\phi^4 = 6.8541020 + 0.1458980 = 7 = F_4 + 2F_3 = 3 + 4.

Proof. For n=1n = 1: ϕ=F1ϕ+F0\phi = F_1 \phi + F_0. Let n≥1n \ge 1 and suppose that ϕn=Fnϕ+Fn−1\phi^n = F_n\phi + F_{n-1}. Multiply by ϕ\phi and use ϕ2=ϕ+1\phi^2 = \phi + 1: ϕn+1=Fn(ϕ+1)+Fn−1ϕ=(Fn+Fn−1)ϕ+Fn=Fn+1ϕ+Fn\phi^{n+1} = F_n(\phi + 1) + F_{n-1}\phi = (F_n + F_{n-1})\phi + F_n = F_{n+1}\phi + F_n. The proof for ϕ^\hat\phi is the same, since ϕ^2=ϕ^+1\hat\phi^2 = \hat\phi + 1. Add the two equations and use ϕ+ϕ^=1\phi + \hat\phi = 1: ϕn+ϕ^n=Fn⋅1+2Fn−1\phi^n + \hat\phi^n = F_n \cdot 1 + 2F_{n-1}. □\square

Theorem (the convolution of the Fibonacci numbers, TAOCP eq. 1.2.8(17)). For each integer n≥1n \ge 1,

∑k=0nFkFn−k=15((n+1)(ϕn+ϕ^n)−2Fn+1)=15(n+1)(Fn+2Fn−1)−25Fn+1=15(n−1)Fn+25nFn−1.\sum_{k=0}^{n} F_k F_{n-k} = \frac15 \bigl( (n+1)(\phi^n + \hat\phi^n) - 2F_{n+1} \bigr) = \frac15 (n+1)(F_n + 2F_{n-1}) - \frac25 F_{n+1} = \frac15 (n-1) F_n + \frac25 n F_{n-1}.

Node: TAF9PG9N45 · status: not stated yet

Explanation. The sum of the products FkFn−kF_k F_{n-k} is a convolution, and the coefficient of znz^n in G(z)2G(z)^2 is exactly this sum. The theorem finds a closed form for it. It is not a Fibonacci number, but a combination of two Fibonacci numbers with coefficients that are linear in nn. The first term has a factor nn that comes from the series of 1/(1−ϕz)21/(1 - \phi z)^2. This is the first example of the rule that a repeated root of the denominator gives a factor of nn.

Example. For n=6n = 6: F0F6+F1F5+F2F4+F3F3+F4F2+F5F1+F6F0=0+5+3+4+3+5+0=20F_0F_6 + F_1F_5 + F_2F_4 + F_3F_3 + F_4F_2 + F_5F_1 + F_6F_0 = 0 + 5 + 3 + 4 + 3 + 5 + 0 = 20. The formula gives 15(5⋅8+12⋅5)=15(40+60)=20\frac15(5 \cdot 8 + 12 \cdot 5) = \frac15(40 + 60) = 20. The first values of the sum for n=1,…,8n = 1, \ldots, 8 are 0,1,2,5,10,20,38,710, 1, 2, 5, 10, 20, 38, 71.

Proof. The coefficient of znz^n in G(z)2G(z)^2 is the convolution ∑k=0nFkFn−k\sum_{k=0}^n F_kF_{n-k} by the product rule for series (Section 1.2.9). Read the coefficient from eq. 1.2.8(16). The series 1/(1−ϕz)21/(1 - \phi z)^2 is the square of ∑ϕnzn\sum \phi^n z^n, so the coefficient of znz^n in it is ∑k=0nϕkϕn−k=(n+1)ϕn\sum_{k=0}^n \phi^k\phi^{n-k} = (n+1)\phi^n. The same holds for ϕ^\hat\phi. The coefficient of znz^n in 1/(1−z−z2)1/(1 - z - z^2) is Fn+1F_{n+1}, since z/(1−z−z2)=G(z)z/(1 - z - z^2) = G(z) and the shift by one place moves the coefficient. Hence the coefficient of znz^n in G2G^2 is 15((n+1)ϕn+(n+1)ϕ^n−2Fn+1)\frac15((n+1)\phi^n + (n+1)\hat\phi^n - 2F_{n+1}). By the lemma, ϕn+ϕ^n=Fn+2Fn−1\phi^n + \hat\phi^n = F_n + 2F_{n-1} for n≥1n \ge 1. This gives the second form. For the third form use Fn+1=Fn+Fn−1F_{n+1} = F_n + F_{n-1}:

(n+1)(Fn+2Fn−1)−2(Fn+Fn−1)=(n−1)Fn+2nFn−1.(n+1)(F_n + 2F_{n-1}) - 2(F_n + F_{n-1}) = (n-1) F_n + 2n F_{n-1}.

Divide by 55. □\square

Algorithms and programs

Section 1.2.8 has no algorithm and no program. It mentions Algorithm 1.1E twice. Its proof of Lucas's theorem follows the steps of Euclid's algorithm on the indices, and the history of the section names the bound of E. Leger (1837) on the work of the algorithm: for inputs m,n≤Fkm, n \le F_k, the division step of Algorithm 1.1E is done no more than k−1k - 1 times. The full statement and its proof are Theorem 4.5.3F of the book. The fast way to compute FnF_n with the matrix of eq. 1.2.8(5), by repeated squaring, is not an algorithm of the book, but it is a good use of the theorem.

The exercises

The table has the exercises of Section 1.2.8. The kind is the class of spec 06.3 that C1 proposes, and the indexer of S0 fixes it in the map. The book marks no exercise of this section as recommended in the text that C1 reads.

Exercise Rating Markers Kind Lean Solution
1.2.8-1 10 K3 not yet stated X1, 1.2.8-1
1.2.8-2 20 K3 not yet stated X1, 1.2.8-2
1.2.8-3 25 K5 not yet stated X1, 1.2.8-3
1.2.8-4 14 K3 not yet stated X1, 1.2.8-4
1.2.8-5 20 K3 not yet stated X1, 1.2.8-5
1.2.8-6 10 HM K1 not yet stated X1, 1.2.8-6
1.2.8-7 15 K1 not yet stated X1, 1.2.8-7
1.2.8-8 15 K3 not yet stated X1, 1.2.8-8
1.2.8-9 20 M K2 not yet stated X1, 1.2.8-9
1.2.8-10 15 K2 not yet stated X1, 1.2.8-10
1.2.8-11 20 M K1 not yet stated X1, 1.2.8-11
1.2.8-12 26 M K3 not yet stated X1, 1.2.8-12
1.2.8-13 22 M K3 not yet stated X1, 1.2.8-13
1.2.8-14 28 M K3 not yet stated X1, 1.2.8-14
1.2.8-15 22 M K3 not yet stated X1, 1.2.8-15
1.2.8-16 20 M K1 not yet stated X1, 1.2.8-16
1.2.8-17 24 M K1 not yet stated X1, 1.2.8-17
1.2.8-18 20 K2 not yet stated X1, 1.2.8-18
1.2.8-19 27 M K3 not yet stated X1, 1.2.8-19
1.2.8-20 16 M K3 not yet stated X1, 1.2.8-20
1.2.8-21 25 M K3 not yet stated X1, 1.2.8-21
1.2.8-22 20 M K1 not yet stated X1, 1.2.8-22
1.2.8-23 23 M K1 not yet stated X1, 1.2.8-23
1.2.8-24 20 HM K3 not yet stated X1, 1.2.8-24
1.2.8-25 21 M K1 not yet stated X1, 1.2.8-25
1.2.8-26 20 M K1 not yet stated X1, 1.2.8-26
1.2.8-27 20 M K1 not yet stated X1, 1.2.8-27
1.2.8-28 21 M K3 not yet stated X1, 1.2.8-28
1.2.8-29 23 M K1 not yet stated X1, 1.2.8-29
1.2.8-30 38 M K1 not yet stated X1, 1.2.8-30
1.2.8-31 20 M K1 not yet stated X1, 1.2.8-31
1.2.8-32 24 M K1 not yet stated X1, 1.2.8-32
1.2.8-33 24 HM K1 not yet stated X1, 1.2.8-33
1.2.8-34 24 M K1 not yet stated X1, 1.2.8-34
1.2.8-35 24 M K1 not yet stated X1, 1.2.8-35
1.2.8-36 32 M informal not yet stated X1, 1.2.8-36
1.2.8-37 35 M K3 not yet stated X1, 1.2.8-37
1.2.8-38 35 K5 not yet stated X1, 1.2.8-38
1.2.8-39 24 M K3 not yet stated X1, 1.2.8-39
1.2.8-40 25 M K3 not yet stated X1, 1.2.8-40
1.2.8-41 25 M K1 not yet stated X1, 1.2.8-41
1.2.8-42 26 M K1 not yet stated X1, 1.2.8-42

The order to do them: 1.2.8-1, 4 and 5 first, to get used to the numbers. Then 1.2.8-6, 7 and 8, which are about the matrix form, about composite indices and about the extension to negative indices. Exercise 1.2.8-9 asks which of the identities of the section survive with negative indices, and 1.2.8-17 is the general form of Cassini's identity in that setting. Exercises 1.2.8-11, 12, 13 and 20 use the lemma ϕn=Fnϕ+Fn−1\phi^n = F_n\phi + F_{n-1} or the generating function, and they train the method of the section. Exercises 1.2.8-14 and 15 are the same method with an extra term in the recursion. Exercises 1.2.8-16, 22, 23 and 25 connect the numbers with binomial coefficients. Exercises 1.2.8-26 and 27 give the behavior of FpF_p modulo a prime pp, and 1.2.8-32 is the remainder of one Fibonacci number by another. Exercises 1.2.8-34, 35, 41 and 42 are about the Fibonacci number system and the phi number system, and they are done together. Exercise 1.2.8-30 is the hardest of the set that has a proof, and it comes after 1.2.8-29, the Fibonomial coefficients. Exercises 1.2.8-37 and 38 are the game of chips of Gaskell and Whinihan, and the Fibonacci number system of exercise 34 is its key. Exercises 1.2.8-3 and 38 ask for programs.

Lean

The Lean code of tamnd/taocp-lean at main (commit 6a92ed9) has no declaration for an item of Section 1.2.8 yet, so each Node line of this chapter says "not yet stated". It has TAOCP.fibInt, the extension of the Fibonacci numbers to all integers, with TAOCP.fibInt_natCast and TAOCP.fibInt_neg_natCast, in TAOCP/Notation/Fibonacci.lean, and TAOCP.ogf and TAOCP.coeff_ogf_mul for generating functions in TAOCP/Notation/GenFun.lean. The Mathlib names that the statements will use are these. Each name was found in the source of Mathlib at the time of writing.

  • The sequence: Nat.fib, with Nat.fib_zero, Nat.fib_one and Nat.fib_add_two for eq. 1.2.8(2). For all integer indices there is Int.fib, with Int.fib_add_two, Int.fib_neg_natCast for F−n=(−1)n+1FnF_{-n} = (-1)^{n+1}F_n and Int.fib_neg.
  • The golden ratio and its conjugate: Real.goldenRatio and Real.goldenConj, with Real.goldenRatio_sq and Real.goldenConj_sq for the equation x2=x+1x^2 = x + 1, Real.goldenRatio_add_goldenConj and Real.goldenRatio_mul_goldenConj for the sum 11 and the product −1-1, and Real.goldenConj_neg for the sign.
  • Binet's formula, eq. 1.2.8(14): Real.coe_fib_eq, with Real.coe_fib_eq' as the same formula for the functions of nn, and Real.coe_intFib_eq for all integer indices.
  • Cassini's identity and the addition formula: Int.fib_succ_mul_fib_pred_sub_fib_sq for the integer-indexed sequence, Nat.fib_add and Int.fib_add for the addition formula, and Nat.fib_coprime_fib_succ for the consequence on common factors.
  • The gcd theorem: Nat.fib_gcd for gcd⁡(Fm,Fn)=Fgcd⁡(m,n)\gcd(F_m, F_n) = F_{\gcd(m,n)} and Int.gcd_fib. The divisibility Int.fib_dvd is the statement that m∣nm \mid n gives Fm∣FnF_m \mid F_n. Mathlib has no statement of the form "the set of common divisors is the set of divisors of FgF_g", so a Lean form of Theorem 1.2.8A is stated with Nat.fib_gcd and the divisibility of a common divisor.
  • Mathlib has no theorem for the matrix form of eq. 1.2.8(5) and for the generating function z/(1−z−z2)z/(1 - z - z^2) of the sequence. They are stated in PowerSeries and in Matrix of Mathlib. The nearest integer, eq. 1.2.8(15), is a statement with round and Real.coe_fib_eq.

Theorem 1.2.8A has the divisors as a set, and this is a statement about all common divisors. The fidelity choice for a Lean statement is the form "for each dd, d∣Fm∧d∣Fn↔d∣Fgcd⁡(m,n)d \mid F_m \wedge d \mid F_n \leftrightarrow d \mid F_{\gcd(m,n)}", which is the book's form and is stronger than Nat.fib_gcd.

Notes and history

The sequence is older than Leonardo of Pisa. Indian writers on poetic meter knew it first. A meter of total length nn made of short syllables (one beat) and long syllables (two beats) can be built in Fn+1F_{n+1} ways, and Gopala (before 1135) and Hemacandra (about 1150) list these counts. Johannes Kepler (1611) wrote about the numbers, and he noticed that the ratios of the neighbors tend to a limit. The limit ϕ\phi of the ratios Fn+1/FnF_{n+1}/F_n was already known to Simon Jacob (died 1564), a German teacher of arithmetic.

The name "Fibonacci numbers" is due to Édouard Lucas, who found the great theorems of the sequence in the 1870s, including Theorem 1.2.8A (1876) and the proof that the number 2127−12^{127} - 1 is prime (1876), which used the related sequence Ln=ϕn+ϕ^nL_n = \phi^n + \hat\phi^n. Binet's name is attached to eq. 1.2.8(14), but the formula was known to Daniel Bernoulli and Leonhard Euler about a century before Jacques Binet (1843). The method by generating functions goes back to Abraham de Moivre. Cassini's identity was found by Johannes Kepler before J. D. Cassini published it in 1680. The golden ratio has a long literature: Euclid has the extreme and mean ratio in the Elements, and H. S. M. Coxeter gives a survey. The identity of exercise 1.2.8-41 is from Yuri Matiyasevich (1990).

The bound of E. Leger (1837) on the steps of Euclid's algorithm was the first application of the sequence to an algorithm, and Theorem 4.5.3F gives it in full. Later chapters use the numbers for the Fibonacci search (Section 6.2.1), for the merge sort with polyphase merging (Section 5.4.2) and for the Fibonacci heaps of the literature. The numbers also come up in the exercises on the Zeckendorf representation (exercise 1.2.8-34), which writes each positive integer as a sum of non-adjacent Fibonacci numbers in exactly one way.

The project has no errata of Section 1.2.8 to report.

Section 1.2.8 of TAOCP studies the sequence 0,1,1,2,3,5,8,…0, 1, 1, 2, 3, 5, 8, \ldots in which each number is the sum of the two before it. The section proves four kinds of facts about it: identities such as Cassini's, a theorem on greatest common divisors, a closed form in the golden ratio, and a sum of products. The closed form comes from the generating function of the sequence, which is the first use of this method in the book. This chapter of C1 explains each item of the section, proves each result in full, and checks each formula on numbers.

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