\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=Sunday, May 07, 2023 20:53:42}
%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 15, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 15: 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}{4}

\subsection{Maps (aka functions)}

\setcounter{subsubsection}{7}

\subsubsection{Composition of functions (cont'd)}

In Definition 4.5.11 (in Lecture 14), we defined the \textbf{composition} of
two functions\footnote{Recall: \textquotedblleft Function\textquotedblright%
\ and \textquotedblleft map\textquotedblright\ mean the same thing.} $f$ to
$g$ to be the function%
\begin{align*}
\left(  \text{domain of }g\right)   &  \rightarrow\left(  \text{target of
}f\right)  ,\\
x  &  \mapsto f\left(  g\left(  x\right)  \right)  .
\end{align*}
This composition is denoted by $f\circ g$.

As we saw, the compositions $f\circ g$ and $g\circ f$ are usually not the same
(in fact, in many cases, one of these is defined and the other isn't). In
other words, composition of functions does not satisfy commutativity. However,
it has a few other nice properties:

\begin{theorem}
[associativity of composition]\label{thm.maps.compos.ass}Let $X,Y,Z,W$ be four
sets. Let $f:Z\rightarrow W$, $g:Y\rightarrow Z$ and $h:X\rightarrow Y$ be
three functions. Then,%
\[
\left(  f\circ g\right)  \circ h=f\circ\left(  g\circ h\right)  .
\]

\end{theorem}

\begin{proof}
Both $\left(  f\circ g\right)  \circ h$ and $f\circ\left(  g\circ h\right)  $
are functions from $X$ to $W$. Moreover, for each $x\in X$, we have%
\begin{align*}
\left(  f\circ\left(  g\circ h\right)  \right)  \left(  x\right)   &
=f\left(  \left(  g\circ h\right)  \left(  x\right)  \right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by the definition of }f\circ\left(  g\circ
h\right)  \right) \\
&  =f\left(  g\left(  h\left(  x\right)  \right)  \right)
\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{since the definition of }g\circ h\\
\text{yields }\left(  g\circ h\right)  \left(  x\right)  =g\left(  h\left(
x\right)  \right)
\end{array}
\right)
\end{align*}
and%
\begin{align*}
\left(  \left(  f\circ g\right)  \circ h\right)  \left(  x\right)   &
=\left(  f\circ g\right)  \left(  h\left(  x\right)  \right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by the definition of }\left(  f\circ
g\right)  \circ h\right) \\
&  =f\left(  g\left(  h\left(  x\right)  \right)  \right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by the definition of }f\circ g\right)  ,
\end{align*}
so that%
\[
\left(  f\circ\left(  g\circ h\right)  \right)  \left(  x\right)  =f\left(
g\left(  h\left(  x\right)  \right)  \right)  =\left(  \left(  f\circ
g\right)  \circ h\right)  \left(  x\right)  .
\]
Since this holds for each $x\in X$, we conclude that $f\circ\left(  g\circ
h\right)  =\left(  f\circ g\right)  \circ h$ (because two functions $u$ and
$v$ from $X$ to $W$ are equal if and only if the equality $u\left(  x\right)
=v\left(  x\right)  $ holds for each $x\in X$). This proves the theorem.
\end{proof}

Intuitively, the claim of Theorem \ref{thm.maps.compos.ass} is pretty obvious:
It is just saying that if you can do three things (applying $h$, applying $g$
and applying $f$) in succession, then it does not matter whether you view it
as \textquotedblleft first doing $h$ followed by $g$, and then doing
$f$\textquotedblright\ or as \textquotedblleft first doing $h$, and then doing
$g$ followed by $f$\textquotedblright.

Thanks to Theorem \ref{thm.maps.compos.ass}, we can write compositions of
several functions without parentheses: i.e., instead of writing $f\circ\left(
g\circ h\right)  $ or $\left(  f\circ g\right)  \circ h$, we can just write
$f\circ g\circ h$. \medskip

The following property of composition of functions is even easier. We recall
that $\operatorname*{id}\nolimits_{P}$ means the identity map on a given set
$P$; this is the map from $P$ to $P$ that sends each element $p\in P$ to itself.

\begin{theorem}
\label{thm.maps.compos.id}Let $f:X\rightarrow Y$ be a function. Then,%
\[
f\circ\operatorname*{id}\nolimits_{X}=\operatorname*{id}\nolimits_{Y}\circ
f=f.
\]

\end{theorem}

\begin{proof}
For each $x\in X$, we have%
\begin{align*}
\left(  f\circ\operatorname*{id}\nolimits_{X}\right)  \left(  x\right)   &
=f\left(  \operatorname*{id}\nolimits_{X}\left(  x\right)  \right) \\
&  =f\left(  x\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{since the definition
of }\operatorname*{id}\nolimits_{X}\text{ yields }\operatorname*{id}%
\nolimits_{X}\left(  x\right)  =x\right)  .
\end{align*}
This shows that $f\circ\operatorname*{id}\nolimits_{X}=f$ (since both
$f\circ\operatorname*{id}\nolimits_{X}$ and $f$ are functions from $X$ to
$Y$). A similar computation yields $\operatorname*{id}\nolimits_{Y}\circ f=f$.
Thus, the theorem follows.
\end{proof}

Thanks to Theorem \ref{thm.maps.compos.id}, we can remove identity maps from
compositions: e.g., the composition $f\circ g\circ\operatorname*{id}%
\nolimits_{P}\circ\,h$ (where $P$ is the target of $h$ and the domain of $g$)
can be simplified to $f\circ g\circ h$.

\subsubsection{Jectivities (injectivity, surjectivity and bijectivity)}

Now we introduce some important properties of functions, which have to do with
how often they attain certain values. There are three of these properties, and
I refer to them as the \textquotedblleft jectivity
properties\textquotedblright, as they are called injectivity, surjectivity and bijectivity.

\begin{definition}
\label{def.maps.jects.def}Let $f:X\rightarrow Y$ be a function. Then:

\textbf{(a)} We say that $f$ is \textbf{injective} (aka \textbf{one-to-one},
aka an \textbf{injection}) if
\[
\text{for each }y\in Y\text{, there exists \textbf{at most one} }x\in X\text{
such that }f\left(  x\right)  =y.
\]
In other words: We say that $f$ is \textbf{injective} if there are no two
distinct elements $x_{1},x_{2}\in X$ such that $f\left(  x_{1}\right)
=f\left(  x_{2}\right)  $.

In other words: We say that $f$ is \textbf{injective} if any two elements
$x_{1},x_{2}\in X$ satisfying $f\left(  x_{1}\right)  =f\left(  x_{2}\right)
$ must also satisfy $x_{1}=x_{2}$. \medskip

\textbf{(b)} We say that $f$ is \textbf{surjective} (aka \textbf{onto}, aka a
\textbf{surjection}) if
\[
\text{for each }y\in Y\text{, there exists \textbf{at least one} }x\in X\text{
such that }f\left(  x\right)  =y.
\]
In other words: We say that $f$ is \textbf{surjective} if every element of $Y$
is an output value of $f$. \medskip

\textbf{(c)} We say that $f$ is \textbf{bijective} (aka a \textbf{one-to-one
correspondence}, aka a \textbf{bijection}) if
\[
\text{for each }y\in Y\text{, there exists \textbf{exactly one} }x\in X\text{
such that }f\left(  x\right)  =y.
\]
Thus, $f$ is bijective if and only if $f$ is both injective and surjective.
\end{definition}

Here are some examples:

\begin{itemize}
\item The function%
\begin{align*}
f:\mathbb{N}  &  \rightarrow\mathbb{N},\\
k  &  \mapsto k^{2}%
\end{align*}
is injective (because no two distinct nonnegative integers $x_{1},x_{2}$
satisfy $x_{1}^{2}=x_{2}^{2}$) but not surjective (because, e.g., the
nonnegative integer $2\in\mathbb{N}$ is not the square of any nonnegative
integer). Thus, it is not bijective.

\item Let $S=\left\{  0,1,4,9,16,\ldots\right\}  $ be the set of all perfect
squares (i.e., all squares of integers). Then, the function%
\begin{align*}
g:\mathbb{N}  &  \rightarrow S,\\
k  &  \mapsto k^{2}%
\end{align*}
is injective (for the same reason as the $f$ in the previous example) and also
surjective (since every perfect square can be written as $k^{2}$ for some
$k\in\mathbb{N}$). Thus, it is bijective.

Take note: The functions $f$ and $g$ differ only in their choice of target!
Other than that, they are indistinguishable (both have domain $\mathbb{N}$,
and send each element of this domain to its square). But of course, this
little difference matters for the surjectivity, since the surjectivity depends
crucially on the target. No wonder that $g$ is surjective while $f$ is not.

