Generating functions provide a standard tool for enumeration. In this chapter we combine the use of generating functions with the so-called symbolic method which provides a simple systematic way of obtaining the generating function of a class of combinatorial objects by a symbolic description of the class. Generating functions can be thought of as analytic complex functions or can be viewed simply as formal power series, by disregarding convergence issues. Although we will not completely ignore the analytic perspective, we will mostly adopt this latter point of view. Basic definitions and results on formal power series are included, which includes the useful Lagrange inversion formula.

1.1 Formal Power Series

Consider the set of sequences of complex numbers

$$\displaystyle \begin{aligned} \mathbb C^{\mathbb N}=\{ (a_0,a_1,\ldots ): a_i\in \mathbb C\}. \end{aligned}$$

Defining addition coordinate by coordinate,

$$\displaystyle \begin{aligned} (a_0,a_1,\ldots)+(b_0,b_1,\ldots )=(a_0+b_0,a_1+b_1,\ldots) \end{aligned}$$

and multiplication by convolution,

$$\displaystyle \begin{aligned} (a_0,a_1,\ldots, a_n,\ldots )(b_0,b_1,\ldots, c_n,\ldots )=(a_0b_0,a_0b_1+a_1b_0,\ldots , \sum_{k=0}^na_kb_{n-k},\ldots) \end{aligned}$$

one obtains the ring \(\mathbb C[[z]]\) of formal power series.

This becomes evident if we identify the sequence \((0,1,0,\ldots )\) with the symbol z, so that

$$\displaystyle \begin{aligned} (a_0,a_1,\ldots )=\sum_{n\geqslant 0} a_nz^n. \end{aligned}$$

Proposition 1.1

\(A(z)\in \mathbb C[[z]]\) has multiplicative inverse if and only if \(a_0\neq 0\).

Proof

Suppose that there is \(B(z)\in \mathbb C[[z]]\) such that

$$\displaystyle \begin{aligned} A(z)B(z)=1. \end{aligned}$$

Then \(a_0b_0=1\), so \(a_0\neq 0\).

Reciprocally, if \(a_0\neq 0\) then one can obtain the coefficients of \(B(z)\) such that \(A(z)B(z)=1\) from the equations

$$\displaystyle \begin{aligned} a_0b_0=1 &\ \ \mathrm{implies}\ \ b_0=a_0^{-1}, \ \ \mathrm{and}\\ \sum_{k=0}^n a_kb_{n-k}=0 &\ \ \mathrm{implies} \ \ b_n=-a_0^{-1}\sum_{k=1}^{n} a_kb_{n-k}, \end{aligned} $$

which provide the values of \(b_n\) for all \(n\geqslant 0\). □

We will use the notation

$$\displaystyle \begin{aligned} {[}z^n]A(z) \end{aligned}$$

to denote the n-th coefficient \(a_n\) of the formal power series \(A(z)\).

A brief recap of expansions in power series will be useful. They can be obtained in the context of formal power series, or, in the case of the elementary functions, as a shorthand definition of the series.

$$\displaystyle \begin{aligned} \left(\frac{1}{1-az}\right)^k=&\sum_{n\geqslant 0}\binom{n+k-1}{k-1}a^nz^n,\; k\geqslant 1,\\ (1+z)^{\alpha}=&\sum_{n\geqslant 0}\binom{\alpha}{n}z^n, \alpha\in \mathbb R,\\ e^z=&\sum_{n\geqslant 0} \frac{z^n}{n!},\\ \ln (\frac{1}{1-z})=&\sum_{n\geqslant 1}\frac{z^n}{n},\\ \sin (z)=&\sum_{n\geqslant 1}(-1)^{n+1}\frac{z^{2n-1}}{(2n-1)!},\\ \cos (z)=&\sum_{n\geqslant 0}(-1)^n\frac{z^{2n}}{(2n)!}.\\ \end{aligned} $$

Let \(A(z), B(z)\) be a formal power series with \(b_0=0\). We can define the composition of two series by

$$\displaystyle \begin{aligned} A(B(z))=\sum_{n\geqslant 0} a_n(B(z))^n. \end{aligned}$$

This is well defined since the n-th coefficient of \(C=A(B(z))\) is obtained by the finite sum

$$\displaystyle \begin{aligned} {[z^n]}C(z)=\sum_{k\geqslant 0} a_k[z^{n}] ((B(z))^k)=\sum_{k=0}^n a_k[z^n](B(z)^k). \end{aligned}$$

We note that if \(b_0\neq 0\) then the above expression may lead to a series which can be divergent in \(\mathbb C\). On the other hand, in analysis one can expand in power series the composition \(\exp (1+z)\), say, which would not be admitted in the setting of formal power series.

1.2 Combinatorial Classes

A combinatorial class \(\mathcal A\) is a countable family of combinatorial objects equipped with a size function

$$\displaystyle \begin{aligned} |\cdot|:\mathcal A\to \mathbb N,\end{aligned}$$

with the condition that the number \(a_n\) of objects in \(\mathcal A\) with size n is finite for each natural n.

Examples are the class of natural numbers \(\mathbb N\) with \(|n|=n\), the class of subsets of \(\{1,\ldots ,n\}\) with size the cardinality, or the class of permutations,where its size is the size of the ground set on which the permutations are defined.

The ordinary generating function of a class \(\mathcal A\) is defined as

$$\displaystyle \begin{aligned} A(z)=\sum_{\alpha\in \mathcal A} z^{|\alpha|}=\sum_{n\geqslant 0}a_n z^n, \end{aligned}$$

where \(a_n\) is the number of objects of size n in \(\mathcal A\).

The symbolic method in enumeration consists of translating formal (symbolic) descriptions of a combinatorial class into algebraic operations of the corresponding generating functions. The symbolic method often provides a simple and clean method to obtain generating functions of combinatorial classes built upon simpler ones.

