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.11.1

The O-notation

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.11.1 of the book. The nodes and the exercises of the section.

Contents
  1. The O-notation

The O-notation

Overview

Section 1.2.11.1 of TAOCP introduces the symbol O(f(n))O(f(n)). It stands for an unnamed quantity whose size is at most a fixed multiple of ∣f(n)∣|f(n)| once nn is large. With it, an approximation carries its own error bound: the formula Hn=ln⁡n+γ+O(1/n)H_n = \ln n + \gamma + O(1/n) replaces the sign ≈\approx by the sign == and says how good the approximation is. The section fixes the meaning of the symbol and states the rules for sums, products and nested uses. It uses OO for functions of a complex variable zz near 00 and lists the main power series with their error terms. It shows that an asymptotic formula can be right even when the series behind it diverges (the factorial powers nr‾n^{\overline{r}} and nr‾n^{\underline{r}} for real rr, expanded in powers of nn). A worked case, the quantity n(nn−1)n(\sqrt[n]{n} - 1), ties the rules together. The section ends with the symbols Ω\Omega and Θ\Theta.

The ideas

OO names a set of functions. The symbol O(f(n))O(f(n)) is the set of all functions gg with ∣g(n)∣≤M∣f(n)∣|g(n)| \le M|f(n)| for some constant MM and all n≥n0n \ge n_0. An equation A=BA = B says A⊆BA \subseteq B. This is why the equation is a one-way equation: 12n2+n=O(n2)\frac12 n^2 + n = O(n^2) is true and O(n2)=12n2+nO(n^2) = \frac12 n^2 + n is false.

The constants are hidden, and they are fixed. The constants MM and n0n_0 may differ at each use of the symbol. They may not depend on nn. This is the source of most errors. A sum of nn terms that are each O(n)O(n) is not O(n2)O(n^2) by this argument, since the constants of the nn terms need not stay bounded (exercise 1.2.11.1-6).

The rules are the rules of set algebra. Eqs. (5) to (10) say that a function lies in its own set, that constants, sums, products and nested sets stay in the set. Each proof takes one line.

A convergent power series gives its error term free. If ∑akzk\sum a_k z^k converges at one point z0≠0z_0 \ne 0, then the tail after zmz^m is O(zm+1)O(z^{m+1}) near 00 (eqs. (11) to (15)).

An asymptotic series need not converge. For real rr the factorial powers nr‾n^{\overline{r}} and nr‾n^{\underline{r}} have expansions in powers of nn, with Stirling numbers of a real argument as coefficients. Each truncation is correct with an error of the next order, yet the full series can diverge, for example for r=1/2r = 1/2. The notation OO speaks of one truncation at a time, so it fits.

Ω\Omega and Θ\Theta close the gap. People read g=O(f)g = O(f) as "gg has the order of ff", but gg may be much smaller. Ω(f)\Omega(f) is the lower bound, and Θ(f)\Theta(f) gives both bounds.

C1 follows the order of the section. It proves each of the 21 equations and the two definitions. It adds the small facts that the proofs need: a polynomial is OO of its top power, the Stirling numbers have polynomial extensions, and the ratio of two gamma values has an expansion in powers of 1/x1/x. Each result has a number check.

Definitions, results and proofs

Definition C1.1.2.11.1.1 (the symbol O(f(n))O(f(n)), TAOCP Section 1.2.11.1). Let ff be a real or complex function on the positive integers. A function gg belongs to the set O(f(n))O(f(n)) when two positive numbers MM and n0n_0 exist such that

∣g(n)∣≤M ∣f(n)∣whenever n≥n0.|g(n)| \le M\,|f(n)| \qquad \text{whenever } n \ge n_0.

A formula that contains OO symbols and ordinary functions stands for a set of functions, formed by the operations of the formula (see the next definition). An equation A=BA = B between two such formulas means that each function of the set AA is also in the set BB. If AA is one ordinary function a(n)a(n), then a(n)=Ba(n) = B means a∈Ba \in B.

Node: TAEGH4HAH4 · Lean: TAOCP.BigOWith · status: not stated yet

Explanation. The definition has three parts. The constant n0n_0 says that the bound is about large nn only, so the first few values of gg do not matter. The constant MM says that the ratio ∣g∣/∣f∣|g|/|f| stays below a number. The formula ln⁡n+γ+O(1/n)\ln n + \gamma + O(1/n) is the set of all functions ln⁡n+γ+u(n)\ln n + \gamma + u(n) with u∈O(1/n)u \in O(1/n). The sign == is read as ⊆\subseteq, since the symbol hides a different function at each use. Both sides of O(n)=O(n2)O(n) = O(n^2) are sets, and the left set is inside the right set. The sets are not equal, so the reverse equation is false. The convention keeps the familiar chain a=b+O(f)=c+O(g)a = b + O(f) = c + O(g) from left to right, and each step is true by itself.

In Lean the definition is TAOCP.BigOWith M n₀ f g, which says ∣f(n)∣≤M∣g(n)∣|f(n)| \le M|g(n)| for n≥n0n \ge n_0, with the constants written out. The bridge TAOCP.BigOWith.isBigO gives the statement f =O[atTop] g of Mathlib.

Example. Let g(n)=3n+5g(n) = 3n + 5 and f(n)=nf(n) = n. For n≥5n \ge 5 it holds that 5≤n5 \le n, so ∣g(n)∣=3n+5≤4n|g(n)| = 3n + 5 \le 4n. Hence g∈O(n)g \in O(n) with M=4M = 4 and n0=5n_0 = 5. The constants are not unique: M=8M = 8 and n0=1n_0 = 1 also work, since 3n+5≤8n3n + 5 \le 8n for n≥1n \ge 1. Each M>3M > 3 works with a large enough n0n_0, but M=3M = 3 fails for every n0n_0, since 3n+5>3n3n + 5 > 3n. So the good constants are the numbers above the limit 33 of ∣g(n)/f(n)∣|g(n)/f(n)|, and the limit itself is not one of them. For n0=1n_0 = 1 the smallest MM is 88, the value at n=1n = 1. A function that is not in O(n)O(n) is nln⁡nn \ln n: for each MM the bound nln⁡n≤Mnn \ln n \le M n fails when ln⁡n>M\ln n > M.

Proof that the definition is consistent. A formula is built from sets by sums, products and similar operations, so each formula is a set. The sign == between two formulas is then the relation ⊆\subseteq, which is reflexive and transitive. So a chain A=B=CA = B = C gives A⊆CA \subseteq C, which is the statement that one expects from a chain. If AA has no OO symbol, then AA is a set with one element, and A=BA = B is the membership of this element. □\square

Definition C1.1.2.11.1.2 (operations on sets of functions, TAOCP Section 1.2.11.1). Let SS and TT be sets of functions of nn, and let cc be a constant and a(n)a(n) a function. A single function aa stands for the set {a}\{a\}, and S−TS - T, ln⁡S\ln S, eSe^S and every other operation are formed in the same way. Then

S+T={g+h:g∈S, h∈T},S⋅T={g h:g∈S, h∈T},S + T = \{g + h : g \in S,\ h \in T\}, \qquad S \cdot T = \{g\,h : g \in S,\ h \in T\},

c+S={c+g:g∈S},a⋅S={a g:g∈S}.c + S = \{c + g : g \in S\}, \qquad a \cdot S = \{a\,g : g \in S\}.

Node: none

Explanation. This is the dictionary that turns a formula with OO into a set. The formula a(n)+O(f(n))a(n) + O(f(n)) means {a}+O(f)\{a\} + O(f), the set of all a+ua + u with u∈O(f)u \in O(f). The formula O(f) O(g)O(f)\,O(g) is the set of all products u vu\,v with u∈O(f)u \in O(f) and v∈O(g)v \in O(g).

Example. Let S=O(n)S = O(n) and T=O(n2)T = O(n^2). The function 2n2n is in SS and n2−7n^2 - 7 is in TT. So the function n2+2n−7n^2 + 2n - 7 is in S+TS + T, and (2n)(n2−7)=2n3−14n(2n)(n^2 - 7) = 2n^3 - 14n is in S⋅TS \cdot T.

Theorem C1.1.2.11.1.3 (the harmonic numbers, TAOCP eq. 1.2.11.1(1)). Let γ=lim⁡n→∞(Hn−ln⁡n)\gamma = \lim_{n \to \infty} (H_n - \ln n) be the constant of Euler. Then for all n≥1n \ge 1

0<Hn−ln⁡n−γ<1n,soHn=ln⁡n+γ+O ⁣(1n).0 < H_n - \ln n - \gamma < \frac{1}{n}, \qquad\text{so}\qquad H_n = \ln n + \gamma + O\!\left(\frac{1}{n}\right).

Node: TAHEVEXMDH · Lean: TAOCP.S1_2_11.eq1 (partial) · status: not stated yet

Explanation. The sum Hn=1+1/2+⋯+1/nH_n = 1 + 1/2 + \cdots + 1/n grows like ln⁡n\ln n, and the difference tends to a constant. The statement says how fast the difference approaches its limit: the error is positive and it is less than 1/n1/n. The true size of the error is close to 1/(2n)1/(2n), but the bound with 1/n1/n is easy to prove and it is enough for the form O(1/n)O(1/n) with M=1M = 1 and n0=1n_0 = 1.

Example. The next table has HnH_n from Section 1.2.7 and the error en=Hn−ln⁡n−γe_n = H_n - \ln n - \gamma with γ=0.5772156649\gamma = 0.5772156649.

nn HnH_n ln⁡n+γ\ln n + \gamma ene_n n enn\,e_n
1 1 0.5772157 0.4227843 0.4228
5 2.2833333 2.1866536 0.0966798 0.4834
10 2.9289683 2.8798008 0.0491675 0.4917
1000 7.4854709 7.4849709 0.0004999 0.4999

The product n enn\,e_n stays below 11, as the theorem says, and it tends to 1/21/2.

Proof. Let dn=Hn−ln⁡nd_n = H_n - \ln n. Then dn−dn+1=ln⁡(1+1/n)−1/(n+1)d_n - d_{n+1} = \ln(1 + 1/n) - 1/(n+1). Two facts about the logarithm are used. First, ln⁡(1+x)≤x\ln(1 + x) \le x for x>−1x > -1, so ln⁡(1+1/n)≤1/n\ln(1 + 1/n) \le 1/n. Second, ln⁡(1+1/n)=∫nn+1dt/t>1/(n+1)\ln(1 + 1/n) = \int_n^{n+1} dt/t > 1/(n+1), since the integrand is larger than 1/(n+1)1/(n+1) on the interval. So

0<dn−dn+1≤1n−1n+1=1n(n+1).0 < d_n - d_{n+1} \le \frac{1}{n} - \frac{1}{n+1} = \frac{1}{n(n+1)}.

