taocp

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

Volume P2 · Concrete mathematics

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
Contents
  1. Definition and growth
  2. Harmonic sums
  3. Harmonic numbers of higher order

Definition and growth

Statement

The harmonic numbers are the partial sums of 1/k1/k. 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 Hn−ln⁡nH_n - \ln n converges.

Definition P2.9.1 (the harmonic numbers, TAOCP eq. 1.2.7(1)). For an integer n≥0n \ge 0, Hn=∑k=1n1k=1+12+⋯+1n.H_n = \sum_{k=1}^{n} \frac1k = 1 + \frac12 + \cdots + \frac1n. The empty sum gives H0=0H_0 = 0. For every n≥0n \ge 0, Hn+1=Hn+1n+1H_{n+1} = H_n + \frac{1}{n+1}.

Example P2.9.2. The first values are n012345678Hn01321162512137604920363140761280\begin{array}{c|ccccccccc} n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ \hline H_n & 0 & 1 & \frac32 & \frac{11}{6} & \frac{25}{12} & \frac{137}{60} & \frac{49}{20} & \frac{363}{140} & \frac{761}{280} \end{array} Each entry is the entry before it plus 1n\frac1n. For example, H5=2512+15=12560+1260=13760H_5 = \frac{25}{12} + \frac15 = \frac{125}{60} + \frac{12}{60} = \frac{137}{60}. In decimals, H8≈2.7179H_8 \approx 2.7179 and H10≈2.9290H_{10} \approx 2.9290.

Example P2.9.3. The partial sum of the harmonic series is a sum with a known size of term, 1k→0\frac1k \to 0, but the sum has no limit. a theorem below shows that H2m>1+m2H_{2^m} > 1 + \frac m2, so HnH_n passes every bound. It needs n=4n = 4 terms to pass 22, n=11n = 11 terms to pass 33 and n=31n = 31 terms to pass 44.

Theorem P2.9.4 (the denominators). For n≥2n \ge 2 the number HnH_n is not an integer. More exactly, let 2a≤n<2a+12^a \le n < 2^{a+1}. Then, in lowest terms, the denominator of HnH_n is divisible by 2a2^a.

Lean: Mathlib harmonic_not_int, with harmonic : ℕ → ℚ as the definition (proved in Mathlib).

Proof. Let a≥1a \ge 1 be the exponent with 2a≤n<2a+12^a \le n < 2^{a+1}. Among the numbers 1,…,n1, \dots, n only 2a2^a is divisible by 2a2^a, since the next multiple 2a+12^{a+1} is larger than nn. So every other k≤nk \le n has a power of 22 of at most 2a−12^{a-1} in it. Let mm be the product of all odd numbers up to nn and put M=2a−1mM = 2^{a-1}m. For every k≤nk \le n with k≠2ak \ne 2^a the quotient M/kM/k is an integer, since the odd part of kk divides mm and the power of 22 in kk divides 2a−12^{a-1}. For k=2ak = 2^a the quotient is M/2a=m/2M/2^a = m/2, which is half of an odd number. So MHn=I+m2M H_n = I + \frac m2 with an integer II, and Hn=2I+m2amH_n = \frac{2I + m}{2^a m}. The numerator 2I+m2I + m is odd, so no factor 22 cancels, and the denominator of HnH_n in lowest terms is divisible by 2a2^a. A fraction with an even denominator is not an integer. □\square

Theorem P2.9.5 (logarithmic bounds). For every integer n≥1n \ge 1, ln⁡(n+1)≤Hn≤1+ln⁡n.\ln(n+1) \le H_n \le 1 + \ln n.

Lean: Mathlib log_add_one_le_harmonic and harmonic_le_one_add_log (proved in Mathlib).

Proof. The function 1/x1/x falls on x>0x > 0. For k≥1k \ge 1 it follows that 1k+1≤∫kk+1dxx≤1k\frac{1}{k+1} \le \int_k^{k+1} \frac{dx}{x} \le \frac1k, since the integrand lies between 1k+1\frac1{k+1} and 1k\frac1k on an interval of length 11. Add the right inequality over k=1,…,nk = 1, \dots, n to get ln⁡(n+1)=∫1n+1dxx≤Hn\ln(n+1) = \int_1^{n+1} \frac{dx}{x} \le H_n. Add the left inequality over k=1,…,n−1k = 1, \dots, n-1 to get Hn−1=∑k=2n1k≤∫1ndxx=ln⁡nH_n - 1 = \sum_{k=2}^{n}\frac1k \le \int_1^n \frac{dx}{x} = \ln n. □\square

Theorem P2.9.6 (the powers of two). For every m≥0m \ge 0, 1+m2≤H2m≤1+m.1 + \frac m2 \le H_{2^m} \le 1 + m. The bound on the left is TAOCP eq. 1.2.7(2). It proves that Hn→∞H_n \to \infty.

Lean: not stated.

Proof. Group the terms with 2j−1<k≤2j2^{j-1} < k \le 2^j for j=1,…,mj = 1, \dots, m. Block jj has 2j−12^{j-1} terms. Each term is at most 12j−1+1<12j−1\frac{1}{2^{j-1}+1} < \frac{1}{2^{j-1}} and at least 12j\frac1{2^j}. So block jj is at least 2j−1⋅2−j=122^{j-1} \cdot 2^{-j} = \frac12 and less than 11. Then H2m=1+∑j=1m(block j)H_{2^m} = 1 + \sum_{j=1}^m (\text{block } j) lies between 1+m21 + \frac m2 and 1+m1 + m. For m=0m = 0 both bounds equal H1=1H_1 = 1. □\square

