taocp

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

Volume C1 · Basic concepts · TAOCP Section 1.2.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.

Contents
  1. Harmonic numbers and sums that contain them

Harmonic numbers and sums that contain them

Overview

Section 1.2.7 of TAOCP names one sum, the harmonic number Hn=1+12+⋯+1nH_n = 1 + \frac12 + \cdots + \frac1n, and collects what a reader of the later chapters needs about it. The section shows that HnH_n grows without bound but very slowly, and it gives the asymptotic series Hn=ln⁡n+γ+12n−⋯H_n = \ln n + \gamma + \frac1{2n} - \cdots. It defines the harmonic numbers of order rr, Hn(r)H_n^{(r)}, which stay bounded for r>1r > 1, and it quotes Euler's values of their limit ζ(r)\zeta(r) at even rr. Then it turns to sums that have HkH_k as a factor. Three of them are done: ∑Hk\sum H_k, the sum with binomial weights (km)Hk\binom km H_k by summation by parts, and the sum ∑(nk)xkHk\sum \binom nk x^k H_k, 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 HnH_n is smaller than the one before, so it is easy to believe that the sum levels off. It does not. The terms from 1/(2m+1)1/(2^m + 1) to 1/2m+11/2^{m+1} are 2m2^m numbers, and each is at least 1/2m+11/2^{m+1}, so the block adds at least 12\frac12. The sum grows by 12\frac12 each time the index doubles. This is the behavior of a logarithm. The exact statement is eq. 1.2.7(3): HnH_n is ln⁡n\ln n plus a constant γ\gamma plus a small correction that has an inverse power of nn in each term.

Raising the exponent makes the sum converge. If each term is 1/kr1/k^r with r>1r > 1, then the sum stays below a fixed bound. The comparison with an integral shows this: the sum is less than r/(r−1)r/(r-1). The limit is the zeta function. At even rr the limit is a rational multiple of πr\pi^r, 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 HkH_k as a factor is done in two ways. One way is to write HkH_k as a sum, and to exchange the order of the two sums. This gives ∑k≤nHk=(n+1)Hn−n\sum_{k \le n} H_k = (n+1)H_n - n. 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 (km)Hk\binom km H_k, the sum of (km)\binom km is a binomial coefficient, and the difference of HkH_k is 1/(k+1)1/(k+1). The result is eq. 1.2.7(9).

A recursion in nn gives a closed form. For the sum Sn=∑k(nk)xkHkS_n = \sum_k \binom nk x^k H_k, the rule (n+1k)=(nk)+(nk−1)\binom{n+1}{k} = \binom nk + \binom n{k-1} gives a first order recursion for SnS_n. Divide by (x+1)n+1(x+1)^{n+1} 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 nn 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 n≥0n \ge 0, the harmonic number is the following sum, which is empty and equal to 00 for n=0n = 0:

Hn=∑k=1n1k=1+12+13+⋯+1n.H_n = \sum_{k=1}^{n} \frac1k = 1 + \frac12 + \frac13 + \cdots + \frac1n.

Node: TAJ5CTXKS5 · Lean: TAOCP.S1_2_7.eq1 · status: proved

Explanation. The number HnH_n is rational. It is the partial sum of the harmonic series, and this is the reason for the name. It has the recursion Hn=Hn−1+1/nH_n = H_{n-1} + 1/n for n≥1n \ge 1, so the differences of HnH_n are the simple numbers 1/n1/n. This is what makes the sums of Sections 1.2.7 and 1.2.9 work: HnH_n is to 1/n1/n what n2n^2 is to 2n−12n - 1. In the literature the number also appears as ψ(n+1)+γ\psi(n+1) + \gamma, where ψ\psi 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 Hn(r)H_n^{(r)} as TAOCP.harmonicPow r n, and TAOCP.harmonicPow_one shows that it agrees with harmonic n at r=1r = 1.

Example. The first values are

nn 0 1 2 3 4 5 6 7 8
HnH_n 00 11 32\frac32 116\frac{11}6 2512\frac{25}{12} 13760\frac{137}{60} 4920\frac{49}{20} 363140\frac{363}{140} 761280\frac{761}{280}

For n=10n = 10 the value is H10=7381/2520≈2.928968H_{10} = 7381/2520 \approx 2.928968. Note that the denominator of H6H_6 is 2020, not 6060, because 13760+16=14760=4920\frac{137}{60} + \frac16 = \frac{147}{60} = \frac{49}{20}. The fractions are reduced.

Proof of the recursion. A sum over 1≤k≤n1 \le k \le n is the sum over 1≤k≤n−11 \le k \le n-1 plus the term k=nk = n. This gives Hn=Hn−1+1/nH_n = H_{n-1} + 1/n. By induction on nn, the denominator of HnH_n divides the least common multiple of 1,…,n1, \ldots, n, since each new term adds a fraction with denominator nn. □\square

Theorem C1.1.2.7.2 (a lower bound at the powers of 2, TAOCP eq. 1.2.7(2)). For each integer m≥0m \ge 0 the bound below holds. Consequently HnH_n is not bounded: for each real NN there is an nn with Hn>NH_n > N.

H2m≥1+m2.H_{2^m} \ge 1 + \frac m2.

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 2m2^m terms the sum is at least 1+m/21 + m/2. The bound is weak. The true value of H2mH_{2^m} is about mln⁡2+0.577m \ln 2 + 0.577, which is 0.69m0.69 m and not 0.5m0.5 m. 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 H2m≤1+mH_{2^m} \le 1 + m (exercise 1.2.7-2), so H2mH_{2^m} lies between 1+m/21 + m/2 and 1+m1 + m.

Example. The exact values and the bounds for m=0,…,6m = 0, \ldots, 6:

mm 2m2^m H2mH_{2^m} 1+m/21 + m/2 1+m1 + m
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 m=0m = 0 and m=1m = 1. The first nn with Hn>3H_n > 3 is n=11n = 11, and the first nn with Hn>4H_n > 4 is n=31n = 31. The first nn with Hn>10H_n > 10 is n=12367n = 12367. So a sum that exceeds 1010 needs more than twelve thousand terms. The bound of the theorem guarantees only n≤219=524288n \le 2^{19} = 524288 for this case, since 1+19/2>101 + 19/2 > 10.

Proof. The proof is by induction on mm. For m=0m = 0 the claim is H1=1≥1H_1 = 1 \ge 1. Let m≥0m \ge 0 and suppose that H2m≥1+m/2H_{2^m} \ge 1 + m/2. The difference of two harmonic numbers is a sum of terms:

