Volume P2 · Concrete mathematics
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 first
Definition and growth
Statement
The harmonic numbers are the partial sums of . They grow without bound, but very slowly. This section defines them, computes the first values, proves that they are not integers, bounds them by logarithms and proves that converges.
Definition P2.9.1 (the harmonic numbers, TAOCP eq. 1.2.7(1)). For an integer , The empty sum gives . For every , .
Example P2.9.2. The first values are Each entry is the entry before it plus . For example, . In decimals, and .
Example P2.9.3. The partial sum of the harmonic series is a sum with a known size of term, , but the sum has no limit. a theorem below shows that , so passes every bound. It needs terms to pass , terms to pass and terms to pass .
Theorem P2.9.4 (the denominators). For the number is not an integer. More exactly, let . Then, in lowest terms, the denominator of is divisible by .
Lean: Mathlib harmonic_not_int, with harmonic : ℕ → ℚ as the definition (proved in Mathlib).
Proof. Let be the exponent with . Among the numbers only is divisible by , since the next multiple is larger than . So every other has a power of of at most in it. Let be the product of all odd numbers up to and put . For every with the quotient is an integer, since the odd part of divides and the power of in divides . For the quotient is , which is half of an odd number. So with an integer , and . The numerator is odd, so no factor cancels, and the denominator of in lowest terms is divisible by . A fraction with an even denominator is not an integer.
Theorem P2.9.5 (logarithmic bounds). For every integer ,
Lean: Mathlib log_add_one_le_harmonic and harmonic_le_one_add_log (proved in Mathlib).
Proof. The function falls on . For it follows that , since the integrand lies between and on an interval of length . Add the right inequality over to get . Add the left inequality over to get .
Theorem P2.9.6 (the powers of two). For every , The bound on the left is TAOCP eq. 1.2.7(2). It proves that .
Lean: not stated.
Proof. Group the terms with for . Block has terms. Each term is at most and at least . So block is at least and less than . Then lies between and . For both bounds equal .
Theorem P2.9.7 (Euler's constant). The numbers decrease with and stay positive. So the limit exists, and . For all , . The value is
Lean: Mathlib Real.eulerMascheroniConstant, with the sequence Real.eulerMascheroniSeq (proved in Mathlib).
Proof. The difference of two terms is The integrand is positive on , so . The integrand is also at most , so the integral is at most . The sequence is positive by the left bound of the last theorem, since . A decreasing sequence that is bounded below has a limit, so exists, and . For , the sum of the differences gives . Let to get . Since and the sequence decreases strictly, . Since , also .
Remark P2.9.8 (the full expansion). Euler's summation formula gives the asymptotic series which TAOCP states as eq. 1.2.7(3). The terms have the form with the Bernoulli numbers of Chapter 11. P5 proves the series, and Section 11.3 shows its first form. Here it serves to check numbers: for the terms above give , and to six places.
Proof
The bounds all come from one picture: the rectangle of width and height lies above or below the area under . The proof of the theorem on the denominators uses the highest power of in , which occurs only once. The proof of the existence of is the standard one for a decreasing sequence: show a positive sequence has a limit by monotonicity, and bound the tail by a telescoping sum.
Examples
Example P2.9.9. For the bounds say . The values are .
Example P2.9.10. The theorem on the powers of two with says . The exact value is .
Example P2.9.11. The numbers for and are and . Their distance to is and , so is below as the theorem says. In fact it is close to , as the series shows.
Example P2.9.12. The denominator of is , which is divisible by , and . The denominator of is , which is divisible by .
Exercises
- [10] Write and as fractions in lowest terms.
- [M20] Prove that for .
- [15] Use the logarithmic bounds to find integers such that for and for . Then find the least with by direct computation.
- [M25] Prove that is not an integer for , except for and , and check the denominator of .
- [M20] Prove that for , and use to show .
- [15] Prove that .
- [M20] Prove that for by blocks, and find the least for which the bound of the theorem on the powers of two tells that .
- [HM20] Prove that , and find its limit as .
- [M20] A stack of identical blocks of length rests on a table, each block above the other, the edge of the table to the right. Show that the stack can be built so that the top block sticks out beyond the edge of the table, and find the overhang for .
- [15] Compute and to four places, and check the inequalities against the value of .
Lean
Mathlib has the harmonic numbers as harmonic : ℕ → ℚ, defined by the sum , with harmonic_succ as the step . The bounds are log_add_one_le_harmonic and harmonic_le_one_add_log. The theorem harmonic_not_int states that is not an integer for . Euler's constant is Real.eulerMascheroniConstant, defined as the limit of Real.eulerMascheroniSeq, and the file has Real.one_half_lt_eulerMascheroniConstant. The asymptotic series is not in Mathlib in this form.
Notes and history
The divergence of the harmonic series was proved by Nicole Oresme around 1350 with the grouping of the powers of two, and again by Jakob Bernoulli, who published a proof in 1689. Euler introduced the constant in 1735 and computed it to 16 places in 1781. It is still not known whether is irrational. The theorem that is never an integer for is due to Theisinger (1915), and Kürschák proved the same in 1918.
TAOCP defines in eq. 1.2.7(1), proves the lower bound at the powers of as eq. 1.2.7(2) and states the asymptotic series as eq. 1.2.7(3). The proofs here follow the integral comparison of GKP94 Section 6.3 and are not the proofs of the book. The map of the equations is in the table at the end of Section 9.3.
Harmonic sums
Statement
A sum with in the summand has two standard attacks. The first is summation by parts (Section 3.2), with as the factor that gets a difference: is simple. The second is a recurrence in for the whole sum. This section applies the first to the sums of with a polynomial weight and the second to the sums with binomial weights. Section 3.2 proved the first two theorems below as examples of summation by parts. They are restated here with short proofs, because the rest of the chapter and TAOCP use them in this form.
Theorem P2.9.13 (the sum of the harmonic numbers, TAOCP eq. 1.2.7(8)). For every integer ,
Lean: not stated.
Proof. Write the sum as and use summation by parts, . Take and , so and . With the formula gives Since , the right side is .
Example P2.9.14. For the sum is , and the formula gives . For the formula gives .
Theorem P2.9.15 (binomial weights, TAOCP eq. 1.2.7(9)). For all integers and ,
Lean: not stated.
Proof. Take and . Pascal's rule gives . Also and . Summation by parts with gives Here . The absorption identity turns the last sum into , by summation on the upper index (Section 6.3).
Example P2.9.16. For the theorem reads , which is the first theorem with replaced by . For and it reads , and the left side is .
Example P2.9.17. The weight gives . For this, take and in place of : , and put . For it gives , and the direct sum is .
Theorem P2.9.18 (the alternating sum for ). For every integer ,
Lean: not stated.
Proof. Call the right side . For , Pascal's rule splits , so , where is the part with (the term vanishes). Absorption gives . So the second sum is , by the binomial theorem. Then with , and by induction.
Example P2.9.19. For the sum is . For it is .
Theorem P2.9.20 (the binomial transform of , TAOCP eq. 1.2.7(10)). Let be a number with . For every integer , For and , the value of the sum is .
Lean: not stated.
Proof. Let be the sum. For use Pascal's rule on : The part with is . The part with is, by absorption, . So For this gives for . For put . Then and . Adding up gives .
Example P2.9.21. For and the sum is . The formula gives . Here and , so .
Example P2.9.22. For and : .
Proof
Both methods are the standard ones for sums that contain a number with no closed form. Summation by parts moves the difference from to the other factor, where cancels against and leaves a plain sum. The recurrence in uses Pascal's rule to split the sum and the identity to split the summand. The same two ideas solve most sums with in them.
Examples
Example P2.9.23. To find , write . Then . For this is , and the direct sum is .
Example P2.9.24. The values of for are , , , , and . Each is .
Exercises
- [10] Evaluate with the first theorem and check it by adding.
- [M15] Prove that .
- [M20] Find a closed form of and check it for .
- [10] Evaluate with the theorem for .
- [M22] Prove that .
- [M15] Evaluate in terms of and a sum, and check it for .
- [10] Prove that .
- [M20] Prove that by summation by parts.
- [M20] Use binomial inversion (Section 7.2) on the alternating sum for to prove that for .
Lean
Mathlib has harmonic and harmonic_succ, but no lemma for the sums of this section. A Lean proof of is a short induction on with harmonic_succ, and Finset.sum_range_succ. The binomial weights need Nat.choose with Nat.succ_mul_choose_eq for the absorption.
Notes and history
The sum of the first harmonic numbers and its generalization to binomial weights are in GKP94 Section 6.3, where summation by parts is the method. TAOCP gives them in Section 1.2.7 as eqs. 1.2.7(8) and 1.2.7(9), and it proves eq. 1.2.7(10) by the same recurrence in as here, as a step to Theorem 1.2.7A. The alternating sum for is an old identity. Under binomial inversion it pairs with the identity , as Exercise 9 shows.
Harmonic numbers of higher order
Statement
If the terms are replaced by , the partial sums behave in a different way. For they stay bounded and have a limit, which is a value of the Riemann zeta function. This section defines these sums, proves that they converge with an error bound, states the values of the limit for even and proves two sums over values of and one sum that mixes and .
Definition P2.9.25 (the harmonic numbers of order , TAOCP eq. 1.2.7(4)). For a real number and an integer , So .
Example P2.9.26. For the first values are In decimals and . For the values are , , and for .
Example P2.9.27. For the sum grows like , so it is unbounded. For the exponent it grows like . Only an exponent above gives a bounded sequence.
Theorem P2.9.28 (convergence for , TAOCP Section 1.2.7). Let . The sequence increases and, for every , So it has a limit , with . The error is bounded by
Lean: not stated. Mathlib has hasSum_zeta_two and hasSum_zeta_four for the values of the limit.
Proof. The sequence increases since every term is positive. The function falls, so for we have . Add over : . This is the first bound, and it is below , which gives . An increasing sequence that is bounded above has a limit. Since for , the limit exceeds . For the error, gives , and gives .
Example P2.9.29. For and the error bounds say . The values are . For and the error is at most . With it follows that . The true value is
Definition P2.9.30 (the zeta function, TAOCP eq. 1.2.7(5)). For real , . In TAOCP the number is written .
Example P2.9.31. , and . The values approach as grows, since , which tends to .
Theorem P2.9.32 (the values at even arguments, TAOCP eqs. 1.2.7(6) and 1.2.7(7)). For every integer , with the Bernoulli numbers of Chapter 11. The first four values are
Lean: Mathlib hasSum_zeta_two and hasSum_zeta_four for , and riemannZeta_two_mul_nat for the general formula, in the form of the complex zeta function (proved in Mathlib).
The proof of this theorem is in Section 11.3, after the Bernoulli numbers are defined. It is not needed for the rest of this chapter.
Example P2.9.33. The partial sum and the tail bound show that lies between and , where the lower end is . The value lies in this range. For the partial sum with is , and , which is between and .
Theorem P2.9.34 (a telescoping sum of zeta values). The sum of the numbers for is
Lean: not stated.
Proof. Write . The double sum has non-negative terms, so the order of summation may change. For fixed the sum over is a geometric series, . Then , since the partial sums telescope to .
Example P2.9.35. The first terms are , , , and . They add to , and the remaining terms for add to , so the total is .
Theorem P2.9.36 (a sum of ). For every integer ,
Lean: not stated.
Proof. Expand the square: . The terms with give . The other terms come in pairs and , so . For a fixed the sum over is , so . Then , and solving for the sum gives the claim.
Example P2.9.37. For : . The right side is .
Proof
The proof of convergence compares the sum with an integral, as the logarithmic bounds of Section 9.1 do. The sum over of the numbers is a double sum of non-negative terms, and the order of its summation is free. The last proof counts the terms of the product twice, in the form of a triangle above the diagonal.
Examples
Example P2.9.38. The sum is also bounded by a telescoping sum. Since for , we get . This is the bound for .
Example P2.9.39. The sum over the odd numbers is . The partial sum over the odd numbers up to is .
Exercises
- [10] Write as a fraction.
- [M15] Use the theorem on convergence with to show that .
- [M20] Prove that .
- [M20] Prove that .
- [M25] Prove that for .
- [M20] Prove that , and find the value of .
- [M15] Prove that for .
- [M15] Find from the value of , and find .
- [M20] Prove that .
Lean
Mathlib has hasSum_zeta_two : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 2) (π ^ 2 / 6) and hasSum_zeta_four with the value . The general formula is riemannZeta_two_mul_nat, for the complex zeta function and the Bernoulli numbers bernoulli. The partial sums and the convergence for have no name of their own in Mathlib; the proof by comparison with an integral is AntitoneOn.sum_le_integral and its relatives. The two sums of this section are not stated.
Notes and history
Euler found the value in 1735, and the general formula for a few years later. The problem to find this sum had stood open since Pietro Mengoli posed it in 1650 and the Bernoulli family had tried it. No closed form is known for ; Roger Apéry proved in 1978 that it is irrational. The sum of the numbers is an old exercise in the change of the order of a double sum.
TAOCP defines in eq. 1.2.7(4), the zeta function in eq. 1.2.7(5) and the formula for even arguments in eqs. 1.2.7(6) and 1.2.7(7). The table shows the equations of Section 1.2.7 and the items of this chapter.
| TAOCP 1.2.7 | Result of P2 |
|---|---|
| eq. (1) | Definition (the harmonic numbers) |
| eq. (2) | Theorem (the powers of two) |
| eq. (3) | Remark (the full expansion) |
| eq. (4) | Definition (the harmonic numbers of order ) |
| eq. (5) | Definition (the zeta function) |
| eqs. (6), (7) | Theorem (the values at even arguments) |
| eq. (8) | Theorem (the sum of the harmonic numbers) |
| eq. (9) | Theorem (binomial weights) |
| eq. (10) | Theorem (the binomial transform of ) |
The harmonic number is the partial sum of the harmonic series. It has no closed form, yet it appears in many analyses of algorithms: the mean number of left-to-right maxima of a random permutation is , the mean cost of quicksort has in it, and the Stirling number equals . A reader of TAOCP meets first in Section 1.2.7 and then in almost every analysis of Volumes 1 to 3.
Section 9.1 defines , tabulates it, shows that is never an integer for , and traces its growth. It bounds between two logarithms by comparing the sum with an integral, and it proves that the difference has a limit, Euler's constant . Section 9.2 sums harmonic numbers. Summation by parts from Chapter 3 gives and the sums with binomial weights , and a recurrence in gives the sums . Section 9.3 defines the harmonic numbers of order , proves that they converge for , states the values of the limit for even and proves a few sums of values of .
TAOCP treats the same material in Section 1.2.7, in the equations 1.2.7(1) to 1.2.7(10). The table at the end of Section 9.3 maps these equations to the items of this chapter. The full asymptotic series of comes from Euler's summation formula of Section 1.2.11.2, and P5 proves it. This chapter states the series and uses it only to check numbers.
The chapter needs the sums of Chapter 1, the difference operator and summation by parts of Chapter 3, and the binomial coefficients and inversion of Chapters 6 and 7. The natural logarithm is . The proof of and its relatives is in Section 11.3. The companion section is C1 Section 1.2.7, and the exercises of TAOCP 1.2.7 have solutions in X1.
The source of this page. Something is wrong? Report it.