Volume C1 · Basic concepts · TAOCP Section 1.2.7
Harmonic 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.7 of the book. The nodes and the exercises of the section.
Harmonic numbers and sums that contain them
Overview
Section 1.2.7 of TAOCP names one sum, the harmonic number , and collects what a reader of the later chapters needs about it. The section shows that grows without bound but very slowly, and it gives the asymptotic series . It defines the harmonic numbers of order , , which stay bounded for , and it quotes Euler's values of their limit at even . Then it turns to sums that have as a factor. Three of them are done: , the sum with binomial weights by summation by parts, and the sum , which ends in Theorem 1.2.7A. The section uses the sums and the binomial coefficients of Sections 1.2.3 and 1.2.6. It points forward to Section 1.2.9, which gives the series of the logarithm, and to Section 1.2.11.2, which proves the asymptotic series.
The ideas
The sum grows like a logarithm. Each new term of is smaller than the one before, so it is easy to believe that the sum levels off. It does not. The terms from to are numbers, and each is at least , so the block adds at least . The sum grows by each time the index doubles. This is the behavior of a logarithm. The exact statement is eq. 1.2.7(3): is plus a constant plus a small correction that has an inverse power of in each term.
Raising the exponent makes the sum converge. If each term is with , then the sum stays below a fixed bound. The comparison with an integral shows this: the sum is less than . The limit is the zeta function. At even the limit is a rational multiple of , and the multiple comes from a Bernoulli number. The book quotes these values without proof. The C1 chapter proves them with the Fourier series of the Bernoulli polynomials.
A sum with as a factor is done in two ways. One way is to write as a sum, and to exchange the order of the two sums. This gives . The other way is summation by parts, the discrete form of integration by parts. It works when one factor of the term has a simple sum and the other has a simple difference. For , the sum of is a binomial coefficient, and the difference of is . The result is eq. 1.2.7(9).
A recursion in gives a closed form. For the sum , the rule gives a first order recursion for . Divide by and the recursion becomes a telescoping sum. The series of the logarithm turns the closed form into an approximation, and this is Theorem 1.2.7A.
C1 proves eq. 1.2.7(9) by induction on and gives the book's derivation by parts as a second proof. The book states the asymptotic series (3) and the values (6) of the zeta function without proof, and the proof is left to Section 1.2.11.2 and to the literature. C1 proves (6) in full, and it proves (3) from Euler's summation formula of Section 1.2.11.2.
Definitions, results and proofs
Definition C1.1.2.7.1 (the harmonic number, TAOCP eq. 1.2.7(1)). For an integer , the harmonic number is the following sum, which is empty and equal to for :
Node: TAJ5CTXKS5 · Lean: TAOCP.S1_2_7.eq1 · status: proved
Explanation. The number is rational. It is the partial sum of the harmonic series, and this is the reason for the name. It has the recursion for , so the differences of are the simple numbers . This is what makes the sums of Sections 1.2.7 and 1.2.9 work: is to what is to . In the literature the number also appears as , where is the logarithmic derivative of the gamma function. In Mathlib the number is harmonic n, of type ℚ, with harmonic_zero and harmonic_succ. The project defines as TAOCP.harmonicPow r n, and TAOCP.harmonicPow_one shows that it agrees with harmonic n at .
Example. The first values are
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
|---|---|---|---|---|---|---|---|---|---|
For the value is . Note that the denominator of is , not , because . The fractions are reduced.
Proof of the recursion. A sum over is the sum over plus the term . This gives . By induction on , the denominator of divides the least common multiple of , since each new term adds a fraction with denominator .
Theorem C1.1.2.7.2 (a lower bound at the powers of 2, TAOCP eq. 1.2.7(2)). For each integer the bound below holds. Consequently is not bounded: for each real there is an with .
Node: TA4XT2XDNS · Lean: TAOCP.S1_2_7.eq2 · status: proved
Explanation. The theorem says that the harmonic series diverges, and it gives a number: after terms the sum is at least . The bound is weak. The true value of is about , which is and not . The bound has the right kind of growth, and this is why it is the first estimate of the section. The argument of the proof also gives an upper bound (exercise 1.2.7-2), so lies between and .
Example. The exact values and the bounds for :
| 0 | 1 | 1 | 1 | 1 |
| 1 | 2 | 1.5 | 1.5 | 2 |
| 2 | 4 | 2.0833 | 2 | 3 |
| 3 | 8 | 2.7179 | 2.5 | 4 |
| 4 | 16 | 3.3807 | 3 | 5 |
| 5 | 32 | 4.0585 | 3.5 | 6 |
| 6 | 64 | 4.7439 | 4 | 7 |
The bound is exact at and . The first with is , and the first with is . The first with is . So a sum that exceeds needs more than twelve thousand terms. The bound of the theorem guarantees only for this case, since .
Proof. The proof is by induction on . For the claim is . Let and suppose that . The difference of two harmonic numbers is a sum of terms:
This sum has terms. Each term has , so . Hence the sum is at least . So . This is the claim for .
For the second part, let be real. Choose an integer with . Then .
Theorem C1.1.2.7.3 (the asymptotic series of , TAOCP eq. 1.2.7(3)). Let be Euler's constant. For each integer ,
Node: TA3ZGC66Y9 · Lean: TAOCP.S1_2_7.eq3_tendsto, TAOCP.S1_2_7.eq3_lower, TAOCP.S1_2_7.eq3_upper (partial) · status: not stated yet
Explanation. This is the main tool for the size of . The first two terms, , are the main part. The next terms are corrections that get small fast. The series is asymptotic and does not converge as an infinite series: the terms have Bernoulli numbers in the numerator, and these grow faster than any geometric sequence. For a fixed , the error of the finite sum is less than the first term that is left out, and this is the reason for the bound on . The statement in the book is the case of three correction terms. The book proves the series in Section 1.2.11.2, where Euler's summation formula gives the general form (eq. 1.2.11.2(16)). The existence of is a theorem in its own right, and C1 proves it first. In Mathlib the constant is Real.eulerMascheroniConstant, and Real.tendsto_harmonic_sub_log is the statement that tends to it.
Example. Take . With and ,
The exact value is . The difference is , and the bound is . So holds, and the bound is sharp to . For , , and the bound is . For the series gives with , so the theorem is true even for .
Proof. First, the constant exists. Let . Then
The function is the integral of a decreasing function over an interval of length , so it is larger than , the value at the right end. Hence , and decreases. For the same reason, for each , so . Thus . A decreasing sequence that is bounded below has a limit, and the limit satisfies .
Second, the series. Euler's summation formula (eq. 1.2.11.2(10), proved in the C1 chapter on Section 1.2.11.2) applies to on . Its derivatives are , so the odd derivatives are . The formula for the sum over has the integral , then the term of , which is , then for each the term of , which is
and then a remainder , an integral of a Bernoulli function times . Take the terms up to and add to both sides to get :
With , and , the three terms of the sum are , and . The function has a convergent integral to , so with a finite number . Collect all the terms that do not depend on into one constant . Then
Since , . So the theorem holds with . The remainder lemma of Section 1.2.11.2 (eq. 1.2.11.2(13)) applies with . Its condition is that and have the same sign, and and are both positive on . It says that the remainder has the sign of the first term left out and is smaller than this term in absolute value. The first term left out is in the series for . So , which gives for each with , that is for . For the check is by arithmetic: , which lies between and .
The error at is a test of this proof. The series for is , which at is . The true error is .
Definition C1.1.2.7.4 (the harmonic numbers of order , TAOCP eq. 1.2.7(4)). For and ,
Node: TAAAPCGY2W · Lean: TAOCP.S1_2_7.eq4 (partial) · status: proved
Explanation. The number is . The new numbers change the exponent of the denominator. They come up in the analysis of sorting and hashing, and in the evaluation of sums like (exercise 1.2.7-14). The statement of the section is that these numbers are bounded when . The theorem below proves this and gives a bound. The project has TAOCP.harmonicPow r n for natural . The book also uses real , and a definition for these has not been made yet.
Example. With : , , , , and . With : . For the sum after ten terms is already within of its limit.
Theorem C1.1.2.7.5 (the harmonic numbers of order are bounded, TAOCP Section 1.2.7). For each real and each ,
Node: none · Lean: TAOCP.S1_2_7.harmonicPow_lt_two (partial)
Explanation. The theorem is the contrast to eq. 1.2.7(2): for there is no bound, and for each there is a bound that depends only on . Near the bound is good in ratio: is about , so the bound exceeds the limit by about . For large the bound tends to , as does, but its excess is much larger than , which is about . The argument of eq. 1.2.7(2), with blocks of terms, also gives a bound (exercise 1.2.7-3). The proof here uses an integral and gives another bound.
Example. For the bound is , and . For the bound is , and . For the bound is . The real limit is , so near the bound is close to the truth.
Proof. For the function is decreasing, so on the interval its value is at least . Hence . Add this for :
Add the term , which is , to get .
Definition C1.1.2.7.6 (the zeta function, TAOCP eq. 1.2.7(5)). For ,
Node: TASEC18JZ4 · Lean: TAOCP.S1_2_7.eq5, TAOCP.S1_2_7.eq5_zeta (partial) · status: proved
Explanation. The sequence is increasing and, by the theorem above, bounded, so it has a limit. The limit is Riemann's zeta function at . The speed of the approach is given by a comparison with an integral: the tail is about . For the limit is close to the sum of a few terms. In Mathlib, riemannZeta is the function for complex arguments, and riemannZeta_two, riemannZeta_four and riemannZeta_two_mul_nat are the values of eq. 1.2.7(6) and (7).
Example. The limit for is , and . The tail after terms for is . The tail bounds below give and . So the value is between them.
Proof of the tail bounds. For and , the decreasing function gives . Sum over :
For and these are and .
Theorem C1.1.2.7.7 (Euler's values of at even arguments, TAOCP eq. 1.2.7(6)). For each integer ,
Node: TARHF9ZQ4W · Lean: TAOCP.S1_2_7.eq6 · status: proved
Explanation. The theorem expresses as a rational number times . The rational number comes from the Bernoulli number . The Bernoulli numbers of the book are defined in Section 1.2.11.2 by and for , and the first values are , , , , . They have alternating signs at even index: has the sign , so the absolute value in the theorem is the same as . The values at odd arguments, , have no such formula. The theorem is due to Euler. In Mathlib it is riemannZeta_two_mul_nat, in a form with bernoulli (2 * k) and a power of .
Example. With : . With : . With : . With : . The computation for is .
Proof. The proof uses the Bernoulli polynomials and their Fourier series. This is not the proof of the book, which quotes the result.
Define the polynomials by , and for . These conditions fix each , since the first fixes it up to a constant and the second fixes the constant. So and . For , , so . Let . The derivative rule gives the Taylor expansion . Put and use for to get . This is the recursion of the book, with . So the numbers here are the Bernoulli numbers of the book.
Now let and let be the function on , extended to the real line with period . Since , is continuous, and it is smooth except at the integers. For an integer , let . Integrate by parts. For the boundary term is , and the rest is
where is defined by the same integral with . For the boundary term is , and the integral of is . So . By induction, for . The mean value is . The coefficients are with , so the Fourier series of the continuous, piecewise smooth function converges absolutely and uniformly to :
Let . Then for and for . The terms for and are complex conjugates, and their sum has . Hence
Put : . Since , the sign of is , so and .
Example C1.1.2.7.8 (the values at , TAOCP eq. 1.2.7(7)). The first four values of the theorem are
Node: TABN8N7259 · Lean: TAOCP.S1_2_7.eq7 (partial) · status: proved
Explanation. The first of these, , was the famous problem that Euler solved in 1735. The values give sharp bounds for the sums that use , which appear in the average cost of several searching methods. All four are the instances of the theorem above, and the check of the arithmetic is in its example. The numerical values are given below.
Example. To eight digits, , , and . These agree with the sums: is for . For the first two terms give , and the third adds .
Proof. Put in the theorem with , , and . The arithmetic is in the example of the theorem.
Theorem C1.1.2.7.9 (the sum of the first harmonic numbers, TAOCP eq. 1.2.7(8)). For each integer ,
Node: TA398RK35R · Lean: TAOCP.S1_2_7.eq8 · status: proved
Explanation. The sum of the first values of is almost times the last one. The correction has the same form as in the integral , since is close to . Exercise 1.2.7-8 asks to compare the sum with . The result is the case of eq. 1.2.7(9).
Example. With : , and . With : and .
Proof. Write as a sum and exchange the order of the sums, as in Section 1.2.3:
The set of pairs with is the same in both orders. The inner sum on the right has equal terms. Split the fraction: . Hence the sum is .
Theorem C1.1.2.7.10 (the sum with binomial weights, TAOCP eq. 1.2.7(9)). For integers and ,
Node: TAF82ZCVZC · Lean: TAOCP.S1_2_7.eq9 · status: proved
Explanation. The formula adds the harmonic numbers with the weights , which are polynomials of degree in . For it is eq. 1.2.7(8): . The right side is the product of the sum with , minus a correction. This is the pattern of the discrete integration by parts: the book compares it with the integral , which has the same shape. The derivation of the book uses summation by parts, a rule that is proved in exercise 1.2.7-10. C1 proves the formula by induction on , and then it shows the summation by parts.
Example. With and : . The right side is .
Proof by induction on . For the left side is the empty sum . The right side is . For this is , and for the binomial coefficient is . Now let and suppose that the formula holds for . Call the right side . It is enough to show that . Use and . Then
The absorption rule of Section 1.2.6 gives . So
where was written in the same form. The two differences of binomial coefficients are equal to . So the last two terms cancel, and .
Second proof, by parts. Summation by parts (exercise 1.2.7-10) is . Take and . By Pascal's rule, , and . The sum of over , which is the sum over , is then . By absorption, . The sum of over is (eq. 1.2.6(11)), so the sum over is . Also . The two terms with are , which is since when . What is left is .
Theorem C1.1.2.7.11 (the step of the proof of Theorem 1.2.7A, TAOCP eq. 1.2.7(10)). Let and . Then and for , and for
Node: TAYWT10542 · Lean: TAOCP.S1_2_7.eq10, TAOCP.S1_2_7.S_succ · status: proved
Explanation. This is an exact formula for . The sum with has been turned into minus a partial sum of a series. The series is the one of in Section 1.2.9, at . So the closed form is the exact form behind Theorem 1.2.7A, and the theorem is the statement that the partial sum is close to the logarithm.
Example. Let and . Then . The left side is . The right side is . The recursion gives , with , so .
Proof. The value , since . For the recursion, use :
The first sum is . In the second, replace by and put . It splits into and . In the last sum use the absorption rule . Then it becomes . Together, . Divide by :
Let . By the last equation, for each . Also , and the case agrees with . Add the differences for to get .
Theorem C1.1.2.7.12 (a sum of binomial terms with , TAOCP Theorem 1.2.7A). Let and . Then
Node: TA179D7MH2 · Lean: TAOCP.S1_2_7.theoremA · status: not stated yet
Explanation. For large and fixed , the sum is times , and the error is small compared with this: it is bounded by , which is a bound that does not grow with , while the main term grows like . So . The case gives . The condition is needed: the proof uses a convergent series with positive terms. For the logarithm is not defined, and exercise 1.2.7-9 asks for the exact value of the sum in that case.
Example. Take and . The exact sum is . The main term is . So , and the bound is . Another case: and gives , the main term , , and the bound is .
Proof. By eq. 1.2.7(10), . Let , so . The series converges to (Section 1.2.9, eq. 1.2.9(17)). Since , . So
Let . It is positive. For , , so . With this is . Hence , and satisfies .
Algorithms and programs
Section 1.2.7 has no algorithm and no program. The only computation in it is the exact evaluation of as a fraction, and each of its formulas can be run with exact rational arithmetic. To check eq. 1.2.7(9) by machine, add the terms with the exact fractions of a language with rational numbers, and compare with the closed form. The numbers of this chapter were found in that way.
The exercises
The table has the exercises of Section 1.2.7. 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.7-1 | 01 | K3 | not yet stated | X1, 1.2.7-1 | |
| 1.2.7-2 | 13 | K1 | not yet stated | X1, 1.2.7-2 | |
| 1.2.7-3 | 21 | M | K3 | not yet stated | X1, 1.2.7-3 |
| 1.2.7-4 | 10 | K2 | not yet stated | X1, 1.2.7-4 | |
| 1.2.7-5 | 15 | informal | not yet stated | X1, 1.2.7-5 | |
| 1.2.7-6 | 15 | M | K1 | not yet stated | X1, 1.2.7-6 |
| 1.2.7-7 | 21 | M | K3 | not yet stated | X1, 1.2.7-7 |
| 1.2.7-8 | 18 | HM | K4 | not yet stated | X1, 1.2.7-8 |
| 1.2.7-9 | 18 | M | K3 | not yet stated | X1, 1.2.7-9 |
| 1.2.7-10 | 20 | M | K1 | not yet stated | X1, 1.2.7-10 |
| 1.2.7-11 | 21 | M | K3 | not yet stated | X1, 1.2.7-11 |
| 1.2.7-12 | 10 | M | K3 | not yet stated | X1, 1.2.7-12 |
| 1.2.7-13 | 22 | M | K1 | not yet stated | X1, 1.2.7-13 |
| 1.2.7-14 | 22 | M | K3 | not yet stated | X1, 1.2.7-14 |
| 1.2.7-15 | 23 | M | K3 | not yet stated | X1, 1.2.7-15 |
| 1.2.7-16 | 18 | K3 | not yet stated | X1, 1.2.7-16 | |
| 1.2.7-17 | 24 | M | K1 | not yet stated | X1, 1.2.7-17 |
| 1.2.7-18 | 33 | M | K3 | not yet stated | X1, 1.2.7-18 |
| 1.2.7-19 | 30 | M | K3 | not yet stated | X1, 1.2.7-19 |
| 1.2.7-20 | 22 | HM | K1 | not yet stated | X1, 1.2.7-20 |
| 1.2.7-21 | 24 | M | K3 | not yet stated | X1, 1.2.7-21 |
| 1.2.7-22 | 28 | M | K3 | not yet stated | X1, 1.2.7-22 |
| 1.2.7-23 | 20 | HM | informal | not yet stated | X1, 1.2.7-23 |
| 1.2.7-24 | 21 | HM | K1 | not yet stated | X1, 1.2.7-24 |
| 1.2.7-25 | 21 | M | K1 | not yet stated | X1, 1.2.7-25 |
The order to do them: 1.2.7-1 and 4 first, to get a feel for the size of . Then 1.2.7-2 and 3, which repeat the argument of eq. 1.2.7(2) with other bounds, and 1.2.7-16, which writes a sum of odd reciprocals in . Exercises 1.2.7-10, 11, 14, 15 and 21 train summation by parts and the exchange of sums. Exercise 1.2.7-10 is the rule that eq. 1.2.7(9) needs, and 1.2.7-11 is its first use. Exercise 1.2.7-6 connects with the Stirling numbers of Section 1.2.6. Exercise 1.2.7-13 and 25 are identities that have short proofs by induction on . Exercise 1.2.7-8 and 9 go with eq. 1.2.7(8) and Theorem 1.2.7A. Exercises 1.2.7-17, 18 and 19 are about the numerators and denominators of harmonic numbers, and they use number theory, so do them after Section 1.2.4. Exercises 1.2.7-20, 23 and 24 use calculus and the gamma function: 20 is the analytic way to the sums of Theorem 1.2.7A, and 23 and 24 extend to noninteger and give the product for .
Lean
The Lean code of tamnd/taocp-lean at main (commit b48ef97) has the file TAOCP/V1/S1_2_7.lean. It states eqs. (1) to (10) and Theorem 1.2.7A as TAOCP.S1_2_7.eq1 to TAOCP.S1_2_7.eq10 and TAOCP.S1_2_7.theoremA. Some of them are weaker than the book, and their Node lines say "partial". Eq. (3) is stated as the limit with Euler's constant and two one-sided bounds, not as the asymptotic series. The harmonic numbers of order , the zeta function and the bound of the theorem for are stated for a natural only. Eq. (7) has the values of and only. The Node lines of this chapter that have no Lean name say "not yet stated". The chapter also uses the file TAOCP/Notation/Harmonic.lean with the definition for a natural as TAOCP.harmonicPow, and the lemmas TAOCP.harmonicPow_zero_right, TAOCP.harmonicPow_succ and TAOCP.harmonicPow_one. 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 harmonic number:
harmonic : ℕ → ℚ, withharmonic_zero,harmonic_succ,harmonic_eq_sum_Iccandharmonic_pos. Mathlib also has the boundslog_add_one_le_harmonicandharmonic_le_one_add_log, which are weaker than eq. 1.2.7(3). - Euler's constant:
Real.eulerMascheroniConstant, withReal.tendsto_harmonic_sub_log. The asymptotic series of eq. 1.2.7(3) is not in Mathlib. The statement will useAsymptoticsand a remainder with an explicit bound. - The zeta function and the Bernoulli numbers:
riemannZeta,bernoulli,riemannZeta_two,riemannZeta_fourandriemannZeta_two_mul_nat. Mathlib'sbernoullifollows the convention , as the book does, so a statement of eq. 1.2.7(6) in Lean needs no change of sign. The zeta function of Mathlib is a function on the complex numbers, and the book's for natural is the real number(riemannZeta r).re, or the sum∑' k, 1 / (k + 1) ^ r. - The binomial coefficient:
Nat.choose, withNat.choose_succ_succ'for the rule of Pascal andNat.add_one_mul_choose_eqfor absorption.
Eq. 1.2.7(8) and (9) are identities of rational numbers and can be proved in Lean by induction on , as in the proof above. For eq. 1.2.7(9) the statement is a sum over k ∈ Finset.Icc 1 n of (k.choose m : ℚ) * harmonic k. Theorem 1.2.7A has a real logarithm, so it is a statement in ℝ with the cast of harmonic n. Theorem 1.2.7A has an error term that the book defines by the equation, so in Lean it is a statement of the two inequalities on the difference.
Notes and history
The divergence of the harmonic series was known to Nicole Oresme in the 14th century, and it was proved again by Pietro Mengoli in 1650 and by Jakob Bernoulli in 1689. The proof by blocks of terms is the proof of Oresme. Leonhard Euler studied the partial sums in 1734 and 1735. He found the asymptotic series and the constant, and he soon computed the constant to 15 decimal places. In the same years he found and then the values at all even integers, which solved the problem of Mengoli of 1650 that Jakob and Johann Bernoulli had tried in vain. The series of Euler for is divergent. The theory of such series, with a bound by the first term that is left out, is in the chapters of Section 1.2.11.
The Bernoulli numbers come from the formula for the sum of the powers . They appear in the posthumous book of Jakob Bernoulli, Ars Conjectandi (1713). The proof in this chapter by the Fourier series of the Bernoulli polynomials is classical. C1 prefers it, since it needs only the formula for Fourier coefficients. The letter for the numbers is the choice of the book. Mathlib uses harmonic.
The numerator of is divisible by for an odd prime (exercise 1.2.7-17). This is the theorem of E. Waring of 1782, and J. Wolstenholme proved in 1862 that for the numerator is divisible by . The number is an integer only for and (exercise 1.2.7-19). L. Theisinger proved in 1915 that is not an integer for , and J. Kürschák proved in 1918 that no sum with is an integer. Mathlib has the first result as harmonic_not_int. The function extends to non-integers (exercise 1.2.7-23).
The sums of this section are a first example of the method of the next two sections: use a recursion or a generating function to find a closed form, and then find an approximation for it. Section 1.2.9 gives the series of that Theorem 1.2.7A uses.
The project has no errata of Section 1.2.7 to report.
Section 1.2.7 of TAOCP gives a name to the sum . The sum appears in the analysis of algorithms almost every time a quantity is averaged over equally likely cases. The section shows how large is, how its relatives behave, and how to add sums in which is a factor. 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.