The disjoint union \(\mathcal A+ \mathcal B\) of two combinatorial classes \(\mathcal A\) and \(\mathcal B\) is the class formed by all objects in \(\mathcal A\) and all objects in \(\mathcal B\). If \(\gamma \in \mathcal {C}\) then it is either in \(\mathcal A\) and its size is as it is in \(\mathcal A\) or it is in \(\mathcal B\) and its size is as it is in \(\mathcal B\).

Proposition 1.2

If \(\mathcal {C}=\mathcal A+\mathcal B\) then the ordinary generating function for \(\mathcal {C}\) is

$$\displaystyle \begin{aligned} C(z)=A(z)+B(z). \end{aligned}$$

The cartesian product \(\mathcal A\times \mathcal B\) of two combinatorial classes is the class

$$\displaystyle \begin{aligned} {\mathcal C}=\{ (\alpha, \beta), \alpha \in \mathcal A, \beta\in \mathcal B\}, \end{aligned}$$

equipped with the size function

$$\displaystyle \begin{aligned} |(\alpha,\beta)|{}_{\mathcal C}=|\alpha|{}_{\mathcal A}+|\beta|{}_{\mathcal B}. \end{aligned}$$

Proposition 1.3

If \(\mathcal {C}=\mathcal A\times \mathcal B\) then the ordinary generating function for \(\mathcal {C}\) is

$$\displaystyle \begin{aligned} C(z)=A(z)B(z). \end{aligned}$$

Proof

We have

$$\displaystyle \begin{aligned} C(z)=\sum_{(\alpha,\beta)\in \mathcal A\times \mathcal B} z^{|(\alpha,\beta)|}=\sum_{(\alpha,\beta)\in \mathcal A\times \mathcal B} z^{|\alpha|+|\beta|}=\left(\sum_{\alpha\in \mathcal A}z^{|\alpha|}\right)\left(\sum_{\beta\in \mathcal B}z^{|\beta|}\right). \end{aligned}$$

The sequence \({\text{Seq}}(\mathcal A)\) of \(\mathcal A\) is defined as

$$\displaystyle \begin{aligned} \text{Seq}(\mathcal A)=\{ \epsilon\}+\mathcal A+(\mathcal A\times \mathcal A)+(\mathcal A\times \mathcal A\times \mathcal A)+\cdots \end{aligned}$$

and consists of all k-tuples \((\alpha _1,\ldots ,\alpha _k)\) of elements of \(\mathcal A\) with \(k\geqslant 0\). The class \(\{\epsilon \}\) is a special class containing a single object \(\epsilon \) of size zero.

Proposition 1.4

If \(\mathcal {C}=\mathit{\text{Seq}}(\mathcal A)\) then

$$\displaystyle \begin{aligned} C(z)=\frac{1}{1-A(z)}. \end{aligned}$$

Proof

According to the formal description of \( \text{Seq}(\mathcal A)\) we have

$$\displaystyle \begin{aligned} C(z)=1+A(z)+A(z)^2+A^3(z)+\cdots, \end{aligned}$$

which in the ring of formal power series is the multiplicative inverse of \((1-A(z))\). □

1.3 Examples

The above three operations of classes already provide the means to address a large number of enumerative problems. Some additional operations will be discussed in the list of exercises.

A composition of a number n is a k-tuple \((a_1,\ldots ,a_k)\) of nonzero integers, for some \(k\geqslant 1\), such that

$$\displaystyle \begin{aligned} n=a_1+\cdots +a_k.\end{aligned}$$

Its size is the sum n of its components.

The class \({\mathcal C}\) of compositions can be constructed from the class \(\mathbb N\) of integers (not including zero) as

$$\displaystyle \begin{aligned} {\mathcal C}=\text{Seq} (\mathbb N). \end{aligned}$$

If \(N(z)=\sum _{n\geqslant 1}z^n\) denotes the generating function of \(\mathbb N\) then

$$\displaystyle \begin{aligned} C(z)=\frac{1}{1-N(z)}=\frac{1}{1-\frac{z}{1-z}}=\frac{1-z}{1-2z}. \end{aligned}$$

By expanding the power series we get

$$\displaystyle \begin{aligned} [z^n]C(z)=2^{n-1}. \end{aligned}$$

Observe that this result can be easily obtained by considering n dots in row. By placing or not placing a separator between two consecutive dots, we obtain a composition of n by letting \(a_i\) be the number of dots between the \((i-1)\)-th separator and the i-th separator, see Fig. 1.1.

Fig. 1.1
An illustration. Eight dots are presented. Three vertical lines are drawn between the second and third dots, the fifth and sixth dots, and the sixth and seventh dots.

The composition \((2,3,1,2)\) of the number 8

The flexibility of the symbolic method is illustrated by considering variations of an enumeration problem. Consider the class \({\mathcal C}_k\) of compositions of a number into k summands. Then

$$\displaystyle \begin{aligned} {\mathcal C}_k=(\mathbb N)^k,\; \text{and}\; C_k(z)=\left(\frac{z}{1-z}\right)^k, \end{aligned}$$

from which

$$\displaystyle \begin{aligned} [z^n]C_k(z)=\binom{n-1}{k-1}. \end{aligned}$$

One can also consider restrictions on the number of parts and on the nature of the parts.

Proposition 1.5

Let \(\mathcal {C}_{A,B}\) be the class of compositions of integers in which the number of parts belongs to \(A\subset \mathbb N\) and the parts themselves belong to \(B\subset \mathbb N\). The generating function of \(\mathcal {C}_{A,B}\) is

$$\displaystyle \begin{aligned} C_{A,B}=\sum_{k\in A}(B(z))^k, \end{aligned}$$

