For the complete documentation index, see llms.txt. This page is also available as Markdown.

Chapter 5: Analytic Combinatorics

Exercise 5.1 ๐ŸŒŸ

Consider the class GG of binary strings having no three consecutive 0 bits. Such strings are either โˆŠ, a single 0, a double 00, or 1 or 01 or 001 followed by a string with no three consecutive 0 bits. Symbolically, this argument gives the combinatorial construction

G=โˆŠ+Z0+Z0ร—Z0+(Z1+Z0ร—Z1+Z0ร—Z0ร—Z1)ร—G.G = โˆŠ + Z_0 + Z_0ร—Z_0+(Z_1 + Z_0 ร— Z_1+Z_0ร—Z_0 ร— Z_1) ร— G.

Theorem 5.1 allows us to translate this immediately into a formula for the generating function G(z)G(z) that enumerates such strings:

G(z)=1+z+z2+(z+z2+z3)G(z)โˆดG(z)=1+z+z21โˆ’zโˆ’z2โˆ’z3.G(z) = 1 + z +z^2 + (z + z^2+z^3)G(z) \\ \therefore G(z)=\frac{1+z+z^2}{1-z-z^2-z^3}.

The numerator is consisted of shift factors, as in the example from the book. The denominator is a well-known polynomial describing Tribonacci numbers (see Exercise 4.18). Therefore, the number of strings of length NN with no three consecutive 0 bits is TN+TN+1+TN+2=TN+3T_N+T_{N+1}+T_{N+2}=T_{N+3}, a sequence registered under A000073.

Exercise 5.2

We can express our class GG symbolically as

G=SEQ(Z1)ร—SEQ(Z0).G=SEQ(Z_1) \times SEQ(Z_0).

This gives

G(z)=1(1โˆ’z)2โˆด[zN]G(z)=N+1.G(z)=\frac{1}{(1-z)^2} \\[0.2cm] \therefore [z^N]G(z)=N+1.

Exercise 5.3

This is a simple variation of the example from the book. The class UU matches the construction

U=Zโ–ก+Zโ– ร—Uร—U.U = Z_\square + Z_\blacksquare ร— U ร— U.

We translate both ZZ classes as zz to get

U(z)=z+zU(z)2โˆดU(z)=1โˆ’1โˆ’4z22z.U(z)=z+zU(z)^2 \\[0.2 cm] \therefore U(z)=\frac{1-\sqrt{1-4z^2}}{2z}.

Itโ€™s always wise to check our OGF. For example, WolframAlpha can expand the generating function with series \frac{1-\sqrt{1-4z^2}}{2z} to order 9.

Exercise 5.4

The total number of binary trees with NN nodes is given by the NNth Catalan number. We need to figure out the number of binary trees with NN nodes without superleaves. The ratio of these numbers specifies the required fraction. The recursive decomposition of our combinatorial structure is

T=Zโ–ก+Zโ– ร—Tร—Tโˆ’Zโ– ร—Zโ– ร—Zโ– .T=Z_\square+Z_\blacksquare \times T \times T-Z_\blacksquare \times Z_\blacksquare \times Z_\blacksquare.

Notice that we must exclude a symmetric tree with 3 internal nodes that produces a superleaf at the root. This translates to

Tโ– (z)=1+zTโ– (z)2โˆ’z3โˆดTโ– (z)=1โˆ’1โˆ’4z+4z42z.T^\blacksquare(z)=1+zT^\blacksquare(z)^2-z^3 \\[0.2 cm] \therefore T^\blacksquare(z)=\frac{1-\sqrt{1-4z+4z^4}}{2z}.

With the help of WolframAlpha we can confirm that the coefficients divided by the Catalan numbers produce the desired ratios. There is only one caveat; trees with less than 3 nodes never produce a superleaf, so instead of zero their ratios should give one.

Exercise 5.5 ๐ŸŒŸ

We can regard BB as a series of independent decisions. The combinatorial construction for a decision DD about any single object of size nn in AA is

D=ฯต+Znโ€…โ€ŠโŸนโ€…โ€ŠD(z)=1+zn.D=\epsilon+Z_n \implies D(z)=1+z^n.

In other words, we either skip it or include it in our collection. Now, if we have AnA_n distinct objects of size nn in AA, then we make such decisions for every object. The construction is simply a sequence of AnA_n decisions that translates to (1+zn)An(1+z^n)^{A_n}. Finally, the whole product comes from repeating this endeavor for every possible size nn.

The second part of the proof follows from turning a product into a sum by taking a logarithm and employing Taylor expansion of lnโก(1+x)\ln(1+x). This gives

