Skip to main content
\(\newcommand{\set}[1]{\{1,2,\dotsc,#1\,\}} \newcommand{\ints}{\mathbb{Z}} \newcommand{\posints}{\mathbb{N}} \newcommand{\rats}{\mathbb{Q}} \newcommand{\reals}{\mathbb{R}} \newcommand{\complexes}{\mathbb{C}} \newcommand{\twospace}{\mathbb{R}^2} \newcommand{\threepace}{\mathbb{R}^3} \newcommand{\dspace}{\mathbb{R}^d} \newcommand{\nni}{\mathbb{N}_0} \newcommand{\nonnegints}{\mathbb{N}_0} \newcommand{\dom}{\operatorname{dom}} \newcommand{\ran}{\operatorname{ran}} \newcommand{\prob}{\operatorname{prob}} \newcommand{\Prob}{\operatorname{Prob}} \newcommand{\height}{\operatorname{height}} \newcommand{\width}{\operatorname{width}} \newcommand{\length}{\operatorname{length}} \newcommand{\crit}{\operatorname{crit}} \newcommand{\inc}{\operatorname{inc}} \newcommand{\HP}{\mathbf{H_P}} \newcommand{\HCP}{\mathbf{H^c_P}} \newcommand{\GP}{\mathbf{G_P}} \newcommand{\GQ}{\mathbf{G_Q}} \newcommand{\AG}{\mathbf{A_G}} \newcommand{\GCP}{\mathbf{G^c_P}} \newcommand{\PXP}{\mathbf{P}=(X,P)} \newcommand{\QYQ}{\mathbf{Q}=(Y,Q)} \newcommand{\GVE}{\mathbf{G}=(V,E)} \newcommand{\HWF}{\mathbf{H}=(W,F)} \newcommand{\bfC}{\mathbf{C}} \newcommand{\bfG}{\mathbf{G}} \newcommand{\bfH}{\mathbf{H}} \newcommand{\bfF}{\mathbf{F}} \newcommand{\bfI}{\mathbf{I}} \newcommand{\bfK}{\mathbf{K}} \newcommand{\bfP}{\mathbf{P}} \newcommand{\bfQ}{\mathbf{Q}} \newcommand{\bfR}{\mathbf{R}} \newcommand{\bfS}{\mathbf{S}} \newcommand{\bfT}{\mathbf{T}} \newcommand{\bfNP}{\mathbf{NP}} \newcommand{\bftwo}{\mathbf{2}} \newcommand{\cgA}{\mathcal{A}} \newcommand{\cgB}{\mathcal{B}} \newcommand{\cgC}{\mathcal{C}} \newcommand{\cgD}{\mathcal{D}} \newcommand{\cgE}{\mathcal{E}} \newcommand{\cgF}{\mathcal{F}} \newcommand{\cgG}{\mathcal{G}} \newcommand{\cgM}{\mathcal{M}} \newcommand{\cgN}{\mathcal{N}} \newcommand{\cgP}{\mathcal{P}} \newcommand{\cgR}{\mathcal{R}} \newcommand{\cgS}{\mathcal{S}} \newcommand{\bfn}{\mathbf{n}} \newcommand{\bfm}{\mathbf{m}} \newcommand{\bfk}{\mathbf{k}} \newcommand{\bfs}{\mathbf{s}} \newcommand{\bijection}{\xrightarrow[\text{onto}]{\text{$1$--$1$}}} \newcommand{\injection}{\xrightarrow[]{\text{$1$--$1$}}} \newcommand{\surjection}{\xrightarrow[\text{onto}]{}} \newcommand{\nin}{\not\in} \newcommand{\prufer}{\mbox{prüfer}} \DeclareMathOperator{\fix}{fix} \DeclareMathOperator{\stab}{stab} \DeclareMathOperator{\var}{var} \newcommand{\inv}{^{-1}} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Section8.6Exponential generating functions

If we had wanted to be absolutely precise earlier in the chapter, we would have referred to the generating functions we studied as ordinary generating functions or even ordinary power series generating functions. This is because there are other types of generating functions, based on other types of power series. In this section, we briefly introduce another type of generating function, the exponential generating function. While an ordinary generating function has the form \(\sum_{n} a_n x^n\text{,}\) an exponential generating function is based on the power series for the exponential function \(e^x\text{.}\) Thus, the exponential generating function for the sequence \(\{a_n\colon n\geq 0\}\) is \(\sum_n a_n x^n/n!\text{.}\) In this section, we will see some ways we can use exponential generating functions to solve problems that we could not tackle with ordinary generating functions. However, we will only scratch the surface of the potential of this type of generating function. We begin with the most fundamental exponential generating function, in analogy with the ordinary generating function \(1/(1-x)\) of Example 8.1.

Example8.16

Consider the constant sequence \(1, 1, 1, 1, \dots\text{.}\) Then the exponential generating function for this sequence is \begin{equation*} E(x) = \sum_{n=0}^\infty \frac{x^n}{n!}. \end{equation*} From calculus, you probably recall that this is the power series for the exponential function \(e^x\text{,}\) which is why we call this type of generating function an exponential generating function. From this example, we can quickly recognize that the exponential generating function for the number of binary strings of length \(n\) is \(e^{2x}\) since \begin{equation*} e^{2x} = \sum_{n=0}^\infty \frac{(2x)^n}{n!} = \sum_{n=0}^\infty 2^n\frac{x^n}{n!}. \end{equation*}

In our study of ordinary generating functions earlier in this chapter, we considered examples where quantity (number of apples, etc.) mattered but order did not. One of the areas where exponential generating functions are preferable to ordinary generating functions is in applications where order matters, such as counting strings. For instance, although the bit strings \(10001\) and \(011000\) both contain three zeros and two ones, they are not the same strings. On the other hand, two fruit baskets containing two apples and three oranges would be considered equivalent, regardless of how you arranged the fruit. We now consider a couple of examples to illustrate this technique.

Example8.17

Suppose we wish to find the number of ternary strings in which the number of \(0\)s is even. (There are no restrictions on the number of \(1\)s and \(2\)s.) As with ordinary generating functions, we determine a generating function for each of the digits and multiply them. For \(1\)s and \(2\)s, since we may have any number of each of them, we introduce a factor of \(e^x\) for each. For an even number of \(0\)s, we need \begin{equation*} 1 + \frac{x^2}{2!} + \frac{x^4}{4!} + \frac{x^6}{6!} + \cdots = \sum_{n=0}^\infty \frac{x^{2n}}{(2n)!}. \end{equation*} Unlike with ordinary generating functions, we cannot represent this series in a more compact form by simply substituting a function of \(x\) into the series for \(e^y\text{.}\) However, with a small amount of cleverness, we are able to achieve the desired result. To do this, first notice that \begin{equation*} e^{-x} = 1 - x + \frac{x^2}{2!} - \frac{x^3}{3!} + \cdots = \sum_{n=0}^\infty \frac{(-1)^nx^n}{n!}. \end{equation*} Thus, when we add the series for \(e^{-x}\) to the series for \(e^x\) all of the terms with odd powers of \(x\) will cancel! We thus find \begin{equation*} e^x+e^{-x} = 2+2\frac{x^2}{2!} + 2\frac{x^4}{4!} + \cdots, \end{equation*} which is exactly twice what we need. Therefore, the factor we introduce for \(0\)s is \((e^x+e^{-x})/2\text{.}\)

Now we have an exponential generating function of \begin{equation*} \frac{e^x+e^{-x}}{2}e^x e^x = \frac{e^{3x} + e^x}{2} = \frac{1}{2}\left(\sum_{n=0}^\infty \frac{3^nx^n}{n!} + \sum_{n=0}^\infty \frac{x^n}{n!}\right). \end{equation*} To find the number of ternary strings in which the number of \(0\)s is even, we thus need to look at the coefficient on \(x^n/n!\) in the series expansion. In doing this, we find that the number of ternary strings with an even number of \(0\)s is \((3^n+1)/2\text{.}\)

We can also use exponential generating functions when there are bounds on the number of times a symbol appears, such as in the following example.

Example8.18

How many ternary strings of length \(n\) have at least one \(0\) and at least one \(1\text{?}\)

Solution

Before proceeding to an additional example, let's take a minute to look at another way to answer the question from the previous example. To count the number of ternary strings of length \(n\) with at least one \(0\) and at least one \(1\text{,}\) we can count all ternary strings of length \(n\) and use the principle of inclusion-exclusion to eliminate the undesirable strings lacking a \(0\) and/or a \(1\text{.}\) If a ternary string lacks a \(0\text{,}\) we're counting all strings made up of \(1\)s and \(2\)s, so there are \(2^n\) strings. Similarly for lacking a \(1\text{.}\) However, if we subtract \(2\cdot 2^n\text{,}\) then we've subtracted the strings that lack both a \(0\) and a \(1\) twice. A ternary string that has no \(0\)s and no \(1\)s consists only of \(2\)s. There is a single ternary string of length \(n\) satisfying this criterion. Thus, we obtain \(3^n-2\cdot 2^n+1\) in another way.

Example8.19

Alice needs to set an eight-digit passcode for her mobile phone. The restrictions on the passcode are a little peculiar. Specifically, it must contain an even number of \(0\)s, at least one \(1\text{,}\) and at most three \(2\)s. Bob remarks that although the restrictions are unusual, they don't do much to reduce the number of possible passcodes from the total number of \(10^8\) eight-digit strings. Carlos isn't convinced that's the case, so he works up an exponential generating function as follows. For the seven digits on which there are no restrictions, a factor of \(e^{7x}\) is introduced. To account for an even number of \(0\)s, he uses \((e^x+e^{-x})/2\text{.}\) For at least one \(1\text{,}\) a factor of \(e^x-1\) is required. Finally, \(1+x+x^2/2!+x^3/3!\) accounts for the restriction of at most three \(2\)s. The exponential generating function for the number of \(n\)-digit passcodes is thus \begin{equation*} e^{7x}\frac{e^x+e^{-x}}{2}(e^x-1)\left(1+x+\frac{x^2}{2!} + \frac{x^3}{3!}\right). \end{equation*}

Dave sees this mess written on the whiteboard and groans. He figures they'll be there all day multiplying and making algebra mistakes in trying to find the desired coefficient. Alice points out that they don't really need to find the coefficient on \(x^n/n!\) for all \(n\text{.}\) Instead, she suggests they use a computer algebra system to just find the coefficient on \(x^8/8!\text{.}\) After doing this, they find that there are \(33847837\) valid passcodes for the mobile phone. A quick calculation shows that Bob was totally off base in claiming that there was no significant reduction in the number of possible strings to use as a passcode. The total number of valid passcodes is only \(33.85\%\) of the total number of eight-digit strings!

Exponential generating functions are useful in many other situations beyond enumerating strings. For instance, they can be used to count the number of \(n\)-vertex, connected, labeled graphs. However, doing so is beyond the scope of this book. If you are interested in learning much more about generating functions, the book generatingfunctionology by Herbert S. Wilf is available online at http://www.math.upenn.edu/~wilf/DownldGF.html.