where \(B(z)=\sum _{b\in B}z^b\) is the generating function of B.

For example, the number of compositions into an odd number of odd parts has generating function

$$\displaystyle \begin{aligned} \sum_{k\geqslant 0} (B(z))^{2k+1}=&B(z)\sum_{k\geqslant 0}(B(z))^{2k}=\frac{B(z)}{1-B^2(z)}\\ &=\frac{\frac{z}{1-z^2}}{1-\frac{z^2}{(1-z^2))^2}}=\frac{z(1-z^2)}{(1-z^2)^2-z^2}\\ &=\frac{z(1-z^2)}{1-3z^2+z^4}. \end{aligned} $$

As another example, the number of compositions of n into parts 1 and 2 is

$$\displaystyle \begin{aligned} {\mathcal C}_{\{1,2\}}=\text{Seq}(\{1\}+\{2\}), \end{aligned}$$

and

$$\displaystyle \begin{aligned} C_{\{1,2\}}(z)=\frac{1}{1-z-z^2}. \end{aligned}$$

The denominator factorises as

$$\displaystyle \begin{aligned} 1-z-z^2=(1-\phi z)(1-\bar{\phi}z) \end{aligned}$$

where \(\phi =\frac {-1+\sqrt {5}}{2}\) and \(\bar {\phi }=\frac {-1-\sqrt {5}}{2}\). By expanding in power series,

$$\displaystyle \begin{aligned} C_{\{1,2\}}(z) & = \frac{1}{(1-\phi z)(1-\bar{\phi}z)}=\frac{1}{\sqrt{5}}\left( \frac{\phi}{1-\phi z}-\frac{\bar{\phi}}{1-\bar{\phi}z}\right)\\ & = \frac{1}{\sqrt{5}}\sum_{n\geqslant 0} (\phi^{n+1}-\bar{\phi}^{n+1})z^n, \end{aligned} $$

from which

$$\displaystyle \begin{aligned} [z^n]C_{\{1,2\}}(z)=\frac{1}{\sqrt{5}}(\phi^{n+1}-\bar{\phi}^{n+1}), \end{aligned}$$

is the n-th Fibonacci number.

An integer partition is a multi-set \(\{a_1,\ldots ,a_k\}\) where \(n=a_1+\cdots +a_k\) is its size. An integer partition can be seen as a sequence of 1, followed by a sequence of 2’s and so on, where each sequence can be empty. Therefore,

$$\displaystyle \begin{aligned} {\mathcal P}=\text{Seq}(\{1\})\times \text{Seq}(\{2\})\times\cdots, \end{aligned}$$

where \(\{ k \}\) is the combinatorial class with 1 object of size k, and so has ordinary generating function \(z^k\).

Hence, the generating function of the class of integer partitions is

$$\displaystyle \begin{aligned} P(z)=\prod_{k\geqslant 1} \frac{1}{1-z^k}. \end{aligned}$$

The Frobenius problem asks for the number of partitions where the parts belong to a set \(A\subset \mathbb N\). The class \({\mathcal P}_A\) of partitions with parts in \(A=\{a_1,a_2,\ldots \}\) is

$$\displaystyle \begin{aligned} {\mathcal P}_A=\text{Seq}(\{a_1\})\times \text{Seq}(\{a_2\})\times\cdots, \end{aligned}$$

and its generating function is

$$\displaystyle \begin{aligned} P_A(z)=\prod_{k\in A} \frac{1}{1-z^k}. \end{aligned}$$

For example, if \(A=\{1,2\}\) then

$$\displaystyle \begin{aligned} P_{\{1,2\}}(z)=\frac{1}{(1-z)}\frac{1}{(1-z^2)}=\frac{1}{4}\frac{1}{(1-z)}+\frac{1}{2}\frac{1}{(1-z)^2}+\frac{1}{4}\frac{1}{(1+z)}. \end{aligned}$$

By expanding the above as a power series,

$$\displaystyle \begin{aligned} P_{\{1,2\}}(z)& =\frac{1}{4}\sum_{n\geqslant 0} z^n+\frac{1}{2}\sum_{n\geqslant 0} (n+1)z^n+\frac{1}{4}\sum_{n\geqslant 0}(-1)^nz^n\\ & =\sum_{n\geqslant 0} \left(\frac{1+(-1)^n}{4}+\frac{n+1}{2}\right)z^n, \end{aligned} $$

which gives

$$\displaystyle \begin{aligned} [z^n]P_{\{1,2\}}(z)=\begin{cases} (n+2)/2, & n\; \text{even}\\ (n+1)/2, & n\; \text{odd}\end{cases} \end{aligned}$$

again a result which can be obtained by direct analysis.

A set partition is a partition of \(\{1,\ldots ,n\}\) into k parts. The size of a partition is n. The class \(\Pi _k\) denotes the combinatorial class of set partitions into k parts.

A symbolic description of the class of partitions can be obtained with the following encoding of set partitions into k parts. Denote by \(\{b_1,\ldots ,b_k\}\) the subsets of the partition ordered by its smaller element, so

$$\displaystyle \begin{aligned} \min b_1<\min b_2<\cdots <\min b_k. \end{aligned}$$

We construct a word of length n with the letters \(b_i\) by placing \(b_i\) in the j-th position if and only if \(j\in b_i\). The resulting word identifies the partition and it has the property that, for \(i<j\), the letter \(b_j\) does not appear in the word before \(b_{i}\). For example,

$$\displaystyle \begin{aligned} \{\{1,3,4\},\{2,8\},\{5,6,7\}\}\leftrightarrow (b_1,b_2,b_1,b_1,b_3,b_3,b_3,b_2). \end{aligned}$$

The set of such words has the symbolic description