\item The function
\begin{align*}
h:\mathbb{N}  &  \rightarrow\mathbb{N},\\
k  &  \mapsto k//2
\end{align*}
(recall that $k//2$ is the quotient of the division of $k$ by $2$) is not
injective (for example, the two distinct elements $0,1\in\mathbb{N}$ satisfy
$h\left(  0\right)  =h\left(  1\right)  $, because both $h\left(  0\right)
=0//2$ and $h\left(  1\right)  =1//2$ are $0$), but is surjective (because for
each $y\in\mathbb{N}$, there exists an $x\in\mathbb{N}$ such that $h\left(
x\right)  =y$, namely for example $x=2y$). Hence, it is not bijective.

\item Let $E=\left\{  0,2,4,6,\ldots\right\}  $ be the set of all even
nonnegative integers. The function%
\begin{align*}
h_{\operatorname*{even}}:E  &  \rightarrow\mathbb{N},\\
k  &  \mapsto k//2
\end{align*}
(note that $k//2=k/2$ here, since $k$ is even) is both injective and
surjective, thus bijective.

\item Let $O=\left\{  1,3,5,7,\ldots\right\}  $ be the set of all odd
nonnegative integers. The function%
\begin{align*}
h_{\operatorname*{odd}}:O  &  \rightarrow\mathbb{N},\\
k  &  \mapsto k//2
\end{align*}
is also injective and surjective, thus bijective.
\end{itemize}

The following criterion for injectivity, surjectivity and bijectivity is just
a restatement of Definition \ref{def.maps.jects.def}, but it can be quite
useful for checking these properties:

\begin{remark}
\label{rmk.maps.jects.table}Consider a function $f:X\rightarrow Y$ given by a
table of all its values (possibly an infinite table if $X$ is infinite).
Imagine that all possible inputs $x\in X$ appear in the top row, and the
corresponding outputs $f\left(  x\right)  $ appear in the bottom row, so the
table looks as follows:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c}\hline
$x$ & $a$ & $b$ & $c$ & $d$ & $\cdots$\\\hline
$f\left(  x\right)  $ & $f\left(  a\right)  $ & $f\left(  b\right)  $ &
$f\left(  c\right)  $ & $f\left(  d\right)  $ & $\cdots$\\\hline
\end{tabular}
\ \ \ \ .
\]
Then:

\textbf{(a)} The function $f$ is injective if and only if the bottom row of
this table has no two equal entries.

\textbf{(b)} The function $f$ is surjective if and only if every element of
$Y$ appears in the bottom row.

\textbf{(c)} The function $f$ is bijective if and only if every element of $Y$
appears exactly once in the bottom row.
\end{remark}

For example:

\begin{itemize}
\item The function%
\begin{align*}
f:\left\{  1,2,3\right\}   &  \rightarrow\left\{  7,8,9\right\}  ,\\
k  &  \mapsto k+6
\end{align*}
is bijective, as you can see from its table of values:%
\[%
\begin{tabular}
[c]{|c||c|c|c|}\hline
$k$ & $1$ & $2$ & $3$\\\hline
$f\left(  k\right)  $ & $7$ & $8$ & $9$\\\hline
\end{tabular}
\]
(by noticing that every element of $\left\{  7,8,9\right\}  $ appears exactly
once in the bottom row of this table). Of course, this can also be shown
logically (by arguing that $f$ is injective and surjective because adding $6$
can be undone by subtracting $6$).

\item The function\footnote{Recall that $k\%3$ denotes the remainder of the
division of $k$ by $3$.}%
\begin{align*}
f:\left\{  4,6,7\right\}   &  \rightarrow\left\{  0,1,2\right\}  ,\\
k  &  \mapsto k\%3
\end{align*}
is neither injective nor surjective. Indeed, its table of values%
\[%
\begin{tabular}
[c]{|c||c|c|c|}\hline
$k$ & $4$ & $6$ & $7$\\\hline
$f\left(  k\right)  $ & $1$ & $0$ & $1$\\\hline
\end{tabular}
\]
has the element $1$ appear twice in the bottom row (so $f$ is not injective)
and does not have the element $2$ in its bottom row (so $f$ is not surjective).
\end{itemize}

Here is yet another way to restate Definition \ref{def.maps.jects.def}:

\begin{remark}
If you visualize a function $f:X\rightarrow Y$ as a blobs-and-arrows picture
(as explained in \S 4.5.3), then

\begin{itemize}
\item the function $f$ is injective if and only if no two arrows hit the same
$Y$-node;

\item the function $f$ is surjective if and only if every node in the $Y$-blob
gets hit by at least one arrow;

\item the function $f$ is bijective if and only if every node in the $Y$-blob
gets hit by exactly one arrow.
\end{itemize}
\end{remark}

