This section contains an introduction to the topic of generating functions and how they are used to solve recurrence relations, among other problems. Methods that employ generating functions are based on the concept that you can take a problem involving sequences and translate it into a problem involving generating functions. Once you've solved the new problem, a translation back to sequences gives you a solution of the original problem.

This section covers:

1. The definition of a generating function.

2. Solution of a recurrence relation using generating functions to identify the skills needed to use generating functions.

3. An introduction and/or review of the skills identified in point b.

4. Some applications of generating functions.

##### Definition8.5.1Generating Function of a Sequence

The generating function of a sequence $S$ with terms $S_0,S_1 ,S_2, \dots$, is the infinite sum $G(S;z)=\sum_{n=0}^{\infty} S_n z^n=S_0+S_1 z+S_2 z^2+S_3 z^3+\cdots$ The domain and codomain of generating functions will not be of any concern to us since we will only be performing algebraic operations on them.

##### Example8.5.2First Examples

1. If $S_n = 3^n$,$n \geq 0$, then \begin{equation*}\begin{split} G(S;z) &= 1 + 3z + 9z^2 + 27z^3 +\cdots \\ & =\sum_{n=0}^{\infty} 3^n z^n\\ &=\sum_{n=0}^{\infty} (3 z)^n\\ \end{split}\end{equation*} We can get a closed form expression for $G(S;z)$ by observing that $G(S;z) - 3z G(S;z) = 1$. Therefore, $G(S;z) =\frac{1}{1-3 z}$.

2. Finite sequences have generating functions. For example, the sequence of binomial coefficients $\binom{n}{0}$, $\binom{n}{1}$, $\ldots$,$\binom{n}{n}$, $n \geq 1$ has generating function \begin{equation*}\begin{split} G(\binom{n}{\cdot}; z) & = \binom{n}{0} + \binom{n}{1} z +\cdots + \binom{n}{n} z^n\\ & = \sum_{k=0}^{\infty} \binom{n}{k} z^k\\ &=(1+z)^n\\ \end{split}\end{equation*} by application of the binomial formula.

3. If $Q(n) = n^2$, $G(Q;z)=\sum_{n=0}^{\infty} n^2 z^n=\sum_{k=0}^{\infty} k^2 z^k$. Note that the index that is used in the summation has no significance. Also, note that the lower limit of the summation could start at 1 since $Q(0)=0$.

# Subsection8.5.2Solution of a Recurrence Relation Using Generating Functions¶ permalink

We illustrate the use of generating functions by solving $S(n) - 2S(n - 1) - 3S(n - 2) = 0$, $n \geq 2$, with $S(0) = 3$ and $S(1) = 1$.

1. Translate the recurrence relation into an equation about generating functions.

Let $V(n) = S(n) - 2S (n - 1) - 3S (n - 2)$, $n \geq 2$, with $V(0) = 0$ and $V(1) = 0$. Therefore, $G(V;z) = 0 + 0z +\sum_{n=2}^{\infty} (S(n) - 2S (n - 1) - 3S (n - 2)) z^n= 0$

2. Solve for the generating function of the unknown sequence, $G(S,z) = \sum_{n=0}^{\infty} S_n z^n$. \begin{equation*} \begin{split} 0 & =\sum_{n=2}^{\infty} {(S(n) - 2S (n - 1) - 3 S (n - 2)) z^n}\\ & =\sum_{n=2}^{\infty} {S(n) z^n-2} \left(\sum_{n=2}^{\infty } S(n-1) z^n\right)-3\left(\sum_{n=2}^{\infty} S(n-2) z^n\right) \end{split} \end{equation*}

Close examination of the three sums above shows:

1. \begin{equation*} \begin{split} \sum_{n=2}^{\infty} S_n z^n &=\sum_{n=0}^{\infty} S_n z^n - S(0)-S(1)z\\ &= G(S;z)-3-z \end{split} \end{equation*} since $S(0)=3$ and $S(1)=1$.

2. \begin{equation*} \begin{split} \sum_{n=2}^{\infty} S(n-1) z^n &=z\left(\sum_{n=2}^{\infty} S(n-1) z^{n-1}\right)\\ & =z\left(\sum_{n=1}^{\infty} S(n) z^n\right)\\ & = z\left(\sum_{n=0}^{\infty} S(n) z^n-S(0)\right)\\ &= z(G(S;z)-3) \end{split} \end{equation*}