$$\displaystyle \begin{aligned} \Pi_k=\{b_1\}\times\text{Seq}(\{b_1\})\times \{b_2\}\times\text{Seq}(\{b_1,b_2\})\times \cdots \times \{b_k\}\times\text{Seq}(\{b_1,\ldots ,b_k\}). \end{aligned}$$

Accordingly, its generating function is

$$\displaystyle \begin{aligned} P_k(z)=\frac{z^k}{(1-z)(1-2z)\cdots (1-kz)}. \end{aligned}$$

By decomposing into simple fractions,

$$\displaystyle \begin{aligned} \frac{1}{(1-z)(1-2z)\cdots (1-kz)}=\sum_{j=1}^k\frac{\alpha_j}{(1-jz)}, \end{aligned}$$

where the value of \(\alpha _j\) can be obtained by multiplying both sides by \((1-jz)\) and setting \(z=1/j\), which gives

$$\displaystyle \begin{aligned} \alpha_j=\frac{1}{\prod_{i=1,i\neq j}^k((j-i)/j)}=(-1)^{k-j}\frac{j^{k-1}}{(j-1)!(k-j)!}. \end{aligned}$$

In this way one obtains the formula for the Stirling numbers of the second kind,

$$\displaystyle \begin{aligned} \left\{\begin{array}{cc}n\\k\end{array}\right\}=[z^n]P_k(z)=\frac{1}{k!}\sum_{j=1}^k (-1)^{k-j}{k\choose j}j^n. \end{aligned}$$

A Dyck path is a sequence of points in the plane integer lattice starting with \((0,0)\), ending in \((2n,0)\), and making steps \((1,1)\) or \((1,-1)\) with the property that the path does not cross the x-axis, i.e. all points have non-negative ordinate (y coordinate). Its size is 2n.

Figure 1.2 shows the five Dyck paths of length six.

Fig. 1.2
Five six-by-three grids. A, a line passes through (0, 0), (3, 3),(6, 0). B, a line passes through (0, 0), (2, 2), (3, 1), (4, 2), (6, 0). C, a line passes through (0, 0), (2, 2), (4, 0), (5, 1), (6, 0). D, a line passes through (0, 0), (1, 1), (2, 0), (3, 1), (4, 0), (5, 1), (6, 0).

The Dyck paths of length six

If we represent the steps by \(\nearrow \) and \(\searrow \) then a Dyck path is a sequence of these two symbols such that the number of \(\nearrow \)’s is never smaller than the number of \(\searrow \)’s as we make the path from \((0,0)\) to \((2n,0)\). In order to give a symbolic description of this property, we write the following recursive description of the class \({\mathcal D}\) of Dyck paths. By considering the first time the path hits the line \(\{y=0\}\), we can describe (uniquely) a Dyck path as a step \(\nearrow \) followed by a Dyck path followed by a step \(\searrow \) and another Dyck path. Therefore,

$$\displaystyle \begin{aligned} {\mathcal D}=\{\epsilon\}+\{\nearrow\}\times {\mathcal D}\times \{\searrow\}\times {\mathcal D}. \end{aligned}$$

Note that the use of the class \(\{\epsilon \}\) with an only object of size zero is crucial for the correctness of the above description.

This gives, for the generating function, the functional equation

$$\displaystyle \begin{aligned} D(z)=1+z^2(D(z))^2. \end{aligned}$$

which gives

$$\displaystyle \begin{aligned} D(z)=\frac{1\pm\sqrt{1-4z^2}}{2z^2}. \end{aligned}$$

The value \(D(0)=1\) indicates the choice of minus sign as the appropriate branch of the solution.

By power expansion we obtain

$$\displaystyle \begin{aligned} d_{2n}=\frac{1}{n+1}\binom{2n}{n}, \end{aligned}$$

the n-th Catalan number, for the number of Dyck paths of length 2n. In Sect. 1.5, we will see a more efficient method to obtain this coefficient directly from the functional equation.

1.4 Rooted Plane Trees

A rooted plane tree is a rooted tree drawn in the plane, so that the order of the subtrees pending from the root is taken into account. In other words, a plane tree is a rooted tree in which for every node, there is an ordering of its children. Thus, the two trees in Fig. 1.3 are distinct as plane trees.

Fig. 1.3
An illustration of two distinct rooted plane trees with five nodes. A, a node branched into two nodes. The second node branches to two nodes. B, a node branched into two nodes. The first node branches to two nodes.

Two distinct rooted plane trees

Let \({\mathcal T}\) be the class of rooted plane trees, its size being the number of nodes. The class admits a recursive functional description as

$$\displaystyle \begin{aligned} {\mathcal T}={\mathcal N}\times \text{Seq}({\mathcal T}), \end{aligned}$$

where \({\mathcal N}\) is a class with a single object of size one. So, a plane tree is a root together with a sequence of plane trees.

This gives the generating function

$$\displaystyle \begin{aligned} T(z)=z\frac{1}{1-T(z)} \end{aligned}$$

from which we obtain

$$\displaystyle \begin{aligned} T(z)=\frac{1-\sqrt{1-4z}}{2}, \end{aligned}$$

where the minus sign is chosen so that \(T(0)=0\). By expanding in power series one gets

$$\displaystyle \begin{aligned} T_n=[z^n]T(z)=\frac{1}{n}\binom{2n-2}{n-1}, \end{aligned}$$

the \((n-1)\)-th Catalan number.

The symbolic method shows its flexibility once more by allowing one to consider restricted classes of plane trees according to the number of children of each node.

Proposition 1.6

Let \({\mathcal T}_U\) be the class of rooted plane trees in which the number of children of every node is in \(U\subset \mathbb N\). Its generating function satisfies the functional equation