This can be illustrated by the following four examples:%
\[%
\begin{tabular}
[c]{|c|c|}\hline
$%
\begin{array}
[c]{c}%
%TCIMACRO{\TeXButton{tikzpicture}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
%\node(5) at (3, 2) {$1$};
%\node(6) at (3, 1) {$2$};
%\node(7) at (3, 0) {$3$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (6);
%\draw[->, very thick, green!50!black] (2) -- (7);
%\draw[->, very thick, green!50!black] (3) -- (6);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
\node(5) at (3, 2) {$1$};
\node(6) at (3, 1) {$2$};
\node(7) at (3, 0) {$3$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (6);
\draw[->, very thick, green!50!black] (2) -- (7);
\draw[->, very thick, green!50!black] (3) -- (6);
\end{tikzpicture}%
%EndExpansion
\\
\text{neither injective nor surjective}\\
\text{(since }1\in Y\text{ is not hit,}\\
\text{while }2\in Y\text{ is hit twice)}%
\end{array}
$ & $%
\begin{array}
[c]{c}%
%TCIMACRO{\TeXButton{tikzpicture}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1.5) ellipse (1 and 1);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
%\node(5) at (3, 2) {$1$};
%\node(6) at (3, 1) {$2$};
%\node(7) at (3, 0) {$3$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (5);
%\draw[->, very thick, green!50!black] (2) -- (7);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1.5) ellipse (1 and 1);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
\node(5) at (3, 2) {$1$};
\node(6) at (3, 1) {$2$};
\node(7) at (3, 0) {$3$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (5);
\draw[->, very thick, green!50!black] (2) -- (7);
\end{tikzpicture}%
%EndExpansion
\\
\text{injective but not surjective}\\
\text{(since }2\in Y\text{ is not hit)}%
\end{array}
$\\\hline
$%
\begin{array}
[c]{c}%
%TCIMACRO{\TeXButton{tikzpicture}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 1.5) ellipse (1 and 1);
%\node(5) at (3, 2) {$1$};
%\node(6) at (3, 1) {$2$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (5);
%\draw[->, very thick, green!50!black] (2) -- (6);
%\draw[->, very thick, green!50!black] (3) -- (5);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 1.5) ellipse (1 and 1);
\node(5) at (3, 2) {$1$};
\node(6) at (3, 1) {$2$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (5);
\draw[->, very thick, green!50!black] (2) -- (6);
\draw[->, very thick, green!50!black] (3) -- (5);
\end{tikzpicture}%
%EndExpansion
\\
\text{surjective but not injective}\\
\text{(since }1\in Y\text{ is hit twice)}%
\end{array}
$ & $%
\begin{array}
[c]{c}%
%TCIMACRO{\TeXButton{tikzpicture}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
%\node(1) at (0, 2) {$1$};
%\node(2) at (0, 1) {$2$};
%\node(3) at (0, 0) {$3$};
%\node(Cname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
%\node(5) at (3, 2) {$1$};
%\node(6) at (3, 1) {$2$};
%\node(7) at (3, 0) {$3$};
%\node(Dname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (1) -- (6);
%\draw[->, very thick, green!50!black] (2) -- (7);
%\draw[->, very thick, green!50!black] (3) -- (5);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 1) ellipse (1 and 1.5);
\node(1) at (0, 2) {$1$};
\node(2) at (0, 1) {$2$};
\node(3) at (0, 0) {$3$};
\node(Cname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 1) ellipse (1 and 1.5);
\node(5) at (3, 2) {$1$};
\node(6) at (3, 1) {$2$};
\node(7) at (3, 0) {$3$};
\node(Dname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (1) -- (6);
\draw[->, very thick, green!50!black] (2) -- (7);
\draw[->, very thick, green!50!black] (3) -- (5);
\end{tikzpicture}%
%EndExpansion
\\
\text{both injective and surjective}\\
\text{(i.e., bijective)}%
\end{array}
$\\\hline
\end{tabular}
\]


\subsubsection{Inverses}

Bijective maps have a special power: They can be \textbf{inverted}. Here is
what this means:

\begin{definition}
Let $f:X\rightarrow Y$ be a function. An \textbf{inverse} of $f$ means a
function $g:Y\rightarrow X$ such that%
\[
f\circ g=\operatorname*{id}\nolimits_{Y}\ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ g\circ f=\operatorname*{id}\nolimits_{X}.
\]


In other words, an \textbf{inverse} of $f$ means a function $g:Y\rightarrow X$
such that%
\begin{align*}
f\left(  g\left(  y\right)  \right)   &  =y\ \ \ \ \ \ \ \ \ \ \text{for each
}y\in Y,\ \ \ \ \ \ \ \ \ \ \text{and}\\
g\left(  f\left(  x\right)  \right)   &  =x\ \ \ \ \ \ \ \ \ \ \text{for each
}x\in X.
\end{align*}

\end{definition}

Roughly speaking, an inverse of $f$ thus means a map that both undoes $f$ and
is undone by $f$.

Not every function has an inverse. We shall soon see which ones do and which
ones don't; we will also prove that an inverse of $f$ is unique if it exists.
For now, however, let us explore a few examples:

\begin{itemize}
\item Let $f:\left\{  1,2,3\right\}  \rightarrow\left\{  7,8,9\right\}  $ be
the \textquotedblleft add $6$\textquotedblright\ function -- i.e., the
function that sends each $x\in\left\{  1,2,3\right\}  $ to $x+6\in\left\{
7,8,9\right\}  $. Then, $f$ has an inverse: the \textquotedblleft subtract
$6$\textquotedblright\ function (i.e., the function from $\left\{
7,8,9\right\}  $ to $\left\{  1,2,3\right\}  $ that sends each $y$ to $y-6$).
Indeed, if we denote the \textquotedblleft subtract $6$\textquotedblright%
\ function by $g$, then we have%
\begin{align*}
f\left(  g\left(  y\right)  \right)   &  =f\left(  y-6\right)  =\left(
y-6\right)  +6=y\ \ \ \ \ \ \ \ \ \ \text{for each }y\in\left\{
7,8,9\right\}  ,\ \ \ \ \ \ \ \ \ \ \text{and}\\
g\left(  f\left(  x\right)  \right)   &  =g\left(  x+6\right)  =\left(
x+6\right)  -6=x\ \ \ \ \ \ \ \ \ \ \text{for each }x\in\left\{
1,2,3\right\}  .
\end{align*}


\item Let $f:\left\{  1,2,3,4,5\right\}  \rightarrow\left\{
1,2,3,4,5\right\}  $ be the function that sends $1,2,3,4,5$ to $3,4,1,5,2$,
respectively. Then, $f$ has an inverse: namely, the function $g$ that sends
$1,2,3,4,5$ to $3,5,1,2,4$, respectively. We can check that $f\left(  g\left(
y\right)  \right)  =y$ for each $y\in\left\{  1,2,3,4,5\right\}  $. For
example, for $y=3$, this is because $f\left(  g\left(  3\right)  \right)
=f\left(  1\right)  =3$. Similarly we can check that $g\left(  f\left(
x\right)  \right)  =x$ for each $x\in\left\{  1,2,3,4,5\right\}  $.

This is best seen by drawing the blobs-and-arrows diagrams of $f$ and $g$ side
by side:%
\[%
\begin{tabular}
[c]{|c|c|}\hline
$%
\begin{array}
[c]{c}%
%TCIMACRO{\TeXButton{tikzpicture}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 0) ellipse (1 and 2.5);
%\node(A1) at (0, 2) {$1$};
%\node(A2) at (0, 1) {$2$};
%\node(A3) at (0, 0) {$3$};
%\node(A4) at (0, -1) {$4$};
%\node(A5) at (0, -2) {$5$};
%\node(Aname) at (0, 3) {$X$};
%\filldraw[fill=cyan!20!white] (3, 0) ellipse (1 and 2.5);
%\node(B1) at (3, 2) {$1$};
%\node(B2) at (3, 1) {$2$};
%\node(B3) at (3, 0) {$3$};
%\node(B4) at (3, -1) {$4$};
%\node(B5) at (3, -2) {$5$};
%\node(Aname) at (3, 3) {$Y$};
%\draw[->, very thick, green!50!black] (A1) -- (B3);
%\draw[->, very thick, green!50!black] (A2) -- (B4);
%\draw[->, very thick, green!50!black] (A3) -- (B1);
%\draw[->, very thick, green!50!black] (A4) -- (B5);
%\draw[->, very thick, green!50!black] (A5) -- (B2);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 0) ellipse (1 and 2.5);
\node(A1) at (0, 2) {$1$};
\node(A2) at (0, 1) {$2$};
\node(A3) at (0, 0) {$3$};
\node(A4) at (0, -1) {$4$};
\node(A5) at (0, -2) {$5$};
\node(Aname) at (0, 3) {$X$};
\filldraw[fill=cyan!20!white] (3, 0) ellipse (1 and 2.5);
\node(B1) at (3, 2) {$1$};
\node(B2) at (3, 1) {$2$};
\node(B3) at (3, 0) {$3$};
\node(B4) at (3, -1) {$4$};
\node(B5) at (3, -2) {$5$};
\node(Aname) at (3, 3) {$Y$};
\draw[->, very thick, green!50!black] (A1) -- (B3);
\draw[->, very thick, green!50!black] (A2) -- (B4);
\draw[->, very thick, green!50!black] (A3) -- (B1);
\draw[->, very thick, green!50!black] (A4) -- (B5);
\draw[->, very thick, green!50!black] (A5) -- (B2);
\end{tikzpicture}%
%EndExpansion
\\
f
\end{array}
$ & $%
\begin{array}
[c]{c}%
%TCIMACRO{\TeXButton{tikzpicture}{\begin{tikzpicture}
%\filldraw[fill=cyan!20!white] (0, 0) ellipse (1 and 2.5);
%\node(A1) at (0, 2) {$1$};
%\node(A2) at (0, 1) {$2$};
%\node(A3) at (0, 0) {$3$};
%\node(A4) at (0, -1) {$4$};
%\node(A5) at (0, -2) {$5$};
%\node(Aname) at (0, 3) {$Y$};
%\filldraw[fill=cyan!20!white] (3, 0) ellipse (1 and 2.5);
%\node(B1) at (3, 2) {$1$};
%\node(B2) at (3, 1) {$2$};
%\node(B3) at (3, 0) {$3$};
%\node(B4) at (3, -1) {$4$};
%\node(B5) at (3, -2) {$5$};
%\node(Aname) at (3, 3) {$X$};
%\draw[->, very thick, green!50!black] (A3) -- (B1);
%\draw[->, very thick, green!50!black] (A4) -- (B2);
%\draw[->, very thick, green!50!black] (A1) -- (B3);
%\draw[->, very thick, green!50!black] (A5) -- (B4);
%\draw[->, very thick, green!50!black] (A2) -- (B5);
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 0) ellipse (1 and 2.5);
\node(A1) at (0, 2) {$1$};
\node(A2) at (0, 1) {$2$};
\node(A3) at (0, 0) {$3$};
\node(A4) at (0, -1) {$4$};
\node(A5) at (0, -2) {$5$};
\node(Aname) at (0, 3) {$Y$};
\filldraw[fill=cyan!20!white] (3, 0) ellipse (1 and 2.5);
\node(B1) at (3, 2) {$1$};
\node(B2) at (3, 1) {$2$};
\node(B3) at (3, 0) {$3$};
\node(B4) at (3, -1) {$4$};
\node(B5) at (3, -2) {$5$};
\node(Aname) at (3, 3) {$X$};
\draw[->, very thick, green!50!black] (A3) -- (B1);
\draw[->, very thick, green!50!black] (A4) -- (B2);
\draw[->, very thick, green!50!black] (A1) -- (B3);
\draw[->, very thick, green!50!black] (A5) -- (B4);
\draw[->, very thick, green!50!black] (A2) -- (B5);
\end{tikzpicture}%
%EndExpansion
\\
g
\end{array}
$\\\hline
\end{tabular}
\ \ \ .
\]
As you see, there is a \textquotedblleft dual\textquotedblright\ relationship
between these two diagrams: Whenever the diagram of $f$ has an arrow from some
$x\in X$ to some $y\in Y$, the diagram of $g$ has an arrow from $y$ to $x$. In
other words, the diagram of $g$ can be obtained from the diagram of $f$ by
swapping the $X$-blob with the $Y$-blob and reversing the direction of each
arrow. This rule applies not just to our specific two maps $f$ and $g$, but to
any map $f$ that has an inverse. Thus, if you have drawn a blobs-and-arrows
diagram of a function $f$, it is fairly easy to construct its inverse (as long
as such an inverse exists).

This rule can also be restated in terms of tables of values: If you have a
table of all values of a function $f:X\rightarrow Y$, then you can get an
inverse of $f$ by swapping the two rows of this table. For instance, if
$f:\left\{  1,2,3,4,5\right\}  \rightarrow\left\{  1,2,3,4,5\right\}  $ is the
function we just showed, then $f$ has the table of values%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|}\hline
$k$ & $1$ & $2$ & $3$ & $4$ & $5$\\\hline
$f\left(  k\right)  $ & $3$ & $5$ & $1$ & $2$ & $4$\\\hline
\end{tabular}
\ \ ,
\]
and thus you can get its inverse $g$ by swapping the two rows:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|}\hline
$k$ & $3$ & $5$ & $1$ & $2$ & $4$\\\hline
$g\left(  k\right)  $ & $1$ & $2$ & $3$ & $4$ & $5$\\\hline
\end{tabular}
\ \ .
\]


\item Let $f:\left\{  1,2,3,4\right\}  \rightarrow\left\{  1,2,3,4\right\}  $
be the function that sends $1,2,3,4$ to $1,2,3,3$, respectively. Then, $f$ has
no inverse. Indeed, if $g$ was an inverse of $f$, then we would have%
\begin{align*}
3  &  =g\left(  f\left(  3\right)  \right)  \ \ \ \ \ \ \ \ \ \ \left(
\text{since }g\left(  f\left(  x\right)  \right)  =x\text{ for each }%
x\in\left\{  1,2,3,4\right\}  \right) \\
&  =g\left(  f\left(  4\right)  \right)  \ \ \ \ \ \ \ \ \ \ \left(
\text{since }f\left(  3\right)  =3=f\left(  4\right)  \right) \\
&  =4\ \ \ \ \ \ \ \ \ \ \left(  \text{since }g\left(  f\left(  x\right)
\right)  =x\text{ for each }x\in\left\{  1,2,3,4\right\}  \right)  ,
\end{align*}
which is absurd.

The same argument shows that more generally, if a function $f:X\rightarrow Y$
is to have an inverse, then $f$ should be injective, because two distinct
elements $x_{1}$ and $x_{2}$ of $X$ satisfying $f\left(  x_{1}\right)
=f\left(  x_{2}\right)  $ would create a contradiction via $x_{1}=g\left(
f\left(  x_{1}\right)  \right)  =g\left(  f\left(  x_{2}\right)  \right)
=x_{2}$.

\item Let $f:\left\{  1,2,3\right\}  \rightarrow\left\{  1,2,3,4\right\}  $ be
the function that sends $1,2,3$ to $1,2,3$, respectively. Then, $f$ has no
inverse. Indeed, if $g$ was an inverse of $f$, then we would have $f\left(
g\left(  4\right)  \right)  =4$, but this is absurd, since $4$ is not an
output of $f$.

The same argument shows that more generally, if a function $f:X\rightarrow Y$
is to have an inverse, then $f$ should be surjective, because each $y\in Y$
will satisfy $y=f\left(  g\left(  y\right)  \right)  $ and thus be an output
value of $f$.
\end{itemize}

Combining the morals of the last two examples, we conclude that if a function
$f:X\rightarrow Y$ is to have an inverse, then $f$ should be both injective
and surjective, i.e., should be bijective. In other words, only bijective maps
have a chance at having inverses. This turns out to be sufficient as well: If
a map is bijective, then it has an inverse. Let us summarize this as a theorem:

\begin{theorem}
\label{thm.maps.jects.inv=bij}Let $f:X\rightarrow Y$ be a map between two sets
$X$ and $Y$. Then, $f$ has an inverse if and only if $f$ is bijective.
\end{theorem}

\begin{fineprint}
\begin{proof}
We must prove the logical equivalence%
\begin{equation}
\left(  f\text{ has an inverse}\right)  \Longleftrightarrow\left(  f\text{ is
bijective}\right)  . \label{pf.thm.maps.jects.inv=bij.goal}%
\end{equation}


Let us prove the $\Longrightarrow$ and $\Longleftarrow$ directions separately:

$\Longrightarrow:$ Assume that $f$ has an inverse. We must show that $f$ is
bijective.\footnote{We have already done this in the above examples, but we
repeat it for the sake of completeness.}

We assumed that $f$ has an inverse. Let $g$ be this inverse.

Let us show that $f$ is injective. Let $x_{1},x_{2}\in X$ satisfy $f\left(
x_{1}\right)  =f\left(  x_{2}\right)  $. We must prove that $x_{1}=x_{2}$. Set
$y=f\left(  x_{1}\right)  $; then, $y=f\left(  x_{2}\right)  $ as well (since
$f\left(  x_{1}\right)  =f\left(  x_{2}\right)  $). Since $g$ is an inverse of
$f$, we have $x_{1}=g\left(  f\left(  x_{1}\right)  \right)  =g\left(
y\right)  $ (since $f\left(  x_{1}\right)  =y$) and $x_{2}=g\left(  f\left(
x_{2}\right)  \right)  =g\left(  y\right)  $ (since $f\left(  x_{2}\right)
=y$). Thus, $x_{1}=g\left(  y\right)  =x_{2}$. This completes our proof that
$f$ is injective.

Let us show that $f$ is surjective. Let $y\in Y$. Then, $y=f\left(  g\left(
y\right)  \right)  $ (since $g$ is an inverse of $f$). Therefore, there exists
an $x\in X$ such that $y=f\left(  x\right)  $ (namely, $x=g\left(  y\right)
$). So we have proved for each $y\in Y$ that there exists an $x\in X$ such
that $y=f\left(  x\right)  $. In other words, $f$ is surjective.

So $f$ is both injective and surjective, thus bijective. This proves the
\textquotedblleft$\Longrightarrow$\textquotedblright\ direction of our
equivalence (\ref{pf.thm.maps.jects.inv=bij.goal}).

Let us now prove the \textquotedblleft$\Longleftarrow$\textquotedblright\ direction:

$\Longleftarrow:$ Assume that $f$ is bijective. We must show that $f$ has an inverse.

Since $f$ is bijective, for each $y\in Y$, there exists a \textbf{unique}
$x\in X$ such that $f\left(  x\right)  =y$. Thus, we can define a map%
\[
g:Y\rightarrow X,
\]
which sends each $y\in Y$ to this unique $x$. It is easy to see that $g$ is an
inverse of $f$. Thus, $f$ has an inverse. This proves the \textquotedblleft%
$\Longleftarrow$\textquotedblright\ direction of our equivalence
(\ref{pf.thm.maps.jects.inv=bij.goal}). Thus, the proof of
(\ref{pf.thm.maps.jects.inv=bij.goal}) is complete, i.e., Theorem
\ref{thm.maps.jects.inv=bij} is proved.
\end{proof}
\end{fineprint}

Theorem \ref{thm.maps.jects.inv=bij} says that bijective maps are the same as
invertible maps (i.e., maps that have an inverse). This is a fundamental
result that is used all over mathematics.

\bigskip

As we promised, let us now show that an inverse of a map $f$ is unique if it exists:

\begin{theorem}
\label{thm.maps.inverse.unique}Let $f:X\rightarrow Y$ be a function. Then, $f$
has at most one inverse.
\end{theorem}

\begin{proof}
What does \textquotedblleft at most one inverse\textquotedblright\ mean? It
means that $f$ has no two distinct inverses. In other words, it means that any
two inverses of $f$ are identical.

So let us prove this. Let $g_{1}$ and $g_{2}$ be two inverses of $f$. We must
show that $g_{1}=g_{2}$.

Since $g_{1}$ is an inverse of $f$, we have $g_{1}\circ f=\operatorname*{id}%
\nolimits_{X}$ and $f\circ g_{1}=\operatorname*{id}\nolimits_{Y}$.

Since $g_{2}$ is an inverse of $f$, we have $g_{2}\circ f=\operatorname*{id}%
\nolimits_{X}$ and $f\circ g_{2}=\operatorname*{id}\nolimits_{Y}$.

By associativity of composition (Theorem \ref{thm.maps.compos.ass}), the two
maps $\left(  g_{1}\circ f\right)  \circ g_{2}$ and $g_{1}\circ\left(  f\circ
g_{2}\right)  $ are equal. Thus, we can denote both of these maps by
$g_{1}\circ f\circ g_{2}$.

Comparing%
\begin{align*}
g_{1}\circ\underbrace{f\circ g_{2}}_{=\operatorname*{id}\nolimits_{Y}}  &
=g_{1}\circ\operatorname*{id}\nolimits_{Y}=g_{1}%
\ \ \ \ \ \ \ \ \ \ \text{with}\\
\underbrace{g_{1}\circ f}_{=\operatorname*{id}\nolimits_{X}}\circ\,g_{2}  &
=\operatorname*{id}\nolimits_{X}\circ g_{2}=g_{2},
\end{align*}
we find $g_{1}=g_{2}$, qed.
\end{proof}

\begin{definition}
Let $f:X\rightarrow Y$ be a map that has an inverse. Then, this inverse (which
is unique by Theorem \ref{thm.maps.inverse.unique}) is called $f^{-1}$.
\end{definition}

Thus, if $f:X\rightarrow Y$ is a map that has an inverse (i.e., by Theorem
\ref{thm.maps.jects.inv=bij}, a bijective map), then we have%
\[
f^{-1}\circ f=\operatorname*{id}\nolimits_{X}\ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ f\circ f^{-1}=\operatorname*{id}\nolimits_{Y},
\]
that is,%
\begin{align}
f^{-1}\left(  f\left(  x\right)  \right)   &  =x\ \ \ \ \ \ \ \ \ \ \text{for
each }x\in X,\ \ \ \ \ \ \ \ \ \ \text{and}\label{eq.def.maps.inverse.f-1f}\\
f\left(  f^{-1}\left(  y\right)  \right)   &  =y\ \ \ \ \ \ \ \ \ \ \text{for
each }y\in Y. \label{eq.def.maps.inverse.ff-1}%
\end{align}
These equalities should explain why the notation $f^{-1}$ was chosen for the
inverse of $f$.

\bigskip

Here are some further examples of inverses:

\begin{itemize}
\item Let $E=\left\{  0,2,4,6,\ldots\right\}  $ be the set of all even
nonnegative integers. Consider the function%
\begin{align*}
f:E  &  \rightarrow\mathbb{N},\\
k  &  \mapsto k/2.
\end{align*}
Then, $f$ has an inverse. This inverse is the function%
\begin{align*}
f^{-1}:\mathbb{N}  &  \rightarrow E,\\
k  &  \mapsto2k.
\end{align*}


\item Let $\mathbb{R}_{\geq0}=\left\{  \text{all nonnegative real
numbers}\right\}  $. Then, the function
\begin{align*}
f:\mathbb{R}_{\geq0}  &  \rightarrow\mathbb{R}_{\geq0},\\
x  &  \mapsto x^{2}%
\end{align*}
has an inverse. This inverse is the function%
\begin{align*}
f^{-1}:\mathbb{R}_{\geq0}  &  \rightarrow\mathbb{R}_{\geq0},\\
x  &  \mapsto\sqrt{x}.
\end{align*}


\item In contrast, the function%
\begin{align*}
f:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto x^{2}%
\end{align*}
has no inverse. In fact, this function is not injective (since $f\left(
1\right)  =f\left(  -1\right)  $) and not surjective (since $-1$ is not a
square of a real number), so it is certainly not bijective, and thus not invertible.

\item The function%
\begin{align*}
f:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto x^{3}%
\end{align*}
has an inverse. This inverse is the function%
\begin{align*}
f^{-1}:\mathbb{R}  &  \rightarrow\mathbb{R},\\
x  &  \mapsto\sqrt[3]{x}.
\end{align*}

\end{itemize}

\bigskip

Here are some more general properties of inverses:

\begin{proposition}
Let $X$ be any set. Then, the identity map $\operatorname*{id}\nolimits_{X}%
:X\rightarrow X$ is bijective, and is its own inverse.
\end{proposition}

\begin{proof}
The map $\operatorname*{id}\nolimits_{X}$ is an inverse of itself (since
$\operatorname*{id}\nolimits_{X}\circ\operatorname*{id}\nolimits_{X}%
=\operatorname*{id}\nolimits_{X}$ and $\operatorname*{id}\nolimits_{X}%
\circ\operatorname*{id}\nolimits_{X}=\operatorname*{id}\nolimits_{X}$). Hence,
it has an inverse, and thus is bijective (by Theorem
\ref{thm.maps.jects.inv=bij}).
\end{proof}

\begin{theorem}
\label{thm.maps.inverse.invinv}Let $f:X\rightarrow Y$ be a map that has an
inverse $f^{-1}:Y\rightarrow X$. Then, $f^{-1}$ has an inverse, namely $f$.
\end{theorem}

\begin{proof}
Since $f^{-1}$ is an inverse of $f$, we have $f\circ f^{-1}=\operatorname*{id}%
\nolimits_{Y}$ and $f^{-1}\circ f=\operatorname*{id}\nolimits_{X}$. But the
same two equalities can be read as saying that $f$ is an inverse of $f^{-1}$.
\end{proof}

\begin{theorem}
[socks-and-shoes formula]\label{thm.maps.inverse.socks}Let $X$, $Y$ and $Z$ be
three sets. Let $g:X\rightarrow Y$ and $f:Y\rightarrow Z$ be two bijective
functions. Then, the composition $f\circ g:X\rightarrow Z$ is bijective as
well, and its inverse is%
\[
\left(  f\circ g\right)  ^{-1}=g^{-1}\circ f^{-1}.
\]

\end{theorem}

\begin{proof}
This is obvious from the blobs-and-arrows picture; but let us check this rigorously.

For any $x\in X$, we have%
\[
\left(  g^{-1}\circ f^{-1}\right)  \left(  \left(  f\circ g\right)  \left(
x\right)  \right)  =g^{-1}\left(  \underbrace{f^{-1}\left(  f\left(  g\left(
x\right)  \right)  \right)  }_{=g\left(  x\right)  }\right)  =g^{-1}\left(
g\left(  x\right)  \right)  =x.
\]
For any $z\in Z$, we have%
\[
\left(  f\circ g\right)  \left(  \left(  g^{-1}\circ f^{-1}\right)  \left(
z\right)  \right)  =f\left(  \underbrace{g\left(  g^{-1}\left(  f^{-1}\left(
z\right)  \right)  \right)  }_{=f^{-1}\left(  z\right)  }\right)  =f\left(
f^{-1}\left(  z\right)  \right)  =z.
\]
Thus, $g^{-1}\circ f^{-1}$ is an inverse of $f\circ g$. Hence, $f\circ g$ has
an inverse, and thus is bijective (by Theorem \ref{thm.maps.jects.inv=bij}).
\end{proof}

\begin{remark}
Note that $g^{-1}\circ f^{-1}$ is not the same as $f^{-1}\circ g^{-1}$.
Indeed, $f^{-1}\circ g^{-1}$ might not even exist in Theorem
\ref{thm.maps.inverse.socks}.
\end{remark}

A surprising feature of the socks-and-shoes formula $\left(  f\circ g\right)
^{-1}=g^{-1}\circ f^{-1}$ is that the order in which the inverses $f^{-1}$ and
$g^{-1}$ appear on the right hand side is different from the order in which
$f$ and $g$ appear on the left hand side. However, this is completely natural:
If you want to undo two things you have done in some order, then you should
undo them in the opposite order! For example, if you have put on your socks
and then your shoes in the morning, then you need to first take off the shoes
and then the socks when you go to bed. (The formula owes its moniker to this metaphor.)

\begin{remark}
Part of Theorem \ref{thm.maps.inverse.socks} says that a composition of two
bijective functions is bijective. However, a composition $f\circ g$ of two
non-bijective functions $f$ and $g$ can sometimes also be bijective. Here is
an example:%
\[
\begin{tikzpicture}
\filldraw[fill=cyan!20!white] (0, 0) ellipse (0.5 and 0.5);
\node(1) at (0, 0) {$1$};
\node(Cname) at (0, 1) {$\set{1}$};
\filldraw[fill=cyan!20!white] (3, 0.5) ellipse (1 and 1);
\node(11) at (3, 1) {$1$};
\node(22) at (3, 0) {$2$};
\node(Dname) at (3, 2) {$\set{1,2}$};
\filldraw[fill=cyan!20!white] (6, 0) ellipse (0.5 and 0.5);
\node(111) at (6, 0) {$1$};
\node(Ename) at (6, 1) {$\set{1}$};
\draw[->, very thick, green!50!black] (11) -- (111);
\draw[->, very thick, green!50!black] (22) -- (111);
\draw[->, very thick, green!50!black] (1) -- (11);
\node(oname) at (1.5, -0.5) {$\color{green!50!black}{g}$};
\node(pname) at (4.5, -0.5) {$\color{green!50!black}{f}$};
\end{tikzpicture}
\]

\end{remark}

\subsubsection{Some solved exercises}

Here are a few solved exercises on jectivities.

\begin{exercise}
\label{exe.maps.jects.compos}Let $X$, $Y$ and $Z$ be three sets, and
$f:Y\rightarrow Z$ and $g:X\rightarrow Y$ be two maps. Which of the following
are true? \medskip

\textbf{(a)} If $f$ and $g$ are injective, then $f\circ g$ is injective.
\medskip

\textbf{(b)} If $f\circ g$ is injective, then $f$ is injective. \medskip

\textbf{(c)} If $f\circ g$ is injective, then $g$ is injective. \medskip

\textbf{(d)} If $f$ and $g$ are surjective, then $f\circ g$ is surjective.
\medskip

\textbf{(e)} If $f\circ g$ is surjective, then $f$ is surjective. \medskip

\textbf{(f)} If $f\circ g$ is surjective, then $g$ is surjective. \medskip

\textbf{(g)} If $f$ and $g$ are bijective, then $f\circ g$ is bijective.
\medskip

\textbf{(h)} If $f\circ g$ is bijective, then $f$ is bijective. \medskip

\textbf{(i)} If $f\circ g$ is bijective, then $g$ is bijective.
\end{exercise}

\begin{proof}
[Solution.]We shall use the following definitions of \textquotedblleft
injective\textquotedblright, \textquotedblleft surjective\textquotedblright%
\ and \textquotedblleft bijective\textquotedblright\footnote{We gave several
equivalent definitions for \textquotedblleft injective\textquotedblright,
\textquotedblleft surjective\textquotedblright\ and \textquotedblleft
bijective\textquotedblright\ in Definition \ref{def.maps.jects.def}; you can
just as well use any of them instead.}:

\begin{itemize}
\item A map $h:U\rightarrow V$ is \textbf{injective} if and only if it has the
following property: For any $u_{1},u_{2}\in U$ satisfying $h\left(
u_{1}\right)  =h\left(  u_{2}\right)  $, we have $u_{1}=u_{2}$.

\item A map $h:U\rightarrow V$ is \textbf{surjective} if and only if it has
the following property: For any $v\in V$, there exists some $u\in U$ such that
$h\left(  u\right)  =v$.

\item A map $h:U\rightarrow V$ is \textbf{bijective} if and only if $h$ is
both injective and surjective.
\end{itemize}

\textbf{(a)} This is \textbf{true}.

[\textit{Proof:} Assume that $f$ and $g$ are injective. We must prove that
$f\circ g$ is injective.

Let $u_{1},u_{2}\in X$ satisfy $\left(  f\circ g\right)  \left(  u_{1}\right)
=\left(  f\circ g\right)  \left(  u_{2}\right)  $. We shall show that
$u_{1}=u_{2}$.

Indeed, we have $\left(  f\circ g\right)  \left(  u_{1}\right)  =f\left(
g\left(  u_{1}\right)  \right)  $ (by the definition of $f\circ g$), so that%
\[
f\left(  g\left(  u_{1}\right)  \right)  =\left(  f\circ g\right)  \left(
u_{1}\right)  =\left(  f\circ g\right)  \left(  u_{2}\right)  =f\left(
g\left(  u_{2}\right)  \right)
\]
(again by the definition of $f\circ g$). Since $f$ is injective, we thus
conclude that $g\left(  u_{1}\right)  =g\left(  u_{2}\right)  $%
\ \ \ \ \footnote{In some more detail:
\par
We know that $f$ is injective. In other words, for any $v_{1},v_{2}\in Y$
satisfying $f\left(  v_{1}\right)  =f\left(  v_{2}\right)  $, we have
$v_{1}=v_{2}$ (by our definition of \textquotedblleft
injective\textquotedblright). Applying this to $v_{1}=g\left(  u_{1}\right)  $
and $v_{2}=g\left(  u_{2}\right)  $, we obtain $g\left(  u_{1}\right)
=g\left(  u_{2}\right)  $ (since $f\left(  g\left(  u_{1}\right)  \right)
=f\left(  g\left(  u_{2}\right)  \right)  $).}. Since $g$ is injective, we
thus conclude that $u_{1}=u_{2}$.

Forget that we fixed $u_{1},u_{2}$. We thus have shown that for any
$u_{1},u_{2}\in X$ satisfying $\left(  f\circ g\right)  \left(  u_{1}\right)
=\left(  f\circ g\right)  \left(  u_{2}\right)  $, we have $u_{1}=u_{2}$. In
other words, the map $f\circ g$ is injective (by our definition of
\textquotedblleft injective\textquotedblright). This completes our proof.]
\medskip

\textbf{(b)} This is \textbf{false}.

[\textit{Counterexample:} For instance, we can set $X=\left\{  1\right\}  $
and $Y=\left\{  1,2\right\}  $ and $Z=\left\{  1\right\}  $, and let
$f:Y\rightarrow Z$ be the map that sends both elements of $Y$ to $1$, while
$g:X\rightarrow Y$ is the map sending $1$ to $1$. Then, $f\circ g$ is
injective (in fact, $f\circ g$ is the identity map $\operatorname*{id}%
\nolimits_{\left\{  1\right\}  }$), but $f$ is not.] \medskip

\textbf{(c)} This is \textbf{true}.

[\textit{Proof:} Assume that $f\circ g$ is injective. We must prove that $g$
is injective.

Let $u_{1},u_{2}\in X$ satisfy $g\left(  u_{1}\right)  =g\left(  u_{2}\right)
$. We shall show that $u_{1}=u_{2}$.

Indeed, we have $\left(  f\circ g\right)  \left(  u_{1}\right)  =f\left(
g\left(  u_{1}\right)  \right)  $ (by the definition of $f\circ g$) and
$\left(  f\circ g\right)  \left(  u_{2}\right)  =f\left(  g\left(
u_{2}\right)  \right)  $ (likewise). Hence,%
\[
\left(  f\circ g\right)  \left(  u_{1}\right)  =f\left(  \underbrace{g\left(
u_{1}\right)  }_{=g\left(  u_{2}\right)  }\right)  =f\left(  g\left(
u_{2}\right)  \right)  =\left(  f\circ g\right)  \left(  u_{2}\right)  .
\]
Since $f\circ g$ is injective, this entails $u_{1}=u_{2}$.

Forget that we fixed $u_{1},u_{2}$. We thus have shown that for any
$u_{1},u_{2}\in X$ satisfying $g\left(  u_{1}\right)  =g\left(  u_{2}\right)
$, we have $u_{1}=u_{2}$. In other words, the map $g$ is injective (by our
definition of \textquotedblleft injective\textquotedblright). This completes
our proof.] \medskip

\textbf{(d)} This is \textbf{true}.

[\textit{Proof:} Assume that $f$ and $g$ are surjective. We must prove that
$f\circ g$ is surjective.

Let $z\in Z$ be arbitrary. We shall show that there exists some $x\in X$ such
that $\left(  f\circ g\right)  \left(  x\right)  =z$.

Indeed, recall that $f$ is surjective. Thus, there exists some $y\in Y$ such
that $f\left(  y\right)  =z$. Consider this $y$.

Recall now that $g$ is surjective. Thus, there exists some $w\in X$ such that
$g\left(  w\right)  =y$. Consider this $w$.

We have $\left(  f\circ g\right)  \left(  w\right)  =f\left(
\underbrace{g\left(  w\right)  }_{=y}\right)  =f\left(  y\right)  =z$. Hence,
there exists some $x\in X$ such that $\left(  f\circ g\right)  \left(
x\right)  =z$ (namely, $x=w$).

Forget that we fixed $z$. We thus have shown that for any $z\in Z$, there
exists some $x\in X$ such that $\left(  f\circ g\right)  \left(  x\right)
=z$. In other words, the map $f\circ g$ is surjective (by our definition of
\textquotedblleft surjective\textquotedblright). This completes our proof.]
\medskip

\textbf{(e)} This is \textbf{true}.

[\textit{Proof:} Assume that $f\circ g$ is surjective. We must prove that $f$
is surjective.

Let $z\in Z$ be arbitrary. We shall show that there exists some $y\in Y$ such
that $f\left(  y\right)  =z$.

Indeed, recall that $f\circ g$ is surjective. Thus, there exists some $x\in X$
such that $\left(  f\circ g\right)  \left(  x\right)  =z$. Consider this $x$.

Now, $f\left(  g\left(  x\right)  \right)  =\left(  f\circ g\right)  \left(
x\right)  =z$. Hence, there exists some $y\in Y$ such that $f\left(  y\right)
=z$ (namely, $y=g\left(  x\right)  $).

Forget that we fixed $z$. We thus have shown that for any $z\in Z$, there
exists some $y\in Y$ such that $f\left(  y\right)  =z$. In other words, the
map $f$ is surjective (by our definition of \textquotedblleft
surjective\textquotedblright). This completes our proof.] \medskip

\textbf{(f)} This is \textbf{false}.

[\textit{Counterexample:} For instance, we can set $X=\left\{  1\right\}  $
and $Y=\left\{  1,2\right\}  $ and $Z=\left\{  1\right\}  $, and let
$f:Y\rightarrow Z$ be the map that sends both elements of $Y$ to $1$, while
$g:X\rightarrow Y$ is the map sending $1$ to $1$. Then, $f\circ g$ is
surjective (in fact, $f\circ g$ is the identity map $\operatorname*{id}%
\nolimits_{\left\{  1\right\}  }$), but $g$ is not.] \medskip

\textbf{(g)} This is \textbf{true}.

[\textit{Proof:} Assume that $f$ and $g$ are bijective. Thus, $f$ and $g$ are
both injective and surjective. Hence, $f\circ g$ is injective (by Exercise
\ref{exe.maps.jects.compos} \textbf{(a)}) and surjective (by Exercise
\ref{exe.maps.jects.compos} \textbf{(d)}). Thus, $f\circ g$ is bijective.]
\medskip

\textbf{(h)} This is \textbf{false}.

[\textit{Counterexample:} For instance, we can set $X=\left\{  1\right\}  $
and $Y=\left\{  1,2\right\}  $ and $Z=\left\{  1\right\}  $, and let
$f:Y\rightarrow Z$ be the map that sends both elements of $Y$ to $1$, while
$g:X\rightarrow Y$ is the map sending $1$ to $1$. Then, $f\circ g$ is
bijective (in fact, $f\circ g$ is the identity map $\operatorname*{id}%
\nolimits_{\left\{  1\right\}  }$), but $f$ is not.] \medskip

\textbf{(i)} This is \textbf{false}.

[\textit{Counterexample:} For instance, we can set $X=\left\{  1\right\}  $
and $Y=\left\{  1,2\right\}  $ and $Z=\left\{  1\right\}  $, and let
$f:Y\rightarrow Z$ be the map that sends both elements of $Y$ to $1$, while
$g:X\rightarrow Y$ is the map sending $1$ to $1$. Then, $f\circ g$ is
bijective (in fact, $f\circ g$ is the identity map $\operatorname*{id}%
\nolimits_{\left\{  1\right\}  }$), but $g$ is not.]
\end{proof}

\begin{exercise}
Let $f:X\rightarrow Y$ be a map that has an inverse $f^{-1}:Y\rightarrow X$.
Let $x\in X$ and $y\in Y$. Prove that we have the logical equivalence%
\[
\left(  f\left(  x\right)  =y\right)  \ \Longleftrightarrow\ \left(
f^{-1}\left(  y\right)  =x\right)  .
\]

\end{exercise}

\begin{proof}
[Solution.]We shall prove the \textquotedblleft$\Longrightarrow$%
\textquotedblright\ and \textquotedblleft$\Longleftarrow$\textquotedblright%
\ parts of this equivalence separately:

$\Longrightarrow:$ If we have $f\left(  x\right)  =y$, then%
\[
f^{-1}\left(  \underbrace{y}_{=f\left(  x\right)  }\right)  =f^{-1}\left(
f\left(  x\right)  \right)  =x\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{eq.def.maps.inverse.f-1f})}\right)  .
\]
Thus, the \textquotedblleft$\Longrightarrow$\textquotedblright\ part of the
equivalence holds.

$\Longleftarrow:$ If we have $f^{-1}\left(  y\right)  =x$, then%
\[
f\left(  \underbrace{x}_{=f^{-1}\left(  y\right)  }\right)  =f\left(
f^{-1}\left(  y\right)  \right)  =y\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{eq.def.maps.inverse.ff-1})}\right)  .
\]
Thus, the \textquotedblleft$\Longleftarrow$\textquotedblright\ part of the
equivalence holds.
\end{proof}

