Added generating functions

This commit is contained in:
Mark 2025-01-09 11:09:27 -08:00
parent 7c21b0d489
commit bd1a72b089
5 changed files with 500 additions and 0 deletions

View File

@ -0,0 +1,22 @@
% use [nosolutions] flag to hide solutions.
% use [solutions] flag to show solutions.
\documentclass[
solutions,
singlenumbering
]{../../resources/ormc_handout}
\usepackage{../../resources/macros}
\uptitlel{Advanced 2}
\uptitler{\smallurl{}}
\title{Generating Functions}
\subtitle{Prepared by Mark on \today \\ Based on a handout by Aaron Anderson}
\begin{document}
\maketitle
\input{parts/00 introduction.tex}
\input{parts/01 fibonacci.tex}
\input{parts/02 dice.tex}
\input{parts/03 coins.tex}
\end{document}

View File

@ -0,0 +1,106 @@
\section{Introduction}
\definition{}
Say we have a sequence $a_0, a_1, a_2, ...$. \par
The \textit{generating function} of this sequence is defined as follows:
\begin{equation*}
A(x) = \sum_{n=0}^\infty a_nx^n = a_0 + a_1x + a_2x^2 + a_3x+3 + ...
\end{equation*}
Under some circumstances, this sum does not converge, and thus $A(x)$ is undefined. \par
However, we can still manipulate this infinite sum to get useful results even if $A(x)$
diverges.
\problem{}
Let $A(x)$ be the generating function of the sequence $a_n$, \par
and let $B(x)$ be the generating function of the sequence $b_n$. \par
Find the sequences that correspond to the following generating functions:
\begin{itemize}[itemsep=2mm]
\item $cA(x)$
\item $xA(x)$
\item $A(x) + B(x)$
\item $A(x)B(x)$
\end{itemize}
\begin{solution}
\begin{itemize}[itemsep=2mm]
\item $cA(x)$ corresponds to $ca_n$
\item $xA(x)$ corresponds to $0, a_0, a_1, ...$
\item $A(x) + B(x)$ corresponds to $a_n+b_n$
\item $A(x)B(x)$ is $a_0b_0 + (a_0b_1 + a_1b_0)x + (a_0b_2 + a_1b_1 + a_2b_0)x^2 + ...$ \par
Which corresponds to $c_n = \sum_{k=0}^n a_kb_{n-k}$
\end{itemize}
\end{solution}
\vfill
\pagebreak
\problem{}<xminusone>
Assuming $|x| < 1$, show that
\begin{equation*}
\frac{1}{1-x} = 1 + x + x^2 + x^3 + ...
\end{equation*}
\begin{solution}
Let $S = 1 + x + x^2 + ...$ \par
Then, $xS = x + x^2 + x^3 + ...$ \par
\vspace{2mm}
So, $xS = S - 1$ \par
and $1 = S - xS = S(1 - x)$ \par
and $S = \frac{1}{1-x}$.
\end{solution}
\vfill
\problem{}
Let $A(x)$ be the generating function of the sequence $a_n$. \par
Find the sequence that corresponds to the generating function $\frac{A(x)}{1-x}$
\begin{solution}
\begin{align*}
\frac{A(x)}{1-x}
&=~ A(x)(1 + x + x^2 + ...) \\
&=~ (a_0 + a_1x + a_2x^2 + ...)(1 + x + x^2 + ...)\\
&=~ a_0 + (a_0 + a_1)x + (a_0 + a_1 + a_2)x^2 + ...
\end{align*}
Which corresponds to the sequence $c_n = \sum_{k=0}^n a_k$
\end{solution}
\vfill
\problem{}
Find short expressions for the generating functions for the following sequences:
\begin{itemize}
\item $1, 0, 1, 0, ...$
\item $1, 2, 4, 8, 16, ...$
\item $1, 2, 3, 4, 5, ...$
\end{itemize}
\begin{solution}
\begin{itemize}[itemsep=2mm]
\item $1, 0, 1, 0, ...$ corresponds to $1 + x^2 + x^4 + ...$. \par
By \ref{xminusone}, this is $\frac{1}{1-x^2}$.
\item $1, 2, 4, 8, 16, ...$ corresponds to $1 + 2x + (2x)^2 + ...$. \par
By \ref{xminusone}, this is $\frac{1}{1-2x}$.
\item $1, 2, 3, 4, 5, ...$ corresponds to $1 + 2x + 3x^2 + 4x^3 + ...$.\par
This is equal to $(1 + x + x^2 + ...)^2$, and thus is $\left(\frac{1}{1-x}\right)^2$
\end{itemize}
\end{solution}
\vfill
\pagebreak