$$\displaystyle \begin{aligned} T_U(z)= z(U(T(z))),\; \mathit{\text{where}}\; U(z)=\sum_{n\in U}z^n. \end{aligned}$$

A binary tree is a rooted plane tree in which every node has either two or zero children. Let \(\mathcal B\) be the class of binary trees where the size of a tree is the number of internal nodes (not the number of nodes this time). A binary tree is a root from which two binary trees are hanging. The root has now size zero, so

$$\displaystyle \begin{aligned} \mathcal B=\{\epsilon\}+{\mathcal N}\times \mathcal B\times \mathcal B, \end{aligned}$$

which gives the functional equation

$$\displaystyle \begin{aligned} B(z)=1+zB^2(z). \end{aligned}$$

Therefore,

$$\displaystyle \begin{aligned} B(z)=\frac{1-\sqrt{1-4z}}{2z}, \end{aligned}$$

and

$$\displaystyle \begin{aligned} b_n=\frac{1}{n+1}\binom{2n}{n}, \end{aligned}$$

which is again the n-th Catalan number.

1.5 Lagrange Inversion Formula

A natural extension of the ring of formal power series is its quotient field. In order to obtain a field one can use the formal Laurent series,

$$\displaystyle \begin{aligned} \sum_{n\geqslant -k} a_nz^n, \end{aligned}$$

where \(k\in \mathbb N\), so the series has a finite number of negative powers. The sum and product are defined in the same way as before. The field of formal Laurent series is the quotient field of \(\mathbb C[[z]]\) denoted by \(\mathbb C((z))\).

If \(k \in {\mathbb Z}\) (in particular if \(k<0\)) and \(A(z)=\sum _{n\geqslant k} a_nz^n\), the multiplicative inverse of \(A(z)\), in the set of formal Laurent series, can be obtained by writing

$$\displaystyle \begin{aligned} A(z)=z^k(\sum_{n\geqslant 0} a_{n+k} z^n)=z^kA_1(z). \end{aligned}$$

If \(B_1(z)=\sum _{n\geqslant 0}b_nz^n\) is the multiplicative inverse of \(A_1(z)\) in \(\mathbb C [[z]]\) then

$$\displaystyle \begin{aligned} B(z)=z^{-k} B_1^{-1}(z)=\frac{b_0}{z^k}+\frac{b_1}{z^{k-1}}+\cdots =\sum_{n\geqslant -k} b_{n+k}z^n \end{aligned}$$

is the multiplicative inverse of \(A(z)\) in \(\mathbb C ((z))\).

The formal derivation of a power series \(A(z)\sum _{n\geqslant 0}a_nz^n\) is

$$\displaystyle \begin{aligned} A'(z)=\sum_{n\geqslant 1} na_nz^{n-1}, \end{aligned}$$

which can be easily seen to satisfy the usual properties of derivation, for example the product and chain rules hold. The usual rule for derivation of quotients also holds and extends the notion of derivative to the field of formal Laurent series: if \(A(z)=\sum _{n\geqslant -k} a_nz^n\), where \(k>0\), then

$$\displaystyle \begin{aligned} A'(z)=\sum_{n\geqslant -k} na_n z^{n-1}. \end{aligned}$$

The coefficient \(a_{-1}\) of \(z^{-1}\) in \(A(z)\) is called the residue of \(A(z)\) (notation again coming from analysis). It is denoted \(\mathrm {Res}(A(z))\) and it plays a significant role.