\subsubsection{Isomorphic sets}

As an application of inverses, we can define the concept of isomorphic sets:

\begin{definition}
Let $X$ and $Y$ be two sets. We say that these two sets $X$ and $Y$ are
\textbf{isomorphic as sets} (or, for short, \textbf{isomorphic}, or \textbf{in
bijection}, or \textbf{in one-to-one correspondence}, or \textbf{equinumerous}%
) if there exists a bijective map from $X$ to $Y$.
\end{definition}

Note that this relation \textquotedblleft isomorphic as sets\textquotedblright%
\ is symmetric (i.e., if $X$ and $Y$ are isomorphic, then $Y$ and $X$ are
isomorphic). This is because if $f:X\rightarrow Y$ is a bijective map, then
$f$ has an inverse $f^{-1}$ (by Theorem \ref{thm.maps.jects.inv=bij}), and
this inverse $f^{-1}$ is again bijective (since Theorem
\ref{thm.maps.inverse.invinv} shows that $f^{-1}$ again has an inverse).

Some examples:

\begin{itemize}
\item The sets $\left\{  1,2\right\}  $ and $\left\{  1,2,3\right\}  $ are
\textbf{not} isomorphic. In fact, there is no surjective map $f:\left\{
1,2\right\}  \rightarrow\left\{  1,2,3\right\}  $ (since, informally, a map
from $\left\{  1,2\right\}  $ to $\left\{  1,2,3\right\}  $ has only two
arrows, but two arrows cannot hit all three elements of $\left\{
1,2,3\right\}  $). Thus, there is no bijective map $f:\left\{  1,2\right\}
\rightarrow\left\{  1,2,3\right\}  $ either.

