\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{}<fibo>
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 the equation from \ref<fibo> 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


\definition{}
\textit{Partial fraction decomposition} is an algebreic technique that works as follows: \par
If $p(x)$ is a polynomial and $a$ and $b$ are constants,
we can rewrite the rational function $\frac{p(x)}{(x-a)(x-b)}$ as follows:
\begin{equation*}
	\frac{p(x)}{(x-a)(x-b)} = \frac{c}{x-a} + \frac{d}{x-b}
\end{equation*}
where $c$ and $d$ are constants.


\problem{}<pfd>
Now that we have a rational function for $F(x)$, \par
find a closed-form expression for its coefficients using partial fraction decomposition.

\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