H2m+1−H2m=∑j=2m+12m+11j.H_{2^{m+1}} - H_{2^m} = \sum_{j = 2^m + 1}^{2^{m+1}} \frac1j.

This sum has 2m+1−2m=2m2^{m+1} - 2^m = 2^m terms. Each term has j≤2m+1j \le 2^{m+1}, so 1/j≥1/2m+11/j \ge 1/2^{m+1}. Hence the sum is at least 2m/2m+1=122^m / 2^{m+1} = \frac12. So H2m+1≥H2m+12≥1+(m+1)/2H_{2^{m+1}} \ge H_{2^m} + \frac12 \ge 1 + (m+1)/2. This is the claim for m+1m + 1.

For the second part, let NN be real. Choose an integer m≥0m \ge 0 with m≥2Nm \ge 2N. Then H2m≥1+m/2>NH_{2^m} \ge 1 + m/2 > N. □\square

Theorem C1.1.2.7.3 (the asymptotic series of HnH_n, TAOCP eq. 1.2.7(3)). Let γ=lim⁡n→∞(Hn−ln⁡n)=0.5772156649…\gamma = \lim_{n \to \infty} (H_n - \ln n) = 0.5772156649\ldots be Euler's constant. For each integer n≥1n \ge 1,

Hn=ln⁡n+γ+12n−112n2+1120n4−ϵ,0<ϵ<1252n6.H_n = \ln n + \gamma + \frac1{2n} - \frac1{12n^2} + \frac1{120n^4} - \epsilon, \qquad 0 < \epsilon < \frac1{252n^6}.

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 HnH_n. The first two terms, ln⁡n+γ\ln n + \gamma, 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 B2k/(2k n2k)B_{2k}/(2k\, n^{2k}) have Bernoulli numbers in the numerator, and these grow faster than any geometric sequence. For a fixed nn, 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 ϵ\epsilon. 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 γ\gamma 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 Hn−ln⁡nH_n - \ln n tends to it.

Example. Take n=10n = 10. With ln⁡10=2.302585093…\ln 10 = 2.302585093\ldots and γ=0.577215665…\gamma = 0.577215665\ldots,

ln⁡10+γ+120−11200+11200000=2.928968257 89…\ln 10 + \gamma + \frac1{20} - \frac1{1200} + \frac1{1200000} = 2.928968257\,89\ldots

The exact value is H10=2.928968253 96…H_{10} = 2.928968253\,96\ldots. The difference is ϵ=3.9273×10−9\epsilon = 3.9273 \times 10^{-9}, and the bound is 1/(252⋅106)=3.9683×10−91/(252 \cdot 10^6) = 3.9683 \times 10^{-9}. So 0<ϵ<1/(252n6)0 < \epsilon < 1/(252 n^6) holds, and the bound is sharp to 1%1\%. For n=100n = 100, H100=5.187377517 64…H_{100} = 5.187377517\,64\ldots, ϵ=3.96784×10−15\epsilon = 3.96784 \times 10^{-15} and the bound is 3.96825×10−153.96825 \times 10^{-15}. For n=1n = 1 the series gives 1.0022157−ϵ1.0022157 - \epsilon with ϵ=0.0022157<1/252=0.0039683\epsilon = 0.0022157 < 1/252 = 0.0039683, so the theorem is true even for n=1n = 1.

Proof. First, the constant exists. Let an=Hn−ln⁡na_n = H_n - \ln n. Then

an−an+1=ln⁡(1+1n)−1n+1.a_n - a_{n+1} = \ln\Bigl(1 + \frac1n\Bigr) - \frac1{n+1}.

The function ln⁡(1+1/n)=∫nn+1dx/x\ln(1 + 1/n) = \int_n^{n+1} dx/x is the integral of a decreasing function over an interval of length 11, so it is larger than 1/(n+1)1/(n+1), the value at the right end. Hence an−an+1>0a_n - a_{n+1} > 0, and (an)(a_n) decreases. For the same reason, ln⁡(1+1/k)<1/k\ln(1 + 1/k) < 1/k for each kk, so ln⁡(n+1)=∑k=1nln⁡(1+1/k)<Hn\ln(n + 1) = \sum_{k=1}^{n} \ln(1 + 1/k) < H_n. Thus an>ln⁡(n+1)−ln⁡n>0a_n > \ln(n+1) - \ln n > 0. A decreasing sequence that is bounded below has a limit, and the limit γ\gamma satisfies 0≤γ≤a1=10 \le \gamma \le a_1 = 1.

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 f(x)=1/xf(x) = 1/x on [1,n][1, n]. Its derivatives are f(j)(x)=(−1)jj!/xj+1f^{(j)}(x) = (-1)^j j!/x^{j+1}, so the odd derivatives are f(2k−1)(x)=−(2k−1)!/x2kf^{(2k-1)}(x) = -(2k-1)!/x^{2k}. The formula for the sum over 1≤k<n1 \le k < n has the integral ∫1ndx/x=ln⁡n\int_1^n dx/x = \ln n, then the term of B1=−12B_1 = -\frac12, which is B1(f(n)−f(1))=12−12nB_1(f(n) - f(1)) = \frac12 - \frac1{2n}, then for each kk the term of B2kB_{2k}, which is

B2k(2k)!(f(2k−1)(n)−f(2k−1)(1))=B2k2k(1−1n2k),\frac{B_{2k}}{(2k)!}\bigl(f^{(2k-1)}(n) - f^{(2k-1)}(1)\bigr) = \frac{B_{2k}}{2k}\Bigl(1 - \frac1{n^{2k}}\Bigr),

and then a remainder R6(1,n)R_6(1, n), an integral of a Bernoulli function times f(6)f^{(6)}. Take the terms up to k=3k = 3 and add 1/n1/n to both sides to get HnH_n:

Hn=ln⁡n+12n−∑k=13B2k2k n2k+(12+∑k=13B2k2k)+R6(1,n).H_n = \ln n + \frac1{2n} - \sum_{k=1}^{3} \frac{B_{2k}}{2k\, n^{2k}} + \Bigl(\frac12 + \sum_{k=1}^{3}\frac{B_{2k}}{2k}\Bigr) + R_6(1, n).

With B2=16B_2 = \frac16, B4=−130B_4 = -\frac1{30} and B6=142B_6 = \frac1{42}, the three terms of the sum are −112n2-\frac1{12n^2}, +1120n4+\frac1{120n^4} and −1252n6-\frac1{252n^6}. The function f(6)(x)=720/x7f^{(6)}(x) = 720/x^7 has a convergent integral to ∞\infty, so R6(1,n)=R6(1,∞)−R6(n,∞)R_6(1, n) = R_6(1, \infty) - R_6(n, \infty) with a finite number R6(1,∞)R_6(1, \infty). Collect all the terms that do not depend on nn into one constant CC. Then

