% AUTOGENERATED FILE; you probably want to edit the .tex.in file, not this.
\documentclass[letter,12pt]{article}
\usepackage[margin=0.5in,hmargin=4cm]{geometry}
\pagestyle{headings}
\usepackage{amssymb,amsmath,hyperref,enumerate}
\usepackage{parskip}
\usepackage[all,cmtip]{xy}
\parindent=0pt
\newcommand{\defn}{\underline}
\newcommand{\qed}{\hfill\ensuremath{\Box}}
\begin{document}
\section*{Number sequences}

A \underline{number sequence} is simply an infinite sequence $h_0,h_1,h_2,...$ of numbers.
\\For us, $h_i$ will typically be an integer.

\paragraph{Examples:}
\mbox{}\\    1,2,3,4,5,...
\\    2,4,8,16,32,...
\\    2,3,5,7,13,...
\\    1,1,2,3,5,8,13,...
\\    1,5,10,10,5,1,0,0,0,0,...

\subsection*{Generating functions}

The \underline{generating function} of a number sequence $h_0,h_1,....$ is the formal
power series $g(x) = \sum_{n=0}^\infty h_n x^n$.

\paragraph{Technical remark:}
\mbox{}\\    Despite the notation and terminology, we do not assume any convergence;
\\    we do not need $g(a)$ to make sense for $a$ a real number,
\\    so $g$ doesn't really have to be a function in the usual sense.
\\    for example, $\sum_{n=0}^\infty n^n x^n$ doesn't converge for $x\neq 0$,
\\    but it's a perfectly good generating function.

    We use the usual algebraic notation for generating functions. We can make
    sense of algebraic operations as follows:\;

    Given formal power series $g(x)=\sum_{n=0}^\infty h_n x^n$ and
    $g'(x)=\sum_{n=0}^\infty h'_n x^n$, and a number $c$, we define
\mbox{}\\ \mbox{\hspace{2em}}$g(x)+g'(x) := \sum_{n=0}^\infty (h_n+h'_n) x^n$
\mbox{}\\ \mbox{\hspace{2em}}$c g(x) := \sum_{n=0}^\infty ch_n x^n$
\mbox{}\\ \mbox{\hspace{2em}}$g(x)g'(x) := \sum_{n=0}^\infty (\sum_{j=0}^n h_jh'_{n-j}) x^n$.

    We also write $c(x) = \frac{a(x)}{b(x)}$ to mean that $a(x) = b(x)c(x)$
    (this is well-defined).

We can often use this algebraic structure to write generating functions compactly.

\paragraph{Example 1:}
\mbox{}\\    Consider the binomial coefficients ${m\choose n}$ for a fixed $m$.
\\    This is a finite number sequence, but we can make it infinite by appending
    0s,
\mbox{}\\ \mbox{\hspace{2em}}${m\choose 0},{m\choose 1},...,{m\choose m},0,0,0,...$.

    So the generating function is
\mbox{}\\ \mbox{\hspace{2em}}${m\choose 0} + {m\choose 1}x + {m \choose 2} x^2 ... + {m \choose m} x^m$
\mbox{}\\ \mbox{\hspace{4em}}$= (x+1)^m$

\paragraph{Example 2:}
\mbox{}\\    The generating function of the number sequence
\mbox{}\\ \mbox{\hspace{2em}}$1,1,1,...$
\\    is $g(x) = \sum_{n=0}^\infty x^n = 1+x+x^2+...$.

    Now, multiplying out,
\mbox{}\\ \mbox{\hspace{2em}}$(1+x+x^2+...)(1-x) = 1 + (-1+1)x + (-1+1) x^2 + ...$,
\\    so $g(x) = 1/(1-x)$.
\\    \qed

Generating functions provide an efficient notation for describing and
manipulating classes of combinatorial problems.

\paragraph{Example 3:}
\mbox{}\\    Given $t$, let $h_n$ be the number of $n$-combinations of a multiset with
    $t$ types and infinite multiplicity for each type.

    We know $h_n = {n+t-1\choose t-1}$, so
    the generating function is
\mbox{}\\ \mbox{\hspace{2em}}$g(x) = \sum_{n=0}^\infty h_n x^n = \sum_{n=0}^\infty {n+t-1\choose t-1} x^n$.

    But note also that 
\mbox{}\\ \mbox{\hspace{2em}}$g(x) = (1+x+x^2+...)^t$,
\\    since when we multiply the right hand side out,
\\    the coefficient of $x^n$ is precisely the number of ways of obtaining
    $x^n$ as $x^{e_1}x^{e_2}...x^{e_t}$,
