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.
Fibonacci numbers, their identities and their closed form
Overview
Section 1.2.8 of TAOCP introduces the Fibonacci numbers 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 . The proof of Lucas's theorem follows the steps of Euclid's algorithm. Then the section builds the generating function of the sequence, expands it in partial fractions, and reads off the closed form with the golden ratio and its conjugate . Two more results come from the same function: is the integer nearest to , and the sum 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 with the rule . The other proof uses a matrix. The matrix with rows and has the Fibonacci numbers as the entries of its powers. The determinant of the power gives Cassini's identity, and the rule gives the addition formula.
The gcd theorem is Euclid's algorithm in disguise. The addition formula shows that a number that divides and divides . Together with the fact that and have no common factor, this gives the converse. So the pair and the pair have the same common divisors. Subtract from as often as possible, and the pair becomes with . This is one step of Euclid's algorithm on the indices, and the common divisors are not changed. At the end the pair is with .
A generating function packs the whole sequence into one object. Let . Multiply by and by , and subtract from . By the rule of the sequence, all terms vanish except one, and . This is a closed form. The step "if exists" in the book is made exact by working with formal power series: the series is an object of algebra, and the division by is allowed since the constant term of this polynomial is .
Partial fractions turn the closed form into the formula of Binet. The polynomial is a product . The fraction is the difference of two fractions with one factor each, and each of them is a geometric series. The coefficient of is then a difference of two powers. The second power is small, and so is near .
C1 proves the identities of the section in the order of the book, but it adds a proof with the matrix and a lemma , 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 . 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
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 with the value . The values are equal, so the sequence is not strictly increasing until .
Example. The first 25 values, from to , are . Each is the sum of the two before it: . Some later values are and .
Proof. The statement is a list of values, and the next definition gives the rule that produces them. Check the list with the rule: , , , , , , , .
Definition (the Fibonacci numbers, TAOCP eq. 1.2.8(2)). The Fibonacci numbers are the integers given by
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 . 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 months is , 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 as an ordered sum of s and s, which is (exercise 1.2.8-16 is the related sum of binomial coefficients). The rule can be run backwards, as , and this defines for negative : , , and in general (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 is , that is for . After months the count is . For the rule run backwards: , , , , .
Proof that the rule has one solution. The two starting values and the rule fix for 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 , each is a nonnegative integer, and for , since when .
Definition (the golden ratio, TAOCP eq. 1.2.8(3)). The golden ratio is the number
Node: TAPK7STDZ5 · status: not stated yet
Explanation. The number is the positive root of (eq. 1.2.1(5)). Dividing by gives , so . The old Greek name is the "extreme and mean ratio": a segment is cut in two parts and with , 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 . The reason that is in a section on the Fibonacci numbers is that the ratios tend to and that is close to . In Mathlib, Real.goldenRatio is this number and Real.goldenRatio_sq is the equation .
Example. The ratios for are . The last is , and . The ratios are alternately above and below . As a check of the equation, and .
Proof that . By the square, .
Theorem (Cassini's identity, TAOCP eq. 1.2.8(4)). For each integer ,
Node: TA6QETC2S6 · status: not stated yet
Explanation. The product of the two neighbors of differs from by only , with the sign alternating. So the ratio is nearly equal to , which is another way to see that the ratios have a limit. The identity has a consequence that the book uses at once: and have no common factor greater than , since a common divisor divides . 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 : . For : . The sequence of the differences for is .
Proof by induction on . For : . Suppose that the identity holds for an . Write . Replace by in :
Since , this is . By the hypothesis , so .
Proof of the consequence. Let be a positive common divisor of and . It divides , so .
Theorem (the matrix form, TAOCP eq. 1.2.8(5)). For each integer ,
Node: TASB15C6AK · status: not stated yet
Explanation. Multiplying a column by the matrix with rows and gives . So is a machine that makes the next pair of Fibonacci numbers, and the power makes the -th. The theorem has two uses in the book. The determinant of is , and the determinant of the power is , which is Cassini's identity. The rule gives the addition formula, eq. 1.2.8(6). It also gives a fast way to compute with about matrix multiplications, by repeated squaring. This is the method that Mathlib's Nat.fastFib uses with and .
Example. For the matrix is , with , and . The determinant is . For the matrix is itself, .
Proof by induction on . The case is , which is . Suppose that has the form of the theorem. Then
by the rule of the sequence.
Second proof of eq. 1.2.8(4). The determinant of a product of square matrices is the product of the determinants. So . The determinant of the matrix of the theorem is .
Theorem (the addition formula, TAOCP eq. 1.2.8(6)). For each integer and each integer ,
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 and . An induction on with gives . For example, divides and , divides and , and divides and . 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 , and the version for integer indices is Int.fib_add.
Example. With and : . With : , and for this is .
Proof by induction on . Fix . For the formula is . For it is , which is the rule of the sequence. Let and suppose that the formula holds for and for . Add the two instances:
This is the formula for .
Second proof, by the matrix. For and , the entry at the top right of is (the top row of times the right column of ). Exchange the names and to get the formula of the theorem. For the formula is trivial.
Theorem (the gcd of two Fibonacci numbers, TAOCP eq. 1.2.8(7)). For all integers ,
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 shows that and have no common factor when and have none. Another case: divides when divides , as in the explanation of the addition formula, and for the converse is true. Indeed gives with . For and the value is less than , so and . The condition is needed: divides every . 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 .
Example. , and . Also . For coprime indices, .
Proof. See the proof of Theorem 1.2.8A below. The equation is its last sentence.
Theorem (Lucas, TAOCP Theorem 1.2.8A). Let and . A positive integer divides both and if and only if divides . In particular .
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 do not change when is replaced by (the first lemma) or by (the second). Euclid's algorithm on ends with the pair , and the common divisors of are the divisors of . The theorem is by Édouard Lucas (1876).
Example. Take and . The common divisors of and are , which are the divisors of . The steps of Euclid's algorithm on the indices are . At each step the pair of Fibonacci numbers has the same common divisors: , then , then , then . The common divisors of are again .
Proof. For a pair of nonnegative integers, let be the set of the positive integers that divide both and . By eq. 1.2.8(9), if then . The claim is . The proof is by strong induction on (the smaller of the pair after one step). If , then , and the claim is trivial. If , then by the lemma and the symmetry of , and by the lemma of Algorithm 1.1E. Since , the hypothesis gives . So .
Now is the set of the positive divisors of , since each integer divides . This is the first statement. For the second, is one of the common divisors. If , then , and every positive divisor of is at most . So the greatest common divisor is . If then , and .
Lemma (the first step of Theorem 1.2.8A, TAOCP eq. 1.2.8(8)). For all integers and each positive integer ,
Node: TAKVSF4GGN · status: not stated yet
Explanation. Adding to does not change the common divisors with . The direction from left to right follows from the addition formula: if divides and , then divides . The other direction needs that and have no common factor, which is Cassini's identity. The reason is as follows. From the addition formula, a common divisor of and divides . The common divisor is a divisor of , so it has no factor in common with , and so it divides .
Example. Let and , so and , . The common divisors of are , and the common divisors of are . With , : , , . The common divisors of are , and of they are .
Proof. If , then and both sides say "". Let . By the addition formula with and ,
() If and , then divides each of the two products on the right, so . () Let and . Then divides . By Cassini's identity, . Since , divides . A number that divides a product and has no factor in common with one of the factors divides the other factor, so .
Lemma (the second step of Theorem 1.2.8A, TAOCP eq. 1.2.8(9)). For integers and and each positive integer ,
Node: TA1FRXMQ74 · status: not stated yet
Explanation. This is the version of the first lemma that corresponds to a whole run of subtractions. Write with . The first lemma says that the common divisors with are the same for the indices , , , and so on up to . The lemma is the reason why the proof of Theorem 1.2.8A can use the remainder, as Euclid's algorithm does.
Example. Take and , so . The values are , , . The common divisors of are , and of also . With and : , and . The common divisors of are , and of also .
Proof. For an integer let be the statement " and ". The first lemma, with replaced by , says that . By induction on , for each . With this is the claim.
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
Node: TAJ026XQAQ · status: not stated yet
Explanation. A generating function holds a whole sequence in one object. The coefficient of is the -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 exist?" of the book has the answer yes at once. For the real or complex value of the series converges when , since (eq. 1.2.1(3)) and a geometric series with ratio 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 . At the sum is to the precision of the first 80 terms. This is the value that the closed form of the next theorem gives, .
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 are integers, which holds by the definition of the sequence.
Theorem (the closed form of the generating function, TAOCP eq. 1.2.8(11)). The generating function satisfies
Node: TAG6CC9W9B · status: not stated yet
Explanation. The quotient is a rational function, and so the whole sequence is described by one fraction with a quadratic denominator. The denominator is the rule written as a polynomial. The numerator 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 as a power series by long division: . The terms with to are , then , then , then , then . These are .
Proof. Compute the product of with in the ring of formal power series. The coefficient of in is , where terms with a negative index are . For it is . For it is . For it is . So . The polynomial has constant term , so it has an inverse in the ring of formal power series, and .
Theorem (the partial fractions of the generating function, TAOCP eq. 1.2.8(12)). With ,
Node: TANX9HQRXX · status: not stated yet
Explanation. The denominator of 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 . The book says that the partial fractions come "after a little calculation". The calculation is the check below, with the two facts that and .
Example. At : and to four digits. The difference is and . This is , the value of the closed form at .
Proof. The product of the two denominators is , by the next definition. Put the two fractions over this common denominator:
Since , the factor cancels it, and the result is .
Definition (the conjugate of the golden ratio, TAOCP eq. 1.2.8(13)). The conjugate of is the number
Node: TAQ5FQ0YDD · status: not stated yet
Explanation. The number is the other root of . The two roots satisfy and , as the sum and the product of the roots of . So , and . This last fact is why is small for large . 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 : , , and . The powers are , and , which get small. The check of the equation: .
Proof of the sum and the product. . . For the equation, .
Theorem (Binet's formula, TAOCP eq. 1.2.8(14)). For each integer ,
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 : and . The difference is , and . This is . For : , , and .
Proof from the generating function. By eq. 1.2.8(12), is the difference of two geometric series. The series is (check by multiplication by ), and the same holds for . So . Two formal series are equal exactly when they have the same coefficients, and by the definition of the coefficient of is .
Second proof, by induction. The formula holds for : . It holds for : . Let and suppose that it holds for and . Both and satisfy , so for and . Subtracting the two equations and dividing by shows that the sequence of the right sides satisfies the rule of the Fibonacci numbers. So it equals .
Theorem (the nearest integer, TAOCP eq. 1.2.8(15)). For each integer , is the integer nearest to . More exactly, , which has absolute value less than , and the sign .
Node: TAQBM3B4M9 · status: not stated yet
Explanation. The second term of Binet's formula is small. Since , the quantity is at most , and it tends to as grows. So a computer can find by one power and a rounding. The error is of the size , and for the number differs from by only . The sign shows that is above for even and below it for odd (exercise 1.2.8-10).
Example.
| 0 | 0 | 0.4472136 | 0.4472136 |
| 1 | 1 | 0.7236068 | |
| 2 | 1 | 1.1708204 | 0.1708204 |
| 5 | 5 | 4.9596748 | |
| 10 | 55 | 55.0036361 | 0.0036361 |
| 11 | 89 | 88.9977528 | |
| 20 | 6765 | 6765.0000296 | 0.0000296 |
For the rounding gives , since .
Proof. By Binet's formula, . For the bound holds, so , since . An integer that differs from a real number by less than is the integer nearest to . The sign of is the sign of to the , which is since .
Theorem (the square of the generating function, TAOCP eq. 1.2.8(16)). In the ring of formal power series,
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 . The right side has three terms, each with a simple series, so the coefficients of 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 : . On the right: , , . The sum of the first two minus the third is , and .
Proof. Square the partial fractions of eq. 1.2.8(12): with and , the square is . The product is , as in the proof of the partial fractions.
Lemma (a power of in the basis , ). For each integer , , and the same holds for . Consequently .
Node: none · Lean: not yet stated
Explanation. Each power of is a combination of and with integer coefficients, and the coefficients are Fibonacci numbers (this is exercise 1.2.8-11). The lemma is needed to put the sum , which appears after the use of eq. 1.2.8(16), in the form of Fibonacci numbers.
Example. For : , and . The sum .
Proof. For : . Let and suppose that . Multiply by and use : . The proof for is the same, since . Add the two equations and use : .
Theorem (the convolution of the Fibonacci numbers, TAOCP eq. 1.2.8(17)). For each integer ,
Node: TAF9PG9N45 · status: not stated yet
Explanation. The sum of the products is a convolution, and the coefficient of in 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 . The first term has a factor that comes from the series of . This is the first example of the rule that a repeated root of the denominator gives a factor of .
Example. For : . The formula gives . The first values of the sum for are .
Proof. The coefficient of in is the convolution by the product rule for series (Section 1.2.9). Read the coefficient from eq. 1.2.8(16). The series is the square of , so the coefficient of in it is . The same holds for . The coefficient of in is , since and the shift by one place moves the coefficient. Hence the coefficient of in is . By the lemma, for . This gives the second form. For the third form use :
Divide by .
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 , the division step of Algorithm 1.1E is done no more than times. The full statement and its proof are Theorem 4.5.3F of the book. The fast way to compute 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 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 modulo a prime , 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, withNat.fib_zero,Nat.fib_oneandNat.fib_add_twofor eq. 1.2.8(2). For all integer indices there isInt.fib, withInt.fib_add_two,Int.fib_neg_natCastfor andInt.fib_neg. - The golden ratio and its conjugate:
Real.goldenRatioandReal.goldenConj, withReal.goldenRatio_sqandReal.goldenConj_sqfor the equation ,Real.goldenRatio_add_goldenConjandReal.goldenRatio_mul_goldenConjfor the sum and the product , andReal.goldenConj_negfor the sign. - Binet's formula, eq. 1.2.8(14):
Real.coe_fib_eq, withReal.coe_fib_eq'as the same formula for the functions of , andReal.coe_intFib_eqfor all integer indices. - Cassini's identity and the addition formula:
Int.fib_succ_mul_fib_pred_sub_fib_sqfor the integer-indexed sequence,Nat.fib_addandInt.fib_addfor the addition formula, andNat.fib_coprime_fib_succfor the consequence on common factors. - The gcd theorem:
Nat.fib_gcdfor andInt.gcd_fib. The divisibilityInt.fib_dvdis the statement that gives . Mathlib has no statement of the form "the set of common divisors is the set of divisors of ", so a Lean form of Theorem 1.2.8A is stated withNat.fib_gcdand 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 of the sequence. They are stated in
PowerSeriesand inMatrixof Mathlib. The nearest integer, eq. 1.2.8(15), is a statement withroundandReal.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 , ", 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 made of short syllables (one beat) and long syllables (two beats) can be built in 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 of the ratios 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 is prime (1876), which used the related sequence . 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 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.