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

Chapter 3: Generating Functions

Exercise 3.1 🌟

In all subproblems, {ak}km\{a_k\}_{k \ge m} denotes a sequence am,am+1,a_m,a_{m+1},\dots; for example, {k3}k2\{k^3\}_{k \ge 2} starts with 8 (without leading zeros).


Sequence {2k+1}k0\{2^{k+1}\}_{k \ge 0}

We can represent {2k+1}k0\{2^{k+1}\}_{k \ge 0} as 2{2k}k02\{2^k\}_{k \ge 0}, which is 2x an elementary OGF from Table 3.1 with c=2.c=2. Thus, 2/(12z)=k02k+1zk\boxed{2/(1-2z)=\sum_{k \ge 0}2^{k+1}z^k}.


Sequence {k2k+1}k0\{k2^{k+1}\}_{k \ge 0}

We can represent {k2k+1}k0\{k2^{k+1}\}_{k \ge 0} as 2{k2k}k02\{k2^k\}_{k \ge 0}, which is a scaled version of an elementary OGF from Table 3.1. Thus, 4z/(12z)2=k0k2k+1zk\boxed{4z/(1-2z)^2=\sum_{k \ge 0}k2^{k+1}z^k}.


Sequence {kHk}k1\{kH_k\}_{k \ge 1}

Let A(z)=k0k(Hk1)zkA(z)=\sum_{k \ge 0} k(H_k-1)z^k and B(z)=k0kzkB(z)=\sum_{k \ge 0} kz^k, so that our sequence is their left shifted sum (both summands are elementary OGFs from Table 3.1). We have

C(z)=A(z)+B(z)z=1(1z)2(ln11z+1)=k0(k+1)Hk+1zk.\begin{align*} C(z) &= \frac{A(z)+B(z)}{z} \\ &= \boxed{\frac{1}{(1-z)^2}\left(\ln \frac{1}{1-z}+1\right) =\sum_{k \ge 0}(k+1)H_{k+1}z^k}. \end{align*}

Sequence {k3}k2\{k^3\}_{k \ge 2}

Notice that k3=6(k3)+6(k2)+kk^3=6\binom{k}{3}+6\binom{k}{2}+k, so that our sequence is doubly left shifted sum of the corresponding elementary OGFs from Table 3.1. We have

A(z)=6z3(1z)4+6z2(1z)3+z(1z)2z1z=6z2(1z)4+6z(1z)3+1(1z)21z=6z(1z)4+6(1z)3+1z(1z)21z=85z+4z2z3(1z)4=k0(k+2)3zk.\begin{align*} A(z)&=\frac{\cfrac{\cfrac{6z^3}{(1-z)^4}+\cfrac{6z^2}{(1-z)^3}+\cfrac{z}{(1-z)^2}}{z}-1}{z} \\[0.2cm] &= \frac{\cfrac{6z^2}{(1-z)^4}+\cfrac{6z}{(1-z)^3}+\cfrac{1}{(1-z)^2}-1}{z} \\[0.3cm] &= \frac{6z}{(1-z)^4}+\frac{6}{(1-z)^3}+\frac{1}{z(1-z)^2}-\frac{1}{z} \\[0.4cm] &=\boxed{ \frac{8 - 5z + 4z^2 - z^3}{(1-z)^4}=\sum_{k \ge 0}(k+2)^3z^k}. \end{align*}

Exercise 3.2 🌟

The idea behind each subproblem is to find the root OGF from Table 3.1 and then see what operations have been performed on it from Table 3.2.


[zN]1(13z)4[z^N]\frac{1}{(1-3z)^4}

This is a scaled elementary OGF from Table 3.1 with M=3M=3, so

[zN]1(13z)4=3N6(N+1)(N+2)(N+3).\boxed{[z^N]\frac{1}{(1-3z)^4}=\frac{3^N}{6}(N+1)(N+2)(N+3)}.

[zN](1z)2ln1(1z)[z^N](1-z)^2\ln\frac{1}{(1-z)}

The difference operation is applied twice in succession on the elementary OGF. We have to be careful to avoid a division by zero error. For this reason, the first three terms are enumerated separately. We have

