\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{latexsym}
\usepackage{verbatim}
\usepackage[pdftex]{graphicx}
\usepackage{url}
\usepackage{mathrsfs}
\usepackage{hyperref}
\hypersetup{colorlinks=true}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{.25in}
\setlength{\textwidth}{6in}
\setlength{\topmargin}{-0.4in}
\setlength{\textheight}{8.5in}

\input{preamble.tex}

\begin{document}

\lecture{1: Basic Counting}{Week 0}

Discrete mathematics is a \textbf{staggeringly} huge field of study in mathematics.  Over the coming three quarters, we will use this class to explore as much of this field as we can: our lectures will range from the fundamentals (where we'll see topics like groups, rings, fields, linear algebra, number theory, graph theory, and others) to current research topics (in sequential dynamical systems, Ramsey theory, cryptography, or the probabilistic method.)  

To begin studying all of these concepts and definitions, however, we need somewhere to start!  So, let's pick the least-structured thing we know: sets.  For this class, we will adopt the following naive definition of what a set is:

\begin{defn}
A \textbf{set} is simply a collection of objects.  To denote a set, we will use curly braces $\{, \}$ to enclose the objects we are placing in our set, and list the objects in our set inside of these braces.  For example, $\{1,2,3\}$ is the set containing the three numbers 1,2 and 3, while $\{$melon, lemon$\}$ is a set containing the two objects lemon and melon.
\end{defn}

There are some subtle complications that can come up with this definition, as you'll see in the Introduction to Higher Mathematics course!  However, in this course, this definition is completely accurate, so let's run with it.

So: given a set, what can we do with it?  Well: unless we add more structure (like a way to ``add'' things in our set, compare elements in our set, multiply elements from our set, or other such things,) our options are pretty limited.  Given a set without any other underlying interpretation for its elements, basically all we can do with a given set is look at its elements.  Now, given any two elements, the only thing we can do with them (again, without any other structure) is tell if they are the same or different!  Really, then, the only thing we can do with a set is the following: \textbf{count} the number of elements in that set!

\section{How to Count}

This might seem like a silly section title; counting, after all, is something that you learned how to do at a very young age\footnote{In particular, if you've seen binomial coefficients, factorials, and other combinatorial objects like that, this section may be review.}.  So let's clarify what we mean by ``counting.''  On one hand, it is very easy to see that there are four elements in a set like
\begin{align*}
A = \{3,5,7, \textrm{Snape}\}.
\end{align*}
In whatever definition we come up with for ``counting,'' this should be an acceptable answer!

But this can get a little trickier.  

\subsection{How to Count: Multiplication}

Consider the following problem:
\begin{problem}
Suppose that we have $k$ different kinds of postcards, and $n$ friends.  In how many ways can we mail out all of our postcards to our friends? 
\end{problem}

As phrased above, this doesn't look like a question about sets; so let's rephrase it a bit.  In the setup above, a valid ``way'' to mail postcards to friends is some way to assign each friend to a postcard, so that each friend is assigned to at least at least one postcard (because we're mailing each of our friends a postcard) and no friend is assigned to two different postcards at the same time.  In other words, a ``way'' to mail postcards is just a function from the set\footnote{Some useful notation: $[n]$ denotes the collection of all integers from 1 to $n$, i.e.\ $\{1,2,\ldots n\}$.} $[n] = \{1,2,3,\ldots n\}$ of postcards to our set $[k] = \{1,2,3,\ldots k\}$ of friends!  

In other words, we want to find the size of the following set:
\begin{align*}
A = \Big\{\textrm{all of the functions that map }[n] \textrm{ to }[k]\Big\}.
\end{align*}

We can do this!  Think about how any function $f: [n] \to [k]$ is constructed.  For each value in $[n] = \{1,2,\ldots n\}$, we have to pick exactly one value from $[k]$.  Doing this for each value in $[n]$ completely determines our function; furthermore, any two functions $f,g$ are different if and only if there is some value $m \in [n]$ at which we made a different choice (i.e. where $f(m) \neq g(m)$.)

\begin{align*}
\underbrace{\fbox{k \textrm{choices}} \cdot \fbox{k \textrm{choices}} \cdot \ldots \cdot \fbox{k \textrm{choices}}  }_{n \textrm{ total slots}} 
\end{align*}
Consequently, we have 
\begin{align*}
\underbrace{k \cdot k \cdot \ldots \cdot k}_{n} = k^n
\end{align*}
total ways in which we can construct distinct functions.  This gives us this answer $k^N$ to our problem!

This looks like an excellent sort of answer to a counting problem: given a set defined by parameters $n, k$, we created a closed-form algebraic expression $k^n$ for the number of elements in that set!  Again, under any theory of counting that we come up with, this should count as a pretty good answer.  

Alongside our answer, we also came up with a fairly interesting \textbf{method} for counting at the same time.  Specifically, we had a set $A$ of the following form:
\begin{enumerate}
\item Each element of $A$ can be split into $k$ parts in order.
\item For each part, we had $k$ total possible choices.
\item Therefore, we had $\underbrace{k \cdot k \cdot \ldots \cdot k}_{n} = k^n$ total elements in $A$.
\end{enumerate}
This can be generalized as follows:
\begin{obs}
(\textbf{Multiplication principle.})  Suppose that you have a set $A$, each element of which can be broken up into $n$ pieces in order.  Suppose furthermore that the $i$-th piece has $k_i$ total possible states for each $i$, and that our choices for the $i$-th stage do not interact with our choices for any other stage.  Then there are
\begin{align*}
k_1 \cdot k_2 \cdot\ldots \cdot k_n = \prod_{i=1}^n k_i
\end{align*}
total elements in $A$.
\end{obs}

Pretty intuitive, right?



Let's try changing our postcard problem a bit from before:
\begin{problem}
Suppose that we have $k$ different kinds of postcards, and $n$ friends, and that we still want to mail these postcards to our friends.  This time, however, we don't want to duplicate any of our postcards!  In how many ways can we mail out postcards now?
\end{problem}

We can solve this using the same reasoning as before.  We can still describe each way of sending postcards as a sequence of choices:
\begin{align*}
\underbrace{\fbox{? \textrm{choices}} \cdot \fbox{? \textrm{choices}} \cdot \ldots \cdot \fbox{? \textrm{choices}}  }_{n \textrm{ total slots}} 
\end{align*}
As before, we still have $k$ possibilities for what to send to our first friend.  However, the multiplication principle doesn't apply here: because we don't want to have any repetitions, we only have $k-1$ choices for our second slot, instead of $k$ as before!  In general, we have the following sequence of choices:
\begin{align*}
\underbrace{\fbox{k \textrm{choices}} \cdot \fbox{k-1 \textrm{choices}} \cdot \fbox{k-2 \textrm{choices}} \cdot \ldots \cdot \fbox{k- (n-1) \textrm{choices}}  }_{n \textrm{ total slots}},
\end{align*}
which translates into
\begin{align*}
k \cdot (k-1) \cdot \ldots \cdot (k - (n-1))
\end{align*}
many choices in total.

A convenient way to describe the above is as the following quantity:
\begin{align*}
k \cdot (k-1) \cdot \ldots \cdot (k - (n-1)) &=  \frac{\Big(k \cdot (k-1) \cdot \ldots \cdot (k - (n-1)) \Big)\cdot \Big( (k-n) \cdot (k-(n+1)) \cdot \ldots \cdot 3 \cdot 2 \cdot 1 \Big)}{\Big( (k-n) \cdot (k-(n+1)) \cdot \ldots \cdot 3 \cdot 2 \cdot 1 \Big)}\\
&= \frac{k!}{(k-n)!},
\end{align*}
where by $n!$ we mean \textbf{n-factorial}, the product of all of the natural numbers between 1 and n, inclusive.  (By convention we define $0! = 1$, as another natural definition for $n!$ is the number of ways of ordering a list of $n$ objects, and there is exactly one way to order an empty list.)

Let's tweak the postcard problem again!\footnote{In mathematics: whenever you have a problem at hand, constantly look for modifications like these to make to the problem!  If you're stuck, it can give you different avenues to approach or think about the problem; conversely, if you think you understand the problem, this can be a way to test and deepen that understanding.}
\begin{problem}
We still have $k$ different kinds of postcards, and $n$ friends; now we want to mail $m$ postcards to each friend, so that no friend receives any repeated postcards.  (Different friends can receive the same postcards, though!)  In how many ways can this happen?
\end{problem}
Again, we describe each way of sending postcards as a sequence of choices:
\begin{align*}
\underbrace{\fbox{? \textrm{choices}} \cdot \fbox{? \textrm{choices}} \cdot \ldots \cdot \fbox{? \textrm{choices}}  }_{n \textrm{ total slots}} 
\end{align*}

Notice that because different friends can receive the same postcards, we can now return to the multiplication principle (as our choices for any given friend do not influence our choices for other friends!)  Thus, it suffices to understand how many postcards can be sent to a given friend!

We have $k$ different kinds of postcards, and we want to find out how many ways to send $m$ different cards to a given friend.  At first glance, you might think that this is the same as the answer to our second puzzle: i.e.\ we have $m$ slots, and we clearly have $k$ choices for the first slot, $k-1$ choices for the second slot, and so on/so forth until we have $k-(m-1)$ choices for our last slot.  

This would certainly seem to indicate that there are $\frac{k!}{(k-m)!}$ many ways to assign cards.  However, our situation from before is not quite the same as the one we have now!  In particular: notice that the order in which we pick our our postcards to send to this one friend does not matter to our friend, as they will receive them all at once anyways!  Therefore, our process above is \textbf{over-counting} the total number of ways to send out postcards: it would think that sending card $X$ and$Y$ is a different action to sending card $Y$ and card $X$!  

To fix this, we need to correct for our over-counting errors above.  Notice that for any given set of $m$ distinct cards, there are $m!$ different ways to order that set.  Therefore, if we are looking at the collection of ordered length $m$ sequences of cards, each unordered sequence of $m$ cards corresponds to $m!$ elements in this ordered sequence!  Therefore, if we want to only count the unordered sequences, we can simply divide the size of our set of ordered sequences by $m!$

Consequently, there are actually
\begin{align*}
\frac{k!}{(k-m)! \cdot m!}
\end{align*}
many ways to pick out $m$ cards from our set of $k$ postcards, without any elements being repeated.  This concept --- given a set of $k$ things, in how many ways can we pick $m$ of them, if we don't care about the order in which we pick those elements --- is an incredibly useful one, and as such we have notation to describe this object.  Namely, we denote this quantity via the \textbf{binomial coefficient} $\binom{k}{m}$, and define\footnote{Often, in mathematical papers, when a mathematician defines some object via an equation, they will put the object being defined on the left, write $:=$ to draw attention to the fact that this is a definition, and put the quantity the object is being defined as on the right.  So, if you were wondering why there a was a colon by the equals sign: this is why!}
\begin{align*}
\binom{k}{m} := \frac{k!}{(k-m)! \cdot m!}.
\end{align*}

Finally, if we return to our original postcard problem: we have $n$ total people to send postcards to, and we've just shown that for each person we have $\binom{k}{m}$ many ways in which to send them postcards.  This gives us 
\begin{align*}
\underbrace{\binom{k}{m} \cdot \ldots \cdot \binom{k}{m}}_{n \textrm{ choices}} = \left(\binom{k}{m}\right)^n
\end{align*}
total ways to send postcards!

\subsection{How to Count: Addition}

Our ``multiplication principle'' is not the only tool we have for counting things.  Consider the following common-sense idea for how to count the elements in a set:
\begin{obs}
(\textbf{Summation principle}.)  Suppose that you have a set $A$ that you can write as the \textbf{union}\footnote{Given two sets $A, B$, we denote their \textbf{union}, $A \cup B$, as the set containing all of the elements in either $A$ or $B$, or both.  For example, $\{2\} \cup \{$lemur$\} = \{2, $ lemur$\}$, while $\{1,\alpha\} \cup \{ \alpha, $lemur$\} = \{1, \alpha, $ lemur$\}$.}of several smaller disjoint\footnote{Sets are called \textbf{disjoint}if they  haven no elements in common.  For example,  $\{2\}$ and  $\{$lemur$\}$ are disjoint, while $\{1,\alpha\}$ and $\{ \alpha, $lemur$\}$ are not disjoint.}  sets $A_1, \ldots A_n$.

Then the number of elements in $A$ is just the summed number of elements in the $A_i$ sets.  If we let $|S|$ denote the number of elements in a set $S$, then we can express this in a formula:
\begin{align*}
|A| = |A_1| + |A_2| + \ldots + |A_n|.
\end{align*}
\end{obs}

We work one simple example, and one trickier example:

\begin{question}
Pizzas!  Specifically, suppose Pizza My Heart (a local chain/ great pizza place) has the following deal on pizzas: for 7\$, you can get a pizza with any two different vegetable toppings, or any one meat topping.  There are $m$ meat choices and $v$ vegetable choices.  As well, with any pizza you can pick one of $c$ cheese choices.

How many different kinds of pizza are covered by this sale?
\end{question}
\begin{solution}
Using the summation principle, we can break our pizzas into two types: pizzas with one meat topping, or pizzas with two vegetable toppings.

For the meat pizzas, we have $m \cdot c$ possible pizzas, by the multiplication principle (we pick one of $m$ meats and one of $c$ cheeses.)

For the vegetable pizzas, we have $\binom{v}{2} \cdot c$ possible pizzas (we pick two different vegetables out of $v$ vegetable choices, and the order doesn't matter in which we choose them; we also choose one of $c$ cheeses.)

Therefore, in total, we have $c \cdot \left(m + \binom{v}{2}\right)$ possible pizzas!
\end{solution}


\begin{question}
Demonstrate the following equality:
\begin{align*}
\binom{n}{k} = \binom{n-1}{k} + \binom{n-1}{k-1}.
\end{align*}
\end{question}
\begin{solution}
While it is not particularly obvious, we can do this with the summation principle!  

We do this as follows: take the set $\{1, \ldots n\}$, and consider all of the $k$-element subsets\footnote{We say that a set $A$ is a subset of a set $B$, and write $A \subseteq B$, if every element of $A$ is an element of $B$.  For example, $\{1,2,$ Batman$\}$ is a subset of $\{1,2,3,4,5,$ Batman, $7\}$.} of this set.  On one hand, there are $\binom{n}{k}$ many such subsets --- this is because there are precisely $\binom{n}{k}$ many ways to pick out $k$ things from a set of $n$ things if we don't care about the order in which we pick things, and that is precisely what we are doing when we are finding $k$-element subsets.

On the other hand, let's break our subsets of $\{1, \ldots n\}$ into two cases:
\begin{enumerate}
\item The subsets that contain the element $n$.  How many such subsets are there?  Well: to create any such subset, we have to pick the element $n$, and then we have to pick $k-1$ more elements out of a set of $n-1$ total possible objects (to fill in the rest of the set.)  But this just means that there are $\binom{n-1}{k-1}$ many such sets!
\item The subsets that \textbf{do not} contain the element $n$.  How many such subsets are there?  Well: to create any such subset, we have to pick $k$ elements out of a set of $n-1$ total possible objects (because we need $k$ things that are not $n$.)  But this just means that there are $\binom{n-1}{k}$ many such sets!
\end{enumerate}
By the rule of sum, because each subset of $\{1, \ldots n\}$ falls into exactly one of the two cases above, we can conclude that the total number of $k$-element-sized subsets of $\{1,\ldots n\}$ is just
\begin{align*}
\binom{n-1}{k} + \binom{n-1}{k-1}.
\end{align*}

Combining our two observations above gives us that

\begin{align*}
\binom{n}{k} = \binom{n-1}{k} + \binom{n-1}{k-1}.
\end{align*}
\end{solution}


\subsection{How to Count: Double-Counting}

There is another really useful idea in the above example, that bears noting: to show that $\binom{n}{k} = \binom{n-1}{k} + \binom{n-1}{k-1}$, we actually looked at a third object (the collection of all $k$-element subsets of $\{1,\ldots n\}$, and showed that if you count it in one way you get $\binom{n}{k}$, and if you count it in another way you get $\binom{n-1}{k} + \binom{n-1}{k-1}$.  Consequently, we claimed that these quantities are equal!

This idea, of \textbf{double-counting}, is as useful as our earlier observations:
\begin{obs}
(\textbf{Double-counting principle}.)  Suppose that you have a set $A$, and two different expressions that count the number of elements in $A$.  Then those two expressions are equal.
\end{obs}

We give one quick example of this in action:

\begin{question}
Without using induction\footnote{We'll get to this in the introduction to proofs class; if you're not in that course and you want to know what this is, talk to me or check out Wikipedia!}, prove the following equality:
\begin{align*}
\sum_{i=1}^n i = \frac{n(n+1)}{2}
\end{align*}
\end{question}
\begin{solution}

First, make a $(n+1) \times (n+1)$ grid of dots:
\begin{center}
\includegraphics[width=2in]{gridofdots.pdf}
\end{center}

How many dots are in this grid?  On one hand, the answer is easy to calculate: it's $(n+1)\cdot(n+1) = n^2 + 2n + 1$.

On the other hand, suppose that we group dots by the following diagonal lines:
\begin{center}
\includegraphics[width=2in]{gridofdots2.pdf}
\end{center}

The number of dots in the top-left line is just one; the number in the line directly beneath that line is two, the number directly beneath that line is three, and so on/so forth until we get to the line containing the bottom-left and top-right corners, which contains $n+1$ dots.  From there, as we keep moving right, our lines go down by one in size each time until we get to the line containing only the bottom-right corner, which again has just one point.

So, if we use the summation principle, we have that there are
\begin{align*}
1+2+3+\ldots + (n-1) + n + (n+1) + n + (n-1) + \ldots + 3 + 2 + 1
\end{align*}
points in total.

Therefore, by our double-counting principle, we have just shown that
\begin{align*}
n^2 + 2n + 1 = 1+2+3+\ldots + (n-1) + n + (n+1) + n + (n-1) + \ldots + 3 + 2 + 1.
\end{align*}
Rearranging the right-hand side using summation notation lets us express this as
\begin{align*}
n^2 + 2n + 1 = (n+1) + 2\sum_{i=1}^n i;
\end{align*}
subtracting $n+1$ from both sides and dividing by 2 gives us finally
\begin{align*}
\frac{n^2 + n}{2} = \sum_{i=1}^n i,
\end{align*}
which is our claim!
\end{solution}

\subsection{How to Count: Recursion}

In each of the above problems, the answers we got to,
\begin{align*}
k^n \quad , \quad\frac{k!}{(k-n)!}\quad, \quad  c \cdot \left(m+\binom{v}{2}\right)\quad, \quad \frac{n(n+1)}{2}\quad,
\end{align*} 
all looked like ``good'' answers for how to count the elements in our sets!  This is because these answers were all \textbf{closed-form} expressions for the sizes of these sets: in other words, each of our answers above are short, simple expressions that we can calculate in a finite number of steps given values for our parameters.

However, not all questions obviously admit such solutions.  Consider the following problem:
\begin{question}
Suppose that we have a petri dish in which we're growing a population of amoebae, each of which can be in two possible states (\textbf{small} and \textbf{large}). 

Amoebas grow as follows: if an amoeba is small at some time $t$, then at time $t+1$ it becomes large, by eating food around it.  If an amoeba is large at some time $t$, then at time $t+1$ it splits into one large amoeba and one small amoeba.

Suppose our petri dish starts out with one small amoeba at time $t=1$.  How many amoebae in total will be in this dish at time $t=n$, for any natural number $n$?
\end{question}

\begin{answer}
One approach to this problem is to use the technique of \textbf{recursion}.  Roughly speaking, recursion, (or induction, depending on where you start) is the art of taking a larger problem and finding a way of breaking it into smaller instances of the same problem.  For example, \textbf{multiplication} is a task that can be described recursively!  Suppose you wanted to calculate $m \times n$, for two natural numbers $m, n$.
\begin{enumerate}
\item If $n = 0$, then $m \cdot n$ is 0.  Otherwise, go to line 2.
\item If $n > 0$, notice that $m \cdot n = n + m \cdot (n-1)$.  Therefore, it suffices to calculate $m \cdot (n-1)$.  To do this, use $m, (n-1)$ as your inputs to line 1.
\end{enumerate}

For example, we could recursively calculate that
\begin{align*}
8 \cdot 5 = 8 + (8 \cdot 4) = 8 + (8 + (8 \cdot 3)) &= (8+(8+(8+(8 \cdot 2))))\\
&=(8+(8+(8+(8+(8 \cdot 1)))))\\
&=(8+(8+(8+(8+(8 + (8 \cdot 0))))))\\
&=(8+(8+(8+(8+(8 + 0)))))\\
&= 40.
\end{align*}

Recursion, or ``divide and conquer,' is an incredibly useful and common tactic to solve problems in mathematics.  It can often be easier to see how to break a problem into smaller cases than to see how to solve it all at once!  Furthermore, if we can find some sort of a recursive relationship, we can often use this to get a full answer to our problem --- it can be a lot easier to solve a few smaller or base cases for a problem rather than solving all of them at once! 

Formally speaking, we can define\footnote{Informally speaking, we can define recursion with footnote 9.} recursion as follows:
\begin{defn}
Suppose that we have an set $A(n)$ that we would like to count, that depends on some natural number $n$.  (For example, in our amoeba problem above, $A(n)$ could be ``the number of amoebae in our petri dish at time $t=n$.)

A \textbf{recurrence relation} for $A(n)$ is just an expression for $A(n)$ in terms of earlier-occurring terms $A(m)$. (For example, suppose that $A(n) = 2^n$.  Then $A(n) = 2 \cdot A(n-1)$: this is a recurrence relation that defines $A(n)$ in terms of an earlier-occurring term.)
\end{defn}

To give a slightly more interesting example of a recurrence relation: let's consider our amoeba problem!  To help find any such recurrence relation, let's make a chart of our amoeba populations over the first six time steps:
\begin{align*}
\begin{array}{c|cccccc}
& 1 & 2 & 3 & 4 & 5 & 6\\\hline
\textrm{Large} & 0 & 1 & 1 & 2 & 3 & 5\\
\textrm{Small} & 1 & 0 & 1 & 1 & 2 & 3\\
\textrm{Total} & 1 & 1 & 2 & 3 & 5 & 8\\
\end{array}
\end{align*}

This chart lets us make the following observations:
\begin{enumerate}
\item The number of large amoebae at time $n$ is precisely the total number of amoebae at time $n-1$.  This is because every amoeba at time $n-1$ either grows into a large amoeba or already was an amoeba!
\item The number of small amoebae at time $n$ is the number of large amoebae at time $n-1$.  This is because the only source of small amoebae are the large amoebae from the earlier step when they split!
\item By combining 1 and 2 together, we can observe that the number of small amoebae at time $n$ is the total number of amoebae at time $n-2$!
\item Consequently, because we can count the total number of amoebae by adding the large amoebae to the small amoebae, we can conclude that \textbf{the total number of amoebae at time }$n$\textrm{ is the total number of amoebae at time }$n-1$,\textrm{ plus the total number of amoebae at time }$n-2$.  In symbols,
\end{enumerate}
\begin{align*}
A(n) = A(n-1) + A(n-2).
\end{align*}

This is a recurrence relation!  Moreover, I claim that this is a \textbf{good answer} to our question earlier, about how many amoebae are in our petri dish.  

However, when we look at an expression like $k^n$, we immediately know how to calculate this quantity --- this is part of why we liked this as an answer to our earlier counting problems!  Can the same be said for our recurrence-relation answer?

I claim that with a bit of thought, and in specific the concept of \textbf{induction}, the answer to this question is yes!
\end{answer}

We make a quick detour to discuss what induction is here: if you've seen induction before, skip this subsection for the next part of our lecture!

\subsection{Detour: Induction}

Sometimes, in mathematics, we will want to prove the truth of some statement $P(n)$ that depends on some variable $n$.  For example:
\begin{itemize}
\item$ P(n) =$   ``The sum of the first $n$ natural numbers is $\frac{n(n+1)}{2}$.''
\item $P(n) =$ ``If $ q \geq 2$, we have $n \leq q^n$.
\item $P(n) = $  ``Every polynomial of degree $n$ has at most $n$ roots.''
\end{itemize}

For any fixed $n$, we can usually use our previously-established methods to prove the truth or falsity of the statement.  However, sometimes we will want to prove that one of these statements holds for \textbf{every} value $n \in \mathbb{N}$. How can we do this?  

One method for proving such claims for every $n \in \mathbb{N}$ is the method of \textbf{mathematical induction}! Proofs by induction are somewhat more complicated than the previous two methods.  We sketch their structure below:
\begin{itemize}
\item To start, we take our claim $P(n)$, that we want to prove holds for every $n \in \mathbb{N}$.
\item The first step in our proof is the \textbf{base step}:in this step, we explicitly prove that the statement $P(1)$ holds, using normal proof methods.
\item With this done, we move to the \textbf{induction step} of our proof: here, we prove the statement $P(n) \implies P(n+1)$, for every $n \in \mathbb{N}$.  This is an implication; we will usually prove it directly by assuming that $P(n)$ holds and using this to conclude that $P(n+1)$ holds. 
\end{itemize}
Once we've done these two steps, the principle of induction says that we've actually proven our claim for all $n \in \mathbb{N}$!  The rigorous reason for this is the \textbf{well-ordering principle}, which we discussed in class; however, there are perhaps more intuitive ways to think about induction as well.

The way I usually think of inductive proofs is to think of \href{http://en.wikipedia.org/wiki/Dominoes#Other_uses_of_dominoes}{toppling dominoes}.  Specifically, think of each of your $P(n)$ propositions as individual dominoes -- one labeled $P(1)$, one labeled $P(2)$, one labeled $P(3)$, and so on/so forth.  With our inductive step, we are insuring that all of our dominoes are \textit{lined up} -- in other words, that if one of them is true, that it will ``knock over'' whichever one comes after it and force it to be true as well!  Then, we can think of the base step as ``knocking over'' the first domino; once we do that, the inductive step makes it so that all of the later dominoes also have to fall, and therefore that our proposition must be true for all $n$ (because all the dominoes fell!)

To illustrate how these kinds of proofs go, here's an example:
\begin{defn}
The $n$-th \textbf{Fibonacci number} is defined recursively as follows:
\begin{itemize}
\item $f_0 = 0$.
\item $f_1  = 1$.
\item $f_n = f_{n-2} + f_{n-1}$.
\end{itemize}
\end{defn}

\begin{exmp}
Here is the start of the  Fibonacci number sequence:
\begin{align*}
0,1,1,2,3,5,8,13,21,34,55,89, \ldots
\end{align*}
\end{exmp}

Notice that the Fibonacci sequence is precisely our amoeba-growth pattern from our earlier example!

The Fibonacci sequence satisfies a number of properties that can be demonstrated via induction.  We study one such example here:

\begin{claim}
The $n$-th Fibonacci number is even iff $n$ is a multiple of 3.
\end{claim}
\begin{proof}
As noted above, the ``recursive'' construction of the Fibonacci numbers, where it looks like we're building our numbers out of earlier-defined numbers, suggests induction.  

So: let's try!  Our base case for a number of immediate cases is trivially true: we can check by hand that $f_0 = 0, f_1 = 1, $ and $f_2 = 1$.

So: inductively, suppose we know that $f_n$ is even if and only if $n$ is a multiple of 3.   Does this help us with $f_{n+1}$?

The answer is \ldots no, not really.  Because
\begin{align*}
f_{n+1} = f_n + f_{n-1},
\end{align*}
we really need more information than just $f_n$: we also need to know whether $f_{n-1}$ is even or odd!  Our normal induction isn't strong enough here; we need something\ldots stronger.  Like \ldots \textbf{strong} induction!

Strong induction proceeds very similarly to normal induction:
\begin{itemize}
\item To start, we take our claim $P(n)$, that we want to prove holds for every $n \in \mathbb{N}$.
\item The first step in our proof is the \textbf{base step}:in this step, we explicitly prove that the statement $P(1)$ holds, using normal proof methods.
\item With this done, we move to the \textbf{induction step} of our proof.  For strong induction, we prove the statement that the combined statements $P(1) \wedge P(2) \wedge \ldots P(n)$ implies $P(n+1)$.  If you go back to our domino analogy, this is like asking whether knowing that \textbf{every} domino from 1 to $n$ falling over tells you that the $n+1$-th domino falls over.
\end{itemize}

So: if we're using strong induction, then we're allowed to assume that our inductive hypothesis holds for every value between $0$ and $n$, and prove that it holds for $n+1$.  We know that 
\begin{align*}
f_{n+1} = f_n + f_{n-1};
\end{align*}
so, it suffices to consider the three possible cases for $n+1$.  Either $n+1$ is a multiple of 3, in which case we can write it as $3k$, or it is 1 mod 3, in which case it can be written as $3k+1$, or it's 2 mod 3, in which case we can write it as $3k+2$.  In any case, we can use our inductive hypothesis to see that
\begin{align*}
f_{3k} = f_{3k-1} + f_{3k-2} = \textrm{odd} +\textrm{odd} = \textrm{even},\\
f_{3k+1} = f_{3k} + f_{3k- 1} = \textrm{even} +\textrm{odd} = \textrm{odd},\\
f_{3k+2} = f_{3k+1} + f_{3k} = \textrm{odd} +\textrm{even} = \textrm{odd},\\
\end{align*}
and thus that our property holds in any of these three cases.  Thus, by induction, we know that $f_n$ is even if and only if it is a multiple of 3.
\end{proof}

\subsection{How to Count: Recursion (again!)}

The reason we mention induction here is that it's basically \textbf{recursion in reverse}.  In one situation, we took a complicated problem and broke it down into smaller pieces; in the other, we took a base case and grew it up into larger cases!

In particular, the neat thing about induction is that it tells us how to count things we've measured recursively!  Let's think about our amoeba problem once more.  
\begin{itemize}
\item We know that $A(1) = 1$, by assumption, and that $A(2) = 1$, by looking at the data we collected earlier!
\item We also know that $A(n) = A(n-1) + A(n-2)$.
\end{itemize}
I claim that by using induction, we actually know what $A(n)$ is for any $n$!  This is a pretty silly, but honestly legitimate notion of how induction works:
\begin{itemize}
\item As a base case, we clearly know what $A(1)$ and $A(2)$ are, as demonstrated above.
\item For an inductive step: assume that we ``know'' what $A(m)$ is, for every $m < n$.  Then because $A(n) = A(n-1) + A(n-2)$, we also know what $A(n)$ is!
\end{itemize}
Therefore, by induction, our recurrence relation is actually a valid way to count!  

It's not necessarily the fastest way to count, mind you: to find $A(n)$ with our formula above, we have to perform $n$ addition operations, starting from our base cases.  This is different than say a closed-form expression like $k^n$, which we can usually evaluate very quickly using clever algorithms for exponentiation.  So, if you're programming, you may find yourself objecting to a recurrence relation as a ``good'' way to count.  As well, it can be hard to tell from a glance how ``fast'' our recurrence relation is growing --- unlike an expression like $n^3$, it's hard to tell roughly how big $A(n)$ will be for a given input $n$.  This can cause issues with approximation problems, where we want to count something tricky but don't care about exactly what it is --- a recurrence relation doesn't immediately tell us that information!

Later in this course, we'll talk about how to fix those two problems (because they are fixable!) 


For now, however, let's look at a few more examples of recursion:
\subsection{Recursion examples!}
\begin{exmp}
The Towers of Hanoi is the following puzzle: Start with $3$ rods.  On one rod, place $n$ disks with radii $1, 2, \ldots n$, so that the disk with radius $n$ is on the bottom, the disk with radius $n-1$ is on top of that disk, and so on/so forth.  

The goal of this puzzle is to move all of the disks from one rod to another rod, obeying the following rules:
\begin{itemize}
\item You can move only one disk at a time.
\item Each move consists of taking the top disk off of some rod and placing it on another rod.
\item You cannot place a disk $A$ on top of any disk $B$ with radius smaller than $A$.
\end{itemize}
\begin{center}
\includegraphics[width=2in]{MC2012_wk5blurbs_hanoi.pdf}
\end{center}
What is the smallest number of moves needed to move all of our disks from the first peg to the third peg?
\end{exmp}
\begin{answer}
If you haven't played around with this puzzle before, take a break now and do so!

(waits)

Ok!  I'm assuming now that you've done some basic work on this problem, and in particular worked some small cases out!  Along the way, you've probably made the following observations:
\begin{enumerate}
\item If there is only one disk, we can do this in one move; if there are two disks, it takes us three moves; if there are three disks, it takes us seven moves, and if there are four disks, it takes us fifteen moves at best.  (So, if you were to guess a pattern, $2^n - 1$ seems like a good bet!)
\item You can break down the task of moving a stack of $n$ disks into three steps:
\begin{enumerate}
\item Move the first $n-1$ disks onto the second pole.
\item Move the $n$-th disk to the third pole.
\item Move the remaining $n-1$ disks on top of this $n$-th disk.
\end{enumerate}
\item Furthermore, we know that all of these tasks are necessary: to move all of the disks to the third pole, we need to start by getting the $n$-th disk to the third pole.  To do this, we need to get the first $n-1$ disks out of the way by putting them somewhere else (namely, the second pole!)  Finally, when we have moved the $n$-th disk to the third pole, moving the remaining $n-1$ disks on top of that disk is exactly what it means to finish our puzzle.
\end{enumerate}
These last two observations, when combined, give us a \textbf{recurrence relation}: if $H_n$ is the total number of moves it takes to move a tower of $n$ disks, we have just shown that
\begin{align*}
H_n = H_{n-1} + 1 + H_{n-1},
\end{align*}
because we must move a tower of $n-1$ disks, move one disk, and then move that $n-1$ tower again!

Using this recurrence relation, we can prove our guess that $H_n = 2^n - 1$ via induction:
\begin{enumerate}
\item[Base case:] We know $H_1 = 1 = 2^1 - 1$ from our case work.
\item[Ind. step:]  Assume that $H_n = 2^n - 1$ for each $n$ from 1 to $m$; we will seek to prove that $H_{m+1} = 2^{m+1} - 1$.  This is pretty quick: notice that
\begin{align*}
H_{m+1} &= H_{m} + 1 + H_{m}, \textrm{ by our recurrence relation,}\\
 &= (2^m - 1) + 1 + (2^m - 1), \textrm{ by our inductive hypothesis},\\
 &= 2 \cdot 2^m - 1\\
 &= 2^{m+1} - 1, \textrm{ as claimed.}
\end{align*}
\end{enumerate}

\end{answer}

\begin{exmp}
Draw some straight lines in the plane.  Notice that when we do this, we divide the plane up into regions bounded by these lines.  What is the maximum number of regions we can divide the plane into with $n$ lines?
\end{exmp}
\begin{answer}
Again, take a moment to work out some base cases and figure out what's going on here!

Here's a few observations you're likely to have made:
\begin{enumerate}
\item No lines break the plane into one piece, as we've not split anything up!  One line breaks the plane into two pieces; two lines breaks the plane into up to four pieces if those lines are not parallel; three lines can break the plane up into seven pieces if we are careful to not let all three lines intersect at the same place; and four lines can break the plane up into up to 11 pieces if we are again careful to not have any more than two lines intersect at any point, and also not have any parallel lines!  In general, it looks like $n$ lines is giving us $1 + \frac{n(n+1)}{2}$ regions, given enough data and staring at things.
\item In general, it looks like the $n$-th line is adding at most $n$ new regions to our plane.  To see why this might hold in general, consider the process of drawing any line.
\begin{enumerate}
\item If our line intersects any region, it divides that region into two pieces!  This is the only way our line creates new regions.
\item Our line enters a region if and only if it crosses one of the lines that bounds that region.
\item As well, before our line crosses any other regions, it by default starts in some region already.
\item Therefore, the total number of times our line intersects other lines, plus one, is the total number of new regions created!
\item We can cross each other line at most once, as our lines are straight.
\item Therefore, if there are $n$ lines in existence, we can create at most $n+1$ new regions by adding a $n+1$-th line.
\end{enumerate}
\item Furthermore, notice that it is always possible to draw such a line!  To draw a line, we need to give two pieces of information:
\begin{enumerate}
\item Its slope needs to not be parallel to any other existing line's slope, to insure that it can intersect that line.  There are only $n$ slopes currently used and infinitely many possibilities, so this is always possible.
\item Given a slope, we need to pick a $x$-intercept for our line.  Furthermore, we want to do this so that our line does not intersect any other lines at places where multiple lines are already intersecting: this would make our line use up multiple ``intersecting other line'' instances, while only entering one region (which means we wouldn't get to $n+1$!)  There are only finitely many such existing intersection points, and infinitely many choices of $x$-intercept; so we can also avoid all of these possibilities.
\end{enumerate}
Therefore, it is possible to always draw a line that intersects other lines in $n$ places, and thus that creates $n+1$ new regions!
\end{enumerate}
By the above, we have a rather nice recurrence relation: if $L_n$ is the total number of regions that we can divide the plane up into with $n$ lines, we have
\begin{align*}
L_{n+1} = (n+1) + L_{n}.
\end{align*}

Using this, we can prove that our guess of $L_n = 1 + \frac{n(n+1)}{2}$ is right via induction:
\begin{enumerate}
\item[Base case:] We know $L_0 = 1 = 1 + \frac{0\cdot 1}{2}$ from our case work.
\item[Ind. step:]  Assume that $L_n = 1 + \frac{n(n+1)}{2}$ for each $n$ from 1 to $m$; we will seek to prove that $L_{m+1} = 1 + \frac{(m+1)(m+2)}{2}$.  This is pretty quick: notice that
\begin{align*}
L_{m+1} &= (m+1) + L_m, \textrm{ by our recurrence relation,}\\
 &= (m+1) + \frac{m(m+1)}{2} + 1, \textrm{ by our inductive hypothesis},\\
 &= \frac{m^2 + m + 2m + 2}{2} + 1\\
 &= \frac{(m+1)(m+2)}{2} + 1, \textrm{ as claimed.}
\end{align*}
\end{enumerate}
\end{answer}


We work one last example here: the Josephus problem!  This is a problem with a lot of fascinating history behind it (see \href{http://en.wikipedia.org/wiki/Josephus_problem}{this Wikipedia article} for a quick gloss); in the interest of me getting to sleep sometime tonight, we will simply focus on the math here for now.
\begin{exmp}
Take any natural number $n$, and write down the integers from 1 to $n$ clockwise around a circle.  Starting from $1$, go clockwise around our circle and eliminate every second not-yet-eliminated number until only one number remains: we call this number the Josephus number for $n$, and denote it $J(n)$.
\begin{center}
\includegraphics[width=5in]{josephus.pdf}\\
\footnotesize The Josephus system for $n=12$.  The purple arrow tells us where we currently are in the process, and the red cross-outs denote eliminating a number.\normalsize
\end{center}
What is $J(n)$, for any $n$?
\end{exmp}
\begin{answer}
As in our last two examples, we start by making observations and collecting data.  Take some time to check this problem out on your own!  When you return, verify the following results:

\begin{enumerate}
\item We can calculate a small table for values of $J(n)$ by hand:
\begin{align*}
\begin{array}{c|cccccccccccccccc}
 & 1&2&3&4&5&6&7&8&9&10&11&12&13&14&15&16\\\hline
J(n) & 1 & 1 & 3 & 1 & 3 & 5 & 7 & 1 & 3 & 5 & 7 & 9 & 11 & 13 & 15 & 1\\
\end{array}
\end{align*}
The pattern here can be hard to see; after some thought, however, it looks like our rule is the following: take any number $n$.  Write $n = 2^m + l$, for some $0 \leq l \leq 2^m - 1$; we can do this for any number (why?)  If we do this, then it appears that our Josephus numbers $J(n)$ are given by the equation $J(n) = 2l+1$; it sets $J(2^m) = 1$ for every $m$, and gives us the odd-number-progressions that we're seeing in between all of these powers of 2!
\item When looking at the above table, we can notice that there are no even Josephus numbers!  This is not too hard to see. If we are trying to find the Josephus number of $2k$, then after we have gone $k$ steps into our game all of the even numbers are eliminated, and we have a circle with just the values $1,3,5,7,9, \ldots 2k-1$ on it, where we're starting with 1.  

Similarly, if we're trying to find the Josephus number of $2k-1$, then going $k-1$ steps into our game gives us a circle with the values $1,3,5,7, \ldots 2k-1$, where we're starting at $2k-1$; going one step more gives us a circle of the form $3,5,7, \ldots 2k-1$ where we're starting at 3.
\item This gives us a recurrence relation!  In fact, our first observation tells us that the Josephus number of $2k$ is related to the Josephus number of $k$, via the relation
\begin{align*}
J(2k) = 2J(k) -1.
\end{align*}
Similarly, our second observation tells us that the Josephus number of $2k-1$ is related to the Josephus number of $k-1$, via the relation
\begin{align*}
J(2k - 1) = 2J(k - 1) +1.
\end{align*}
(If you don't see why these relations are true, think about this for a while!)
\end{enumerate}

We can use induction to prove our claimed pattern.  First, notice that by induction we have $J(2^m) = 1$ for all $m$:
\begin{enumerate}
\item[Base case:] We know $J(2^0) = J(1) = 1$.
\item[Ind. step:]  Assume that $J(2^n) = 1 $ for each $n$ from 1 to $m$; we will seek to prove that $J(2^{m+1}) = 1$.  This is almost trivial;
\begin{align*}
J(2^{m+1}) &= 2J(2^m) - 1, \textrm{ by our recurrence relation,}\\
 &= 2 \cdot 1 - 1, \textrm{ by our inductive hypothesis},\\
 &=  1, \textrm{ as claimed.}
\end{align*}
\end{enumerate}

Now, suppose we're looking at $J(2^m + l)$.  If we take $l$ moves in this game, we now have a Josephus circle with $2^m$ entries on it, starting at the location $2l+1$.  We know that playing on this board, the surviving entry is precisely wherever we start, by our inductive proof above!  Therefore, $J(2^m + l) = 2l+ 1$, as claimed.
\end{answer}







\end{document}