The sequence dnd_n decreases, and it is bounded below, since the sum of the differences from nn to N−1N - 1 is at most ∑k=nN−11/(k(k+1))=1/n−1/N<1/n\sum_{k=n}^{N-1} 1/(k(k+1)) = 1/n - 1/N < 1/n. So dnd_n has a limit γ\gamma, and dn−γ=∑k≥n(dk−dk+1)d_n - \gamma = \sum_{k \ge n} (d_k - d_{k+1}). This sum has positive terms, so it is positive, and it is at most ∑k≥n1/(k(k+1))=1/n\sum_{k \ge n} 1/(k(k+1)) = 1/n. The inequality is strict because the first inequality ln⁡(1+x)≤x\ln(1+x) \le x is strict for x≠0x \ne 0. □\square

Theorem C1.1.2.11.1.4 (a polynomial is OO of its top power, TAOCP Section 1.2.11.1). If P(n)=a0+a1n+⋯+amnmP(n) = a_0 + a_1 n + \cdots + a_m n^m is a polynomial of degree at most mm, then P(n)=O(nm)P(n) = O(n^m). In detail, ∣P(n)∣≤(∣a0∣+⋯+∣am∣) nm|P(n)| \le (|a_0| + \cdots + |a_m|)\, n^m for all n≥1n \ge 1.

Node: none · Lean: TAOCP.S1_2_11.poly_isBigO

Explanation. The top power of nn dominates all lower powers, once n≥1n \ge 1. The constant MM is the sum of the sizes of the coefficients, and n0=1n_0 = 1.

Example. Take P(n)=4−7n+3n2P(n) = 4 - 7n + 3n^2 and m=2m = 2. Then M=4+7+3=14M = 4 + 7 + 3 = 14. At n=3n = 3 it holds that P(3)=4−21+27=10P(3) = 4 - 21 + 27 = 10, and the bound is 14⋅9=12614 \cdot 9 = 126. The bound is far from tight, but it holds.

Proof. For n≥1n \ge 1 and 0≤k≤m0 \le k \le m it holds that nk≤nmn^k \le n^m. So ∣P(n)∣≤∑k∣ak∣nk≤∑k∣ak∣nm|P(n)| \le \sum_k |a_k| n^k \le \sum_k |a_k| n^m. □\square

Example C1.1.2.11.1.5 (a true bound that is weak, TAOCP eq. 1.2.11.1(2)). For the sum of squares,

12+22+⋯+n2=O(n4).1^2 + 2^2 + \cdots + n^2 = O(n^4).

Node: TA543H17GK · Lean: TAOCP.S1_2_11.eq2 · status: not stated yet

Explanation. The sum of squares is S(n)=13n(n+12)(n+1)=13n3+12n2+16nS(n) = \frac13 n (n + \frac12)(n + 1) = \frac13 n^3 + \frac12 n^2 + \frac16 n (Section 1.2.3). It is a polynomial of degree 33, so it is O(n3)O(n^3) by Theorem C1.1.2.11.1.4, and it is also O(n4)O(n^4), since n3≤n4n^3 \le n^4. The statement is true, but it is weak: it gives an upper bound that is larger than the truth by a factor of nn. An OO bound never says that the bound is close to the truth.

Example. For n=10n = 10 the sum is 385385 and n4=10000n^4 = 10000. For n=100n = 100 the sum is 338350338350 and n4=108n^4 = 10^8. The ratio S(n)/n4S(n)/n^4 is 0.03850.0385 and 0.00340.0034 at these two points and it tends to 00. So the constant M=1M = 1 is far larger than needed for large nn.

Proof. By Theorem C1.1.2.11.1.4 with m=4m = 4 and the coefficients 0,1/6,1/2,1/3,00, 1/6, 1/2, 1/3, 0, it holds that S(n)≤(1/6+1/2+1/3)n4=n4S(n) \le (1/6 + 1/2 + 1/3) n^4 = n^4 for n≥1n \ge 1. So M=1M = 1 and n0=1n_0 = 1. □\square

Example C1.1.2.11.1.6 (a stronger bound, TAOCP eq. 1.2.11.1(3)). For the same sum,

12+22+⋯+n2=O(n3).1^2 + 2^2 + \cdots + n^2 = O(n^3).

Node: TA5DHAEJHJ · Lean: TAOCP.S1_2_11.eq3 · status: not stated yet

Explanation. This is the sharp order of growth. The sum is a polynomial of degree 33, so the exponent 33 cannot be lowered.

Example. At n=10n = 10 the ratio S(n)/n3S(n)/n^3 is 0.3850.385. At n=100n = 100 it is 0.338350.33835. It tends to 1/31/3. A constant that works is M=1M = 1, and it is tight at n=1n = 1 where S(1)=1=13S(1) = 1 = 1^3.

Proof. The proof needs 13(n+12)(n+1)≤n2\frac13(n + \frac12)(n+1) \le n^2 for n≥1n \ge 1. The left side is 13n2+12n+16\frac13 n^2 + \frac12 n + \frac16, and n2−(13n2+12n+16)=23n2−12n−16=16(4n2−3n−1)=16(4n+1)(n−1)≥0n^2 - (\frac13 n^2 + \frac12 n + \frac16) = \frac23 n^2 - \frac12 n - \frac16 = \frac16(4n^2 - 3n - 1) = \frac16(4n+1)(n-1) \ge 0 for n≥1n \ge 1. Hence S(n)≤n3S(n) \le n^3 with M=1M = 1 and n0=1n_0 = 1. □\square

Example C1.1.2.11.1.7 (the leading term and an error, TAOCP eq. 1.2.11.1(4)). For the same sum,

12+22+⋯+n2=13n3+O(n2).1^2 + 2^2 + \cdots + n^2 = \frac13 n^3 + O(n^2).

Node: TAM5S69K8G · Lean: TAOCP.S1_2_11.eq4 · status: not stated yet

Explanation. This is the strongest of the three statements. It gives the main term 13n3\frac13 n^3 exactly and bounds the rest. The rest is 12n2+16n\frac12 n^2 + \frac16 n, which is O(n2)O(n^2) by Theorem C1.1.2.11.1.4.

Example. At n=10n = 10 the difference S(n)−n3/3S(n) - n^3/3 is 385−333.33=51.67385 - 333.33 = 51.67, and n2=100n^2 = 100, so the ratio is 0.51670.5167. At n=100n = 100 the ratio is 5016.67/10000=0.50175016.67/10000 = 0.5017. It tends to 1/21/2, so the best constant for large nn is a little over 1/21/2.

Proof. It holds that S(n)−13n3=12n2+16n≤(12+16)n2=23n2S(n) - \frac13 n^3 = \frac12 n^2 + \frac16 n \le (\frac12 + \frac16) n^2 = \frac23 n^2 for n≥1n \ge 1. So M=2/3M = 2/3 and n0=1n_0 = 1. □\square

Theorem C1.1.2.11.1.8 (a function is OO of itself, TAOCP eq. 1.2.11.1(5)). For each function ff,

f(n)=O(f(n)).f(n) = O(f(n)).

Node: TAPPCTBPSY · Lean: TAOCP.S1_2_11.eq5 · status: not stated yet

Explanation. This is the equation that lets a plain function enter a formula with OO.

Example. Let f(n)=n2−3f(n) = n^2 - 3. Then ∣f(n)∣≤1⋅∣f(n)∣|f(n)| \le 1 \cdot |f(n)| for all nn. So M=1M = 1 and n0=1n_0 = 1, and the bound is an equality.

Proof. The bound ∣f(n)∣≤1⋅∣f(n)∣|f(n)| \le 1 \cdot |f(n)| is true for each nn. □\square

Theorem C1.1.2.11.1.9 (a constant factor, TAOCP eq. 1.2.11.1(6)). If cc is a constant, then

c⋅O(f(n))=O(f(n)).c \cdot O(f(n)) = O(f(n)).

Node: TASP3P3WPA · Lean: TAOCP.S1_2_11.eq6 · status: not stated yet

Explanation. A constant factor is absorbed into the hidden constant MM. The statement holds also for c=0c = 0. For c≠0c \ne 0 the reverse inclusion is true too, since g=c⋅(g/c)g = c \cdot (g/c).

Example. Let u(n)=2n+1u(n) = 2n + 1, which lies in O(n)O(n) with M=3M = 3 and n0=1n_0 = 1. Then −5u(n)=−10n−5-5u(n) = -10n - 5 has ∣−10n−5∣≤15n|{-10n - 5}| \le 15 n. So it lies in O(n)O(n) with M=15M = 15.

Proof. Let g∈O(f)g \in O(f) with constants MM and n0n_0. Then ∣c g(n)∣=∣c∣ ∣g(n)∣≤∣c∣ M ∣f(n)∣|c\,g(n)| = |c|\,|g(n)| \le |c|\,M\,|f(n)| for n≥n0n \ge n_0. The constant ∣c∣M|c| M is positive if c≠0c \ne 0 (use any positive constant if c=0c = 0). So c g∈O(f)c\,g \in O(f). □\square

Theorem C1.1.2.11.1.10 (the sum of two terms of the same order, TAOCP eq. 1.2.11.1(7)).

O(f(n))+O(f(n))=O(f(n)).O(f(n)) + O(f(n)) = O(f(n)).

Node: TAZEJMRFX0 · Lean: TAOCP.S1_2_11.eq7 · status: not stated yet

Explanation. The two hidden functions may differ and they have different constants. The sum has the larger n0n_0 and the sum of the two constants MM.

Example. Let u(n)=3n−2u(n) = 3n - 2 and v(n)=−7n+4v(n) = -7n + 4, both in O(n)O(n). The first has ∣3n−2∣≤3n+2≤5n|3n - 2| \le 3n + 2 \le 5n, so Mu=5M_u = 5. The second has ∣−7n+4∣≤7n+4≤11n|-7n + 4| \le 7n + 4 \le 11n, so Mv=11M_v = 11. The sum is −4n+2-4n + 2, and ∣−4n+2∣≤4n+2≤6n|-4n + 2| \le 4n + 2 \le 6n for n≥1n \ge 1. So the sum lies in O(n)O(n) with M=6M = 6. The proof below gives the larger constant Mu+Mv=16M_u + M_v = 16, which is valid but not the best.

Proof. Let uu have the constants (M1,n1)(M_1, n_1) and vv the constants (M2,n2)(M_2, n_2). For n≥max⁡(n1,n2)n \ge \max(n_1, n_2) it holds that ∣u+v∣≤∣u∣+∣v∣≤(M1+M2)∣f∣|u + v| \le |u| + |v| \le (M_1 + M_2)|f|. □\square

Theorem C1.1.2.11.1.11 (an OO of an OO, TAOCP eq. 1.2.11.1(8)).

O(O(f(n)))=O(f(n)).O(O(f(n))) = O(f(n)).

Node: TAQD01BT8E · Lean: TAOCP.S1_2_11.eq8 · status: not stated yet