\item The sets $\left\{  1,2,3\right\}  $ and $\left\{  6,7,8\right\}  $ are
isomorphic. In fact, the map%
\begin{align*}
\left\{  1,2,3\right\}   &  \rightarrow\left\{  6,7,8\right\}  ,\\
k  &  \mapsto k+5
\end{align*}
(that is, the \textquotedblleft add $5$\textquotedblright\ map) is bijective
(and its inverse sends $k\mapsto k-5$).

\item The sets $\left\{  1,2,3\right\}  $ and $\left\{  1,3,5\right\}  $ are
isomorphic. In fact, the map%
\begin{align*}
\left\{  1,2,3\right\}   &  \rightarrow\left\{  1,3,5\right\}  ,\\
k  &  \mapsto2k-1
\end{align*}
is a bijection.

\item The sets $\mathbb{N}$ and $E:=\left\{  \text{all even nonnegative
integers}\right\}  $ are isomorphic, since the map%
\begin{align*}
\mathbb{N}  &  \rightarrow E,\\
n  &  \mapsto2n
\end{align*}
is a bijection.

\item The sets $\mathbb{N}$ and $O:=\left\{  \text{all odd nonnegative
integers}\right\}  $ are isomorphic, since the map%
\begin{align*}
\mathbb{N}  &  \rightarrow O,\\
n  &  \mapsto2n+1
\end{align*}
is a bijection.