Hn=ln⁡n+C+12n−112n2+1120n4−1252n6−R6(n,∞).H_n = \ln n + C + \frac1{2n} - \frac1{12n^2} + \frac1{120n^4} - \frac1{252n^6} - R_6(n, \infty).

Since R6(n,∞)→0R_6(n, \infty) \to 0, C=lim⁡(Hn−ln⁡n)=γC = \lim (H_n - \ln n) = \gamma. So the theorem holds with ϵ=1252n6+R6(n,∞)\epsilon = \frac1{252n^6} + R_6(n, \infty). The remainder lemma of Section 1.2.11.2 (eq. 1.2.11.2(13)) applies with m=6m = 6. Its condition is that f(8)f^{(8)} and f(10)f^{(10)} have the same sign, and f(8)(x)=8!/x9f^{(8)}(x) = 8!/x^9 and f(10)(x)=10!/x11f^{(10)}(x) = 10!/x^{11} are both positive on [n,∞)[n, \infty). 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 −B8/(8n8)=+1/(240n8)-B_8/(8 n^8) = +1/(240 n^8) in the series for HnH_n. So 0<−R6(n,∞)<1/(240n8)0 < -R_6(n, \infty) < 1/(240 n^8), which gives 0<ϵ<1/(252n6)0 < \epsilon < 1/(252 n^6) for each nn with 1/(240n8)≤1/(252n6)1/(240 n^8) \le 1/(252 n^6), that is for n≥2n \ge 2. For n=1n = 1 the check is by arithmetic: γ+12−112+1120−H1=0.5772157+0.5−0.0833333+0.0083333−1=0.0022157\gamma + \frac12 - \frac1{12} + \frac1{120} - H_1 = 0.5772157 + 0.5 - 0.0833333 + 0.0083333 - 1 = 0.0022157, which lies between 00 and 1/252=0.00396831/252 = 0.0039683. □\square

The error at n=10n = 10 is a test of this proof. The series for ϵ\epsilon is 1252n6−1240n8+1132n10−⋯\frac1{252n^6} - \frac1{240n^8} + \frac1{132n^{10}} - \cdots, which at n=10n = 10 is 3.96825×10−9−0.04167×10−9+0.00076×10−9=3.92734×10−93.96825 \times 10^{-9} - 0.04167 \times 10^{-9} + 0.00076 \times 10^{-9} = 3.92734 \times 10^{-9}. The true error is 3.92732×10−93.92732 \times 10^{-9}.

Definition C1.1.2.7.4 (the harmonic numbers of order rr, TAOCP eq. 1.2.7(4)). For r>0r > 0 and n≥0n \ge 0,

Hn(r)=∑k=1n1kr=1+12r+⋯+1nr.H_n^{(r)} = \sum_{k=1}^{n} \frac1{k^r} = 1 + \frac1{2^r} + \cdots + \frac1{n^r}.

Node: TAAAPCGY2W · Lean: TAOCP.S1_2_7.eq4 (partial) · status: proved

Explanation. The number Hn(1)H_n^{(1)} is HnH_n. 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 ∑Hk/k\sum H_k/k (exercise 1.2.7-14). The statement of the section is that these numbers are bounded when r>1r > 1. The theorem below proves this and gives a bound. The project has TAOCP.harmonicPow r n for natural rr. The book also uses real rr, and a definition for these has not been made yet.

Example. With r=2r = 2: H1(2)=1H_1^{(2)} = 1, H2(2)=54H_2^{(2)} = \frac54, H3(2)=4936≈1.3611H_3^{(2)} = \frac{49}{36} \approx 1.3611, H4(2)=205144≈1.4236H_4^{(2)} = \frac{205}{144} \approx 1.4236, and H10(2)≈1.549768H_{10}^{(2)} \approx 1.549768. With r=3r = 3: H10(3)≈1.197532H_{10}^{(3)} \approx 1.197532. For r=2r = 2 the sum after ten terms is already within 0.10.1 of its limit.

Theorem C1.1.2.7.5 (the harmonic numbers of order r>1r > 1 are bounded, TAOCP Section 1.2.7). For each real r>1r > 1 and each n≥1n \ge 1,

Hn(r)<rr−1.H_n^{(r)} < \frac r{r-1}.

Node: none · Lean: TAOCP.S1_2_7.harmonicPow_lt_two (partial)

Explanation. The theorem is the contrast to eq. 1.2.7(2): for r=1r = 1 there is no bound, and for each r>1r > 1 there is a bound that depends only on rr. Near r=1r = 1 the bound is good in ratio: ζ(r)\zeta(r) is about 1r−1+γ\frac1{r-1} + \gamma, so the bound 1+1r−11 + \frac1{r-1} exceeds the limit by about 1−γ=0.421 - \gamma = 0.42. For large rr the bound tends to 11, as Hn(r)H_n^{(r)} does, but its excess 1r−1\frac1{r-1} is much larger than ζ(r)−1\zeta(r) - 1, which is about 2−r2^{-r}. The argument of eq. 1.2.7(2), with blocks of 2j2^j terms, also gives a bound (exercise 1.2.7-3). The proof here uses an integral and gives another bound.

Example. For r=2r = 2 the bound is 22, and H10(2)=1.5498H_{10}^{(2)} = 1.5498. For r=3r = 3 the bound is 32\frac32, and H10(3)=1.1975H_{10}^{(3)} = 1.1975. For r=1.1r = 1.1 the bound is 1111. The real limit is ζ(1.1)≈10.58\zeta(1.1) \approx 10.58, so near r=1r = 1 the bound is close to the truth.

Proof. For k≥2k \ge 2 the function x−rx^{-r} is decreasing, so on the interval [k−1,k][k - 1, k] its value is at least k−rk^{-r}. Hence k−r<∫k−1kx−r dxk^{-r} < \int_{k-1}^{k} x^{-r}\,dx. Add this for k=2,…,nk = 2, \ldots, n:

∑k=2n1kr<∫1nx−r dx=1−n1−rr−1<1r−1.\sum_{k=2}^{n} \frac1{k^r} < \int_1^n x^{-r}\,dx = \frac{1 - n^{1-r}}{r - 1} < \frac1{r-1}.