Explanation. The left side is the set of all gg for which some h∈O(f)h \in O(f) has g∈O(h)g \in O(h). A chain of two bounds is a bound by the product of the two constants.

Example. Let h(n)=2n2+1h(n) = 2n^2 + 1, which lies in O(n2)O(n^2) with M=3M = 3 and n0=1n_0 = 1. Let g(n)=5(−1)n(2n2+1)g(n) = 5(-1)^n(2n^2 + 1). Then ∣g∣=5∣h∣|g| = 5|h|, so g∈O(h)g \in O(h) with M=5M = 5. Also ∣h∣≤3n2|h| \le 3n^2, so ∣g∣≤15n2|g| \le 15 n^2, and g∈O(n2)g \in O(n^2) with the product of the constants, 5⋅3=155 \cdot 3 = 15.

Proof. Let h∈O(f)h \in O(f) with the constants (M1,n1)(M_1, n_1), and let g∈O(h)g \in O(h) with the constants (M2,n2)(M_2, n_2). For n≥max⁡(n1,n2)n \ge \max(n_1, n_2) it holds that ∣g(n)∣≤M2∣h(n)∣≤M2M1∣f(n)∣|g(n)| \le M_2 |h(n)| \le M_2 M_1 |f(n)|. So g∈O(f)g \in O(f). □\square

Theorem C1.1.2.11.1.12 (a product, TAOCP eq. 1.2.11.1(9)).

O(f(n)) O(g(n))=O(f(n) g(n)).O(f(n))\,O(g(n)) = O(f(n)\,g(n)).

Node: TAEMBJPWG8 · Lean: TAOCP.S1_2_11.eq9 · status: not stated yet

Explanation. The product of two bounded errors is bounded by the product of the bounds. This is the tool for the product of two formulas with errors.

Example. Let u(n)=3n+1∈O(n)u(n) = 3n + 1 \in O(n) with M=4M = 4 and n0=1n_0 = 1, and let v(n)=2n2−5∈O(n2)v(n) = 2n^2 - 5 \in O(n^2) with M=7M = 7 and n0=1n_0 = 1. The product uv=6n3+2n2−15n−5uv = 6n^3 + 2n^2 - 15n - 5 satisfies ∣uv∣≤28n3|uv| \le 28 n^3. At n=2n = 2: uv=7⋅3=21uv = 7 \cdot 3 = 21 and 28⋅8=22428 \cdot 8 = 224.

Proof. Let u∈O(f)u \in O(f) with (M1,n1)(M_1, n_1) and v∈O(g)v \in O(g) with (M2,n2)(M_2, n_2). For n≥max⁡(n1,n2)n \ge \max(n_1, n_2) it holds that ∣uv∣=∣u∣∣v∣≤M1∣f∣ M2∣g∣=M1M2∣fg∣|uv| = |u||v| \le M_1 |f| \, M_2 |g| = M_1 M_2 |fg|. □\square

Theorem C1.1.2.11.1.13 (a factor comes out, TAOCP eq. 1.2.11.1(10)).

O(f(n) g(n))=f(n) O(g(n)).O(f(n)\,g(n)) = f(n)\,O(g(n)).

Node: TAXVEXFG67 · Lean: TAOCP.S1_2_11.eq10, TAOCP.S1_2_11.eq10_rev · status: not stated yet

Explanation. Here f(n)f(n) is a fixed function, not an OO symbol, and both inclusions hold. The proof needs a convention for the places where f(n)=0f(n) = 0: there every element of the left set is 00 for n≥n0n \ge n_0.

Example. Let f(n)=nf(n) = n and g(n)=ln⁡ng(n) = \ln n. A function in O(nln⁡n)O(n \ln n) is h(n)=2nln⁡n+nh(n) = 2n \ln n + n for n≥3n \ge 3 (since ln⁡n≥1\ln n \ge 1 then, ∣h∣≤3nln⁡n|h| \le 3 n \ln n). Write h=n⋅uh = n \cdot u with u(n)=2ln⁡n+1u(n) = 2 \ln n + 1, and ∣u∣≤3ln⁡n|u| \le 3 \ln n. So u∈O(ln⁡n)u \in O(\ln n), and h∈n⋅O(ln⁡n)h \in n \cdot O(\ln n). In the other direction n⋅(ln⁡n⋅(−1)n)n \cdot (\ln n \cdot (-1)^n) lies in O(nln⁡n)O(n \ln n) with M=1M = 1.

Proof. The inclusion from right to left: let u∈O(g)u \in O(g) with (M,n0)(M, n_0). For n≥n0n \ge n_0, ∣f(n)u(n)∣≤M∣f(n)g(n)∣|f(n)u(n)| \le M |f(n) g(n)|. So fu∈O(fg)fu \in O(fg). The inclusion from left to right: let h∈O(fg)h \in O(fg) with (M,n0)(M, n_0). Define u(n)=h(n)/f(n)u(n) = h(n)/f(n) if f(n)≠0f(n) \ne 0 and u(n)=0u(n) = 0 if f(n)=0f(n) = 0. For n≥n0n \ge n_0, if f(n)≠0f(n) \ne 0 then ∣u(n)∣=∣h(n)∣/∣f(n)∣≤M∣g(n)∣|u(n)| = |h(n)|/|f(n)| \le M|g(n)|. If f(n)=0f(n) = 0 then ∣h(n)∣≤M⋅0=0|h(n)| \le M \cdot 0 = 0, so h(n)=0=f(n)u(n)h(n) = 0 = f(n) u(n), and ∣u(n)∣=0≤M∣g(n)∣|u(n)| = 0 \le M|g(n)|. So u∈O(g)u \in O(g) and h=fu∈f⋅O(g)h = fu \in f \cdot O(g). □\square

Definition C1.1.2.11.1.14 (the symbol OO for a complex variable near zero, TAOCP Section 1.2.11.1). Let ff be a function of a complex variable zz. Sums, products and equations with the symbol O(f(z))O(f(z)) are read as in Definition C1.1.2.11.1.1. Here a function gg belongs to O(f(z))O(f(z)) when two positive numbers MM and rr exist such that

∣g(z)∣≤M ∣f(z)∣whenever ∣z∣<r.|g(z)| \le M\,|f(z)| \qquad \text{whenever } |z| < r.

Node: none

Explanation. This is the same idea with a different limit. Now zz goes to 00, and the bound holds inside a disc of radius rr. All the rules of eqs. (5) to (10) hold in the same form, with the same proofs: replace "n≥n0n \ge n_0" by "∣z∣<r|z| < r" and take the smaller of two radii where a proof takes the larger of two n0n_0. A third form, with x→∞x \to \infty over the real numbers, is used in Lemma C1.1.2.11.1.21.

Example. The function sin⁡z\sin z is in O(z)O(z). For ∣z∣<1|z| < 1 the series z−z3/3!+z5/5!−⋯z - z^3/3! + z^5/5! - \cdots gives ∣sin⁡z∣≤∣z∣∑k≥01/(2k+1)!=∣z∣sinh⁡1<1.18 ∣z∣|\sin z| \le |z| \sum_{k \ge 0} 1/(2k+1)! = |z| \sinh 1 < 1.18\,|z|. So M=1.18M = 1.18 and r=1r = 1 work.

Theorem C1.1.2.11.1.15 (a convergent power series, TAOCP eq. 1.2.11.1(11)). Let g(z)=∑k≥0akzkg(z) = \sum_{k \ge 0} a_k z^k be a power series that converges at one point z0≠0z_0 \ne 0. Then for each integer m≥0m \ge 0

g(z)=a0+a1z+⋯+amzm+O(zm+1).g(z) = a_0 + a_1 z + \cdots + a_m z^m + O(z^{m+1}).

Node: TAXX69HR0S · Lean: TAOCP.S1_2_11.eq11 · status: not stated yet

Explanation. The tail of the series is small. Convergence at one point z0z_0 makes the terms akz0ka_k z_0^k bounded, and the bound controls the tail inside the disc of radius ∣z0∣/2|z_0|/2. If the series converges at a point far from 00, then rr can be large.

Example. Take g(z)=ezg(z) = e^z, m=2m = 2 and z0=1z_0 = 1. Then akz0k=1/k!≤1=Ba_k z_0^k = 1/k! \le 1 = B. The proof below gives M=2B/∣z0∣3=2M = 2B/|z_0|^3 = 2 and r=1/2r = 1/2. At z=0.1z = 0.1: e0.1=1.10517092e^{0.1} = 1.10517092, the partial sum 1+0.1+0.0051 + 0.1 + 0.005 is 1.1051.105, the tail is 0.000170920.00017092, and the bound is 2⋅0.13=0.0022 \cdot 0.1^3 = 0.002.

Proof. The terms akz0ka_k z_0^k of a convergent series tend to 00, so there is a number BB with ∣akz0k∣≤B|a_k z_0^k| \le B for all kk. Let ∣z∣≤∣z0∣/2|z| \le |z_0|/2 and put q=∣z/z0∣≤1/2q = |z/z_0| \le 1/2. Then

∣∑k>makzk∣≤∑k>m∣akz0k∣ qk≤B∑k>mqk=B qm+11−q≤2B qm+1=2B∣z0∣m+1 ∣z∣m+1.\left|\sum_{k > m} a_k z^k\right| \le \sum_{k > m} |a_k z_0^k|\, q^k \le B \sum_{k > m} q^k = \frac{B\, q^{m+1}}{1 - q} \le 2B\, q^{m+1} = \frac{2B}{|z_0|^{m+1}}\, |z|^{m+1}.

(The sum ∑k≥0akzk\sum_{k \ge 0} a_k z^k converges at zz, since the comparison with the geometric series shows that it converges absolutely.) So the tail is in O(zm+1)O(z^{m+1}) with M=2B/∣z0∣m+1M = 2B/|z_0|^{m+1} and r=∣z0∣/2r = |z_0|/2. □\square

Theorem C1.1.2.11.1.16 (the exponential, TAOCP eq. 1.2.11.1(12)). For each m≥0m \ge 0,

ez=1+z+z22!+⋯+zmm!+O(zm+1).e^z = 1 + z + \frac{z^2}{2!} + \cdots + \frac{z^m}{m!} + O(z^{m+1}).

Node: TAJ9YJDR17 · Lean: TAOCP.S1_2_11.eq12, TAOCP.S1_2_11.eq12_real · status: not stated yet

Explanation. The exponential series converges for all zz, so Theorem C1.1.2.11.1.15 applies with any z0z_0. For real z≥0z \ge 0 there is a sharper bound: 0≤ez−∑k≤mzk/k!≤zm+1ez/(m+1)!0 \le e^z - \sum_{k \le m} z^k/k! \le z^{m+1} e^z/(m+1)!, since (m+1+j)!≥(m+1)! j!(m+1+j)! \ge (m+1)!\,j!.