\item The sets $\mathbb{N}$ and $\mathbb{Z}$ are isomorphic, since there is a
bijection from $\mathbb{N}$ to $\mathbb{Z}$ that sends%
\begin{align*}
&  0,1,2,3,4,5,6,7,8,\ldots\ \ \ \ \ \ \ \ \ \ \text{to}\\
&  0,1,-1,2,-2,3,-3,4,-4,\ldots,\ \ \ \ \ \ \ \ \ \ \text{respectively.}%
\end{align*}
Explicitly, this map $f$ can be defined by the following formula:%
\[
f\left(  n\right)  =%
\begin{cases}
-n/2, & \text{if }n\text{ is even};\\
\left(  n+1\right)  /2, & \text{if }n\text{ is odd}%
\end{cases}
\ \ \ \ \ \ \ \ \ \ \text{for each }n\in\mathbb{N}.
\]
(This formula ensures that the values $f\left(  0\right)  ,f\left(  2\right)
,f\left(  4\right)  ,f\left(  6\right)  ,\ldots$ cover exactly the integers
$0,-1,-2,-3,\ldots$ that are $\leq0$, whereas the values $f\left(  1\right)
,f\left(  3\right)  ,f\left(  5\right)  ,f\left(  7\right)  ,\ldots$ cover
exactly the positive integers $1,2,3,4,\ldots$.)

