\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{latexsym}
\usepackage{fancyvrb}
\usepackage{verbatim}
\usepackage[pdftex]{graphicx}
\usepackage{wasysym}
\usepackage{url}
\usepackage{color}
\usepackage{mathrsfs}
\usepackage{hyperref}

\hypersetup{colorlinks=true}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{.25in}
\setlength{\textwidth}{6in}
\setlength{\topmargin}{-0.4in}
\setlength{\textheight}{8.5in}

\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\input{preamble.tex}

\begin{document}

\lecture{3: Catalan Numbers}{Week 3}

In this week, we start studying specific examples of commonly-occurring sequences of numbers (as opposed to the more general counting techniques we discussed for the past few weeks.)  Our first example of such a sequence are the \textbf{Catalan numbers}:

\section{Catalan Numbers}

\subsection{Ascii Mountain Ranges}

\begin{quest}
Suppose you have a number of forward-slashes ``/'' and backward-slashes ``\textbackslash''.  An \textbf{Ascii mountain range} is any sequence made of these $2n$ slash marks, with forward slashes interpreted as an increase in altitude and backward-slashes interpreted as a decrease in altitude, so that 
\begin{itemize}
\item We end at the same height that we start.
\item We never dip below the height that we start at.
\end{itemize}
Here are some Ascii mountain ranges:
\begin{center}
\begin{BVerbatim}
                  /\                                      /\
  /\             /  \/\                 /\               /  \
 /  \         /\/      \               /  \         /\  /    \/\
/    \       /          \       /\/\/\/    \       /  \/        \/\     
\end{BVerbatim}
\end{center}
Here are some sequences that are \textbf{not} mountain ranges:
\begin{center}
\begin{BVerbatim}
  /\/\/\/                                              /\
 /                      /\         /\                 /  \    /\
/              /\  /\/\/  \       /  \  /\/\       /\/    \  /  \
                 \/                   \/                   \/    \
\end{BVerbatim}
\end{center}
Let $M_n$ denote the total number of mountain ranges of length $2n$.  What is $M_n$, for any $n$?
\end{quest}

\begin{answer}
We start by first collecting some data, to help us make a guess.  In a sense, there is exactly one possible mountain range made out of $0$ slash marks, in the same way that there is one way to pick $0$ things out of a set: so we say that $M_0 = 1$.  

More intuitively, there is exactly one mountain range made out of $2$ slash marks; this is because our first move must be to place a $/$ so that we increase in altitude, which we must follow with a $\backslash$ to go back down to our starting height.
\begin{center}
\begin{BVerbatim}
/\
\end{BVerbatim}
\end{center}
There are two possible mountain ranges made out of $4$ slash marks:
\begin{center}
\begin{BVerbatim}
            /\
/\/\       /  \
\end{BVerbatim}
\end{center}
There are five possible mountain ranges made out of $6$ slash marks:
\begin{center}
\begin{BVerbatim}
                                         /\
              /\             /\         /  \         /\/\
/\/\/\       /  \/\       /\/  \       /    \       /    \
\end{BVerbatim}
\end{center}

With some time, you can figure out that $M_4 = 14$ and $M_5 = 42$, giving us the following table:
\begin{align*}
\begin{array}{c|cccccc}
n & 0 & 1 & 2 & 3 &4 &5 \\\hline
M_n  & 1 & 1 & 2 & 5 & 14 & 42\\
\end{array}
\end{align*}