\\    which is the number of solutions in non-negative integers to
    $e_1+...+e_k=n$,
\\    which (as we've seen before) is $h_n$.

    So as in the previous example,
\mbox{}\\ \mbox{\hspace{2em}}$g(x) = (1+x+x^2+...)^t = \left(\frac{1}{1-x}\right)^t = \frac{1}{(1-x)^t}$.
\\    \qed

Note we found here the power series expansion of $\frac 1{(1-x)^t}$, which
will come in handy later.

\paragraph{Lemma 1:}
\mbox{}\\ \mbox{\hspace{2em}}$\frac{1}{(1-x)^t} = \sum_{n=0}^\infty {n+t-1 \choose t-1} x^n$

If we have restrictions on how many of each type we're allowed to take in a
combination, we can incorporate these into an algebraic expression for the
generating function.

\paragraph{Example 4:}
\mbox{}\\    {\it Find the generating function for the number $h_n$ of bags of $n$ marbles
    consisting of an even number of red marbles, at least 1 green marble, at
    most 36 blue marbles, and an odd number of yellow marbles.}

    Arguing as in the previous example, the generating function is
\mbox{}\\ \mbox{\hspace{2em}}$g(x) = (1+x^2+x^4+...)(x+x^2+x^3+...)(1+x+x^2+...+x^36)(x+x^3+x^5+...)$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac 1{1-x^2}\frac x{1-x}\frac{1-x^{37}}{1-x}\frac x{1-x^2}$.
\mbox{}\\ \mbox{\hspace{4em}}$= \frac{x^2(1-x^{37})}{(1-x^2)^2(1-x)^2}$.

\paragraph{Example 5:}
\mbox{}\\    {\it Find the generating function for the number $h_n$ of bags of $n$ marbles
    consisting of an even number of red marbles, a multiple of 3 of green marbles, at
    most 2 blue marbles, and at most one yellow marble. Hence explicitly
    determine $h_n$.}

\mbox{}\\ \mbox{\hspace{2em}}$g(x) = (1+x^2+x^4+...)(1+x^3+x^6+...)(1+x+x^2)(1+x)$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac 1{1-x^2}\frac 1{1-x^3}\frac{1-x^3}{1-x}(1+x)$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac{1+x}{(1-x^2)(1-x)}$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac{1+x}{(1+x)(1-x)(1-x)}$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac{1}{(1-x)^2}$
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{n=0}^\infty {n+2-1\choose 2-1} x^n$ (by Lemma 1) 
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{n=0}^\infty (n+1) x^n$.

    So there are $n+1$ such bags of $n$ marbles!

    (Exercise: find a direct proof of this, without going via generating
    functions.)

\paragraph{Example 6:}
\mbox{}\\    {\it Find the generating function for the number $h_n$ of ways of making
    $n$ cents out of Canadian coins.}

    The coins in current circulation are worth 5,10,25,100, and 200 cents
    each.

    So $h_n$ is the number of solutions in non-negative integers to
\mbox{}\\ \mbox{\hspace{2em}}$5N+10D+25Q+100L+200T=n$.
\\    Equivalently, $h_n$ is the number of solutions to
\mbox{}\\ \mbox{\hspace{2em}}$e_1+e_2+e_3+e_4+e_5=n$
\\    where $e_1$ is a multiple of 5, $e_2$ is a multiple of 10, etc.

    So as above,
\mbox{}\\ \mbox{\hspace{2em}}$g(x) = (x^5+x^{10}+x^{15}+...)(x^{10}+x^{20}+...)...(x^{200}+x^{400}+...)$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac 1{(1-x^5)(1-x^{10})...(1-x^{200})}$.

\subsection*{Exponential Generating Functions}

The \underline{exponential generating function} of a number sequence $h_0,h_1,...$ is
the formal power series
\mbox{}\\ \mbox{\hspace{2em}}$g^{(e)}(x) = \sum_{n=0}^\infty h_n \frac{x^n}{n!}$.

While ordinary generating functions are useful for counting combinations,
\\exponential generating functions are useful for counting permutations.

\paragraph{Example 7:}
\mbox{}\\    The exponential generating function of
\mbox{}\\ \mbox{\hspace{2em}}$(m,0),P(m,1),...,P(m,m),0,0,0,...$
\\    is
\mbox{}\\ \mbox{\hspace{2em}}$g^{(e)} = \sum_{n=0}^m \frac{m!}{(m-n)!}\frac{x^n}{n!}$
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{n=0}^m {m\choose n}x^n$
\mbox{}\\ \mbox{\hspace{4em}}$= (1+x)^m$

\paragraph{Example 8:}
\mbox{}\\    Let $h_n$ be the number of $n$-permutations of a multiset with $k$
    different types, each with infinite multiplicity,
\mbox{}\\ \mbox{\hspace{2em}}$\{\infty\cdot a_1,..., \infty \cdot a_k\}$.


    So $h_n=k^n$.
\\    Then the exponential generating function is
    : $g^{(e)}(x) = \sum_{n=0}^\infty \frac{k^nx^n}{n!} = e^{kx}$.

(remark for anyone who might worry what exactly we mean by this last
equality: we can just \underline{define} $e^{ax}$ to be the formal power series
$\sum_{n=0}^\infty \frac{a^n}{n!}x^n$. This obeys the usual law $e^{ax}e^{bx}
= e^{(a+b)x}$. We could define more, but this will suffice for our purposes.)

\paragraph{Theorem:}
\mbox{}\\    Let $h_n$ be the number of $n$-permutations of the multiset
\mbox{}\\ \mbox{\hspace{2em}}$S := \{n_1\cdot a_1,..., n_k \cdot a_k\}$,
\\    with $n_i \in \mathbb{N}\cup\{\infty\}$.

    Then the exponential generating function is
\mbox{}\\ \mbox{\hspace{2em}}$g^{(e)} = f_{n_1}(x)f_{n_2}(x)...f_{n_k}(x)$
\\    where
\mbox{}\\ \mbox{\hspace{2em}}$f_{n}(x) = \sum_{i=0}^n \frac{x^i}{i!}$
\\    and in particular, $f_\infty(x) = e^x$.

\paragraph{Proof:}
\mbox{}\\ \mbox{\hspace{2em}}$h_n = \sum_{\textrm{$S'$ an $n$-combination of $S$}} (\textrm{number of permutations of $S'$})$
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{\{(m_1,...,m_k) \;|\; m_1+...+m_k=n,\; 0\leq m_i\leq n_i \}}$
\mbox{}\\ \mbox{\hspace{4em}}\;\;\;\; $(\textrm{number of permutations of $\{m_1 * a_1,...,m_k*a_k\}$}$
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{\{(m_1,...,m_k) \;|\; m_1+...+m_k=n,\; 0\leq m_i\leq n_i \}} \frac{n!}{m_1!...m_k!}$
\mbox{}\\ \mbox{\hspace{4em}}$= n! \sum_{\{(m_1,...,m_k) \;|\; m_1+...+m_k=n,\; 0\leq m_i\leq n_i \}} \frac{1}{m_1!...m_k!}$

    Meanwhile, if we multiply out $f_{n_1}(x)f_{n_2}(x)...f_{n_k}(x)$, we find
    the coefficient of $x^n$ is 
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{\{(m_1,...,m_k) \;|\; m_1+...+m_k=n,\; 0\leq m_i\leq n_i \}} \frac{1}{m_1!...m_k!}$.

    So this is indeed the exponential generating function.
\\    \qed

Just as we saw with ordinary generating functions, if we have restrictions on
how many of each type we are allowed in a permutation, we can incorporate
these restrictions into the factors in the above expression for the
exponential generating function, by only including the appropriate powers of
$x$.

Often, expanding out the resulting power series will give us a solution to the
combinatorial problem, as the following example demonstrates.

\paragraph{Example 9:}
\mbox{}\\    {\it How many $n$-digit numbers can be written using only the digits
    '1','2', and '3', using an even number of '2's and at least 1 '3'?}

    The exponential generating function is
\mbox{}\\ \mbox{\hspace{2em}}$g^{(e)}(x) = (\sum_{n=0}^\infty \frac{x^n}{n!})(\sum_{n=0}^\infty \frac{x^{2n}}{(2n)!})(\sum_{n=1}^\infty \frac{x^n}{n!})$
\mbox{}\\ \mbox{\hspace{4em}}$= (e^x)(\frac{e^x+e^{-x}}2)(e^x-1)$
\mbox{}\\ \mbox{\hspace{4em}}$= \frac 12 (e^{3x}+e^x-e^{2x}-1)$
\mbox{}\\ \mbox{\hspace{4em}}$= \sum_{n=1}^\infty \frac{3^n + 1 - 2^n}{2n!}$

    So the answer is $\frac{3^n + 1 - 2^n}2$
\end{document}