Theorem P2.9.7 (Euler's constant). The numbers γn=Hn−ln⁡n\gamma_n = H_n - \ln n decrease with nn and stay positive. So the limit γ=lim⁡n→∞(Hn−ln⁡n)\gamma = \lim_{n \to \infty} (H_n - \ln n) exists, and 0<γ<10 < \gamma < 1. For all n≥1n \ge 1, 0<γn−γ≤1n0 < \gamma_n - \gamma \le \frac1n. The value is γ=0.5772156649…\gamma = 0.5772156649\ldots

Lean: Mathlib Real.eulerMascheroniConstant, with the sequence Real.eulerMascheroniSeq (proved in Mathlib).

Proof. The difference of two terms is γn−γn+1=ln⁡n+1n−1n+1=∫nn+1(1x−1n+1)dx.\gamma_n - \gamma_{n+1} = \ln\frac{n+1}{n} - \frac{1}{n+1} = \int_n^{n+1} \Bigl(\frac1x - \frac{1}{n+1}\Bigr)dx. The integrand is positive on [n,n+1)[n, n+1), so γn>γn+1\gamma_n > \gamma_{n+1}. The integrand is also at most 1n−1n+1\frac1n - \frac1{n+1}, so the integral is at most 1n−1n+1\frac1n - \frac1{n+1}. The sequence γn\gamma_n is positive by the left bound of the last theorem, since Hn≥ln⁡(n+1)>ln⁡nH_n \ge \ln(n+1) > \ln n. A decreasing sequence that is bounded below has a limit, so γ\gamma exists, and γ≥0\gamma \ge 0. For m>nm > n, the sum of the differences gives γn−γm≤∑k=nm−1(1k−1k+1)=1n−1m\gamma_n - \gamma_m \le \sum_{k=n}^{m-1}\bigl(\frac1k - \frac1{k+1}\bigr) = \frac1n - \frac1m. Let m→∞m \to \infty to get γn−γ≤1n\gamma_n - \gamma \le \frac1n. Since γ1=1\gamma_1 = 1 and the sequence decreases strictly, γ<1\gamma < 1. Since γ≥γ20−120>0.55\gamma \ge \gamma_{20} - \frac1{20} > 0.55, also γ>0\gamma > 0. □\square

Remark P2.9.8 (the full expansion). Euler's summation formula gives the asymptotic series Hn=ln⁡n+γ+12n−112n2+1120n4−1252n6+⋯ ,H_n = \ln n + \gamma + \frac{1}{2n} - \frac{1}{12n^2} + \frac{1}{120n^4} - \frac{1}{252n^6} + \cdots, which TAOCP states as eq. 1.2.7(3). The terms have the form B2k/(2kn2k)B_{2k}/(2kn^{2k}) with the Bernoulli numbers B2kB_{2k} of Chapter 11. P5 proves the series, and Section 11.3 shows its first form. Here it serves to check numbers: for n=10n = 10 the terms above give 2.302585+0.577216+0.05−0.000833+0.0000083−0.000000004=2.9289682.302585 + 0.577216 + 0.05 - 0.000833 + 0.0000083 - 0.000000004 = 2.928968, and H10=2.928968H_{10} = 2.928968 to six places.

Proof

The bounds all come from one picture: the rectangle of width 11 and height 1/k1/k lies above or below the area under 1/x1/x. The proof of the theorem on the denominators uses the highest power of 22 in 1,…,n1, \dots, n, which occurs only once. The proof of the existence of γ\gamma 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 n=10n = 10 the bounds say ln⁡11≤H10≤1+ln⁡10\ln 11 \le H_{10} \le 1 + \ln 10. The values are 2.398≤2.929≤3.3032.398 \le 2.929 \le 3.303.

Example P2.9.10. The theorem on the powers of two with m=3m = 3 says 2.5≤H8≤42.5 \le H_8 \le 4. The exact value is H8=761280≈2.718H_8 = \frac{761}{280} \approx 2.718.

Example P2.9.11. The numbers γn\gamma_n for n=10n = 10 and n=20n = 20 are 0.626380.62638 and 0.602010.60201. Their distance to γ\gamma is 0.04920.0492 and 0.02480.0248, so γn−γ\gamma_n - \gamma is below 1n\frac1n as the theorem says. In fact it is close to 12n\frac{1}{2n}, as the series shows.

Example P2.9.12. The denominator of H6=4920H_6 = \frac{49}{20} is 2020, which is divisible by 222^2, and 22≤6<232^2 \le 6 < 2^3. The denominator of H8=761280H_8 = \frac{761}{280} is 280=8⋅35280 = 8 \cdot 35, which is divisible by 232^3.

Exercises

  1. [10] Write H9H_9 and H10H_{10} as fractions in lowest terms.
  2. [M20] Prove that ln⁡2n+1n+1≤H2n−Hn≤ln⁡2\ln\frac{2n+1}{n+1} \le H_{2n} - H_n \le \ln 2 for n≥1n \ge 1.
  3. [15] Use the logarithmic bounds to find integers a<ba < b such that Hn≤4H_n \le 4 for n≤an \le a and Hn>4H_n > 4 for n≥bn \ge b. Then find the least nn with Hn>4H_n > 4 by direct computation.
  4. [M25] Prove that Hn−HmH_n - H_m is not an integer for 0≤m<n0 \le m < n, except for m=0m = 0 and n=1n = 1, and check the denominator of H12−H8H_{12} - H_8.
  5. [M20] Prove that 0<γn−γ≤1n0 < \gamma_n - \gamma \le \frac1n for γn=Hn−ln⁡n\gamma_n = H_n - \ln n, and use n=20n = 20 to show 0.55<γ<0.610.55 < \gamma < 0.61.
  6. [15] Prove that ∑k=1n12k−1=H2n−12Hn\sum_{k=1}^{n}\frac{1}{2k-1} = H_{2n} - \frac12 H_n.
  7. [M20] Prove that H2m<1+mH_{2^m} < 1 + m for m≥1m \ge 1 by blocks, and find the least mm for which the bound of the theorem on the powers of two tells that H2m>10H_{2^m} > 10.
  8. [HM20] Prove that ∑k=12n(−1)k+1k=H2n−Hn\sum_{k=1}^{2n}\frac{(-1)^{k+1}}{k} = H_{2n} - H_n, and find its limit as n→∞n \to \infty.
  9. [M20] A stack of nn identical blocks of length 11 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 12Hn\frac12 H_n beyond the edge of the table, and find the overhang for n=4n = 4.
  10. [15] Compute γ10=H10−ln⁡10\gamma_{10} = H_{10} - \ln 10 and γ20\gamma_{20} to four places, and check the inequalities γ20−120<γ<γ20\gamma_{20} - \frac1{20} < \gamma < \gamma_{20} against the value of γ\gamma.

Lean

Mathlib has the harmonic numbers as harmonic : ℕ → ℚ, defined by the sum ∑i<n(i+1)−1\sum_{i<n} (i+1)^{-1}, with harmonic_succ as the step Hn+1=Hn+1n+1H_{n+1} = H_n + \frac{1}{n+1}. The bounds are log_add_one_le_harmonic and harmonic_le_one_add_log. The theorem harmonic_not_int states that HnH_n is not an integer for n≥2n \ge 2. 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 γ\gamma in 1735 and computed it to 16 places in 1781. It is still not known whether γ\gamma is irrational. The theorem that HnH_n is never an integer for n≥2n \ge 2 is due to Theisinger (1915), and Kürschák proved the same in 1918.

TAOCP defines HnH_n in eq. 1.2.7(1), proves the lower bound at the powers of 22 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 HkH_k in the summand has two standard attacks. The first is summation by parts (Section 3.2), with HkH_k as the factor that gets a difference: ΔHk=1k+1\Delta H_k = \frac{1}{k+1} is simple. The second is a recurrence in nn for the whole sum. This section applies the first to the sums of HkH_k 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 n≥0n \ge 0, ∑k=1nHk=(n+1)Hn−n.\sum_{k=1}^{n} H_k = (n+1)H_n - n.

Lean: not stated.

Proof. Write the sum as ∑0≤k<n+1Hk\sum_{0 \le k < n+1} H_k and use summation by parts, ∑0≤k<Nu(k)Δv(k)=u(N)v(N)−u(0)v(0)−∑0≤k<Nv(k+1)Δu(k)\sum_{0 \le k < N} u(k)\Delta v(k) = u(N)v(N) - u(0)v(0) - \sum_{0 \le k < N} v(k+1)\Delta u(k). Take u(k)=Hku(k) = H_k and v(k)=kv(k) = k, so Δv=1\Delta v = 1 and Δu(k)=Hk+1−Hk=1k+1\Delta u(k) = H_{k+1} - H_k = \frac{1}{k+1}. With N=n+1N = n+1 the formula gives ∑0≤k<n+1Hk=(n+1)Hn+1−∑0≤k<n+1(k+1)⋅1k+1=(n+1)Hn+1−(n+1).\sum_{0 \le k < n+1} H_k = (n+1)H_{n+1} - \sum_{0 \le k < n+1} (k+1)\cdot\frac{1}{k+1} = (n+1)H_{n+1} - (n+1). Since Hn+1=Hn+1n+1H_{n+1} = H_n + \frac{1}{n+1}, the right side is (n+1)Hn+1−(n+1)=(n+1)Hn−n(n+1)H_n + 1 - (n+1) = (n+1)H_n - n. □\square

Example P2.9.14. For n=4n = 4 the sum is 1+32+116+2512=12+18+22+2512=77121 + \frac32 + \frac{11}{6} + \frac{25}{12} = \frac{12 + 18 + 22 + 25}{12} = \frac{77}{12}, and the formula gives 5⋅2512−4=125−4812=77125 \cdot \frac{25}{12} - 4 = \frac{125 - 48}{12} = \frac{77}{12}. For n=6n = 6 the formula gives 7⋅4920−6=223207 \cdot \frac{49}{20} - 6 = \frac{223}{20}.

Theorem P2.9.15 (binomial weights, TAOCP eq. 1.2.7(9)). For all integers m≥0m \ge 0 and n≥0n \ge 0, ∑0≤k<n(km)Hk=(nm+1)(Hn−1m+1).\sum_{0 \le k < n} \binom{k}{m} H_k = \binom{n}{m+1}\Bigl(H_n - \frac{1}{m+1}\Bigr).

Lean: not stated.

Proof. Take u(k)=Hku(k) = H_k and v(k)=(km+1)v(k) = \binom{k}{m+1}. Pascal's rule gives Δv(k)=(k+1m+1)−(km+1)=(km)\Delta v(k) = \binom{k+1}{m+1} - \binom{k}{m+1} = \binom{k}{m}. Also Δu(k)=1k+1\Delta u(k) = \frac{1}{k+1} and v(k+1)=(k+1m+1)v(k+1) = \binom{k+1}{m+1}. Summation by parts with N=nN = n gives ∑0≤k<n(km)Hk=Hn(nm+1)−H0(0m+1)−∑0≤k<n(k+1m+1)1k+1.\sum_{0 \le k < n}\binom{k}{m}H_k = H_n\binom{n}{m+1} - H_0\binom{0}{m+1} - \sum_{0 \le k < n}\binom{k+1}{m+1}\frac{1}{k+1}. Here H0=0H_0 = 0. The absorption identity 1k+1(k+1m+1)=1m+1(km)\frac{1}{k+1}\binom{k+1}{m+1} = \frac{1}{m+1}\binom{k}{m} turns the last sum into 1m+1∑0≤k<n(km)=1m+1(nm+1)\frac{1}{m+1}\sum_{0 \le k < n}\binom{k}{m} = \frac{1}{m+1}\binom{n}{m+1}, by summation on the upper index (Section 6.3). □\square

Example P2.9.16. For m=0m = 0 the theorem reads ∑0≤k<nHk=n(Hn−1)\sum_{0 \le k < n} H_k = n(H_n - 1), which is the first theorem with nn replaced by n−1n - 1. For m=1m = 1 and n=4n = 4 it reads H1+2H2+3H3=(42)(2512−12)=6⋅1912=192H_1 + 2H_2 + 3H_3 = \binom42\bigl(\frac{25}{12} - \frac12\bigr) = 6 \cdot \frac{19}{12} = \frac{19}{2}, and the left side is 1+3+112=1921 + 3 + \frac{11}{2} = \frac{19}{2}.

Example P2.9.17. The weight kk gives ∑k=1nkHk=n(n+1)2Hn−n(n−1)4\sum_{k=1}^n kH_k = \frac{n(n+1)}{2}H_n - \frac{n(n-1)}{4}. For this, take m=1m = 1 and n+1n + 1 in place of nn: ∑0≤k≤nkHk=(n+12)(Hn+1−12)\sum_{0 \le k \le n} kH_k = \binom{n+1}{2}\bigl(H_{n+1} - \frac12\bigr), and put Hn+1=Hn+1n+1H_{n+1} = H_n + \frac{1}{n+1}. For n=4n = 4 it gives 10⋅2512−3=107610 \cdot \frac{25}{12} - 3 = \frac{107}{6}, and the direct sum is 1+3+112+253=10761 + 3 + \frac{11}{2} + \frac{25}{3} = \frac{107}{6}.

Theorem P2.9.18 (the alternating sum for HnH_n). For every integer n≥1n \ge 1, Hn=∑k=1n(−1)k+11k(nk).H_n = \sum_{k=1}^{n}(-1)^{k+1}\frac{1}{k}\binom{n}{k}.

Lean: not stated.

Proof. Call the right side TnT_n. For n≥2n \ge 2, Pascal's rule splits (nk)=(n−1k)+(n−1k−1)\binom nk = \binom{n-1}{k} + \binom{n-1}{k-1}, so Tn=Tn−1+∑k=1n(−1)k+11k(n−1k−1)T_n = T_{n-1} + \sum_{k=1}^n(-1)^{k+1}\frac1k\binom{n-1}{k-1}, where Tn−1T_{n-1} is the part with (n−1k)\binom{n-1}{k} (the term k=nk = n vanishes). Absorption gives 1k(n−1k−1)=1n(nk)\frac1k\binom{n-1}{k-1} = \frac1n\binom nk. So the second sum is 1n∑k=1n(−1)k+1(nk)=1n(1−(1−1)n)=1n\frac1n\sum_{k=1}^n(-1)^{k+1}\binom nk = \frac1n\bigl(1 - (1-1)^n\bigr) = \frac1n, by the binomial theorem. Then Tn=Tn−1+1nT_n = T_{n-1} + \frac1n with T1=1T_1 = 1, and Tn=HnT_n = H_n by induction. □\square

Example P2.9.19. For n=3n = 3 the sum is 3−32+13=116=H33 - \frac32 + \frac13 = \frac{11}{6} = H_3. For n=4n = 4 it is 4−3+43−14=2512=H44 - 3 + \frac43 - \frac14 = \frac{25}{12} = H_4.

Theorem P2.9.20 (the binomial transform of HkH_k, TAOCP eq. 1.2.7(10)). Let xx be a number with x≠−1x \ne -1. For every integer n≥0n \ge 0, ∑k(nk)xkHk=(1+x)n(Hn−∑k=1n1k(1+x)k).\sum_{k}\binom nk x^k H_k = (1+x)^n\Bigl(H_n - \sum_{k=1}^{n}\frac{1}{k(1+x)^k}\Bigr). For x=−1x = -1 and n≥1n \ge 1, the value of the sum is −1n-\frac1n.

Lean: not stated.

Proof. Let SnS_n be the sum. For n≥1n \ge 1 use Pascal's rule on (nk)\binom nk: Sn=∑k(n−1k)xkHk+∑k(n−1k−1)xkHk=Sn−1+∑k(n−1k−1)xk(Hk−1+1k).S_n = \sum_k\binom{n-1}{k}x^kH_k + \sum_k\binom{n-1}{k-1}x^kH_k = S_{n-1} + \sum_k\binom{n-1}{k-1}x^k\Bigl(H_{k-1} + \frac1k\Bigr). The part with Hk−1H_{k-1} is x∑k(n−1k−1)xk−1Hk−1=xSn−1x\sum_k\binom{n-1}{k-1}x^{k-1}H_{k-1} = xS_{n-1}. The part with 1k\frac1k is, by absorption, 1n∑k≥1(nk)xk=(1+x)n−1n\frac1n\sum_{k\ge1}\binom nk x^k = \frac{(1+x)^n - 1}{n}. So Sn=(1+x)Sn−1+(1+x)n−1n.S_n = (1+x)S_{n-1} + \frac{(1+x)^n - 1}{n}. For x=−1x = -1 this gives Sn=−1nS_n = -\frac1n for n≥1n \ge 1. For x≠−1x \ne -1 put Sn=(1+x)nTnS_n = (1+x)^nT_n. Then Tn=Tn−1+1n(1−(1+x)−n)T_n = T_{n-1} + \frac{1}{n}\bigl(1 - (1+x)^{-n}\bigr) and T0=S0=0T_0 = S_0 = 0. Adding up gives Tn=Hn−∑k=1n(1+x)−kkT_n = H_n - \sum_{k=1}^n\frac{(1+x)^{-k}}{k}. □\square

Example P2.9.21. For x=1x = 1 and n=4n = 4 the sum is ∑k(4k)Hk=4+9+223+2512=26912\sum_k\binom4kH_k = 4 + 9 + \frac{22}{3} + \frac{25}{12} = \frac{269}{12}. The formula gives 16(2512−12−18−124−164)16\bigl(\frac{25}{12} - \frac12 - \frac18 - \frac1{24} - \frac1{64}\bigr). Here 12+18+124+164=96+24+8+3192=131192\frac12 + \frac18 + \frac1{24} + \frac1{64} = \frac{96 + 24 + 8 + 3}{192} = \frac{131}{192} and 2512−131192=400−131192=269192\frac{25}{12} - \frac{131}{192} = \frac{400 - 131}{192} = \frac{269}{192}, so 16⋅269192=2691216 \cdot \frac{269}{192} = \frac{269}{12}.

Example P2.9.22. For x=−1x = -1 and n=3n = 3: −3⋅1+3⋅32−116=−3+92−116=−13-3 \cdot 1 + 3 \cdot \frac32 - \frac{11}{6} = -3 + \frac92 - \frac{11}{6} = -\frac13.

Proof

Both methods are the standard ones for sums that contain a number with no closed form. Summation by parts moves the difference from HkH_k to the other factor, where 1k+1\frac{1}{k+1} cancels against k+1k+1 and leaves a plain sum. The recurrence in nn uses Pascal's rule to split the sum and the identity Hk=Hk−1+1kH_k = H_{k-1} + \frac1k to split the summand. The same two ideas solve most sums with HkH_k in them.

Examples

Example P2.9.23. To find ∑k=1nk2Hk\sum_{k=1}^n k^2H_k, write k2=2(k2)+kk^2 = 2\binom k2 + k. Then ∑0≤k<nk2Hk=2(n3)(Hn−13)+(n2)(Hn−12)\sum_{0 \le k < n}k^2H_k = 2\binom n3\bigl(H_n - \frac13\bigr) + \binom n2\bigl(H_n - \frac12\bigr). For n=3n = 3 this is 2⋅32+3⋅43=72 \cdot \frac32 + 3 \cdot \frac43 = 7, and the direct sum is 0+1+4⋅32=70 + 1 + 4 \cdot \frac32 = 7.

Example P2.9.24. The values of ∑k=1nHk\sum_{k=1}^nH_k for n=1,…,6n = 1, \dots, 6 are 11, 52\frac52, 133\frac{13}{3}, 7712\frac{77}{12}, 8710\frac{87}{10} and 22320\frac{223}{20}. Each is (n+1)Hn−n(n+1)H_n - n.

Exercises

  1. [10] Evaluate ∑k=16Hk\sum_{k=1}^{6}H_k with the first theorem and check it by adding.
  2. [M15] Prove that ∑k=1nkHk=n(n+1)2Hn−n(n−1)4\sum_{k=1}^nkH_k = \frac{n(n+1)}{2}H_n - \frac{n(n-1)}{4}.
  3. [M20] Find a closed form of ∑0≤k<nk2Hk\sum_{0 \le k < n}k^2H_k and check it for n=4n = 4.
  4. [10] Evaluate ∑k(4k)Hk\sum_k\binom 4kH_k with the theorem for x=1x = 1.
  5. [M22] Prove that ∑k=1n(−1)k+1(nk)1k2=∑k=1nHkk\sum_{k=1}^n(-1)^{k+1}\binom nk\frac{1}{k^2} = \sum_{k=1}^n\frac{H_k}{k}.
  6. [M15] Evaluate ∑k(nk)(−2)kHk\sum_k\binom nk(-2)^kH_k in terms of HnH_n and a sum, and check it for n=3n = 3.
  7. [10] Prove that ∑k=1n(Hn−Hk−1)=n\sum_{k=1}^n(H_n - H_{k-1}) = n.
  8. [M20] Prove that ∑0≤k<nHk(k+1)(k+2)=n−Hnn+1\sum_{0 \le k < n}\frac{H_k}{(k+1)(k+2)} = \frac{n - H_n}{n+1} by summation by parts.
  9. [M20] Use binomial inversion (Section 7.2) on the alternating sum for HnH_n to prove that ∑k(−1)k(nk)Hk=−1n\sum_k(-1)^k\binom nkH_k = -\frac1n for n≥1n \ge 1.

Lean

Mathlib has harmonic and harmonic_succ, but no lemma for the sums of this section. A Lean proof of ∑k=1nHk=(n+1)Hn−n\sum_{k=1}^nH_k = (n+1)H_n - n is a short induction on nn 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 nn 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 nn as here, as a step to Theorem 1.2.7A. The alternating sum for HnH_n is an old identity. Under binomial inversion it pairs with the identity ∑k(−1)k(nk)Hk=−1n\sum_k(-1)^k\binom nkH_k = -\frac1n, as Exercise 9 shows.

Harmonic numbers of higher order

Statement

If the terms 1k\frac1k are replaced by 1kr\frac{1}{k^r}, the partial sums behave in a different way. For r>1r > 1 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 rr and proves two sums over values of ζ\zeta and one sum that mixes HkH_k and Hn(2)H_n^{(2)}.

Definition P2.9.25 (the harmonic numbers of order rr, TAOCP eq. 1.2.7(4)). For a real number r>0r > 0 and an integer n≥0n \ge 0, Hn(r)=∑k=1n1kr.H_n^{(r)} = \sum_{k=1}^{n}\frac{1}{k^r}. So Hn(1)=HnH_n^{(1)} = H_n.

Example P2.9.26. For r=2r = 2 the first values are n12345Hn(2)154493620514452693600\begin{array}{c|ccccc} n & 1 & 2 & 3 & 4 & 5 \\ \hline H_n^{(2)} & 1 & \frac54 & \frac{49}{36} & \frac{205}{144} & \frac{5269}{3600} \end{array} In decimals H5(2)≈1.4636H_5^{(2)} \approx 1.4636 and H10(2)≈1.5498H_{10}^{(2)} \approx 1.5498. For r=3r = 3 the values are 11, 98\frac98, 251216\frac{251}{216} and 20351728\frac{2035}{1728} for n=1,…,4n = 1, \dots, 4.

Example P2.9.27. For r=12r = \frac12 the sum Hn(1/2)H_n^{(1/2)} grows like 2n2\sqrt n, so it is unbounded. For the exponent r=1r = 1 it grows like ln⁡n\ln n. Only an exponent above 11 gives a bounded sequence.

Theorem P2.9.28 (convergence for r>1r > 1, TAOCP Section 1.2.7). Let r>1r > 1. The sequence Hn(r)H_n^{(r)} increases and, for every n≥1n \ge 1, Hn(r)≤1+1−n1−rr−1<rr−1.H_n^{(r)} \le 1 + \frac{1 - n^{1-r}}{r-1} < \frac{r}{r-1}. So it has a limit ζ(r)=lim⁡n→∞Hn(r)\zeta(r) = \lim_{n \to \infty} H_n^{(r)}, with 1<ζ(r)≤rr−11 < \zeta(r) \le \frac{r}{r-1}. The error is bounded by 1(r−1)(n+1)r−1≤ζ(r)−Hn(r)≤1(r−1)nr−1.\frac{1}{(r-1)(n+1)^{r-1}} \le \zeta(r) - H_n^{(r)} \le \frac{1}{(r-1)n^{r-1}}.

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 x−rx^{-r} falls, so for k≥2k \ge 2 we have k−r≤∫k−1kx−rdxk^{-r} \le \int_{k-1}^{k}x^{-r}dx. Add over k=2,…,nk = 2, \dots, n: Hn(r)−1≤∫1nx−rdx=1−n1−rr−1H_n^{(r)} - 1 \le \int_1^nx^{-r}dx = \frac{1 - n^{1-r}}{r-1}. This is the first bound, and it is below 1r−1\frac{1}{r-1}, which gives Hn(r)<rr−1H_n^{(r)} < \frac{r}{r-1}. An increasing sequence that is bounded above has a limit. Since Hn(r)>H1(r)=1H_n^{(r)} > H_1^{(r)} = 1 for n≥2n \ge 2, the limit exceeds 11. For the error, k−r≤∫k−1kx−rdxk^{-r} \le \int_{k-1}^kx^{-r}dx gives ∑k>nk−r≤∫n∞x−rdx=1(r−1)nr−1\sum_{k > n}k^{-r} \le \int_n^\infty x^{-r}dx = \frac{1}{(r-1)n^{r-1}}, and k−r≥∫kk+1x−rdxk^{-r} \ge \int_k^{k+1}x^{-r}dx gives ∑k>nk−r≥∫n+1∞x−rdx=1(r−1)(n+1)r−1\sum_{k>n}k^{-r} \ge \int_{n+1}^\infty x^{-r}dx = \frac{1}{(r-1)(n+1)^{r-1}}. □\square

Example P2.9.29. For r=2r = 2 and n=10n = 10 the error bounds say 111≤ζ(2)−H10(2)≤110\frac1{11} \le \zeta(2) - H_{10}^{(2)} \le \frac1{10}. The values are 0.0909≤0.0952≤0.10.0909 \le 0.0952 \le 0.1. For r=3r = 3 and n=10n = 10 the error is at most 12⋅100=0.005\frac1{2 \cdot 100} = 0.005. With H10(3)=1.19753…H_{10}^{(3)} = 1.19753\ldots it follows that 1.1975<ζ(3)<1.20261.1975 < \zeta(3) < 1.2026. The true value is ζ(3)=1.20206…\zeta(3) = 1.20206\ldots

Definition P2.9.30 (the zeta function, TAOCP eq. 1.2.7(5)). For real r>1r > 1, ζ(r)=∑k≥1k−r\zeta(r) = \sum_{k \ge 1}k^{-r}. In TAOCP the number ζ(r)\zeta(r) is written H∞(r)H_\infty^{(r)}.

Example P2.9.31. ζ(2)≈1.6449\zeta(2) \approx 1.6449, ζ(3)≈1.2021\zeta(3) \approx 1.2021 and ζ(4)≈1.0823\zeta(4) \approx 1.0823. The values approach 11 as rr grows, since ζ(r)−1≤2−r+21−rr−1\zeta(r) - 1 \le 2^{-r} + \frac{2^{1-r}}{r-1}, which tends to 00.

Theorem P2.9.32 (the values at even arguments, TAOCP eqs. 1.2.7(6) and 1.2.7(7)). For every integer k≥1k \ge 1, ζ(2k)=(−1)k+1B2k(2π)2k2 (2k)!,\zeta(2k) = \frac{(-1)^{k+1}B_{2k}(2\pi)^{2k}}{2\,(2k)!}, with the Bernoulli numbers B2kB_{2k} of Chapter 11. The first four values are ζ(2)=π26,ζ(4)=π490,ζ(6)=π6945,ζ(8)=π89450.\zeta(2) = \frac{\pi^2}{6},\quad \zeta(4) = \frac{\pi^4}{90},\quad \zeta(6) = \frac{\pi^6}{945},\quad \zeta(8) = \frac{\pi^8}{9450}.

Lean: Mathlib hasSum_zeta_two and hasSum_zeta_four for k=1,2k = 1, 2, 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 H10(4)=1.0820366…H_{10}^{(4)} = 1.0820366\ldots and the tail bound 13⋅103=0.00033\frac{1}{3 \cdot 10^3} = 0.00033 show that ζ(4)\zeta(4) lies between 1.082281.08228 and 1.082371.08237, where the lower end is H10(4)+13⋅113H_{10}^{(4)} + \frac{1}{3 \cdot 11^3}. The value π490=1.0823232…\frac{\pi^4}{90} = 1.0823232\ldots lies in this range. For r=2r = 2 the partial sum with n=100n = 100 is 1.634981.63498, and π26−1.63498=0.00995\frac{\pi^2}{6} - 1.63498 = 0.00995, which is between 1101\frac1{101} and 1100\frac1{100}.

Theorem P2.9.34 (a telescoping sum of zeta values). The sum of the numbers ζ(k)−1\zeta(k) - 1 for k≥2k \ge 2 is ∑k≥2(ζ(k)−1)=1.\sum_{k \ge 2}\bigl(\zeta(k) - 1\bigr) = 1.

Lean: not stated.

Proof. Write ζ(k)−1=∑m≥2m−k\zeta(k) - 1 = \sum_{m \ge 2}m^{-k}. The double sum ∑k≥2∑m≥2m−k\sum_{k \ge 2}\sum_{m \ge 2}m^{-k} has non-negative terms, so the order of summation may change. For fixed m≥2m \ge 2 the sum over k≥2k \ge 2 is a geometric series, ∑k≥2m−k=m−21−1/m=1m(m−1)\sum_{k \ge 2}m^{-k} = \frac{m^{-2}}{1 - 1/m} = \frac{1}{m(m-1)}. Then ∑m≥21m(m−1)=∑m≥2(1m−1−1m)=1\sum_{m \ge 2}\frac{1}{m(m-1)} = \sum_{m \ge 2}\bigl(\frac1{m-1} - \frac1m\bigr) = 1, since the partial sums telescope to 1−1M1 - \frac1M. □\square

Example P2.9.35. The first terms are ζ(2)−1=0.6449\zeta(2) - 1 = 0.6449, ζ(3)−1=0.2021\zeta(3) - 1 = 0.2021, ζ(4)−1=0.0823\zeta(4) - 1 = 0.0823, ζ(5)−1=0.0369\zeta(5) - 1 = 0.0369 and ζ(6)−1=0.0173\zeta(6) - 1 = 0.0173. They add to 0.98360.9836, and the remaining terms for k≥7k \ge 7 add to 0.01640.0164, so the total is 11.

Theorem P2.9.36 (a sum of Hk/kH_k/k). For every integer n≥1n \ge 1, ∑k=1nHkk=12(Hn2+Hn(2)).\sum_{k=1}^{n}\frac{H_k}{k} = \frac12\Bigl(H_n^2 + H_n^{(2)}\Bigr).

Lean: not stated.

Proof. Expand the square: Hn2=∑j=1n∑k=1n1jkH_n^2 = \sum_{j=1}^n\sum_{k=1}^n\frac{1}{jk}. The terms with j=kj = k give Hn(2)H_n^{(2)}. The other terms come in pairs (j,k)(j, k) and (k,j)(k, j), so Hn2=Hn(2)+2∑1≤j<k≤n1jkH_n^2 = H_n^{(2)} + 2\sum_{1 \le j < k \le n}\frac{1}{jk}. For a fixed kk the sum over j<kj < k is Hk−1k\frac{H_{k-1}}{k}, so ∑j<k1jk=∑k=1nHk−1k=∑k=1nHkk−Hn(2)\sum_{j<k}\frac1{jk} = \sum_{k=1}^n\frac{H_{k-1}}{k} = \sum_{k=1}^n\frac{H_k}{k} - H_n^{(2)}. Then Hn2=Hn(2)+2∑k=1nHkk−2Hn(2)H_n^2 = H_n^{(2)} + 2\sum_{k=1}^n\frac{H_k}{k} - 2H_n^{(2)}, and solving for the sum gives the claim. □\square

Example P2.9.37. For n=4n = 4: ∑k=14Hkk=1+34+1118+2548=415144\sum_{k=1}^4\frac{H_k}{k} = 1 + \frac34 + \frac{11}{18} + \frac{25}{48} = \frac{415}{144}. The right side is 12(625144+205144)=415144\frac12\bigl(\frac{625}{144} + \frac{205}{144}\bigr) = \frac{415}{144}.

Proof

The proof of convergence compares the sum with an integral, as the logarithmic bounds of Section 9.1 do. The sum over kk of the numbers ζ(k)−1\zeta(k) - 1 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 Hn⋅HnH_n \cdot H_n twice, in the form of a triangle above the diagonal.

Examples

Example P2.9.38. The sum ∑k≥11k2\sum_{k \ge 1}\frac{1}{k^2} is also bounded by a telescoping sum. Since 1k2<1k(k−1)\frac1{k^2} < \frac1{k(k-1)} for k≥2k \ge 2, we get ζ(2)<1+∑k≥2(1k−1−1k)=2\zeta(2) < 1 + \sum_{k \ge 2}\bigl(\frac1{k-1} - \frac1k\bigr) = 2. This is the bound rr−1\frac{r}{r-1} for r=2r = 2.

Example P2.9.39. The sum over the odd numbers is ∑k≥11(2k−1)2=ζ(2)−14ζ(2)=34⋅π26=π28≈1.2337\sum_{k \ge 1}\frac{1}{(2k-1)^2} = \zeta(2) - \frac14\zeta(2) = \frac34 \cdot \frac{\pi^2}{6} = \frac{\pi^2}{8} \approx 1.2337. The partial sum over the odd numbers up to 2⋅1062 \cdot 10^6 is 1.23370031.2337003.

Exercises

  1. [10] Write H4(3)H_4^{(3)} as a fraction.
  2. [M15] Use the theorem on convergence with n=10n = 10 to show that 1.19<ζ(3)<1.211.19 < \zeta(3) < 1.21.
  3. [M20] Prove that ∑k≥2(−1)k(ζ(k)−1)=12\sum_{k \ge 2}(-1)^k\bigl(\zeta(k) - 1\bigr) = \frac12.
  4. [M20] Prove that ∑k=1nHkk+1=12(Hn+12−Hn+1(2))\sum_{k=1}^n\frac{H_k}{k+1} = \frac12\bigl(H_{n+1}^2 - H_{n+1}^{(2)}\bigr).
  5. [M25] Prove that ∑k=1n−1Hkn−k=Hn2−Hn(2)\sum_{k=1}^{n-1}\frac{H_k}{n-k} = H_n^2 - H_n^{(2)} for n≥1n \ge 1.
  6. [M20] Prove that ∑k=1nHkk(k+1)=Hn+1(2)−Hn+1n+1\sum_{k=1}^{n}\frac{H_k}{k(k+1)} = H_{n+1}^{(2)} - \frac{H_{n+1}}{n+1}, and find the value of ∑k≥1Hkk(k+1)\sum_{k \ge 1}\frac{H_k}{k(k+1)}.
  7. [M15] Prove that 1n+1<ζ(2)−Hn(2)<1n\frac{1}{n+1} < \zeta(2) - H_n^{(2)} < \frac1n for n≥1n \ge 1.
  8. [M15] Find ∑k≥11(2k−1)2\sum_{k \ge 1}\frac{1}{(2k-1)^2} from the value of ζ(2)\zeta(2), and find ∑k≥1(−1)k+1k2\sum_{k \ge 1}\frac{(-1)^{k+1}}{k^2}.
  9. [M20] Prove that ∑k=1nHk(2)=(n+1)Hn(2)−Hn\sum_{k=1}^nH_k^{(2)} = (n+1)H_n^{(2)} - H_n.

Lean

Mathlib has hasSum_zeta_two : HasSum (fun n : ℕ => (1 : ℝ) / (n : ℝ) ^ 2) (π ^ 2 / 6) and hasSum_zeta_four with the value π490\frac{\pi^4}{90}. The general formula is riemannZeta_two_mul_nat, for the complex zeta function and the Bernoulli numbers bernoulli. The partial sums Hn(r)H_n^{(r)} and the convergence for r>1r > 1 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 ζ(2)=π26\zeta(2) = \frac{\pi^2}{6} in 1735, and the general formula for ζ(2k)\zeta(2k) 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 ζ(3)\zeta(3); Roger Apéry proved in 1978 that it is irrational. The sum of the numbers ζ(k)−1\zeta(k) - 1 is an old exercise in the change of the order of a double sum.

TAOCP defines Hn(r)H_n^{(r)} 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 rr)
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 HkH_k)