It's hard to see a pattern in the above data!  So, instead, let's try to think about how we actually \textbf{make} these mountains.  Notice that with any mountain,we must have the following:
\begin{itemize}
\item We must start our mountain with a forward slash.  Let's color it green: ``{\color{green}/}.''
\item We must at some point in time return back to our original height via a backslash.  Let's color the first such backslash that returns to our original height red: ``{\color{red}\textbackslash}.''
\end{itemize}
\begin{center}
\begin{BVerbatim}[commandchars=\\\{\},codes={\catcode`$=3\catcode`^=7\catcode`_=8}]
    /\texttt{\symbol{92}}
   /  \texttt{\symbol{92}}  /\texttt{\symbol{92}}
  /    \texttt{\symbol{92}}/  \texttt{\symbol{92}}    /\texttt{\symbol{92}}/\texttt{\symbol{92}}
 /          \texttt{\symbol{92}}  /    \texttt{\symbol{92}}
\color{green}/            \color{red}\texttt{\symbol{92}}\color{black}/      \texttt{\symbol{92}}
\end{BVerbatim}
\end{center}
Now, make the following observations:
\begin{itemize}
\item Between our green forward-slash and our red backslash, we have a mountain that starts at height 1 and never dips below height 1.
\item After our red backslash, we have a mountain that starts and ends at height 0.
\end{itemize}
In other words, we have written our original mountain range as the \textbf{combination} of two smaller mountains, one of which we put on top of the ``{\color{green}/}, {\color{red}\textbackslash}'' marks and the other of which we put to the right of the ``{\color{red}\textbackslash}'' mark.  Furthermore,
\begin{itemize}
\item This decomposition is \textbf{unique}: that is, given any original mountain range, our process above isn't ambiguous in how it breaks our mountain into two smaller mountains!
\item This process is \textbf{reversible}: given our two smaller mountains, we can ``combine'' them by undoing our process to get back to our original mountain range!
\end{itemize}
Consequently, if we want to count the total number of large mountains, it suffices to count all of the pairs of smaller mountains that can create those larger mountains.   In other words, we have a recursive relationship!  Specifically, because we can break any $2n$-length mountain down into some $2k$-length mountain on top of the ``{\color{green}/}, {\color{red}\textbackslash}'' marks, along with a $2(n-1 - k)$-length mountain after those marks, we have the following recursive relationship:
\begin{align*}
M_n = M_0  M_{n-1} + M_1  M_{n-2} + \ldots  = \sum_{k=0}^{n-1} M_k  M_{n-1-k}.
\end{align*}

This looks familiar!  In fact, we've noticed a relationship like this before: last week, when we studied generating functions, we saw that 
\begin{align*}
\left(\sum_{n=0}^\infty a_n x^n \right)\cdot \left(\sum_{n=0}^\infty b_n x^n\right) = \sum_{n=0}^\infty \left( \sum_{k=0}^n a_k b_{n-k} \right)x^n 
\end{align*}
for any two formal power series $\sum_{n=0}^\infty a_n x^n$, $\sum_{n=0}^\infty b_n x^n$.

In particular, this tells us that if we set $F(x) = \sum_{n=0}^\infty M_n x^n$, we get
\begin{align*}
F(x) \cdot F(x) = \left(\sum_{n=0}^\infty M_n x^n \right)\cdot \left(\sum_{n=0}^\infty M_n x^n\right) &= \sum_{n=0}^\infty \left( \sum_{k=0}^n M_k M_{n-k} \right)x^n \\
\end{align*}
Our recursive relationship tells us that $ \sum_{k=0}^n M_k M_{n-k}  = M_{n+1}$; therefore, we have
\begin{align*}
(F(x))^2 &= \sum_{n=0}^\infty \left( \sum_{k=0}^n M_k M_{n-k} \right)x^n = \sum_{n=0}^\infty M_{n+1}x^n \\
\Rightarrow x(F(x))^2&= \sum_{n=0}^\infty M_{n+1}x^{n+1} = \sum_{n=1}^\infty M_n x^n = -M_0 + \sum_{n=0}^\infty M_n x^n\\
\Rightarrow x(F(x))^2 &= -1 + F(x)\\
\Rightarrow x(F(x))^2 &- F(x) + 1 = 0.\\
\end{align*}

So: we have an expression for $F(x)$!  In particular, we have a quadratic-polynomial-type expression for $F(x)$: therefore, we know that $F(x)$ has to algebraically satisfy this expression!  However, we know the form of any solution to a quadratic of the form $a\circled{?}^2 + b\circled{?} + c$: it's given by the quadratic formula $\circled{?} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.

In particular, we have that
\begin{align*}
F(x) = \frac{1 \pm \sqrt{1 -4x}}{2x}
\end{align*}
for our specific formal power series $F(x)$.

Now: remember when we defined formal power series, and I said that we'd never plug things into them?  I kinda lied.  We will \textbf{almost never} plug things into generating functions, and whenever we do we will be careful to make sure that the infinite sum we've created actually converges to something sensible and that we're making sense.  But!  Now is totally one of the times where it makes sense to do this!  Consider what we've got here:
\begin{itemize}
\item On one hand, if we take any formal power series --- no matter what it is! --- we can always plug in $x=0$ to it and get something well-defined.  Specifically, if our formal power series is some $A(x) = \sum_{n=0}^\infty a_n x^n$, setting $x=0$ is just saying that every term other than the $a_0$ term gets multiplied by $0^n = 0$; in other words, $A(0) = a_0$!  So no matter what our formal power series is, we know that plugging in $0$ to it should give us its constant term.
\item On the other hand, for the problem we're currently considering, we know that $F(x) = \frac{1 \pm \sqrt{1 -4x}}{2x}$.  This is a little irritating, in that we have this $\pm$ term: we're getting two possible answers for $F(x)$, when we really want one (after all, there is only \textbf{one} correct value for $M_n$, the number of $2n$-length mountain ranges!)  
\item So: what happens when we plug in $x=0$ to $\frac{1 \pm \sqrt{1 -4x}}{2x}$?  Well: if we have the $+$-branch, we get something of the form $\frac{2}{0}$ at $x=0$; this is hopeless, as it will neither equal $1 = M_0 = F(0)$ nor could it even equal $1$ in the limit, as the top goes to $2$ while the bottom goes to $0$!

Conversely, if we take the $-$ branch, we get something of the form $\frac{0}{0}$ at $x=0$, which is \ldots not great, but better!  In specific, if we take limits + use L'Hopital, we can see that
\begin{align*}
\lim_{x \to 0} \frac{1 - \sqrt{1-4x}}{2x} = \lim_{x\to 0} \frac{ \frac{d}{dx}\left( 1 - \sqrt{1-4x}\right)}{\frac{d}{dx}\left( 2x \right)} = \lim_{x \to 0} \frac{\frac{1}{2} (1-4x)^{-1/2} \cdot 4}{2} = 1,
\end{align*}
which \textbf{is} right!
\item So, we actually know which of the two branches is right to consider here: we must have 
\begin{align*}
F(x) = \frac{1 - \sqrt{1 -4x}}{2x}.
\end{align*}
\end{itemize}

Cool!  So.  If this was a standard generating-functions problem, we'd find some way to expand the right-hand side as a power series, and use this expansion to determine what the $M_n$'s are!  To do this, we're going to need new tools, however: we have this $\sqrt{1-4x}$ term, which we don't have tools for.  

Let's build them!

\subsection{Detour: Newton's Generalized Binomial Theorem}

Last week, we proved that for any $n \in \mathbb{N}$,
\begin{align*}
(x+y)^n = \sum_{k=0}^n \binom{n}{k} x^ky^{n-k}.
\end{align*}
We want to understand $(1-4x)^{1/2}$.  A seemingly very dumb thing we could write to try to answer this problem is the following:
\begin{align*}
(1-4x)^{1/2}= \sum_{k=0}^{1/2} \binom{1/2}{k} 1^k(-4x)^{(1/2)-k}.
\end{align*}

Surprisingly, this is actually correct!  Let's make some definitions, so we can prove this:
\begin{defn}
Take any real number $r$ not in the natural numbers, and any natural number $k$.  We define the generalized binomial coefficient $\binom{r}{k}$ as follows:
\begin{align*}
\binom{r}{k} = \frac{(r)(r-1)(r-2)\ldots (r-(k-1))}{k!}.
\end{align*}
Notice that if $r$ was a natural number $\geq k$, this is literally the same thing as the normal binomial coefficient!

By convention, if $k = 0$, we set this expression equal to 1.
\end{defn}

This lets us make the $\binom{1/2}{k}$ terms make sense.  To get the rest of the expression, let's pull out some results from calculus:

\begin{defn}
Take any function $f(x)$.  The \textbf{Taylor series around 0} corresponding to $f(x)$ is the power series
\begin{align*}
\sum_{n=0}^\infty \frac{f^{(n)}(0)}{n!} x^n,
\end{align*}
where $f^{(n)}(0)$ denotes the $n$-th derivative of $f(x)$ evaluated at $x=0$.
\end{defn}

So.  Suppose that we consider the Taylor series for $(x+y)^{r}$, for any non-natural real value $r$.  To do this, we'll need to find the derivatives of this function with respect to $x$.  It is not too hard to see that
\begin{align*}
\frac{d}{dx} \left((x+y)^{r}\right) &= r (x+y)^{r-1} \cdot \frac{d}{dx}(x+y) =  r (x+y)^{r-1} \cdot 1 = r (x+y)^{r-1} \\
\frac{d^2}{dx^2} \left((x+y)^{r}\right) &= \frac{d}{dx} \left( r (x+y)^{r-1}\right) = r(r-1) (x+y)^{r-2 }  \cdot \frac{d}{dx}(x+y) = r(r-1)(x+y)^{r-2 } \\
\frac{d^3}{dx^3} \left((x+y)^{r}\right) &= \frac{d}{dx} \left( r(r-1) (x+y)^{r-2}\right) = r(r-1)(r-2) (x+y)^{r-3}  \\
\vdots &\\
\frac{d^n}{dx^n} \left((x+y)^{r}\right) &= \frac{d}{dx} \left( r(r-1)\ldots (r-(n-2)) (x+y)^{r-2}\right) = r(r-1)\ldots (r-(n-1))(x+y)^{r-n}.  \\
\end{align*}
(The last step here is justified by induction; we leave formal details to the reader!  Do this iff you don't see why it's true.)

If you plug in $x=0$, you get that
\begin{align*}
\frac{d^n}{dx^n} \left((x+y)^{r}\right) \Big|_{x=0}&= r(r-1)\ldots (r-(n-1))(x+y)^{r-n} \Big|_{x=0}&=  = r(r-1) \ldots (r-(n-1)) y^{r-n}, \\
\end{align*}
and therefore that the Taylor series corresponding to $(x+y)^r$ is just 
\begin{align*}
\sum_{n=0}^\infty \frac{f^{(n)}(0)}{n!} x^n = \sum_{n=0}^\infty \frac{ r(r-1) \ldots (r-(n-1)) }{n!} y^{r-n}x^n.
\end{align*}

The coefficients here are precisely our generalized binomial coefficients!  Therefore, we've shown that the Taylor series for $(x+y)^r$ is actually
\begin{align*}
\sum_{n=0}^\infty \binom{r}{n} y^{r-n}x^n,
\end{align*}
and specifically that the Taylor series for $(1-4x)^{1/2}$ is
\begin{align*}
\sum_{n=0}^\infty \binom{r}{n} (-4x)^n.
\end{align*}

From here, we need a few quick results from calculus: we simply state them, and leave their derivation (because they involve more in-depth Taylor series manipulations than we want to do here) for the reader!
\begin{itemize}
\item Our Taylor series for $(1-4x)^{1/2}$ converges and is equal to $(1-4x)^{1/2}$ for values of $x$ in $(-1/4, 1/4)$.
\item Two power series are equal if and only if all of their coefficients are equal!
\item Therefore, we have
\begin{align*}
\sum_{n=0}^\infty M_n x^n = F(x) = \frac{1 - \sqrt{1 -4x}}{2x} = \frac{1 - \sum_{n=0}^\infty \binom{1/2}{n} (-4x)^n}{2x}.
\end{align*}
\end{itemize}

\subsection{Back to Mountains}
So we can solve for the $M_n$ coefficients!  We do this here.

First, let's clean up our expression above, by just doing some algebraic manipulations.  Nothing crazy happens here; try to read line-by-line and make sure you follow our steps!

\begin{align*}
\sum_{n=0}^\infty M_n x^n & = \frac{1 - \sum_{n=0}^\infty \binom{1/2}{n} (-4x)^n}{2x}\\
& = \frac{1 - \binom{1/2}{0}(-4x)^{0} - \sum_{n=1}^\infty \binom{1/2}{n} (-4x)^n}{2x} \\
& = \frac{1 - 1 -  \sum_{n=1}^\infty \binom{1/2}{n} (-4x)^n}{2x}\\
& = \sum_{n=1}^\infty -\frac{\binom{1/2}{n} (-4x)^n}{2x}\\
&=  \sum_{n=0}^\infty -\frac{\binom{1/2}{n+1} (-4x)^{n+1}}{2x}\\
&=  \sum_{n=0}^\infty 2\binom{1/2}{n+1} (-4x)^{n}\\
&=  \sum_{n=0}^\infty 2\frac{(1/2)((1/2)-1) \cdot \ldots \cdot ((1/2)-((n+1)-1))}{(n+1)!} (-4x)^{n}\\
&=  \sum_{n=0}^\infty 2\frac{\overbrace{\frac{1}{2} \cdot \frac{-1}{2} \cdot \frac{-3}{2} \cdot \frac{-5}{2} \cdot \ldots \cdot \frac{1-2n}{2}}^{(n+1) \textrm{ terms}}}{(n+1)!} (-1)^n 4^n x^{n}\\
&=  \sum_{n=0}^\infty 2\frac{\overbrace{\frac{1}{2} \cdot \frac{1}{2} \cdot \frac{3}{2} \cdot \frac{5}{2} \cdot \ldots \cdot \frac{2n-1}{2}}^{(n+1) \textrm{ terms}} \cdot (-1)^n}{(n+1)!} (-1)^n 4^n x^{n}\\
&=  \sum_{n=0}^\infty \frac{1 \cdot 3 \cdot 5 \cdot 7 \cdot \ldots \cdot (2n-1) \cdot (-1)^n \cdot \frac{1}{2^n}}{(n+1)!} (-1)^n 4^n x^{n}\\
&=  \sum_{n=0}^\infty \frac{1 \cdot 3 \cdot 5 \cdot 7 \cdot \ldots \cdot (2n-1)}{(n+1)!} 2^n x^{n}\\
\end{align*}
Ok, let's breathe for a second.  The right-hand side is certainly \textbf{less} awful than before, but it's still not as simple as possible.  In particular, the $1 \cdot 3 \cdot 5 \cdot 7 \cdot \ldots \cdot (2n-1)$ expression isn't necessarily as simple as we'd like!

We can fix this, with the following clever trick; I call this out mostly because it's a manipulation I've seen come up about once every four-five months, and it's useful to have somewhere in your mind!  Notice that
\begin{align*}
2^n \cdot n! = 2^n \cdot (1 \cdot 2 \cdot \ldots \cdot n) = 2 \cdot 4 \cdot 6 \cdot \ldots \cdot 2n.
\end{align*}
Therefore, we have
\begin{align*}
1 \cdot 3 \cdot 5 \cdot 7 \cdot \ldots \cdot (2n-1) = \frac{(2n)!}{2^n \cdot n!},
\end{align*}
and thus that

\begin{align*}
\sum_{n=0}^\infty M_n x^n 
&=  \sum_{n=0}^\infty \frac{1 \cdot 3 \cdot 5 \cdot 7 \cdot \ldots \cdot (2n-1)}{(n+1)!} 2^n x^{n}\\
&=  \sum_{n=0}^\infty \frac{(2n)!}{2^n n! (n+1)!} 2^n x^{n}\\
&=  \sum_{n=0}^\infty \frac{1}{n+1}\frac{(2n)!}{2^n n! n!} 2^n x^{n}\\
&=  \sum_{n=0}^\infty \frac{1}{n+1}\binom{2n}{n} x^{n}\\
\end{align*}

That is\ldots a far nicer expression.  Also: it works!  In theory, we should have $M_n = \frac{1}{n+1}\binom{2n}{n}$ for all $n$, and check it out:
\begin{align*}
M_0 &= \frac{1}{0+1}\binom{2\cdot 0}{0}  = 1,\\
M_1 &= \frac{1}{1+1}\binom{2\cdot 1}{1}  = \frac{1}{2}\frac{2!}{1!1!} = 1,\\
M_2 &= \frac{1}{2+1}\binom{2\cdot 2}{2}  = \frac{1}{3}\frac{4!}{2!2!} = 2,\\
M_3 &= \frac{1}{3+1}\binom{2\cdot 3}{3}  = \frac{1}{4}\frac{6!}{3!3!} = 5,\\
M_4 &= \frac{1}{4+1}\binom{2\cdot 4}{4}  = \frac{1}{5}\frac{8!}{4!4!} = 14,\\
M_5 &= \frac{1}{5+1}\binom{2\cdot 5}{4}  = \frac{1}{6}\frac{10!}{5!5!} = 42.\\
\end{align*}

Amazing!  Math: it's ridiculous.

\subsection{Alternate Derivations}

When you get an answer as simple as $M_n = \frac{1}{n+1}\binom{2n}{n}$, it suggests that there may be a nice combinatorial interpretation of this formula as it relates to mountains --- that is, some way in which we can ``pick'' $n$ things out of $2n$ things, and after scaling by $1/(n+1)$ to deal with overcounting get our answer!  Pleasantly, this is true: there is a way to derive our closed-form forumla for $M_n$ without generating functions!  We present this here, after the generating function solution, because (while this is a much shorter solution) it is arguably one that requires more \textbf{cleverness}: unlike the above, which was a (crazy) application of tools we know, this one involves either knowing the answer $M_n = \frac{1}{n+1}\binom{2n}{n}$ ahead of time or coming up with some surprising insights into mountain ranges (or both!)

We do this here.  First, let's change our problem somewhat: consider any sequence made out of $n+1$ forward-slashes ``$/$'' and $n$ backslashes ``\textbackslash.''  Here, we're not worrying about these sequences forming proper mountain ranges: i.e. we can dip below our starting altitude.  Moreover, we know that after one of these sequences, we will be precisely one unit higher than we started, as we went ``up'' $n+1$ times and ``down'' $n$ times.

Imagine drawing these slashes on the integer lattice $\mathbb{Z}^2$, so that each forward slash connects some $(a,b)$ to $(a+1, b+1)$, and each backwards slash connects some $(a,b)$ to $(a+1, b-1)$.  
\begin{center}

\end{center}



\end{answer}


\subsection{Catalan Numbers in Other Contexts}

Not to knock the above derivations, but they're actually not what most mathematicians think are the ``cool'' things here!  Instead, consider the recurrence relation we studied to get these numbers:
\begin{align*}
C_0 = C_1 = 1, ~~C_n = \sum_{k=0}^{n-1} C_kC_{(n-1)-k}
\end{align*}

The crazy thing about this recurrence is that there are literally hundreds of mathematical objects and concepts that reduce to this pattern!  On the homework you have six of these recurrences to study; we give one more particularly beautiful example here.

Let $C_n$ denote the total number of ways to take a $n+2$-sided regular convex polygon can be cut into triangles by drawing straight lines between vertices.  There are fourteen ways to do this for $n=4$, as drawn below:
\begin{center}
\includegraphics[width=3in]{catalan4.pdf}\\
\footnotesize (Picture stolen from Wikipedia)\normalsize
\end{center}

I claim that this sequence satisfies the recurrence relation described above.  Our base cases, as typical, are automatic; $C_0$ is kind-of trivially 1, as there's exactly one way (do nothing) to cut the non-existent 2-sided regular polygon into triangles, while $C_1 = 1$ because there's exactly one way (do nothing!) to cut a triangle into\ldots triangles.

To get our recurrence relation: Take any regular $n+2$-gon.  How are we going to break this into smaller polygons?  Well: if we've divided our polygons into triangles, this motivates us to think about cutting along a triangle to get smaller polygons!

Specifically, take our polygon, and pick out the triangle that uses the top edge: because we've broken our polygon into triangles, we know that exactly one such triangle exists!  Split our polygon into two polygons along this triangle: because we create two new edges from the chord-lines of this triangle, and delete one edge by getting rid of the top edge, we must have

\begin{center}
\includegraphics[width=1in]{catalan5.pdf}\\
\end{center}

Split our polygon into two polygons along this triangle: because we create two new edges from the chord-lines of this triangle, and delete one edge by getting rid of the top edge, we must have $n+2 + 2 - 1 = n+3$ edges, split over two polygons.  So we have one $k+2$-gon and one $n-1-k+2$-gon!  In other words, we have the recurrence 
\begin{align*}
C_0 = C_1 = 1, ~~C_n = \sum_{k=0}^{n-1} C_kC_{(n-1)-k}
\end{align*}
as claimed.



\end{document}