Example. Let m=3m = 3 and z=0.1z = 0.1. The partial sum is 1+0.1+0.005+0.000166667=1.1051666671 + 0.1 + 0.005 + 0.000166667 = 1.105166667. The value is e0.1=1.105170918e^{0.1} = 1.105170918. The error is 4.251⋅10−64.251 \cdot 10^{-6}, and the next term of the series z4/24=4.167⋅10−6z^4/24 = 4.167 \cdot 10^{-6} is close to it, as the sharper bound predicts: the bound is 10−4⋅1.1052/24=4.60⋅10−610^{-4} \cdot 1.1052/24 = 4.60 \cdot 10^{-6}.

Proof. Take ak=1/k!a_k = 1/k! and z0=1z_0 = 1 in Theorem C1.1.2.11.1.15. The series converges by the ratio test, since ak+1/ak=1/(k+1)→0a_{k+1}/a_k = 1/(k+1) \to 0. □\square

Theorem C1.1.2.11.1.17 (the logarithm, TAOCP eq. 1.2.11.1(13)). For each m≥1m \ge 1,

ln⁡(1+z)=z−z22+⋯+(−1)m+1m zm+O(zm+1).\ln(1 + z) = z - \frac{z^2}{2} + \cdots + \frac{(-1)^{m+1}}{m}\, z^m + O(z^{m+1}).

Node: TA92HN8ZFR · Lean: TAOCP.S1_2_11.eq13, TAOCP.S1_2_11.eq13_real · status: not stated yet

Explanation. The series of ln⁡(1+z)\ln(1 + z) converges for ∣z∣<1|z| < 1 and it converges also at z=1z = 1. The point z0=1/2z_0 = 1/2 is used, where the terms are easy to bound. The statement is about zz in a disc around 00, so 1+z1 + z stays near 11 and the logarithm is the principal one.

Example. Let m=3m = 3 and z=0.1z = 0.1. The partial sum is 0.1−0.005+0.000333333=0.0953333330.1 - 0.005 + 0.000333333 = 0.095333333 and ln⁡1.1=0.0953101798\ln 1.1 = 0.0953101798. The error is −2.315⋅10−5-2.315 \cdot 10^{-5}, which is close to the next term −z4/4=−2.5⋅10−5-z^4/4 = -2.5 \cdot 10^{-5}.

Proof. It holds that ln⁡(1+z)=∑k≥1(−1)k+1zk/k\ln(1 + z) = \sum_{k \ge 1} (-1)^{k+1} z^k/k for ∣z∣<1|z| < 1, as the integral of 1/(1+t)=∑(−t)k1/(1+t) = \sum (-t)^k from 00 to zz (Section 1.2.9). The series converges at z0=1/2z_0 = 1/2. Theorem C1.1.2.11.1.15 gives the claim. □\square

Theorem C1.1.2.11.1.18 (the binomial series, TAOCP eq. 1.2.11.1(14)). For each real or complex α\alpha and each m≥0m \ge 0,

(1+z)α=1+αz+(α2)z2+⋯+(αm)zm+O(zm+1).(1 + z)^{\alpha} = 1 + \alpha z + \binom{\alpha}{2} z^2 + \cdots + \binom{\alpha}{m} z^m + O(z^{m+1}).

Node: TA9RPN3V4M · Lean: TAOCP.S1_2_11.eq14 (partial) · status: not stated yet

Explanation. The binomial series is the Taylor series of (1+z)α(1+z)^\alpha, and it converges for ∣z∣<1|z| < 1. The coefficients (αk)=α(α−1)⋯(α−k+1)/k!\binom{\alpha}{k} = \alpha(\alpha - 1) \cdots (\alpha - k + 1)/k! are defined for each α\alpha (Section 1.2.6). When α\alpha is a nonnegative integer, the series stops at k=αk = \alpha and the error is 00 for m≥αm \ge \alpha.

Example. Take α=1/2\alpha = 1/2, m=2m = 2 and z=0.1z = 0.1. The coefficients are (1/21)=1/2\binom{1/2}{1} = 1/2 and (1/22)=−1/8\binom{1/2}{2} = -1/8. The partial sum is 1+0.05−0.00125=1.048751 + 0.05 - 0.00125 = 1.04875 and 1.1=1.048808848\sqrt{1.1} = 1.048808848. The error is 5.885⋅10−55.885 \cdot 10^{-5}, close to the next term (1/23)z3=z3/16=6.25⋅10−5\binom{1/2}{3} z^3 = z^3/16 = 6.25 \cdot 10^{-5}.

Proof. The series ∑(αk)zk\sum \binom{\alpha}{k} z^k has the ratio ∣(αk+1)/(αk)∣=∣α−k∣/(k+1)→1|\binom{\alpha}{k+1}/\binom{\alpha}{k}| = |\alpha - k|/(k+1) \to 1 of consecutive coefficients, so it converges for ∣z∣<1|z| < 1 and in particular at z0=1/2z_0 = 1/2. Its sum is (1+z)α(1+z)^\alpha for ∣z∣<1|z| < 1 (Section 1.2.9). Theorem C1.1.2.11.1.15 gives the claim. □\square

Theorem C1.1.2.11.1.19 (the series of the harmonic numbers, TAOCP eq. 1.2.11.1(15)). For each m≥1m \ge 1, with Hk=1+1/2+⋯+1/kH_k = 1 + 1/2 + \cdots + 1/k,

11−zln⁡11−z=z+H2z2+⋯+Hmzm+O(zm+1).\frac{1}{1 - z} \ln \frac{1}{1 - z} = z + H_2 z^2 + \cdots + H_m z^m + O(z^{m+1}).

Node: TAC9CS23R1 · status: not stated yet

Explanation. The left side is the generating function of the harmonic numbers (Section 1.2.9). The statement is that the first mm harmonic numbers are the first mm coefficients, with an error of the order of the next power. Since H1=1H_1 = 1, the first term is zz and not H1zH_1 z written out.

Example. Take m=3m = 3 and z=0.1z = 0.1. The partial sum is 0.1+1.5⋅0.01+(11/6)⋅0.001=0.1168333330.1 + 1.5 \cdot 0.01 + (11/6) \cdot 0.001 = 0.116833333. The left side is ln⁡(1/0.9)/0.9=0.117067240\ln(1/0.9)/0.9 = 0.117067240. The error is 2.339⋅10−42.339 \cdot 10^{-4}, and the next term H4z4=(25/12)⋅10−4=2.083⋅10−4H_4 z^4 = (25/12) \cdot 10^{-4} = 2.083 \cdot 10^{-4} is of the same size.

Proof. The product of 1/(1−z)=∑j≥0zj1/(1-z) = \sum_{j \ge 0} z^j and ln⁡(1/(1−z))=∑k≥1zk/k\ln(1/(1-z)) = \sum_{k \ge 1} z^k/k has the coefficient of znz^n equal to ∑k=1n1/k=Hn\sum_{k=1}^{n} 1/k = H_n, since zk/kz^k/k pairs with zn−kz^{n-k}. Both series converge for ∣z∣<1|z| < 1, so the product converges there and equals the left side. At z0=1/2z_0 = 1/2 the terms Hn2−nH_n 2^{-n} tend to 00 because Hn≤nH_n \le n. Theorem C1.1.2.11.1.15 gives the claim. □\square

Lemma C1.1.2.11.1.20 (the Stirling numbers of a real argument, TAOCP Section 1.2.11.1). For each integer k≥0k \ge 0 there are polynomials σk(r)\sigma_k(r) and τk(r)\tau_k(r) in rr, of degree at most 2k2k, with σk(n)=[nn−k]\sigma_k(n) = \left[{n \atop n-k}\right] for all integers n≥0n \ge 0 and τk(n)={nn−k}\tau_k(n) = \left\{{n \atop n-k}\right\} for all integers n≥kn \ge k. For real rr the book writes [rr−k]\left[{r \atop r-k}\right] and {rr−k}\left\{{r \atop r-k}\right\} for σk(r)\sigma_k(r) and τk(r)\tau_k(r). The first ones are

σ0=τ0=1,σ1=τ1=r(r−1)2,\sigma_0 = \tau_0 = 1, \qquad \sigma_1 = \tau_1 = \frac{r(r-1)}{2}, σ2=r(r−1)(r−2)(3r−1)24,τ2=r(r−1)(r−2)(3r−5)24,\sigma_2 = \frac{r(r-1)(r-2)(3r-1)}{24}, \qquad \tau_2 = \frac{r(r-1)(r-2)(3r-5)}{24}, σ3=r2(r−1)2(r−2)(r−3)48,τ3=r(r−1)(r−2)2(r−3)248.\sigma_3 = \frac{r^2 (r-1)^2 (r-2)(r-3)}{48}, \qquad \tau_3 = \frac{r(r-1)(r-2)^2 (r-3)^2}{48}.

Node: none

Explanation. The Stirling numbers are defined for integers. When the lower index is the upper index minus a fixed kk, the number is a polynomial in the upper index, and this gives the meaning for real rr. The polynomials are unique, since a polynomial is fixed by its values at infinitely many integers. Note that σk(n)=0\sigma_k(n) = 0 for integers 0≤n<k0 \le n < k, and the polynomial takes the value 00 there too.

Example. The values σ2(4)=4⋅3⋅2⋅11/24=11=[42]\sigma_2(4) = 4 \cdot 3 \cdot 2 \cdot 11/24 = 11 = \left[{4 \atop 2}\right], σ3(4)=16⋅9⋅2⋅1/48=6=[41]\sigma_3(4) = 16 \cdot 9 \cdot 2 \cdot 1/48 = 6 = \left[{4 \atop 1}\right], τ2(4)=4⋅3⋅2⋅7/24=7={42}\tau_2(4) = 4 \cdot 3 \cdot 2 \cdot 7/24 = 7 = \left\{{4 \atop 2}\right\} and τ3(4)=4⋅3⋅4⋅1/48=1={41}\tau_3(4) = 4 \cdot 3 \cdot 4 \cdot 1/48 = 1 = \left\{{4 \atop 1}\right\} agree with Section 1.2.6. At r=1/2r = 1/2 the values are σ1=τ1=−1/8\sigma_1 = \tau_1 = -1/8, σ2=1/128\sigma_2 = 1/128, τ2=−7/128\tau_2 = -7/128, σ3=5/1024\sigma_3 = 5/1024 and τ3=−75/1024\tau_3 = -75/1024.

