\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=Thursday, February 29, 2024 22:43:48}
%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 13, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 13: 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}

\setcounter{subsection}{2}

\subsection{Counting subsets (cont'd)}

\subsubsection{Counting them all (cont'd)}

Last time, we proved:\footnote{Recall that the symbol \textquotedblleft%
\#\textquotedblright\ means \textquotedblleft number\textquotedblright.}

\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}

More generally, we have the following:

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

\end{theorem}

\begin{proof}
[Informal proof.]This follows from Theorem \ref{thm.count.subsets.all.n},
since we can rename the $n$ elements of $S$ as $1,2,\ldots,n$.
\end{proof}

For example,
\[
\left(  \text{\# of subsets of }\left\{  \text{\textquotedblleft
cat\textquotedblright, \textquotedblleft dog\textquotedblright,
\textquotedblleft bat\textquotedblright}\right\}  \right)  =2^{3}.
\]


\subsubsection{Counting the subsets of a given size}

Let us now refine our question: Instead of counting all subsets of $\left\{
1,2,\ldots,n\right\}  $, we shall only count the ones that have a given size
$k$. Here, the \textbf{size} of a set means the \# of its elements, i.e., how
many distinct elements it has. (For example, the set $\left\{
1,4,1,15\right\}  $ has size $3$, nevermind that I needlessly listed one of
its elements twice.) A set of size $k$ is also known as a $k$\textbf{-element
set}. (Soon we will define these concepts rigorously.)

For instance, $\left\{  1,2,3,4\right\}  $ is a $4$-element set. How many
$2$-element subsets does it have? It has six:%
\[
\left\{  1,2\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  1,3\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  1,4\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{
2,3\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  2,4\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  3,4\right\}  .
\]


More generally, the answer to the question \textquotedblleft how many
$k$-element subsets does a given $n$-element set have\textquotedblright\ turns
out to be the binomial coefficient $\dbinom{n}{k}$. Let us state this as a
theorem and give an informal proof (which will easily become rigorous once we
have the basic concepts of counting pinned down):\footnote{This theorem is
exactly Theorem 2.5.12 in Lecture 6.}

\begin{theorem}
\label{thm.count.subsets.size.S}Let $n\in\mathbb{N}$, and let $k$ be any
number (not necessarily an integer). Let $S$ be an $n$-element set. Then,%
\[
\left(  \text{\# of }k\text{-element subsets of }S\right)  =\dbinom{n}{k}.
\]

\end{theorem}

\begin{proof}
[Informal proof.]We induct on $n$ (without fixing $k$). That is, we use
induction on $n$ to prove the statement%
\[
P\left(  n\right)  :=\left(
\begin{array}
[c]{c}%
\text{\textquotedblleft for any number }k\text{ and any }n\text{-element set
}S,\\
\text{we have }\left(  \text{\# of }k\text{-element subsets of }S\right)
=\dbinom{n}{k}\text{\textquotedblright}%
\end{array}
\right)
\]
for each $n\in\mathbb{N}$.

\textit{Base case:} Let $k$ be any number. The only $0$-element set is
$\varnothing$, and its only subset is $\varnothing$. Thus, a $0$-element set
$S$ necessarily has one $0$-element subset ($\varnothing$) and no other
subsets. Hence, it satisfies%
\[
\left(  \text{\# of }k\text{-element subsets of }S\right)  =%
\begin{cases}
1, & \text{if }k=0;\\
0, & \text{else.}%
\end{cases}
\]
However, we also have%
\[
\dbinom{0}{k}=%
\begin{cases}
1, & \text{if }k=0;\\
0, & \text{else}%
\end{cases}
\]
(this follows easily from the definition of binomial coefficients). By
comparing these two equalities, we see that any $0$-element set $S$ satisfies
\[
\left(  \text{\# of }k\text{-element subsets of }S\right)  =\dbinom{0}{k}.
\]
In other words, $P\left(  0\right)  $ holds.

\textit{Induction step:} Let $n$ be a positive integer. Assume (as the
induction hypothesis) that $P\left(  n-1\right)  $ holds. We must prove that
$P\left(  n\right)  $ holds.

So we consider any number $k$ and any $n$-element set $S$. We must prove that%
\[
\left(  \text{\# of }k\text{-element subsets of }S\right)  =\dbinom{n}{k}.
\]


We rename the $n$ elements of $S$ as $1,2,\ldots,n$, so we must prove that%
\[
\left(  \text{\# of }k\text{-element subsets of }\left\{  1,2,\ldots
,n\right\}  \right)  =\dbinom{n}{k}.
\]


To prove this, we define

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

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

For instance, for $n=4$ and $k=2$, the red sets are%
\[
\left\{  1,4\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  2,4\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  3,4\right\}  ,
\]
while the green sets are%
\[
\left\{  1,2\right\}  ,\ \ \ \ \ \ \ \ \ \ \left\{  1,3\right\}
,\ \ \ \ \ \ \ \ \ \ \left\{  2,3\right\}  .
\]


Each $k$-element subset of $\left\{  1,2,\ldots,n\right\}  $ is either red or
green (but not both). Hence,%
\begin{align}
&  \left(  \text{\# of }k\text{-element subsets of }\left\{  1,2,\ldots
,n\right\}  \right) \nonumber\\
&  =\left(  \text{\# of red sets}\right)  +\left(  \text{\# of green
sets}\right)  . \label{pf.thm.count.subsets.size.S.sum}%
\end{align}


The green sets are just the $k$-element subsets of $\left\{  1,2,\ldots
,n-1\right\}  $. Thus,%
\begin{align*}
\left(  \text{\# of green sets}\right)   &  =\left(  \text{\# of
}k\text{-element subsets of }\left\{  1,2,\ldots,n-1\right\}  \right) \\
&  =\dbinom{n-1}{k}%
\end{align*}
(by the statement $P\left(  n-1\right)  $, which we have assumed to hold).

Now, let's try to count the red sets.

If $T$ is a red set, then $T\setminus\left\{  n\right\}  $ is a $\left(
k-1\right)  $-element subset of $\left\{  1,2,\ldots,n-1\right\}  $.

Let us refer to the $\left(  k-1\right)  $-element subsets of $\left\{
1,2,\ldots,n-1\right\}  $ as \textbf{blue sets}. Thus, if $T$ is a red set,
then $T\setminus\left\{  n\right\}  $ is a blue set. Conversely, if $U$ is a
blue set, then $U\cup\left\{  n\right\}  $ is a red set. This sets up a
one-to-one correspondence between the red sets and the blue sets: We turn red
sets into blue sets by removing the element $n$, and conversely we turn blue
sets red by inserting the element $n$ into the set.\footnote{For instance, for
$n=4$ and $k=2$, this correspondence looks like this:%
\[%
\begin{tabular}
[c]{|c||c|c|c|}\hline
red set & $\left\{  1,4\right\}  $ & $\left\{  2,4\right\}  $ & $\left\{
3,4\right\}  $\\\hline
& $\updownarrow$ & $\updownarrow$ & $\updownarrow$\\\hline
blue set & $\left\{  1\right\}  $ & $\left\{  2\right\}  $ & $\left\{
3\right\}  $\\\hline
\end{tabular}
\ \ \ .
\]
} Hence,%
\begin{align*}
\left(  \text{\# of red sets}\right)   &  =\left(  \text{\# of blue
sets}\right) \\
&  =\left(  \text{\# of }\left(  k-1\right)  \text{-element subsets of
}\left\{  1,2,\ldots,n-1\right\}  \right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(  \text{since this is how the
blue sets were defined}\right) \\
&  =\dbinom{n-1}{k-1}%
\end{align*}
(again by the statement $P\left(  n-1\right)  $, but now applied to $k-1$
instead of $k$). Note that we deliberately did not fix $k$ in our induction,
so that we were now able to apply $P\left(  n-1\right)  $ to $k-1$ instead of
$k$.

Now, (\ref{pf.thm.count.subsets.size.S.sum}) becomes%
\begin{align*}
\left(  \text{\# of }k\text{-element subsets of }\left\{  1,2,\ldots
,n\right\}  \right)   &  =\underbrace{\left(  \text{\# of red sets}\right)
}_{=\dbinom{n-1}{k-1}}+\underbrace{\left(  \text{\# of green sets}\right)
}_{=\dbinom{n-1}{k}}\\
&  =\dbinom{n-1}{k-1}+\dbinom{n-1}{k}=\dbinom{n}{k}%
\end{align*}
by Pascal's recurrence (Theorem 2.5.3 in Lecture 6). But this is precisely the
equality that we have to prove. This completes the induction step, and thus
Theorem \ref{thm.count.subsets.size.S} is proved.
\end{proof}

The above proof can also be used to write an algorithm that lists all the
$k$-element subsets of $\left\{  1,2,\ldots,n\right\}  $. This algorithm is
recursive and proceeds as follows:

\begin{itemize}
\item If $n=0$, then:

\begin{itemize}
\item if $k=0$, then list $\varnothing$ (i.e., the resulting list will consist
only of $\varnothing$).

\item otherwise, list nothing.
\end{itemize}

\item Otherwise,

\begin{itemize}
\item list the red sets (by listing all the $\left(  k-1\right)  $-element
subsets of $\left\{  1,2,\ldots,n-1\right\}  $, and inserting $n$ into each of them);

\item list the green sets (i.e., the $k$-element subsets of $\left\{
1,2,\ldots,n-1\right\}  $);

\item combine these two lists.
\end{itemize}
\end{itemize}

In Python, this algorithm (or one possible implementation of it) looks as
follows\footnote{Note that lists are enclosed within brackets in Python: e.g.,
a list that we call $\left(  a,b,c\right)  $ would be written \texttt{[a,b,c]}
in Python. Also, Python's notation \texttt{set([a,b,c])} corresponds to our
$\left\{  a,b,c\right\}  $.}:\medskip\Needspace{12pc}

\texttt{\qquad def subsets(n, k):}

\texttt{\qquad\qquad\# listing all subsets of \{1, 2, ..., n\} that have size
k.}

\texttt{\qquad\qquad if n == 0:}

\texttt{\qquad\qquad\qquad if k == 0:}

\texttt{\qquad\qquad\qquad\qquad return [set([])] \# set([]) is the empty set}

\texttt{\qquad\qquad\qquad return [] \# empty list}

\texttt{\qquad\qquad\# Now, the case when n is not 0:}

\texttt{\qquad\qquad green\_sets = subsets(n-1, k)}

\texttt{\qquad\qquad\# This is the list of all green sets.}

\texttt{\qquad\qquad red\_sets = [U.union([n]) for U in subsets(n-1, k-1)]}

\texttt{\qquad\qquad\# This is the list of all red sets. We construct it by}

\texttt{\qquad\qquad\# taking all the (k-1)-element subsets of \{1, 2, ...,
n-1\}}

\texttt{\qquad\qquad\# (i.e., the blue sets), and inserting n into each of}

\texttt{\qquad\qquad\# them.}

\texttt{\qquad\qquad return red\_sets + green\_sets}

\texttt{\qquad\qquad\# In Python, the plus sign can be used to combine two
lists. }\medskip

With this code, \texttt{subsets(4, 2)} yields

\texttt{\qquad\lbrack\{3, 4\}, \{2, 4\}, \{1, 4\}, \{2, 3\}, \{1, 3\}, \{1,
2\}]}

\noindent as an output, and this is indeed a list of all $2$-element subsets
of $\left\{  1,2,\ldots,4\right\}  =\left\{  1,2,3,4\right\}  $. \medskip

Theorem \ref{thm.count.subsets.size.S} is often called the
\textbf{combinatorial interpretation of binomial coefficients}, since it
reveals that the binomial coefficients $\dbinom{n}{k}$ (at least for
$n\in\mathbb{N}$) have a combinatorial meaning (viz., counting $k$-element
subsets of a given $n$-element set). However, it is just one of many such
interpretations, and we will see four others as we progress through this chapter!

\subsection{Tuples (aka lists)}

\subsubsection{Definition and disambiguation}

Speaking of lists: What is a finite list? Here is a somewhat awkward definition:

\begin{definition}
\label{def.count.list}A \textbf{finite list} (aka \textbf{tuple}) is a list
consisting of finitely many objects. The objects appear in this list in a
specified order, and they don't have to be distinct.

A finite list is delimited using parentheses: i.e., the list that contains the
objects $a_{1},a_{2},\ldots,a_{n}$ in this order is denoted by $\left(
a_{1},a_{2},\ldots,a_{n}\right)  $.

\textquotedblleft Specified order\textquotedblright\ means that the list has a
well-defined first entry, a well-defined second entry, and so on. Thus, two
lists $\left(  a_{1},a_{2},\ldots,a_{n}\right)  $ and $\left(  b_{1}%
,b_{2},\ldots,b_{m}\right)  $ are considered equal if and only if

\begin{itemize}
\item we have $n=m$, and

\item we have $a_{i}=b_{i}$ for each $i\in\left\{  1,2,\ldots,n\right\}  $.
\end{itemize}
\end{definition}

For example:

\begin{itemize}
\item The lists $\left(  1,2\right)  $ and $\left(  2,1\right)  $ are not
equal (although the sets $\left\{  1,2\right\}  $ and $\left\{  2,1\right\}  $
are equal).

\item The lists $\left(  1,2\right)  $ and $\left(  1,1,2\right)  $ are not
equal (although the sets $\left\{  1,2\right\}  $ and $\left\{  1,1,2\right\}
$ are equal).

\item The lists $\left(  1,1,2\right)  $ and $\left(  1,2,2\right)  $ are not
equal (although the sets $\left\{  1,1,2\right\}  $ and $\left\{
1,2,2\right\}  $ are equal).
\end{itemize}

\begin{definition}
\textbf{(a)} The \textbf{length} of a list $\left(  a_{1},a_{2},\ldots
,a_{n}\right)  $ is defined to be the number $n$.

\textbf{(b)} A list of length $2$ is called a \textbf{pair} (or an
\textbf{ordered pair}).

\textbf{(c)} A list of length $3$ is called a \textbf{triple}.

\textbf{(d)} A list of length $4$ is called a \textbf{quadruple}.

\textbf{(e)} A list of length $n$ is called an $n$\textbf{-tuple}.
\end{definition}

For example, $\left(  1,3,2,2\right)  $ is a list of length $4$ (although it
has only $3$ \textbf{distinct} entries), i.e., a quadruple or a $4$-tuple. For
another example, $\left(  5,8\right)  $ is a pair, i.e., a $2$-tuple.

Note that there is exactly one list of length $0$: the empty list $\left(
{}\right)  $, which contains nothing.

Lists of length $1$ consist of just a single entry. For example, $\left(
3\right)  $ is a list containing only the entry $3$.

\subsubsection{Counting pairs}

Now, let us count some pairs:

\begin{itemize}
\item How many pairs $\left(  a,b\right)  $ are there with $a,b\in\left\{
1,2,3\right\}  $ ? There are nine:%
\begin{align*}
&  \left(  1,1\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  1,2\right)
,\ \ \ \ \ \ \ \ \ \ \left(  1,3\right)  ,\\
&  \left(  2,1\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  2,2\right)
,\ \ \ \ \ \ \ \ \ \ \left(  2,3\right)  ,\\
&  \left(  3,1\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  3,2\right)
,\ \ \ \ \ \ \ \ \ \ \left(  3,3\right)  .
\end{align*}
The fact that there are nine of them is not surprising given how I've laid
them out: They are forming a table with $3$ rows and $3$ columns, where the
row determines the first entry of the pair\footnote{i.e.:
\par
\begin{itemize}
\item The first row contains the pairs that begin with $1$.
\par
\item The second row contains the pairs that begin with $2$.
\par
\item The third row contains the pairs that begin with $3$.
\end{itemize}
} and the column determines the second entry. Thus, their total number is
$3\cdot3=9$.

\item How many pairs $\left(  a,b\right)  $ are there with $a,b\in\left\{
1,2,3\right\}  $ and $a<b$ ? There are three:%
\[
\left(  1,2\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  1,3\right)
,\ \ \ \ \ \ \ \ \ \ \left(  2,3\right)  .
\]


\item How many pairs $\left(  a,b\right)  $ are there with $a,b\in\left\{
1,2,3\right\}  $ and $a=b$ ? Again, three:%
\[
\left(  1,1\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  2,2\right)
,\ \ \ \ \ \ \ \ \ \ \left(  3,3\right)  .
\]


\item How many pairs $\left(  a,b\right)  $ are there with $a,b\in\left\{
1,2,3\right\}  $ and $a>b$ ? Again, three:%
\[
\left(  2,1\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  3,1\right)
,\ \ \ \ \ \ \ \ \ \ \left(  3,2\right)  .
\]

\end{itemize}

Let us generalize this:

\begin{proposition}
\label{prop.count.pairs.nn}Let $n\in\mathbb{N}$. Then:

\textbf{(a)} The \# of pairs $\left(  a,b\right)  $ with $a,b\in\left\{
1,2,\ldots,n\right\}  $ is $n^{2}$.

\textbf{(b)} The \# of pairs $\left(  a,b\right)  $ with $a,b\in\left\{
1,2,\ldots,n\right\}  $ and $a<b$ is $1+2+\cdots+\left(  n-1\right)  $.

\textbf{(c)} The \# of pairs $\left(  a,b\right)  $ with $a,b\in\left\{
1,2,\ldots,n\right\}  $ and $a=b$ is $n$.

\textbf{(d)} The \# of pairs $\left(  a,b\right)  $ with $a,b\in\left\{
1,2,\ldots,n\right\}  $ and $a>b$ is $1+2+\cdots+\left(  n-1\right)  $.
\end{proposition}

\begin{proof}
[Informal proof.]\textbf{(a)} These pairs can be arranged in a table with $n$
rows and $n$ columns, where the rows determine the first entry and the columns
determine the second. Here is how this table looks like:%
\[%
\begin{array}
[c]{cccc}%
\left(  1,1\right)  , & \left(  1,2\right)  , & \ldots, & \left(  1,n\right)
,\\
\left(  2,1\right)  , & \left(  2,2\right)  , & \ldots, & \left(  2,n\right)
,\\
\vdots & \vdots & \ddots & \vdots\\
\left(  n,1\right)  , & \left(  n,2\right)  , & \ldots, & \left(  n,n\right)
.
\end{array}
\]
So there are $n\cdot n=n^{2}$ of these pairs.

\textbf{(b)} In the table we have just shown, a pair $\left(  a,b\right)  $
satisfies $a<b$ if and only if it is placed above the main diagonal (i.e., the
diagonal starting at the northwestern corner and ending at the southeastern
corner of the table). Thus, the \# of such pairs is the \# of cells above the
main diagonal in this table. But this \# is
\[
0+1+2+\cdots+\left(  n-1\right)  ,
\]
because there are $0$ such cells in the first column, $1$ such cell in the
second, $2$ such cells in the third, and so on. Hence,%
\begin{align*}
&  \left(  \text{\# of pairs }\left(  a,b\right)  \text{ with }a,b\in\left\{
1,2,\ldots,n\right\}  \text{ and }a<b\right) \\
&  =0+1+2+\cdots+\left(  n-1\right) \\
&  =1+2+\cdots+\left(  n-1\right)  .
\end{align*}


\textbf{(c)} A pair $\left(  a,b\right)  $ with $a=b$ is just a pair of the
form $\left(  a,a\right)  $, that is, a single element of $\left\{
1,2,\ldots,n\right\}  $ written twice in succession. Counting such pairs is
therefore tantamount to counting single elements of $\left\{  1,2,\ldots
,n\right\}  $; but there are clearly $n$ of them.

\textbf{(d)} The pairs $\left(  a,b\right)  $ that satisfy $a>b$ are in
one-to-one correspondence with the pairs $\left(  a,b\right)  $ that satisfy
$a<b$: Namely, each former pair becomes a latter pair if we swap its two
entries, and vice versa. Thus, the \# of former pairs equals the \# of latter
pairs. But we have already found (in part \textbf{(b)}) that the \# of latter
pairs is $1+2+\cdots+\left(  n-1\right)  $. Hence, the \# of former pairs is
$1+2+\cdots+\left(  n-1\right)  $ as well.
\end{proof}

Proposition \ref{prop.count.pairs.nn} has a nice consequence: For any
$n\in\mathbb{N}$, we have%
\begin{align*}
n^{2}  &  =\left(  \text{\# of pairs }\left(  a,b\right)  \text{ with }%
a,b\in\left\{  1,2,\ldots,n\right\}  \right)  \ \ \ \ \ \ \ \ \ \ \left(
\text{by Proposition \ref{prop.count.pairs.nn} \textbf{(a)}}\right) \\
&  =\underbrace{\left(  \text{\# of pairs }\left(  a,b\right)  \text{ with
}a,b\in\left\{  1,2,\ldots,n\right\}  \text{ and }a<b\right)  }%
_{\substack{=1+2+\cdots+\left(  n-1\right)  \\\text{(by Proposition
\ref{prop.count.pairs.nn} \textbf{(b)})}}}\\
&  \ \ \ \ \ \ \ \ \ \ +\underbrace{\left(  \text{\# of pairs }\left(
a,b\right)  \text{ with }a,b\in\left\{  1,2,\ldots,n\right\}  \text{ and
}a=b\right)  }_{\substack{=n\\\text{(by Proposition \ref{prop.count.pairs.nn}
\textbf{(c)})}}}\\
&  \ \ \ \ \ \ \ \ \ \ +\underbrace{\left(  \text{\# of pairs }\left(
a,b\right)  \text{ with }a,b\in\left\{  1,2,\ldots,n\right\}  \text{ and
}a>b\right)  }_{\substack{=1+2+\cdots+\left(  n-1\right)  \\\text{(by
Proposition \ref{prop.count.pairs.nn} \textbf{(d)})}}}\\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{since each pair }\left(  a,b\right)  \text{ satisfies either }a<b\text{
or }a=b\text{ or }a>b\text{,}\\
\text{and never more than one of these three conditions}%
\end{array}
\right) \\
&  =\underbrace{\left(  1+2+\cdots+\left(  n-1\right)  \right)  +n}%
_{=1+2+\cdots+n}+\underbrace{\left(  1+2+\cdots+\left(  n-1\right)  \right)
}_{=\left(  1+2+\cdots+n\right)  -n}\\
&  =\left(  1+2+\cdots+n\right)  +\left(  1+2+\cdots+n\right)  -n\\
&  =2\cdot\left(  1+2+\cdots+n\right)  -n.
\end{align*}
Solving this for $1+2+\cdots+n$, we obtain%
\[
1+2+\cdots+n=\dfrac{n^{2}+n}{2}=\dfrac{n\left(  n+1\right)  }{2}.
\]
Thus, we have recovered the Little Gauss formula (Theorem 1.3.1 in Lecture 2)
by counting pairs. This illustrates the fact that counting can be used to
prove algebraic identities.

\begin{exercise}
How many pairs $\left(  a,b\right)  $ are there with $a\in\left\{
1,2,3\right\}  $ and $b\in\left\{  1,2,3,4,5\right\}  $ ?
\end{exercise}

\begin{proof}
[Solution.]By the same reasoning as in Proposition \ref{prop.count.pairs.nn}
\textbf{(a)}, there are $15$ such pairs, since the pairs can be arranged in a
table with $3$ rows and $5$ columns.
\end{proof}

The same reasoning gives the following more general result:

\begin{theorem}
\label{thm.count.pairs.nm}Let $n,m\in\mathbb{N}$. Let $A$ be an $n$-element
set. Let $B$ be an $m$-element set. Then,%
\[
\left(  \text{\# of pairs }\left(  a,b\right)  \text{ with }a\in A\text{ and
}b\in B\right)  =nm.
\]

\end{theorem}

What about triples?

\begin{theorem}
\label{thm.count.triples.nmp}Let $n,m,p\in\mathbb{N}$. Let $A$ be an
$n$-element set. Let $B$ be an $m$-element set. Let $C$ be a $p$-element set.
Then,%
\[
\left(  \text{\# of triples }\left(  a,b,c\right)  \text{ with }a\in A\text{
and }b\in B\text{ and }c\in C\right)  =nmp.
\]

\end{theorem}

\begin{proof}
[Informal proof.]You can think of these triples as occupying the cells of a
$3$-dimensional table, but this kind of visualization is tricky (and gets even
less reliable when you get to higher dimensions).

A better approach: Re-encode each triple $\left(  a,b,c\right)  $ as a pair
$\left(  \left(  a,b\right)  ,c\right)  $ (a pair whose first entry is itself
a pair). This is a pair whose first entry comes from the set of all pairs
$\left(  a,b\right)  $ with $a\in A$ and $b\in B$, whereas its second entry
comes from $C$. Let $U$ be the set of all pairs $\left(  a,b\right)  $ with
$a\in A$ and $b\in B$. Then, this set $U$ is an $nm$-element set, because
\begin{align*}
\left(  \text{\# of elements of }U\right)   &  =\left(  \text{\# of pairs
}\left(  a,b\right)  \text{ with }a\in A\text{ and }b\in B\right) \\
&  =nm\ \ \ \ \ \ \ \ \ \ \left(  \text{by Theorem \ref{thm.count.pairs.nm}%
}\right)  .
\end{align*}


Now, we have re-encoded each triple $\left(  a,b,c\right)  $ as a pair
$\left(  \left(  a,b\right)  ,c\right)  $ with $\left(  a,b\right)  \in U$ and
$c\in C$. Thus,
\begin{align*}
&  \left(  \text{\# of triples }\left(  a,b,c\right)  \text{ with }a\in
A\text{ and }b\in B\text{ and }c\in C\right) \\
&  =\left(  \text{\# of pairs }\left(  \left(  a,b\right)  ,c\right)  \text{
with }\left(  a,b\right)  \in U\text{ and }c\in C\right) \\
&  =\left(  \text{\# of pairs }\left(  u,c\right)  \text{ with }u\in U\text{
and }c\in C\right) \\
&  =\left(  nm\right)  p
\end{align*}
(by Theorem \ref{thm.count.pairs.nm}, since $U$ is an $nm$-element set while
$C$ is a $p$-element set). In other words,%
\[
\left(  \text{\# of triples }\left(  a,b,c\right)  \text{ with }a\in A\text{
and }b\in B\text{ and }c\in C\right)  =nmp.
\]
This proves Theorem \ref{thm.count.triples.nmp}.
\end{proof}

\subsubsection{Cartesian products}

There is a general notation for sets of pairs:

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

The set of all pairs $\left(  a,b\right)  $ with $a\in A$ and $b\in B$ is
denoted by $A\times B$, and is called the \textbf{Cartesian product} (or just
\textbf{product}) of the sets $A$ and $B$.
\end{definition}

For instance, $\left\{  1,2\right\}  \times\left\{  7,8,9\right\}  $ is the
set of all pairs $\left(  a,b\right)  $ with $a\in\left\{  1,2\right\}  $ and
$b\in\left\{  7,8,9\right\}  $. Explicitly, it consists of the following six
pairs:%
\begin{align*}
&  \left(  1,7\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  1,8\right)
,\ \ \ \ \ \ \ \ \ \ \left(  1,9\right)  ,\\
&  \left(  2,7\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  2,8\right)
,\ \ \ \ \ \ \ \ \ \ \left(  2,9\right)  .
\end{align*}


A similar notation exists for sets of triples, of quadruples or of $k$-tuples
in general:

\begin{definition}
Let $A_{1},A_{2},\ldots,A_{k}$ be $k$ sets.

The set of all $k$-tuples $\left(  a_{1},a_{2},\ldots,a_{k}\right)  $ with
$a_{1}\in A_{1}$ and $a_{2}\in A_{2}$ and $\cdots$ and $a_{k}\in A_{k}$ is
denoted by%
\[
A_{1}\times A_{2}\times\cdots\times A_{k},
\]
and is called the \textbf{Cartesian product} (or just \textbf{product}) of the
sets $A_{1},A_{2},\ldots,A_{k}$.
\end{definition}

For example, the set $\left\{  1,2\right\}  \times\left\{  5\right\}
\times\left\{  2,7,6\right\}  $ consists of all triples $\left(  a_{1}%
,a_{2},a_{3}\right)  $ with $a_{1}\in\left\{  1,2\right\}  $ and $a_{2}%
\in\left\{  5\right\}  $ and $a_{3}\in\left\{  2,7,6\right\}  $. One such pair
is $\left(  2,5,2\right)  $; another is $\left(  2,5,6\right)  $. In total,
there are $3\cdot1\cdot2$ such triples (by Theorem \ref{thm.count.triples.nmp}).

The word \textquotedblleft Cartesian\textquotedblright\ in \textquotedblleft
Cartesian product\textquotedblright\ honors Ren\'{e} Descartes, who has
observed that a point in the Euclidean plane can be characterized by its two
coordinates (i.e., a pair of real numbers), whereas a point in space can be
characterized by its three coordinates (i.e., a triple of real numbers). These
two observations allow us to think of the plane as the Cartesian product
$\mathbb{R}\times\mathbb{R}$, and to think of space as the Cartesian product
$\mathbb{R}\times\mathbb{R}\times\mathbb{R}$. \medskip

Using the notation $A\times B$, we can restate Theorem
\ref{thm.count.pairs.nm} as follows:

\begin{theorem}
[product rule for two sets]\label{thm.count.pairs.nm-x}If $A$ is an
$n$-element set, and $B$ is an $m$-element set, then $A\times B$ is an
$nm$-element set.
\end{theorem}

More generally:

\begin{theorem}
[product rule for $k$ sets]\label{thm.count.triples.nmp-x-n}Let $A_{1}%
,A_{2},\ldots,A_{k}$ be $k$ sets. If each $A_{i}$ is an $n_{i}$-element set,
then $A_{1}\times A_{2}\times\cdots\times A_{k}$ is an $n_{1}n_{2}\cdots
n_{k}$-element set.
\end{theorem}

In other words, when you count $k$-tuples, with each entry coming from a
certain set, the total number is the product of the numbers of options for
each entry.

You can prove Theorem \ref{thm.count.triples.nmp-x-n} by induction on $k$,
using Theorem \ref{thm.count.pairs.nm-x} and the same \textquotedblleft
re-encode a tuple as a nested pair\textquotedblright\ trick that we used in
our proof of Theorem \ref{thm.count.triples.nmp}. We will later come back to
this in more detail.

\subsubsection{Counting strictly increasing tuples (informally)}

In Proposition \ref{prop.count.pairs.nn} \textbf{(b)}, we have seen that for
any given $n\in\mathbb{N}$, the \# of pairs $\left(  a,b\right)  $ of elements
of $\left\{  1,2,\ldots,n\right\}  $ satisfying $a<b$ is%
\[
1+2+\cdots+\left(  n-1\right)  =\dfrac{\left(  n-1\right)  n}{2}=\dbinom{n}%
{2}.
\]


What is the \# of triples $\left(  a,b,c\right)  $ of elements of $\left\{
1,2,\ldots,n\right\}  $ satisfying $a<b<c$ ?

Such a triple $\left(  a,b,c\right)  $ always determines a $3$-element subset
$\left\{  a,b,c\right\}  $ of $\left\{  1,2,\ldots,n\right\}  $ (and yes, this
will really be a $3$-element subset, because $a<b<c$ entails that $a,b,c$ are
distinct). Conversely, any $3$-element subset of $\left\{  1,2,\ldots
,n\right\}  $ becomes a triple $\left(  a,b,c\right)  $ with $a<b<c$ if we
list its elements in increasing order. Thus, the triples $\left(
a,b,c\right)  $ of elements of $\left\{  1,2,\ldots,n\right\}  $ satisfying
$a<b<c$ are just the $3$-element subsets of $\left\{  1,2,\ldots,n\right\}  $
in disguise.\footnote{We are again being informal here. To be more rigorous,
we should be speaking of a one-to-one correspondence between the former
triples and the latter subsets. But it is not yet the time for this pedantry.}
Hence,%
\begin{align*}
&  \left(  \text{\# of triples }\left(  a,b,c\right)  \text{ of elements of
}\left\{  1,2,\ldots,n\right\}  \text{ satisfying }a<b<c\right) \\
&  =\left(  \text{\# of }3\text{-element subsets of }\left\{  1,2,\ldots
,n\right\}  \right) \\
&  =\dbinom{n}{3}\ \ \ \ \ \ \ \ \ \ \left(  \text{by Theorem
\ref{thm.count.subsets.size.S}, applied to }S=\left\{  1,2,\ldots,n\right\}
\text{ and }k=3\right)  .
\end{align*}
More generally, for any $k\in\mathbb{N}$, we have%
\begin{align*}
&  \left(  \text{\# of }k\text{-tuples }\left(  a_{1},a_{2},\ldots
,a_{k}\right)  \text{ of elements of }\left\{  1,2,\ldots,n\right\}  \text{
satisfying }a_{1}<a_{2}<\cdots<a_{k}\right) \\
&  =\dbinom{n}{k}%
\end{align*}
(by a similar argument: these $k$-tuples are just the $k$-element subsets of
$\left\{  1,2,\ldots,n\right\}  $ in disguise). For comparison, if we drop the
\textquotedblleft$a_{1}<a_{2}<\cdots<a_{k}$\textquotedblright\ requirement,
then we have
\begin{align*}
&  \left(  \text{\# of }k\text{-tuples }\left(  a_{1},a_{2},\ldots
,a_{k}\right)  \text{ of elements of }\left\{  1,2,\ldots,n\right\}  \right)
\\
&  =\underbrace{nn\cdots n}_{k\text{ times}}\ \ \ \ \ \ \ \ \ \ \left(
\text{by Theorem \ref{thm.count.triples.nmp-x-n}}\right) \\
&  =n^{k}.
\end{align*}


Other counting problems don't have answers this simple. For instance, it is
not hard to see that%
\begin{align*}
&  \left(  \text{\# of }k\text{-tuples }\left(  a_{1},a_{2},\ldots
,a_{k}\right)  \text{ of elements of }\left\{  1,2,\ldots,n\right\}  \text{
such that }a_{1}\text{ is the largest entry}\right) \\
&  =1^{k-1}+2^{k-1}+3^{k-1}+\cdots+n^{k-1},
\end{align*}
but there is no way to express this without a \textquotedblleft$\cdots
$\textquotedblright\ or a $\sum$ sign. For each specific $k$, however, we can
simplify this:%
\begin{align*}
1^{0}+2^{0}+\cdots+n^{0}  &  =\underbrace{1+1+\cdots+1}_{n\text{ times}}=n;\\
1^{1}+2^{1}+\cdots+n^{1}  &  =1+2+\cdots+n=\dfrac{n\left(  n+1\right)  }{2};\\
1^{2}+2^{2}+\cdots+n^{2}  &  =\dfrac{n\left(  n+1\right)  \left(  2n+1\right)
}{6};\\
1^{3}+2^{3}+\cdots+n^{3}  &  =\dfrac{n^{2}\left(  n+1\right)  ^{2}}{4};\\
1^{4}+2^{4}+\cdots+n^{4}  &  =\dfrac{n\left(  2n+1\right)  \left(  n+1\right)
\left(  3n+3n^{2}-1\right)  }{30};\\
&  \ldots.
\end{align*}
Such a closed-form expression for $1^{m}+2^{m}+\cdots+n^{m}$ exists for any
specific value of $m$ (see, e.g., \cite[Lecture 17, Theorem 2.5.3]{22fco} for
how to find it).

\bigskip

Next time, we will learn what it means for a set to have $n$ elements, and
what rules we have actually been using in our above informal arguments.

\begin{thebibliography}{99999}                                                                                            %


\bibitem[22fco]{22fco}Darij Grinberg, \textit{Math 222: Enumerative
Combinatorics, Fall 2022}.\newline\url{https://www.cip.ifi.lmu.de/~grinberg/t/22fco/}
\end{thebibliography}


\end{document}