There are, of course, many other bijections from $\mathbb{N}$ to $\mathbb{Z}$.

\item The sets $\mathbb{N}$ and $\mathbb{Q}$ are isomorphic, since there is a
bijection from $\mathbb{N}$ to $\mathbb{Q}$ that sends%
\begin{align*}
&  0,1,2,3,4,5,6,7,8,9,\ldots\ \ \ \ \ \ \ \ \ \ \text{to}\\
&  \underbrace{\dfrac{-1}{1},\dfrac{0}{1},\dfrac{1}{1}}_{\substack{\text{all
reduced fractions}\\\text{whose numerator and}\\\text{denominator are }%
\leq1\\\text{in absolute value}\\\text{(ordered from smallest}\\\text{to
largest)}}},\ \underbrace{\dfrac{-2}{1},\dfrac{-1}{2},\dfrac{1}{2},\dfrac
{2}{1}}_{\substack{\text{all reduced fractions}\\\text{whose numerator
and}\\\text{denominator are }\leq2\\\text{but not }\leq1\\\text{in absolute
value}\\\text{(ordered from smallest}\\\text{to largest)}}%
},\ \underbrace{\dfrac{-3}{1},\dfrac{-3}{2},\dfrac{-2}{3},\dfrac{-1}{3}%
,\dfrac{1}{3},\dfrac{2}{3},\dfrac{3}{2},\dfrac{3}{1}}_{\substack{\text{all
reduced fractions}\\\text{whose numerator and}\\\text{denominator are }%
\leq3\\\text{but not }\leq2\\\text{in absolute value}\\\text{(ordered from
smallest}\\\text{to largest)}}},\ldots,
\end{align*}
respectively. (To be precise, we must only allow \textbf{fully reduced}
fractions -- i.e., fractions $\dfrac{a}{b}$ with $a\in\mathbb{Z}$ and
$b\in\left\{  1,2,3,\ldots\right\}  $ and $\gcd\left(  a,b\right)  =1$ -- in
order to avoid having the same rational number appear twice.)