Proof. First kind. The product x(x+1)⋯(x+n−1)=xn∏i=0n−1(1+i/x)x(x+1)\cdots(x+n-1) = x^n \prod_{i=0}^{n-1}(1 + i/x) has the coefficient of xn−kx^{n-k} equal to the elementary symmetric sum ek(0,1,…,n−1)e_k(0, 1, \ldots, n-1). By Section 1.2.6 this coefficient is [nn−k]\left[{n \atop n-k}\right]. Newton's identities k ek=∑i=1k(−1)i−1ek−i pik\,e_k = \sum_{i=1}^{k} (-1)^{i-1} e_{k-i}\, p_i with the power sums pi=0i+1i+⋯+(n−1)ip_i = 0^i + 1^i + \cdots + (n-1)^i express eke_k as a polynomial in p1,…,pkp_1, \ldots, p_k, each term of which has the form ∏pit\prod p_{i_t} with ∑it≤k\sum i_t \le k. The sum pip_i is a polynomial in nn of degree i+1i + 1 (Section 1.2.11.2 below, or induction on ii with the difference of ni+1n^{i+1}). A product of t≤kt \le k of them has degree ∑(it+1)≤2k\sum (i_t + 1) \le 2k. So eke_k is a polynomial σk(n)\sigma_k(n) of degree at most 2k2k, and the identity holds for all integers n≥0n \ge 0 (the Newton identities are identities of polynomials in the variables, so they also give ek=0e_k = 0 when there are fewer than kk variables).

Second kind. The recursion {nm}=m{n−1m}+{n−1m−1}\left\{{n \atop m}\right\} = m \left\{{n-1 \atop m}\right\} + \left\{{n-1 \atop m-1}\right\} is also the recursion of the complete symmetric sum hn−m(1,2,…,m)h_{n-m}(1, 2, \ldots, m) in the variable mm and the degree n−mn - m: with hk(1..m)=m hk−1(1..m)+hk(1..m−1)h_k(1..m) = m\,h_{k-1}(1..m) + h_k(1..m-1), which splits the monomials by the power of mm. The start values agree: for m=0m = 0 both sides are 00 unless n=0n = 0, and for k=0k = 0 both sides are 11. So {nn−k}=hk(1,…,n−k)\left\{{n \atop n-k}\right\} = h_k(1, \ldots, n-k). Newton's identities for hh, k hk=∑i=1khk−i pik\,h_k = \sum_{i=1}^{k} h_{k-i}\, p_i, with pi=1i+⋯+(n−k)ip_i = 1^i + \cdots + (n-k)^i, give a polynomial in nn of degree at most 2k2k by the same count. This holds for all integers n≥kn \ge k.

The table is the result of this computation for k≤3k \le 3. Each entry was checked against the integer values n=0,…,12n = 0, \ldots, 12 of the Stirling numbers. □\square

Lemma C1.1.2.11.1.21 (the ratio of two gamma values, a tool of C1 for TAOCP eqs. 1.2.11.1(16) and (17)). Let ss be real and m≥0m \ge 0 an integer. As x→∞x \to \infty through the real numbers,

Γ(x+s)Γ(x)=xs(1+∑k=1mσk(s) x−k)+O ⁣(xs−m−1).\frac{\Gamma(x + s)}{\Gamma(x)} = x^s \left(1 + \sum_{k=1}^{m} \sigma_k(s)\, x^{-k}\right) + O\!\left(x^{s-m-1}\right).

Node: none

Explanation. This is the form of eq. (16) for real xx. For the integer x=nx = n the left side is ns‾n^{\overline{s}}, the rising power of nn with a real exponent ss (Section 1.2.5 defines ns‾=Γ(n+s)/Γ(n)n^{\overline{s}} = \Gamma(n+s)/\Gamma(n)). The lemma has two steps. The first step uses the series of Stirling to show that an expansion exists, with coefficients ck(s)c_k(s) that are polynomials in ss. The second step shows that ck=σkc_k = \sigma_k by a comparison with integer ss.

Example. Take s=−1s = -1. Then Γ(x−1)/Γ(x)=1/(x−1)=x−1(1+x−1+x−2+⋯ )\Gamma(x - 1)/\Gamma(x) = 1/(x - 1) = x^{-1}(1 + x^{-1} + x^{-2} + \cdots), and the coefficients are 1,1,1,…1, 1, 1, \ldots. The polynomials give σ1(−1)=(−1)(−2)/2=1\sigma_1(-1) = (-1)(-2)/2 = 1 and σ2(−1)=(−1)(−2)(−3)(−4)/24=1\sigma_2(-1) = (-1)(-2)(-3)(-4)/24 = 1. For s=1/2s = 1/2 the coefficients are 1,−1/8,1/128,5/10241, -1/8, 1/128, 5/1024 (Lemma C1.1.2.11.1.20), and a numeric check at x=100x = 100 gives Γ(100.5)/Γ(100)=9.98750786126\Gamma(100.5)/\Gamma(100) = 9.98750786126 against 10⋅(1−0.00125+0.00000078125+0.00000000488)=9.9875078613310 \cdot (1 - 0.00125 + 0.00000078125 + 0.00000000488) = 9.98750786133.

Proof. Step 1. The series of Stirling holds also with a shift. The book proves the case of n!n! in eqs. 1.2.11.2(18) and (19), and Euler's summation formula of Section 1.2.11.2, used on ln⁡(x+s+k)\ln(x + s + k) for k≥0k \ge 0, gives the shifted form in the same way. For fixed real ss,

ln⁡Γ(x+s)=(x+s−12)ln⁡x−x+12ln⁡2π+∑j=1m(−1)j+1Bj+1(s)j(j+1) x−j+O(x−m−1),\ln \Gamma(x + s) = \left(x + s - \tfrac12\right)\ln x - x + \tfrac12 \ln 2\pi + \sum_{j=1}^{m} \frac{(-1)^{j+1} B_{j+1}(s)}{j(j+1)}\, x^{-j} + O(x^{-m-1}),

where Bj+1(s)B_{j+1}(s) is the Bernoulli polynomial. Subtract the same formula for s=0s = 0. Since Bj+1(0)=Bj+1B_{j+1}(0) = B_{j+1}, the difference is

ln⁡Γ(x+s)Γ(x)=sln⁡x+u(x),u(x)=∑j=1maj(s) x−j+O(x−m−1),aj(s)=(−1)j+1(Bj+1(s)−Bj+1)j(j+1).\ln \frac{\Gamma(x+s)}{\Gamma(x)} = s \ln x + u(x), \qquad u(x) = \sum_{j=1}^{m} a_j(s)\, x^{-j} + O(x^{-m-1}), \quad a_j(s) = \frac{(-1)^{j+1}(B_{j+1}(s) - B_{j+1})}{j(j+1)}.

Each aja_j is a polynomial in ss of degree j+1j + 1. Since u(x)=O(1/x)→0u(x) = O(1/x) \to 0, eq. (12) gives eu=∑l≤mul/l!+O(um+1)e^{u} = \sum_{l \le m} u^l/l! + O(u^{m+1}). Expand the powers of the sum in uu and drop the terms of order x−m−1x^{-m-1} and higher. This gives eu(x)=1+∑k=1mck(s) x−k+O(x−m−1)e^{u(x)} = 1 + \sum_{k=1}^{m} c_k(s)\, x^{-k} + O(x^{-m-1}). Each ck(s)c_k(s) is a sum of products ∏ajt(s)\prod a_{j_t}(s) with ∑jt=k\sum j_t = k, so it is a polynomial in ss of degree at most ∑(jt+1)≤2k\sum (j_t + 1) \le 2k. Multiply by xsx^s.

Step 2. Let ss be an integer with s≥0s \ge 0. Then Γ(x+s)/Γ(x)=x(x+1)⋯(x+s−1)=∑k=0sσk(s)xs−k\Gamma(x+s)/\Gamma(x) = x(x+1)\cdots(x+s-1) = \sum_{k=0}^{s} \sigma_k(s) x^{s-k} exactly, by Lemma C1.1.2.11.1.20. So xs∑k≤m(ck(s)−σk(s)) x−k=O(xs−m−1)x^s \sum_{k \le m} (c_k(s) - \sigma_k(s))\, x^{-k} = O(x^{s-m-1}), with σk(s)=0\sigma_k(s) = 0 for k>sk > s (which the lemma gives). A sum ∑k≤mwkx−k\sum_{k \le m} w_k x^{-k} that is O(x−m−1)O(x^{-m-1}) has all wk=0w_k = 0: if wjw_j is the first nonzero one, multiply by xjx^j and let x→∞x \to \infty to get wj=0w_j = 0. Hence ck(s)=σk(s)c_k(s) = \sigma_k(s) for every integer s≥0s \ge 0. Two polynomials in ss that agree at all nonnegative integers are equal, so ck=σkc_k = \sigma_k. □\square

Theorem C1.1.2.11.1.22 (the rising power by powers, TAOCP eq. 1.2.11.1(16)). Let nr‾=Γ(n+r)/Γ(n)n^{\overline{r}} = \Gamma(n+r)/\Gamma(n) be the rising power of Section 1.2.5, and let [rr−k]=σk(r)\left[{r \atop r-k}\right] = \sigma_k(r) be the polynomial of Lemma C1.1.2.11.1.20. For each real rr and each integer m≥0m \ge 0, as n→∞n \to \infty,

nr‾=∑k=0m[rr−k]nr−k+O ⁣(nr−m−1).n^{\overline{r}} = \sum_{k=0}^{m} \left[{r \atop r-k}\right] n^{r-k} + O\!\left(n^{r-m-1}\right).

Node: TAY1623TM5 · status: not stated yet

Explanation. For a nonnegative integer rr the rising power n(n+1)⋯(n+r−1)n(n+1)\cdots(n+r-1) is a polynomial, and its coefficients are the Stirling numbers of the first kind. The formula says that the same coefficients, extended to real rr by Lemma C1.1.2.11.1.20, give the correct expansion of nr‾n^{\overline{r}} in powers of nn, even when rr is not an integer. If rr is an integer, the sum stops at k=rk = r, and the error is 00 for m≥rm \ge r. For a negative integer rr the full series converges once nn exceeds ∣r∣|r|. For r=−1r = -1 it holds that n−1‾=1/(n−1)=n−1+n−2+n−3+⋯n^{\overline{-1}} = 1/(n-1) = n^{-1} + n^{-2} + n^{-3} + \cdots, and σk(−1)=1\sigma_k(-1) = 1 for all kk.

The sum is not a convergent series in general. For r=1/2r = 1/2 the coefficients σk(1/2)\sigma_k(1/2) become large. Exact fractions give the terms ∣σk(1/2)∣ 2−k|\sigma_k(1/2)|\,2^{-k} at n=2n = 2: 0.06250.0625 for k=1k = 1, 0.000610.00061 for k=3k = 3, 2.1⋅10−72.1 \cdot 10^{-7} for k=10k = 10 and 9.9⋅10−89.9 \cdot 10^{-8} for k=14k = 14, which is the smallest. After that the terms rise: 303303 for k=44k = 44 and 4762047620 for k=48k = 48. So the series diverges, as the book says for each nn, and exercise 1.2.11.1-12 proves it. Each truncation is still right.