Add the term k=1k = 1, which is 11, to get Hn(r)<1+1r−1=rr−1H_n^{(r)} < 1 + \frac1{r-1} = \frac r{r-1}. □\square

Definition C1.1.2.7.6 (the zeta function, TAOCP eq. 1.2.7(5)). For r>1r > 1,

H∞(r)=ζ(r)=∑k≥11kr=lim⁡n→∞Hn(r).H_\infty^{(r)} = \zeta(r) = \sum_{k \ge 1} \frac1{k^r} = \lim_{n \to \infty} H_n^{(r)}.

Node: TASEC18JZ4 · Lean: TAOCP.S1_2_7.eq5, TAOCP.S1_2_7.eq5_zeta (partial) · status: proved

Explanation. The sequence Hn(r)H_n^{(r)} is increasing and, by the theorem above, bounded, so it has a limit. The limit is Riemann's zeta function at rr. The speed of the approach is given by a comparison with an integral: the tail is about n1−r/(r−1)n^{1-r}/(r-1). For r≥2r \ge 2 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 r=2r = 2 is ζ(2)=1.6449341\zeta(2) = 1.6449341, and ζ(3)=1.2020569\zeta(3) = 1.2020569. The tail after n=10n = 10 terms for r=2r = 2 is ζ(2)−H10(2)=0.0951663\zeta(2) - H_{10}^{(2)} = 0.0951663. The tail bounds below give 111=0.0909\frac1{11} = 0.0909 and 110=0.1\frac1{10} = 0.1. So the value 0.09520.0952 is between them.

Proof of the tail bounds. For n≥1n \ge 1 and k≥n+1k \ge n + 1, the decreasing function x−rx^{-r} gives ∫kk+1x−r dx<k−r<∫k−1kx−r dx\int_{k}^{k+1} x^{-r}\,dx < k^{-r} < \int_{k-1}^{k} x^{-r}\,dx. Sum over k≥n+1k \ge n + 1:

(n+1)1−rr−1<ζ(r)−Hn(r)<n1−rr−1.\frac{(n+1)^{1-r}}{r-1} < \zeta(r) - H_n^{(r)} < \frac{n^{1-r}}{r-1}.

For r=2r = 2 and n=10n = 10 these are 111\frac1{11} and 110\frac1{10}. □\square