B(z)=โˆnโ‰ฅ1(1+zn)An=expโก{โˆ‘nโ‰ฅ1Anlnโก(1+zn)}=expโก{โˆ‘nโ‰ฅ1An(znโˆ’z2n/2+z3n/3โˆ’โ‹ฏโ€‰)}(seeย sectionย 4.2ย inย theย book)=expโก{โˆ‘nโ‰ฅ1Anznโˆ’12โˆ‘nโ‰ฅ1An(z2)n+13โˆ‘nโ‰ฅ1An(z3)nโˆ’โ‹ฏ}=expโก{A(z)โˆ’12A(z2)+13A(z3)โˆ’โ‹ฏ}.\begin{align*} B(z) &= \prod_{n \ge 1}(1+z^n)^{A_n} \\ &= \exp\bigg\{ \sum_{n \ge 1} A_n\ln(1+z^n)\bigg\} \\ &= \exp\bigg\{ \sum_{n \ge 1} A_n(z^n-z^{2n}/2+z^{3n}/3- \cdots)\bigg\} \qquad \text{(see section 4.2 in the book)} \\ &= \exp\bigg\{\sum_{n \ge 1} A_nz^n - \frac{1}{2}\sum_{n \ge 1} A_n(z^2)^n + \frac{1}{3}\sum_{n \ge 1} A_n(z^3)^n - \cdots \bigg\} \\ &= \exp\bigg\{A(z) - \frac{1}{2}A(z^2) + \frac{1}{3}A(z^3) - \cdots\bigg\}. \end{align*}

The above derivation assumes that A0=0A_0=0, which is a general precondition for any composition of GFs to be valid (see Exercise 3.41).

Exercise 5.6 ๐ŸŒŸ

We can regard BB as a series of independent decisions. The combinatorial construction for a decision DD about any single object of size nn in AA is

D=ฯต+Zn+Znร—Zn+Znร—Znร—Zn+โ‹ฏ=SEQ(Zn)โ€…โ€ŠโŸนโ€…โ€ŠD(z)=11โˆ’zn.D=\epsilon+Z_n+Z_n \times Z_n+Z_n \times Z_n \times Z_n + \cdots = SEQ(Z_n) \implies D(z)=\frac{1}{1-z^n}.

In other words, we either skip it, include it once, or twice, or any number of times (infinite geometric series). Now, if we have AnA_n distinct objects of size nn in AA, then we make such decisions for every object. The construction is simply a sequence of AnA_n decisions that translates to 1/(1โˆ’zn)An1/(1-z^n)^{A_n}. Finally, the whole product comes from repeating this endeavor for every possible size nn.

For the second part of the proof, we follow the same approach as in the previous exercise (including the remark about A0=0A_0=0)

B(z)=โˆnโ‰ฅ11(1โˆ’zn)An=expโก{โˆ’โˆ‘nโ‰ฅ1Anlnโก(1โˆ’zn)}(lnโก1=0)=expโก{โˆ’โˆ‘nโ‰ฅ1An(โˆ’znโˆ’z2n/2โˆ’z3n/3โˆ’โ‹ฏโ€‰)}(seeย sectionย 4.2ย inย theย book)=expโก{โˆ‘nโ‰ฅ1Anzn+12โˆ‘nโ‰ฅ1An(z2)n+13โˆ‘nโ‰ฅ1An(z3)n+โ‹ฏ}=expโก{A(z)+12A(z2)+13A(z3)+โ‹ฏ}.\begin{align*} B(z) &= \prod_{n \ge 1}\frac{1}{(1-z^n)^{A_n}} \\ &= \exp\bigg\{- \sum_{n \ge 1} A_n\ln(1-z^n)\bigg\} \qquad \text{($\ln 1=0$)} \\ &= \exp\bigg\{-\sum_{n \ge 1} A_n(-z^n-z^{2n}/2-z^{3n}/3- \cdots)\bigg\} \qquad \text{(see section 4.2 in the book)} \\ &= \exp\bigg\{\sum_{n \ge 1} A_nz^n + \frac{1}{2}\sum_{n \ge 1} A_n(z^2)^n + \frac{1}{3}\sum_{n \ge 1} A_n(z^3)^n + \cdots \bigg\} \\ &= \exp\bigg\{A(z) + \frac{1}{2}A(z^2) + \frac{1}{3}A(z^3) + \cdots\bigg\}. \end{align*}

Exercise 5.7

The combinatorial construction is

PODDโˆ—=SET(CYC1(Z)+CYC3(Z)+CYC5(Z)+โ‹ฏโ€‰).P^*_{ODD} = SET(CYC_1(Z)+CYC_3(Z)+CYC_5(Z)+\cdots).

The EGF associated with the combinatorial class PODDโˆ—P^*_{ODD} is

PODDโˆ—(z)=exp{z+z33+z55+โ‹ฏ}=exp{lnโก11โˆ’zโˆ’z22โˆ’z44โˆ’โ‹ฏ}=eโˆ’โˆ‘kโ‰ฅ1z2k2k1โˆ’z=e12lnโก(1โˆ’z2)1โˆ’z=1โˆ’z21โˆ’z=1+z1โˆ’z.\begin{align*} P^*_{ODD}(z) &= exp\bigg\{z+\frac{z^3}{3}+\frac{z^5}{5}+\cdots\bigg\} \\[0.3 cm] &=exp\bigg\{\ln \frac{1}{1-z}-\frac{z^2}{2}-\frac{z^4}{4}-\cdots\bigg\} \\[0.3 cm] &=\frac{e^{-\sum_{k \ge 1} \frac{z^{2k}}{2k}}}{1-z} \\[0.3 cm] &=\frac{e^{\frac{1}{2}\ln (1-z^2)}}{1-z} \\[0.3 cm] &=\frac{\sqrt{1-z^2}}{1-z}= \sqrt{\frac{1+z}{1-z}}. \end{align*}

