# Stirling numbers and exponential generating functions in symbolic combinatorics

The use of exponential generating functions (EGFs) to study the properties of Stirling numbers is a classical exercise in combinatorial mathematics and possibly the canonical example of how symbolic combinatorics is used. It also illustrates the parallels in the construction of these two types of numbers, lending support to the binomial-style notation that is used for them.

This article uses the coefficient extraction operator $[z^n]$ for formal power series, as well as the (labelled) operators $\mathfrak{C}$ (for cycles) and $\mathfrak{P}$ (for sets) on combinatorial classes, which are explained on the page for symbolic combinatorics. Given a combinatorial class, the cycle operator creates the class obtained by placing objects from the source class along a cycle of some length, where cyclical symmetries are taken into account, and the set operator creates the class obtained by placing objects from the source class in a set (symmetries from the symmetric group, i.e. an "unstructured bag".) The two combinatorial classes (shown without additional markers) are

• permutations (for unsigned Stirling numbers of the first kind):
$\mathcal{P} = \mathfrak{P}(\mathfrak{C}(\mathcal{Z})),$

and

• set partitions into non-empty subsets (for Stirling numbers of the second kind):
$\mathcal{B} = \mathfrak{P}(\mathfrak{P}_{\ge 1}(\mathcal{Z})),$

where $\mathcal{Z}$ is the singleton class.

Warning: The notation used here for the Stirling numbers is not that of the Wikipedia articles on Stirling numbers; square brackets denote the signed Stirling numbers here.

## Stirling numbers of the first kind

The unsigned Stirling numbers of the first kind count the number of permutations of [n] with k cycles. A permutation is a set of cycles, and hence the set $\mathcal{P}\,$ of permutations is given by

$\mathcal{P} = \mathfrak{P}(\mathcal{U} \mathfrak{C}(\mathcal{Z})), \,$

where the singletion $\mathcal{U}$ marks cycles. This decomposition is examined in some detail on the page on the statistics of random permutations.

Translating to generating functions we obtain the mixed generating function of the unsigned Stirling numbers of the first kind:

$G(z, u) = \exp \left( u \log \frac{1}{1-z} \right) = \left(\frac{1}{1-z} \right)^u = \sum_{n=0}^\infty \sum_{k=0}^n \left|\left[\begin{matrix} n \\ k \end{matrix}\right]\right| u^k \, \frac{z^n}{n!}.$

Now the signed Stirling numbers of the first kind are obtained from the unsigned ones through the relation

$\left[\begin{matrix} n \\ k \end{matrix}\right] = (-1)^{n-k} \left|\left[\begin{matrix} n \\ k \end{matrix}\right]\right|.$

Hence the generating function $H(z, u)$ of these numbers is

$H(z, u) = G(-z, -u) = \left(\frac{1}{1+z} \right)^{-u} = (1+z)^u = \sum_{n=0}^\infty \sum_{k=0}^n \left[\begin{matrix} n \\ k \end{matrix}\right] u^k \, \frac{z^n}{n!}.$

A variety of identities may be derived by manipulating this generating function:

$(1+z)^u = \sum_{n=0}^\infty {u \choose n} z^n = \sum_{n=0}^\infty \frac {z^n}{n!} \sum_{k=0}^n \left[\begin{matrix} n \\ k \end{matrix}\right] u^k = \sum_{k=0}^\infty u^k \sum_{n=k}^\infty \frac {z^n}{n!} \left[\begin{matrix} n \\ k \end{matrix}\right] = e^{u\log(1+z)}.$

In particular, the order of summation may be exchanged, and derivatives taken, and then z or u may be fixed.

### Finite sums

A simple sum is

$\sum_{k=0}^n (-1)^k \left[\begin{matrix} n \\ k \end{matrix}\right] = (-1)^n n!.$

This formula holds because the exponential generating function of the sum is

$H(z, -1) = \frac{1}{1+z} \quad \mbox{and hence} \quad n! [z^n] H(z, -1) = (-1)^n n!.$

### Infinite sums

Some infinite sums include

$\sum_{n=k}^\infty \left[\begin{matrix} n \\ k \end{matrix}\right] \frac{z^n}{n!} = \frac {\left(\log (1+z)\right)^k}{k!}$

where $|z|<1$ (the singularity nearest to $z=0$ of $\log (1+z)$ is at $z=-1.$)

This relation holds because

$[u^k] H(z, u) = [u^k] \exp \left( u \log (1+z) \right) = \frac {\left(\log (1+z)\right)^k}{k!}.$

## Stirling numbers of the second kind

These numbers count the number of partitions of [n] into k nonempty subsets. First consider the total number of partitions, i.e. Bn where

$B_n = \sum_{k=1}^n \left\{\begin{matrix} n \\ k \end{matrix}\right\} \mbox{ and } B_0 = 1,$

i.e. the Bell numbers. The Symbolic combinatorics#The Flajolet–Sedgewick fundamental theorem applies (labelled case). The set $\mathcal{B}\,$ of partitions into non-empty subsets is given by ("set of non-empty sets of singletons")

$\mathcal{B} = \mathfrak{P}(\mathfrak{P}_{\ge 1}(\mathcal{Z})).$

This decomposition is entirely analogous to the construction of the set $\mathcal{P}\,$ of permutations from cycles, which is given by

$\mathcal{P} = \mathfrak{P}(\mathfrak{C}(\mathcal{Z})).$

and yields the Stirling numbers of the first kind. Hence the name "Stirling numbers of the second kind."

The decomposition is equivalent to the EGF

$B(z) = \exp \left(\exp z - 1\right).$

Differentiate to obtain

$\frac{d}{dz} B(z) = \exp \left(\exp z - 1\right) \exp z = B(z) \exp z,$

which implies that

$B_{n+1} = \sum_{k=0}^n {n \choose k} B_k,$

by convolution of exponential generating functions and because differentiating an EGF drops the first coefficient and shifts Bn+1 to z n/n!.

The EGF of the Stirling numbers of the second kind is obtained by marking every subset that goes into the partition with the term $\mathcal{U}\,$, giving

$\mathcal{B} = \mathfrak{P}(\mathcal{U} \; \mathfrak{P}_{\ge 1}(\mathcal{Z})).$

Translating to generating functions, we obtain

$B(z, u) = \exp \left(u \left(\exp z - 1\right)\right).$

This EGF yields the formula for the Stirling numbers of the second kind:

$\left\{\begin{matrix} n \\ k \end{matrix}\right\} = n! [u^k] [z^n] B(z, u) = n! [z^n] \frac{(\exp z - 1)^k}{k!}$

or

$n! [z^n] \frac{1}{k!} \sum_{j=0}^k {k \choose j} \exp(jz) (-1)^{k-j}$

which simplifies to

$\frac{n!}{k!} \sum_{j=0}^k {k \choose j} (-1)^{k-j} \frac{j^n}{n!} = \frac{1}{k!} \sum_{j=0}^k {k \choose j} (-1)^{k-j} j^n.$