\documentclass[numbers=enddot,12pt,final,onecolumn,notitlepage]{scrartcl}%
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[all,cmtip]{xy}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{framed}
\usepackage{comment}
\usepackage{color}
\usepackage[breaklinks=True]{hyperref}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{needspace}
\usepackage{tabls}
\usepackage{tikz}
\usepackage{bbding}
%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{LastRevised=Tuesday, March 07, 2023 22:52:31}
%TCIDATA{SuppressPackageManagement}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Language=American English}
%BeginMSIPreambleData
\providecommand{\U}[1]{\protect\rule{.1in}{.1in}}
%EndMSIPreambleData
\usetikzlibrary{arrows.meta}
\usetikzlibrary{chains}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\newcounter{exer}
\newcounter{exera}
\theoremstyle{definition}
\newtheorem{theo}{Theorem}[subsection]
\newenvironment{theorem}[1][]
{\begin{theo}[#1]\begin{leftbar}}
{\end{leftbar}\end{theo}}
\newtheorem{lem}[theo]{Lemma}
\newenvironment{lemma}[1][]
{\begin{lem}[#1]\begin{leftbar}}
{\end{leftbar}\end{lem}}
\newtheorem{prop}[theo]{Proposition}
\newenvironment{proposition}[1][]
{\begin{prop}[#1]\begin{leftbar}}
{\end{leftbar}\end{prop}}
\newtheorem{defi}[theo]{Definition}
\newenvironment{definition}[1][]
{\begin{defi}[#1]\begin{leftbar}}
{\end{leftbar}\end{defi}}
\newtheorem{remk}[theo]{Remark}
\newenvironment{remark}[1][]
{\begin{remk}[#1]\begin{leftbar}}
{\end{leftbar}\end{remk}}
\newtheorem{coro}[theo]{Corollary}
\newenvironment{corollary}[1][]
{\begin{coro}[#1]\begin{leftbar}}
{\end{leftbar}\end{coro}}
\newtheorem{conv}[theo]{Convention}
\newenvironment{convention}[1][]
{\begin{conv}[#1]\begin{leftbar}}
{\end{leftbar}\end{conv}}
\newtheorem{quest}[theo]{Question}
\newenvironment{question}[1][]
{\begin{quest}[#1]\begin{leftbar}}
{\end{leftbar}\end{quest}}
\newtheorem{warn}[theo]{Warning}
\newenvironment{warning}[1][]
{\begin{warn}[#1]\begin{leftbar}}
{\end{leftbar}\end{warn}}
\newtheorem{conj}[theo]{Conjecture}
\newenvironment{conjecture}[1][]
{\begin{conj}[#1]\begin{leftbar}}
{\end{leftbar}\end{conj}}
\newtheorem{exam}[theo]{Example}
\newenvironment{example}[1][]
{\begin{exam}[#1]\begin{leftbar}}
{\end{leftbar}\end{exam}}
\newtheorem{exmp}[exer]{Exercise}
\newenvironment{exercise}[1][]
{\begin{exmp}[#1]\begin{leftbar}}
{\end{leftbar}\end{exmp}}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\begin{small}}{\end{small}}
\iffalse
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{convention}[1][Convention]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{question}[1][Question]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\fi
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}
\newcommand\arxiv[1]{\href{http://www.arxiv.org/abs/#1}{\texttt{arXiv:#1}}}
\setlength\tablinesep{3pt}
\setlength\arraylinesep{3pt}
\setlength\extrarulesep{3pt}
\setlength\textheight{22.5cm}
\setlength\textwidth{14.8cm}
\newenvironment{verlong}{}{}
\newenvironment{vershort}{}{}
\newenvironment{noncompile}{}{}
\excludecomment{verlong}
\includecomment{vershort}
\excludecomment{noncompile}
\newcommand{\defn}[1]{{\color{darkred}\emph{#1}}}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\KK}{\mathbb{K}}
\newcommand{\set}[1]{\left\{ #1 \right\}}
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\tup}[1]{\left( #1 \right)}
\newcommand{\ive}[1]{\left[ #1 \right]}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\are}{\ar@{-}}
\newcommand{\arebi}[1][]{\ar@{<-}@/_/[#1] \ar@/^/[#1]}
\newcommand{\of}{\text{ of }}
\newtheoremstyle{plainsl}
{8pt plus 2pt minus 4pt}
{8pt plus 2pt minus 4pt}
{\slshape}
{0pt}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}
\theoremstyle{plainsl}
\ihead{Lecture 12, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 12: Enumeration}

\textbf{website:}
\texttt{\href{https://www.cip.ifi.lmu.de/~grinberg/t/23wd}{\texttt{https://www.cip.ifi.lmu.de/\symbol{126}%
grinberg/t/23wd}}}

\setcounter{section}{3}

\section{An introduction to enumeration}

Enumeration is a fancy word for counting -- i.e., answering questions of the
form \textquotedblleft how many things of a certain type are
there?\textquotedblright. Here are some examples of counting problems:

\begin{itemize}
\item How many ways are there to choose $3$ odd integers between $0$ and $20$,
if the order matters (i.e., we count the choice $1,3,5$ as different from the
choice $3,1,5$)? (The answer is $1000$.)

\item How many ways are there to choose $3$ odd integers between $0$ and $20$,
if the order does not matter? (The answer is $220$.)

\item How many ways are there to choose $3$ distinct odd integers between $0$
and $20$, if the order matters? (The answer is $720$.)

\item How many ways are there to choose $3$ distinct odd integers between $0$
and $20$, if the order does not matter? (The answer is $120$.)

\item How many prime factorizations does $200$ have (where we count different
orderings as distinct)? (The answer is $10$. This is a mix between a number
theory problem and a counting problem.)

\item How many ways are there to tile a $2\times15$-rectangle with dominos
(i.e., rectangles of size $1\times2$ or $2\times1$) ? (The answer is $987$.
For instance, the tiling
\[
\begin{tikzpicture}[scale=0.8]
\draw (0, 0) rectangle (1, 2);
\draw (1, 0) rectangle (3, 1);
\draw (1, 1) rectangle (3, 2);
\draw (3, 0) rectangle (4, 2);
\draw (4, 0) rectangle (5, 2);
\draw (5, 0) rectangle (7, 1);
\draw (5, 1) rectangle (7, 2);
\draw (7, 0) rectangle (9, 1);
\draw (7, 1) rectangle (9, 2);
\draw (9, 0) rectangle (10, 2);
\draw (10, 0) rectangle (12, 1);
\draw (10, 1) rectangle (12, 2);
\draw (12, 0) rectangle (13, 2);
\draw (13, 0) rectangle (14, 2);
\draw (14, 0) rectangle (15, 2);
\end{tikzpicture}
\]
is one of these $987$ ways.)

\item How many addends do you get when you expand the product \newline$\left(
a+b\right)  \left(  c+d+e\right)  \left(  f+g\right)  $ ? (The answer is $12$.)

\item How many different monomials do you get when you expand the product
$\left(  a-b\right)  \left(  a^{2}+ab+b^{2}\right)  $ ? (This one is more of
an algebra problem, but I wanted to list it because it is connected to
counting. The answer is $2$, because $\left(  a-b\right)  \left(
a^{2}+ab+b^{2}\right)  =a^{3}-b^{3}$.)

\item How many positive divisors does $24$ have? (We can actually list them:
$1,\ 2,\ 3,\ 4,\ 6,\ 8,\ 12,\ 24$. This one is again a mix of a counting
problem and a number theory problem.)
\end{itemize}

We will first solve a few basic counting problems informally, and then make
the underlying concepts rigorous.

\subsection{A refresher on sets}

In prerequisite courses, you have seen basic properties of sets, and basic
notations around sets, but let me quickly remind you of them.

Formally, the notion of a set is fundamental and cannot be defined.

Informally, a \textbf{set} is a collection of objects (which can be anything:
numbers, matrices, functions or other sets) that knows which objects it
contains and which objects it doesn't.

That is, if $S$ is a set and $p$ is any object, then $S$ can either contain
$p$ (in which case we write $p\in S$) or not contain $p$ (in which case we
write $p\notin S$). There is no such thing as \textquotedblleft containing $p$
twice\textquotedblright.

The objects that a set $S$ contains are called the \textbf{elements} of $S$;
they are said to \textbf{belong to }$S$ (or \textbf{lie in }$S$, or \textbf{be
contained in }$S$).

A set can be finite or infinite (i.e., contain finitely or infinitely many
elements). It can be empty (i.e., contain nothing) or nonempty (i.e., contain
at least one element).

An example of a set is the set of all odd integers. This is the set that
contains each odd integer and no other objects. Generally, \textquotedblleft
the set of X\textquotedblright\ means the set that contains X and nothing else.

When a set is finite, it can be written by listing all its elements. For
example, the set of all odd integers between $0$ and $10$ can be written as%
\[
\left\{  1,3,5,7,9\right\}  .
\]
The braces $\{$ and $\}$ around the list are there to signal that we mean the
set of all the elements, not the single elements themselves. These braces are
called \textquotedblleft set braces\textquotedblright, and are involved in
several different notations for sets.

Some more examples of finite sets are%
\begin{align*}
&  \left\{  1,2,3,4,5\right\}  ,\\
&  \left\{  1,2\right\}  ,\\
&  \left\{  1\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{this is the set that
only contains }1\right)  ,\\
&  \left\{  {}\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{the empty set, also
denoted }\varnothing\right)  ,\\
&  \left\{  1,2,\ldots,1000\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{you
understand what \textquotedblleft}\ldots\text{\textquotedblright\ means
here}\right)  .
\end{align*}


Some infinite sets can also be written in this form:%
\begin{align*}
&  \left\{  1,2,3,\ldots\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{this is
the set of all positive integers}\right)  ,\\
&  \left\{  0,1,2,\ldots\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{this is
the set of all nonnegative integers}\right)  ,\\
&  \left\{  4,5,6,\ldots\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{this is
the set of all integers }\geq4\right)  ,\\
&  \left\{  -1,-2,-3,\ldots\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{this is
the set of all negative integers}\right)  ,\\
&  \left\{  \ldots,-2,-1,0,1,2,\ldots\right\}  \ \ \ \ \ \ \ \ \ \ \left(
\text{this is the set of all integers}\right)  .
\end{align*}
Some others cannot. For example, how would you list all the real numbers? Or
even all the rational numbers?

Another way to describe a set is just by putting a description of its elements
in set braces. For example:%
\begin{align*}
&  \left\{  \text{all integers}\right\}  \ \ \ \ \ \ \ \ \ \ \left(
\text{this is the set of all integers}\right)  ,\\
&  \left\{  \text{all integers between }3\text{ and }9\text{ inclusive}%
\right\}  ,\\
&  \left\{  \text{all real numbers}\right\}  .
\end{align*}


Often, you want to define a set that contains all objects of a certain type
that satisfy a certain condition. For example, let's say you want the set of
all integers $x$ that satisfy $x^{2}<13$. There is a notation for this:%
\[
\left\{  x\text{ is an integer }\mid\text{ }x^{2}<13\right\}  .
\]
The vertical bar $\mid$ here should be read as \textquotedblleft such
that\textquotedblright\ (don't mistake it for a divisibility or absolute value
bracket). The part before this bar says what type of objects you are
considering (in our case, it is the integers $x$); the part after this bar
imposes a condition (or several) on these objects (in our case, the condition
is $x^{2}<13$). What you get is the set of all objects of the former type that
satisfy the latter condition. For instance,%
\begin{align*}
&  \left\{  x\text{ is an integer }\mid\text{ }x^{2}<13\right\} \\
&  =\left\{  \text{all integers whose square is smaller than }13\right\} \\
&  =\left\{  -3,-2,-1,0,1,2,3\right\}  .
\end{align*}
Some authors write a colon ($:$) instead of the vertical bar $\mid$. Thus,
they write $\left\{  x\text{ is an integer }\mid\text{ }x^{2}<13\right\}  $ as
$\left\{  x\text{ is an integer }:\text{ }x^{2}<13\right\}  $.

Some sets have standard names:%
\begin{align*}
\mathbb{Z}  &  =\left\{  \text{all integers}\right\}  =\left\{  \ldots
,-2,-1,0,1,2,\ldots\right\}  ;\\
\mathbb{N}  &  =\left\{  \text{all nonnegative integers}\right\}  =\left\{
0,1,2,\ldots\right\} \\
&  \ \ \ \ \ \ \ \ \ \ \left(  \text{beware that some authors use }%
\mathbb{N}\text{ for }\left\{  1,2,3,\ldots\right\}  \text{ instead}\right)
;\\
\mathbb{Q}  &  =\left\{  \text{all rational numbers}\right\}  ;\\
\mathbb{R}  &  =\left\{  \text{all real numbers}\right\}
\ \ \ \ \ \ \ \ \ \ \left(  \text{you barely need them in this course}\right)
;\\
\mathbb{C}  &  =\left\{  \text{all complex numbers}\right\}
\ \ \ \ \ \ \ \ \ \ \left(  \text{you don't need them in this course}\right)
;\\
\varnothing &  =\left\{  {}\right\}  \ \ \ \ \ \ \ \ \ \ \left(  \text{this is
the empty set}\right)  .
\end{align*}


Using these notations, we can rewrite
\[
\left\{  x\text{ is an integer }\mid\text{ }x^{2}<13\right\}
\ \ \ \ \ \ \ \ \ \ \text{as}\ \ \ \ \ \ \ \ \ \ \left\{  x\in\mathbb{Z}\text{
}\mid\text{ }x^{2}<13\right\}  .
\]


Yet another way of defining sets is when you let a variable range over a given
set and collect certain derived quantities. For example,%
\[
\left\{  x^{2}+2\ \mid\ x\in\left\{  1,3,5,7,9\right\}  \right\}
\]
means the set whose elements are the numbers $x^{2}+2$ for all $x\in\left\{
1,3,5,7,9\right\}  $. Thus,%
\begin{align*}
\left\{  x^{2}+2\ \mid\ x\in\left\{  1,3,5,7,9\right\}  \right\}   &
=\left\{  1^{2}+2,\ 3^{2}+2,\ 5^{2}+2,\ 7^{2}+2,\ 9^{2}+2\right\} \\
&  =\left\{  3,\ 11,\ 27,\ 51,\ 83\right\}  .
\end{align*}
In general, if $S$ is a given set, then the notation%
\[
\left\{  \text{an expression }\mid\ x\in S\right\}
\]
stands for the set whose elements are the values of the given expression for
all $x\in S$.

Some more examples of this:%
\begin{align*}
\left\{  \dfrac{x+1}{x}\ \mid\ x\in\left\{  1,2,3,4,5\right\}  \right\}   &
=\left\{  \dfrac{1+1}{1},\ \dfrac{2+1}{2},\ \dfrac{3+1}{3},\ \dfrac{4+1}%
{4},\ \dfrac{5+1}{5}\right\} \\
&  =\left\{  2,\ \dfrac{3}{2},\ \dfrac{4}{3},\ \dfrac{5}{4},\ \dfrac{6}%
{5}\right\}
\end{align*}
and%
\begin{align*}
\left\{  x^{2}\%5\ \mid\ x\in\mathbb{N}\right\}   &  =\left\{  0^{2}%
\%5,\ 1^{2}\%5,\ 2^{2}\%5,\ 3^{2}\%5,\ 4^{2}\%5,\ 5^{2}\%5,\ 6^{2}%
\%5,\ \ldots\right\} \\
&  =\left\{
0,\ 1,\ 4,\ 4,\ 1,\ 0,\ 1,\ 4,\ 4,\ 1,\ 0,\ 1,\ 4,\ 4,\ 1,\ 0,\ \ldots
\right\}  .
\end{align*}
Note that the remainders $x^{2}\%5$ repeat every five steps, because every
integer $x$ satisfies $\left(  x+5\right)  ^{2}\equiv x^{2}\operatorname{mod}%
5$ and thus $\left(  x+5\right)  ^{2}\%5=x^{2}\%5$ (by Proposition 3.3.15 in
Lecture 9).

Let me stress once again that a set cannot contain an element more than once.
Also, sets do not come with an ordering of their elements. Thus,%
\[
\left\{  1,2\right\}  =\left\{  2,1\right\}  =\left\{  2,1,1\right\}
=\left\{  1,2,1,2,1\right\}  ,
\]
since each of these four sets contains $1$ and $2$ and nothing else. If $S$ is
a set and $p$ is an object, then $S$ either contains $p$ or does not contain
$p$; it cannot \textquotedblleft contain $p$ twice\textquotedblright, nor can
it contain an element \textquotedblleft before\textquotedblright\ another. So
when you write $\left\{  2,1,1\right\}  $, you aren't making a set that
contains $1$ twice; you are just saying twice that it contains $1$, and this
is equivalent to saying the same thing once. Likewise, the sets $\left\{
1,2\right\}  $ and $\left\{  2,1\right\}  $ do not \textquotedblleft contain
$1$ and $2$ in different orders\textquotedblright; you are just saying in
different orders that they contain $1$ and $2$, but the meaning is the same.
So%
\begin{align*}
\left\{  x^{2}\%5\ \mid\ x\in\mathbb{N}\right\}   &  =\left\{
0,\ 1,\ 4,\ 4,\ 1,\ 0,\ 1,\ 4,\ 4,\ 1,\ 0,\ 1,\ 4,\ 4,\ 1,\ 0,\ \ldots\right\}
\\
&  =\left\{  0,\ 1,\ 4\right\}  .
\end{align*}
This is a finite set, even though $\mathbb{N}$ is infinite!

\bigskip

Sets can be compared and combined in several ways:

\begin{definition}
Let $A$ and $B$ be two sets.

\textbf{(a)} We say that $A$ is a \textbf{subset} of $B$ (and we write
$A\subseteq B$) if every element of $A$ is an element of $B$.

\textbf{(b)} We say that $A$ is a \textbf{superset} of $B$ (and we write
$A\supseteq B$) if every element of $B$ is an element of $A$. This is
tantamount to saying $B\subseteq A$.

\textbf{(c)} We say that $A=B$ if the sets $A$ and $B$ contain the same
elements. This is tantamount to saying that both $A\subseteq B$ and
$A\supseteq B$ hold.

\textbf{(d)} We define the \textbf{union} of $A$ and $B$ to be the set%
\begin{align*}
A\cup B:=  &  \left\{  \text{all elements that are contained in }A\text{ or
}B\right\} \\
=  &  \left\{  x\ \mid\ x\in A\text{ or }x\in B\right\}  .
\end{align*}
(The \textquotedblleft or\textquotedblright\ is non-exclusive, as usual. So
this includes the elements that are contained in both $A$ and $B$.)

\textbf{(e)} We define the \textbf{intersection} of $A$ and $B$ to be the set%
\begin{align*}
A\cap B:=  &  \left\{  \text{all elements that are contained in both }A\text{
and }B\right\} \\
=  &  \left\{  x\ \mid\ x\in A\text{ and }x\in B\right\}  .
\end{align*}


\textbf{(f)} We define the \textbf{set difference} of $A$ and $B$ to be the
set%
\begin{align*}
A\setminus B:=  &  \left\{  \text{all elements that are contained in }A\text{
but not in }B\right\} \\
=  &  \left\{  x\ \mid\ x\in A\text{ and }x\notin B\right\}  .
\end{align*}
This is also denoted by $A-B$ by certain authors.

\textbf{(g)} We say that $A$ and $B$ are \textbf{disjoint} if $A\cap
B=\varnothing$ (that is, $A$ and $B$ have no element in common).
\end{definition}

For example,%
\begin{align*}
\left\{  1,3,5\right\}   &  \subseteq\left\{  1,2,3,4,5\right\}  ,\\
\left\{  1,2,3,4,5\right\}   &  \supseteq\left\{  1,3,5\right\}  ,\\
\text{we \textbf{don't} have }\left\{  5,6,7\right\}   &  \subseteq\left\{
1,2,3,4,5\right\}  ,\\
\left\{  1,2,3\right\}   &  =\left\{  3,2,1\right\}  ,\\
\left\{  1,3,5\right\}  \cup\left\{  3,6\right\}   &  =\left\{
1,3,5,3,6\right\}  =\left\{  1,3,5,6\right\}  ,\\
\left\{  1,3,5\right\}  \cap\left\{  3,6\right\}   &  =\left\{  3\right\}  ,\\
\left\{  1,2,4\right\}  \cap\left\{  3,5\right\}   &  =\varnothing
\ \ \ \ \ \ \ \ \ \ \left(  \text{so that the sets }\left\{  1,2,4\right\}
\text{ and }\left\{  3,5\right\}  \text{ are disjoint}\right)  ,\\
\left\{  1,3,5\right\}  \setminus\left\{  3,6\right\}   &  =\left\{
1,5\right\}  ,\\
\mathbb{Z}\setminus\mathbb{N}  &  =\left\{  -1,-2,-3,\ldots\right\}  =\left\{
\text{all negative integers}\right\}  .
\end{align*}


\begin{definition}
Several sets $A_{1},A_{2},\ldots,A_{k}$ are said to be \textbf{disjoint} if
any two of them (not counting a set and itself) are disjoint, i.e., if we have
$A_{i}\cap A_{j}=\varnothing$ for all $i<j$.
\end{definition}

For example, the three sets $\left\{  1,2\right\}  $, $\left\{  5\right\}  $
and $\left\{  0,7\right\}  $ are disjoint.

\subsection{Counting, informally}

Now, let us see how the elements of a set can be counted. Formally speaking,
we will define \textquotedblleft counting\textquotedblright\ later, so we will
play around with not-quite-rigorous concepts for now. As long as we are
working with finite sets, your intuitive understanding of \textquotedblleft
counting\textquotedblright\ should not mislead you.

For example, the set of all odd integers between $0$ and $10$ has $5$ elements
($1,\ 3,\ 5,\ 7,\ 9$), and this doesn't change if you write it redundantly as
$\left\{  1,3,5,5,5,5,7,9\right\}  $. In other words, there are $5$ odd
integers between $0$ and $10$.

More generally, I claim:

\begin{proposition}
\label{prop.count.odd-0-n}Let $n\in\mathbb{N}$. Then, there are exactly
$\left(  n+1\right)  //2=\left\lfloor \dfrac{n+1}{2}\right\rfloor $ odd
integers between $0$ and $n$ (inclusive).
\end{proposition}

\begin{proof}
[Informal proof.]The equality $\left(  n+1\right)  //2=\left\lfloor
\dfrac{n+1}{2}\right\rfloor $ follows from Proposition 3.3.13 in Lecture 8. It
remains to show that there are exactly $\left\lfloor \dfrac{n+1}%
{2}\right\rfloor $ odd integers between $0$ and $n$. (We shall always
understand the word \textquotedblleft between\textquotedblright\ to be
inclusive, so that $n$ itself is counted if $n$ is odd.)

We prove this by induction on $n$:

\textit{Base case:} For $n=0$, the claim is true, because there are
$0=\left\lfloor \dfrac{0+1}{2}\right\rfloor $ odd integers between $0$ and $0$.

\textit{Induction step:} Let $n$ be a positive integer. Assume (as the
induction hypothesis) that the claim is true for $n-1$. That is, assume that
there are exactly $\left\lfloor \dfrac{n}{2}\right\rfloor $ odd integers
between $0$ and $n-1$. We must show that the claim also holds for $n$, i.e.,
that there are exactly $\left\lfloor \dfrac{n+1}{2}\right\rfloor $ odd
integers between $0$ and $n$.

Let me introduce a shorthand: The symbol \textquotedblleft\#\textquotedblright%
\ shall mean \textquotedblleft number\textquotedblright. Thus, our induction
hypothesis says%
\begin{equation}
\left(  \text{\# of odd integers between }0\text{ and }n-1\right)
=\left\lfloor \dfrac{n}{2}\right\rfloor , \label{pf.prop.count.odd-0-n.IH}%
\end{equation}
and our goal is to prove that%
\[
\left(  \text{\# of odd integers between }0\text{ and }n\right)  =\left\lfloor
\dfrac{n+1}{2}\right\rfloor .
\]


We are in one of the following two cases:

\textit{Case 1:} The number $n$ is even.

\textit{Case 2:} The number $n$ is odd.

Let us consider Case 1 first. In this case, $n$ is even. Thus, $n$ is not odd.
Therefore, the odd integers between $0$ and $n$ are precisely the odd integers
between $0$ and $n-1$ (since the extra integer $n$ does not qualify as odd).
Hence,%
\begin{align}
&  \left(  \text{\# of odd integers between }0\text{ and }n\right) \nonumber\\
&  =\left(  \text{\# of odd integers between }0\text{ and }n-1\right)
\nonumber\\
&  =\left\lfloor \dfrac{n}{2}\right\rfloor \ \ \ \ \ \ \ \ \ \ \left(
\text{by (\ref{pf.prop.count.odd-0-n.IH})}\right)  .
\label{pf.prop.count.odd-0-n.c1.3}%
\end{align}


However, $n+1$ is odd (since $n$ is even), and thus $2\nmid n+1$. Therefore,
Corollary 3.3.17 \textbf{(b)} in Lecture 9 (applied to $2$ and $n+1$ instead
of $d$ and $n$) yields $\left\lfloor \dfrac{n+1}{2}\right\rfloor =\left\lfloor
\dfrac{\left(  n+1\right)  -1}{2}\right\rfloor =\left\lfloor \dfrac{n}%
{2}\right\rfloor $. Comparing this with (\ref{pf.prop.count.odd-0-n.c1.3}), we
find%
\[
\left(  \text{\# of odd integers between }0\text{ and }n\right)  =\left\lfloor
\dfrac{n+1}{2}\right\rfloor .
\]
Thus, we have achieved our goal in Case 1.

Let us now consider Case 2. In this case, $n$ is odd. Thus, the odd integers
between $0$ and $n$ are precisely the odd integers between $0$ and $n-1$ along
with the new odd integer $n$. Hence,%
\begin{align}
&  \left(  \text{\# of odd integers between }0\text{ and }n\right) \nonumber\\
&  =\left(  \text{\# of odd integers between }0\text{ and }n-1\right)
+1\nonumber\\
&  =\left\lfloor \dfrac{n}{2}\right\rfloor +1\ \ \ \ \ \ \ \ \ \ \left(
\text{by (\ref{pf.prop.count.odd-0-n.IH})}\right)  .
\label{pf.prop.count.odd-0-n.c2.3}%
\end{align}


However, $n+1$ is even (since $n$ is odd), and thus $2\mid n+1$. Therefore,
Corollary 3.3.17 \textbf{(a)} in Lecture 9 (applied to $2$ and $n+1$ instead
of $d$ and $n$) yields $\left\lfloor \dfrac{n+1}{2}\right\rfloor =\left\lfloor
\dfrac{\left(  n+1\right)  -1}{2}\right\rfloor +1=\left\lfloor \dfrac{n}%
{2}\right\rfloor +1$. Comparing this with (\ref{pf.prop.count.odd-0-n.c2.3}),
we find%
\[
\left(  \text{\# of odd integers between }0\text{ and }n\right)  =\left\lfloor
\dfrac{n+1}{2}\right\rfloor .
\]
Thus, we have achieved our goal in Case 2.

So the goal has been achieved in either case, and the induction step is
complete. This proves Proposition \ref{prop.count.odd-0-n}.
\end{proof}

\textbf{Note:} We called the above proof \textquotedblleft
informal\textquotedblright\ because we still don't have a rigorous definition
of the size of a set (i.e., of what \textquotedblleft the number
of\textquotedblright\ means). But we will soon see such a definition. Once we
have learnt this definition and its basic properties, the above proof will
become a formal proof with trivial changes.

\bigskip

Incidentally, let me state the formula for the number of integers (not just
odd integers) in a given interval:

\begin{proposition}
\label{prop.count.fencepost}Let $a,b\in\mathbb{Z}$ be such that $a\leq b+1$.

Then, there are exactly $b-a+1$ numbers in the set $\left\{
a,\ a+1,\ a+2,\ \ldots,\ b\right\}  $. In other words, there are exactly
$b-a+1$ integers between $a$ and $b$ (inclusive).
\end{proposition}

\begin{proof}
[Informal proof.]This is intuitively obvious and can be rigorously proved by
induction on $b$.
\end{proof}

The hard part about Proposition \ref{prop.count.fencepost} is not the proof,
but rather remembering the \textquotedblleft$+1$\textquotedblright! If your
intuition comes from calculus, you think of the interval $\left[  a,b\right]
$ as having length $b-a$ (if $b\geq a$). But since we are doing discrete
mathematics, we are computing not the geometric length of this interval, but
rather the number of integers on this interval, including both endpoints; and
this number is $1$ larger than the length. (For example, if $a=b$, then the
geometric interval $\left[  a,b\right]  $ has zero length, but it contains one
integer, namely $a$.)

\bigskip

It is also worth saying that if two integers $a$ and $b$ satisfy $a\leq b-1$,
then there are exactly $b-a-1$ integers between $a$ and $b$ exclusive (meaning
that we count neither $a$ nor $b$).

\bigskip

\begin{convention}
We agree to use the symbol \textquotedblleft\#\textquotedblright\ for
\textquotedblleft number\textquotedblright.
\end{convention}

\subsection{Counting subsets}

\subsubsection{Counting them all}

Now, let us count something less trivial than numbers.

How many subsets does the set $\left\{  1,2,3\right\}  $ have? These subsets
are%
\begin{align*}
&  \left\{  {}\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  1\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  2\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{
3\right\}  ,\\
&  \left\{  1,2\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  1,3\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  2,3\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{
1,2,3\right\}  .
\end{align*}
(Yes, every set $A$ satisfies $A\subseteq A$ and $\left\{  {}\right\}
\subseteq A$.) Thus, there are $8$ subsets of $\left\{  1,2,3\right\}  $ in total.

Likewise,

\begin{itemize}
\item there are $4$ subsets of $\left\{  1,2\right\}  $, namely $\left\{
{}\right\}  ,\ \left\{  1\right\}  ,\ \left\{  2\right\}  ,\ \left\{
1,2\right\}  $.

\item there are $2$ subsets of $\left\{  1\right\}  $, namely $\left\{
{}\right\}  $ and $\left\{  1\right\}  $.

\item there is $1$ subset of $\left\{  {}\right\}  $, namely $\left\{
{}\right\}  $.

\item there are $16$ subsets of $\left\{  1,2,3,4\right\}  $.
\end{itemize}

The pattern here is hard to miss:

\begin{theorem}
\label{thm.count.subsets.all.n}Let $n\in\mathbb{N}$. Then,%
\[
\left(  \text{\# of subsets of }\left\{  1,2,\ldots,n\right\}  \right)
=2^{n}.
\]

\end{theorem}

\begin{proof}
[Informal proof.]We induct on $n$.

The \textit{base case} ($n=0$) is easy: The set $\left\{  1,2,\ldots
,0\right\}  $ is empty, and thus its only subset is $\left\{  {}\right\}  $
itself; hence, the \# of subsets of $\left\{  1,2,\ldots,0\right\}  $ is
$1=2^{0}$.

\textit{Induction step:} We proceed from $n-1$ to $n$. Thus, let $n$ be a
positive integer. We assume (as the induction hypothesis) that Theorem
\ref{thm.count.subsets.all.n} holds for $n-1$ instead of $n$, and we set out
to prove that it holds for $n$.

So our induction hypothesis says that%
\[
\left(  \text{\# of subsets of }\left\{  1,2,\ldots,n-1\right\}  \right)
=2^{n-1}.
\]
Our goal is to prove that%
\[
\left(  \text{\# of subsets of }\left\{  1,2,\ldots,n\right\}  \right)
=2^{n}.
\]


We define

\begin{itemize}
\item a \textbf{red set} to be a subset of $\left\{  1,2,\ldots,n\right\}  $
that contains $n$;

\item a \textbf{green set} to be a subset of $\left\{  1,2,\ldots,n\right\}  $
that does not contain $n$.
\end{itemize}

For example, if $n=3$, then the red sets are%
\[
\left\{  3\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  1,3\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  2,3\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{
1,2,3\right\}  ,
\]
whereas the green sets are%
\[
\left\{  {}\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  1\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  2\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{
1,2\right\}  .
\]


Each subset of $\left\{  1,2,\ldots,n\right\}  $ is either red or green, but
not both. Hence,%
\[
\left(  \text{\# of subsets of }\left\{  1,2,\ldots,n\right\}  \right)
=\left(  \text{\# of red sets}\right)  +\left(  \text{\# of green
sets}\right)  .
\]
(This is an instance of a basic counting principle: If some objects are
classified into two types, then we can count these objects by counting the
objects of each type and adding the results. Later we will state this as a
rigorous theorem, called the \textbf{sum rule for two sets}.)

Thus it remains to count the red sets and the green sets separately.

The green sets are easy: They are just the subsets of $\left\{  1,2,\ldots
,n-1\right\}  $. Hence,%
\[
\left(  \text{\# of green sets}\right)  =\left(  \text{\# of subsets of
}\left\{  1,2,\ldots,n-1\right\}  \right)  =2^{n-1}%
\]
(by the induction hypothesis).

Counting the red sets is trickier, but we can reduce the problem to counting
the green sets: Indeed, the red sets are just the green sets with the element
$n$ inserted into them. To be more precise: Each green set can be turned into
a red set by inserting $n$ into it\footnote{For example, if $n=3$, then the
green set $\left\{  2\right\}  $ becomes $\left\{  2,3\right\}  $ in this
way.}. Conversely, each red set can be turned into a green set by removing the
element $n$ from it. These two operations are mutually inverse, and thus set
up a one-to-one correspondence between the green sets and the red
sets.\footnote{For instance, for $n=3$, it looks like this:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|}\hline
green set & $\left\{  {}\right\}  $ & $\left\{  1\right\}  $ & $\left\{
2\right\}  $ & $\left\{  1,2\right\}  $\\\hline
& $\updownarrow$ & $\updownarrow$ & $\updownarrow$ & $\updownarrow$\\\hline
red set & $\left\{  3\right\}  $ & $\left\{  1,3\right\}  $ & $\left\{
2,3\right\}  $ & $\left\{  1,2,3\right\}  $\\\hline
\end{tabular}
\ \ .
\]
} This reveals that the \# of red sets is the \# of green sets. Thus,%
\[
\left(  \text{\# of red sets}\right)  =\left(  \text{\# of green sets}\right)
=2^{n-1}.
\]


Combining what we have shown, we now obtain
\begin{align*}
\left(  \text{\# of subsets of }\left\{  1,2,\ldots,n\right\}  \right)   &
=\underbrace{\left(  \text{\# of red sets}\right)  }_{=2^{n-1}}%
+\underbrace{\left(  \text{\# of green sets}\right)  }_{=2^{n-1}}\\
&  =2^{n-1}+2^{n-1}=2\cdot2^{n-1}=2^{n}.
\end{align*}
This is precisely what we needed to prove. This completes the induction step,
and thus Theorem \ref{thm.count.subsets.all.n} is proved.
\end{proof}


\end{document}