Example. Take r=3r = 3 and n=4n = 4: 4⋅5⋅6=120=43+3⋅42+2⋅4=64+48+84 \cdot 5 \cdot 6 = 120 = 4^3 + 3 \cdot 4^2 + 2 \cdot 4 = 64 + 48 + 8, with σ1(3)=3\sigma_1(3) = 3 and σ2(3)=2\sigma_2(3) = 2. Take r=1/2r = 1/2 and n=100n = 100: the exact value is Γ(100.5)/Γ(100)=9.98750786126\Gamma(100.5)/\Gamma(100) = 9.98750786126. The partial sums ∑k≤m\sum_{k \le m} and their errors are

mm partial sum exact minus sum error / nr−m−1/\ n^{r-m-1}
0 10 −1.249⋅10−2-1.249 \cdot 10^{-2} −0.1249-0.1249
1 9.9875 7.861⋅10−67.861 \cdot 10^{-6} 0.007860.00786
2 9.9875078125 4.876⋅10−84.876 \cdot 10^{-8} 0.0048760.004876
3 9.98750786132812 −6.561⋅10−11-6.561 \cdot 10^{-11} −0.000656-0.000656

The last column tends to the next coefficient σm+1(1/2)\sigma_{m+1}(1/2), which is −0.125-0.125, 0.007810.00781, 0.004880.00488 and −0.00064-0.00064 for m=0,1,2,3m = 0, 1, 2, 3. So the error is the next term, up to a factor that tends to 11.

Proof. Put s=rs = r and x=nx = n in Lemma C1.1.2.11.1.21 and multiply the sum by nrn^r term by term. The remainder is O(nr−m−1)O(n^{r-m-1}) already. □\square

Theorem C1.1.2.11.1.23 (the falling power by powers, TAOCP eq. 1.2.11.1(17)). Let nr‾=Γ(n+1)/Γ(n+1−r)n^{\underline{r}} = \Gamma(n+1)/\Gamma(n+1-r) be the falling power for real rr (it is n(n−1)⋯(n−r+1)n(n-1)\cdots(n-r+1) for a nonnegative integer rr), and let [rr−k]=σk(r)\left[{r \atop r-k}\right] = \sigma_k(r) be the polynomial of Lemma C1.1.2.11.1.20. For each real rr and each integer m≥0m \ge 0, as n→∞n \to \infty,

nr‾=∑k=0m(−1)k[rr−k]nr−k+O ⁣(nr−m−1).n^{\underline{r}} = \sum_{k=0}^{m} (-1)^k \left[{r \atop r-k}\right] n^{r-k} + O\!\left(n^{r-m-1}\right).

Node: TAGS7CH2PT · status: not stated yet

Explanation. This is the companion of eq. (16) for the falling power. The coefficients are the same polynomials σk(r)\sigma_k(r), now with the alternating sign (−1)k(-1)^k. For a nonnegative integer rr the sum stops at k=rk = r, the error is 00 for m≥rm \ge r, and the formula is eq. 1.2.6(44), the expansion of nr‾n^{\underline{r}} in powers of nn with the Stirling numbers of the first kind. For other rr the sum is an asymptotic series in the same sense as eq. (16): for r=1/2r = 1/2 its terms are, up to sign, the terms of the divergent series of eq. (16).

Example. Take r=3r = 3 and n=4n = 4: 4⋅3⋅2=24=43−3⋅42+2⋅4=64−48+84 \cdot 3 \cdot 2 = 24 = 4^3 - 3 \cdot 4^2 + 2 \cdot 4 = 64 - 48 + 8, with σ1(3)=3\sigma_1(3) = 3 and σ2(3)=2\sigma_2(3) = 2. Take r=1/2r = 1/2 and n=100n = 100: the exact value is n1/2‾=Γ(101)/Γ(100.5)=10.0125077636093n^{\underline{1/2}} = \Gamma(101)/\Gamma(100.5) = 10.0125077636093. The partial sums and their errors are

mm partial sum exact minus sum error / nr−m−1/\ n^{r-m-1}
0 10 1.251⋅10−21.251 \cdot 10^{-2} 0.12510.1251
1 10.0125 7.764⋅10−67.764 \cdot 10^{-6} 0.007760.00776
2 10.0125078125 −4.889⋅10−8-4.889 \cdot 10^{-8} −0.004889-0.004889
3 10.0125077636719 −6.256⋅10−11-6.256 \cdot 10^{-11} −0.000626-0.000626

The last column tends to the next coefficient (−1)m+1σm+1(1/2)(-1)^{m+1}\sigma_{m+1}(1/2), which is 0.1250.125, 0.007810.00781, −0.00488-0.00488 and −0.00064-0.00064 for m=0,1,2,3m = 0, 1, 2, 3.

Proof. Put x=n+1−rx = n + 1 - r. Then nr‾=Γ(x+r)/Γ(x)n^{\underline{r}} = \Gamma(x + r)/\Gamma(x), and Lemma C1.1.2.11.1.21 gives nr‾=∑k≤mσk(r) xr−k+O(xr−m−1)n^{\underline{r}} = \sum_{k \le m} \sigma_k(r)\, x^{r-k} + O(x^{r-m-1}). Write xr−k=nr−k(1+(1−r)/n)r−kx^{r-k} = n^{r-k}(1 + (1-r)/n)^{r-k} and expand by eq. (14): xr−k=nr−k∑l≤m−k(r−kl)(1−r)ln−l+O(nr−m−1)x^{r-k} = n^{r-k} \sum_{l \le m-k} \binom{r-k}{l}(1-r)^l n^{-l} + O(n^{r-m-1}). Collect the powers of nn. This gives nr‾=∑i≤mdi(r) nr−i+O(nr−m−1)n^{\underline{r}} = \sum_{i \le m} d_i(r)\, n^{r-i} + O(n^{r-m-1}) with di(r)=∑k+l=iσk(r)(r−kl)(1−r)ld_i(r) = \sum_{k+l=i} \sigma_k(r) \binom{r-k}{l}(1-r)^l, a polynomial in rr. For an integer r≥0r \ge 0 the falling power is the polynomial ∑i(−1)iσi(r) nr−i\sum_i (-1)^i \sigma_i(r)\, n^{r-i} by eq. 1.2.6(44), so di(r)=(−1)iσi(r)d_i(r) = (-1)^i \sigma_i(r) at all integers r≥0r \ge 0 by the uniqueness of the coefficients (see the proof of Lemma C1.1.2.11.1.21). Two polynomials that agree at all nonnegative integers are equal. So di=(−1)iσid_i = (-1)^i \sigma_i for all real rr. □\square

The inverse expansion. The same method expands the power nrn^r in falling powers: for each real rr and each integer m≥0m \ge 0,

nr=∑k=0m{rr−k}nr−k‾+O ⁣(nr−m−1),{rr−k}=τk(r).n^{r} = \sum_{k=0}^{m} \left\{{r \atop r-k}\right\} n^{\underline{r-k}} + O\!\left(n^{r-m-1}\right), \qquad \left\{{r \atop r-k}\right\} = \tau_k(r).

For a nonnegative integer rr this is eq. 1.2.6(45). A check at r=3r = 3 and n=4n = 4: 64=4⋅3⋅2+3⋅4⋅3+1⋅4=24+36+464 = 4 \cdot 3 \cdot 2 + 3 \cdot 4 \cdot 3 + 1 \cdot 4 = 24 + 36 + 4, with τ1(3)=3\tau_1(3) = 3 and τ2(3)=1\tau_2(3) = 1. A check at r=1/2r = 1/2 and n=100n = 100, with n1/2−k‾=Γ(101)/Γ(100.5+k)n^{\underline{1/2-k}} = \Gamma(101)/\Gamma(100.5 + k): the partial sums are 10.012507810.0125078, 10.000054410.0000544, 10.0000007210.00000072 and 10.000000016110.0000000161 for m=0,1,2,3m = 0, 1, 2, 3. The errors 10−sum10 - \text{sum} divided by nr−m−1n^{r-m-1} are −0.1251-0.1251, −0.0544-0.0544, −0.0717-0.0717 and −0.161-0.161. They tend to τm+1(1/2)\tau_{m+1}(1/2), which is −1/8-1/8, −7/128=−0.0547-7/128 = -0.0547, −75/1024=−0.0732-75/1024 = -0.0732 and −5509/32768=−0.168-5509/32768 = -0.168.

Proof of the inverse expansion. Insert the theorem with r−kr - k in place of rr into the right side:

∑k≤mτk(r) nr−k‾=∑k≤mτk(r)∑i≤m−k(−1)iσi(r−k) nr−k−i+O(nr−m−1)=∑j≤mwj(r) nr−j+O(nr−m−1),\sum_{k \le m} \tau_k(r)\, n^{\underline{r-k}} = \sum_{k \le m} \tau_k(r) \sum_{i \le m-k} (-1)^i \sigma_i(r-k)\, n^{r-k-i} + O(n^{r-m-1}) = \sum_{j \le m} w_j(r)\, n^{r-j} + O(n^{r-m-1}),

with wj(r)=∑k+i=j(−1)iτk(r) σi(r−k)w_j(r) = \sum_{k+i=j} (-1)^i \tau_k(r)\, \sigma_i(r-k), a polynomial in rr. Claim: w0=1w_0 = 1 and wj=0w_j = 0 for j≥1j \ge 1. It holds that w0=τ0σ0=1w_0 = \tau_0 \sigma_0 = 1. Let r≥j≥1r \ge j \ge 1 be an integer. Then nr=∑k=0r{rr−k}nr−k‾n^r = \sum_{k=0}^{r} \left\{{r \atop r-k}\right\} n^{\underline{r-k}} exactly by eq. 1.2.6(45), and each falling power is the polynomial ∑i(−1)i[r−kr−k−i]nr−k−i\sum_i (-1)^i \left[{r-k \atop r-k-i}\right] n^{r-k-i} of eq. 1.2.6(44). The coefficient of nr−jn^{r-j} on the right is wj(r)w_j(r), and on the left it is 00 for j≥1j \ge 1. So wjw_j vanishes at all integers r≥jr \ge j, and it is the zero polynomial. Therefore the sum is nr+O(nr−m−1)n^r + O(n^{r-m-1}). □\square

Theorem C1.1.2.11.1.24 (the nnth root of nn, TAOCP eq. 1.2.11.1(18)). For all integers n≥1n \ge 1, with x=ln⁡n/nx = \ln n / n,

nn=ex=1+ln⁡nn+O ⁣((ln⁡nn)2),0≤nn−1−ln⁡nn≤(ln⁡nn)2.\sqrt[n]{n} = e^{x} = 1 + \frac{\ln n}{n} + O\!\left(\left(\frac{\ln n}{n}\right)^{2}\right), \qquad 0 \le \sqrt[n]{n} - 1 - \frac{\ln n}{n} \le \left(\frac{\ln n}{n}\right)^{2}.