View File

@ -0,0 +1,168 @@
\section{Fibonacci}
\definition{}
The \textit{Fibonacci numbers} are defined by the following recurrence relation:
\begin{itemize}
\item $f_0 = 0$
\item $f_1 = 1$
\item $f_n = f_{n-1} + f_{n-2}$
\end{itemize}
\problem{}
Let $F(x)$ be the generating function that corresponds to the Fibonacci numbers. \par
Find the generating function of $0, f_0, f_1, ...$ in terms of $F(x)$. \par
Call this $G(x)$.
\begin{solution}
\begin{equation*}
G(x) = xF(x)
\end{equation*}
\end{solution}
\vfill
\problem{}
Find the generating function of $0, 0, f_0, f_1, ...$ in terms of $F(x)$.
Call this $H(x)$.
\begin{solution}
\begin{equation*}
H(x) = x^2F(x)
\end{equation*}
\end{solution}
\vfill
\problem{}
Calculate $F(x) - G(x) - H(x)$ using the recurrence relation that
we used to define the Fibonacci numbers.
\begin{solution}
\begin{align*}
F(x) - G(x) - H(x)
&=~ f_0 + (f_1 - f_0)x + (f_2 - f_1 - f_0)x^2 + (f_3 - f_2 - f_1)x^3 + ... \\
&=~ f_0 + (f_1 - f_0)x \\
&=~ x
\end{align*}
\end{solution}
\vfill
\pagebreak
\problem{}
Using the problems on the previous page, find $F(x)$ in terms of $x$.
\begin{solution}
\begin{align*}
x
&=~ F(x) - G(x) - H(x) \\
&=~ F(x) - xF(x) - x^2F(x) \\
&=~ F(x)(1-x-x^2)
\end{align*}
So,
\begin{equation*}
F(x) = \frac{x}{1-x-x^2}
\end{equation*}
\end{solution}
\vfill
\definition{}
A \textit{rational function} $f$ is a function that can be written as a quotient of polynomials. \par
That is, $f(x) = \frac{p(x)}{q(x)}$ where $p$ and $q$ are polynomials.
\problem{}
Solve this equation for $F(x)$, expressing it as a rational function.
\begin{solution}
\begin{align*}
F(x)
&=~ \frac{-x}{x^2+x-1} = \frac{-x}{(x-a)(x-b)} \\
&=~ \frac{1 - \sqrt{5}}{2\sqrt{5}}\frac{1}{x-a} + \frac{-1 - \sqrt{5}}{2\sqrt{5}}\frac{1}{x-b}
\end{align*}
where
\begin{equation*}
a = \frac{-1 + \sqrt{5}}{2} ;~~
b = \frac{-1 - \sqrt{5}}{2}
\end{equation*}
\end{solution}
\vfill
\pagebreak
\problem{}<pfd>
Now that we have a rational function for $F(x)$, \par
find a closed-form expression for its coefficients.
\vspace{2mm}
Do this using \textit{partial fraction decomposition:} \par
We can break up a rational function $\frac{p(x)}{(x-a)(x-b)}$ as follows:
\begin{equation*}
F(x) = \frac{p(x)}{(x-a)(x-b)} = \frac{c}{x-a} + \frac{d}{x-b}
\end{equation*}
where $c$ and $d$ are constants.
\begin{solution}
\begin{align*}
F(x)
&=~
\left(\frac{1 - \sqrt{5}}{2\sqrt{5}}\right)\left(\frac{-1}{a}\right)\left(\frac{1}{1-\frac{x}{a}}\right)
+ \left(\frac{-1 - \sqrt{5}}{2\sqrt{5}}\right)\left(\frac{-1}{b}\right)\left(\frac{1}{1-\frac{x}{b}}\right) \\
&=~
\left(\frac{1}{\sqrt{5}}\right)\left(\frac{1}{1-\frac{x}{a}}\right)
+ \left(\frac{-1}{\sqrt{5}}\right)\left(\frac{1}{1-\frac{x}{b}}\right) \\
&=~
\frac{1}{\sqrt{5}}\left(1 + \frac{x}{a} + \left(\frac{x}{a}\right)^2 + ...\right)
- \frac{1}{\sqrt{5}}\left(1 + \frac{x}{b} + \left(\frac{x}{b}\right)^2 + ...\right)
\end{align*}
\end{solution}
\vfill
\problem{}
Using problems from the introduction and \ref{pfd}, find an expression
for the coefficients of $F(x)$ (and this, for the Fibonacci numbers).
\begin{solution}
\begin{align*}
f_0 &= \frac{1}{\sqrt{5}} - \frac{1}{\sqrt{5}} = 0 \\
f_1 &= \frac{1}{a\sqrt{5}} - \frac{1}{b\sqrt{5}} = 1 \\
f_n &= \frac{1}{\sqrt{5}}\left(\frac{1}{a^n} - \frac{1}{b^n}\right)
= \frac{1}{\sqrt{5}}\left(
\left(\frac{1 + \sqrt{5}}{2}\right)^n
- \left(\frac{1-\sqrt{5}}{2}\right)^n
\right)
\end{align*}
\end{solution}
\vfill
\pagebreak
\problem{Bonus}
Repeat the method of recurrence, generating function,
partial fraction decomposition, and geometric series
to find a closed form for the following sequence:
\begin{equation*}
a_0 = 1 ;~~ a_{n+1} = 2a_n + n
\end{equation*}
\hint{
When doing partial fraction decomposition with a
denominator of the form $(x-a)^2(x-b)$,
you may need to express your expression as a sum of three fractions:
$\frac{c}{(x-a)^2} + \frac{d}{x-a} + \frac{e}{x-b}$.`'
}
\vfill
\pagebreak

View File

@ -0,0 +1,102 @@
\section{Dice}
\definition{}
A \textit{die} is a device that randomly selects a positive integer from
a finite list of options. For example, the standard 6-sided die selects a value from
$[1,2,3,4,5,6]$. We may have many sides with the same value, as in $[1, 1, 2, 3]$.
To describe a die with a generating function, let $a_k$ be the number of times
$k$ appears as a side of the die and consider $a_0 + a_1x + x_2x^2 + ... $. \par
A die has a finite number of sides, so this will be a regular polynomial.
\problem{}
What is the generating function of the standard 6-sided die?
\begin{solution}
$x + x^2 + x^3 + x^4 + x^5 + x^6$
\end{solution}
\vfill
\problem{}
What is the generating function of the die with sides $[1, 2, 3, 5]$?
\begin{solution}
$2x + x^2 + x^3 + x^5$
\end{solution}
\vfill
\problem{}
Let $A(x)$ and $B(x)$ be the generating functions of two dice. \par
What is the significance of $A(1)$?
\begin{solution}
$A(1) = $ the number of sides on the die
\end{solution}
\vfill
\problem{}
Using formulas we found earlier, show that the $k^\text{th}$ coefficient
of $A(x)B(x)$ is the number of ways to roll $k$ as the sum of the two dice.
\begin{solution}
The $k^\text{th}$ coefficient of $A(x)B(x)$ is...
\begin{align*}
a_0b_k + a_1b_{k+1} + ... + a_kb_0 \\
&=~ \text{count}(A = 0; B = k) + ... + \text{count}(A = k; B = 0) \\
&=~ \text{number of ways} A + B = k
\end{align*}
\end{solution}
\vfill
\pagebreak
\problem{}
Find a generating function for the sequence $c_0, c_1, ...$, where $c_k$ is
the probability that the sum of the two dice is $k$.
\begin{solution}
\begin{equation*}
c_k
= \frac{\text{number of ways sum } = k}{\text{number of total outcomes}}
= \frac{\text{number of ways sum } = k}{A(1)B(1)}
\end{equation*}
So,
\begin{equation*}
c_0 + c_1x + c_2x^2 =
\frac{A(x)B(x)}{A(1)B(1)}
\end{equation*}
\end{solution}
\vfill
\problem{}
Using generating functions, find two six-sided dice whose sum has the same
distribution as the sum of two standard six-sided dice? \par
That is, for any integer $k$, the number if ways that the sum of the two
nonstandard dice rolls as $k$ is equal to the numer of ways the sum of
two standard dice rolls as $k$.
\hint{factor polynomials.}
\begin{solution}
We need a different factorization of
\begin{equation*}
(x + x^2 + x^3 + x^4 + x^5 + x^6)^2 = A(x)B(x)
\end{equation*}
We can use
\begin{equation*}
(x + 2x^2 + 2x^3 + x^4)
(x + x^3 + x^4 + x^5 + x^6 + x^8)
\end{equation*}
\end{solution}
\vfill
\pagebreak

View File

@ -0,0 +1,102 @@
\section{Coins}
Consider the following problem:
\say{How many different ways can you make change for \$0.50 \par
using pennies, nickels, dimes, quarters and half-dollars?}
\vspace{2mm}
Most ways of solving this involve awkward brute-force
approache that don't reveal anything interesting about the problem:
how can we change our answer if we want to make change for
\$0.51, or \$1.05, or some other quantity?
\vspace{2mm}
We can use generating functions to solve this problem in a general way.
\definition{}
Let $p_0, p_1, p_2, ...$ be such that $p_k$ is the number
of ways to make change for $k$ cents with only pennies.
Similarly, let...
\begin{itemize}
\item $n_k$ be the number of ways to make change for $k$ cents with only nickels;
\item $d_k$ be the number of ways using only dimes;
\item $q_k$ be the number of ways using only quarters;
\item and $h_k$ be the number of ways using only half-dollars.
\end{itemize}
\problem{}<pcoins>
Let $p(x)$ be the generating function that corresponds to $p_n$. \par
Express $p(x)$ as a rational function.
\vfill
\problem{}
Modify \ref{pcoins} to find expressions for $n(x)$, $d(x)$, $q(x)$, and $h(x)$.
\vfill
\pagebreak
\definition{}
Now, let $N(x)$ be the generating function for the sequence
$n_0, n_1, ...$, where $n_k$ is the number of ways to make
change for $k$ cents using pennies and nickels.
Similarly, let...
\begin{itemize}
\item let $D(x)$ be the generating function for the sequence using pennies, nickels, and dimes;
\item let $Q(x)$ use pennies, nickels, dimes, and quarters;
\item and let $H(x)$ use all coins.
\end{itemize}
\problem{}
Express $N(x)$ as a rational function.
\vfill
\problem{}
Using the previous problem, write $D(x)$, then $Q(x)$, then $H(x)$
as rational functions.
\vfill
\problem{}
Using these generating functions, find recurrence relations for
the sequences $N_k$, $D_k$, $Q_k$, and $H_k$.
\hint{
Your recurrence relation for $N_k$ should refer to the
previous values of itself and some values of $p_k$.
Your recurrence for $D_k$ should refer to itself and $N_k$;
the one for $Q_k$ should refer to itself $D_k$;
and the one for $H_k$ should refer to itself and $Q_k$.
}
\vfill
\problem{}
Using these recurrence relations, fill following table
and solve the original problem.
\begin{center}
\begin{tabular}{ c|cccc|cccc|ccc }
$n$ & 0 & 5 & 10 & 15 & 20 & 25 & 30 & 35 & 40 & 45 & 50 \\
\hline
$p_k$ &&&&&&&&&& \\
$N_k$ &&&&&&&&&& \\
\hline
$D_k$ &&&&&&&&&& \\
\hline
$Q_k$ &&&&&&&&&& \\
$H_k$ &&&&&&&&&&
\end{tabular}
\end{center}
\vspace{1cm}
\pagebreak