Since \([z^{-1}]A'(z)=0\),

$$\displaystyle \begin{aligned} \mathrm{Res} (A'(z))=0, \end{aligned}$$

for every formal Laurent series \(A(z)\).

Moreover, if \(A(z)=\sum _{n\geqslant -k} a_nz^n\) then

$$\displaystyle \begin{aligned} {} \mathrm{Res}(\frac{A'(z)}{A(z)})=-k. \end{aligned} $$
(1.1)

To see the last equality one can write

$$\displaystyle \begin{aligned} A'(z)=z^{-k-1}\sum_{n\geqslant -k}na_nz^{n+k} \end{aligned}$$

and

$$\displaystyle \begin{aligned} A(z)=z^{-k}\sum_{n\geqslant -k} a_nz^{n+k}, \end{aligned}$$

so that the quotient

$$\displaystyle \begin{aligned} \frac{A'(z)}{A(z)}=\frac{1}{z}(c_0+c_1z+\cdots), \end{aligned}$$

where \(-ka_{-k}=c_0a_{-k}\).

We can now state the main result of this section.

Theorem 1.7

Let \(A(z)=\sum _{n\geqslant 1} a_nz^n\), that is, \(a_0=0\) and \(a_1\neq 0\). Let B be the functional inverse of A, i.e.

$$\displaystyle \begin{aligned} B(A(z))=z. \end{aligned}$$

Then

$$\displaystyle \begin{aligned} [z^n] B(z) = [z^{-1}]\frac{1}{n A(z)^n}. \end{aligned}$$

Proof

Let \(B(z)=\sum _{n\geqslant 1}b_nz^n\). The formal derivative of \(B((A(z))=z\) leads to

$$\displaystyle \begin{aligned} \sum_{k\geqslant 1} jb_jA'(z)(A(z))^{j-1}=1. \end{aligned}$$

For a fixed n we divide both sides of the equality by \(nA(z)^n\) and take the residue.

For \(j\neq n\),

$$\displaystyle \begin{aligned} (A(z))^{j-1-n}A'(z)=\frac{1}{j-n}(A(z)^{j-n})' \end{aligned}$$

is a derivative and therefore the terms for which with \(j \neq n\) have residue zero.

For \(j=n\) one gets \(A'(z)/A(z)\) whose residue is 1 by (1.1) with \(k=-1\), which proves the lemma. □

The Lagrange inversion formula is one of the consequences of Theorem 1.7.

Theorem 1.8 (Lagrange inversion)

Let \(\phi \) be an analytic function with \(\phi (0)\neq 0\). Let \(Y(z)\) satisfy the functional equation

$$\displaystyle \begin{aligned} Y(z) = z \phi(Y(z)). \end{aligned}$$

Then

$$\displaystyle \begin{aligned} [z^n] Y(z) = \frac{1}{n} [w^{n-1}] \phi(w)^n. \end{aligned}$$

Proof

One can write \(Y(z)/\phi (Y(z))=z\) so that \(B(w)=w/\phi (w)\) is the functional inverse of \(Y(z)\). By Theorem 1.7 we have

$$\displaystyle \begin{aligned} [z^n] Y(z)=[w^{-1}]\frac{1}{n B(w)^n}=\frac{1}{n} [w^{n-1}] (\phi(w))^n, \end{aligned}$$

as claimed. □

Example 1.9

For the class \(\mathcal D\) of Dyck paths we obtained the functional equation

$$\displaystyle \begin{aligned} D(z)=1+z^2D^2(z). \end{aligned}$$

By writing \(U(z)=zD(z)\) we get

$$\displaystyle \begin{aligned} U(z)=z(1+U^2(z)). \end{aligned}$$

By the Lagrange inversion formula,

$$\displaystyle \begin{aligned} [z^{2m+1}]U(z)=\frac{1}{2m+1}[t^{2m}](1+t^2)^{2m+1}=\frac{1}{2m+1}\binom{2m+1}{m}. \end{aligned}$$

Therefore,

$$\displaystyle \begin{aligned} [z^{2m}]D(z)=[z^{2m+1}]U(z)=\frac{1}{2m+1}\binom{2m+1}{m}=\frac{1}{m+1}\binom{2m}{m}. \end{aligned}$$

Example 1.10

A Motzkin path is a path with steps \((1,1), (1,-1)\) and \((1,0)\) which does not cross the x-axis. By considering the first time the path hits the line \(\{y=0\}\), we can describe (uniquely) a Motzkin path either as a step \(\nearrow \) followed by a Motzkin path followed by a step \(\searrow \) and another Motzkin path, or a horizontal step \(\rightarrow \) followed by a Motzkin path. The combinatorial class \({\mathcal M}\) of Motzkin paths is described by the symbolic equation,

$$\displaystyle \begin{aligned} {\mathcal M}=\{\epsilon\}+\{\rightarrow\}\times {\mathcal M}+\{\nearrow\}\times {\mathcal M}\times \{\searrow\}\times {\mathcal M}. \end{aligned}$$

This leads to the functional equation,

$$\displaystyle \begin{aligned} {} M(z)=1+zM(z)+z^2M^2(z). \end{aligned} $$
(1.2)

If we let \(U(z)=zM(z)\) then

$$\displaystyle \begin{aligned} U(z)=z(1+U(z)+U^2(z)). \end{aligned}$$

By Lagrange inversion formula with \(\phi (t)=(1+t+t^2)\) one gets

$$\displaystyle \begin{aligned} [z^n]U(z)&=\frac{1}{n}[t^{n-1}]\phi^n(t)=\frac{1}{n}[t^{n-1}]\sum_{i+j+k=n}{n\choose i,j,k}t^{2i+j}\\ &=\frac{1}{n}\sum_{i\geqslant 0}{n\choose i}{n-i\choose i+1}, \end{aligned} $$

and so

$$\displaystyle \begin{aligned} M_n=[z^{n+1}]U(z)=\frac{1}{n+1}\sum_{i\geqslant 0}{n+1\choose i}{n+1-i\choose i+1}, \end{aligned}$$

which gives the sequence \(1, 1, 2, 4, 9, 21, 51, 127, 323, 835, \ldots \)

This formula implies that \(M_4=9\) and Fig. 1.4 shows the 9 Motzkin paths of length four.

Fig. 1.4
9 4 by 2 grids. A, a line passes through (0, 0), (2, 2),(4, 0). B, a line passes through (0, 0), (1, 1), (3, 1), (4, 0). C, a line passes through (0, 0), (1, 1), (2, 0), (3, 1), (4, 0). D, a line passes through (0, 0), (1, 1), (3, 1), (4, 0). E, a line passes through (0, 0), (1, 1), (2, 1), (3, 0).

The nine Motzkin path of length four

Example 1.11

A dissection of a convex polygon P is a decomposition of P into polygons by non-crossing diagonals. Let \({\mathcal D} \) be the class of dissections, its size being the number of vertices of the polygon. We want to find a symbolic description of D and deduce a formula for the number \(D_n\) of dissections of a polygon of n sides.

Let \(\delta \) be a dissection of the polygon. Fix a side xy of the polygon and consider \(\rho \) the region containing the edge xy. If the polygon has \(r+1\) edges then we can identify the dissection \(\delta \) with a sequence of r dissections (possibly reduced to a single edge). In Fig. 1.5, the r dissections have sizes 2 (the edge between y and \(v_1\)), 4 (from \(v_1\) to \(v_2\)), 6 (from \(v_2\) to \(v_3\)) and 3 (from \(v_3\) to x). The r-dissections are put together in such a way that \(r-1\) of the vertices are counted twice, precisely the vertices \(v_1,v_2,v_3\) in the example. Therefore, a dissection consists of r dissections, in which \(r-1\) of the vertices have been counted twice, which gives the \({D^r}/{z^{r-1}}\) term in the functional equation for \(D(z)\). Observe that a polygon with two vertices is an edge, which has size two and of which there is one dissection.

Fig. 1.5
A dodecagon with five of its vertices x, y, v 1, v 2, and v 3 are labeled. A diagonal from v 2 to v 3 is marked and it forms an obtuse triangle with lines from another vertex joining v 2 and v 3. The area bound by x, y, v 1, v 2, and v 3 is shaded.

A dissection of the regular 12-gon

Therefore, the generating function satisfies the functional equation

$$\displaystyle \begin{aligned} D=z^2+\frac{D^2}{z}+\frac{D^3}{z^2}+\cdots+\frac{D^r}{z^{r-1}}+\cdots, \end{aligned}$$

which leads to

$$\displaystyle \begin{aligned} 2D^2-z(1+z)D+z^3=0. \end{aligned}$$

By writing \(D=zU\) we get

$$\displaystyle \begin{aligned} U=z\frac{U-1}{2U-1}. \end{aligned}$$

The coefficients of U can be extracted by the Lagrange inversion formula:

$$\displaystyle \begin{aligned} [z^n]U=\frac{1}{n}[t^{n-1}]\left(\frac{t-1}{2t-1}\right)^n=\frac{1}{n-1}\sum_{i=0}^{n-2}(-1)^i{n-1\choose i}{2n-4-i \choose n-2-i}2^{n-2-i}. \end{aligned}$$

A useful extension of Lagrange formula is given in the following theorem.

Theorem 1.12 (Bürmann–Lagrange Inversion Formula)

Let \(\phi \) be an analytic function such that \(\phi (0)\neq 0\). Let \(Y(z)\) satisfy the functional equation

$$\displaystyle \begin{aligned} Y(z) = z \phi(Y(z)). \end{aligned}$$

Then, for every analytic function g one has

$$\displaystyle \begin{aligned} [z^n] g(Y(z)) = \frac{1}{n} [t^{n-1}] g'(t)\phi(t)^n. \end{aligned}$$

In particular, if \(Y(z)=z\phi (Y(z))\) one can obtain a direct expression for the coefficients of \(Y^k(z)\) by taking \(g(t)=t^k\) in the Bürman–Lagrange formula and get

$$\displaystyle \begin{aligned} [z^n](Y(z))^k=\frac{1}{n}[t^{n-1}]kt^{k-1} \phi(t)^n=\frac{k}{n}[t^{n-k}] (\phi (t))^n. \end{aligned}$$

1.6 Notes and References

This symbolic approach to combinatorial enumeration was mostly developed by Flajolet and Sedgewick and their book Analytic Combinatorics (Flajolet and Sedgewick, 2009) is an excellent reference on the topic. The Catalan numbers appear in a host of enumeration problems, see for example Stanley (2015). The proof of the Lagrange inversion formula described here is based on Henrici (1964), see also van Lint and Wilson (2001, Appendix).

1.7 Exercises

Exercise 1.1

(Euler) Show that the number of partitions of an integer n into odd parts equals the number of partitions in distinct parts.

Exercise 1.2

Let \({\mathcal D}_k\) be the class of paths in the plane lattice which start at \((0,k)\) and end at \((n,0)\) formed by steps \((1,1)\) or \((1,-1)\) such that the points have non-negative ordinate.

  1. i.

    Find a symbolic description of \({\mathcal D}_k\) in terms of \({\mathcal D}_0\).

  2. ii.

    Give an explicit formula for the number of paths of length n in \({\mathcal D}_k\).

Exercise 1.3

(Schroeder paths) Let \({\mathcal S}\) be the class of paths in the plane lattice starting at \((0,0)\), ending at \((2n,0)\) with steps \((1,1), (2,0), (1,-1)\) such that the ordinate of every point is non-negative. Find the number of such paths with length 2n.

Exercise 1.4

Let m be a positive integer and let \({\mathcal D}^{\leqslant m}\) be the class of Dyck paths whose height does not exceed m.

  1. i.

    Show that the generating function of \({\mathcal D}^{\leqslant m}\) is a rational function. Give the generating function for \(m=2\).

  2. ii.

    Let \({\mathcal S}^{\leqslant \pm m}\) be the class of lattice paths with steps \((1,1)\) and \((1,-1)\) which start at \((0,0)\) and end at \((n,0)\) and that are contained between the lines \(y=m\) and \(y=-m\). Show that the generating function of \({\mathcal S}^{\leqslant \pm m}\) is a rational function and find an expression for \(m=3\).

Exercise 1.5

Let \({\mathcal D}\) be the class of Dyck paths such that every descent has length exactly two (the two such paths of length 8 are depicted below)

Two eight-by-three grids. A, a line starts at (0, 0), increases to (2, 2), decreases to (0, 4), increases to (2, 6), and decreases to (0, 8). B, a line starts at (0, 0), increases to (3, 3), decreases to (1, 4), increases to (2, 6), and decreases to (0, 8).
  1. i.

    Give a symbolic implicit formula for the class and derive a functional equation for the ordinary generating function of the class.

  2. ii.

    Use the Lagrange inversion to compute \(D_{4n}\) the number of paths in the class of length 4n in terms of Catalan numbers.

  3. iii.

    Use the Bürman–Lagrange inversion formula to calculate the number of ordered pairs of paths in \({\mathcal D}\) with total length 4n.

Exercise 1.6

Let \({\mathcal A}\) be the class of lattice paths starting at \((0,0)\) and ending at \((3n,0)\) with steps \((1,2)\) and \((1,-1)\) which do not cross the x-axis, and let \({\mathcal A}^+\) be the class of paths in \({\mathcal A}\) which do not touch the x-axis except in the initial and last points. The size of a path is its length.

  1. i.

    Find a symbolic description of \({\mathcal A}\) and deduce a functional equation for its generating function.

  2. ii.

    By using the Lagrange inversion formula find an explicit formula for \(a_{n}\). Describe all paths in \({\mathcal A}\) of length six.

  3. iii.

    Find a symbolic description of \({\mathcal A}^+\) and deduce a functional equation for its generating function. Give an expression for \(a^+_n\) and check it directly for \(n=6\).

Exercise 1.7

Compute the number \(E_n\) of rooted plane trees with n nodes such that every node has an even number of children.

Exercise 1.8

Let \({\mathcal W}^{<k}\) be the class of binary words with no k consecutive zeros, the size being their length. Find the generating function of the class \({\mathcal W}^{<k}\).

Exercise 1.9

Let \({\mathcal W}\) be the class of words on the alphabet \({\mathcal A}=\{a_1,a_2,\ldots ,a_m\}\), the size of a word is its length (including the empty word of size zero).

  1. i.

    Let \({\mathcal S}\subset {\mathcal W}\) be the class of words which contain no pattern of two repeated consecutive letters and that do not start with \(a_1\).

    1. (i.a)

      Justify the symbolic identity

      $$\displaystyle \begin{aligned} {\mathcal W}=((\epsilon+\{a_1\})\times {\mathcal S})+(\{a_1\}\times {\mathcal S}\times {\mathcal Z}\times {\mathcal W})+({\mathcal S}-\epsilon)\times {\mathcal Z}\times {\mathcal W}). \end{aligned}$$
    2. (i.b)

      Use the above symbolic description to derive the generating function of \({\mathcal S}\).

    3. (i.c)

      Obtain a formula for \(S_n\). Give a direct combinatorial proof of the latter.

  2. ii

    Let \(\Pi ^{nc}\) be the class of partitions of \([n]\) into k parts so that no part contains two consecutive elements, the size of the partition being the cardinality of \([n]\).

    1. (ii.a)

      Write a symbolic description of \(\Pi ^{nc}\) (recall the symbolic description of the class of all partitions into k parts).

    2. (ii.b)

      Obtain the generating function \(\Pi ^{nc}(z)\).

    3. (ii.c)

      Give an expression for the number of partitions of \([n]\) into blocks not containing consecutive elements. Check your answer for \(n=k\) and for \(n=k+1\).

Exercise 1.10

(Euler) Let \(\Pi _n\) be a convex n-gon. A triangulation of \(\Pi _n\) is a subdivision of its interior into triangles by noncrossing diagonals.

  1. i.

    Count the number of diagonals and the number of triangles a triangulation fo \(\Pi _n\) has.

  2. ii.

    Find the number of triangulations of \(\Pi _n\).

Exercise 1.11

Let \({[n]\choose k}_{\leqslant d}\) denote the set of k-subsets of \([n]\) such that every two consecutive elements are at distance (absolute value of their difference) at most d. For instance \({[4]\choose 2}_{<2}=\{\{1,2\},\{2,3\},\{3,4\}\}\). Similalry, \({[n]\choose k}_{>d}\) denotes the set of k-subsets of \([n]\) such that every two elements are at distance larger than d.

  1. i.

    Find the generating function \(\sum _{n} {n\choose k}_{\leqslant d}z^n\). Deduce that

    $$\displaystyle \begin{aligned} {n\choose k}_{\leqslant d}=\sum_j (-1)^j{k-1\choose j}{n-jd\choose k}. \end{aligned}$$
  2. ii.

    Find the generating function \(\sum _{n} {n\choose k}_{>d}z^n\) and an expression for these numbers.

[Hint: It may be useful to start from the formal specification \(\mathrm {Seq}(\{0\})\times \mathrm {Seq}(\mathrm {Seq}(\{1\}\times \mathrm {Seq}(\{0\}))\) of the binary sequences.]

Exercise 1.12

Let k and m be fixed positive integers. Let \({\mathcal T}\) be the class of rooted plane trees in which every node has at most k children, the number of nodes being the size.

  1. i.

    Give a symbolic implicit formula for the class \({\mathcal T}\) and derive a functional equation for the ordinary generating function.

  2. ii.

    Use Lagrange inversion to compute \(T_{n}\), the number of trees in the class with n nodes. Check your answer for \(k=2\) and \(n=3\).

  3. iii.

    Use the Bürman–Lagrange inversion formula for the number of forests (ordered sequences) of m trees in \({\mathcal T}\) with total number of nodes n.

Exercise 1.13

Let \({\mathcal U}\) be the class of monic polynomials in \(\mathbb F_q\), the finite field with q elements. Denote by \({\mathcal I}\) the subclass of irreducible polynomials in \({\mathcal U}\). The size of a polynomial is its degree.

  1. i.

    Give a symbolic relationship among the two classes and deduce a relation among the respective generating functions.

  2. ii.

    By taking logarithms and expanding in power series, find a relationship between the coefficients of the two generating functions.

  3. iii.

    By using the Möbius inversion formula find an explicit form of the number of the monic irreducible polynomials of degree n in \(\mathbb F_q\). How many monic irreducible polynomials of degree three are there in \(\mathbb F_8\)?

Exercise 1.14

A permutation \(\sigma =\sigma _1 \ldots \sigma _n\in Sym(n)\) contains the pattern 132 if there are subscripts \(1\leqslant i<j<k\leqslant n\) such that \(\sigma _i<\sigma _k<\sigma _j\). For example, the permutation 2143 contains the pattern 132 in 243 and in 143, while 4321 does not contain the pattern 132. Let \({\mathcal P}^{132}\) denote the class of permutations avoiding the pattern 132.

  1. i.

    Justify the equation

    $$\displaystyle \begin{aligned} {\mathcal P}^{132}={\mathcal E}+{\mathcal P}^{132}\times{\mathcal N}\times {\mathcal P}^{132}. \end{aligned}$$
  2. ii.

    By using the Lagrange inversion formula obtain the number of permutations of n symbols avoiding the pattern 132.