Node: TAC0KQZM1W · Lean: TAOCP.S1_2_11.eq18 · status: not stated yet

Explanation. Taking the nnth root pushes a number toward 11, but the number nn grows, and it is not clear at first which effect wins. The theorem shows that nn\sqrt[n]{n} tends to 11 and tells how fast. Write the root as exe^x with x=ln⁡n/nx = \ln n/n and use eq. (12) with m=1m = 1. The only fact needed about xx is that it is small: x≤1/ex \le 1/e for all nn.

Example. The values of nn\sqrt[n]{n} are

nn 1 2 3 4 5 10 100
nn\sqrt[n]{n} 1 1.41421 1.44225 1.41421 1.37973 1.25893 1.04713

The sequence has its maximum at n=3n = 3 and decreases to 11 from there on. At n=1000n = 1000 it holds that x=0.006907755x = 0.006907755, ex=1.006931669e^x = 1.006931669, 1+x=1.0069077551 + x = 1.006907755 and the error is 2.391⋅10−52.391 \cdot 10^{-5}, below x2=4.772⋅10−5x^2 = 4.772 \cdot 10^{-5}. The ratio of the error to x2x^2 is 0.5010.501, so the best constant for large nn is close to 1/21/2.

Proof. Let 0≤x≤10 \le x \le 1. The series gives ex−1−x=∑k≥2xk/k!≤x2∑k≥21/k!=x2(e−2)<x2e^x - 1 - x = \sum_{k \ge 2} x^k/k! \le x^2 \sum_{k \ge 2} 1/k! = x^2 (e - 2) < x^2, because xk≤x2x^k \le x^2 for k≥2k \ge 2 and 0≤x≤10 \le x \le 1. The function ln⁡t/t\ln t/t has the derivative (1−ln⁡t)/t2(1 - \ln t)/t^2, so it has its maximum 1/e1/e at t=et = e. Hence 0≤ln⁡n/n≤1/e<10 \le \ln n/n \le 1/e < 1 for n≥1n \ge 1, and the bound applies with x=ln⁡n/nx = \ln n / n. So M=1M = 1 and n0=1n_0 = 1. The same derivative is negative for t>et > e, so ln⁡n/n\ln n/n decreases for n≥3n \ge 3, and so does nn=eln⁡n/n\sqrt[n]{n} = e^{\ln n/n}. It tends to e0=1e^0 = 1 because ln⁡n/n→0\ln n/n \to 0 (exercise 1.2.11.1-8). □\square

Theorem C1.1.2.11.1.25 (the size of n(nn−1)n(\sqrt[n]{n} - 1), TAOCP eq. 1.2.11.1(19)). For all integers n≥1n \ge 1,

n(nn−1)=ln⁡n+O ⁣((ln⁡n)2n),0≤n(nn−1)−ln⁡n≤(ln⁡n)2n.n\left(\sqrt[n]{n} - 1\right) = \ln n + O\!\left(\frac{(\ln n)^2}{n}\right), \qquad 0 \le n\left(\sqrt[n]{n} - 1\right) - \ln n \le \frac{(\ln n)^2}{n}.

Node: TAMV62YZHH · Lean: TAOCP.S1_2_11.eq19 · status: not stated yet

Explanation. The quantity n(nn−1)n(\sqrt[n]{n} - 1) is the difference quotient of t↦ntt \mapsto n^t at t=0t = 0 with step 1/n1/n, and the derivative of this function at t=0t = 0 is ln⁡n\ln n. So ln⁡n\ln n is the natural guess, and the theorem bounds the error of the guess. The proof multiplies eq. (18) by nn: n (ln⁡n/n+O((ln⁡n/n)2))=ln⁡n+O((ln⁡n)2/n)n\,\bigl(\ln n/n + O((\ln n/n)^2)\bigr) = \ln n + O((\ln n)^2/n) by eqs. (6) and (10).

Example. At n=10n = 10: n(nn−1)=2.589254n(\sqrt[n]{n} - 1) = 2.589254, ln⁡10=2.302585\ln 10 = 2.302585, and the difference is 0.2866690.286669 against the bound (ln⁡10)2/10=0.530190(\ln 10)^2/10 = 0.530190. At n=1000n = 1000 the value is 6.9316696.931669, ln⁡1000=6.907755\ln 1000 = 6.907755 and the difference is 0.0239140.023914 against the bound 0.0477170.047717. At n=106n = 10^6 the ratio of the difference to the bound is 0.5000020.500002.

Proof. Multiply the inequality of Theorem C1.1.2.11.1.24 by nn: 0≤n(nn−1)−ln⁡n≤n(ln⁡n/n)2=(ln⁡n)2/n0 \le n(\sqrt[n]{n} - 1) - \ln n \le n (\ln n/n)^2 = (\ln n)^2/n. □\square

Definition C1.1.2.11.1.26 (lower bound and exact order, TAOCP Section 1.2.11.1). Let ff and gg be functions of nn. Write g(n)=Ω(f(n))g(n) = \Omega(f(n)) when two positive numbers LL and n0n_0 exist with the lower bound L ∣f(n)∣≤∣g(n)∣L\,|f(n)| \le |g(n)| at every n≥n0n \ge n_0. Write g(n)=Θ(f(n))g(n) = \Theta(f(n)) if both g(n)=O(f(n))g(n) = O(f(n)) and g(n)=Ω(f(n))g(n) = \Omega(f(n)).

Node: TAKKBTFWYX · Lean: TAOCP.BigOmegaWith, TAOCP.S1_2_11.IsOmega · status: not stated yet

Explanation. The symbol OO gives an upper bound only. A reader who sees g=O(f)g = O(f) may think that ff is the true order of gg, but gg can be much smaller, for example n=O(n2)n = O(n^2). The symbol Ω\Omega is the lower bound: the function gg is at least a fixed multiple of ff for large nn. The symbol Θ\Theta states both bounds at once, so that gg and ff have the same order of growth up to constant factors. In Lean the three are TAOCP.BigOWith, TAOCP.BigOmegaWith and TAOCP.ThetaWith, each with the constants written out.

Example. The function g(n)=(n2+n)/2g(n) = (n^2 + n)/2 is Ω(n2)\Omega(n^2) with L=1/2L = 1/2 and n0=1n_0 = 1, since (n2+n)/2≥n2/2(n^2 + n)/2 \ge n^2/2. It is also O(n2)O(n^2) with M=1M = 1, since n≤n2n \le n^2. So it is Θ(n2)\Theta(n^2). It is not Ω(n3)\Omega(n^3), since the ratio g(n)/n3g(n)/n^3 tends to 00. For the function ln⁡n\ln n and the harmonic numbers it holds that Hn=Θ(ln⁡n)H_n = \Theta(\ln n) with L=1L = 1, M=1+1/ln⁡2=2.4427M = 1 + 1/\ln 2 = 2.4427 and n0=2n_0 = 2: at n=2n = 2 the ratio Hn/ln⁡nH_n/\ln n is 1.5/0.6931=2.1641.5/0.6931 = 2.164, and at n=1000n = 1000 it is 7.4855/6.9078=1.0847.4855/6.9078 = 1.084.

Proof that the example is correct. For n≥2n \ge 2 it holds that Hn≥ln⁡(n+1)>ln⁡nH_n \ge \ln(n+1) > \ln n, since Hn=∑k≤n1/k≥∑k≤n∫kk+1dt/t=ln⁡(n+1)H_n = \sum_{k \le n} 1/k \ge \sum_{k \le n} \int_k^{k+1} dt/t = \ln(n+1). Also Hn≤1+ln⁡nH_n \le 1 + \ln n, since Hn−1=∑k=2n1/k≤∑k=2n∫k−1kdt/t=ln⁡nH_n - 1 = \sum_{k=2}^{n} 1/k \le \sum_{k=2}^{n} \int_{k-1}^{k} dt/t = \ln n. (Theorem C1.1.2.11.1.3 alone gives only Hn<ln⁡n+γ+1/nH_n < \ln n + \gamma + 1/n, which is larger than 1+ln⁡n1 + \ln n at n=2n = 2.) Further 1≤ln⁡n/ln⁡21 \le \ln n/\ln 2 for n≥2n \ge 2, so Hn≤(1/ln⁡2+1)ln⁡nH_n \le (1/\ln 2 + 1) \ln n. □\square

Theorem C1.1.2.11.1.27 (the lower bound, TAOCP eq. 1.2.11.1(20)). Let ff and gg be functions of nn. The statement below is true exactly when some L>0L > 0 and some n0n_0 give ∣g(n)∣≥L∣f(n)∣|g(n)| \ge L|f(n)| from n=n0n = n_0 on:

g(n)=Ω(f(n)).(20)g(n) = \Omega(f(n)). \tag{20}

Node: TAP9PXM23T · Lean: TAOCP.BigOmegaWith, TAOCP.S1_2_11.IsOmega · status: not stated yet

Explanation. This is the equation that names the lower bound. The condition has the shape of the definition of OO with the inequality turned around. The Lean predicate TAOCP.BigOmegaWith L n₀ f g says L∣g(n)∣≤∣f(n)∣L|g(n)| \le |f(n)| for n≥n0n \ge n_0, so its first function is the larger one. The condition of eq. (20) is therefore TAOCP.BigOmegaWith L n₀ g f, with gg first, and for L>0L > 0 the bridge TAOCP.BigOmegaWith.isBigO turns it into f =O[atTop] g of Mathlib.

Example. Let g(n)=n2−10ng(n) = n^2 - 10n. Then g(n)≥n2/2g(n) \ge n^2/2 when n≥20n \ge 20, since n2/2≥10nn^2/2 \ge 10n exactly when n≥20n \ge 20. So g=Ω(n2)g = \Omega(n^2) with L=1/2L = 1/2 and n0=20n_0 = 20. For n<20n < 20 the bound can fail: at n=10n = 10 it holds that g(10)=0g(10) = 0, while n2/2=50n^2/2 = 50. This is why the definition has n0n_0.

Proof. The statement is the definition of Ω\Omega in Definition C1.1.2.11.1.26, so the "if and only if" is immediate. □\square

Theorem C1.1.2.11.1.28 (the exact order, TAOCP eq. 1.2.11.1(21)). For functions ff and gg the equivalence below holds. Each side of it is true exactly when some L>0L > 0, M>0M > 0 and n0n_0 give L∣f(n)∣≤∣g(n)∣≤M∣f(n)∣L|f(n)| \le |g(n)| \le M|f(n)| from n=n0n = n_0 on.

g(n)=Θ(f(n))  ⟺  g(n)=O(f(n)) and g(n)=Ω(f(n)).(21)g(n) = \Theta(f(n)) \iff g(n) = O(f(n)) \text{ and } g(n) = \Omega(f(n)). \tag{21}

Node: TAE0Z4VBP3 · Lean: TAOCP.ThetaWith, TAOCP.S1_2_11.eq21 · status: not stated yet