3. \begin{equation*} \begin{split} \sum_{n=2}^{\infty} S(n-2) z^n & = z^2\left(\sum_{n=2}^{\infty} S(n-2) z^{n-2}\right)\\ & =z^2G(S;z) \end{split} \end{equation*}

Therefore, \begin{equation*} \begin{split} &(G(S;z)-3-z)-2z(G(S;z)-3)-3z^2G(S;z)=0\\ & \Rightarrow G(S;z)-2z G(S;z)-3z^2G(S;z)=3 - 5z\\ &\Rightarrow G(S;z)=\frac{3-5z}{1-2z-3z^2} \end{split} \end{equation*}

3. Determine the sequence whose generating function is the one we got in Step 2.

For our example, we need to know one general fact about the closed form expression of an exponential sequence (a proof will be given later): \begin{gather} T(n)=b a^n ,n\geq 0 \Leftrightarrow G(T;z)=\frac{b}{1-a z} \label{gf-of-exp}\tag{8.5.1} \end{gather}

Now, in order to recognize $S$ in our example, we must write our closed form expression for $G(S;z)$ as a sum of terms like $G(T;z)$ above. Note that the denominator of $G(S;z)$ can be factored: $G(S;z)=\frac{3-5z}{1-2z-3z^2} =\frac{3-5z}{(1-3z)(1+z)}$ If you look at this last expression for $G(S;z)$ closely, you can imagine how it could be the result of addition of two fractions, \begin{gather} \frac{3-5z}{(1-3z)(1+z)} = \frac{A}{1-3z}+ \frac{B}{1+z}\label{eq-pf}\tag{8.5.2} \end{gather} where $A$ and $B$ are two real numbers that must be determined. Starting on the right of (8.5.2), it should be clear that the sum, for any $A$ and $B$, would look like the left-hand side. The process of finding values of $A$ and $B$ that make (8.5.2) true is called the partial fractions decomposition of the left-hand side: \begin{equation*} \begin{split} \frac{A}{1-3z}+ \frac{B}{1+z} &=\frac{A(1+z)}{(1-3z)(1+z)}+ \frac{B(1-3z)}{(1-3z)(1+z)}\\ & =\frac{(A+B)+(A-3B)z}{(1-3z)(1+z)} \end{split} \end{equation*}

Therefore, $\left\{ \begin{array}{c} A+B=3 \\ A-3B=-5 \\ \end{array} \right\}\Rightarrow \left\{ \begin{array}{c} A=1 \\ B=2 \\ \end{array} \right\}$ and $G(S;z)= \frac{1}{1-3z}+ \frac{2}{1+z}$

We can apply (8.5.1) to each term of $G(S;z)$:

• $\frac{1}{1-3z}$ is the generating function for $S_1(n)=1\cdot 3^n= 3^n$

• $\frac{2}{1+z}$ is the generating function for $S_2(n)=2(-1)^n$.

Therefore, $S(n)=3^n+ 2(-1)^n$.

From this example, we see that there are several skills that must be mastered in order to work with generating functions. You must be able to:

1. Manipulate summation expressions and their indices (in Step 2).

2. Solve algebraic equations and manipulate algebraic expressions, including partial function decompositions (Steps 2 and 3).

3. Identify sequences with their generating functions (Steps 1 and 3).

We will concentrate on the last skill first, a proficiency in the other skills is a product of doing as many exercises and reading as many examples as possible.

First, we will identify the operations on sequences and on generating functions.

##### Definition8.5.3Operations on Sequences