Theorem C1.1.2.7.7 (Euler's values of ζ\zeta at even arguments, TAOCP eq. 1.2.7(6)). For each integer k≥1k \ge 1,

ζ(2k)=12∣B2k∣(2π)2k(2k)!.\zeta(2k) = \frac12 |B_{2k}| \frac{(2\pi)^{2k}}{(2k)!}.

Node: TARHF9ZQ4W · Lean: TAOCP.S1_2_7.eq6 · status: proved

Explanation. The theorem expresses ζ(2k)\zeta(2k) as a rational number times π2k\pi^{2k}. The rational number comes from the Bernoulli number B2kB_{2k}. The Bernoulli numbers of the book are defined in Section 1.2.11.2 by B0=1B_0 = 1 and ∑j=0m(m+1j)Bj=0\sum_{j=0}^{m} \binom{m+1}{j} B_j = 0 for m≥1m \ge 1, and the first values are B1=−12B_1 = -\frac12, B2=16B_2 = \frac16, B4=−130B_4 = -\frac1{30}, B6=142B_6 = \frac1{42}, B8=−130B_8 = -\frac1{30}. They have alternating signs at even index: B2kB_{2k} has the sign (−1)k+1(-1)^{k+1}, so the absolute value in the theorem is the same as (−1)k+1B2k(-1)^{k+1} B_{2k}. The values at odd arguments, ζ(3),ζ(5),…\zeta(3), \zeta(5), \ldots, 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 −1-1.

Example. With k=1k = 1: 12⋅16⋅4π22=π26\frac12 \cdot \frac16 \cdot \frac{4\pi^2}{2} = \frac{\pi^2}6. With k=2k = 2: 12⋅130⋅16π424=π490\frac12 \cdot \frac1{30} \cdot \frac{16\pi^4}{24} = \frac{\pi^4}{90}. With k=3k = 3: 12⋅142⋅64π6720=π6945\frac12 \cdot \frac1{42} \cdot \frac{64\pi^6}{720} = \frac{\pi^6}{945}. With k=4k = 4: 12⋅130⋅256π840320=π89450\frac12 \cdot \frac1{30} \cdot \frac{256\pi^8}{40320} = \frac{\pi^8}{9450}. The computation for k=4k = 4 is 2562⋅30⋅40320=2562419200=19450\frac{256}{2 \cdot 30 \cdot 40320} = \frac{256}{2419200} = \frac1{9450}.

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 Bn(x)B_n(x) by B0(x)=1B_0(x) = 1, Bn′(x)=nBn−1(x)B_n'(x) = n B_{n-1}(x) and ∫01Bn(x) dx=0\int_0^1 B_n(x)\,dx = 0 for n≥1n \ge 1. These conditions fix each Bn(x)B_n(x), since the first fixes it up to a constant and the second fixes the constant. So B1(x)=x−12B_1(x) = x - \frac12 and B2(x)=x2−x+16B_2(x) = x^2 - x + \frac16. For n≥2n \ge 2, Bn(1)−Bn(0)=∫01nBn−1(x) dx=0B_n(1) - B_n(0) = \int_0^1 n B_{n-1}(x)\,dx = 0, so Bn(1)=Bn(0)B_n(1) = B_n(0). Let Bn=Bn(0)B_n = B_n(0). The derivative rule gives the Taylor expansion Bn(x)=∑j=0n(nj)Bjxn−jB_n(x) = \sum_{j=0}^{n} \binom nj B_j x^{n-j}. Put x=1x = 1 and use Bn(1)=Bn(0)B_n(1) = B_n(0) for n≥2n \ge 2 to get ∑j=0n−1(nj)Bj=0\sum_{j=0}^{n-1} \binom nj B_j = 0. This is the recursion of the book, with m=n−1m = n - 1. So the numbers BnB_n here are the Bernoulli numbers of the book.

Now let m≥2m \ge 2 and let fmf_m be the function Bm(x)B_m(x) on [0,1][0, 1], extended to the real line with period 11. Since Bm(1)=Bm(0)B_m(1) = B_m(0), fmf_m is continuous, and it is smooth except at the integers. For an integer q≠0q \ne 0, let cq(m)=∫01Bm(x)e−2πiqx dxc_q^{(m)} = \int_0^1 B_m(x) e^{-2\pi i q x}\,dx. Integrate by parts. For m≥2m \ge 2 the boundary term is Bm(1)−Bm(0)=0B_m(1) - B_m(0) = 0, and the rest is

cq(m)=12πiq∫01mBm−1(x)e−2πiqx dx=m2πiqcq(m−1),c_q^{(m)} = \frac{1}{2\pi i q} \int_0^1 m B_{m-1}(x) e^{-2\pi i q x}\,dx = \frac{m}{2\pi i q} c_q^{(m-1)},

where cq(1)c^{(1)}_q is defined by the same integral with m=1m = 1. For m=1m = 1 the boundary term is −12πiq(B1(1)−B1(0))=−12πiq-\frac{1}{2\pi i q}(B_1(1) - B_1(0)) = -\frac1{2\pi i q}, and the integral of B0e−2πiqxB_0 e^{-2\pi i q x} is 00. So cq(1)=−1/(2πiq)c_q^{(1)} = -1/(2\pi i q). By induction, cq(m)=−m!/(2πiq)mc_q^{(m)} = -m!/(2\pi i q)^m for m≥1m \ge 1. The mean value is c0(m)=∫01Bm=0c_0^{(m)} = \int_0^1 B_m = 0. The coefficients are O(q−m)O(q^{-m}) with m≥2m \ge 2, so the Fourier series of the continuous, piecewise smooth function fmf_m converges absolutely and uniformly to fmf_m:

Bm(x)=−m!∑q≠0e2πiqx(2πiq)m,0≤x≤1.B_m(x) = -m! \sum_{q \ne 0} \frac{e^{2\pi i q x}}{(2\pi i q)^m}, \qquad 0 \le x \le 1.

Let m=2km = 2k. Then (2πiq)2k=(−1)k(2πq)2k(2\pi i q)^{2k} = (-1)^k (2\pi q)^{2k} for qq and for −q-q. The terms for qq and −q-q are complex conjugates, and their sum has e2πiqx+e−2πiqx=2cos⁡2πqxe^{2\pi i q x} + e^{-2\pi i q x} = 2 \cos 2\pi q x. Hence

B2k(x)=(−1)k+12 (2k)!(2π)2k∑q≥1cos⁡2πqxq2k.B_{2k}(x) = (-1)^{k+1} \frac{2\,(2k)!}{(2\pi)^{2k}} \sum_{q \ge 1} \frac{\cos 2\pi q x}{q^{2k}}.

Put x=0x = 0: B2k=(−1)k+12 (2k)!(2π)2k ζ(2k)B_{2k} = (-1)^{k+1} \dfrac{2\,(2k)!}{(2\pi)^{2k}}\, \zeta(2k). Since ζ(2k)>0\zeta(2k) > 0, the sign of B2kB_{2k} is (−1)k+1(-1)^{k+1}, so ∣B2k∣=(−1)k+1B2k|B_{2k}| = (-1)^{k+1} B_{2k} and ζ(2k)=12∣B2k∣(2π)2k/(2k)!\zeta(2k) = \frac12 |B_{2k}| (2\pi)^{2k}/(2k)!. □\square

Example C1.1.2.7.8 (the values at r=2,4,6,8r = 2, 4, 6, 8, TAOCP eq. 1.2.7(7)). The first four values of the theorem are

H∞(2)=π26,H∞(4)=π490,H∞(6)=π6945,H∞(8)=π89450.H_\infty^{(2)} = \frac{\pi^2}6, \qquad H_\infty^{(4)} = \frac{\pi^4}{90}, \qquad H_\infty^{(6)} = \frac{\pi^6}{945}, \qquad H_\infty^{(8)} = \frac{\pi^8}{9450}.

Node: TABN8N7259 · Lean: TAOCP.S1_2_7.eq7 (partial) · status: proved

Explanation. The first of these, ζ(2)=π2/6\zeta(2) = \pi^2/6, was the famous problem that Euler solved in 1735. The values give sharp bounds for the sums that use Hn(2)H_n^{(2)}, which appear in the average cost of several searching methods. All four are the instances k=1,2,3,4k = 1, 2, 3, 4 of the theorem above, and the check of the arithmetic is in its example. The numerical values are given below.

Example. To eight digits, π2/6=1.6449341\pi^2/6 = 1.6449341, π4/90=1.0823232\pi^4/90 = 1.0823232, π6/945=1.0173431\pi^6/945 = 1.0173431 and π8/9450=1.0040774\pi^8/9450 = 1.0040774. These agree with the sums: 1+116+181+⋯1 + \frac1{16} + \frac1{81} + \cdots is 1.08232321.0823232 for r=4r = 4. For r=8r = 8 the first two terms give 1+1256=1.00391 + \frac1{256} = 1.0039, and the third adds 16561=0.00015\frac1{6561} = 0.00015.

Proof. Put k=1,2,3,4k = 1, 2, 3, 4 in the theorem with B2=16B_2 = \frac16, B4=−130B_4 = -\frac1{30}, B6=142B_6 = \frac1{42} and B8=−130B_8 = -\frac1{30}. The arithmetic is in the example of the theorem. □\square

Theorem C1.1.2.7.9 (the sum of the first nn harmonic numbers, TAOCP eq. 1.2.7(8)). For each integer n≥0n \ge 0,

∑k=1nHk=(n+1)Hn−n.\sum_{k=1}^{n} H_k = (n+1) H_n - n.

Node: TA398RK35R · Lean: TAOCP.S1_2_7.eq8 · status: proved

Explanation. The sum of the first nn values of HkH_k is almost (n+1)(n+1) times the last one. The correction −n-n has the same form as in the integral ∫1nln⁡x dx=nln⁡n−n+1\int_1^n \ln x\,dx = n \ln n - n + 1, since HnH_n is close to ln⁡n\ln n. Exercise 1.2.7-8 asks to compare the sum with ∑ln⁡k=ln⁡n!\sum \ln k = \ln n!. The result is the case m=0m = 0 of eq. 1.2.7(9).

Example. With n=5n = 5: H1+⋯+H5=1+32+116+2512+13760=8710H_1 + \cdots + H_5 = 1 + \frac32 + \frac{11}6 + \frac{25}{12} + \frac{137}{60} = \frac{87}{10}, and 6H5−5=13710−5=87106 H_5 - 5 = \frac{137}{10} - 5 = \frac{87}{10}. With n=1n = 1: H1=1H_1 = 1 and 2H1−1=12 H_1 - 1 = 1.

Proof. Write HkH_k as a sum and exchange the order of the sums, as in Section 1.2.3:

∑k=1nHk=∑k=1n∑j=1k1j=∑j=1n∑k=jn1j=∑j=1nn+1−jj.\sum_{k=1}^{n} H_k = \sum_{k=1}^{n} \sum_{j=1}^{k} \frac1j = \sum_{j=1}^{n} \sum_{k=j}^{n} \frac1j = \sum_{j=1}^{n} \frac{n+1-j}{j}.

The set of pairs (j,k)(j, k) with 1≤j≤k≤n1 \le j \le k \le n is the same in both orders. The inner sum on the right has n−j+1n - j + 1 equal terms. Split the fraction: n+1−jj=n+1j−1\frac{n+1-j}{j} = \frac{n+1}{j} - 1. Hence the sum is (n+1)Hn−n(n+1) H_n - n. □\square

Theorem C1.1.2.7.10 (the sum with binomial weights, TAOCP eq. 1.2.7(9)). For integers m≥0m \ge 0 and n≥0n \ge 0,

∑k=1n(km)Hk=(n+1m+1)(Hn+1−1m+1).\sum_{k=1}^{n} \binom km H_k = \binom{n+1}{m+1} \Bigl(H_{n+1} - \frac1{m+1}\Bigr).

Node: TAF82ZCVZC · Lean: TAOCP.S1_2_7.eq9 · status: proved

Explanation. The formula adds the harmonic numbers with the weights (km)\binom km, which are polynomials of degree mm in kk. For m=0m = 0 it is eq. 1.2.7(8): (n+1)(Hn+1−1)=(n+1)Hn+1−(n+1)=(n+1)Hn−n(n+1)(H_{n+1} - 1) = (n+1) H_n + 1 - (n+1) = (n+1) H_n - n. The right side is the product of the sum ∑k(km)=(n+1m+1)\sum_k \binom km = \binom{n+1}{m+1} with Hn+1H_{n+1}, minus a correction. This is the pattern of the discrete integration by parts: the book compares it with the integral ∫1nxmln⁡x dx=nm+1m+1(ln⁡n−1m+1)+1(m+1)2\int_1^n x^m \ln x\,dx = \frac{n^{m+1}}{m+1}(\ln n - \frac1{m+1}) + \frac1{(m+1)^2}, 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 nn, and then it shows the summation by parts.

Example. With m=2m = 2 and n=6n = 6: ∑k=16(k2)Hk=0+1⋅32+3⋅116+6⋅2512+10⋅13760+15⋅4920=94912\sum_{k=1}^{6} \binom k2 H_k = 0 + 1 \cdot \frac32 + 3 \cdot \frac{11}6 + 6 \cdot \frac{25}{12} + 10 \cdot \frac{137}{60} + 15 \cdot \frac{49}{20} = \frac{949}{12}. The right side is (73)(H7−13)=35⋅(363140−13)=35⋅949420=94912\binom73 (H_7 - \frac13) = 35 \cdot (\frac{363}{140} - \frac13) = 35 \cdot \frac{949}{420} = \frac{949}{12}.

Proof by induction on nn. For n=0n = 0 the left side is the empty sum 00. The right side is (1m+1)(H1−1m+1)\binom1{m+1}(H_1 - \frac1{m+1}). For m=0m = 0 this is 1⋅(1−1)=01 \cdot (1 - 1) = 0, and for m≥1m \ge 1 the binomial coefficient (1m+1)\binom1{m+1} is 00. Now let n≥1n \ge 1 and suppose that the formula holds for n−1n - 1. Call the right side R(n)R(n). It is enough to show that R(n)−R(n−1)=(nm)HnR(n) - R(n-1) = \binom nm H_n. Use (n+1m+1)=(nm+1)+(nm)\binom{n+1}{m+1} = \binom n{m+1} + \binom nm and Hn+1=Hn+1n+1H_{n+1} = H_n + \frac1{n+1}. Then

R(n)=(n+1m+1)Hn+1n+1(n+1m+1)−1m+1(n+1m+1).R(n) = \binom{n+1}{m+1} H_n + \frac{1}{n+1}\binom{n+1}{m+1} - \frac1{m+1} \binom{n+1}{m+1}.

The absorption rule of Section 1.2.6 gives 1n+1(n+1m+1)=1m+1(nm)\frac{1}{n+1}\binom{n+1}{m+1} = \frac1{m+1}\binom nm. So

R(n)−R(n−1)=((n+1m+1)−(nm+1))Hn+1m+1(nm)−1m+1((n+1m+1)−(nm+1)),R(n) - R(n-1) = \Bigl(\binom{n+1}{m+1} - \binom n{m+1}\Bigr) H_n + \frac1{m+1}\binom nm - \frac1{m+1}\Bigl(\binom{n+1}{m+1} - \binom n{m+1}\Bigr),

where R(n−1)=(nm+1)(Hn−1m+1)R(n-1) = \binom n{m+1}(H_n - \frac1{m+1}) was written in the same form. The two differences of binomial coefficients are equal to (nm)\binom nm. So the last two terms cancel, and R(n)−R(n−1)=(nm)HnR(n) - R(n-1) = \binom nm H_n. □\square

Second proof, by parts. Summation by parts (exercise 1.2.7-10) is ∑1≤k<n(ak+1−ak)bk=anbn−a1b1−∑1≤k<nak+1(bk+1−bk)\sum_{1 \le k < n}(a_{k+1} - a_k) b_k = a_n b_n - a_1 b_1 - \sum_{1 \le k < n} a_{k+1}(b_{k+1} - b_k). Take ak=(km+1)a_k = \binom k{m+1} and bk=Hkb_k = H_k. By Pascal's rule, ak+1−ak=(km)a_{k+1} - a_k = \binom km, and bk+1−bk=1k+1b_{k+1} - b_k = \frac1{k+1}. The sum of (km)Hk\binom km H_k over 1≤k≤n1 \le k \le n, which is the sum over 1≤k<n+11 \le k < n + 1, is then (n+1m+1)Hn+1−(1m+1)H1−∑1≤k≤n(k+1m+1)1k+1\binom{n+1}{m+1} H_{n+1} - \binom1{m+1}H_1 - \sum_{1 \le k \le n} \binom{k+1}{m+1}\frac1{k+1}. By absorption, (k+1m+1)1k+1=1m+1(km)\binom{k+1}{m+1}\frac1{k+1} = \frac1{m+1}\binom km. The sum of (km)\binom km over 0≤k≤n0 \le k \le n is (n+1m+1)\binom{n+1}{m+1} (eq. 1.2.6(11)), so the sum over 1≤k≤n1 \le k \le n is (n+1m+1)−[m=0]\binom{n+1}{m+1} - [m = 0]. Also (1m+1)H1=[m=0]\binom1{m+1}H_1 = [m = 0]. The two terms with [m=0][m = 0] are −[m=0]+1m+1[m=0]-[m = 0] + \frac1{m+1}[m = 0], which is 00 since m+1=1m + 1 = 1 when m=0m = 0. What is left is (n+1m+1)Hn+1−1m+1(n+1m+1)\binom{n+1}{m+1} H_{n+1} - \frac1{m+1}\binom{n+1}{m+1}. □\square

Theorem C1.1.2.7.11 (the step of the proof of Theorem 1.2.7A, TAOCP eq. 1.2.7(10)). Let x≠−1x \ne -1 and Sn=∑k(nk)xkHkS_n = \sum_{k} \binom nk x^k H_k. Then S1=xS_1 = x and Sn+1=(x+1)Sn+(x+1)n+1−1n+1S_{n+1} = (x + 1) S_n + \frac{(x+1)^{n+1} - 1}{n+1} for n≥0n \ge 0, and for n≥1n \ge 1

Sn(x+1)n=Hn−∑k=1n1k(x+1)k.\frac{S_n}{(x+1)^n} = H_n - \sum_{k=1}^{n} \frac1{k(x+1)^k}.

Node: TAYWT10542 · Lean: TAOCP.S1_2_7.eq10, TAOCP.S1_2_7.S_succ · status: proved

Explanation. This is an exact formula for SnS_n. The sum with HkH_k has been turned into HnH_n minus a partial sum of a series. The series is the one of ln⁡(1/(1−z))\ln(1/(1-z)) in Section 1.2.9, at z=1/(x+1)z = 1/(x+1). 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 x=1x = 1 and n=3n = 3. Then S3=(31)H1+(32)H2+(33)H3=3+92+116=283S_3 = \binom31 H_1 + \binom32 H_2 + \binom33 H_3 = 3 + \frac92 + \frac{11}6 = \frac{28}3. The left side is 283⋅8=76\frac{28}{3 \cdot 8} = \frac76. The right side is H3−(12+18+124)=116−23=76H_3 - (\frac12 + \frac18 + \frac1{24}) = \frac{11}6 - \frac23 = \frac76. The recursion gives S3=2S2+23−13S_3 = 2 S_2 + \frac{2^3 - 1}{3}, with S2=2H1+H2=2+32=72S_2 = 2 H_1 + H_2 = 2 + \frac32 = \frac72, so S3=7+73=283S_3 = 7 + \frac73 = \frac{28}3.

Proof. The value S1=(10)⋅0+(11)xH1=xS_1 = \binom10 \cdot 0 + \binom11 x H_1 = x, since H0=0H_0 = 0. For the recursion, use (n+1k)=(nk)+(nk−1)\binom{n+1}k = \binom nk + \binom n{k-1}:

Sn+1=∑k(nk)xkHk+∑k≥1(nk−1)xkHk.S_{n+1} = \sum_k \binom nk x^k H_k + \sum_{k \ge 1} \binom n{k-1} x^k H_k.

The first sum is SnS_n. In the second, replace HkH_k by Hk−1+1kH_{k-1} + \frac1k and put xk=x⋅xk−1x^k = x \cdot x^{k-1}. It splits into x∑k≥1(nk−1)xk−1Hk−1=xSnx \sum_{k \ge 1}\binom n{k-1} x^{k-1} H_{k-1} = x S_n and x∑k≥1(nk−1)xk−1kx\sum_{k \ge 1} \binom n{k-1}\frac{x^{k-1}}{k}. In the last sum use the absorption rule (nk−1)1k=1n+1(n+1k)\binom n{k-1}\frac1k = \frac1{n+1}\binom{n+1}{k}. Then it becomes 1n+1∑k≥1(n+1k)xk=(x+1)n+1−1n+1\frac1{n+1}\sum_{k \ge 1}\binom{n+1}{k} x^k = \frac{(x+1)^{n+1} - 1}{n+1}. Together, Sn+1=(x+1)Sn+(x+1)n+1−1n+1S_{n+1} = (x + 1) S_n + \frac{(x+1)^{n+1} - 1}{n+1}. Divide by (x+1)n+1(x+1)^{n+1}:

Sn+1(x+1)n+1=Sn(x+1)n+1n+1−1(n+1)(x+1)n+1.\frac{S_{n+1}}{(x+1)^{n+1}} = \frac{S_n}{(x+1)^n} + \frac1{n+1} - \frac1{(n+1)(x+1)^{n+1}}.

Let Tn=Sn/(x+1)nT_n = S_n/(x+1)^n. By the last equation, Tk−Tk−1=1k−1k(x+1)kT_k - T_{k-1} = \frac1k - \frac1{k (x+1)^k} for each k≥1k \ge 1. Also T0=S0=H0=0T_0 = S_0 = H_0 = 0, and the case k=1k = 1 agrees with T1=x/(x+1)=1−1x+1T_1 = x/(x+1) = 1 - \frac1{x+1}. Add the differences for k=1,…,nk = 1, \ldots, n to get Tn=Hn−∑k=1n1k(x+1)kT_n = H_n - \sum_{k=1}^{n}\frac1{k(x+1)^k}. □\square

Theorem C1.1.2.7.12 (a sum of binomial terms with HkH_k, TAOCP Theorem 1.2.7A). Let x>0x > 0 and n≥1n \ge 1. Then

∑k=1n(nk)xkHk=(x+1)n(Hn−ln⁡(1+1x))+ϵ,0<ϵ<1x(n+1).\sum_{k=1}^{n} \binom nk x^k H_k = (x+1)^n \Bigl(H_n - \ln\Bigl(1 + \frac1x\Bigr)\Bigr) + \epsilon, \qquad 0 < \epsilon < \frac1{x(n+1)}.

Node: TA179D7MH2 · Lean: TAOCP.S1_2_7.theoremA · status: not stated yet

Explanation. For large nn and fixed xx, the sum is (x+1)n(x+1)^n times Hn−ln⁡(1+1/x)H_n - \ln(1 + 1/x), and the error is small compared with this: it is bounded by 1/(x(n+1))1/(x(n+1)), which is a bound that does not grow with nn, while the main term grows like (x+1)nln⁡n(x+1)^n \ln n. So Sn/(x+1)n=Hn−ln⁡(1+1/x)+o(1)S_n / (x+1)^n = H_n - \ln(1 + 1/x) + o(1). The case x=1x = 1 gives ∑k(nk)Hk≈2n(Hn−ln⁡2)\sum_k \binom nk H_k \approx 2^n (H_n - \ln 2). The condition x>0x > 0 is needed: the proof uses a convergent series with positive terms. For x=−1x = -1 the logarithm ln⁡(1+1/x)\ln(1 + 1/x) is not defined, and exercise 1.2.7-9 asks for the exact value of the sum in that case.

Example. Take x=1x = 1 and n=10n = 10. The exact sum is S10=721213315=2289.56508S_{10} = \frac{721213}{315} = 2289.56508. The main term is 210(H10−ln⁡2)=1024⋅(2.928968−0.693147)=2289.480782^{10}(H_{10} - \ln 2) = 1024 \cdot (2.928968 - 0.693147) = 2289.48078. So ϵ=0.08430\epsilon = 0.08430, and the bound is 11⋅11=0.0909\frac1{1 \cdot 11} = 0.0909. Another case: x=2x = 2 and n=5n = 5 gives S5=22825=456.4S_5 = \frac{2282}5 = 456.4, the main term 35(H5−ln⁡32)=456.32203^5(H_5 - \ln\frac32) = 456.3220, ϵ=0.0780\epsilon = 0.0780, and the bound is 12⋅6=0.0833\frac1{2 \cdot 6} = 0.0833.

Proof. By eq. 1.2.7(10), Sn=(x+1)n(Hn−∑k=1n1k(x+1)k)S_n = (x+1)^n(H_n - \sum_{k=1}^{n} \frac1{k(x+1)^k}). Let y=1/(x+1)y = 1/(x+1), so 0<y<10 < y < 1. The series ∑k≥1yk/k\sum_{k \ge 1} y^k/k converges to −ln⁡(1−y)-\ln(1 - y) (Section 1.2.9, eq. 1.2.9(17)). Since 1−y=x/(x+1)1 - y = x/(x+1), −ln⁡(1−y)=ln⁡x+1x=ln⁡(1+1/x)-\ln(1 - y) = \ln\frac{x+1}x = \ln(1 + 1/x). So

∑k=1nykk=ln⁡(1+1x)−∑k>nykk.\sum_{k=1}^{n}\frac{y^k}k = \ln\Bigl(1 + \frac1x\Bigr) - \sum_{k > n}\frac{y^k}k.

Let δn=∑k>nyk/k\delta_n = \sum_{k > n} y^k/k. It is positive. For k>nk > n, 1k≤1n+1\frac1k \le \frac1{n+1}, so δn<1n+1∑k≥n+1yk=yn+1(n+1)(1−y)\delta_n < \frac1{n+1} \sum_{k \ge n+1} y^k = \frac{y^{n+1}}{(n+1)(1 - y)}. With y/(1−y)=1/xy/(1-y) = 1/x this is yn(n+1)x\frac{y^n}{(n+1)x}. Hence Sn=(x+1)n(Hn−ln⁡(1+1/x)+δn)S_n = (x+1)^n(H_n - \ln(1 + 1/x) + \delta_n), and ϵ=(x+1)nδn\epsilon = (x+1)^n \delta_n satisfies 0<ϵ<(x+1)nyn(n+1)x=1x(n+1)0 < \epsilon < (x+1)^n \frac{y^n}{(n+1) x} = \frac1{x(n+1)}. □\square

Algorithms and programs

Section 1.2.7 has no algorithm and no program. The only computation in it is the exact evaluation of HnH_n 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 HnH_n. 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 HnH_n. 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 HnH_n 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 nn. 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 HnH_n to noninteger nn and give the product for 1/Γ(x)1/\Gamma(x).

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 rr, the zeta function and the bound of the theorem for r>1r > 1 are stated for a natural r≥2r \ge 2 only. Eq. (7) has the values of ζ(2)\zeta(2) and ζ(4)\zeta(4) 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 Hn(r)H_n^{(r)} for a natural rr 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 : ℕ → ℚ, with harmonic_zero, harmonic_succ, harmonic_eq_sum_Icc and harmonic_pos. Mathlib also has the bounds log_add_one_le_harmonic and harmonic_le_one_add_log, which are weaker than eq. 1.2.7(3).
  • Euler's constant: Real.eulerMascheroniConstant, with Real.tendsto_harmonic_sub_log. The asymptotic series of eq. 1.2.7(3) is not in Mathlib. The statement will use Asymptotics and a remainder with an explicit bound.
  • The zeta function and the Bernoulli numbers: riemannZeta, bernoulli, riemannZeta_two, riemannZeta_four and riemannZeta_two_mul_nat. Mathlib's bernoulli follows the convention B1=−12B_1 = -\frac12, 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 H∞(r)H_\infty^{(r)} for natural rr is the real number (riemannZeta r).re, or the sum ∑' k, 1 / (k + 1) ^ r.
  • The binomial coefficient: Nat.choose, with Nat.choose_succ_succ' for the rule of Pascal and Nat.add_one_mul_choose_eq for absorption.

Eq. 1.2.7(8) and (9) are identities of rational numbers and can be proved in Lean by induction on nn, 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 ϵ\epsilon 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 2m2^m 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 ζ(2)=π2/6\zeta(2) = \pi^2/6 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 HnH_n 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 1p+⋯+np1^p + \cdots + n^p. 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 HH for the numbers is the choice of the book. Mathlib uses harmonic.

The numerator of Hp−1H_{p-1} is divisible by pp for an odd prime pp (exercise 1.2.7-17). This is the theorem of E. Waring of 1782, and J. Wolstenholme proved in 1862 that for p≥5p \ge 5 the numerator is divisible by p2p^2. The number HnH_n is an integer only for n=0n = 0 and n=1n = 1 (exercise 1.2.7-19). L. Theisinger proved in 1915 that HnH_n is not an integer for n≥2n \ge 2, and J. Kürschák proved in 1918 that no sum 1m+1m+1+⋯+1n\frac1m + \frac1{m+1} + \cdots + \frac1n with n>m≥1n > m \ge 1 is an integer. Mathlib has the first result as harmonic_not_int. The function ψ(x+1)+γ\psi(x + 1) + \gamma extends HxH_x to non-integers xx (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 ln⁡(1/(1−z))\ln(1/(1-z)) 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 Hn=1+1/2+⋯+1/nH_n = 1 + 1/2 + \cdots + 1/n. The sum appears in the analysis of algorithms almost every time a quantity is averaged over nn equally likely cases. The section shows how large HnH_n is, how its relatives Hn(r)H_n^{(r)} behave, and how to add sums in which HkH_k 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.