\section{Functions and Maps}

\definition{}<deffun>
A \textit{function} or \textit{map} $f$ from a set $A$ to a set $B$ is a rule that assigns an element of $B$ to each element of $A$. We write this as $f: A \to B$.

\vspace{1mm}

Let $L = \{\texttt{a}, \texttt{b}, \texttt{c}, \texttt{d}, ..., \texttt{z}\}$ be the set of lowercase english letters. \par
Let $C = \{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}, ..., \texttt{Z}\}$ be the set of uppercase english letters. \par

\vspace{1mm}

Say we have a function $g: L \to C$ that capitalizes english letters. \par
We can think of this function as a \textit{map} from $A$ to $B$, shown below using arrows:


\begin{center}
	\begin{tikzpicture}[scale=0.5]
		\node[anchor=south] at (0, 1) {Set $A$};
		\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5);
		\node at (0, 0) {\texttt{a}};
		\node at (0, -1) {\texttt{b}};
		\node at (0, -2) {\texttt{c}};
		\node at (0, -3) {\texttt{d}};
		\node at (0, -4) {\texttt{...}};

		\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
		\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -1);
		\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -2);
		\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -3);
		\node[fill=white, text=gray] at (2, 0) {$g$};

		\node[anchor=south] at (4, 1) {Set $B$};
		\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5);
		\node at (4, 0) {\texttt{A}};
		\node at (4, -1) {\texttt{B}};
		\node at (4, -2) {\texttt{C}};
		\node at (4, -3) {\texttt{D}};
		\node at (4, -4) {\texttt{...}};
	\end{tikzpicture}
\end{center}


\definition{}
We say a map $f$ is \textit{one-to-one} if $a = b$ implies $f(a) = f(b)$ for all $a, b \in A$. \par
In other words, this means that no two elements of $A$ are mapped to the same $b$:

\null\hfill
\begin{minipage}{0.48\textwidth}
\begin{center}
\textbf{A one-to-one function:} \par
\vspace{2mm}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {Set $A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -3);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -2);
	\node[fill=white, text=gray] at (2, 0) {$f$};

	\node[anchor=south] at (4, 1) {Set $B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3) {\texttt{d}};
	\node at (4, -4) {\texttt{e}};
\end{tikzpicture}
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}
\begin{center}
\textbf{NOT a one-to-one function:} \par
\vspace{2mm}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {Set $A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.4, -1.8);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -2.2);
	\node[fill=white, text=gray] at (2, 0) {$f$};

	\node[anchor=south] at (4, 1) {Set $B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3) {\texttt{d}};
	\node at (4, -4) {\texttt{e}};

	\draw[line width = 0.4mm, ->] (5.5, -2) -- (4.5, -2);
	\node[anchor=west] at (5.5, -2) {!!!};

\end{tikzpicture}
\end{center}
\end{minipage}
\hfill\null

\vfill


\definition{}
We say a map $f$ is \textit{onto} if for every $b \in B$, there is an $a \in A$ so that $b = f(a)$. \par
In other words, this means that every element of $B$ has some element of $A$ mapped to it:

\null\hfill
\begin{minipage}{0.48\textwidth}
\begin{center}
\textbf{An onto function:} \par
\vspace{2mm}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {Set $A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};
	\node at (0, -4) {\texttt{5}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -2);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -3);
	\draw[line width = 0.4mm, ->, gray] (0.5, -4) -- (3.4, -3.4);
	\node[fill=white, text=gray] at (2, 0) {$f$};

	\node[anchor=south] at (4, 1) {Set $B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3.1) {\texttt{d}};
\end{tikzpicture}
\end{center}
\end{minipage}
\hfill
\begin{minipage}{0.48\textwidth}
\begin{center}
\textbf{NOT an onto function:} \par
\vspace{2mm}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {Set $A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};
	\node at (0, -4) {\texttt{5}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, -0.8);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -2);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1.2);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -3);
	\draw[line width = 0.4mm, ->, gray] (0.5, -4) -- (3.4, -3.4);
	\node[fill=white, text=gray] at (2, -0.4) {$f$};

	\node[anchor=south] at (4, 1) {Set $B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3.1) {\texttt{d}};

	\draw[line width = 0.4mm, ->] (5.5, 0) -- (4.5, 0);
	\node[anchor=west] at (5.5, 0) {!!!};
\end{tikzpicture}
\end{center}
\end{minipage}
\hfill\null

\vfill
\pagebreak

\generic{Remark:}
The words \say{function} and \say{map} are two views of the same mathematical object. We usually think of functions as \say{machines} that take an input, change it, and produce an output. We think of maps as \say{rules} that match each element of a set $A$ to an element of a set $B$.

\vspace{2mm}

Again, functions and maps are \textit{identical}. They do the same thing. The only difference between \say{functions} and \say{maps} is how we think about them.

% one-to-one = injective
% onto = surjective

\problem{}
Is the \say{capitalize} function in \ref{deffun} one-to-one? Is it onto?

\vfill

\problem{}
Consider the function $f: \mathbb{Z} \to \mathbb{Z}$ defined by $f(x) = x^2$. \par
Is this function one-to-one? Is it onto?

\vfill