\item The sets $\mathbb{N}$ and $\mathbb{N}\times\mathbb{N}$ are isomorphic,
since there is a bijection $f$ from $\mathbb{N}$ to $\mathbb{N}\times
\mathbb{N}$ that sends%
\begin{align*}
&  0,1,2,3,4,5,6,7,8,9,\ldots\ \ \ \ \ \ \ \ \ \ \text{to}\\
&  \underbrace{\left(  0,0\right)  }_{\substack{\text{all pairs}\\\text{whose
entries}\\\text{sum to }0}},\ \underbrace{\left(  0,1\right)  ,\ \left(
1,0\right)  }_{\substack{\text{all pairs}\\\text{whose entries}\\\text{sum to
}1\\\text{(ordered by}\\\text{increasing}\\\text{first entry)}}%
},\ \underbrace{\left(  0,2\right)  ,\ \left(  1,1\right)  ,\ \left(
2,0\right)  }_{\substack{\text{all pairs}\\\text{whose entries}\\\text{sum to
}2\\\text{(ordered by}\\\text{increasing}\\\text{first entry)}}%
},\ \underbrace{\left(  0,3\right)  ,\ \left(  1,2\right)  ,\ \left(
2,1\right)  ,\ \left(  3,0\right)  }_{\substack{\text{all pairs}\\\text{whose
entries}\\\text{sum to }3\\\text{(ordered by}\\\text{increasing}\\\text{first
entry)}}},\ \ldots,
\end{align*}
respectively. The inverse $f^{-1}:\mathbb{N}\times\mathbb{N}\rightarrow
\mathbb{N}$ of this bijection can actually be described by an explicit
formula:%
\[
f^{-1}\left(  n,m\right)  =\dfrac{\left(  n+m\right)  \left(  n+m+1\right)
}{2}+n
\]
(nice and not-too-easy exercise: prove this!). This is the so-called
\href{https://en.wikipedia.org/wiki/Pairing_function}{Cantor pairing function}.
\end{itemize}

\subsection{Counting, formally}

\subsubsection{Definition}

As you might have noticed, isomorphic sets (at least when they are finite)
have the same number of elements -- i.e., the same size. We shall now use this
to \textbf{define} the size of a set!

First, some notations:

\begin{definition}
\textbf{(a)} If $n\in\mathbb{N}$, then $\left[  n\right]  $ shall mean the set
$\left\{  1,2,\ldots,n\right\}  $.

For example, $\left[  3\right]  =\left\{  1,2,3\right\}  $ and $\left[
7\right]  =\left\{  1,2,3,4,5,6,7\right\}  $ and $\left[  0\right]
=\varnothing$ and $\left[  1\right]  =\left\{  1\right\}  $. \medskip

\textbf{(b)} If $a,b\in\mathbb{Z}$, then $\left[  a,b\right]  $ shall mean the
set
\begin{align*}
\left\{  a,a+1,a+2,\ldots,b\right\}   &  =\left\{  \text{all integers }x\text{
satisfying }a\leq x\leq b\right\} \\
&  =\left\{  x\in\mathbb{Z}\ \mid\ a\leq x\leq b\right\}  .
\end{align*}
If $a>b$, then this is understood to be the empty set.

For example, $\left[  2,6\right]  =\left\{  2,3,4,5,6\right\}  $ and $\left[
3,3\right]  =\left\{  3\right\}  $ and $\left[  4,2\right]  =\varnothing$.
\end{definition}

Now, let us define the size of a finite set:

\begin{definition}
\label{def.sets.size.1}Let $n\in\mathbb{N}$. A set $S$ is said to have
\textbf{size }$n$ if $S$ is isomorphic to $\left[  n\right]  $ (that is, if
there exists a bijection from $S$ to $\left[  n\right]  $).
\end{definition}

For example:

\begin{itemize}
\item The set $\left\{  \text{\textquotedblleft cat\textquotedblright%
},\ \text{\textquotedblleft dog\textquotedblright},\ \text{\textquotedblleft
rat\textquotedblright}\right\}  $ has size $3$, since the map%
\begin{align*}
\left\{  \text{\textquotedblleft cat\textquotedblright}%
,\ \text{\textquotedblleft dog\textquotedblright},\ \text{\textquotedblleft
rat\textquotedblright}\right\}   &  \rightarrow\left[  3\right]  ,\\
\text{\textquotedblleft cat\textquotedblright}  &  \mapsto1,\\
\text{\textquotedblleft dog\textquotedblright}  &  \mapsto2,\\
\text{\textquotedblleft rat\textquotedblright}  &  \mapsto3
\end{align*}
is a bijection.

\item The set $\left\{  4,5,6,7\right\}  $ has size $4$, since the map%
\begin{align*}
\left\{  4,5,6,7\right\}   &  \rightarrow\left[  4\right]  ,\\
k  &  \mapsto k-3
\end{align*}
is a bijection.

\item The set $\mathbb{N}$ is infinite, so there is no bijection from
$\mathbb{N}$ to $\left[  n\right]  $ for any $n\in\mathbb{N}$. Thus,
$\mathbb{N}$ does not have size $n$ for any $n\in\mathbb{N}$.
\end{itemize}

Here is another equivalent definition of size:

\begin{definition}
\label{def.sets.size.2}We define the notion of a \textquotedblleft set of size
$n$\textquotedblright\ recursively as follows:

\textbf{(a)} A set $S$ is said to have \textbf{size }$0$ if and only if it is empty.

\textbf{(b)} Let $n$ be a positive integer. A set $S$ is said to have
\textbf{size }$n$ if and only if there exists an $s\in S$ such that
$S\setminus\left\{  s\right\}  $ has size $n-1$.
\end{definition}

In other words, a set has size $n$ (for $n>0$) if and only if we can remove a
single element from it and obtain a set of size $n-1$. This is a recursive
definition, as it reduces the question \textquotedblleft what is a set of size
$n$\textquotedblright\ to the (simpler) question \textquotedblleft what is a
set of size $n-1$\textquotedblright.

The following fact is not obvious, but can be proved:

\begin{theorem}
\label{thm.sets.size.1=2}\textbf{(a)} The above two definitions of size
(Definition \ref{def.sets.size.1} and Definition \ref{def.sets.size.2}) are equivalent.

\textbf{(b)} The size of a finite set is determined uniquely -- i.e., a set
cannot have two different sizes at the same time.
\end{theorem}

Now, we are ready to introduce some notations for sizes of sets:

\begin{definition}
\textbf{(a)} An $n$\textbf{-element set} (for some $n\in\mathbb{N}$) means a
set of size $n$.

\textbf{(b)} A set is said to be \textbf{finite} if it has size $n$ for some
$n\in\mathbb{N}$.

\textbf{(c)} If $S$ is a finite set, then $\left\vert S\right\vert $ shall
denote the size of $S$ (which is unique because of Theorem
\ref{thm.sets.size.1=2} \textbf{(b)}).

\textbf{(d)} We also refer to $\left\vert S\right\vert $ as the
\textbf{cardinality} of $S$, or as the \textbf{number} of elements of $S$.
\end{definition}

Thus, our examples above show that
\[
\left\vert \left\{  \text{\textquotedblleft cat\textquotedblright%
},\ \text{\textquotedblleft dog\textquotedblright},\ \text{\textquotedblleft
rat\textquotedblright}\right\}  \right\vert =3\ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ \left\vert \left\{  4,5,6,7\right\}  \right\vert =4.
\]

\end{document}