Explanation. The equivalence is the definition of Θ\Theta as a conjunction. The second form uses one common n0n_0, the larger of the two. In Lean, TAOCP.ThetaWith L M n₀ g f is the conjunction of TAOCP.BigOmegaWith L n₀ g f and TAOCP.BigOWith M n₀ g f with a common n0n_0, and for L>0L > 0 the bridge TAOCP.ThetaWith.isTheta gives g =Θ[atTop] f, which is Asymptotics.IsTheta of Mathlib.

Example. Take g(n)=3n2+5ng(n) = 3n^2 + 5n and f(n)=n2f(n) = n^2. For n≥1n \ge 1: 3n2≤g(n)≤8n23n^2 \le g(n) \le 8n^2. So g=Θ(n2)g = \Theta(n^2) with L=3L = 3, M=8M = 8 and n0=1n_0 = 1. The ratio g(n)/n2=3+5/ng(n)/n^2 = 3 + 5/n falls from 88 at n=1n = 1 toward 33. So L=3L = 3 is the best lower constant, and for large n0n_0 the upper constant MM can be any number above 33, but never 33 itself.

Proof. If g=O(f)g = O(f) with (M,n1)(M, n_1) and g=Ω(f)g = \Omega(f) with (L,n2)(L, n_2), then for n≥max⁡(n1,n2)n \ge \max(n_1, n_2) both L∣f∣≤∣g∣L|f| \le |g| and ∣g∣≤M∣f∣|g| \le M|f| hold. Conversely the two bounds with a common n0n_0 give the two statements. □\square

Theorem C1.1.2.11.1.29 (the lower bound and the upper bound are dual, TAOCP exercise 1.2.11.1-13). The statements g=Ω(f)g = \Omega(f) and f=O(g)f = O(g) are equivalent. As a consequence, g=Θ(f)g = \Theta(f) holds exactly when both g=O(f)g = O(f) and f=O(g)f = O(g) hold.

Node: none · Lean: TAOCP.S1_2_11.isOmega_iff

Explanation. A lower bound on gg by ff is the same as an upper bound on ff by gg. The constant changes from LL to 1/L1/L. The proof uses that the constants of the definitions are positive; if L=0L = 0 were allowed, then each function would be Ω\Omega of every other function, and the equivalence would fail, for example for g=ng = n and f=n2f = n^2.

Example. For g=n2g = n^2 and f=nf = n: n2≥1⋅nn^2 \ge 1 \cdot n for n≥1n \ge 1, so g=Ω(f)g = \Omega(f) with L=1L = 1. And n≤1⋅n2n \le 1 \cdot n^2, so f=O(g)f = O(g) with M=1M = 1. For g=n2/4g = n^2/4 the constants are L=1/4L = 1/4 in the first and M=4M = 4 in the second.

Proof. If ∣g(n)∣≥L∣f(n)∣|g(n)| \ge L|f(n)| for n≥n0n \ge n_0 with L>0L > 0, then ∣f(n)∣≤L−1∣g(n)∣|f(n)| \le L^{-1}|g(n)|, so f=O(g)f = O(g) with M=1/LM = 1/L. If ∣f(n)∣≤M∣g(n)∣|f(n)| \le M|g(n)| with M>0M > 0, then ∣g(n)∣≥M−1∣f(n)∣|g(n)| \ge M^{-1}|f(n)|, so g=Ω(f)g = \Omega(f) with L=1/ML = 1/M. The second sentence follows from the definition of Θ\Theta. □\square

Algorithms and programs

Section 1.2.11.1 has no algorithm and no program. Each formula of it can be checked by machine with exact fractions for the polynomial parts, and with a 30-digit float for the gamma function and the logarithm. The numbers of this chapter were found in that way: the table of Hn−ln⁡n−γH_n - \ln n - \gamma, the partial sums of eqs. (16) and (17), and the values of nn\sqrt[n]{n}.

The exercises

The table has the exercises of Section 1.2.11.1. The kind is the class of spec 06.3, and the indexer of S0 fixes it in the map.

Exercise Rating Markers Kind Lean Solution
1.2.11.1-1 01 HM K3 not yet stated X1, 1.2.11.1-1
1.2.11.1-2 10 M K3 not yet stated X1, 1.2.11.1-2
1.2.11.1-3 15 M K4 not yet stated X1, 1.2.11.1-3
1.2.11.1-4 15 M K4 not yet stated X1, 1.2.11.1-4
1.2.11.1-5 20 M K2 not yet stated X1, 1.2.11.1-5
1.2.11.1-6 20 M K2 not yet stated X1, 1.2.11.1-6
1.2.11.1-7 15 HM K1 not yet stated X1, 1.2.11.1-7
1.2.11.1-8 20 HM K1 not yet stated X1, 1.2.11.1-8
1.2.11.1-9 20 HM K1 not yet stated X1, 1.2.11.1-9
1.2.11.1-10 22 HM K4 not yet stated X1, 1.2.11.1-10
1.2.11.1-11 11 M K1 not yet stated X1, 1.2.11.1-11
1.2.11.1-12 25 HM K1 not yet stated X1, 1.2.11.1-12
1.2.11.1-13 10 M K2 not yet stated X1, 1.2.11.1-13

The order to do them: start with 1.2.11.1-1 and 2, which test the meaning of OO as a set. Then do 1.2.11.1-3 and 4, which apply eqs. (6) to (10) and (12). Exercises 1.2.11.1-5 and 6 ask for a counterexample and for the error in an argument, and the constants of the definition decide both. Exercises 1.2.11.1-7 and 8 are the limits behind eq. (18), and exercise 1.2.11.1-11 is its proof. Exercises 1.2.11.1-9 and 10 extend eqs. (12) and (13) to an error that is itself an OO. Exercise 1.2.11.1-12 proves the divergence that Theorem C1.1.2.11.1.22 shows by numbers. Exercise 1.2.11.1-13 is Theorem C1.1.2.11.1.29.

Check for exercise 1.2.11.1-4 with a=3a = 3: the value of n(an−1)n(\sqrt[n]{a} - 1) at n=10,100,1000n = 10, 100, 1000 agrees with ln⁡a+(ln⁡a)2/(2n)+(ln⁡a)3/(6n2)\ln a + (\ln a)^2/(2n) + (\ln a)^3/(6n^2), and the error times n3n^3 is 0.06070.0607, close to (ln⁡a)4/24(\ln a)^4/24.

Lean

The Lean code of tamnd/taocp-lean at main has the file TAOCP/V1/S1_2_11.lean, in the namespace TAOCP.S1_2_11, and the definitions in TAOCP/Notation/BigO.lean. The Node lines name the declarations. Where the Lean statement differs from the handbook, the Node line says "partial".

  • TAOCP.BigOWith, TAOCP.BigOmegaWith and TAOCP.ThetaWith give the bounds with the constants written out. The bridges TAOCP.BigOWith.isBigO, TAOCP.BigOmegaWith.isBigO and TAOCP.ThetaWith.isTheta connect them to =O[atTop] and =Θ[atTop] of Mathlib.
  • Eqs. (1) to (4) are TAOCP.S1_2_11.eq1, eq2, eq3 and eq4, with the closed form TAOCP.S1_2_11.sum_squares. The polynomial rule is TAOCP.S1_2_11.poly_isBigO.
  • Eqs. (5) to (10) are TAOCP.S1_2_11.eq5 to eq10, and TAOCP.S1_2_11.eq10_rev is the reverse inclusion of eq. (10).
  • Eqs. (11) to (14) are TAOCP.S1_2_11.eq11 to eq14. Eqs. (12) and (13) also have the real forms TAOCP.S1_2_11.eq12_real and eq13_real. Eqs. (18) and (19) are TAOCP.S1_2_11.eq18 and eq19.
  • Eq. (20) is TAOCP.S1_2_11.IsOmega, the duality of Ω\Omega and OO is TAOCP.S1_2_11.isOmega_iff, and eq. (21) is TAOCP.S1_2_11.eq21.

The Lean statement differs from the handbook in two places. Eq. (1) states Hn=ln⁡n+γ+O(1/n)H_n = \ln n + \gamma + O(1/n) only. The strict bounds 0<Hn−ln⁡n−γ<1/n0 < H_n - \ln n - \gamma < 1/n are not stated. Eq. (14) states real α\alpha and real zz only.

Not yet stated: the Node lines that say "Lean: not yet stated", which include the asymptotic series with the coefficients σk\sigma_k and τk\tau_k and the results on the gamma function.

Notes and history

The symbol OO comes from P. Bachmann, in the second volume of his Analytische Zahlentheorie (1894). E. Landau made it common in number theory in his Handbuch der Lehre von der Verteilung der Primzahlen (1909), where he added the symbol oo. G. H. Hardy and J. E. Littlewood introduced Ω\Omega in 1914, and in that literature Ω\Omega means "not oo", a weaker statement than the lower bound of the section. Knuth proposed the present meaning of Ω\Omega and the symbol Θ\Theta for computer science in "Big Omicron and big Omega and big Theta", SIGACT News 8, 2 (1976).

The series of eq. (16) is a case of the asymptotic series of H. Poincaré (1886): a series that need not converge, whose partial sums have the right error order. The coefficients σk\sigma_k and τk\tau_k are polynomials in rr. Graham, Knuth and Patashnik, Concrete Mathematics (1989), Section 6.2, write them with the help of the Stirling polynomials, which are not the σk\sigma_k of this chapter.

Eqs. (16) and (17) both expand a factorial power in ordinary powers, and both use the numbers of the first kind. The inverse expansion of Theorem C1.1.2.11.1.23, with the numbers of the second kind, is not in the section. A reader who mixes the two should note that the sign (−1)k(-1)^k belongs to the expansion of nr‾n^{\underline{r}}: for r=2r = 2 the form n2=n2‾−[21]n1‾n^2 = n^{\underline{2}} - \left[{2 \atop 1}\right] n^{\underline{1}} would give n2−2nn^2 - 2n on the right.

The proofs of eqs. (16) and (17) in this chapter use the series of Stirling from Section 1.2.11.2. No result of Section 1.2.11.2 uses eq. (16) or (17), so there is no circle.

The project has no errata of Section 1.2.11.1 to report.

Section 1.2.11.1 of TAOCP gives a short way to write an approximation together with the size of its error. The statement Hn=ln⁡n+γ+O(1/n)H_n = \ln n + \gamma + O(1/n) says that the error is at most a fixed multiple of 1/n1/n for all large nn, and it does so without any value for the multiple. The section defines the notation, lists the rules that let a reader compute with it, applies it to power series and to the powers of Section 1.2.6, and ends with the lower bound Ω\Omega and the exact order Θ\Theta. This chapter of C1 explains each item of the section, proves each rule, and checks each formula on numbers.

The source of this page. Something is wrong? Report it.