Exercise 5.8

Symbolically, we have the construction

G=SEQ(CYC(Z)),G=SEQ(CYC(Z)),

which, by the cycle and sequence rules in Theorem 5.2, gives the EGF

G(z)=11โˆ’lnโก11โˆ’z=11+lnโก(1โˆ’z).G(z)=\frac{1}{1-\ln \frac{1}{1-z}}=\frac{1}{1+\ln (1-z)}.

Exercise 5.9

Symbolically, we have the construction that omits an empty sequence

G=CYC(SEQโ‰ฅ1(Z)),G=CYC(SEQ_{\ge 1}(Z)),

which, by the cycle and sequence rules in Theorem 5.2, gives the EGF

G(z)=lnโก11โˆ’z1โˆ’z=lnโก1โˆ’z1โˆ’2z.G(z)=\ln \frac{1}{1-\frac{z}{1-z}}=\ln \frac{1-z}{1-2z}.

Exercise 5.10

The proof is available on Analytic Combinatorics by RS and PF bookโ€™s website (see slide 12).

Exercise 5.11

The first part of the proof is

โˆ‘cโˆˆA+Bzโˆฃcโˆฃโˆฃcโˆฃ!ucost(c)=โˆ‘aโˆˆAzโˆฃaโˆฃโˆฃaโˆฃ!ucost(a)+โˆ‘bโˆˆBzโˆฃbโˆฃโˆฃbโˆฃ!ucost(b)=A(z,u)+B(z,u).\begin{align*} \sum_{c \in A + B} \frac{z^{|c|}}{|c|!} u^{\text{cost}(c)} &= \sum_{a \in A} \frac{z^{|a|}}{|a|!} u^{\text{cost}(a)} + \sum_{b \in B} \frac{z^{|b|}}{|b|!} u^{\text{cost}(b)} \\ &= A(z, u)+B(z, u). \end{align*}

For the labeled product Aโ‹†BA \star B, we have

โˆ‘cโˆˆAโ‹†Bzโˆฃcโˆฃโˆฃcโˆฃ!ucost(c)=โˆ‘aโˆˆAโˆ‘bโˆˆB(โˆฃaโˆฃ+โˆฃbโˆฃโˆฃaโˆฃ)zโˆฃaโˆฃ+โˆฃbโˆฃ(โˆฃaโˆฃ+โˆฃbโˆฃ)!ucost(a)+cost(b)=โˆ‘aโˆˆAโˆ‘bโˆˆB(โˆฃaโˆฃ+โˆฃbโˆฃ)!โˆฃaโˆฃ!โˆฃbโˆฃ!zโˆฃaโˆฃzโˆฃbโˆฃ(โˆฃaโˆฃ+โˆฃbโˆฃ)!ucost(a)ucost(b)=(โˆ‘aโˆˆAzโˆฃaโˆฃโˆฃaโˆฃ!ucost(a))(โˆ‘bโˆˆBzโˆฃbโˆฃโˆฃbโˆฃ!ucost(b))=A(z,u)B(z,u).\begin{align*} \sum_{c \in A \star B} \frac{z^{|c|}}{|c|!} u^{\text{cost}(c)} &= \sum_{a \in A} \sum_{b \in B} \binom{|a| + |b|}{|a|} \frac{z^{|a|+|b|}}{(|a|+|b|)!} u^{\text{cost}(a) + \text{cost}(b)} \\ &= \sum_{a \in A} \sum_{b \in B} \frac{(|a| + |b|)!}{|a|!|b|!} \frac{z^{|a|}z^{|b|}}{(|a|+|b|)!} u^{\text{cost}(a)} u^{\text{cost}(b)} \\ &= \left( \sum_{a \in A} \frac{z^{|a|}}{|a|!} u^{\text{cost}(a)} \right) \left( \sum_{b \in B} \frac{z^{|b|}}{|b|!} u^{\text{cost}(b)} \right) = A(z, u)B(z, u). \end{align*}

Having established both the labelled summation and product, the remainder of the proof proceeds identically to that presented for Theorem 5.2.

Exercise 5.12

Bu(z,1)=z(1โˆ’(1+u)z)2โˆฃu=1=z(1โˆ’2z)2=12โ€‰2z(1โˆ’2z)2.B_u(z,1)=\frac{z}{(1-(1+u)z)^2}\bigg|_{u=1}=\frac{z}{(1-2z)^2}=\frac{1}{2}\,\frac{2z}{(1-2z)^2}.

Thus, the average number of 1 bits in a random bitstring of length NN is

[zN]Bu(z,1)2N=N2Nโˆ’12N=N/2.\frac{[z^N]B_u(z,1)}{2^N}=\frac{N2^{N-1}}{2^N}=N/2.

Exercise 5.13

Symbolically, we have the construction (see the book)

G=ฯต+Z0+(Z1+Z0ร—Z1)ร—G.G = \epsilon + Z_0 + (Z_1 + Z_0 ร— Z_1) ร— G.

We should translate each Z1Z_1 as uzuz, to get

G(z,u)=1+z1โˆ’uz(1+z).G(z,u)=\frac{1+z}{1-uz(1+z)}.

The cumulative number of 1 bits is