Let $S$ and $T$ be sequences of numbers and let $c$ be a real number. Define the sum $S + T$, the scalar product $c S$, the product $S T$, the convolution $S*T$, the pop operation $S\uparrow$ (read “$S$ pop”), and the push operation $S\downarrow$ (read “$S$ push”) term-wise for $k \geq 0$ by \begin{gather} (S + T)(k) = S(k) + T(k)\label{seq-op-add}\tag{8.5.3} \end{gather} \begin{gather} (c S)(k) = c S(k)\label{seq-op-sc-mult}\tag{8.5.4} \end{gather} \begin{gather} (S \cdot T)(k) = S(k)T(k)\label{seq-op-mult}\tag{8.5.5} \end{gather} \begin{gather} (S*T)(k) = \sum_{j=0}^k S(j) T(k-j)\label{seq-op-convolve}\tag{8.5.6} \end{gather} \begin{gather} (S\uparrow )(k) = S(k+1)\label{seq-op-pop}\tag{8.5.7} \end{gather} \begin{align} (S\downarrow )(k)=\left\{ \begin{array}{cc} 0 & \textrm{ if } k=0 \\ S(k-1) & \textrm{ if } k>0 \end{array}\right.\label{seq-op-push}\tag{8.5.8} \end{align}

If one imagines a sequence to be a matrix with one row and an infinite number of columns, $S + T$ and $c S$ are exactly as in matrix addition and scalar multiplication. There is no obvious similarity between the other operations and matrix operations.

The pop and push operations can be understood by imagining a sequence to be an infinite stack of numbers with $S(0)$ at the top, $S(1)$ next, etc., as in Figure 8.5.4a. The sequence $S\uparrow$ is obtained by “popping” S(0) from the stack, leaving a stack as in Figure 8.5.4b, with S(1) at the top, S(2) next, etc. The sequence $S\downarrow$ is obtained by placing a zero at the top of the stack, resulting in a stack as in Figure 8.5.4c. Keep these figures in mind when we discuss the pop and push operations.

##### Example8.5.5Some Sequence Operations

If $S(n) = n$, $T(n) = n^2$, $U(n) = 2^n$, and $R(n) =n 2^n$:

1. $(S + T)(n) = n + n^2$

2. $(U + R)(n) = 2^n+ n 2^n= (1+n)2^n$

3. $(2 U)(n) = 2\cdot 2^n= 2^{n+1}$

4. $\left(\frac{1}{2}R\right)(n)= \frac{1}{2}n 2^n= n 2^{n-1}$

5. $(S\cdot T)(n) = n n^2 = n^3$

6. $(S*T)(n)= \sum_{j=0}^n S(j) T(n-j)= \sum_{j=0}^n j (n-j)^2\\ \\ \quad \quad =\sum_{j=0}^n \left( j n^2-2 n j^2 + j^3\right)\\ \\ \quad \quad = n^2\sum_{j=0}^n j-2n \sum_{j=0}^n j^2 + \sum_{j=0}^n j ^3\\ \\ \quad \quad =n^{2 }\left(\frac{n (n+1)}{2}\right)- 2n\left(\frac{(2n+1)(n+1)n}{6}\right)+\frac{1}{4} n^2 (n+1)^2\\ \\ \quad \quad = \frac{n^2(n+1)(n-1)}{12}$

7. $(U*U)(n) =\sum_{j=0}^n U(j) U(n-j)\\ \\ \quad \quad =\sum_{j=0}^n 2^j 2^{n-j}\\ \\ \quad \quad = (n+1)2^n$

8. $(S\uparrow )(n)=n+1$

9. $(S\downarrow )(n)=\max (0,n-1)$

10. $((S\downarrow )\downarrow )(n)= \max (0, n - 2)$

11. $(U\downarrow )(n)=\left\{ \begin{array}{cc} 2^{n-1} & \textrm{ if } n>0 \\ 0 & \textrm{ if } n=0 \\ \end{array} \right.$

12. $((U\downarrow )\uparrow )(n)=(U\downarrow )(n+1)= 2^n= U(n)$

13. $((U\uparrow )\downarrow ) (n)=\left\{ \begin{array}{cc} 0 & \textrm{ if } n = 0 \\ U(n) & \textrm{ if } n>0 \\ \end{array} \right.$

Note that $(U\downarrow )\uparrow \neq (U\uparrow )\downarrow$.

##### Definition8.5.6Multiple Pop and Push

If S is a sequence of numbers and $p$ a positive integer greater than 1, define $S\uparrow p = (S\uparrow (p - 1))\uparrow \quad\textrm{ if }p \geq 2 \textrm{ and }S\uparrow 1 = S\uparrow$ Similarly, define $S\downarrow p = (S\downarrow (p - 1))\downarrow \quad\textrm{ if } p \geq 2\textrm{ and }S\downarrow 1 = S\downarrow$

In general, $(S \uparrow p)(k) = S(k+p),$ and \begin{equation*} (S\downarrow p)(k)=\left\{ \begin{array}{cc} 0 & \textrm{ if } k < p \\ S(k-p) & \textrm{ if } k\geq p \\ \end{array} \right. \end{equation*}

# Subsection8.5.4Operations on Generating Functions¶ permalink

##### Definition8.5.7Operations on Generating Functions

If $G(z)=\sum_{k=0}^{\infty} a_k z^k$ and $H(z) =\sum_{k=0}^{\infty} b_k z^k$ are generating functions and $c$ is a real number, then the sum $G + H$, scalar product $c G$, product $G H$, and monomial product $z^p G$, $p \geq 1$ are generating functions, where \begin{gather} (G + H)(z)=\sum_{k=0}^{\infty} \left(a_k+b_k\right) z^k\label{gf-sum}\tag{8.5.9}\\ [(c G)(z)=\sum_{k=0}^{\infty} c a_k z^k\label{gf-scalarmult}\tag{8.5.10}\\ (G H)(z) = \sum_{k=0}^{\infty} c z^k \textrm{ where } c_k= \sum_{j=0}^k a_jb_{k-j}\label{gf-product}\tag{8.5.11}\\ \left(z^p G\right)(z) = z^p\sum_{k=0}^{\infty} a_k z^k=\sum_{k=0}^{\infty} a_k z^{k+p} = \sum_{n=p}^{\infty} a_{n-p} z^n\label{gf-shift}\tag{8.5.12} \end{gather}

The last sum is obtained by substituting $n - p$ for $k$ in the previous sum.

##### Example8.5.8Some operations on generating functions

If $D(z) =\sum_{k=0}^{\infty} kz^k$ and $H(z) =\sum_{k=0}^{\infty} 2^k z^k$ then $(D + H)(z) =\sum_{k=0}^{\infty} \left(k+2^k\right) z^k$ $(2H)(z)= \sum_{k=0}^{\infty} 2\cdot 2^kz^k =\sum_{k=0}^{\infty} 2^{k+1}z^k$ $(z D)(z) = z\sum_{k=0}^{\infty} kz^k= \sum_{k=0}^{\infty} kz^{k+1}= \sum_{k=1}^{\infty} (k-1) z^k \quad = D(z)- \sum_{k=1}^{\infty} z^k$ $(D H)(z)=\sum_{k=0}^{\infty} \left(\sum_{j=0}^k j 2^{k-j}\right)z^k$ $(H H)(z)= \sum_{k=0}^{\infty} \left(\sum_{j=0}^k 2^j2^{k-j}\right) z^k=\sum_{k=0}^{\infty} (k+1)2^k z^k$

Note: $D(z) = G(S;z)$, and $H(z) = G(U;z)$ from Example 8.5.2.

Now we establish the connection between the operations on sequences and generating functions. Let $S$ and $T$ be sequences and let $c$ be a real number. \begin{gather} G(S+T;z)=G(S;z)+G(T;z)\label{gf-ops-1}\tag{8.5.13}\\ G(cS;z)=c G(S;z)\label{gf-ops-2}\tag{8.5.14}\\ G(S*T;z)=G(S;z) G(T;z)\label{gf-ops-3}\tag{8.5.15}\\ G(S\uparrow ;z)=(G(S;z)-S(0))/z\label{gf-ops-4}\tag{8.5.16}\\ G(S\downarrow ;z)=z G(S;z)\label{gf-ops-5}\tag{8.5.17} \end{gather}

In words, (8.5.13) says that the generating function of the sum of two sequences equals the sum of the generating functions of those sequences. Take the time to write out the other four identities in your own words. From the previous examples, these identities should be fairly obvious, with the possible exception of the last two. We will prove (8.5.16) as part of the next theorem and leave the proof of (8.5.17) to the interested reader. Note that there is no operation on generating functions that is related to sequence multiplication; that is, $G(S\cdot T;z)$ cannot be simplified.

# Subsection8.5.5Closed Form Expressions for Generating Functions¶ permalink

The most basic tool used to express generating functions in closed form is the closed form expression for the geometric series, which is an expression of the form $a + a r + a r^2+ \cdots$. It can either be terminated or extended infinitely.

Finite Geometric Series: \begin{gather} a + a r + a r^2+ \cdots +a r^n= a\left(\frac{1-r^{n+1}}{1-r}\right)\label{finite-geometric-series}\tag{8.5.18} \end{gather}

Infinite Geometric Series: \begin{gather} a + a r + a r^2+ \cdots = \frac{a}{1-r}\label{infinite-geometric-series}\tag{8.5.19} \end{gather}

Restrictions: $a$ and $r$ represent constants and the right sides of the two equations apply under the following conditions:

1. $r$ must not equal 1 in the finite case. Note that $a + a r + \cdots a r^n = (n + 1)a$ if $r = 1$.

2. In the infinite case, the absolute value of $r$ must be less than 1.

These restrictions don't come into play with generating functions. We could derive (8.5.18) by noting that if $S(n) = a + a r +\cdots + a r^n$, $n > 0$, then $S(n) = r S(n - 1) + a$ (See Exercise 10 of Section 8.3). An alternative derivation was used in Section 8.4. We will take the same steps to derive (8.5.19). Let $x = a + a r + a r^2 + \cdots$. Then \begin{equation*}r x =a r+ ar^2 +\cdots = x- a \Rightarrow x-rx=a \Rightarrow x= \frac{a}{1-r}\end{equation*}

##### Example8.5.10Generating Functions involving Geometric Sums

1. If $S(n) = 9\cdot 5^n$, $n \geq 0$, $G(S;z)$ is an infinite geometric series with $a = 9$ and $r = 5z$.Therefore, $G(S;z) = \frac{9}{1 - 5z}$.

2. If $T(n) = 4$, $n \geq$0, then $G(T;z) = 4/(1 - z)$.

3. If $U(n) = 3(-1)^n$, then $G(U;z) = 3/(1 + z)$.

4. Let $C(n) = S(n) + T(n) + U(n) = 9 \cdot 5^n + 4 + 3(-1)^n$. Then \begin{equation*} \begin{split} G(C;z) & = G(S;z) + G(T;z) + G(U;z)\\ & = \frac{9}{1-5z} + \frac{4}{1-z}+ \frac{3}{1+z}\\ & = -\frac{14 z^2+34z-16}{5 z^3-z^2-5 z+1} \end{split} \end{equation*}

Given a choice between the last form of $G(C;z)$ and the previous sum of three fractions, we would prefer leaving it as a sum of three functions. As we saw in an earlier example, a partial fractions decomposition of a fraction such as the last expression requires some effort to produce.

5. If $G(Q;z) = 34/(2 - 3z)$, then $Q$ can be determined by multiplying the numerator and denominator by 1/2 to obtain $\frac{17}{1-\frac{3}{2}z}$. We recognize this fraction as the sum of the infinite geometric series with $a = 17$ and $r = \frac{3}{2}z$. Therefore $Q(n) = 17(3/2)^n$.

6. If $G(A;z) = (1 + z)^3$ , then we expand $(1 + z)^3$ to $1 + 3z + 3z^2 + z^{3}$ . Therefore $A(0) = 1$, $A(1) = 3$ $A(2)= 3$, $A(3) = 1$, and, since there are no higher-powered terms, $A(n) = 0$, $n \geq 4$. A more concise way of describing $A$ is $A(k) = \binom{3}{k}$, since $\binom{n}{k}$ is interpreted as 0 of $k > n$.

Table 8.5.11 lists some closed form expressions for the generating functions of some common sequences.

##### Example8.5.12Another Complete Solution

Solve $S(k) + 3S(k - 1) - 4S(k -2) = 0$, $k\geq 2$, with $S(0) = 3$ and $S(1) = -2$. The solution will be derived using the same steps that were used earlier in this section, with one variation.

1. Translate to an equation about generating functions. First, we change the index of the recurrence relation by substituting $n + 2$ for $k$. The result is $S(n + 2) + 3S(n + 1) - 4S(n) = 0$, $n \geq 0$. Now, if $V(n) = S(n + 2) + 3 S(n + 1) - 4S(n)$, then $V$ is the zero sequence, which has a zero generating function. Furthermore, $V = S\uparrow 2+3(S\uparrow )-4 S$. Therefore, $0 = G(V;z) \\ \\ \quad = G(S\uparrow 2; z) + 3 G(S\uparrow ;z) - 4G(S;z) \\ \\ \quad = \frac{G(S;z) - S(0) - S(1)z }{z^2}+4 \frac{(G(S;z) - S(0))}{z} - 4G(S;z)$.

2. We want to now solve the following equation for $G(S;z)$: $\frac{G(S;z) - S(0) - S(1)z }{z^2}+4 \frac{(G(S;z) - S(0))}{z} - 4G(S;z) = 0$ Multiply by $z^2$ : $G(S;z) - 3 + 2z + 3z(G(S;z) - 3) - 4z^2 G(S;z) = 0$ Expand and collect all terms involving $G(S;z)$ on one side of the equation: $G(S;z) + 3z G(S;z) - 4z^2 G(S;z) = 3 + 7z$ $\left(1 + 3z - 4z^2 \right)G(S;z)= 3 + 7z$ Therefore, $G(S;z)= \frac{3+7z}{1 + 3z - 4z^2}$

3. Determine S from its generating function. $1 + 3z - 4z^2 = (1 + 4z) (1 - z)$ thus a partial fraction decomposition of $G(S;z)$ would be: $\frac{A}{1+4z}+ \frac{B}{1-z}=\frac{A z-A-4 B z-B}{(z-1) (4 z+1)} =\frac{(A+B)+(4B-A)z}{(z-1) (4 z+1)}$ Therefore, $A + B = 3$ and $4B - A = 7$. The solution of this set of equations is $A = 1$ and $B = 2$. $G(S;z)= \frac{1}{1+4z}+ \frac{2}{1-z}$. \begin{equation*}\begin{array}{c} \frac{1}{1+4z} \textrm{ is the generating function of }S_1(n)=(-4)^n\textrm{, and}\\ \frac{2}{1-z} \textrm{ is the generating function of }S_2(n) = 2(1)^n = 2\\ \end{array}\end{equation*} In conclusion, since $G(S;z) = G\left(S_1;z\right) + G\left(S _2;z\right)$, $S(n) = 2 + (-4)^n$.

##### Example8.5.13An Application to Counting

Let $A = \{a, b, c, d, e\}$ and let $A^*$ be the set of all strings of length zero or more that can be made using each of the elements of $A$ zero or more times. By the generalized rule of products, there are $5^n$ such strings that have length $n$, $n\geq 0$, Suppose that $X_n$ is the set of strings of length $n$ with the property that all of the $a$'s and $b$'s precede all of the $c$'s, $d$'s, and $e$'s. Thus $aaabde \in X_6$, but $abcabc \notin X_6$. Let $R(n) =\lvert X_n \rvert$. A closed form expression for $R$ can be obtained by recognizing $R$ as the convolution of two sequences. To illustrate our point, we will consider the calculation of $R(6)$.

Note that if a string belongs to $X_6$, it starts with $k$ characters from $\{a, b\}$ and is followed by $6 - k$ characters from $\{c, d, e\}$. Let $S(k)$ be the number of strings of $a$'s and $b$'s with length $k$ and let $T(k)$ be the number of strings of $c$'s, $d$'s, and $e$'s with length $k$. By the generalized rule of products, $S(k) = 2^k$ and $T(k) = 3^k$. Among the strings in $X_6$ are the ones that start with two $a$'s and $b$'s and end with $c$'s, $d$'s, and $e$'s. There are $S(2)T(4)$ such strings. By the law of addition, $\lvert X_6 \rvert =R(6)=S(0)T(6)+S(1)T(5)+\cdots +S(5)T(1)+S(6)T(0\right)$. Note that the sixth term of R is the sixth term of the convolution of $S$ with $T$, $S*T$. Think about the general situation for a while and it should be clear that $R =S*T$. Now, our course of action will be to:

1. Determine the generating functions of $S$ and $T$,

2. Multiply $G(S;z)$ and $G(T;z)$ to obtain $G(S*T;z) = G(R;z)$\, and

3. Determine $R$ on the basis of $G(R;z)$.

1. $G(S;z) =\sum_{k=0}^{\infty} 2^k z^k=\frac{1}{1-2z}$ , and $G(T;z) =\sum_{k=0}^{\infty} 3^k z^k=\frac{1}{1-3z}$

2. $G(R;z) = G(S;z)G(T;z) = \frac{1}{(1-2z)(1-3z)}$

3. To recognize $R$ from $G(R;z)$, we must do a partial fractions decomposition: $\frac{1}{(1-2z)(1-3z)}=\frac{A}{1-2z}+\frac{B}{1-3z}=\frac{-3 A z+A-2 B z+B}{(2 z-1) (3 z-1)}=\frac{(A+B)+(-3 A -2 B )z}{(2 z-1) (3 z-1)}$ Therefore, $A + B = 1$ and $-3A - 2B = 0$. The solution of this pair of equations is $A = - 2$ and $B = 3$. Since $G(R;z) =\frac{-2}{1-2z}+\frac{3}{1-3z}$, which is the sum of the generating functions of $-2(2)^k$ and $3 (3)^k$, $R(k) =-2(2)^k+3 (3)^k = 3^{k+1}-2^{k+1}$

For example, $R(6) = 3^7 - 2^7= 2187 - 128 = 2059$. Naturally, this equals the sum that we get from $(S*T)(6)$. To put this number in perspective, the total number of strings of length 6 with no restrictions is $5^6=15625$, and $\frac{2059}{15625}\approx 0.131776$. Therefore approximately 13 percent of the strings of length 6 satisfy the conditions of the problem.

The remainder of this section is intended for readers who have had, or who intend to take, a course in combinatorics. We do not advise that it be included in a typical course. The method that was used in the previous example is a very powerful one and can be used to solve many problems in combinatorics. We close this section with a general description of the problems that can be solved in this way, followed by some examples.

Consider the situation in which $P_1$, $P_2$, $\ldots$, $P_m$ are $m$ actions that must be taken, each of which results in a well-defined outcome. For each $k = 1,2, . . . ,m$ define $X_k$ to be the set of possible outcomes of $P_k$ . We will assume that each outcome can be quantified in some way and that the quantification of the elements of $X_k$ is defined by the function $Q_k : X_k \to \{0, 1,2, . . .\}$. Thus, each outcome has a non-negative integer associated with it. Finally, define a frequency function $F_k : \{0, 1, 2, . . .\} \to \{0, 1, 2, . . .\}$ such that $F_k(n)$ is the number of elements of $X_k$ that have a quantification of $n$.

Now, based on these assumptions, we can define the problems that can be solved. If a process $P$ is defined as a sequence of actions $P_1,P_2,\ldots ,P_m$ as above, and if the outcome of $P$, which would be an element of $X_1\times X_2\times \cdots \times X_m$, is quantified by $Q\left(a_1,a_2, \ldots , a_m\right)= \sum_{k=1}^m Q_k\left(a_k\right)$ then the frequency function, $F$, for $P$ is the convolution of the frequency functions for$P_1$, $P_2$, $\ldots$, $P_m$, which has a generating function equal to the product of the generating functions of the frequency functions $F_1$, $F_2$, $\ldots$, $F_m$. That is, \begin{equation*} G(F;z) =G\left(F_1;z\right)G\left(F_2;z\right) \cdots \left(F_m;z\right) \end{equation*}

##### Example8.5.14Rolling Two Dice

Suppose that you roll a die two times and add up the numbers on the top face for each roll. Since the faces on the die represent the integers 1 through 6, the sum must be between 2 and 12. How many ways can any one of these sums be obtained? Obviously, 2 can be obtained only one way, with two 1's. There are two sequences that yield a sum of 3: 1-2 and 2-1. To obtain all of the frequencies with which the numbers 2 through 12 can be obtained, we set up the situation as follows. For $j = 1, 2$; $P_j$ is the rolling of the die for the $j^{\text{th}}$ time. $X_j = \{1, 2, . . . , 6\}$ and $Q_j : X_j \rightarrow \{0, 1, 2, 3,\ldots \}$ is defined by $Q_j(x) = x$. Since each number appears on a die exactly once, the frequency function is $F_j(k)=1$ if $1 \leq k \leq 6$, and $F_j(k) = 0$ otherwise. The process of rolling the die two times is quantified by adding up the ${Q_j}'s$; that is, $Q\left(a_1, a_2\right) =Q_{1}\left(a_1\right)+Q_2\left(a_2\right)$ . The generating function for the frequency function of rolling the die two times is then \begin{equation*} \begin{split} G(F; z) & = G\left(F_1;z\right)G\left(F_2;z\right)\\ & = (z^6+z^5+z^4+z^3+z^2+z)^2\\ & =z^{12}+2 z^{11}+3 z^{10}+4 z^9+5 z^8+6 z^7+5 z^6+4 z^5+3 z^4+2 z^3+z^2 \end{split} \end{equation*}

Now, to get $F(k)$, just read the coefficient of $z^k$. For example, the coefficient of $z^5$ is 4, so there are four ways to roll a total of 5.

To apply this method, the crucial step is to decompose a large process in the proper way so that it fits into the general situation that we've described.

##### Example8.5.15Distribution of a Committee

Suppose that an organization is divided into three geographic sections, A, B, and C. Suppose that an executive committee of 11 members must be selected so that no more than 5 members from any one section are on the committee and that Sections A, B, and C must have minimums of 3, 2, and 2 members, respectively, on the committee. Looking only at the number of members from each section on the committee, how many ways can the committee be made up? One example of a valid committee would be 4 A's, 4 B's, and 3 C's.

Let $P_A$ be the action of deciding how many members (not who) from Section A will serve on the committee. $X_A= \{3, 4, 5\}$ and $Q_A(k)=k$. The frequency function, $F_A$ , is defined by $F_A(k)=1$ if $k\in X_k$ , with $F_A(k)=0$ otherwise. $G\left(F_A;z\right)$ is then $z^3+ z^4+z^5$ . Similarly, $G\left(F_B;z\right) =z^2+ z^3+ z ^4 + z^5= G\left(F_C ;z\right)$. Since the committee must have 11 members, our answer will be the coefficient of $z^{11}$ in $G\left(F_A;z\right)G\left(F_B;z\right)G\left(F_C;z\right)$, which is 10.

# Subsection8.5.7Exercises for Section 8.5

##### 1

What sequences have the following generating functions?

1. 1

2. $\frac{10}{2-z}$

3. $1 + z$

4. $\frac{3}{1+2z}+ \frac{3}{1-3z}$

##### 2

What sequences have the following generating functions?

1. $\frac{1}{1+z}$

2. $\frac{1}{4-3z}$

3. $\frac{2}{1-z}+ \frac{1}{1+z}$

4. $\frac{z+2}{z+3}$

##### 3

Find closed form expressions for the generating functions of the following sequences:

1. $V(n) = 9^n$

2. $P$, where $P(k) - 6 P(k - 1) + 5 P(k - 2) = 0$ for $k \geq 2$, with $P(0) = 2$and $P(1) = 2$.

3. The Fibonacci sequence: $F(k + 2) = F(k + 1) + F(k)$, $k \geq 0$, with $F(0) = F(1) = 1$.

##### 4

Find closed form expressions for the generating functions of the following sequences:

1. $W(n) = \binom{5}{n} 2^n$ for $0 \leq n \leq 5$ and $W(n) = 0$ for $n > 5$.

2. $Q$, where $Q(k) + Q(k - 1) - 42Q(k - 2) = 0$ for $k\geq 2$, with $Q(0) = 2$ and $Q(1) = 2$.

3. $G$, where $G(k + 3) = G(k + 2) + G(k + 1) + G(k)$ for $k \geq 0$, with $G(0) = G(1) = G(2) = 1$.

##### 5

For each of the following expressions, find the partial fraction decomposition and identify the sequence having the expression as a generating function.

1. $\frac{5+2z}{1-4z^2}$

2. $\frac{32-22z}{2-3z+z^2}$

3. $\frac{6-29z}{1-11z+ 30z^2}$

##### 6

Find the partial fraction decompositions and identify the sequence having the following expressions:

1. $\frac{1}{1-9z^2}$

2. $\frac{1+3z}{16-8z+z^2}$

3. $\frac{2z}{1-6z-7z^2}$

##### 7

Given that $S(k) = k$ and $T(k) = 10k$, what is the $k^{\text{th}}$ term of the generating function of each of the following sequences:

1. $S + T$

2. $S\uparrow * T$

3. $S * T$

4. $S\uparrow *S\uparrow$

##### 8

Given that $P(k) = \binom{10}{k}$ and $Q(k) = k!$, what is the $k^{\text{th}}$ term of the generating function of each of the following sequences:

1. $P * P$

2. $P + P\uparrow$

3. $P * Q$

4. $Q * Q$

##### 9

A game is played by rolling a die five times. For the $k^{\text{th}}$ roll, one point is added to your score if you roll a number higher than $k$. Otherwise, your score is zero for that roll. For example, the sequence of rolls $2,3,4,1,2$ gives you a total score of three; while a sequence of 1,2,3,4,5 gives you a score of zero. Of the $6^5 = 7776$ possible sequences of rolls, how many give you a score of zero?, of one? $\ldots$ of five?