[zN](1z)2ln1(1z)={0if N=0,1if N=1,3/2if N=2,2N(N1)(N2)if N3.\boxed{[z^N](1-z)^2\ln\frac{1}{(1-z)} = \begin{cases} 0 & \text{if } N=0, \\ 1 & \text{if } N=1, \\ -3/2 & \text{if } N=2, \\ \cfrac{2}{N(N-1)(N-2)} & \text{if } N \ge 3. \end{cases}}

[zN]1(12z2)2[z^N]\frac{1}{(1-2z^2)^2}

The starting point is the elementary OGF 11z2=N0z2N\frac{1}{1-z^2}=\sum_{N \ge 0}z^{2N}. It is scaled by λ=2\lambda=\sqrt 2 to get 112z2\frac{1}{1-2z^2}. Finally, it is an elementary OGF from Table 3.1 with M=1M=1, so

[zN]1(12z2)2={(N2+1)2N/2if N is even,0if N is odd.\boxed{[z^N]\frac{1}{(1-2z^2)^2} = \begin{cases} \left(\frac{N}{2} + 1\right) 2^{N/2} & \text{if } N \text{ is even,} \\ 0 & \text{if } N \text{ is odd}. \end{cases}}

Exercise 3.3

1(1z)ln1(1z)=N1HNzNln1(1z)+1(1z)2=N1NHNzN1(differentiating)z(ln1(1z)+1)(1z)2=N1NHNzN(right shifting)z(1z)2ln1(1z)=N1N(HN1)zN(subtracting z/(1z)2=N1NzN)z(1z)2ln1(1z)=N0N(HN1)zN(altering index for N).\begin{align*} \frac{1}{(1-z)}\ln\frac{1}{(1-z)}&=\sum_{N \ge 1}H_Nz^N \\ \frac{\ln\cfrac{1}{(1-z)}+1}{(1-z)^2}&=\sum_{N \ge 1}NH_Nz^{N-1} && \text{(differentiating)} \\ \frac{z\left(\ln\cfrac{1}{(1-z)}+1\right)}{(1-z)^2}&=\sum_{N \ge 1}NH_Nz^N && \text{(right shifting)} \\ \frac{z}{(1-z)^2}\ln\cfrac{1}{(1-z)}&=\sum_{N \ge 1}N(H_N-1)z^N && \text{(subtracting $z/(1-z)^2=\sum_{N \ge 1}Nz^N$)} \\ \frac{z}{(1-z)^2}\ln\cfrac{1}{(1-z)}&=\sum_{N \ge 0}N(H_N-1)z^N && \text{(altering index for $N$)}. \end{align*}

The last step wasn’t really needed, since any "missing" term has a coefficient of zero.

Exercise 3.4 🌟

The solution is available as part of the course material on the book’s website (see slide 13).

Exercise 3.5

We need to prove a general identity satisfied by the harmonic numbers and binomial coefficients by factoring the initial OGF in different ways. Let’s start with

zM(1z)M+1A(z)ln11zB(z).\underbrace{\frac{z^M}{(1-z)^{M+1}}}_{A(z)} \cdot \underbrace{\ln \frac{1}{1-z}}_{B(z)}.

Both components are elementary OGFs from Table 3.1. We have by definition

[zN](A(z)B(z))=k=MN1(kM)1Nk.[z^N](A(z)B(z)) = \sum_{k=M}^{N-1} \binom{k}{M} \frac{1}{N-k}.

Another possible grouping is

zM(1z)MC(z)11zln11zD(z). \underbrace{ \frac{z^M}{(1-z)^M} }_{C(z)} \cdot \underbrace{ \frac{1}{1-z} \ln \frac{1}{1-z} }_{D(z)}.

Again, both are essentially elementary OGFs from Table 3.1. We have by definition

[zN](C(z)D(z))=k=MN1(k1M1)HNk.[z^N](C(z)D(z)) = \sum_{k=M}^{N-1} \binom{k-1}{M-1} H_{N-k}.

Another possible grouping is

zM1(1z)M1E(z)z(1z)2ln11zF(z). \underbrace{ \frac{z^{M-1}}{(1-z)^{M-1}} }_{E(z)} \cdot \underbrace{ \frac{z}{(1-z)^2} \ln \frac{1}{1-z} }_{F(z)}.

Again, both are essentially elementary OGFs from Table 3.1. We have by definition

[zN](E(z)F(z))=k=M1N1(k1M2)(Nk)(HNk1).[z^N](E(z)F(z)) = \sum_{k=M-1}^{N-1} \binom{k-1}{M-2} (N-k)(H_{N-k}-1).

Looking at the initial OGF, we see that it is

zM1(1z)M+1P(z)ln11zQ(z).z^M \cdot \underbrace{\frac{1}{(1-z)^{M+1}}}_{P(z)} \cdot \underbrace{\ln \frac{1}{1-z}}_{Q(z)}.

Therefore, [zN](A(z)B(z))=[zNM](P(z)Q(z))[z^N](A(z)B(z)) =[z^{N-M}](P(z)Q(z)). The book Concrete Mathematics: A Foundation for Computer Science (2nd ed.) contains an identity (7.43)

P(z)Q(z)=N0(HM+NHM)(M+NN)zN.P(z)Q(z)=\sum_{N \ge 0} (H_{M+N}-H_M)\binom{M+N}{N}z^N.

By combining all components, we get

k=MN1(kM)1Nk=k=MN1(k1M1)HNk=k=M1N1(k1M2)(Nk)(HNk1)=(NM)(HNHM).\boxed{\sum_{k=M}^{N-1} \binom{k}{M} \frac{1}{N-k} = \sum_{k=M}^{N-1} \binom{k-1}{M-1} H_{N-k} =\sum_{k=M-1}^{N-1} \binom{k-1}{M-2} (N-k)(H_{N-k}-1)= \binom{N}{M}(H_N - H_M)}.

Exercise 3.6

See the remark in Exercise 3.1 how to interpret the definition of the sequence. It’s a doubly left shifted self-convolution of an elementary OGF ln11z\ln \frac{1}{1-z}

A(z)=(ln11z)2z2=ln2(1z)z2.A(z)=\frac{\left(\ln \cfrac{1}{1-z}\right)^2}{z^2}=\frac{ \ln^2(1-z)}{z^2}.

Exercise 3.7 🌟

Assume the same interpretation of this definition as in Exercise 3.1. A recipe for crafting the required OGF is as follows:

  1. Start with the elementary OGF for the harmonic numbers.

  2. Left shift it.

  3. Apply the index divide (integration) operation.

  4. Left shift again.

Despite being simple at first blush, the third step requires some advanced knowledge from calculus. The first two steps are

1(1z)ln1(1z)=N1HNzN1z1(1z)ln1(1z)=N0HN+1zN(left shifting).\begin{align*} \frac{1}{(1-z)}\ln\frac{1}{(1-z)}&=\sum_{N \ge 1}H_Nz^N \\ \frac{1}{z} \cdot \frac{1}{(1-z)}\ln\frac{1}{(1-z)}&=\sum_{N \ge 0}H_{N+1}z^N && \text{(left shifting)}. \end{align*}

We can’t directly integrate the LHS, since we have an improper integral (isn’t defined at zero). Let’s break it up and compute the components individually. We get

0zln(1z)z(1z)dz=0zln(1z)(1z+11z)dz=0zln(1z)zdzdilogarithmfunction0zln(1z)1zdz=Li2(z)+12ln2(1z).\begin{align*} \int_0^z \frac{-\ln(1-z)}{z(1-z)} \, dz &= \int_0^z -\ln(1-z) \left( \frac{1}{z} + \frac{1}{1-z} \right) \, dz \\[0.4cm] &= \underbrace{\int_0^z \frac{-\ln(1-z)}{z} \, dz}_{dilogarithm function} - \int_0^z \frac{\ln(1-z)}{1-z} \, dz \\[0.8cm] &= Li_2(z) + \frac{1}{2} \ln^2(1-z). \end{align*}

Wikipedia has more information on the dilogarithm function. For the second integral, we can use WolframAlpha.

Li2(z)+12ln2(1z)=N0HN+1N+1zN+1Li2(z)+12ln2(1z)z=N0HN+1N+1zN(left shifting).\begin{align*} &Li_2(z) + \frac{1}{2} \ln^2(1-z) = \sum_{N \ge 0} \frac{H_{N+1}}{N+1}z^{N+1} \\ &\boxed{\frac{Li_2(z) + \frac{1}{2} \ln^2(1-z)}{z} = \sum_{N \ge 0} \frac{H_{N+1}}{N+1}z^N} && \text{(left shifting)}. \end{align*}

Exercise 3.8 🌟

Let’s tackle first the common OGF A(z)=ln211zA(z)=\ln^2 \frac{1}{1-z} that appears in both subtasks. As usual, there are many equivalent expressions for [zN][z^N]. Let’s reuse the results from the previous two exercises

[zN]A(z)=0<k<N1k(Nk)=2HN1N     for N>1.[z^N]A(z)=\sum_{0<k<N} \frac{1}{k(N-k)}=\frac{2H_{N-1}}{N} \space\space\space\space \text{ for $N>1$}.

For N1N \le 1 the coefficients are zero. Observe that our A(z)A(z) differs from the one from Exercise 3.6, in a sense, that it represents a sequence with two leading zeros. Consequently, we can cleanly perform an index divide operation on the OGF for harmonic numbers without a need for an intermediary left shift. This removes the dilogarithm complication, as we had in the previous exercise.


[zN]11zln211z[z^N]\frac{1}{1-z}\ln^2 \frac{1}{1-z}

We apply the partial sum operation on A(z)A(z) to get B(z)=A(z)/(1z)B(z)=A(z)/(1-z). For pedagogical reasons, we show here another derivation of the identity stated above for A(z)A(z) (see step 3). We have

[zN]B(z)=1<iN0<j<i1j(ij)=1<iN1i0<j<i(1j+1ij)(1j(ij)=1i(1j+1ij))=1<iN2Hi1i=21<iNHi1ii=2i=1NHii2i=1N1i2(set i to start at 1 without influencing the sum)=2(12(HN2+HN(2)))2HN(2)(by identity (6.71))[zN]11zln211z=[zN](ln11z)(11zln11z)    k=1N1HNkk=HN2HN(2).\begin{align*} [z^N]B(z)&=\sum_{1<i\le N}\sum_{0<j<i} \frac{1}{j(i-j)} \\[0.5cm] &= \sum_{1<i\le N} \frac{1}{i}\sum_{0<j<i} \left(\frac{1}{j}+\frac{1}{i-j}\right) \qquad \text{$\left(\frac{1}{j(i-j)}=\frac{1}{i}\left(\frac{1}{j}+\frac{1}{i-j}\right)\right)$} \\[0.6cm] &= \sum_{1<i\le N} \frac{2H_{i-1}}{i} \\ &= 2 \sum_{1<i\le N} \frac{H_i - \cfrac{1}{i}}{i} \\[0.5cm] &= 2 \sum_{i=1}^{N} \frac{H_i}{i} - 2 \sum_{i=1}^{N} \frac{1}{i^2} \qquad \text{(set $i$ to start at 1 without influencing the sum)} \\[0.5cm] &=2 \left( \frac{1}{2} (H_N^2 + H_N^{(2)}) \right) - 2 H_N^{(2)} \qquad \text{(by identity (6.71))} \\[0.5cm] &\therefore \boxed{[z^N]\frac{1}{1-z}\ln^2 \frac{1}{1-z}=[z^N]\left(\ln \frac{1}{1-z}\right)\left(\frac{1}{1-z}\ln \frac{1}{1-z}\right) \implies \sum_{k=1}^{N-1} \frac{H_{N-k}}{k} = H_N^2 - H_N^{(2)}}. \end{align*}

The previous derivation uses the identity (6.71) from the book Concrete Mathematics: A Foundation for Computer Science (2nd ed.).


[zN]ln311z[z^N]\ln^3 \frac{1}{1-z}

We convolve A(z)A(z) with ln11z\ln \frac{1}{1-z} to get B(z)=ln11zA(z)B(z)=\ln \frac{1}{1-z}A(z). We have

[zN]B(z)=2k=1N1HNk1k(Nk)=2N(k=1N1HNk1kS1+k=1N1HNk1NkS2).\begin{align*} [z^N]B(z)&=2 \sum_{k=1}^{N-1} \frac{H_{N-k-1}}{k(N-k)} \\ &= \frac{2}{N} \left( \underbrace{\sum_{k=1}^{N-1} \frac{H_{N-k-1}}{k}}_{S_1} + \underbrace{\sum_{k=1}^{N-1} \frac{H_{N-k-1}}{N-k}}_{S_2} \right). \end{align*}
S1=k=1N1HNk1k=k=1N1HNkkk=1N11k(Nk)=(HN2HN(2))2NHN1=(HN2HN1(2)1N2)2NHN1=(HN1N)(HN+1N)HN1(2)2NHN1=HN1(HN1+2N)HN1(2)2NHN1=HN12HN1(2).\begin{align*} S_1 &= \sum_{k=1}^{N-1} \frac{H_{N-k-1}}{k} \\ &= \sum_{k=1}^{N-1} \frac{H_{N-k}}{k} - \sum_{k=1}^{N-1} \frac{1}{k(N-k)} \\ &= (H_N^2 - H_N^{(2)}) - \frac{2}{N} H_{N-1} \\ &= \left(H_N^2-H_{N-1}^{(2)}- \frac{1}{N^2}\right) - \frac{2}{N} H_{N-1} \\ &= \left(H_N-\frac{1}{N}\right)\left(H_N+\frac{1}{N}\right) -H_{N-1}^{(2)} - \frac{2}{N} H_{N-1} \\ &= H_{N-1}\left(H_{N-1}+\frac{2}{N}\right) -H_{N-1}^{(2)} - \frac{2}{N} H_{N-1} \\ &= H_{N-1}^2 - H_{N-1}^{(2)}. \end{align*}
S2=k=1N1Hk1k(reindexing)=k=1N1Hk1kk=k=1N1Hkkk=1N11k2=12(HN12HN1(2)).\begin{align*} S_2 &= \sum_{k=1}^{N-1} \frac{H_{k-1}}{k} && \text{(reindexing)} \\ &= \sum_{k=1}^{N-1} \frac{H_k - \frac{1}{k}}{k} \\ &= \sum_{k=1}^{N-1} \frac{H_k}{k} - \sum_{k=1}^{N-1} \frac{1}{k^2} \\ &= \frac{1}{2} \left( H_{N-1}^2 - H_{N-1}^{(2)} \right). \end{align*}

Substituting our partial sums into the expression for [zN][z^N] we have

[zN]B(z)=2N(S1+S2)=2N([HN12HN1(2)]+12[HN12HN1(2)])[zN]ln311z=3N(HN12HN1(2))for N>1.\begin{align*} [z^N]B(z) &= \frac{2}{N} (S_1 + S_2) \\ &= \frac{2}{N} \left( \left[ H_{N-1}^2 - H_{N-1}^{(2)} \right] + \frac{1}{2} \left[ H_{N-1}^2 - H_{N-1}^{(2)} \right] \right) \\ &\therefore \boxed{[z^N]\ln^3 \frac{1}{1-z} = \frac{3}{N} \left( H_{N-1}^2 - H_{N-1}^{(2)} \right)} && \text{for $N>1$}. \end{align*}

For N1N \le 1 the coefficients are zeros.

Exercise 3.9 🌟

In all subproblems, {ak}km\{a_k\}_{k \ge m} denotes a sequence am,am+1,a_m,a_{m+1},\dots; for example, {k3}k2\{k^3\}_{k \ge 2} starts with 8 (without leading zeros).


Sequence {2k+1}k0\{2^{k+1}\}_{k \ge 0}

We can represent {2k+1}k0\{2^{k+1}\}_{k \ge 0} as 2{2k}k02\{2^k\}_{k \ge 0}, which is 2x an elementary EGF from Table 3.3 with c=2.c=2. Thus, 2e2z=k02k+1zkk!\boxed{2e^{2z}=\sum_{k \ge 0}2^{k+1}\frac{z^k}{k!}}.


Sequence {k2k+1}k0\{k2^{k+1}\}_{k \ge 0}

We can represent {k2k+1}k0\{k2^{k+1}\}_{k \ge 0} as 2{k2k}k02\{k2^k\}_{k \ge 0}. For the scaled sequence, the starting point is e2ze^{2z}. Next, we need to perform an index multiply operation. To get kakka_k instead of kak1ka_{k-1}, we must again multiply by 2, since ak=2ak1a_k=2a_{k-1} for k>1k>1.. Thus, 4ze2z=k0k2k+1zkk!\boxed{4ze^{2z}=\sum_{k \ge 0}k2^{k+1}\frac{z^k}{k!}}.


Sequence {k3}k2\{k^3\}_{k \ge 2}

Notice that k3=6(k3)+6(k2)+kk^3=6\binom{k}{3}+6\binom{k}{2}+k, so that our sequence is a doubly left shifted sum of the corresponding elementary EGFs from Table 3.3. We have

A(z)=((6/6)z3ez+(6/2)z2ez+zez)=((z3+3z2+z)ez)=((z3+6z2+7z+1)ez)(z3+9z2+19z+8)ez=k0(k+2)3zkk!.\begin{align*} A(z)&=((6/6)z^3e^z+(6/2)z^2e^z+ze^z)'' \\ &=((z^3+3z^2+z)e^z)'' \\ &=((z^3+6z^2+7z+1)e^z)' \\ &\therefore \boxed{(z^3+9z^2+19z+8)e^z=\sum_{k \ge 0}(k+2)^3\frac{z^k}{k!}}. \end{align*}

Exercise 3.10

The sequence 1,3,5,7,1,3,5,7,\dots can be described as {2k+1}k0\{2k+1\}_{k \ge 0}. This is basically a sum of elementary EGFs from Table 3.3, so (1+2z)ez(1+2z)e^z is the matching EGF.

The sequence 0,2,4,6,0,2,4,6,\dots can be described as {2k}k0\{2k\}_{k \ge 0}. This is 2x an elementary EGF from Table 3.3, so 2zez2ze^z is the matching EGF.

Exercise 3.11 🌟

A(z)=11zln11zA(z)=\frac{1}{1-z}\ln \frac{1}{1-z}

If we treat A(z)A(z) as an OGF, then the same EGF is its labelled counterpart. This immediately gives N![zN]A(z)=N!HNN![z^N]A(z)=N!H_N.


A(z)=ln211zA(z)=\ln^2 \frac{1}{1-z}

Using the same reasoing (see Exercise 3.8) we have N![zN]A(z)=2(N1)!HN1N![z^N]A(z)=2(N-1)!H_{N-1} for N>1N>1. For N1N \le1 the coefficients are zeros.


A(z)=ez+z2A(z)=e^{z+z^2}

Since ez+z2=ezez2e^{z+z^2} = e^z \cdot e^{z^2}, A(z)A(z) is a binomial sum operation applied on

B(z)=ez2=N0(2N)!N!z2N(2N)!.B(z)=e^{z^2}=\sum_{N\ge0}\cfrac{(2N)!}{N!}\cfrac{z^{2N}}{(2N)!}.

As in the case of the similar OGF from Table 3.1, odd entries are zero. Using the definition of a binomial sum operation from Table 3.4, we have

N![zN]A(z)=02kN(N2k)b2k(sum over nonzero entries)=0kN/2N!(N2k)!(2k)!(2k)!k!=0kN/2N!(N2k)!k!.\begin{align*} N![z^N]A(z)&=\sum_{0\le 2k\le N}\binom{N}{2k}b_{2k} && \text{(sum over nonzero entries)} \\ &=\sum_{0\le k\le \lfloor N/2 \rfloor}\frac{N!}{(N-2k)!(2k)!} \cdot \frac{(2k)!}{k!} \\ &= \boxed{\sum_{0\le k\le \lfloor N/2 \rfloor}\frac{N!}{(N-2k)!k!}}. \end{align*}

Exercise 3.12

Let’s follow the hint from the book. We start by differentiating (left shifting) the EGF for harmonic numbers

H(z)=N0HN+1zNN!.H'(z) = \sum_{N \ge 0} H_{N+1} \frac{z^N}{N!}.

We can setup the required differential equation by substituting the recurrence relation HN+1=HN+1N+1H_{N+1} = H_N + \frac{1}{N+1} into the sum. We have

H(z)=N0(HN+1N+1)zNN!=N0HNzNN!H(z)+N01N+1zNN!=H(z)+N0zN(N+1)!=H(z)+ez1z.\begin{align*} H'(z) &= \sum_{N \ge 0} \left( H_N + \frac{1}{N+1} \right) \frac{z^N}{N!} \\ &= \underbrace{\sum_{N \ge 0} H_N \frac{z^N}{N!}}_{H(z)} + \sum_{N \ge 0} \frac{1}{N+1} \frac{z^N}{N!} \\ &= H(z) + \sum_{N \ge 0} \frac{z^N}{(N+1)!} \\ &= H(z) + \frac{e^z-1}{z}. \end{align*}

To prove the statement from the book, we just need to follow the steps for solving a linear first-order differential equation with variable coefficients. Therefore,

H(z)=ez0z1ettdt.H(z) = e^z \int_0^z \frac{1 - e^{-t}}{t} \, dt.

H(z)=HNzNN!    N![zN]H(z)=HNH(z)=\sum H_N \frac{z^N}{N!} \implies N! [z^N]H(z)=H_N.

Exercise 3.13

By definition A(z)=k0akzkk!A(z)=\sum_{k\ge 0}a_k\cfrac{z^k}{k!}. We also know that

N![zN]B(z)=0kNN!akk!=0kN(Nk)ak(Nk)!,N![z^N]B(z)=\sum_{0 \le k \le N} N! \frac{a_k}{k!}=\sum_{0 \le k \le N} \binom{N}{k}a_k(N-k)!,

where B(z)B(z) is the unknown EGF. The last summation suggests that it’s a binomial convolution of A(z)A(z) and 1/(1z)1/(1-z). Hence,

B(z)=A(z)1z.B(z)=\frac{A(z)}{1-z}.

Exercise 3.14 🌟

By definition A(z)=k0akzkk!A(z)=\sum_{k\ge 0}a_k\cfrac{z^k}{k!}. Prove that

0A(zt)etdt=k0akzk,\int_0^\infty A(zt) e^{-t} \, dt=\sum_{k\ge 0} a_k z^k,

provided the integral exists. Check this for sequences that appear in Tables 3.1 and 3.3.


The proof revolves around computing the definite integral. We have

0A(zt)etdt=0(k0aktkzkk!)etdt=k0akzkk!0tketdtΓ(k+1)=k!(assuming convergence to flip  and )=k0akzkk!k!=k0akzk.\begin{align*} \int_0^\infty A(zt) e^{-t} \, dt &= \int_0^\infty \left( \sum_{k \ge 0} a_k t^k\frac{ z^k}{k!} \right) e^{-t} \, dt \\ &= \sum_{k \ge 0} a_k\frac{ z^k}{k!} \underbrace{\int_0^\infty t^k e^{-t} \, dt}_{\text{$\Gamma(k+1) = k!$}} && \text{(assuming convergence to flip $\sum$ and $\int$)} \\ &= \sum_{k \ge 0} a_k\frac{ z^k}{k!} \cdot k! \\ &= \sum_{k \ge 0} a_k z^k. \end{align*}

The second line uses the notion of a Gamma function (see also Exercise 4.60). This establishes the desired identity.

Examples

If A(z)=eczA(z)=e^{cz} then

0A(zt)etdt=0e(1cz)tdt=11cz.\begin{align*} \int_0^\infty A(zt) e^{-t} \, dt &= \int_0^\infty e^{-(1-cz)t} \, dt \\[0.4cm] &= \frac{1}{1-cz}. \end{align*}

Type the following snippet into Sage to evaluate the above integral:


If A(z)=zezA(z) =ze^z then

0zteztetdt=z(1z)2.\begin{align*} \int_0^\infty zte^{zt} e^{-t} \, dt &= \frac{z}{(1-z)^2}. \end{align*}

Type the following snippet into Sage to evaluate the above integral:

Exercise 3.15

We need to multiply the recurrence by zn/n!z_n/n! and sum on nn in the first step. Now, F(z)=k0Fkzkk!F(z)=\sum_{k\ge0} F_k \frac{z^k}{k!}, hence we get the following differential equation

F(z)=0zF(t)dt+0z(0zF(t)dt)dt+zF(z)=F(z)+F(z),\begin{align*} &F(z)=\int_0^z F(t)\,dt + \int_0^z \left(\int_0^z F(t)\, dt\right) \, dt +z\\ &F(z)''=F(z)'+F(z), \end{align*}

with initial conditions F(0)=F0=0F(0)=F_0=0 and F(0)=F1=1F'(0)=F_1=1. For the sake of variety. let’s solve it using WolframAlpha. After issuing the command y'' - y' - y = 0, y(0) = 0, y'(0) = 1 we get

F(z)=15(eϕzeϕ^z).F(z)=\frac{1}{\sqrt 5}(e^{\phi z}-e^{\hat\phi z}).

Exercise 3.16 🌟

We describe the process in detail for the first example. The extra summand, which makes a recurrence valid for all nn, is the Kronecker delta function.

an=an1+6an2 for n>1 with a0=0 and a1=1an=an1+6an2+δn11. Make it valid for all n.A(z)=zA(z)+6z2A(z)+z2. Multiply by zn and sum on n.=z1+z6z23. Solve.=z(12z)(1+3z)4. Simplify.=15(112z11+3z)an=152n15(3)n5. Expand.\begin{align*} a_n &= -a_{n-1} + 6a_{n-2} && \text{ for $n > 1$ with $a_0 = 0$ and $a_1 = 1$} \\ \hline \\ a_n &= -a_{n-1} + 6a_{n-2} + \delta_{n1} && \text{1. Make it valid for all $n$.} \\ A(z) &= -zA(z)+6z^2A(z)+z && \text{2. Multiply by $z^n$ and sum on $n$.} \\ &= \frac{z}{1+z-6z^2} && \text{3. Solve.} \\ &= \frac{z}{(1-2z)(1+3z)} && \text{4. Simplify.} \\ &= \frac{1}{5}\left(\frac{1}{1-2z}-\frac{1}{1+3z}\right) \\ &\therefore \boxed{a_n= \frac{1}{5}2^n-\frac{1}{5}(-3)^n} && \text{5. Expand.} \end{align*}

Performing a partial fractions expansion is easy in WolframAlpha. For example, issue Apart[z/(1 + z - 6z^2)] to simplify the polynomial expression in the 4th step (see above).


We use EGF for the next recurrence to demonstrate how it unfolds and to avoid technical difficulties in implementing partial fractions expansion due to unwieldy roots. Solving a homogeneous third-order linear ordinary differential equation with constant coefficients is essentially the same as solving the corresponding recurrence via roots of the characteristic polynomial. The resulting EGF is easily mapped to a closed-form solution.

an=11an26an3     for n>2 with a0=0 and a2=a1=1A(z)=11A(z)6A(z)    with A(0)=0,A(0)=1,A(0)=1...find the roots r1,r2,r3 of the characteristic equation z311z+6=0...A(z)=c0er1z+c1er2z+c2er3z...solve for constants based on initial conditions...=14e3z+1717136e(3+172)z+17+17136e(3172)zan=143n+1717136(3+172)n+17+17136(3172)n.\begin{align*} a_n &= 11a_{n-2} - 6a_{n-3} \space\space\space\space \text{ for $n > 2$ with $a_0 = 0$ and $a_2 = a_1 = 1$} \\ \hline \\ A'''(z) &= 11A'(z) - 6A(z) \space\space\space\space \text{with $A(0) = 0, A'(0) = 1, A''(0) = 1$} \\ &\text{...find the roots $r_1,r_2,r_3$ of the characteristic equation $z^3-11z+6=0$...} \\ A(z) &= c_0e^{r_1 z} + c_1 e^{r_2 z} + c_2 e^{r_3 z} \\ &\text{...solve for constants based on initial conditions...} \\ &=\frac{1}{4} e^{3z} + \frac{-17-\sqrt{17}}{136} e^{\left(\frac{-3+\sqrt{17}}{2}\right)z} + \frac{-17+\sqrt{17}}{136} e^{\left(\frac{-3-\sqrt{17}}{2}\right)z} \\ &\therefore \boxed{a_n = \frac{1}{4} \cdot 3^n + \frac{-17-\sqrt{17}}{136} \left(\frac{-3+\sqrt{17}}{2}\right)^n + \frac{-17+\sqrt{17}}{136} \left(\frac{-3-\sqrt{17}}{2}\right)^n}. \end{align*}

The next two examples have complex roots.

an=3an14an2     for n>1 with a0=0 and a1=1an=3an14an2+δn1A(z)=3zA(z)4z2A(z)+z=z13z+4z2=i7(11(3/2i7/2)z11(3/2+i7/2)z)an=i7((3i72)n(3+i72)n).\begin{align*} a_n &= 3a_{n-1}-4a_{n-2} \space\space\space\space \text{ for $n > 1$ with $a_0 = 0$ and $a_1 = 1$} \\ \hline \\ a_n &= 3a_{n-1}-4a_{n-2} + \delta_{n1} \\ A(z) &= 3zA(z)-4z^2A(z)+z \\ &= \frac{z}{1-3z+4z^2} \\ &= \frac{i}{\sqrt 7}\left(\frac{1}{1-(3/2-i\sqrt 7/2)z}-\frac{1}{1-(3/2+i\sqrt 7/2)z}\right) \\ &\therefore \boxed{a_n= \frac{i}{\sqrt 7}\left(\left(\frac{3-i\sqrt 7}{2}\right)^n-\left(\frac{3+i\sqrt 7}{2}\right)^n\right)} . \end{align*}

Using the technique illustrated in Exercise 2.31, we can convert the above expression into trigonometric form. Thus, an=2n+17sin(narccos(34))\boxed{a_n = \cfrac{2^{n+1}}{\sqrt{7}} \sin\left(n \arccos\left(\frac{3}{4}\right)\right)}.

an=an1an2     for n>1 with a0=0 and a1=1an=an1an2+δn1A(z)=zA(z)z2A(z)+z=z1z+z2=i3(11(1/2i3/2)z11(1/2+i3/2)z)an=i3((1i32)n(1+i32)n)\begin{align*} a_n &= a_{n-1}-a_{n-2} \space\space\space\space \text{ for $n > 1$ with $a_0 = 0$ and $a_1 = 1$} \\ \hline \\ a_n &= a_{n-1}-a_{n-2} + \delta_{n1} \\ A(z) &= zA(z)-z^2A(z)+z \\ &= \frac{z}{1-z+z^2} \\ &= \frac{i}{\sqrt 3}\left(\frac{1}{1-(1/2-i\sqrt 3/2)z}-\frac{1}{1-(1/2+i\sqrt 3/2)z}\right) \\ &\therefore \boxed{a_n= \frac{i}{\sqrt 3}\left(\left(\frac{1-i\sqrt 3}{2}\right)^n-\left(\frac{1+i\sqrt 3}{2}\right)^n\right)} \end{align*}

The trigonometric form is an=23sin(narccos(12))=23sin(nπ3)\boxed{a_n = \cfrac{2}{\sqrt{3}} \sin\left(n \arccos\left(\frac{1}{2}\right)\right)= \cfrac{2}{\sqrt{3}} \sin\left(n \frac{\pi}{3}\right)}.

Exercise 3.17 🌟

The book provides a solution for different initial conditions, but we can reuse some parts of it. More specifically,

g(z)=15z+8z24z3=(1z)(12z)2f(z)=(1+2z+4z2)g(z)modz3=13z+2z2=(1z)(12z)a(z)=f(z)g(z)=112z.\begin{align*} g(z) &= 1 –5z + 8z^2 – 4z^3 = (1 – z)(1 – 2z)^2 \\ f(z) &= (1+2z+4z^2)g(z) \mod z^3=1 -3z+2z^2 =(1-z)(1-2z)\\ a(z) &= \frac{f(z)}{g(z)} = \frac{1}{1 – 2z}. \end{align*}

This is an elementary OGF from Table 3.1. We have an=2n\boxed{a_n=2^n}.

Exercise 3.18

an=2an2an4     for n>3 with a0=a1=0 and a2=a3=1g(z)=12z2+z4=(1z)2(1+z)2f(z)=z2+z3=z2(1+z)a(z)=z2(1z)2(1+z)=z(1z)2z1+z.\begin{align*} a_n &= 2a_{n-2}-a_{n-4}\space\space\space\space \text{ for $n>3$ with $a_0=a_1=0$ and $a_2=a_3=1$} \\ \hline \\ g(z) &= 1-2z^2+z^4=(1-z)^2(1+z)^2 \\ f(z) &= z^2+z^3=z^2(1+z) \\ a(z) &= \frac{z^2}{(1-z)^2(1+z)} = \frac{z}{(1-z)^2} \cdot \frac{z}{1+z}. \end{align*}

The resulting OGF is a convolution of basic OGFs. We have

[zN]z(1z)2z1+z=1k<Nk(1)Nk1=14(1)N(2N(1)N(1)N+1)=N2.\begin{align*} [z^N]\frac{z}{(1-z)^2} \cdot \frac{z}{1+z} &= \sum_{1 \le k <N}k(-1)^{N-k-1} \\ &= \frac{1}{4} (-1)^N (2N (-1)^N - (-1)^N + 1) \\ &=\bigg \lfloor \frac{N}{2} \bigg\rfloor. \end{align*}

The above sum can be computed by entering Sum[k(-1)^(N-k-1),{k,1,N-1}] in WolframAlpha.

Exercise 3.19 🌟

g(z)=16z+12z218z3+27z4=(13z)2(1+3z2)f(z)=z5z2+7z3a(z)=z5z2+7z3(13z)2(1+3z2)=172(13z)+136(13z)2+19z124(1+3z2)=172(113z)+1z1336(3z(13z)2)+19z24(11(i3z)2)124(11(i3z)2).\begin{align*} g(z) &= 1-6z+12z^2-18z^3+27z^4=(1-3z)^2(1+3z^2) \\ f(z) &= z-5z^2+7z^3 \\ a(z) &= \frac{z-5z^2+7z^3}{(1-3z)^2(1+3z^2)}=\frac{1}{72(1-3z)} + \frac{1}{36(1-3z)^2} + \frac{19z - 1}{24(1+3z^2)} \\ &= \frac{1}{72} \cdot \left(\frac{1}{1-3z}\right) + \frac{1}{z} \cdot \frac{1}{3 \cdot 36} \cdot \left(\frac{3z}{(1-3z)^2}\right) + \frac{19z}{24} \cdot \left(\frac{1 }{1-(i\sqrt 3 z)^2}\right) - \frac{1}{24} \cdot \left(\frac{1}{1-(i\sqrt 3 z)^2}\right). \end{align*}

Again, tool support is indispensable. The decomposition of a(z)a(z) was done in WolframAlpha by issuing the Apart[(z - 5 z^2 + 7 z^3)/((1 - 3 z)^2 (1 + 3 z^2))] command.

The resulting OGF is a sum of scaled and/or shifted elementary OGFs. After simplifying terms, and reusing the analysis from the book about OGFs of the form 1/(1+z2)1/(1+z^2), we get

an=3n(2n+3)72+3n/224(193in1+(i)n12in+(i)n2)=3n(2n+3)72+3n/224(193sin(nπ2)cos(nπ2)).\begin{align*} a_n &= \dfrac{3^n(2n+3)}{72} + \dfrac{3^{n/2}}{24}\left(\dfrac{19}{\sqrt{3}} \cdot \dfrac{i^{n-1}+(-i)^{n-1}}{2}-\dfrac{i^n+(-i)^n}{2}\right) \\ &= \boxed{\dfrac{3^n(2n+3)}{72} + \dfrac{3^{n/2}}{24}\left(\dfrac{19}{\sqrt{3}}\sin\left(\dfrac{n\pi}{2}\right)-\cos\left(\dfrac{n\pi}{2}\right)\right)}. \end{align*}

Exercise 3.20

an=3an13an2+an3     for n>2 with a0=a1=0 and a2=1g(z)=13z+3z2z3=(1z)3f(z)=z2a(z)=z2(1z)3an=(n2).\begin{align*} a_n &= 3a_{n-1}-3a_{n-2}+a_{n-3} \space\space\space\space \text{ for $n>2$ with $a_0=a_1=0$ and $a_2=1$} \\ \hline \\ g(z) &= 1-3z+3z^2-z^3=(1-z)^3 \\ f(z) &= z^2 \\ a(z) &= \frac{z^2}{(1-z)^3} \\ &\therefore \boxed{a_n=\binom{n}{2}}. \end{align*}
an=3an13an2+an3     for n>2 with a0=0 and a2=a1=1g(z)=13z+3z2z3=(1z)3f(z)=z2z2a(z)=z2z2(1z)3=1zz2(1z)32z2(1z)3an=(n+12)2(n2)=n(3n)2.\begin{align*} a_n &= 3a_{n-1}-3a_{n-2}+a_{n-3} \space\space\space\space \text{ for $n>2$ with $a_0=0$ and $a_2=a_1=1$} \\ \hline \\ g(z) &= 1-3z+3z^2-z^3=(1-z)^3 \\ f(z) &= z-2z^2 \\ a(z) &= \frac{z-2z^2}{(1-z)^3} \\ &= \frac{1}{z} \cdot \frac{z^2}{(1-z)^3} - 2\frac{z^2}{(1-z)^3} \\ &\therefore \boxed{a_n=\binom{n+1}{2}-2\binom{n}{2}=\frac{n(3-n)}{2}}. \end{align*}

Exercise 3.21 🌟

Let A(z)=n0anznA(z)=\sum_{n\ge0} a_nz^n represent our sequence. We know that

[zn]A(z)={0if n<t1,1if n=t1,1kt(tk)(1)kankif nt.[z^n]A(z)=\begin{cases} 0 &\text{if } n<t-1, \\ 1 &\text{if } n=t-1, \\ -\sum_{1\le k \le t} \binom{t}{k}(-1)^ka_{n-k} & \text{if $n \ge t$}. \end{cases}

Looking at the form of the coefficient for ntn \ge t, it’s definitely a convolution of some OGF B(z)B(z) with A(z).A(z). Therefore, we have the following functional equation

A(z)=zt1B(z)A(z).A(z)=z^{t-1}-B(z)A(z).

Observe the term zt1z^{t-1}, which denotes the initial value at1=1a_{t-1}=1. The convolution only covers the case when ntn \ge t. The range of kk tells that the sequence represented with B(z)B(z) has the following values:

0,t,(t2),,(1)t1kt,0,0,\underbrace{-t,\binom{t}{2},\dots,(-1)^t}_{1 \le k \le t},0,\dots

By searching Table 3.1, it occurs that B(z)=(1z)t1B(z)=(1-z)^t-1, since it is a scaled elementary OGF with a leading zero. Thus,

A(z)=zt1(1z)t    an=(nt1)     for n0.A(z)=\frac{z^{t-1}}{(1-z)^t} \implies \boxed{a_n=\binom{n}{t-1} \space\space\space\space \text{ for $n \ge 0$}}.

Exercise 3.22 🌟

Let a(z)=n1anzna(z)=\sum_{n \ge 1}a_nz^n with an implicit assumption that a0=0a_0=0.

nan=(n2)an1+2     for n>1 with a1=1n2nanzn=n2(n2)an1zn+2n2znza(z)z=n2nan1zn2n2an1zn+2(11zz1)za(z)z=z(za(z))2za(z)+2z21za(z)1=a(z)+za(z)2a(z)+2z1z(1z)a(z)=a(z)+1+z1z.\begin{align*} na_n &= (n-2)a_{n-1}+2 \space\space\space\space \text{ for $n>1$ with $a_1=1$} \\ \hline \\ \sum_{n \ge 2}na_nz^n &= \sum_{n \ge 2}(n-2)a_{n-1}z^n+2\sum_{n \ge 2}z^n \\ za'(z)-z &= \sum_{n \ge 2}na_{n-1}z^n-2\sum_{n \ge 2}a_{n-1}z^n+2\left(\frac{1}{1-z}-z-1\right) \\ za'(z)-z &= z(za(z))'-2za(z)+2\frac{z^2}{1-z} \\ a'(z)-1 &= a(z)+za'(z)-2a(z)+2\frac{z}{1-z} \\ (1-z)a'(z) &= -a(z)+\frac{1+z}{1-z}. \end{align*}

We obtain the solution to this differential equation by solving the corresponding homogeneous equation

ϱ(z)ϱ(z)=11z,\frac{\varrho'(z)}{\varrho(z)}=-\frac{1}{1-z},

to get an “integration factor” ϱ(z)=1z\varrho(z)=1-z. This gives

(a(z)1z)=a(z)(1z)+a(z)(1z)2=1+z(1z)3.\begin{align*} \left(\frac{a(z)}{1-z}\right)' &= \frac{a'(z)(1-z)+a(z)}{(1-z)^2} \\ &= \frac{1+z}{(1-z)^3}. \end{align*}

Integrating (for example, by using WolframAlpha), we get the result

a(z)=z1z    an=1     for n>0.a(z)=\frac{z}{1-z} \implies \boxed{a_n=1 \space\space\space\space \text{ for $n>0$}}.

We’ve already encountered this recurrence in Exercise 2.11. This was another way to attain the same outcome.

Exercise 3.23

Let a(z)=n0anzna(z)=\sum_{n \ge 0}a_nz^n. Assume that tt is an integer.

nan=(n+t1)an1     for n>0 with a0=1n1nanzn=n1(n+t1)an1znza(z)=n1nan1zn+(t1)n1an1znza(z)=z(za(z))+(t1)za(z)za(z)=z2a(z)+za(z)+(t1)za(z)a(z)=za(z)+a(z)+(t1)a(z)a(z)=za(z)+ta(z)a(z)a(z)=t1za(z)=1(1z)t=1zt1zt1(1z)t.\begin{align*} na_n &= (n+t-1)a_{n-1} \space\space\space\space \text{ for $n>0$ with $a_0=1$} \\ \hline \\ \sum_{n \ge 1}na_nz^n &= \sum_{n \ge 1}(n+t-1)a_{n-1}z^n \\ za'(z) &= \sum_{n \ge 1}na_{n-1}z^n+(t-1)\sum_{n \ge 1}a_{n-1}z^n \\ za'(z) &= z(za(z))'+(t-1)za(z) \\ za'(z) &= z^2a'(z)+za(z)+(t-1)za(z) \\ a'(z) &= za'(z)+a(z)+(t-1)a(z) \\ a'(z) &= za'(z)+ta(z) \\ \frac{a'(z)}{a(z)} &= \frac{t}{1-z} \\ &\therefore a(z) = \frac{1}{(1-z)^t}=\frac{1}{z^{t-1}} \cdot \frac{z^{t-1}}{(1-z)^t}. \end{align*}

Thus, a(z)a(z) is an elementary OGF, left shifted t1t-1 times. This gives

an=(n+t1n) for n>0.\boxed{a_n=\binom{n+t-1}{n} \qquad \text{ for $n > 0$}}.

Observe that the formula for ana_n nicely captures the case when t0t \le 0 by the properties of a generalized version of the binomial theorem known as Newton’s formula. Such generalization popped out for "free" due to reliance on GFs.

Exercise 3.24

Fast forwarding the analysis from the book, our recurrence relationship corresponds to a differential equation on the generating function

a(z)=2(1z)3+ta(z)1z.a'(z)=\frac{2}{(1-z)^3}+t\frac{a(z)}{1-z}.

We obtain the solution to this differential equation by solving the corresponding homogeneous equation

ϱ(z)ϱ(z)=t1z,\frac{\varrho'(z)}{\varrho(z)}=\frac{t}{1-z},

to get an “integration factor” ϱ(z)=1/(1z)t\varrho(z)=1/(1-z)^t. This gives

((1z)ta(z))=(1z)ta(z)t(1z)t1a(z)=(1z)t(a(z)ta(z)1z)=2(1z)t3.\begin{align*} ((1-z)^ta(z))' &= (1-z)^ta'(z)-t(1-z)^{t-1}a(z) \\ &= (1-z)^t\left(a'(z)-t\frac{a(z)}{1-z}\right) \\ &= 2(1-z)^{t-3}. \end{align*}

Integrating (for example, by using WolframAlpha), we get the result (recall that a(0)=a0=0a(0)=a_0=0)

a(z)=2t21(1z)2+2t21(1z)t.a(z) = \frac{-2}{t-2} \cdot \frac{1}{(1-z)^2} + \frac{2}{t-2} \cdot \frac{1}{(1-z)^t}.

The first term is a left shifted elementary OGF, so it’s coefficient is proportional to n n. The second term is t1t-1 times left shifted elementary OGF from Table 3.1, so behaves like (n+t1t1)nt1\binom{n+t-1}{t-1} \sim n^{t-1}. We differentiate two cases:

  1. If t=2ϵt=2-\epsilon, then an=Θ(n)=o(nlgn)a_n=\Theta(n)=o(n\lg n).

  2. If t=2+ϵt=2+\epsilon, then an=Θ(n1+ϵ)=ω(nlgn)a_n=\Theta(n^{1+\epsilon})=\omega(n\lg n).

The threshold t=2t=2 is a bifurcation point, where even a tiny disturbance entails an asymptotically different behavior.

Exercise 3.25

Expansion of sin(z)\sin(z)

We have to find the derivatives of sin(z)\sin(z):

sin(z)=cos(z)sin(z)=sin(z)sin(z)=cos(z)sin(4)(z)=sin(z).\begin{align*} \sin'(z) &= \cos(z) \\ \sin''(z) &= -\sin(z) \\ \sin'''(z) &= -\cos(z) \\ \sin^{(4)}(z) &= \sin(z). \end{align*}

Since sin(4)(z)=sin(z)\sin^{(4)}(z) = \sin(z), this pattern repeats. We also know that sin(0)=0\sin(0)=0 and cos(0)=1\cos(0)=1. Thus, we get

sin(z)=zz33!+z55!z77!+=k0(1)k(2k+1)!z2k+1.\begin{align*} \sin(z) &= z-\frac{z^3}{3!}+\frac{z^5}{5!}-\frac{z^7}{7!} + \dots \\ &= \sum_{k \ge 0} \frac{(-1)^k}{(2k+1)!}z^{2k+1}. \end{align*}

Expansion of 2z2^z

We already know the result for the exponential sequence. Since 2z=eln2z=ezln22^z=e^{\ln 2^z}=e^{z\ln2}, substitute z=zln2z=z\ln 2 into the formula from the book. So,

2z=k0lnk2k!zk.2^z=\sum_{k \ge 0} \frac{\ln^k 2}{k!}z^k.

Expansion of zezze^z

Multiply each term on the RHS of the expansion of eze^z with zz. This gives

zez=k1zk(k1)!.ze^z=\sum_{k \ge 1}\frac{z^k}{(k-1)!}.

Exercise 3.26 🌟

Let’s develop some intuition about the stated recurrence for coefficients. Tools are excellent in performing exploratory tasks like this. Issuing taylor series 1/(1-az-bz^2) in WolframAlpha gives us the terms of the expansion:

1+az+(a2+b)z2+(a3+2ab)z3+(a4+3a2b+b2)z4+(a5+4a3b+3ab2)z5+1 + a z + (a^2 + b)z^2 + (a^3 + 2 a b) z^3+ (a^4 + 3 a^2 b + b^2)z^4 + (a^5 + 4 a^3 b + 3 a b^2)z^5 + \dots

Let cnc_n denote the nnth coefficient. It seems to satisfy a second-order linear recurrence with constant coefficients

cn=acn1+bcn2     for n>1 with c0=1 and c1=a.c_n=ac_{n-1}+bc_{n-2} \space\space\space\space \text{ for $n>1$ with $c_0=1$ and $c_1=a$.}

Now, we’ve to show that this holds for all n>1n>1. Let f(z)=(1azbz2)1f(z) = (1 - az - bz^2)^{-1}, so that

cn=f(n)(0)n!.c_n = \frac{f^{(n)}(0)}{n!}.

We aim to establish a relationship between the derivatives f(n)(0)f^{(n)}(0), f(n1)(0)f^{(n-1)}(0) and f(n2)(0)f^{(n-2)}(0). Let’s rewrite our original expression as

f(z)(1azbz2)g(z)=1.f(z)\underbrace{ (1 - az - bz^2)}_{g(z)}=1.

Notice that since g(z)g(z) is a polynomial of degree 2, its derivatives vanish for n>2n>2:

g(0)(z)=1azbz2g(1)(z)=a2bzg(2)(z)=2bg(n)(z)=0(for all n3).\begin{align*} g^{(0)}(z) &= 1 - az - bz^2 \\ g^{(1)}(z) &= -a - 2bz \\ g^{(2)}(z) &= -2b \\ g^{(n)}(z) &= 0 && \text{(for all $n \ge 3$)}. \end{align*}

Differentiating the equation f(z)g(z)=1f(z)g(z) = 1 nn times (where n2n \ge 2) gives:

(n0)f(n)(z)g(0)(z)+(n1)f(n1)(z)g(1)(z)+(n2)f(n2)(z)g(2)(z)=0.\binom{n}{0} f^{(n)}(z) g^{(0)}(z) + \binom{n}{1} f^{(n-1)}(z) g^{(1)}(z) + \binom{n}{2} f^{(n-2)}(z) g^{(2)}(z) = 0.

Evaluated at z=0z=0 gives

f(n)(0)anf(n1)(0)bn(n1)f(n2)(0)=0f(n)(0)n!cnaf(n1)(0)(n1)!cn1bf(n2)(0)(n2)!cn2=0(dividing by n!)\begin{align*} f^{(n)}(0) - a \cdot n \cdot f^{(n-1)}(0) - b \cdot n(n-1) \cdot f^{(n-2)}(0) &= 0 \\ \underbrace{\frac{f^{(n)}(0)}{n!}}_{c_n}- a \underbrace{\frac{f^{(n-1)}(0)}{(n-1)!}}_{c_{n-1}}-b \underbrace{\frac{f^{(n-2)}(0)}{(n-2)!}}_{c_{n-2}} &=0 && \text{(dividing by $n!$)} \end{align*}

This concludes the proof about the recurrence relation for coefficients.

Exercise 3.27

As in the previous exercise, we rely on the general Leibniz rule. Our starting point is

H(z)=11zf(z)ln11zg(z).H(z)=\underbrace{\frac{1}{1-z}}_{f(z)} \cdot \underbrace{\ln\frac{1}{1-z}}_{g(z)}.

We have to find cn=H(n)(0)/n!c_n=H^{(n)}(0)/n!. Notice that g(z)=f(z)    g(n1)(0)=f(n)(0)g'(z)=f(z) \implies g^{(n-1)}(0)=f^{(n)}(0). We also know from the book that the kkth derivative of f(z)f(z) is k!(1z)k1k!(1-z)^{-k-1}. Consequently, f(k)(0)=k!f^{(k)}(0)=k!. Finally, g(0)(0)=g(0)=0g^{(0)}(0)=g(0)=0, so the summation in the Leibniz rule starts at index k=1k=1. Combining all these facts, we have

n!cn=1kn(nk)f(nk)(0)g(k)(0)=1kn(nk)f(nk)(0)f(k1)(0)=1knn!k!(nk)!(nk)!(k1)!=1knn!kcn=1kn1k=Hn.\begin{align*} n! \cdot c_n &= \sum_{1 \le k \le n} \binom{n}{k} f^{(n-k)}(0)g^{(k)}(0) \\ &= \sum_{1 \le k \le n} \binom{n}{k} f^{(n-k)}(0)f^{(k-1)}(0) \\ &= \sum_{1 \le k \le n} \frac{n!}{k!(n-k)!} \cdot (n-k)!(k-1)! \\ &= \sum_{1 \le k \le n} \frac{n!}{k} \\ &\therefore \boxed{c_n = \sum_{1 \le k \le n} \frac{1}{k} = H_n}. \end{align*}

Exercise 3.28 🌟

Let’s expand (1z)α(1-z)^{-\alpha} using Newton’s formula

[zn](1z)α=α(α+1)(α+n1)n!=(n+α1n)=k=0n1α+kk+1.\begin{align*} [z^n](1-z)^{-\alpha} &= \frac{\alpha(\alpha+1)\cdots(\alpha+n-1)}{n!} \\ &= \binom{n+\alpha-1}{n} \\ &= \prod_{k=0}^{n-1} \frac{\alpha + k}{k+1}. \end{align*}

Observe that -1 from the negative exponent and -1 of zz cancel during derivations.

According to the hint, we should differentiate both sides with respect to α\alpha. The LHS is

ddα[(1z)α]=ddα[eln(1z)α]=ddα[eαln(1z)1]=eαln(1z)1ln(1z)1=(1z)αln11z.\begin{align*} \frac{d}{d\alpha} \left[(1-z)^{-\alpha}\right] &= \frac{d}{d\alpha} \left[e^{\ln (1-z)^{-\alpha}}\right] \\ &= \frac{d}{d\alpha} \left[e^{\alpha{\ln {(1-z)^{-1}}}}\right] \\ &= e^{\alpha{\ln (1-z)^{-1}}}\ln (1-z)^{-1} \\ &= (1-z)^{-\alpha} \ln \frac{1}{1-z}. \end{align*}

For the RHS, we’ll first convert the product into a sum using the natural logarithm. This gives

ln(n+α1n)=k=0n1ln(α+k)ln(k+1)ddα[ln(n+α1n)]=k=0n1ddα[ln(α+k)]01(n+α1n)ddα[(n+α1n)]=k=0n11α+kddα[(n+α1n)]=(n+α1n)k=0n11α+k=(n+α1n)(Hn+α1Hα1).\begin{align*} \ln\binom{n+\alpha-1}{n} &= \sum_{k=0}^{n-1} \ln(\alpha + k) - \ln(k+1) \\ \frac{d}{d\alpha} \left[ \ln\binom{n+\alpha-1}{n} \right] &= \sum_{k=0}^{n-1} \frac{d}{d\alpha} [\ln(\alpha + k) ]-0 \\ \frac{1}{\binom{n+\alpha-1}{n}} \cdot \frac{d}{d\alpha} \left[\binom{n+\alpha-1}{n} \right] &= \sum_{k=0}^{n-1} \frac{1}{\alpha + k} \\ \frac{d}{d\alpha} \left[\binom{n+\alpha-1}{n} \right] &= \binom{n+\alpha-1}{n} \sum_{k=0}^{n-1} \frac{1}{\alpha + k} \\ &= \binom{n+\alpha-1}{n} \left(H_{n+\alpha-1}-H_{\alpha-1}\right). \end{align*}

Therefore,

[zn]1(1z)αln11z=(n+α1n)(Hn+α1Hα1).\boxed{[z^n]\frac{1}{(1-z)^{\alpha}} \ln \frac{1}{1-z}=\binom{n+\alpha-1}{n} \left(H_{n+\alpha-1}-H_{\alpha-1}\right)}.

As a quick check, for α=2\alpha=2 we indeed get the expansion of a left shifted OGF from Table 3.1.

In our case, α=1/2\alpha=1/2. This gives

[zn]11zln11z=(n12n)(Hn12H12).[z^n]\frac{1}{\sqrt{1-z}} \ln \frac{1}{1-z} = \binom{n-\frac{1}{2}}{n} \bigl(H_{n-\frac{1}{2}} - H_{-\frac{1}{2}}\bigr).

We can use the identity below, pertaining to the generalized binomial coefficients, to simplify the first term in the RHS. The book already shows the derivation of (12n)\binom{-\frac{1}{2}}{n}.

(n12n)=(1)n(12n)=14n(2nn).\binom{n-\frac{1}{2}}{n} = (-1)^n \binom{-\frac{1}{2}}{n}=\frac{1}{4^n} \binom{2n}{n}.

The digamma function provides a continuous interpolation of the harmonic numbers. As stated on Wikipedia about it’s relation to harmonic numbers, we have

Hn12=ψ ⁣(n+12)+γ=2ln2+2H2nHnH12=ψ ⁣(12)+γ=2ln2.\begin{align*} H_{n-\frac{1}{2}} &= \psi\!\left(n+\frac{1}{2}\right) + \gamma= - 2\ln 2 + 2H_{2n} - H_n \\ H_{-\frac{1}{2}} &= \psi\!\left(\frac{1}{2}\right) + \gamma=-2\ln 2. \end{align*}

After bundling together all components, we get

[zn]11zln11z=14n(2nn)(2H2nHn).\boxed{[z^n]\frac{1}{\sqrt{1-z}} \ln \frac{1}{1-z} = \frac{1}{4^n} \binom{2n}{n} \bigl(2H_{2n} - H_n\bigr)}.

Exercise 3.29

We already have an expression for a generic parameter α\alpha (see the previous exercise). Thus,

[zn]1(1z)tln11z=(n+t1n)(Hn+t1Ht1).\boxed{[z^n]\frac{1}{(1-z)^{t}} \ln \frac{1}{1-z}=\binom{n+t-1}{n} \left(H_{n+t-1}-H_{t-1}\right)}.

Exercise 3.30

[zN]114z114z=[zN]114z.[z^N]\frac{1}{\sqrt {1-4z}} \cdot \frac{1}{\sqrt {1-4z}}=[z^N]\frac{1}{1-4z}.

Both OGFs are elaborated in the book.

Exercise 3.31

The differential equation (3) corresponds to (1), which is the basic recurrence describing the number of comparisons used by quicksort. Multiplying (3) by (1z)2(1-z)^2 is equivalent to differencing the coefficients twice in succession. We get

NCN(N1)CN1((N1)CN1(N2)CN2)[zN1](1z)2C(z)=N(N+1)(N1)N((N1)N(N2)(N1))[zN1](1z)22(1z)3+21kNCk121kN1Ck1(21kN1Ck121kN2Ck1)[zN1](1z)22C(z)(1z)NCN2(N1)CN1+(N2)CN2=2+2(CN1CN2)CN=2CN1CN2+2Nfor N>1.\begin{align*} \underbrace{NC_N-(N-1)C_{N-1}-((N-1)C_{N-1}-(N-2)C_{N-2})}_{[z^{N-1}](1-z)^2C'(z)}&= \underbrace{N(N+1)-(N-1)N-((N-1)N-(N-2)(N-1))}_{[z^{N-1}](1-z)^2\frac{2}{(1-z)^3}}\\ & \hspace{1cm}+\underbrace{2\sum_{1 \le k \le N} C_{k-1}-2\sum_{1 \le k \le N-1} C_{k-1}-\left(2\sum_{1 \le k \le N-1} C_{k-1}-2\sum_{1 \le k \le N-2} C_{k-1}\right)}_{[z^{N-1}](1-z)^2\frac{2C(z)}{(1-z)}} \\ NC_N-2(N-1)C_{N-1}+(N-2)C_{N-2} &= 2+2(C_{N-1} -C_{N-2})\\ &\therefore \boxed{C_N= 2C_{N-1}-C_{N-2}+\frac{2}{N}} \qquad \text{for $N>1$}. \end{align*}

We could have arrived at the same result iteratively by factoring (1z)2=(1z)(1z)(1-z)^2=(1-z)(1-z). Notice that we’re referencing the (N1)(N-1)th coefficient. This is due to the simplified equation (3) in the book, where zz was removed on both sides.

Exercise 3.32

Let A(z)=n0anznA(z)=\sum_{n \ge 0}a_nz^n. The initial differential equation corresponds to the recurrence

(n+1)an+1=an+0knak(for n0)=an+an+0k<nak(n+1)an+1=0k<nak.\begin{align*} (n+1)a_{n+1}&=-a_n+\sum_{0 \le k \le n} a_k && \text{(for $n\ge0$)} \\ &= -a_n+a_n+\sum_{0 \le k < n} a_k \\ &\therefore \boxed{(n+1)a_{n+1}=\sum_{0 \le k < n} a_k}. \end{align*}

If we multiply both sides of the equation by (1z)(1-z) then we get

(n+1)an+1nan=(anan1)+an(for n>0)=an1(n+1)an+1=nan+an1.\begin{align*} (n+1)a_{n+1}-na_n&=-(a_n-a_{n-1})+a_n && \text{(for $n>0$)} \\ &= a_{n-1} \\ &\therefore \boxed{(n+1)a_{n+1}=na_n+a_{n-1}}. \end{align*}

This recurrence is describing probabilities of derangements. If we substitute an=dn/n!a_n=d_n/n!, simplify factorials, multiply through by n!n!, then we get MathWorld's equation (5) with the index shifted by 1 (see the previous link). The equivalent equation (6) can be solved using the method presented in Exercise 2.14. We would arrive at the same result, as shown below.


An easier path is to directly find the OGF and expand.

A(z)A(z)=z1zA(z)=ez11z(A(0)=1).\begin{align*} \frac{A'(z)}{A(z)} &= \frac{z}{1-z} \\ &\therefore A(z) = e^{-z} \cdot \frac{1}{1-z} && \text{($A(0)=1$)}. \end{align*}

This gives

[zn]A(z)=an=0kn(1)kk!.[z^n]A(z)=a_n=\sum_{0 \le k \le n} \frac{(-1)^k}{k!}.

Exercise 3.33 🌟

The LHS is the convolution of two series (see Table 3.1):

(1+z)r=k0(rk)zkand(1z)s=k0(sk)(1)kzk.(1 + z)^r = \sum_{k \ge 0} \binom{r}{k} z^k \quad \text{and} \quad (1 - z)^s = \sum_{k \ge 0} \binom{s}{k} (-1)^k z^k.

The RHS is also a convolution of two series:

(1z2)s=k0(sk)(1)kz2kand(1+z)rs=k0(rsk)zk.(1 - z^2)^s = \sum_{k \ge 0} \binom{s}{k} (-1)^k z^{2k} \quad \text{and} \quad (1 + z)^{r-s} = \sum_{k \ge 0} \binom{r-s}{k} z^k.

By equating [zn][z^n] from both sides, we obtain the identity:

k=0n(1)k(sk)(rnk)=k=0n/2(1)k(sk)(rsn2k).\sum_{k=0}^n (-1)^k \binom{s}{k} \binom{r}{n-k} = \sum_{k=0}^{\lfloor n/2 \rfloor} (-1)^k \binom{s}{k} \binom{r-s}{n-2k}.

What’s the benefit of this identity? Albeit both sides being semantically equivalent, the RHS effectively halves the computation time.When rr and ss are real numbers, then accuracy is potentially increased, as well.

Exercise 3.34

[zt]zs(1z)s+1zr(1z)r+1=[zt]1zzr+s+1(1z)r+s+2.[z^t]\frac{z^s}{(1-z)^{s+1}} \cdot \frac{z^r}{(1-z)^{r+1}}=[z^t]\frac{1}{z} \cdot \frac{z^{r+s+1}}{(1-z)^{r+s+2}}.

Exercise 3.35

We need to compute 0kNFk\sum_{0 \le k\le N} F_k. The book contains the OGF for Fibonacci numbers

F(z)=z1zz2,F(z)=\frac{z}{1-z-z^2},

where [zN]F(z)=FN[z^N]F(z)=F_N. Observe that the sum of Fibonacci numbers can be represented as a partial sum of F(z)F(z). This gives

F(z)1z=z1zz211z=11zz2FN+1+z1zz2FN11z1(via partial fractions expansion)0kNFk=FN+21.\begin{align*} \frac{F(z)}{1-z} &= \frac{z}{1-z-z^2} \cdot \frac{1}{1-z} \\[0.4cm] &= \underbrace{\frac{1}{1-z-z^2}}_{F_{N+1}}+\underbrace{\frac{z}{1-z-z^2}}_{F_{N}}-\underbrace{\frac{1}{1-z}}_{1} && \text{(via partial fractions expansion)} \\ &\therefore \boxed{\sum_{0 \le k \le N} F_k=F_{N+2}-1}. \end{align*}

Exercise 3.36

Wikipedia contains a derivation of the sum expression for [zm]-[z^m] as part of the proof. The generating function in this exercise is a negative of the one associated with Bernoulli numbers.

Exercise 3.37

The idea is to employ substitution, as for Fibonacci numbers in the book, and afterward transform the substituted term with another power series. We have

12ez=1211ez2y=12k0yk=k0ekz2k+1=k012k+1(n0knn!zn)(ez=n0znn!)=n0(1n!k0kn2k+1[zn]12ez)zn.\begin{align*} \frac{1}{2 - e^z} &= \frac{1}{2} \cdot \frac{1}{1 - \undergroup{\cfrac{e^z}{2}}}_{y} \\[0.9cm] &= \frac{1}{2} \sum_{k \ge 0} y^k \\ &= \sum_{k \ge 0} \cfrac{e^{kz}}{2^{k+1}} \\ &= \sum_{k \ge 0} \frac{1}{2^{k+1}} \left( \sum_{n \ge 0} \frac{k^n}{n!} z^n \right) && \text{$\left(e^z = \sum_{n \ge 0} \frac{z^n}{n!}\right)$} \\ &= \sum_{n \ge 0} \left( \underbrace{\frac{1}{n!}\sum_{k \ge 0} \frac{k^n}{2^{k+1}}}_{[z^n]\frac{1}{2 - e^z}} \right) z^n. \end{align*}

If we treat the generating function from this exercise as an EGF, then it describes the ordered Bell numbers.

Exercise 3.38

We employ the same approach as in the previous exercise. This gives

eez1=e1eezy=e1ey=k0e1ykk!=k0e1ekzk!=k0e11k!(n0knn!zn)=n0(e1k0knk!n![zn]eez1)znn!.\begin{align*} e^{e^z-1} &= e^{-1}e^{\undergroup{e^z}_{y}} \\ &= e^{-1}e^y \\ &= \sum_{k \ge 0} e^{-1} \frac{y^k}{k!} \\ &= \sum_{k \ge 0} e^{-1} \frac{e^{kz}}{k!} \\ &= \sum_{k \ge 0} e^{-1} \frac{1}{k!} \left(\sum_{n \ge 0} \frac{k^n}{n!}z^n\right) \\ &= \sum_{n \ge 0} \left(\underbrace{e^{-1}\sum_{k \ge 0} \frac{k^n}{k!}}_{n![z^n]e^{e^z-1}}\right) \frac{z^n}{n!}. \end{align*}

The expression for the coefficient of the corresponding EGF is known as Dobiński's formula.

Exercise 3.39

Let A(z)=nanznA(z)=\sum_n a_nz^n. We need to show that

[zn]B(z)=k(nk)ak(1)kB(z)=11zA(zz1)=11zA(z1z)=11znan(z1z)n=11znan(1)nzn(1z)n=nan(1)nzn(1z)n+1=nan(1)nkn(kn)zk=n(k(nk)ak(1)k)zn.\begin{align*} [z^n]B(z) &= \sum_{k} \binom{n}{k} a_k (-1)^k \\ \hline \\ B(z) &= \frac{1}{1-z}A\left(\frac{z}{z-1}\right) \\ &= \frac{1}{1-z}A\left(-\frac{z}{1-z}\right) \\ &= \frac{1}{1-z} \sum_n a_n \left(-\frac{z}{1-z}\right)^n \\ &= \frac{1}{1-z} \sum_n a_n (-1)^n \frac{z^n}{(1-z)^n} \\ &= \sum_n a_n (-1)^n \frac{z^n}{(1-z)^{n+1}} \\ &= \sum_n a_n (-1)^n \sum_{k \ge n} \binom{k}{n} z^k \\ &= \sum_n \left(\undergroup{\sum_{k} \binom{n}{k} a_k (-1)^k} \right) z^n. \end{align*}

To understand the last step, fix knk\ge n. The coefficient [zk][z^k] will "accumulate" contributions from all nkn\le k. Swapping the roles of nn and kk gives us the desired expression.


If we substitute z=y/(y1)z=y/(y-1), then we get

A(y)=11yB(yy1),A(y) = \frac{1}{1-y}B\left(\frac{y}{y-1}\right),

which, by symmetry, validates the opposite direction.

Exercise 3.40

Wikipedia contains an analysis of the binomial transform including the sketch of the proof without using generating functions. More formally, suppose we start with an arbitrary sequence {an}\{a_n\}. We can generate another sequence {bn}\{b_n\} from it

bn=k=0n(nk)(1)kak    bn=(1)nΔna0,b_n = \sum_{k=0}^{n} \binom{n}{k} (-1)^ka_k \iff b_n = (-1)^n \Delta^n a_0,

where Δ\Delta is the forward difference operator, as mentioned in Chapter 2 of the book, defined by Δan=an+1an\Delta a_n = a_{n+1} - a_n. The nnth forward difference at index 0 is given by:

Δna0=k=0n(nk)(1)nkak.\Delta^n a_0 = \sum_{k=0}^{n} \binom{n}{k} (-1)^{n-k} a_k.

Multiplying both sides by (1)n(-1)^n yields the previously stated equivalence.


The transformation is symmetrical and an=k=0n(nk)(1)kbka_n = \sum_{k=0}^{n} \binom{n}{k} (-1)^k b_k . We can see this by introducing the shift operator an+1=Ean=Ian+Δan=(I+Δ)ana_{n+1}=Ea_n=Ia_n+\Delta a_n=(I+\Delta)a_n, where II is an identity operator. We want to express ana_n in terms of applying the shift operator nn times to a0a_0. This gives

an=Ena0=(I+Δ)na0=k=0n(nk)Δka0=k=0n(nk)(1)kbk.a_n = E^n a_0 = (I + \Delta)^na_0 = \sum_{k=0}^{n} \binom{n}{k} \Delta^k a_0= \sum_{k=0}^{n} \binom{n}{k} (-1)^kb_k.

Observe, that IkΔnk=ΔnkI^k\Delta^{n-k}=\Delta^{n-k}. This concludes the proof.

Exercise 3.41 🌟

Wikipedia contains the formal power series version of the Faà di Bruno’s formula, based on the application of the multinomial theorem. An important detail is the precondition g(0)=0g(0)=0, which makes the composition valid.

Exercise 3.42

Let’s follow the hint from the book and find a differential equation satisfied by the function

f(z)=ez+z2/2f(z)=ez+z2/2(1+z)=f(z)(1+z).\begin{align*} f(z) &= e^{z+z^2/2} \\ \hline \\ f'(z) &= e^{z+z^2/2}(1+z)=f(z)(1+z). \end{align*}

Using Table 3.4, we can convert the above differential equation into recurrence relation on coefficients. This gives

fn+1=fn+nfn1(for n1)fn=fn1+(n1)fn2(for n2).\begin{align*} f_{n+1} &= f_n+nf_{n-1} && \text{(for $n \ge 1$)} \\ f_n &= f_{n-1}+(n-1)f_{n-2} && \text{(for $n \ge 2$)}. \end{align*}

Exercise 3.43

Let f(z)=nfnznn!f(z)=\sum_n f_n \frac{z^n}{n!}, thus f(z/2)=nfn2nznn!f(z/2)=\sum_n \frac{f_n}{2^n} \frac{z^n}{n!}. Then, provided that f(0)=1f(0)=1, we must have

f(z)=ezf(z2)+e2z1=ez(ez2f(z4)+ez1)+e2z1=ez(ez2(ez4f(z8)+ez21)+ez1)+e2z1=e2ze2z+1+e2z1=e2z.\begin{align*} f(z) &= e^{-z}f\left(\frac{z}{2}\right)+e^{2z}-1 \\ &= e^{-z}(e^{-\frac{z}{2}}f\left(\frac{z}{4}\right)+e^z-1)+e^{2z}-1 \\ &=\undergroup{e^{-z}(e^{-\frac{z}{2}}(e^{-\frac{z}{4}}f\left(\frac{z}{8}\right)+e^{\frac{z}{2}}-1)+e^z-1)}+e^{2z}-1 \\ &\dots \\ &= e^{-2z}-e^{-2z}+1+e^{2z}-1 \\ &= e^{2z}. \end{align*}

Let’s dissect in detail the grouped section, to reveal the pattern. The leading term is similar to the example from the book, just with an opposite sign. This provides the first e2ze^{-2z} summand. The following steps are done from inside out

ez(ez2(+ez21)+ez1)=ez(+1ez2+ez1)=ez(ez2+ez)=ez2z+1.\begin{align*} e^{-z}(e^{-\frac{z}{2}}(\dots+e^{\frac{z}{2}}-1)+e^z-1) &= e^{-z}(\dots+1-e^{-\frac{z}{2}}+e^z-1) \\ &= e^{-z}(\dots-e^{-\frac{z}{2}}+e^z) \\ &= \dots\undergroup{-e^{-\frac{z}{2}-z}}+1. \end{align*}

Continuing these iterations will result in a geometric progression that sums to e2ze^{-2z}. The constant terms annihilate leaving +1 at the end. This cancels the -1 in the original formula. As mentioned in the book, technically, we need to justify carrying out the iteration indefinitely, but the solution is easily verified from the original recurrence. Indeed, replacing f(z)=e2zf(z)=e^{2z} verifies this statement.

Therefore, the recurrence relation and its solution are

fn=2n+k(1)nk(nk)fk2k=2n    for n>0 with f0=1.f_n=2^n+\sum_k (-1)^{n-k}\binom{n}{k}\frac{f_k}{2^k}=2^n \space\space\space\space \text{for $n>0$ with $f_0=1$.}

Observe that -1 (from the initial expression) disappears, since it doesn’t influence coefficients for n>0n>0. The sum evaluates to zero (recall that fk=2kf_k=2^k) as stated on Wikipedia about partial sums of binomial coefficients.

Exercise 3.44 🌟

Since the recurrence relations distinguish between even and odd indices, let’s split f(z)f(z) accordingly

f(z)=k0fkzk=n0f2nz2nfe(z)+n0f2n+1z2n+1fo(z).f(z) = \sum_{k\ge0} f_k z^k=\underbrace{\sum_{n\ge0} f_{2n} z^{2n}}_{f_e(z)} + \underbrace{\sum_{n\ge0}f_{2n+1} z^{2n+1}}_{f_o(z)}.

We can write the odd part as

fo(z)=f1z+n1f2n+1z2n+1=z+n1f2nz2n+1(f1=1 and f2n+1=f2n)=z+zn1f2nz2n=z+zn0f2nz2n(f0=0 so we can start n at 0)fo(z)=z+zfe(z).\begin{align*} f_o(z) &= f_1 z + \sum_{n\ge1} f_{2n+1} z^{2n+1} \\ &= z + \sum_{n\ge1} f_{2n} z^{2n+1} && \text{($f_1 = 1$ and $f_{2n+1} = f_{2n}$)} \\ &= z + z \sum_{n\ge1} f_{2n} z^{2n} \\ &= z + z \sum_{n\ge0} f_{2n} z^{2n} && \text{($f_0 = 0$ so we can start $n$ at 0)} \\ &\therefore \boxed{f_o(z)=z + z f_e(z)}. \end{align*}

We can write the even part as

fe(z)=f0+n1f2nz2n=n1(f2n1+fn)z2n=n1f2n1z2nS1+n1fnz2nS2,\begin{align*} f_e(z) &= f_0 + \sum_{n\ge1} f_{2n} z^{2n} \\ &= \sum_{n\ge1} (f_{2n-1} + f_n) z^{2n} \\ &= \undergroup{\sum_{n\ge1} f_{2n-1} z^{2n}}_{S_1} + \undergroup{\sum_{n\ge1} f_n z^{2n}}_{S_2}, \end{align*}
S1=zn1f2n1z2n1=zn0f2n+1z2n+1=zfo(z),\begin{align*} S_1 &= z \sum_{n\ge1} f_{2n-1} z^{2n-1} \\ &= z \sum_{n\ge0} f_{2n+1} z^{2n+1} \\ &= z f_o(z), \end{align*}
S2=n1fn(z2)n=f(z2)f0=f(z2),\begin{align*} S_2 &= \sum_{n\ge1} f_n (z^2)^n \\ &= f(z^2) - f_0 \\ &= f(z^2), \end{align*}
fe(z)=zfo(z)+f(z2).\boxed{f_e(z) = z f_o(z) + f(z^2)}.

We’ve a system of equations

f(z)=fe(z)+fo(z)(1)fo(z)=z(1+fe(z))(2)fe(z)=zfo(z)+f(z2)(3)\begin{align*} f(z) &= f_e(z) + f_o(z) && \text{(1)} \\ f_o(z) &= z(1 + f_e(z)) && \text{(2)} \\ f_e(z) &= z f_o(z) + f(z^2) && \text{(3)} \end{align*}

At this point, we should switch to Sage. The following code presents the solution for f(z)f(z).

f(z)=f(z2)+zz1=z1z+11zf(z2).f(z) =-\frac{f(z^2)+z}{z-1} =\frac{z}{1-z} + \frac{1}{1-z}f(z^2).

We can solve this functional equation by iterating. The objective is to figure out the underlying pattern. This gives

f(z)=z1z+11zf(z2)=z1z+11z[z21z2+11z2f(z4)]=z1z+z2(1z)(1z2)+1(1z)(1z2)f(z4)f(z)=n0z2nk=0n(1z2k).\begin{align*} f(z) &= \frac{z}{1-z} + \frac{1}{1-z}f(z^2) \\ &= \frac{z}{1-z} + \frac{1}{1-z}\left[ \frac{z^2}{1-z^2} + \frac{1}{1-z^2}f(z^4) \right] \\ &= \frac{z}{1-z} + \frac{z^2}{(1-z)(1-z^2)} + \frac{1}{(1-z)(1-z^2)}f(z^4) \\ &\dots \\ &\therefore \boxed{f(z) = \sum_{n\ge0} \frac{z^{2^n}}{\prod_{k=0}^{n} (1-z^{2^k})}}. \end{align*}

Exercise 3.45

The aim is to repeat the process until a distinct pattern emerges.

f(z)=1+zf(z1+z)=1+z(1+z1+zf(z1+2z))=1+z(1+z1+z(1+z1+2zf(z1+3z)))=1+z+z21+z+z3(1+z)(1+2z)+f(z)=n0znk=0n1(1+kz).\begin{align*} f(z) &= 1+zf\left(\frac{z}{1+z}\right) \\ &= 1+z\left(1+\frac{z}{1+z}f\left(\frac{z}{1+2z}\right)\right) \\ &= 1+z\left(1+\frac{z}{1+z}\left(1+\frac{z}{1+2z}f\left(\frac{z}{1+3z}\right)\right)\right) \\ &\dots \\ &=1+z+\frac{z^2}{1+z}+\frac{z^3}{(1+z)(1+2z)}+\dots \\ &\therefore \boxed{f(z)=\sum_{n \ge 0}\frac{z^n}{\prod_{k=0}^{n-1}(1+kz)}}. \end{align*}

We can prove the correctness of the formula by induction on nn. The base case is trivially satisfied; recall that an empty product equals one. The inductive step is based on the following expansion rule

f(z1+(n1)z)=1+z1+(n1)zf(z1+nz).f\left(\frac{z}{1+(n-1)z}\right) = 1+\frac{z}{1+(n-1)z}f\left(\frac{z}{1+nz}\right).

Therefore, the series in the nnth iteration becomes

m=0n1zmk=0m1(1+kz)by the inductive hypothesis+zn1k=0n2(1+kz)z1+(n1)z=m=0nzmk=0m1(1+kz).\underbrace{\sum_{m = 0}^{n-1}\frac{z^{m}}{\prod_{k=0}^{m-1}(1+kz)}}_{\text{by the inductive hypothesis}}+\frac{z^{n-1}}{\prod_{k=0}^{n-2}(1+kz)} \cdot \frac{z}{1+(n-1)z}=\sum_{m = 0}^n\frac{z^m}{\prod_{k=0}^{m-1}(1+kz)}.

Exercise 3.46

Given f(z)f(z) defined by the equation f(z)=z/(1f(z2))f(z)=z/(1-f(z^2)) we’ve to find explicit expressions for a(z)a(z) and b(z)b(z) with f(z)=a(z)/b(z)f(z) = a(z)/b(z). We assume that f(z)f(z) is analytic at z=0z=0, thus f(0)=a(0)=0f(0)=a(0)=0 and b(0)=1b(0)=1 (actually, any scaling factor would work).

Substituting f(z)=a(z)/b(z)f(z) = a(z)/b(z) into the given equation, we get

a(z)b(z)=z1a(z2)b(z2)=zb(z2)b(z2)a(z2).\frac{a(z)}{b(z)} = \frac{z}{1 - \frac{a(z^2)}{b(z^2)}} = \frac{z b(z^2)}{b(z^2) - a(z^2)}.

Comparing the numerators and denominators, we can set up the following system of equations:

a(z)=zb(z2)(1)b(z)=b(z2)a(z2)(2).\begin{align*} a(z) &= z b(z^2) && \text{(1)} \\ b(z) &= b(z^2) - a(z^2) && \text{(2)} . \end{align*}

Substituting (1) into (2), we get b(z)=b(z2)z2b(z4)b(z) = b(z^2) - z^2 b(z^4). We can now solve for b(z)b(z). Let b(z)=n0bnznb(z) = \sum_{n\ge0} b_n z^n, so by substituting this series into the recurrence, we get

n0bnzn=i0biz2ij0bjz4j+2.\sum_{n\ge0} b_n z^n = \sum_{i\ge0} b_i z^{2i} - \sum_{j\ge0} b_j z^{4j+2}.

Apparently, the RHS has only even powers, hence b2n+1=0b_{2n+1}=0 for n0n \ge 0.

If nn is even, then bn=bn/2b(n2)/4.b_n=b_{n/2}-b_{(n-2)/4}. It helps to view nn as a binary number, where division by 2 is right-shifting by one position. The next 4 cases illustrate what happens under the hood, as recursion unfolds until reaching the base case n=0n=0. X2X_2 denotes any binary prefix.

  1. If n=X2010n=X_2010, then bn/2=0b_{n/2}=0 (odd index) and b(n2)/4=bX20b_{(n-2)/4}=-b_{X_20}.

  2. If n=X2000n=X_2000, then bn/2=bX200b_{n/2}=b_{X_200} and b(n2)/4=0b_{(n-2)/4}=0 (non-integer index).

  3. If n=X2100n=X_2100, then bn/2=bX210b_{n/2}=b_{X_210} and b(n2)/4=0b_{(n-2)/4}=0 (non-integer index).

  4. If n=X2110n=X_2110, then bn/2=0b_{n/2}=0 (odd index) and b(n2)/4=0b_{(n-2)/4}=0 (odd index) .

Thus, by induction on bit position, bnb_n is non-zero if and only if the binary expansion of nn contains no consecutive 1s. Furthermore, advancing via bn/2b_{n/2} drops a trailing zero, whilst b(n2)/4b_{(n-2)/4} removes a binary 1 and flips a sign. Thus,

b(z)=nS(1)νnz2na(z)=nS(1)νnz4n+1,\begin{align*} b(z) = \sum_{n \in S} (-1)^{\nu_n} z^{2n} \\ a(z) = \sum_{n \in S} (-1)^{\nu_n} z^{4n+1}, \end{align*}

where SS is a sequence registered under A003714 and νN\nu_N is the population count (see Chapter 2 in the book). Observe that νN=ν2N\nu_N=\nu_{2N}.

Exercise 3.47

Only f(z)=0f(z)=0 satisfies f(z)=sin(f(z))f(z)=\sin(f(z)), where f(z)=n1fnznf(z)=\sum_{n \ge 1}f_nz^n.

Suppose, for the sake of contradiction, that there is also another power series g(z)0g(z) \neq 0 satisfying the same condition. Let gkg_k be the lowest indexed non-zero coefficient for k1k \ge 1. Using Taylor's expansion of the sine function (see Exercise 3.25), and passing g(z)g(z) as an argument, we’ve

sin(g(z))=g(z)g(z)36+g(z)5120\sin(g(z)) = g(z) - \frac{g(z)^3}{6} + \frac{g(z)^5}{120} - \dots

But this entails that

g(z)=g(z)g(z)36+g(z)5120g(z) = g(z) - \frac{g(z)^3}{6} + \frac{g(z)^5}{120} - \dots

since g(z)=sin(g(z))g(z)=\sin(g(z)) by definition. Subtracting g(z)g(z) from both sides, we get

0=g(z)36+g(z)51200 = - \frac{g(z)^3}{6} + \frac{g(z)^5}{120} - \dots

The lowest term in the RHS is 16gk3z3k-\frac{1}{6}g_k^3z^{3k}, since the others have higher powers of zz, so gkg_k must be zero. But this contradicts our assumption that gk0g_k \neq 0. Therefore, f(z)=0f(z)=0 is a unique solution.

Exercise 3.48

Let f(z)=n0fnznf(z) = \sum_{n \ge 0} f_n z^n be the OGF for the number of 2–3 trees , where fnf_n denotes the number of trees with nn external nodes. Based on the functional equation f(z)=z+f(z2+z3)f(z) = z + f(z^2 + z^3), we see that f0=0f_0=0 and f1=1f_1=1. Notice, that the second summand generates higher-order terms, so for n>1n>1 the first summand zz has no effect. We can substitute the form of OGF into the functional equation to get

n2fnzn=k2fk(z2+z3)kLHS=k2fkj=0k(kj)z2jz3(kj)=k2fkj=0k(kj)z3kjRHS.\undergroup{\sum_{n \ge 2} f_n z^n = \sum_{k \ge 2} f_k (z^2 + z^3)^k}_{LHS}=\undergroup{\sum_{k \ge 2} f_k \sum_{j=0}^k \binom{k}{j} z^{2j}z^{3(k-j)}=\sum_{k \ge 2} f_k \sum_{j=0}^k \binom{k}{j} z^{3k-j}}_{RHS}.

To find the recurrence for fnf_n, we equate coefficients of the same rank on both sides. This gives the following constraints on kk, using the fact that 0jk0 \le j \le k, for which there is always some jj such that 3kj=n3k-j=n:

  • 3kjn    2kn    kn/2.3k-j\le n \implies 2k \le n \implies k \le \lfloor n/2 \rfloor.

  • 3kjn    3kn    kn/3.3k-j\ge n \implies 3k \ge n \implies k \ge \lceil n/3 \rceil.

Thus, for any fixed n>1n>1, we have

fn=k=n/3n/2(k3kn)fk.f_n = \sum_{k=\lceil n/3 \rceil}^{\lfloor n/2 \rfloor} \binom{k}{3k - n} f_k.

The next Python script computes the number of 2–3 trees of 100 external nodes.

It prints 5,520,498,313,790,316,0625,520,498,313,790,316,062.

As a verification step, it’s advisable to search for the sequence in the online encyclopedia. For instance, by displaying 20 values generated by this script (including the initial terms), we can confirm that it corresponds to A014535.

Exercise 3.49 🌟

Observe, that Ψ\Psi can be manipulated as any other "symbol" in arithmetic expressions. For the sake of completeness, let’s show that (Ψ+m)(Ψ+n)F(z)=(Ψ+n)(Ψ+m)F(z)(\Psi+m)(\Psi+n)F(z)=(\Psi+n)(\Psi+m)F(z) for any nonnegative integers nn, mm and arbitrary function F(z)F(z). We have

(Ψ+m)(Ψ+n)F(z)=(Ψ+m)((1z)F(z)+nF(z))=Ψ((1z)F(z))+Ψ(nF(z))+m(1z)F(z)+mnF(z)=(1z)F(z)+(1z)2F(z)+n(1z)F(z)+m(1z)F(z)+mnF(z)=(1z)2F(z)+(n+m1)(1z)F(z)+nmF(z)(Ψ+n)(Ψ+m)F(z)=(Ψ+n)((1z)F(z)+mF(z))=Ψ((1z)F(z))+Ψ(mF(z))+n(1z)F(z)+nmF(z)=(1z)F(z)+(1z)2F(z)+m(1z)F(z)+n(1z)F(z)+nmF(z)=(1z)2F(z)+(n+m1)(1z)F(z)+nmF(z).\begin{align*} (\Psi+m)(\Psi+n)F(z) &= (\Psi+m)((1-z)F'(z)+nF(z)) \\ &= \Psi((1-z)F'(z))+\Psi(nF(z))+m(1-z)F'(z)+mnF(z) \\ &= -(1-z)F'(z)+(1-z)^2F''(z)+n(1-z)F'(z)+m(1-z)F'(z)+mnF(z) \\ &= (1-z)^2F''(z)+(n+m-1)(1-z)F'(z)+nmF(z) \\ \hline \\ (\Psi+n)(\Psi+m)F(z) &= (\Psi+n)((1-z)F'(z)+mF(z)) \\ &= \Psi((1-z)F'(z))+\Psi(mF(z))+n(1-z)F'(z)+nmF(z) \\ &= -(1-z)F'(z)+(1-z)^2F''(z)+m(1-z)F'(z)+n(1-z)F'(z)+nmF(z) \\ &= (1-z)^2F''(z)+(n+m-1)(1-z)F'(z)+nmF(z). \end{align*}

We proceed by induction on tt .The base case is trivially satisfied, since ΨC(z)(1z)C(z)\Psi C(z)≡(1-z)C'(z). For the inductive step, we have

(Ψ+t1)((1z)t1C(t1)(z))=Ψ((1z)t1C(t1)(z))+(t1)(1z)t1C(t1)(z)=(1z)((t1)(1z)t2C(t1)(z)+(1z)t1C(t)(z))+(t1)(1z)t1C(t1)(z)=(t1)(1z)t1C(t1)(z)+(1z)tC(t)(z)+(t1)(1z)t1C(t1)(z)(1z)tC(t)(z)=(Ψ+t1)Ψ(Ψ+1)(Ψ+t2)C(z)by the inductive hypothesis.\begin{align*} (\Psi+t-1)((1-z)^{t-1}C^{(t-1)}(z)) &= \Psi((1-z)^{t-1}C^{(t-1)}(z)) + (t-1)(1-z)^{t-1}C^{(t-1)}(z) \\ &= (1-z)(-(t-1)(1-z)^{t-2}C^{(t-1)}(z)+(1-z)^{t-1}C^{(t)}(z)) + (t-1)(1-z)^{t-1}C^{(t-1)}(z) \\ &= -(t-1)(1-z)^{t-1}C^{(t-1)}(z)+(1-z)^tC^{(t)}(z)+ (t-1)(1-z)^{t-1}C^{(t-1)}(z) \\ &\therefore (1-z)^tC^{(t)}(z) = (\Psi+t-1)\underbrace{\Psi(\Psi+1)\dots (\Psi+t-2)C(z)}_{\text{by the inductive hypothesis}}. \end{align*}

By successively swapping neighboring elements, we can move (Ψ+t1)(\Psi+t-1) into the last position without disturbing the relative ordering of the other terms. This proves that the statement of this exercise holds for any t1t \ge 1.

Exercise 3.50

Sedgewick’s paper The Analysis of Quicksort Programs contains a full analysis of median-of-three quick-sort algorithm (see section 3.2). It derives the base formula in a more detailed manner than the book itself.

Exercise 3.51

Section 3.3 of the paper mentioned in the previous exercise shows the analysis of the median of 2t+12t+1 quick-sort algorithm. Therefore, for a sample size of 5 we would use t=2t=2.

Exercise 3.52 🌟

Understanding the Problem

The specific ordinary differential equation (ODE) with variable coefficients considered here is

j=0r(1z)rjdjdzjf(z)=0,\sum_{j=0}^{r} (1-z)^{r-j} \frac{d^j}{dz^j} f(z)=0,

with its inhomogeneous counterpart,

j=0r(1z)rjdjdzjf(z)=(1z)α.\sum_{j=0}^{r} (1-z)^{r-j} \frac{d^j}{dz^j} f(z)= (1-z)^{\alpha}.

Unlike the classical Euler-Cauchy equation, where the power of the independent variable scales directly with the order of the derivative, this equation exhibits an inverse scaling relationship: as the order of the derivative jj increases, the power of the coefficient (1z)rj(1-z)^{r-j} decreases.

Leading-Coefficient Observation

Let’s expand the LHS

ar(z)f(r)(z)+ar1(z)f(r1)(z)++a0(z)f(z),a_r(z) f^{(r)}(z)+a_{r-1}(z) f^{(r-1)}(z)+\dots+a_0(z) f(z),

with aj(z)=(1z)rja_j(z)=(1-z)^{r-j}. The coefficient of the highest derivative is

ar(z)=(1z)rr=(1z)0=1,a_r(z)=(1-z)^{r-r}=(1-z)^0=1,

so the leading coefficient is nonzero at z=1z=1. Consequently, for the homogeneous equation the point z=1z=1 is an ordinary point in the sense that the normalized coefficients aj(z)/ar(z)a_j(z)/a_r(z) are analytic at z=1z=1. This implies homogeneous solutions are analytic at z=1z=1 and admit Taylor expansions about that point.

The inhomogeneous term (1z)α(1-z)^{\alpha} may be non-analytic at z=1z=1, so requires a careful analysis. Our focus will be on the Frobenius method. While it’s traditionally taught as a tool for regular singular points, its utility extends to constructing particular solutions for inhomogeneous equations, as in our case. We’ll showcase the Frobenius method in "inverted" regime.

The method of Frobenius can be viewed as a superset of the power series method. This is another reason why it’s a natural choice for this exercise related to a chapter about generating functions.

Change of Variable

Let x=1zx=1-z, such that

ddz=ddx,djdzj=(1)jdjdxj,\frac{d}{dz}=-\frac{d}{dx},\qquad \frac{d^j}{dz^j}=(-1)^j\frac{d^j}{dx^j},

so the equation becomes

j=0r(1)jxrjf(j)(x)=xα\sum_{j=0}^{r} (-1)^j x^{\,r-j} f^{(j)}(x)=x^{\alpha}

for the inhomogeneous problem. Because the coefficient of f(r)(x)f^{(r)}(x) is (1)rxrr=(1)r(-1)^r x^{r-r}=(-1)^r, a nonzero constant, the homogeneous equation has analytic coefficients at x=0x=0. The above canonical transformation centers a potential singularity at the origin.

First-Order Case

It always make sense to start with the simplest form to develop intuition and cement understanding of the task. The transformed equation is

f(x)xf(x)={0homogeneous variantxαinhomogeneous variant,f'(x)-x f(x)=\begin{cases}0 &\text{homogeneous variant} \\ -x^{\alpha} &\text{inhomogeneous variant} \end{cases},

The closed-form solution of the homogeneous version is f(x)=Cex2/2f(x) = C e^{x^2/2}, where CC is an arbitrary constant. This is an entire function, as expected.

For solving the other version, we apply an integrating factor I(x)=exp ⁣(x22)I(x)=\exp\!\big(-\tfrac{x^2}{2}\big). Multiplying through and integrating gives

f(x)=Cex2/2ex2/2xαex2/2dx.f(x)=C e^{x^2/2}-e^{x^2/2}\int x^{\alpha} e^{-x^2/2}\,dx.

Second-Order Case

The transformed equation is

f(x)xf(x)+x2f(x)={0homogeneous variantxαinhomogeneous variant.f''(x)-x f'(x)+x^2 f(x)=\begin{cases}0 &\text{homogeneous variant} \\ x^{\alpha} &\text{inhomogeneous variant} \end{cases}.

The homogeneous part can be solved using OGFs. Let fH(x)=n0anxnf_H(x)=\sum_{n\ge0} a_n x^n, so substitution yields the recurrence

(n+2)(n+1)an+2nan+an2=0(for n2)an+2=nanan2(n+2)(n+1),\begin{align*} (n+2)(n+1)a_{n+2}-n a_n + a_{n-2} &= 0 \qquad (\text{for }n\ge2) \\ &\therefore \boxed{a_{n+2} = \frac{n a_n - a_{n-2}}{(n+2)(n+1)}}, \end{align*}

with initial relations a2=0a_2=0 and a3=a1/6a_3=a_1/6. The recurrence links coefficients of the same parity, hence the solution space splits into an even {en}\{e_n\} and odd {on}\{o_n\} series. To peek into the derivation details, it’s instructive to read an analysis of the Hermite differential equation.

For finding the particular solution, we employ the Frobenius method. We start with the default ansatz

fP(x)=xkn0bnxn.f_P(x)=x^k\sum_{n \ge0} b_n x^n.

The lowest term is from fP(x)f_P''(x), thus matching to xαx^{\alpha} yields k=α+2k=\alpha+2. This gives

fP(x)=n0bnxα+2+n.f_P(x)=\sum_{n \ge0} b_n x^{\alpha+2+n}.

Matching coefficients for power xα+nx^{\alpha+n} produces a recurrence of the form

(α+n+2)(α+n+1)bn(α+n)bn2+bn4=δn0.(\alpha+n+2)(\alpha+n+1)b_n-(\alpha+n)b_{n-2}+b_{n-4}=\delta_{n0}.

Solving the system for n=0,1,2,3n=0,1,2,3 gives

b0=1(α+1)(α+2)b1=0b2=1(α+1)(α+3)(α+4)b3=0.\begin{align*} b_0 &= \frac{1}{(\alpha+1)(\alpha+2)} \\ b_1 &= 0 \\ b_2 &= \frac{1}{(\alpha+1)(\alpha+3)(\alpha+4)} \\ b_3 &= 0 . \end{align*}

Apparently, odd terms vanish. The full solution is

f(x)=An0enx2n+Bn0onx2n+1+n0b2nxα+2+2n,f(x) = A\sum_{n\ge0} e_nx^{2n} + B \sum_{n\ge0} o_nx^{2n+1} + \sum_{n\ge0} b_{2n} x^{\alpha+2+2n},

where AA and BB are arbitrary constants.

Exceptional Case

If the denominator of any coefficient becomes zero, for instance, when α=2\alpha=-2, then we have to modify the ansatz. The Frobenius method mandates the inclusion of a logarithmic term

fP(x)=xα+2(Alnxn0bnxn+n0cnxn).f_P(x)=x^{\alpha+2}\left(A\ln x\sum_{n\ge0} b_n x^n+\sum_{n\ge0} c_n x^n\right).

The logarithmic coefficient is determined by substituting this ansatz and solving the resulting linear system.

General Case

The transformed equation is

j=0r(1)jxrjf(j)(x)={0homogeneous variantxαinhomogeneous variant.\sum_{j=0}^{r} (-1)^j x^{r-j} f^{(j)}(x)=\begin{cases}0 &\text{homogeneous variant} \\ x^{\alpha} &\text{inhomogeneous variant} \end{cases}.

Again, the homogeneous part can be solved using OGFs. The recurrence relation becomes a difference equation of order rr. Specifically, the coefficient of xnx^n in the expansion involves terms from an+ra_{n+r} down to anra_{n-r}; xrjx^{r-j} is paired with dj/dxjd^j/dx^j, so the shift in power is always (rj)j=r2j(r-j) - j = r - 2j. Thus, the parity of the shifts (even vs odd) is fixed by the parity of rr.

By the fundamental theorem of linear ODEs, an rrth order homogeneous equation at an ordinary point is guaranteed to have exactly rr linearly independent solutions. In the context of our power series f(x)=anxnf(x) = \sum a_n x^n, these rr independent solutions are uniquely determined by the rr arbitrary initial conditions: a0,a1,,ar1a_0, a_1, \dots, a_{r-1}.

The parity of rr simply dictates how these rr degrees of freedom are processed by the recurrence:

  • When rr is even: The rr initial conditions are split evenly across the two independent parity subspaces (r/2r/2 even coefficients, r/2r/2 odd coefficients). The recurrence propagates them independently, yielding r/2r/2 purely even solutions and r/2r/2 purely odd solutions, totaling rr independent solutions. We’ve already seen example of this with r=2r=2.

  • When rr is odd: All rr initial conditions (a0,,ar1a_0, \dots, a_{r-1}) feed into the same unified recurrence chain. By setting one of these initial coefficients to 1 and the other r1r-1 coefficients to 0, and repeating this for each aka_k (0k<r0 \le k < r), the single recurrence naturally generates the full fundamental set of rr linearly independent solutions.

For finding the particular solution, we employ the Frobenius method, starting with the default ansatz. The highest-derivative term f(r)f^{(r)} produces the lowest power, thus matching to xαx^{\alpha} gives

kr=α    k=α+r.k-r=\alpha\implies k=\alpha+r.

Hence, the particular solution begins at xα+rx^{\alpha+r}

fP(x)=n0bnxα+r+n.f_P(x)=\sum_{n\ge0} b_n x^{\alpha+r+n}.

We must manage exceptional cases, as in the situation with r=2r=2.

Exercise 3.53

See Exercise 3.51.

Exercise 3.54

We define TT to be the set of all binary trees, and adopt the notation t|t| to represent, for tTt \in T, the number of external nodes in tt. Then we have the following derivation:

T(z)=tTzt=z+tLTtRTztL+tR=z+T(z)2.\begin{align*} T(z) &= \sum_{t \in T}z^{|t|} \\ &= z + \sum_{t_L \in T}\sum_{t_R \in T} z^{|t_L|+|t_R|} \\ &= z + T(z)^2. \end{align*}

The first line is an alternative way to express T(z)T(z) from its definition. Each tree with exactly kk external nodes contributes exactly 11 to the coefficient of zkz^k, so the coefficient of zkz^k in the sum “counts” the number of trees with kk external nodes. The second line follows from the recursive definition of binary trees: either a binary tree has one external node (which accounts for the zz), or it can be decomposed into two independent binary trees whose external nodes comprise the external nodes of the original tree, without the root (internal node). The third line follows because the index variables tLt_L and tRt_R are independent.

In this case T(0)=0T(0)=0. It is always worthwhile to check our the math with a computer. The next Sage snippet correctly prints the first few known initial values and T6=42=16(105)T_6=42=\frac{1}{6}\binom{10}{5}:

Exercise 3.55 🌟

The given OGF is a rational function

D(z)=1(1z)(1z5)(1z10)(1z25)(1z50).D(z) = \frac{1}{(1-z)(1-z^5)(1-z^{10})(1-z^{25})(1-z^{50})}.

The book contains a remark, that we can learn much about asymptotic behavior of coefficients by looking at singularities of the generating function. A kkth root of unity ω\omega for k{1,5,10,25,50}k \in\{1,5,10,25,50\} makes the denominator zero. To understand the coefficients, we look at the partial fraction decomposition of D(z)D(z) and connect it to these singularities.

The value z=1z=1 has order 55, as it makes any factor 1zk1-z^k zero in the denominator. The matching summand in the decomposition of D(z)D(z) would participate as C/(1z)5C/(1-z)^5, where CC is some constant. Looking at Table 3.1, this would be represented in expanded form as N0(N+4N)zN\sum_{N \ge 0} \binom{N+4}{N}z^N. Therefore, the coefficient of zNz^N would grow as Θ(N4)\Theta(N^4). Observe, that the other roots of unity are associated with lower exponents. Nevertheless, they do introduce cyclic fluctuations to the count, since they are periodic.

Combining the polynomial growth from z=1z=1 and the periodicity from the other roots of unity, we get that the form of [zN]D(z)[z^N]D(z) is a quasi-polynomial. If we denote by rN(mod50)r \equiv N \pmod{50}, where 5050 is a least common multiple of the coin denominations, then we have

[zN]D(z)=a4(r)N4+a3(r)N3+a2(r)N2+a1(r)N+a0(r),[z^N]D(z) = a_4(r)N^4 + a_3(r)N^3 + a_2(r)N^2 + a_1(r)N + a_0(r),

where the coefficients ai(r)a_i(r) depend on the remainder rr.

Exercise 3.56

The next Python program uses the mathematical model from the previous exercise. The idea is to precompute coefficients for r[0,49]r \in [0,49] and afterward evaluate the quasi-polynomial for a given NN. The implementation employs dynamic programming as well as fast linear equations solver from the Numpy package. The system of linear equations is represented as a Vandermonde matrix.

Running this program produces the following output:

LeetCode also offers this problem under Coin Change II, although covers only small cases.

Exercise 3.57

This is a simple variation of Polya's problem of changing a dollar. Instead of coins, we have powers of 2 excluding 202^0. Let the index pip_i denote the number of 2i2^i factors. This gives

T(z)=p1,p2,0zp121+p222+=p1zp121p2zp222=k111z2k.\begin{align*} T(z) &= \sum_{p_1,p_2,\dots \ge 0}z^{p_12^1+p_22^2+\dots} \\ &= \sum_{p_1}z^{p_12^1}\sum_{p_2}z^{p_22^2}\dots \\ &= \prod_{k \ge 1} \frac{1}{1-z^{2^k}}. \end{align*}

Each configuration of powers of 2 that adds up to NN clearly contributes exactly 1 to the coefficient of zNz^N. The second line follows since the indices of summations are all independent. The last line is a translation based on Table 3.1 from the book.

Exercise 3.58

First, we prove by induction on tt that

n=0t1(1+z2n)=n=02t1zn=z2t1z1.\prod_{n=0}^{t-1}{(1+z^{2^n})}=\sum_{n=0}^{2^t-1}z^n= \frac{z^{2^t}-1}{z-1}.

The base case t=1t=1 is trivially satisfied. For t>1t>1 we’ve

n=0t1(1+z2n)=n=0t2(1+z2n)(1+z2t1)=(n=02t11zn)(1+z2t1)(by the inductive hypothesis)=n=02t11zn+z2t1n=02t11zn=n=02t11zn+n=2t12t1zn=n=02t1zn.\begin{align*} \prod_{n=0}^{t-1}{(1+z^{2^n})} &= \prod_{n=0}^{t-2}{(1+z^{2^n})}(1+z^{2^{t-1}}) \\ &= \left(\sum_{n=0}^{2^{t-1}-1}z^n\right)(1+z^{2^{t-1}}) && \text{(by the inductive hypothesis)} \\ &= \sum_{n=0}^{2^{t-1}-1}z^n + z^{2^{t-1}}\sum_{n=0}^{2^{t-1}-1}z^n \\ &= \sum_{n=0}^{2^{t-1}-1}z^n + \sum_{n=2^{t-1}}^{2^t-1}z^n \\ &= \sum_{n=0}^{2^t-1}z^n. \end{align*}

When tt \to \infty then 1/(1z)=nzn=n(1+z2n)1/(1-z)=\sum_nz^n=\prod_n{(1+z^{2^n})}, so Euler's identity follows.


The identity reflects the fact that every non-negative integer has a unique binary representation. Expanding the product is equivalent to forming exponents by summing distinct powers of 2. Since every integer nn can be written as a sum of powers of 2 in exactly one way, every term znz^n appears exactly once in the resulting series.

Exercise 3.59

In base 2, the digits are {0,1}\{0, 1\}, so the factors were (1+z2n)=(z02n+z12n)(1 + z^{2^n}) = (z^{0 \cdot 2^n} + z^{1 \cdot 2^n}).

In base 3, the digits are {0,1,2}\{0, 1,2\}. This means that for each position nn (representing the value 3n3^n), we need a term that offers the choice of adding 03n0 \cdot 3^n, 13n1 \cdot 3^n, or 23n2 \cdot 3^n to the exponent. Therefore, the generalized identity is

11z=n(1+z3n+z23n).\frac{1}{1-z} = \prod_n \left(1 + z^{3^n} + z^{2 \cdot 3^n}\right).

All the other details are analogous to the previous exercise.

Exercise 3.60

As in Exercise 3.58, expanding the product is equivalent to forming exponents by summing distinct powers of 2. But this time the expansion also happens with a sign flip. Adding each power of 2 is equivalent to increasing the number of ones in a binary representation of NN by 1. We start with the factor 1z1-z, hence even number of ones are designated with +1, whilst odd number of ones with -1. This gives

[zN](1z)(1z2)(1z4)=(1)νN,[z^N](1-z)(1-z^2)(1-z^4)\dots = (-1)^{\nu_N},

where νN\nu_N is the population count.

Exercise 3.61

The expected value of XX expressed in terms of rkr_k is known as the tail-sum formula.

var(X)=E(X2)[E(X)]2=k0k2pk[E(X)]2=k0(pki=0k1(2i+1))[E(X)]2(i=0k1(2i+1)=k2)=i0((2i+1)ki+1pk)[E(X)]2=k0(2k+1)(1rk)[E(X)]2=2k0k(1rk)+E[X]E[X]2.\begin{align*} \operatorname{var}(X) &= \mathbb{E}(X^2) - [\mathbb{E}(X)]^2 \\ &= \sum_{k \ge 0} k^2p_k -[\mathbb{E}(X)]^2\\ &= \sum_{k\ge0} \left(p_k \sum_{i=0}^{k-1} (2i+1)\right) - [\mathbb{E}(X)]^2 && \text{($\sum_{i=0}^{k-1} (2i+1)=k^2$)} \\ &= \sum_{i\ge0} \left((2i+1) \sum_{k\ge i+1} p_k\right) - [\mathbb{E}(X)]^2 \\ &= \sum_{k\ge0} (2k+1)(1 - r_k) -[\mathbb{E}(X)]^2 \\ &= 2 \sum_{k \ge 0} k(1 - r_k) + \mathbb{E}[X] - \mathbb{E}[X]^2. \end{align*}

Exercise 3.62

We define a combined function R(x)=P(x)Q(x)R(x) = P(x)Q(x) and apply standard calculus rules. Recall that P(1)=Q(1)=1P(1)=Q(1)=1 is given as a precondition.

To prove the mean we must express R(1)R'(1) in terms of P(1)P'(1) and Q(1)Q'(1). This gives

R(x)=P(x)Q(x)+P(x)Q(x)R(1)=P(1)+Q(1)E(PQ)=E(P)+E(Q)\begin{align*} R'(x) &= P'(x)Q(x) + P(x)Q'(x) \\ R'(1) &= P'(1) + Q'(1) \\ &\therefore \mathbb{E}(PQ)=\mathbb{E}(P)+\mathbb{E}(Q) \qquad \checkmark \end{align*}

The variance is handled in a similar way, but we have to first find the second derivative of R(x)R(x).

R(x)=ddx[P(x)Q(x)+P(x)Q(x)]=[P(x)Q(x)+P(x)Q(x)]+[P(x)Q(x)+P(x)Q(x)]=P(x)Q(x)+2P(x)Q(x)+P(x)Q(x)R(1)=P(1)+2P(1)Q(1)+Q(1).\begin{align*} R''(x) &= \frac{d}{dx}[P'(x)Q(x) + P(x)Q'(x)] \\ &= [P''(x)Q(x) + P'(x)Q'(x)] + [P'(x)Q'(x) + P(x)Q''(x)] \\ &= P''(x)Q(x) + 2P'(x)Q'(x) + P(x)Q''(x) \\ R''(1) &= P''(1) + 2P'(1)Q'(1) + Q''(1). \end{align*}

We can now substitute R(1)R''(1) and R(1)R'(1) into the definition of variance, thus

var(PQ)=R(1)+R(1)R(1)2=[P(1)+2P(1)Q(1)+Q(1)]+[P(1)+Q(1)][P(1)+Q(1)]2=P(1)+2P(1)Q(1)+Q(1)+P(1)+Q(1)(P(1)2+2P(1)Q(1)+Q(1)2)=[P(1)+P(1)P(1)2]+[Q(1)+Q(1)Q(1)2]=var(P)+var(Q)\begin{align*} \operatorname{var}(PQ) &= R''(1) + R'(1) - R'(1)^2 \\ &= [P''(1) + 2P'(1)Q'(1) + Q''(1)] + [P'(1) + Q'(1)] - [P'(1) + Q'(1)]^2 \\ &= P''(1) + 2P'(1)Q'(1) + Q''(1) + P'(1) + Q'(1) - (P'(1)^2 + 2P'(1)Q'(1) + Q'(1)^2) \\ &= [P''(1) + P'(1) - P'(1)^2] + [Q''(1) + Q'(1) - Q'(1)^2] \\ &= \operatorname{var}(P)+\operatorname{var}(Q) \qquad \checkmark \end{align*}

Exercise 3.63

The derivates of Pn(u)P_n(u) can be easily computed using WolframAlpha; the second derivate is one the alternative forms offered by the tool.

Pn(u)=(n1)unnun1+1n(1u)2Pn(u)=n2(u1)2un2+n(1u)(3u1)un2+2(un1)n(u1)3.\begin{align*} P'_n(u) &= \frac{(n - 1) u^n - n u^{n-1} + 1}{n (1 - u)^2} \\ P''_n(u) &= \frac{n^2 (u - 1)^2 u^{n - 2} + n (1 - u) (3 u - 1) u^{n - 2} + 2 (u^n - 1)}{n (u - 1)^3}. \end{align*}

Using l’Hôpital’s rule we can compute the derivatives at 1. Again, WolframAlpha can help a lot in finding derivates of complicated numerators.

limu1Pn(u)=limu1(n1)unnun1+1n(1u)2=limu1(n1)nun1n(n1)un22n(1u)=limu1(n1)2nun2n(n1)(n2)un32n=n12\begin{align*} \lim_{u \to 1}P'_n(u) &= \lim_{u \to 1} \frac{(n - 1) u^n - n u^{n-1} + 1}{n (1 - u)^2} \\ &= \lim_{u \to 1} \frac{(n - 1) n u^{n-1} - n(n-1) u^{n-2}}{-2n (1 - u)} \\ &= \lim_{u \to 1} \frac{(n - 1)^2 n u^{n-2} - n(n-1)(n-2) u^{n-3}}{2n} \\ &= \frac{n-1}{2} \qquad \checkmark \end{align*}
limu1Pn(u)=limu1n2(u1)2un2+n(1u)(3u1)un2+2(un1)n(u1)3=limu1n(n23n+2)(u1)2un33n(u1)2=limu1n(n23n+2)(u1)(n(u1)u+3)un46n(u1)=limu1n(n23n+2)un5(n2(u1)2+n(3u2+10u7)+2(u26u+6))6n=n23n+23=(n2)(n1)3\begin{align*} \lim_{u \to 1}P''_n(u) &= \lim_{u \to 1} \frac{n^2 (u - 1)^2 u^{n - 2} + n (1 - u) (3 u - 1) u^{n - 2} + 2 (u^n - 1)}{n (u - 1)^3} \\ &= \lim_{u \to 1} \frac{n (n^2 - 3 n + 2) (u - 1)^2 u^{n - 3}}{3n (u - 1)^2} \\ &= \lim_{u \to 1} \frac{n (n^2 - 3 n + 2) (u - 1) (n (u - 1) - u + 3) u^{n - 4}}{6n(u-1)} \\ &= \lim_{u \to 1} \frac{n (n^2 - 3 n + 2) u^{n - 5} (n^2 (u - 1)^2 + n (-3 u^2 + 10 u - 7) + 2 (u^2 - 6 u + 6))}{6n} \\ &= \frac{n^2-3n+2}{3} \\ &= \frac{(n-2)(n-1)}{3} \qquad \checkmark \end{align*}

Exercise 3.64

Let XX be the random variable that counts the number of leading zeros in a random binary string. For a string of size nn with independent fair bits, the probability mass function is

pk={(12)k12=12k+1if 0k<n12nif k=n.p_k = \begin{cases} \left(\cfrac{1}{2}\right)^k \cdot \cfrac{1}{2} = \cfrac{1}{2^{k+1}} &\text{if } 0 \le k < n \\ \cfrac{1}{2^n} &\text{if } k = n \end{cases}.

The corresponding PGF is

Pn(u)=12+u4+u28++un12n+un2n=un2n+1un2n2u.P_n(u) = \frac{1}{2} +\frac{u}{4}+\frac{u^2}{8}+ \dots + \frac{u^{n-1}}{2^n}+\frac{u^n}{2^n}= \frac{u^n}{2^n} + \frac{1 - \frac{u^n}{2^n}}{2 - u}.

The mean is Pn(1)=112nP_n'(1)=1-\frac{1}{2^n}.

For the variance we need Pn(1)=2n+12n1P''_n(1)=2-\frac{n+1}{2^{n-1}}, so

var(X)=2n+12n1+112n(112n)2=2n2n1122n12n.\operatorname{var}(X)=2-\frac{n+1}{2^{n-1}}+1-\frac{1}{2^n}-\left(1-\frac{1}{2^n}\right)^2=2-\frac{n}{2^{n-1}}-\frac{1}{2^{2n}}-\frac{1}{2^n}.

The standard deviation is σX=var(X)\sigma_X=\sqrt{\operatorname{var}(X)}. When nn \to \infty then the mean is 1 and the standard deviation is 2\sqrt2.

Exercise 3.65

We must find the only missing piece pn(1)p''_n(1). We have

pn(u)=n(n1)(1+u)n2    pn(1)=n(n1)2n2.p''_n(u)=n(n-1)(1+u)^{n-2} \implies p''_n(1)=n(n-1)2^{n-2}.

After substituting all known quantities into the formula from Table 3.5, we get that the variance for the number of 1 bits in a random binary string of length nn is n/4n/4.

Exercise 3.66

Let’s focus our attention on [zn][z^n], since we want to find the mean for the binomial distribution with size nn. We know that [zn]qk(z)=(nk)[z^n]q_k(z)=\binom{n}{k}, so 0kn0 \le k \le n. Furthermore, [zn]P(z,1)=2n[z^n]P(z,1)=2^n. We also have

[zn]rk(z)=0jk(nj).[z^n]r_k(z)=\sum_{0 \le j \le k} \binom{n}{j}.

Substituting all these into the formula for the cumulated cost gives

[zn]k0(P(z,1)rk(z))=0kn(2n0jk(nj))=(n+1)2n0kn0jk(nj)=(n+1)2n(n+1)2n+2n2=n22n.\begin{align*} [z^n]\sum_{k \ge 0}(P(z,1)-r_k(z)) &= \sum_{0 \le k \le n}\left(2^n-\sum_{0 \le j \le k} \binom{n}{j}\right) \\ &= (n+1)2^n-\sum_{0 \le k \le n}\sum_{0 \le j \le k} \binom{n}{j} \\ &= (n+1)2^n-\frac{(n+1)2^n+2^n}{2} \\ &= \frac{n}{2} \cdot 2^n. \end{align*}

The double sum can be easily calculated by drawing a symmetric square matrix of size (n+1)×(n+1)(n+1) \times (n+1). The kkth row should be filled with (nk)\binom{n}{k}. All columns sum to 2n2^n and the main diagonal also sums to 2n2^n. Our double sum is half the total sum of all entries. There is only one caveat; we must add once again the sum of entries at the main diagonal before dividing by 2.

Finally, the mean is simply the cumulated cost divided by 2n2^n, which results in n/2n/2.

Exercise 3.67

The book doesn’t provide details about derivation of the functional equation that must be satisfied by the BGF. This is important for understanding this and the next exercise. So, we’ll fill the gap here.

Derivation of the Functional Equation

We are given the recurrence for the PGF

QN(u)=1Nk=1NuN+1Qk1(u)QNk(u),Q_N(u) = \frac{1}{N} \sum_{k=1}^{N} u^{N+1} Q_{k-1}(u) Q_{N-k}(u),

that is defining the exponential BGF

Q(z,u)=N0QN(u)zN.Q(z, u) = \sum_{N \geq 0} Q_N(u) z^N.

Notice that Q(z,1)Q(z, 1) represents the sum of probabilities for each NN, so it must designate a sequence of all ones, hence Q(z,1)=1/(1z)Q(z, 1)=1/(1-z).

When dealing with permutations, there is an inherent duality between an exponential BGF and a PGF, as highlighted in the book. Namely, the division by N!N! moves into the kernel of an EBGF, which gets "activated" once we read out the coefficients of partial derivatives evaluated at u=1u=1. It’s unnecessary to perform the division by the number of structures, as this calculation has already been done "from" the kernel. As a matter of fact, stricly dividing by [zN]Q(z,1)=1[z^N]Q(z,1)=1 is redundant.

Let’s differentiate this BGF with respect to zz and substitute the recurrence of QN(u)Q_N(u) into it. We use the compact notation for partial derivatives, as introduced in the book.

Qz(z,u)=N1QN(u)NzN1=N1(k=1NuN+1Qk1(u)QNk(u))zN1=u2N1(k=1NQk1(u)QNk(u))(uz)N1=u2N1(k=0N1Qk(u)QN1k(u))(uz)N1=u2N0(k=0NQk(u)QNk(u))(uz)N=u2Q2(zu,u)(self-convolution of Q(zu, u)).\begin{align*} Q_z(z, u) &= \sum_{N \ge 1} Q_N(u) Nz^{N-1} \\ &= \sum_{N \ge 1} \left( \sum_{k=1}^{N} u^{N+1} Q_{k-1}(u) Q_{N-k}(u) \right) z^{N-1} \\ &= u^2\sum_{N \ge 1} \left( \sum_{k=1}^{N} Q_{k-1}(u) Q_{N-k}(u) \right) (uz)^{N-1} \\ &= u^2\sum_{N \ge 1} \left( \sum_{k=0}^{N-1} Q_k(u) Q_{N-1-k}(u) \right) (uz)^{N-1} \\ &= u^2\sum_{N \ge 0} \left( \sum_{k=0}^N Q_k(u) Q_{N-k}(u) \right) (uz)^N \\ &= u^2Q^2(zu, u) && \text{(self-convolution of Q(zu, u))}. \end{align*}

Solution of the Exercise

We know that QN(1)=1Q_N(1)=1, since QN(u)Q_N(u) is a PGF. This gives

QN(u)=1Nk=1N((N+1)uNQk1(u)QNk(u)+uN+1(Qk1(u)QNk(u)+Qk1(u)QNk(u)))QN(1)=N+1+1Nk=1N(Qk1(1)+QNk(1)).\begin{align*} Q'_N(u) &= \frac{1}{N} \sum_{k=1}^{N} \left((N+1)u^N Q_{k-1}(u) Q_{N-k}(u) + u^{N+1}(Q'_{k-1}(u) Q_{N-k}(u)+Q_{k-1}(u) Q'_{N-k}(u))\right) \\ &\therefore Q'_N(1) = N+1 + \frac{1}{N}\sum_{k=1}^{N} (Q'_{k-1}(1)+Q'_{N-k}(1)). \end{align*}

Notice that QN(1)Q'_N(1) satisfies the standard quicksort recurrence that the book addressed in section 3.3, so it must have the same solution. Consequently,

q[1](z)=Qu(z,u)u=1=N0QN(1)zN=2(1z)2ln11z.q^{[1]}(z)=Q_u(z, u)\bigg|_{u=1}=\sum_{N \geq 0} Q'_N(1) z^N=\frac{2}{(1-z)^2} \ln \frac{1}{1-z}.

To verify the expression for q[2](z)q^{[2]}(z) we must differentiate the functional equation that Q(z,u)Q(z,u) must satisfy twice with respect to uu. To make the exposition manageable, due to convoluted terms, let’s introduce the following substitutions:

  • A(z)=Q(z,1)=1/(1z)A(z)=Q(z,1)=1/(1-z) implying that A(z)=A2(z)A'(z)=A^2(z).

  • xuzx\equiv uz, yuy \equiv u and B(x,y)=Q(x,y)B(x,y)=Q(x,y) implying that Bu=zBx+ByB_u=zB_x+B_y. This follows from applying the multivariable chain rule.

Let’s differentiate Qz=u2B2Q_z=u^2B^2 once w.r.t. uu to get

Qzu=2uB2+2u2BBu.Q_{zu}=2u\,B^2+2u^2\,B\,B_u.

Repeating the previous step once more we arrive at

Qzuu=2B2+8uBBu+2u2(Bu2+BBuu).Q_{zuu}=2B^2+8uBB_u+2u^2\bigl(B_u^2+B\,B_{uu}\bigr).

Evaluated at u=1u=1 this becomes

(q[2])(z)=2A2+8ABu(z,1)+2(Bu2(z,1)+ABuu(z,1)).(q^{[2]})'(z)=2A^2+8A\,B_u(z,1)+2\Bigl(B^2_u(z,1)+A\,B_{uu}(z,1)\Bigr).

It remains to compute Buu(z,1)B_{uu}(z,1). Since Bu=zQz(uz,u)+Qu(uz,u)B_u=zQ_z(uz,u)+Q_u(uz,u) we have

Buu=z(zQzz(uz,u)+Qzu(uz,u))+(zQzu(uz,u)+Quu(uz,u))Buu(z,1)=z2Qzz(z,1)+2zQzu(z,1)+q[2](z).\begin{align*} B_{uu} &=z\Bigl(zQ_{zz}(uz,u)+Q_{zu}(uz,u)\Bigr)+\Bigl(zQ_{zu}(uz,u)+Q_{uu}(uz,u)\Bigr) \\ &\therefore B_{uu}(z,1)=z^2Q_{zz}(z,1)+2z\,Q_{zu}(z,1)+q^{[2]}(z). \end{align*}

Now

Qzz(z,1)=A(z)=2A(z)3,Qzu(z,1)=(q[1])(z).Q_{zz}(z,1)=A''(z)=2A(z)^3,\qquad Q_{zu}(z,1)=(q^{[1]})'(z).

We can eliminate QQ from BuuB_{uu}

Buu(z,1)=2z2A3+2z(q[1])(z)+q[2](z).B_{uu}(z,1)=2z^2A^3+2z(q^{[1]})'(z)+q^{[2]}(z).

We also have

Bu(z,1)=zA2+q[1](z)=z(1z)2+2(1z)2ln11z.B_u(z,1)=zA^2+q^{[1]}(z) =\frac{z}{(1-z)^2}+\frac{2}{(1-z)^2}\ln\frac1{1-z}.

Substituting into the expression for (q[2])(z)(q^{[2]})'(z) and simplifying yields a linear first-order ODE, with q[2](0)=0q^{[2]}(0)=0, of the form

(q[2])(z)21zq[2](z)=14(1z)412(1z)3+24(1z)4ln11z8(1z)3ln11z+8(1z)4ln211z.(q^{[2]})'(z)-\frac{2}{1-z}\,q^{[2]}(z)= \frac{14}{(1-z)^4} - \frac{12}{(1-z)^3} + \frac{24}{(1-z)^4}\ln\frac{1}{1-z} - \frac{8}{(1-z)^3}\ln\frac{1}{1-z} + \frac{8}{(1-z)^4}\ln^2\frac{1}{1-z}.

The integrating factor is (1z)2(1-z)^2. The solution confirms that

q[2](z)=6(1z)3+8(1z)3ln11z+8(1z)4ln211z+8(1z)212(1z)2ln11z4(1z)2ln211z.q^{[2]}(z) = \frac{6}{(1-z)^3} + \frac{8}{(1-z)^3}\ln\frac{1}{1-z} + \frac{8}{(1-z)^4}\ln^2\frac{1}{1-z} + \frac{8}{(1-z)^2} - \frac{12}{(1-z)^2}\ln\frac{1}{1-z} - \frac{4}{(1-z)^2}\ln^2\frac{1}{1-z}.

Exercise 3.68

Let’s start with the sum

q[2](z)+q[1](z)=6(1z)3+8(1z)3ln11z+8(1z)4ln211z+8(1z)210(1z)2ln11z4(1z)2ln211z.q^{[2]}(z)+q^{[1]}(z)= \frac{6}{(1-z)^3} +\frac{8}{(1-z)^3}\ln\frac1{1-z} +\frac{8}{(1-z)^4}\ln^2\frac1{1-z} +\frac{8}{(1-z)^2} -\frac{10}{(1-z)^2}\ln\frac1{1-z} -\frac{4}{(1-z)^2}\ln^2\frac1{1-z}.

The following list shows the necessary coefficient extraction toolbox. The first identity is a left-shifted elementary OGF from Table 3.1. The second identity is given in Exercise 3.28. The last one is derived by differentiating both sides of the second identity w.r.t. α\alpha.

  • [zN]1(1z)α=(N+α1α1)[z^N]\frac1{(1-z)^\alpha}=\binom{N+\alpha-1}{\alpha-1}

  • [zN]1(1z)αln11z=(N+α1α1)(HN+α1Hα1)[z^N]\frac{1}{(1-z)^\alpha}\ln\frac1{1-z} =\binom{N+\alpha-1}{\alpha-1}\bigl(H_{N+\alpha-1}-H_{\alpha-1}\bigr).

  • [zN]1(1z)αln211z=(N+α1α1)((HN+α1Hα1)2(HN+α1(2)Hα1(2)))[z^N]\frac{1}{(1-z)^\alpha}\ln^2\frac1{1-z} =\binom{N+\alpha-1}{\alpha-1}\Bigl(\bigl(H_{N+\alpha-1}-H_{\alpha-1}\bigr)^2-\bigl(H_{N+\alpha-1}^{(2)}-H_{\alpha-1}^{(2)}\bigr)\Bigr).

Now it’s a matter of getting coefficients for each summand and consolidating the result. Recall that variance is defined as

Var(CN)=[zN](q[2](z)+q[1](z))([zN]q[1](z))2.\operatorname{Var}(C_N)=[z^N](q^{[2]}(z)+q^{[1]}(z))-([z^N]q^{[1]}(z))^2.

Using a computer algebra tool we can confirm the exact expression for the variance given in Theorem 3.9.

Exercise 3.69 🌟

n,k0(nk)ukznn!=n0(k0(nk)uk)znn!=n0(1+u)nznn!=n0((1+u)z)nn!=e(1+u)z(see Table 3.4).\begin{align*} \sum_{n,k \ge 0} \binom{n}{k} u^k \frac{z^n}{n!} &= \sum_{n \ge 0} \left( \sum_{k \ge 0} \binom{n}{k} u^k \right) \frac{z^n}{n!} \\ &= \sum_{n \ge 0} (1+u)^n \frac{z^n}{n!} \\ &= \sum_{n \ge 0} \frac{((1+u)z)^n}{n!} \\ &= e^{(1+u)z} && \text{(see Table 3.4)}. \end{align*}
n,k0k![nk]ukznn!=k0k!uk(n0[nk]znn!)=k0k!uk[1k!(ln11z)k](see Table 3.6)=k0(uln11z)k=11uln(11z).\begin{align*} \sum_{n,k \ge 0} k! \left[ \begin{matrix} n \\ k \end{matrix} \right] u^k \frac{z^n}{n!} &= \sum_{k \ge 0} k! u^k \left( \sum_{n \ge 0} \left[ \begin{matrix} n \\ k \end{matrix} \right] \frac{z^n}{n!} \right) \\ &= \sum_{k \ge 0} k! u^k \left[ \frac{1}{k!} \left( \ln \frac{1}{1-z} \right)^k \right] && \text{(see Table 3.6)} \\ &= \sum_{k \ge 0} \left(u \ln \frac{1}{1-z} \right)^k \\ &= \frac{1}{1 - u \ln \left( \frac{1}{1-z} \right)}. \end{align*}
n,k0k!{nk}ukznn!=k0k!uk(n0{nk}znn!)=k0k!uk[1k!(ez1)k](see Table 3.6)=k0(u(ez1))k=11u(ez1).\begin{align*} \sum_{n,k \ge 0} k! \left\{ \begin{matrix} n \\ k \end{matrix} \right\} u^k \frac{z^n}{n!} &= \sum_{k \ge 0} k! u^k \left( \sum_{n \ge 0} \left\{ \begin{matrix} n \\ k \end{matrix} \right\} \frac{z^n}{n!} \right) \\ &= \sum_{k \ge 0} k! u^k \left[ \frac{1}{k!} (e^z - 1)^k \right] && \text{(see Table 3.6)} \\ &= \sum_{k \ge 0} (u (e^z - 1))^k \\ &= \frac{1}{1 - u(e^z - 1)}. \end{align*}

Exercise 3.70

zk(1z)k+1n(nk)zn=zk+1(1z)k+1n(n1k)zn+zk(1z)kn(n1k1)zn.\underbrace{\frac{z^k}{(1-z)^{k+1}}}_{\sum_n\binom{n}{k}z^n} = \underbrace{\frac{z^{k+1}}{(1-z)^{k+1}}}_{\sum_n\binom{n-1}{k}z^n}+\underbrace{\frac{z^k}{(1-z)^k}}_{\sum_n\binom{n-1}{k-1}z^n}.

By matching coefficients on both sides, we obtain the desired identity.

Exercise 3.71

k[nk]uk=u(u+1)(u+2)(u+n1)=u(u+1)(u+n2)k[n1k]uk(u+n1)=(n1)k[n1k]uk+uk[n1k]uk=k(n1)[n1k]uk+k[n1k1]uk=k((n1)[n1k]+[n1k1])uk.\begin{align*} \sum_{k} {n \brack k}u^k &= u(u+1)(u+2)\cdots(u+n-1) \\ &= \underbrace{u(u+1)\cdots(u+n-2)}_{\sum_{k}{n-1 \brack k}u^k} \cdot (u + n - 1) \\ &= (n-1)\sum_{k}{n-1 \brack k}u^k + u\sum_{k}{n-1 \brack k}u^k \\ &= \sum_{k}(n-1){n-1 \brack k}u^k + \sum_{k}{n-1 \brack k-1}u^k \\ &= \sum_{k}\left((n-1){n-1 \brack k}+{n-1 \brack k-1}\right)u^k. \end{align*}

By matching coefficients on both sides, we obtain the desired identity.

Exercise 3.72

zk(1z)(12z)(1kz)n{nk}zn=kzk+1(1z)(12z)(1kz)nk{n1k}zn+zk(1z)(12z)(1(k1)z)n{n1k1}zn.\begin{align*} \underbrace{\frac{z^k}{(1-z)(1-2z)\dots(1-kz)}}_{\sum_n{n \brace k}z^n} = \underbrace{\frac{kz^{k+1}}{(1-z)(1-2z)\dots(1-kz)}}_{\sum_nk{n-1 \brace k}z^n}+\underbrace{\frac{z^k}{(1-z)(1-2z)\dots(1-(k-1)z)}}_{\sum_n{n-1 \brace k-1}z^n}. \end{align*}

By matching coefficients on both sides, we obtain the desired identity.

Exercise 3.73

Setting x=0x = 0 in the definition yields

Bm(0)=k(mk)Bk0mk=(mm)Bm1=Bm.B_m(0) = \sum_k \binom{m}{k} B_k \cdot 0^{m-k} = \binom{m}{m} B_m \cdot 1 = B_m.

Considering the EGF of the Bernoulli polynomials for x=1x=1 and using Table 3.6 gives

m0Bm(1)zmm!=zezez1=zez1+z=m0Bmzmm!+z.\begin{align*} \sum_{m\ge0} B_m(1) \frac{z^m}{m!} &= \frac{z e^z}{e^z - 1} \\ &=\frac{z}{e^z - 1} + z \\ &= \sum_{m\ge0} B_m \frac{z^m}{m!} + z. \end{align*}

By matching coefficients on both sides, we have

  • B0(1)=B0B_0(1)=B_0

  • B1(1)=B1+1B_1(1) = B_1 + 1

  • Bm(1)=BmB_m(1) = B_m for m>1m>1.

Exercise 3.74

We start with the EGF of the Bernoulli numbers (see Table 3.6)

f(z)=zez1=m0Bmzmm!.f(z)=\frac{z}{e^z - 1} = \sum_{m\ge0} B_m \frac{z^m}{m!}.

Let’s define g(z)=f(z)+z/2g(z)=f(z)+z/2. It is easy to show that g(z)=g(z)g(-z)=g(z), which means g(z)g(z) is even. Expanding g(z)g(z) gives

g(z)=m0Bmzmm!+z2=B0+B1z+m2Bmzmm!+z2=1+(12)z+z2+m2Bmzmm!=1+m2Bmzmm!.\begin{align*} g(z) &= \sum_{m\ge0} B_m \frac{z^m}{m!} + \frac{z}{2} \\ &= B_0 + B_1 z + \sum_{m\ge 2} B_m \frac{z^m}{m!} + \frac{z}{2} \\ &= 1 + \left(-\frac{1}{2}\right) z + \frac{z}{2} + \sum_{m\ge 2} B_m \frac{z^m}{m!} \\ &= 1 + \sum_{m\ge 2} B_m \frac{z^m}{m!}. \end{align*}

Since g(z)g(z) is even, its series expansion contains only even powers of zz. Therefore, BkB_k is zero for kk odd, k3k \ge 3. This concludes the proof.

Exercise 3.75

This exercise is a simple generalization of the DGF for even numbers from the book. Observe that a positive integer NN ending in k0k \ge 0 zeros has the form N=2kMN=2^kM, where M1M \ge 1. This gives

N1ends in k 0s1Nz=N11(2kN)z=12kzζ(z).\sum_{\substack{N \ge 1\\\text{ends in $k$ 0s}}} \frac{1}{N^z}=\sum_{N \ge 1} \frac{1}{(2^kN)^z}=\frac{1}{2^{kz}}\zeta(z).

Exercise 3.76

The previous exercise already provides much of the answer, we just need to sum up DGFs for all k1k \ge 1, since absence of a kernel component entails a count of zero (odd number). This gives

N1ψNNz=k112kzζ(z)=ζ(z)k1(12z)k=ζ(z)2z1.\sum_{N\ge1}\frac{\psi_N}{N^z}=\sum_{k\ge1}\frac{1}{2^{kz}}\zeta(z)=\zeta(z)\sum_{k\ge1}\left(\frac{1}{2^{z}}\right)^k=\frac{\zeta(z)}{2^z-1}.

Exercise 3.77

We want to have kernel components only for perfect squares. Using the same idea as for even numbers from the book (see also Exercise 3.75), we have

N11(N2)z=N11N2z=ζ(2z).\sum_{N \ge 1}\frac{1}{(N^2)^z}=\sum_{N \ge 1}\frac{1}{N^{2z}}=\zeta(2z).

Exercise 3.78

This directly follows from the definition of the Lambert series.

Last updated