Gu(z,1)=z(1+z)2(1โˆ’uz(1+z))2โˆฃu=1=1+z(1โˆ’zโˆ’z2)2โˆ’1+z1โˆ’zโˆ’z2.G_u(z,1)=\frac{z(1+z)^2}{(1-uz(1+z))^2}\bigg|_{u=1}=\frac{1+z}{(1-z-z^2)^2} - \frac{1+z}{1-z-z^2}.

The second summand is an OGF for FN+2F_{N+2}. The first summand can be rewritten as

1+z(1โˆ’zโˆ’z2)2=1+zz2โ‹…(z1โˆ’zโˆ’z2โ‹…z1โˆ’zโˆ’z2).\frac{1+z}{(1-z-z^2)^2}=\frac{1+z}{z^2} \cdot \left(\frac{z}{1-z-z^2} \cdot \frac{z}{1-z-z^2}\right).

The OGF inside parenthesis is a self-convolution of Fibonacci numbers (there is a closed-form solution). Hence, after combining all components and simplifying, we get that the average number of 1 bits in a random bitstring of length NN having no 00 is

[zN]Gu(z,1)FN+2=4NFN+2โˆ’(N+2)FN5FN+2.\frac{[z^N]G_u(z,1)}{F_{N+2}}=\frac{4NF_{N+2}-(N+2)F_N}{5F_{N+2}}.

Exercise 5.14

The book contains the formula for the number of derangements DND_N. We can tweak the combinatorial construction, by marking cycles with uu, to derive the cumulative generating function

Du(z,1)=eโˆ’z1โˆ’zโŸโˆ‘Nโ‰ฅ0DNzNN!(lnโก11โˆ’zโˆ’z)โŸโˆ‘Nโ‰ฅ2(Nโˆ’1)!zNN!โˆดN![zN]Du(z,1)DN=โˆ‘k=2N(Nk)(kโˆ’1)!DNโˆ’kDN.D_u(z, 1) = \underbrace{\frac{e^{-z}}{1-z}}_{\sum_{N \ge 0}D_N\frac{z^N}{N!}} \underbrace{\left( \ln \frac{1}{1-z} - z \right)}_{\sum_{N \ge 2}(N-1)!\frac{z^N}{N!}} \\[0.3 cm] \therefore \frac{N! [z^N] D_u(z, 1)}{D_N} = \frac{\sum_{k=2}^N \binom{N}{k} (k-1)! D_{N-k}}{D_N}.

Informally, we already know from the book, that in a random permutation the average number of cycles is HNH_N. Let XX be a random variable counting the number of fixed points (unary cycles) in a random permutation with NN elements. We have X=โˆ‘kXkX=\sum_kX_k, where XkX_k is an indicator random variable telling whether the kkth element remains on its current position. Apparently,

Prโก{Xk=1}=1/Nโ€…โ€ŠโŸนโ€…โ€ŠE[X]=โˆ‘kPrโก{Xk=1}=1.\Pr\{X_k=1\}=1/N \implies \mathbb{E}[X]=\sum_k \Pr\{X_k=1\}=1.

Therefore, the average number of cycles in a random derangement for large NN is โˆผHNโˆ’1\sim H_N-1. Of course, this back-of-the-envelope calculation makes some unjustified assumptions about independence of events, but gives an indication about what happens at the limit.

Exercise 5.15 ๐ŸŒŸ

The total number of binary trees with NN nodes is given by the NNth Catalan number. The recursive decomposition of our combinatorial structure is

T=ฯต+Zโ– +2Zโ– ร—(Tโˆ’ฯต)+Zโ– ร—(Tโˆ’ฯต)2.T=\epsilon+Z_\blacksquare+2Z_\blacksquare \times (T - \epsilon)+Z_\blacksquare \times (T - \epsilon)^2.

In plain English, a tree is one of the following:

  1. An empty tree (external node).

  2. A leaf.

  3. A root with one non-empty subtree (either left or right).

  4. A root with two non-empty subtrees; we must mark this root.

This gives the following BGF

T(z,u)=1+z+2z(T(z,u)โˆ’1)+uz(T(z,u)โˆ’1)2=1โˆ’2z(1โˆ’u)โˆ’1โˆ’4z+4z2(1โˆ’u)2uz.\begin{align*} T(z,u) &= 1 + z + 2z(T(z,u)-1) + uz(T(z,u)-1)^2 \\[0.3cm] &= \frac{1 - 2z(1-u) - \sqrt{1 - 4z + 4z^2(1-u)}}{2uz}. \end{align*}

Finding a partial derivative directly is quite complicated, even with a help of a computer algebra system. Instead, we will use the functional equation. By differentiating it implicitly, we get

Tu(z,u)=2zTu(z,u)+z(T(z,u)โˆ’1)2+2uz(T(z,u)โˆ’1)Tu(z,u)โˆดTu(z,1)=z(T(z,1)โˆ’1)21โˆ’2zT(z,1)=z(T(z,1)โˆ’1)21โˆ’4z=z3T(z,1)41โˆ’4z.T_u(z,u) = 2zT_u(z,u) + z(T(z,u)-1)^2 + 2uz(T(z,u)-1)T_u(z,u) \\[0.3cm] \therefore T_u(z,1)= \frac{z(T(z,1)-1)^2}{1 - 2zT(z,1)}= \frac{z(T(z,1)-1)^2}{\sqrt{1-4z}}=\frac{z^3 T(z,1)^4}{\sqrt{1-4z}}.