The harmonic number Hn=1+12+⋯+1nH_n = 1 + \frac12 + \cdots + \frac1n 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 HnH_n, the mean cost of quicksort has HnH_n in it, and the Stirling number [n+12]{n+1 \brack 2} equals n! Hnn!\,H_n. A reader of TAOCP meets HnH_n first in Section 1.2.7 and then in almost every analysis of Volumes 1 to 3.

Section 9.1 defines HnH_n, tabulates it, shows that HnH_n is never an integer for n≥2n \ge 2, and traces its growth. It bounds HnH_n between two logarithms by comparing the sum with an integral, and it proves that the difference Hn−ln⁡nH_n - \ln n has a limit, Euler's constant γ\gamma. Section 9.2 sums harmonic numbers. Summation by parts from Chapter 3 gives ∑k<nHk\sum_{k<n} H_k and the sums with binomial weights (km)\binom{k}{m}, and a recurrence in nn gives the sums ∑k(nk)xkHk\sum_k \binom nk x^k H_k. Section 9.3 defines the harmonic numbers Hn(r)H_n^{(r)} of order rr, proves that they converge for r>1r > 1, states the values of the limit ζ(r)\zeta(r) for even rr and proves a few sums of values of ζ\zeta.

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 HnH_n 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 ln⁡x=∫1xdt/t\ln x = \int_1^x dt/t. The proof of ζ(2)=π2/6\zeta(2) = \pi^2/6 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.