\problem{}
Consider the function $f: \mathbb{Z} \to \mathbb{Z}$ defined below. \par
Is this function one-to-one? Is it onto?

\[
	f(x) = \begin{cases}
		0 & \text{if } x = 0 \\
		x + 1 & \text{otherwise}
	\end{cases}
\]


% TODO:
% bijections, same size if exists bijection

\vfill
\pagebreak

\definition{Invertible Functions}
A function $g$ is an \textit{inverse} of a function $f$ if $g(f(x)) = x$ for any $x$. \par
In other words, the function $g$ \say{undoes} $f$. Usually, the inverse of a function $f$ is written $f^{-1}$. \par
We say a function is \textit{invertible} if it has an inverse.

\vspace{2mm}

Intuitively, we could say that the inverse of $f$ reverses the \say{arrows} of $f$.

\problem{}
Is the following function invertible? \par
Draw the inverse, or explain why you can't.

\begin{center}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {$A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -3);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -2);
	\node[fill=white, text=gray] at (2, 0) {$f$};

	\node[anchor=south] at (4, 1) {$B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3) {\texttt{d}};
\end{tikzpicture}
\end{center}

\vfill

\problem{}
Is the following function invertible? \par
Draw the inverse, or explain why you can't.

\begin{center}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {Set $A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -4);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -1);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -3);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.5, -2);
	\node[fill=white, text=gray] at (2, 0) {$f$};

	\node[anchor=south] at (4, 1) {Set $B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -5);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3) {\texttt{d}};
	\node at (4, -4) {\texttt{e}};
\end{tikzpicture}
\end{center}

\vfill


\problem{}
Is the following function invertible? \par
Draw the inverse, or explain why you can't.

\begin{center}
\begin{tikzpicture}[scale=0.5]
	\node[anchor=south] at (0, 1) {Set $A$};
	\draw[line width = 0.25mm, rounded corners=2mm] (-1, 1) rectangle (1, -5);
	\node at (0, 0) {\texttt{1}};
	\node at (0, -1) {\texttt{2}};
	\node at (0, -2) {\texttt{3}};
	\node at (0, -3) {\texttt{4}};
	\node at (0, -4) {\texttt{5}};

	\draw[line width = 0.4mm, ->, gray] (0.5, 0) -- (3.5, 0);
	\draw[line width = 0.4mm, ->, gray] (0.5, -1) -- (3.5, -2);
	\draw[line width = 0.4mm, ->, gray] (0.5, -2) -- (3.5, -1);
	\draw[line width = 0.4mm, ->, gray] (0.5, -3) -- (3.4, -3);
	\draw[line width = 0.4mm, ->, gray] (0.5, -4) -- (3.4, -3.4);
	\node[fill=white, text=gray] at (2, 0) {$f$};

	\node[anchor=south] at (4, 1) {Set $B$};
	\draw[line width = 0.25mm, rounded corners=2mm] (3, 1) rectangle (5, -4);
	\node at (4, 0) {\texttt{a}};
	\node at (4, -1) {\texttt{b}};
	\node at (4, -2) {\texttt{c}};
	\node at (4, -3.1) {\texttt{d}};
\end{tikzpicture}
\end{center}

\vfill
\pagebreak


\definition{Bijections}
One-to-one maps are also called \textit{injective} maps. \par
Onto maps are also called \textit{surjective} maps.

\vspace{2mm}

If a function is both one-to-one and onto, we say it is a \textit{bijection}.

\vspace{4mm}

\theorem{}
All bijective functions are invertible. All invertible functions are bijections. \par
You should review the problems on the previous page and convince yourself that this is true.

\problem{}
We say a set $S$ is \textit{finite} if there exists a bijection from $S$ to $\{1, 2, 3, ..., n\}$ for some integer $n$.\par
Convince yourself that this definition of \say{finite-ness} is the same as the one in \ref{infiniteset}.

\problem{}
Is there a bijection between the sets $\{1, 2, 3\}$ and $\{\texttt{A}, \texttt{B}, \texttt{C}\}$? \par
If a bijection exists, find one; if one doesn't, prove it. \par
\vfill

\problem{}
Is there a bijection between the sets $\{1, 2, 3, 4\}$ and $\{\texttt{A}, \texttt{B}, \texttt{C}\}$? \par
If a bijection exists, find one; if one doesn't, prove it. \par
\vfill


\problem{}<samesize>
Let $A$ and $B$ be two sets of different sizes. \par
Show that no bijection between $A$ and $B$ exists.
\vfill


\ref{samesize} reveals a very important fact: if we can find a bijection between two sets $A$ and $B$, these sets must have the same number of elements. Similarly, if we know that a bijection doesn't exist, we know that $A$ and $B$ must have a different number of elements.

\vspace{2mm}

Intuitively, you can think of a bijection as a \say{matching} between elements of $A$ and $B$. If we were to draw a bijection, we'd see an arrow connecting every element in $A$ to every element in $B$. If a bijection exists, every element of $A$ directly corresponds to an element of $B$, therefore $A$ and $B$ must have the same number of elements.

\definition{}
We say two sets $A$ and $B$ are \textit{equinumerous} if there exists a bijection $f: A \to B$.

\pagebreak