Recall that T(z)=T(z,1)=1+zT(z,1)2T(z)=T(z,1)=1+zT(z,1)^2, a standard equation for binary trees. This enables the last simplification. Extracting the coefficient is trivial by employing equation (5.72) from the book Concrete Mathematics by Graham, Knuth and Patashnik

[zN]Tu(z,1)=(2Nโˆ’2Nโˆ’3).[z^N]T_u(z,1)=\binom{2N-2}{N-3} .

The aforementioned book is an indispensable source when dealing with convoluted equations, as it contains numerous identities, like the one weโ€™ve just used.

The average number of internal nodes in a binary tree of size NN with both children internal is

[zN]Tu(z,1)[zN]T(z,1)=(Nโˆ’1)(Nโˆ’2)2(2Nโˆ’1).\frac{[z^N]T_u(z,1)}{[z^N]T(z,1)}= \frac{(N-1)(N-2)}{2(2N-1)}.

The formula checks perfectly for trees in Figure 5.2.

Exercise 5.16

This is a variation of the previous exercise. The only difference is that we must mark the internal node connected to a single non-empty subtree. This gives

T(z,u)=1+z+2uz(T(z,u)โˆ’1)+z(T(z,u)โˆ’1)2=1โˆ’u+1โˆ’(1โˆ’2z(u+1))(1โˆ’2z(uโˆ’1))2z.\begin{align*} T(z,u) &= 1 + z + 2uz(T(z,u)-1) + z(T(z,u)-1)^2 \\[0.3cm] &=1-u + \frac{1 - \sqrt{(1-2z(u+1))(1-2z(u-1))}}{2z}. \end{align*}

Following the same approach as previously, we arrive at

Tu(z,1)=2z2T(z,1)21โˆ’4z.T_u(z,1) = \frac{2z^2 T(z,1)^2}{\sqrt{1-4z}}.

Using the same identity as before, we get

[zN]Tu(z,1)[zN]T(z,1)=2(2nโˆ’2nโˆ’2)1n+1(2nn)=n2โˆ’12nโˆ’1.\frac{[z^N]T_u(z,1)}{[z^N]T(z,1)}=\frac{2 \dbinom{2n-2}{n-2}}{\cfrac{1}{n+1} \dbinom{2n}{n}} =\frac{n^2-1}{2n-1}.

The formula checks perfectly for trees in Figure 5.2.

Exercise 5.17 ๐ŸŒŸ

The explicit formula for T(z,u)T(z,u) is

T(z,u)=1โˆ’1โˆ’4z+4z2(1โˆ’u)2z.\boxed{T(z,u) = \frac{1 - \sqrt{1 - 4z + 4z^2(1-u)}}{2z}}.

We should calculate variance as described in Table 3.5, so we need a second partial derivative

โˆ‚2T(z,u)โˆ‚u2โˆฃu=1=2z3(1โˆ’4z)3/2.\left. \frac{\partial^2 T(z,u)}{\partial u^2} \right|_{u=1} = \frac{2z^3}{(1-4z)^{3/2}}.

To find pnโ€ฒโ€ฒ(1)p''_n(1) we should use the following identities

11โˆ’4z=โˆ‘(2kk)zk(fromย theย book,ย seeย Chapterย 3)1(1โˆ’4z)3/2=โˆ‘k+12(2k+2k+1)zk(byย theย indexย multiplyย operation).\frac{1}{\sqrt{1-4z}} = \sum \binom{2k}{k} z^k \qquad \text{(from the book, see Chapter 3)} \\[0.3cm] \frac{1}{(1-4z)^{3/2}} = \sum \frac{k+1}{2} \binom{2k+2}{k+1} z^k \qquad \text{(by the index multiply operation)}.

This gives (after right-shifting 3 positions due to z3z^3 and multplying by two)

pnโ€ฒโ€ฒ(1)=(nโˆ’2)(2nโˆ’4nโˆ’2).p''_n(1)=(n-2)\binom{2n-4}{n-2}.

Plugging all components (see also the book for pnโ€ฒ(1)p'_n(1)) into the formula for variance and simplifying gives

ฯƒ2=n(n+1)(nโˆ’1)(nโˆ’2)2(2nโˆ’1)2(2nโˆ’3).\sigma^2 = \frac{n(n+1)(n-1)(n-2)}{2(2n-1)^2(2n-3)}.

Exercise 5.18

We can employ the general Leibniz rule to get

[zN]eโˆ’z1โˆ’z=1N!(โˆ‘0โ‰คkโ‰คN(Nk)(โˆ’1)keโˆ’z(Nโˆ’k)!(1โˆ’z)โˆ’(Nโˆ’k)โˆ’1)โˆฃz=0=โˆ‘0โ‰คkโ‰คN(โˆ’1)kk!.[z^N]\frac{e^{-z}}{1-z}=\frac{1}{N!}\left(\sum_{0 \le k \le N}\binom{N}{k} (-1)^ke^{-z} (N-k)!(1-z)^{-(N-k)-1}\right)\bigg|_{z=0}=\sum_{0 \le k \le N} \frac{(-1)^k}{k!}.

Exercise 5.19

The root with the smallest modulus is 1/ฯ•1/\phi, so ฮฒ=ฯ•\beta=\phi. It is a simple algebra to show that

[zN]f(z)g(z)โˆผฯ•N+25.[z^N]\frac{f(z)}{g(z)}\sim\frac{\phi^{N+2}}{\sqrt 5}.

Exercise 5.20

According to Exercise 5.2 A(z)=1(1โˆ’z)2A(z)=\frac{1}{(1-z)^2}. Here, ฮฒ=1\beta=1, ฮฝ=2\nu=2, f(1)=1f(1)=1 and gโ€ฒโ€ฒ(1)=2g''(1)=2. Based on Theorem 4.1, an approximation for the number of bitstrings having no occurrence of 01 is

[zN]f(z)g(z)โˆผN.[z^N]\frac{f(z)}{g(z)}\sim N.

Exercise 5.21 ๐ŸŒŸ

Let f(z)=expโก(z1โˆ’z)f(z) = \exp\left(\frac{z}{1-z}\right). For the power series expansion of the exponent to converge, we must restrict our domain to โˆฃzโˆฃ<1|z|<1 (the criterion for a geometric series to converge). Therefore,

[zn]f(z)โ‰คminโกxโˆˆ(0,1)expโก(x1โˆ’x)xn.[z^n]f(z) \le \underset{x \in (0,1)}{\min} \frac{\exp\left(\frac{x}{1-x}\right)}{x^n}.

We should set xx to balance the growth of the numerator and the denominator as nn grows. Since we must prove that the bound is a function of n\sqrt n, letโ€™s try

x=1โˆ’1n.x = 1 - \frac{1}{\sqrt{n}}.

This is a bit reminiscent of the trial and error process in finding particular solutions of nonhomogeneous differential equations.

Weโ€™ve

expโก(x1โˆ’x)=expโก(1โˆ’1n1n)=expโก(nโˆ’1),\exp\left(\frac{x}{1-x}\right) = \exp\left(\frac{1 - \frac{1}{\sqrt{n}}}{\frac{1}{\sqrt{n}}}\right) = \exp(\sqrt{n} - 1),

and

1xn=(1โˆ’1n)โˆ’n=(1โˆ’1n)n(โˆ’n)โ‰คexpโก(n+1).\frac{1}{x^n} = \left(1 - \frac{1}{\sqrt{n}}\right)^{-n}= \left(1 - \frac{1}{\sqrt{n}}\right)^{\sqrt n (-\sqrt n)} \le \exp(\sqrt n + 1).

See Exercise 4.39 to understand the last step. All in all, this concludes the proof that

[zn]f(z)โ‰คexpโก(nโˆ’1)โ‹…expโก(n+1)=expโก(2n).[z^n]f(z) \le \exp(\sqrt{n} - 1) \cdot \exp(\sqrt{n} + 1) = \exp(2\sqrt{n}).

We arenโ€™t claiming that C=2C=2 is optimal, just that there is such a constant.

Exercise 5.22

This is a variation of the previous exercise. Let f(z)=โˆk=1โˆž(1โˆ’zk)โˆ’1f(z)=\prod_{k=1}^\infty (1-z^k)^{-1}. The radius of convergence is โˆฃzโˆฃ<1|z|<1. To deal with the infinite product, we take the natural logarithm and use the Taylor series expansion lnโก(1โˆ’x)=โˆ’โˆ‘j=1โˆžxjj\ln(1-x) = -\sum_{j=1}^\infty \frac{x^j}{j}. This gives

lnโกf(x)=โˆ’โˆ‘k=1โˆžlnโก(1โˆ’xk)=โˆ‘k=1โˆžโˆ‘j=1โˆžxjkj=โˆ‘j=1โˆž1jโˆ‘k=1โˆž(xj)k(byย absoluteย convergenceย ofย sums)=โˆ‘j=1โˆž1jxj1โˆ’xj.\begin{align*} \ln f(x) &= -\sum_{k=1}^\infty \ln(1-x^k) \\ &= \sum_{k=1}^\infty \sum_{j=1}^\infty \frac{x^{jk}}{j} \\ &= \sum_{j=1}^\infty \frac{1}{j} \sum_{k=1}^\infty (x^j)^k && \text{(by absolute convergence of sums)} \\ &= \sum_{j=1}^\infty \frac{1}{j} \frac{x^j}{1-x^j}. \end{align*}

To bound this, we can use a standard algebraic identity (recall that 0<x<10 <x<1)

1โˆ’xj=(1โˆ’x)(1+x+x2+โ‹ฏ+xjโˆ’1)โ‰ฅ(1โˆ’x)jxjโˆ’1.1 - x^j = (1-x)(1 + x + x^2 + \dots + x^{j-1}) \ge (1-x) j x^{j-1}.

Substituting this back into our series

xj1โˆ’xjโ‰คxj(1โˆ’x)jxjโˆ’1=xj(1โˆ’x)โ‰ค1j(1โˆ’x).\frac{x^j}{1-x^j} \le \frac{x^j}{(1-x) j x^{j-1}} = \frac{x}{j(1-x)} \le \frac{1}{j(1-x)}.

Weโ€™ve

lnโกf(x)โ‰คโˆ‘j=1โˆž1j(1j(1โˆ’x))=11โˆ’xโˆ‘j=1โˆž1j2=ฯ€26(1โˆ’x)โˆดf(x)โ‰คexpโก(ฯ€26(1โˆ’x)).\ln f(x) \le \sum_{j=1}^\infty \frac{1}{j} \left( \frac{1}{j(1-x)} \right) = \frac{1}{1-x} \sum_{j=1}^\infty \frac{1}{j^2} = \frac{\pi^2}{6(1-x)} \\ \therefore f(x) \le \exp\left( \frac{\pi^2}{6(1-x)} \right).

We had already encountered the Basel problem, which was applied above. This gives

[zn]f(z)โ‰คminโกxโˆˆ(0,1)f(x)xnโ‰คminโกxโˆˆ(0,1)expโก(ฯ€26(1โˆ’x)โˆ’nlnโกx).[z^n]f(z) \le \underset{x \in (0,1)}{\min} \frac{f(x)}{x^n} \le \underset{x \in (0,1)}{\min}\exp\left( \frac{\pi^2}{6(1-x)} - n \ln x \right).

Letโ€™s attempt with the same candidate

x=1โˆ’1n.x= 1 - \frac{1}{\sqrt{n}}.

Weโ€™ve

ฯ€26(1โˆ’x)=ฯ€26(1n)=ฯ€26n,\frac{\pi^2}{6(1-x)} = \frac{\pi^2}{6 \left(\frac{1}{\sqrt{n}}\right)} = \frac{\pi^2}{6} \sqrt{n},

and

โˆ’nlnโกx=โˆ’nlnโก(1โˆ’1n)โ‰คn(1n+1n)โŸโˆ’lnโก(1โˆ’x)Taylorย expansionย of=n+1.-n \ln x = -n \ln\left(1 - \frac{1}{\sqrt{n}}\right) \le n\underbrace{\left( \frac{1}{\sqrt{n}} + \frac{1}{n} \right)}_{\overset{\text{Taylor expansion of}}{-\ln(1-x)}} = \sqrt{n} + 1.

Our overall bound becomes

[zn]f(z)โ‰คexpโก((ฯ€26+1)n+1)=O(expโก(Cn)).[z^n]f(z) \le \exp\left( \left( \frac{\pi^2}{6} + 1 \right) \sqrt{n} + 1 \right)=O(\exp(C\sqrt n)).

For a more precise bound, take a look at the Wikipedia article about the partition function.

Exercise 5.23

The GF from Exercise 5.7 is

PODDโˆ—(z)=1+z1โˆ’z.P^*_{ODD}(z) = \sqrt{\frac{1+z}{1-z}}.

Theorem 5.5 immediately gives the result with ฮฑ=1/2\alpha=1/2

[zN]PODDโˆ—(z)โˆผ2ฯ€N=1ฯ€N/2.[z^N]P^*_{ODD}(z) \sim \frac{\sqrt 2}{\sqrt {\pi N}}= \frac{1}{\sqrt {\pi N/2}}.

Exercise 5.24

For the special case f(z)โ‰ก1f(z) \equiv1, the extension of Theorem 5.5 to three terms is available on Analytic Combinatorics by RS and PF bookโ€™s website (see slide 14). Weโ€™ll reuse it for deriving a more precise version of Theorem 5.5.

The asymptotic expansion follows from expanding f(z)f(z) into a Taylor series about z=1z=1

f(z)=โˆ‘k=0โˆžf(k)(1)k!(zโˆ’1)k=โˆ‘k=0โˆžf(k)(1)k!(โˆ’1)k(1โˆ’z)k.f(z) = \sum_{k=0}^{\infty} \frac{f^{(k)}(1)}{k!} (z-1)^k=\sum_{k=0}^{\infty} \frac{f^{(k)}(1)}{k!} (-1)^k(1-z)^k.

This gives

f(z)(1โˆ’z)ฮฑ=โˆ‘k=0โˆž(โˆ’1)kf(k)(1)k!(1โˆ’z)kโˆ’ฮฑ=โˆ‘k=0โˆž(โˆ’1)kf(k)(1)k!(1โˆ’z)โˆ’(ฮฑโˆ’k).\frac{f(z)}{(1-z)^\alpha} = \sum_{k=0}^{\infty} (-1)^k \frac{f^{(k)}(1)}{k!} (1-z)^{k-\alpha} = \sum_{k=0}^{\infty} (-1)^k \frac{f^{(k)}(1)}{k!} (1-z)^{-(\alpha - k)}.

Substituting the first few terms kโˆˆ[0,2]k \in [0,2] and collecting powers of nn gives

[zn]f(z)(1โˆ’z)ฮฑ=nฮฑโˆ’1ฮ“(ฮฑ)โ€‰f(1)+nฮฑโˆ’2ฮ“(ฮฑโˆ’1)(ฮฑ2โ€‰f(1)โˆ’fโ€ฒ(1))+nฮฑโˆ’3ฮ“(ฮฑโˆ’2)(ฮฑ(3ฮฑโˆ’1)24โ€‰f(1)โˆ’ฮฑโˆ’12โ€‰fโ€ฒ(1)+12โ€‰fโ€ฒโ€ฒ(1))+Oโ€‰โฃ(nฮฑโˆ’4)=nฮฑโˆ’1ฮ“(ฮฑ)f(1)[1+C1n+C2n2+O(nโˆ’3)],\begin{align*} [z^n] \frac{f(z)}{(1-z)^\alpha} &= \frac{n^{\alpha-1}}{\Gamma(\alpha)}\,f(1) \\ &\qquad + \frac{n^{\alpha-2}}{\Gamma(\alpha-1)}\left( \frac{\alpha}{2}\,f(1) - f'(1) \right) \\ &\qquad + \frac{n^{\alpha-3}}{\Gamma(\alpha-2)}\left( \frac{\alpha(3\alpha-1)}{24}\,f(1) - \frac{\alpha-1}{2}\,f'(1) + \frac{1}{2}\,f''(1) \right) \\ &\qquad + O\!\left(n^{\alpha-4}\right) \\ &= \frac{n^{\alpha-1}}{\Gamma(\alpha)} f(1) \left[ 1 + \frac{C_1}{n} + \frac{C_2}{n^2} + O(n^{-3}) \right], \end{align*}

where

C1=ฮฑ(ฮฑโˆ’1)2โˆ’(ฮฑโˆ’1)fโ€ฒ(1)f(1),C2=ฮฑ(ฮฑโˆ’1)(ฮฑโˆ’2)(3ฮฑโˆ’1)24โˆ’(ฮฑโˆ’1)2(ฮฑโˆ’2)2fโ€ฒ(1)f(1)+(ฮฑโˆ’1)(ฮฑโˆ’2)2fโ€ฒโ€ฒ(1)f(1).C_1 = \frac{\alpha(\alpha-1)}{2} - (\alpha-1)\frac{f'(1)}{f(1)}, \\[0.4cm] C_2 = \frac{\alpha(\alpha-1)(\alpha-2)(3\alpha-1)}{24} - \frac{(\alpha-1)^2(\alpha-2)}{2}\frac{f'(1)}{f(1)} + \frac{(\alpha-1)(\alpha-2)}{2}\frac{f''(1)}{f(1)}.

Exercise 5.25

We follow the steps from the proof of Theorem 5.5

[zn]f(z)lnโก11โˆ’z=f0n+f1nโˆ’1+โ‹ฏ+fnโˆ’11=1n(f0+f11โˆ’1/n+f21โˆ’2/n+โ‹ฏ+fk01โˆ’k0/n+โ‹ฏ+fnโˆ’11/n)โˆผ1nโˆ‘kfk=f(1)n.\begin{align*} [z^n]f(z) \ln \frac{1}{1-z} &= \frac{f_0}{n}+\frac{f_1}{n-1}+ \cdots +\frac{f_{n-1}}{1} \\ &= \frac{1}{n} \left(f_0+\frac{f_1}{1-1/n}+\frac{f_2}{1-2/n}+ \cdots +\frac{f_{k_0}}{1-k_0/n}+\cdots+\frac{f_{n-1}}{1/n}\right) \\ &\sim \frac{1}{n} \sum_k f_k = \frac{f(1)}{n}. \end{align*}

Weโ€™ve split the sum into two parts around the threshold value k0k_0; in spirit, aligned with the Laplace method for sums. A good choice is k0=โŒŠnโŒ‹k_0 = \lfloor \sqrt{n} \rfloor; the head of the sum captures all of f(1)f(1), where the denominators tend to one. Assuming that f(z)f(z) has a radius of convergence r>1r>1, all terms indexed larger than k0k_0 tend to zero exponentially fast (recall that [zn]f(z)=O(rโˆ’n)[z^n]f(z)=O(r^{-n})). Therefore, the tail sum is negligible.

Exercise 5.26

This is a variation of the previous exercise. From Table 3.1 we know that

[zn]11โˆ’zlnโก11โˆ’z=Hn.[z^n] \frac{1}{1-z} \ln \frac{1}{1-z} = H_n.

We setup a convolution, just like in the proof of Theorem 5.5 from the book

[zn]f(z)(11โˆ’zlnโก11โˆ’z)=โˆ‘k=0nfkHnโˆ’k.[z^n] f(z) \left( \frac{1}{1-z} \ln \frac{1}{1-z} \right) = \sum_{k=0}^{n} f_k H_{n-k}.

We split the sum in the same way as previously, so the leading part is

โˆ‘k=0k0fkHnโˆ’kโˆผHnโˆ‘k=0k0fkโˆผf(1)lnโกn.\sum_{k=0}^{k_0} f_k H_{n-k} \sim H_n \sum_{k=0}^{k_0} f_k \sim f(1) \ln n.

This is true, since Hnโˆ’kโˆผHnโˆผlnโกnH_{n-k} \sim H_n \sim \ln n for large nn and kโ‰คk0=nk\le k_0=\sqrt n. The tail sum is negligible for the same reason as in the previous exercise. Therefore,

[zn]f(z)11โˆ’zlnโก11โˆ’zโˆผf(1)lnโกn.[z^n] f(z) \frac{1}{1-z} \ln \frac{1}{1-z} \sim f(1) \ln n.

Last updated