\documentclass{article}
\usepackage{amssymb, mathrsfs, enumitem}
\usepackage{tikz-cd}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{color}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{amsmath, epsfig, colortbl}
\usepackage[breakable, skins]{tcolorbox}
\setlength{\parskip}{8pt}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{cor}{Corollary}
\theoremstyle{definition}
\newtheorem{prop}{Proposition}
\newtheorem{fact}{Fact}
\newtheorem{example}{Example}
\newtheorem{definition}{Definition}
\newenvironment{solution} {\paragraph{Solution.}}{\hfill$\square$}
\renewenvironment{proof} {\paragraph{Proof.}}{\hfill$\square$}
\renewcommand{\today}{}
\captionsetup{margin=.7in, format=hang}

\newtcolorbox{examplebox}{ breakable, enhanced}
\newtcolorbox{gptbox}{ breakable, enhanced,  colback  = blue!10}

\addtolength{\topmargin}{-.875in}
\addtolength{\oddsidemargin}{-.8in}
\addtolength{\textwidth}{1.6in}
\addtolength{\textheight}{1.75in}

\newcommand{\mc}{\mathcal}
\newcommand{\abs}[1]{\left| #1\right|}
\newcommand{\la}{\Leftarrow}
\newcommand{\ra}{\Rightarrow}
\renewcommand{\iff}{\Leftrightarrow}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\floor}[1]{\left\lfloor #1\right\rfloor}
\newcommand{\ceil}[1]{\left\lceil #1\right\rceil}

\newcommand{\ex}[1]{\begin{examplebox}\begin{example} #1 \end{example}\end{examplebox}}

\newcommand{\eps}{\epsilon}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\inv}[1]{#1^{-1}}
\newcommand{\ba}{\backslash}

\def\cents{\hbox{\rm\rlap/c}}




\begin{document}
\title{Math 127: Functions}
\author{Mary Radcliffe}
\maketitle

\section{Basics}

We begin this discussion of functions with the basic definitions needed to talk about functions.

\begin{definition}
Let $X$ and $Y$ be sets. A {\it function} $f$ from $X$ to $Y$ is an object that, for each element $x\in X$, assigns an element $y\in Y$. We use the notation $f:X\to Y$ to denote a function as described. We write $f(x)=y$ or $f:x\mapsto y$ to denote that the element in $Y$ assigned to $x$ is $y$. We call $X$ the {\it domain} of $f$, and we call $Y$ the {\it codomain} of $f$. If $f(x)=y$, we say that $x$ {\it maps to $y$ under $f$}.
\end{definition}

In general, we will often talk about functions from this perspective of ``mapping;'' we see the role of a function as taking things from $X$, and sending them over to $Y$, where the function $f$ is the map that explains where each element in $X$ is supposed to go. This is visualized in Figure \ref{Function}.

\begin{figure}[htp]\centering
\includegraphics[scale=.6]{BasicFunction.pdf}
\caption{Imagine that the assignment of elements of $Y$ being done by the function $f$ is represented by the red arrows here, so that if $x\in X$ is assigned $y\in Y$, we have a red arrow from $x$ to $y$. Notice that it is permitted to have more than one element in $X$ map to the same $y\in Y$, and it is also permitted to have elements in $y$ that are not mapped to by any $x\in X$.}\label{Function}
\end{figure}

Let's think about this notion with a function we probably feel a little more comfortable with. Consider the function $f:\Z\to\Z$ defined by $f(n)=2n$, as shown in Figure \ref{Fn2n}. Practically, what this function is asking us to do is map elements in $\Z$ over to new elements in $\Z$, where the directions on the map, described by the function, are to multiply something by 2. So if you ask the function ``what do I do with the number 3?'' the function will answer ``Send it over to 6.'' In this way, the function provides us with a mechanism to transform the number 3 according to some rule, which is the definition of the function.

\begin{figure}[htp]\centering
\includegraphics[scale=.6]{fn2n.pdf}
\caption{A representation of the function $f:\Z\to \Z$ defined by $f(n)=2n$.}\label{Fn2n}
\end{figure}

Now, in order for this map to make sense, there are a few basic properties that we need to ensure are satisfied. In particular, we want to make sure that every element of $X$ can be mapped to somewhere, and that the ``somewhere'' is appropriate. Together these properties constitute what is known as well-definedness.

\begin{definition}
An assignment of values $y$ to elements $x\in X$ is said to be a {\it well-defined} function $f:X\to Y$ if it satisfies the following three properties:
\begin{itemize}
\item Totality: For every $x\in X$, there exists $y$ such that $f(x)=y$.
\item Existence: For every $x\in X$, $f(x)\in Y$.
\item Uniqueness: For every $x\in X$, there is only one $y\in Y$ such that $f(x)=y$.
\end{itemize}
\end{definition}

While these properties are trivially true in the definition of a function, it's useful to think about the failure cases to think about what kinds of assignments we might make that are in fact NOT functions. In general, if you are to define a function yourself, it's worth thinking about these things to ensure that the function you are creating is a well-defined function.


\ex{Define $g:\R\to\R$ by $g(x)=\frac{1}{x-1}$. This is NOT a well-defined function, because $g(1)$ is not an element of $\R$. There is no $y$ such that $g(1)=y$, and hence this function fails the totality property.}


\ex{Define $f:\N\to\N$ by $f(n)=n-1$. This is NOT a well-defined function, because $f(1)=0$ is not an element of $\N$. This assignment of values fails the existence property.
}

\ex{Define $f:(0,1)\to\{0,1, 2, \dots, 9\}$ (where $(0,1) = \{x\in \R\ |\ 0<x< 1\}$) by $f(x)=d$, where $d$ is the first digit after the decimal point in the base-10 expansion for $x$. This is NOT a well-defined function, because some numbers have more than one possible base-10 expansion. Indeed\footnote{Just to be sure, let's prove that $0.9999\dots = 1$, which in turn clearly implies that $0.4999\dots = 0.5$. First, let $a=0.9999\dots$, which is some real number. Then $10a=9.9999\dots$, and hence $9a=10a-a=9.9999\dots -0.9999\dots = 9$. Since $9a=9$, we therefore have that $a=1$. Thus, $1=a=0.99999.$ QED.}, $0.5=0.4999999\dots$, and hence we have more than one $y\in \{0, 1, \dots, 9\}$ with $f(\frac 1 2)=y$. This assignment of values fails the uniqueness property.}

When you are defining a function, be on the lookout for these kinds of problems. Some things to think about:
\begin{itemize}
\item If you were handed a value of $x\in X$, would you always know what to do with it?
\item If you're using a formula: can EVERY value of $x\in X$ be plugged in to your formula? If not, what are you doing with the other values?
\item Can the formula ever give you numbers that live outside your codomain?
\item Is there more than one way to represent elements in the domain? If so, do those representations give the same output under this function?
\end{itemize}

As with several of our previous topics, we have some special functions that will show up from time to time, and will be quite useful.

\begin{definition}
The {\it identity function} on a set $X$, denoted by $\iota_X$, is the function $\iota_X:X\to X$ such that $\forall x\in X,\ f(x)=x$. 

The {\it empty function} is any function $f:\emptyset\to X$. Note that there is no need, in the empty function, to define any values for elements in the domain, as there are none!
\end{definition}

Finally, we have to address the question of what it means for two functions to be the same. 

\begin{definition}
Let $X, Y, A, B$ be sets, and let $f:X\to Y$ and $g:A\to B$ be functions. We say that $f$ is identically equal to $g$, denoted by $f\equiv g$, if the following conditions are met:
\begin{itemize}
\item $X=A$
\item $Y=B$
\item $\forall x\in X$, $f(x)=g(x)$.
\end{itemize}
\end{definition}

There is a reason for distinguishing equality of functions with $\equiv$ rather than $=$. There are often times, for example, when it is important to find a specific choice of $x\in X$ for which $f(x)=g(x)$. However, this is quite different from $f(x)=g(x)$ for every single $x\in X$. 

Moreover, we can have functions that are the same on all their common domain elements (that is, $f(x)=g(x)\ \forall x\in X\cap A$), but are not identically equal because perhaps they have different domains. An example might be as follows: define $f:\N\to\N$ by $f(x)=3x$, and for $A$ the set of even integers, define $g:A\to\Z$ by $g(a)=3a$. Then on any $x$ that is both a natural number and an even integer, $f$ and $g$ produce the same value. However, we cannot say that these are really the same function, because there are numbers that $f$ can map and $g$ cannot, and vice versa. Similar qualifications, of course, apply to the codomain.

For these reasons, we distinguish between identical equality of functions and equality on elements. This is similar to the use of $\equiv$ in the world of propositional logic: we use the symbol $\equiv$ to mean that the two objects are the same, all the time, regardless of how we set the corresponding parameters.

\subsection{Functions and Subsets}

We have, already, some language and notation to discuss things like the domain or codomain of a function. However, what if we wish to consider subsets of the domain or codomain? We need to develop concepts to deal with these structures.

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. Given a set $U\subseteq X$, we define the {\it image} of $U$ in $Y$, denoted $f(U)$, to be the subset of $Y$ given by
\[f(U)=\{y\in Y\ | \ \exists x\in U \hbox{ with } f(x)=y\}.\]
If $U=X$, the image of $U$ in $Y$ is also called the {\it range} of $f$.
\end{definition}

This is to say, if we are interested in a subset $U$ of $X$, we might want to ask ourselves: what values in $Y$ are assigned to elements in this subset? This is precisely what the image of $U$ is getting at.

\ex{\label{ex:image}
Define $f:\Z\to\N$ by $f(x)=|x|+1$. To illustrate the concept of image, let's consider a few subsets of $\Z$ here.
\begin{itemize}
\item If $U=\{0, 1, 2\}$, then the image of $U$ is whatever function values are assigned to these 3 numbers. As
\[f(0)=1, \quad f(1)=2, \quad f(2)=3,\]
we have that $f(U)=\{1, 2, 3\}$.

Notice that as $U$ has 3 elements in it, we cannot have more than 3 elements in $f(U)$, due to the uniqueness property of well-defined functions.
\item If $U=\{-2, -1, 0, 1, 2\}$, then the image of $U$ is whatever function values are assigned to these five numbers. Since 
\[f(-2)=3, \quad f(-1)=2, \quad f(0)=1, \quad f(1)=2, \quad f(2)=3,\]
we have that $f(U)=\{1, 2, 3\}$.

Notice that despite the fact that $U$ has 5 elements in it, we still only have 3 elements in $f(U)$. This is due to the fact that some elements of $f(U)$ are assigned to more than one member of $U$.
\item If we wish to consider the range of $f$, we think about $U=\Z$. In this case, we have that every element of $\N$ is a member of the range; if $n\in\N$, then by taking $z=n-1$, we have $f(z)=n$. Hence, for every $n\in\N$, $\exists z\in \Z$ such that $f(z)=n$, so every $n\in\N$ is a member of the range of $f$.
\item If $U=\{0\}$, then the image of $U$ is just $f(U)=\{1\}$. In general, this is true: for any function $f:X\to Y$, we have that $f(\{x\})=\{f(x)\}$ for any $x\in X$; that is, the image of the set containing only one element $x$ is the set containing only one element, $f(x)$.
\end{itemize}
}

In the case of the function shown in Example \ref{ex:image}, we have that the range of the function $f$ is precisely the same as the codomain of $f$. This is because for this function, every element in the codomain is the image of some element in the domain. Of course, this is not true for all functions; if we take $g:\Z\to\Z$ defined by $g(z)=2z$, we clearly have that the codomain is all of $\Z$, but the range is just the even integers. 

Of course, we may be interested in more than just what the function values are on a subset of $X$. Indeed, there are circumstances where we might wish only to consider a subset of $X$, and throw away superfluous elements. In that case, we can define a function on a subset of $X$ as follows.

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. Given a set $U\subseteq X$, the {\it restriction of $f$ to $U$}, denoted as $f|_U$, is the function $f|_U:U\to Y$ defined by $f|_U(x)=f(x)$ for all $x\in U$.
\end{definition}

The restriction of $f$ to a subset will occasionally appear as a useful tool.

Now, for the other side of the coin, suppose we have a subset of $Y$, and wish to think about what elements in $X$ might map to that subset. In that case, we can define a similar type of object to the image, called the preimage.

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. Given a subset $V\subseteq Y$, we define the {\it preimage} of $V$ under $f$, denoted by $f^{-1}(V)$, to be the subset of $X$ given by 
\[ \inv f(V) = \{x\in X\ | \ f(x)\in V\}.\]
\end{definition}

This is to say, the preimage of $V$ is the set of all elements in $X$ whose image is a member of $V$. To ensure we understand the concept, let's consider an example.

\ex{\label{ex:preimage}
Let $f:\Z\to\Z$ with $f(z)=|2z|$ for all $z\in \Z$. Let's consider the preimage of a few sets $V$.
\begin{itemize}
\item If $V=\{2\}$, then the preimage of $V$ is all those elements in $\Z$ that map to $2$; that is, it is all choices of $z$ for which $f(z)=|2z|=2$. There are two such elements, namely $\pm 1$. Hence $\inv f(V)=\{-1, 1\}$.
\item If $V=\{1\}$, then the preimage of $V$ is all those elements in $\Z$ that map to $1$; that is, it is all choices of $z$ for which $f(z)=|2z|=1$. There are no such elements! Hence, $\inv f(V)=\emptyset$.
\item If $V=\{0\}$, then the preimage of $V$ is all those elements of $\Z$ that map to 0, which is clearly just $z=0$. Hence $\inv f(V)=\{0\}$.
\item If $V=\{0, 1, 2, 3, 4\}$, then by repeating above ideas, we have that the elements in $\Z$ for which $f(z)\in V$ are exactly $\inv f(V)=\{-2, -1, 0, 1, 2\}$.
\item If we take $V=\{x\in \Z\ | \ x\geq 0\hbox{ and }x\hbox{ is even}\}$, then every element of $\Z$ has its image in $V$. Hence, we have $\inv f(V)=\Z$.
\end{itemize}
}

Unlike with the image, as we see above the number of elements in the preimage of a set $V$ is not necessarily tied to the number of elements in $V$. We can have empty preimages, which we cannot have with images, and we can have many elements that map to the same $y\in V$ contribute to the preimage.

In general, the preimage and image play well with unions and intersections of sets.

\begin{prop}\label{unint}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function.
\begin{enumerate}
\item If $U_1, U_2\subseteq X$, then $f(U_1\cup U_2) = f(U_1)\cup f(U_2)$.
\item If $U_1, U_2\subseteq X$, then $f(U_1\cap U_2) \subseteq f(U_1)\cap f(U_2)$.
\item If $V_1, V_2\subseteq Y$, then $\inv f(V_1\cup V_2) = \inv f(V_1)\cup \inv f(V_2)$.
\item If $V_1, V_2\subseteq Y$, then $\inv f(V_1\cap V_2) = \inv f(V_1)\cap \inv f(V_2)$.
\end{enumerate}
\end{prop}

We shall not prove all these properties here; those that we do not prove will be left as an exercise. In particular, we shall prove items 2 and 3.

\begin{proof}[Partial Proof.]
Let $X, Y, f$ be as in the statement of Proposition \ref{unint}.
\begin{enumerate}
\item[2.] Let $U_1, U_2\subseteq X$. Suppose that $y\in f(U_1\cap U_2)$. Then by definition, there exists $x\in U_1\cap U_2$ having $f(x)=y$. Since $x\in U_1\cap U_2$, we thus have that $x\in U_1$ and $x\in U_2$, so $y\in f(U_1)$ and $y\in f(U_2)$. But then $y\in f(U_1)\cap f(U_2)$, and thus $f(U_1\cap U_2)\subseteq f(U_1)\cap f(U_2)$.
\item[3.] We prove the set equality by double containment.

First, suppose that $x\in \inv f(V_1\cup V_2)$. Then by definition, $f(x)\in V_1\cup V_2$, so either $f(x)\in V_1$ or $f(x)\in V_2$. Wolog, suppose that $f(x)\in V_1$. Then we have $x\in \inv f(V_1)$, and hence $x\in \inv f(V_1)\cup \inv f(V_2)$.

For the other direction, suppose that $x\in \inv f(V_1)\cup \inv f(V_2)$. Then we have $x\in \inv f(V_1)$ or $x\in \inv f(V_2)$; wolog suppose that $x\in \inv f(V_1)$. Then by definition, we have $f(x)\in V_1$, and thus $f(x)\in V_1\cup V_2$. But then $x\in \inv f(V_1\cup V_2)$.

Therefore, we have that $\inv f(V_1\cup V_2)=\inv f(V_1)\cup \inv f(V_2)$ by double containment.
\end{enumerate}
\end{proof}

In addition, we have similar properties for set complements.

\begin{prop}\label{comps}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function.
\begin{enumerate}
\item If $U\subseteq X$, then $f(X\ba U) \supseteq f(X)\ba f(U)$.
\item If $V\subseteq Y$, then $\inv f(Y\ba V) = X\ba \inv f(V)$
\end{enumerate}
\end{prop}

The proofs of these properties are left as an exercise.

\subsection{Composition}

\begin{definition}
Let $X, Y, Z$ be sets, and let $f:X\to Y$ and $g:Y\to Z$ be functions. We define the composition $g\circ f:X\to Z$ to be the function defined by $g\circ f(x)=g(f(x))$.
\end{definition}

We can imagine a composition as follows. The function $f$ gives us a rule for how to map the set $X$ into the set $Y$, and the function $g$ gives us a rule for how to map the set $Y$ into the set $Z$. By chaining these rules together, first by doing the $f$ rule, then the $g$ rule, we can get from $X$ all the way to $Z$. This new function can disregard the set $Y$ completely, as shown in Figure \ref{fig:comp}. The notation for function composition is set up so that the first function you perform is closest to the $x$; $g\circ f$ indicates that $f$ has to be performed first, because when you put $x$ next to the function, $f$ is closest to it.
\begin{figure}[htp]
\centering
\begin{subfigure}{.45\textwidth}
\includegraphics[scale=.35]{Composition1.pdf}
\caption{}
\end{subfigure}
\hspace{.35in}
\begin{subfigure}{.45\textwidth}
\includegraphics[scale=.35]{Composition2.pdf}
\caption{}
\end{subfigure}
\caption{To construct a composition of functions $f$ and $g$, we can imagine that we have two mappings, as shown in (a). To get the composite $g\circ f$, we start from $X$, and then follow both the red and blue arrows to get to $Z$, resulting in the purple arrows shown in (b). Once we have these purple arrows established, we can then disregard $Y$ and the original functions $f$ and $g$, and treat $g\circ f$ as its own function from $X$ to $Z$.}\label{fig:comp}
\end{figure}

To ensure that we understand this, let's take a look at an example.

\ex{Define $f:\N\to\Z$ by $f(x)=2x$, and define $g:\Z\to \Q$ by $g(x)=\frac x {12}$. The composition $g\circ f$ is a function from $\N$ to $\Q$, that looks as follows: $g\circ f(x) = g(f(x))=g(2x)=\frac {2x}{12}=\frac x 6$. Once we have this expression of $g\circ f$, we can simply treat it as a function from $\N$ to $\Q$, ignoring anything that happened in the middle.
}

The composition of functions operates in a way like a type of multiplication for functions. Indeed, it does satisfy some of the types of properties we like for multiplication. One such property that we shall frequently use is the following:
\begin{quote}
If $f:X\to Y$ is a function, then $f\equiv f\circ \iota_X\equiv \iota_Y\circ f$.
\end{quote}
That is, composing a function with an identity doesn't change anything. This will show up as a useful tool in various proofs; the proof of this property itself is left as a (trivial) exercise.

Moreover, function composition is associative:

\begin{theorem}\label{T:associativity}
Let $W, X, Y, Z$ be sets, and let $f:W\to X$, $g:X\to Y$, and $h:Y\to Z$ be functions. Then $h\circ (g\circ f)\equiv (h\circ g)\circ f$.
\end{theorem}

Before we prove this theorem, let's note the important caveat here about associativity. The theorem states that we can associate composition of functions, under the condition that the function composition makes sense. That is to say, we can perform this associativity, given that the sets involved allow function composition to take place, namely that the domain of each function is equal to the codomain of the preceding function.

\begin{proof}[Proof of Theorem \ref{T:associativity}]
To prove this theorem, we wish to show that $\forall w\in W$, we have that $h\circ (g\circ f)(w)= (h\circ g)\circ f(w)$. 

Choose an arbitrary $w\in W$. Define the following variables:
\begin{itemize}
\item $x=f(w)$, so $x\in X$.
\item $y=g(x)$, so $y\in Y$.
\item $z=h(y)$, so $z\in Z$.
\end{itemize}
Note that by definition of composition, we have $g\circ f(w)=g(f(w))=g(x)=y$. Then we have
\begin{eqnarray*}
h\circ (g\circ f)(w) & = & h( g\circ f(w))\quad \hbox{(by definition of composition)}\\
& = & h(y)\quad \hbox{(by the above calculation)}\\
& = & z.
\end{eqnarray*}
On the other hand, we have
\begin{eqnarray*}
(h\circ g)\circ f(w) & = & (h\circ g)(f(w))\quad \hbox{(by definition of composition)}\\
& = & h\circ g(x)\\
& = & h(g(x))\\
& = & h(y) = z.
\end{eqnarray*}
Therefore, we have $h\circ (g\circ f)(w) = z = (h\circ g)\circ f(w)$. As $w$ is chosen arbitrarily from $W$, this equation is true $\forall w\in W$. Therefore, $h\circ (g\circ f)\equiv (h\circ g)\circ f$. 
\end{proof}

However, there are other types of multiplication properties that we do not see in the world of function composition. In particular, we do not get commutativity for function composition.

\ex{Let $f:\Z\to\Z$ be defined by $f(x)=2x$, and let $g:\Z\to\Z$ be defined by $g(x)=x^2$. Then we have, for any $x\in \Z$,
\[g\circ f(x) = g(f(x)) = g(2x)=(2x)^2=4x^2,\]
but on the other hand,
\[f\circ g(x) = f(g(x))=f(x^2)=2x^2.\]
Hence, $g\circ f \not\equiv f\circ g$.
}

Indeed, things can be substantially worse than this; we may not be able to switch the order at all. Consider:

\ex{Let $f:\N\to\R$ be defined by $f(x)=\sqrt{x}$, and let $g:\R\to \Z$ be defined by $g(x)=\floor x-10$. Then $g\circ f$ is defined as $g(f(x))=\floor{\sqrt x}-10$, an integer. However, we cannot consider $f\circ g$, since the codomain of $g$ is not equal to the domain of $f$. Indeed, if we take $x=0$, then $g(x)=-10$, and we are unable to compute $f(g(x))$ since $f$ is only defined on positive integers.}

\section{Injectivity and Surjectivity}

There are two important properties of functions that appear throughout mathematics, and we will pause a moment to consider them here.

\subsection{Injectivity}

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. We say that $f$ is {\it injective} (sometimes called one-to-one) if $\forall x_1, x_2\in X$, $f(x_1)=f(x_2)\ra x_1=x_2$.
\end{definition}

This definition of injectivity is also often phrased in the contrapositive form: a function $f:X\to Y$ is injective if $x_1\neq x_2\ra f(x_1)\neq f(x_2)$. The idea here is that if we start from two different elements in the domain, we should land at two different elements in the domain. So the example shown in Figure \ref{Function}, our first example of a function, is not injective. We can see this because the top two elements of $X$ both have the same image in $Y$. If we draw out a mapping for an injective function, it should be the case that every element in $Y$ has at most one arrow, as seen in Figure \ref{fig:injective}.

\begin{figure}[htp]\centering
\includegraphics[scale=.6]{Injectivity.pdf}
\caption{A basic picture of an injective function. Every element in the domain $X$ maps to a different element in the codomain $Y$; every element of the codomain $Y$ has at most one element of $X$ that maps to it.}\label{fig:injective}
\end{figure}

To demonstrate that a function is injective, one of two proof strategies is usually employed. First, one can suppose that $f(x_1)=f(x_2)$, and derive that $x_1=x_2$; this is a direct proof following the definition of injectivity above. The other proof technique is to use a contradiction: suppose that $f(x_1)=f(x_2)$, but $x_1\neq x_2$, and derive a contradiction. Let's take a look at some examples.

\ex{Show that the function $f:\R\to\R$ defined by $f(x)=2x+1$ is injective.

\solution{
Suppose that $x_1, x_2\in\R$, and that $f(x_1)=f(x_2)$. Then by definition of $f$, we have $2x_1+1=2x_2+1$, and thus $2x_1=2x_2$, and thus $x_1=x_2$. Therefore $f$ is injective by definition.}}

This proof technique might remind you of showing that something is unique: first, you suppose there are two of it, and then show that those two must actually be the same. This is effectively the idea with injectivity: for each $y\in Y$, if there is an $x$ such that $f(x)=y$, then there is only one such $x$.

\ex{Let $n\in\N$. Show that the function $g:\R\to\R$ defined by $g(x)=x^n-x$ is not injective.

\solution{Notice that when $x=0$, we obtain $g(x)=0^n-0=0$, and when $x=1$, we have $g(x)=1^n-1=0$. Therefore, as $g(0)=g(1)$, and $0\neq 1$, we have that $g$ is not injective.
}}

In general, when considering proving if a function is injective or not, the following procedures can be employed:
\begin{gptbox}
\textbf{To prove a function $f:X\to Y$ is injective:}
\begin{itemize}
\item Let $x_1, x_2\in X$ be such that $f(x_1)=f(x_2)$.
\item Follow any proof technique to conclude that $x_1=x_2$.
\item Conclude that $f$ is injective.
\end{itemize}
\textbf{To prove a function $f:X\to Y$ is NOT injective:}
\begin{itemize}
\item Find a specific choice of $x_1, x_2\in X$, such that $x_1\neq x_2$, and $f(x_1)=f(x_2)$.
\item Conclude that $f$ is not injective.
\end{itemize}
\end{gptbox}

Let's consider how injectivity plays with function composition.

\begin{theorem}\label{T:compinj}
Let $X, Y, Z$ be sets, and let $f:X\to Y$ and $g:Y\to Z$ be functions. If $g$ and $f$ are both injective, then $g\circ f$ is injective.
\end{theorem}

Before we formally prove this theorem, let's think about what it is saying, and why the converse is false. If both $f$ and $g$ are injective, then when we start from two elements in $X$, we map, via $f$, to distinct elements in $Y$. Then these in turn map, via $g$, to distinct elements in $Z$. Since each stage of the mapping yields distinct elements, the images of the two original points in $X$ must be distinct.

On the other hand, we don't necessarily have the converse. Imagine that $g\circ f$ is injective. This means that if we pick two elements in $X$, they map to distinct elements in $Z$ under the composition $g\circ f$. But if the function $f$ misses a lot of elements in $Y$, then we could have that $g$ isn't injective, just that it maps to distinct elements on the image of $f$. Consider the following example:

\ex{\label{ex:notinj}Let $f:\N\to\N$ be defined by $f(x)=2x$, and let $g:\N\to\N$ be defined by $g(x)=\ceil{\frac x 2}$. This is illustrated in Figure \ref{fig:notinj}. Notice that $g$ is not injective, since $g(1)=\ceil{ \frac 1 2}=1=\ceil{\frac 2 2}=g(2)$. However, if we consider the composition $g\circ f$, we have $g\circ f(x)=g(2x)=\ceil{ \frac{2x}{2}}=x$, which is certainly injective. Thus, even though $g\circ f$ is injective, we do not have to have that $g$ and $f$ are both injective.}

\begin{figure}[htp]
\centering
\includegraphics[scale=.6]{injectivecomp.pdf}
\caption{The functions $f$ and $g$ as defined in Example \ref{ex:notinj}. We can see that the composition is injective, even as $g$ is not.}\label{fig:notinj}
\end{figure}

In general, however, we do have a partial converse, the proof of which is left as an exercise:

\begin{prop}
Let $X, Y, Z$ be sets, and let $f:X\to Y$ and $g:Y\to Z$ be functions. If $g\circ f$ is injective, then $f$ is injective.
\end{prop}

Now, let us prove the original theorem.

\begin{proof}[Proof of Theorem \ref{T:compinj}]
Let $f, g$ be as in the statement of the theorem, and suppose that both $f$ and $g$ are injective. We wish to prove that $g\circ f$ is also injective.

Let $x_1, x_2\in X$, having $g\circ f(x_1)=g\circ f(x_2)$. By definition, then $g(f(x_1))=g(f(x_2))$. Since $g$ is injective, this implies that $f(x_1)=f(x_2)$. Since $f$ is injective, this implies that $x_1=x_2$. Therefore, by definition, $g\circ f$ is injective.
\end{proof}

\subsection{Surjectivity}

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. We say that $f$ is {\it surjective} if $\forall y\in Y$, $\exists x\in X$ such that $f(x)=y$.
\end{definition}

For surjectivity, we want a function to have its range actually equal to its codomain. That is to say, every element in the codomain is mapped to by some element in the domain. Pictorially, we can imagine this as saying that when we draw the function, every element in $Y$ gets at least one arrow pointed at it. So, for example, if you look at Figure \ref{fig:notinj}, the function $g:\N\to \N$ with $g(x)=\ceil{\frac x 2}$ is surjective, since every element of the codomain has a blue arrowhead, but the function $f:\N \to\N$ with $f(x)=2x$ is not surjective, since there are some elements of $\N$ in the center that do not have a red arrowhead.

A proof that a function is surjective is effectively an existence proof; given an arbitrary element of the codomain, we need only demonstrate the existence of one element in the domain that maps to it. Let's see an example.

\ex{Define $\Q^+$ to be the set of positive rational numbers. Given $q\in\Q^+$, define $a_q = \min\{m\in \N\ | \ \exists n\in\N\ \hbox{ with } \ nq=m\}$. Note that this function is well defined, since if $q\in \Q^+$ there exist positive integers $a, b$ having $q=\frac a b$, so $bq\in\N$ and thus $\{m\in\N\ | \ \exists n\in\N\ \hbox{ with } nq=m\}$ is nonempty\footnote{Another way to think of this function is to imagine that $a_q$ is the smallest possible numerator for $q$.}. Let $f:\Q^+\to \Z$ be defined by $f(q)=a_q$. Prove that $f$ is surjective.

\begin{proof}
Given $a\in\N$, we need only demonstrate the existence of some $q\in\Q^+$ such that $f(q)=a$.

Suppose $a\in\N$. Let $q=a$. Note, then that $1q=a$, and hence $a\in\{m\in\N\ | \ \exists n\in\N \hbox{ with } nq=m\}$, by taking $n=1$. Moreover, if $n\geq1$, then $na\geq a$, and hence if $b\in \{m\in\N\ | \ \exists n\in\N \hbox{ with } nq=m\}$, then $b\geq a$. Therefore, as $a$ is both a member of this set and is a lower bound for this set, it is the minimum of this set. Thus, $f(a)=a$. 

Since every $a\in\N$ has some $q\in\Q^+$ with $f(q)=a$, we therefore have that $f$ is surjective.
\end{proof}
}

Likewise, to show that something is not surjective, it suffices to show an example of a number in the codomain that is not in the range of the function.

\ex{Let $f:\Z\to\N$ be defined by $f(z)=|z|+2$. Prove that $f$ is not surjective.

\begin{proof}
Notice that for any $z\in\Z$, we have that $f(z)\geq 2$. Therefore, if $y=1$, there is no $z\in Z$ such that $f(z)=y$. Hence, $f$ is not surjective.
\end{proof}}

In general, when considering proving if a function is surjective or not, the following procedures can be employed:
\begin{gptbox}
\textbf{To prove a function $f:X\to Y$ is surjective:}
\begin{itemize}
\item Let $y\in Y$ be an arbitrary element of the codomain.
\item Give an example of $x\in X$ having $f(x)=y$. Usually the choice of $x$ will depend on $y$ in some meaningful way.
\item Conclude that $f$ is surjective.
\end{itemize}
\textbf{To prove a function $f:X\to Y$ is NOT surjective:}
\begin{itemize}
\item Find a specific choice of $y\in Y$ for which there is no $x\in X$ having $f(x)=y$.
\item Conclude that $f$ is not surjective.
\end{itemize}
\end{gptbox}

As with injectivity, we have a theorem about surjectivity and composition.

\begin{theorem}\label{T:compsur}
Let $X, Y, Z$ be sets, and let $f:X\to Y$ and $g:Y\to Z$ be functions. If $f$ and $g$ are surjective, then $g\circ f$ is also surjective.
\end{theorem}

Let us stop to consider this result for a moment. Essentially we have this: if we have any element in $Z$, we know that if $g$ is surjective, there is some element of $Y$ that maps to it. Moreover, if $f$ is surjective, there is some element of $X$ that maps to that. So we can trace any element of $Z$ back to some element of $X$. This is the value of surjectivity; given an element in the codomain, we can trace it back to some (not necessarily unique) corresponding element in the domain.

Of course, as with Theorem \ref{T:compinj}, the converse here is false, and the example from Example \ref{ex:notinj} and shown in Figure \ref{fig:notinj} can prove it. 

\ex{\label{ex:notsur}Let $f:\N\to\N$ be defined by $f(x)=2x$, and let $g:\N\to\N$ be defined by $g(x)=\ceil{\frac x 2}$, as defined in Example \ref{ex:notinj}. This is illustrated in Figure \ref{fig:notinj}. Then $g\circ f$ is surjective, but $f$ is not surjective.

Notice that $f$ is not surjective, since there is no $x\in \N$ having $f(x)=1$. But as noted in Example \ref{ex:notinj}, $g\circ f(x)=x$ for all $x\in\N$, which is clearly surjective.
}

As with Theorem \ref{T:compinj}, we have a partial converse, the proof of which is left as an exercise:

\begin{prop}
Let $X, Y, Z$ be sets, and let $f:X\to Y$ and $g:Y\to Z$ be functions. If $g\circ f$ is surjective, then $g$ is surjective.
\end{prop}

Now, let us prove Theorem \ref{T:compsur}.

\begin{proof}[Proof of Theorem \ref{T:compsur}
Let $f, g$ be as in the statement of the theorem, and suppose that $f$ and $g$ are surjective. 

Given $z\in Z$, there exists some $y\in Y$ such that $g(y)=z$, since $g$ is surjective. Moreover, since $f$ is surjective, there exists some $x\in X$ such that $f(x)=y$. We therefore have that $g\circ f(x)=g(f(x))=g(y)=z$, and hence, for any $z\in Z$, there exists some $x\in X$ such that $g\circ f(x)=z$. Therefore, $g\circ f$ is surjective.
\end{proof}

\section{Bijectivity and Inverses}

Now, let's consider the situation with injectivity and surjectivity pictorially. When we say a function is injective, what we mean is that if we look at the codomain, every element has at most one arrowhead touching it. When we say a function is surjective, what we mean is that if we look at the codomain, every element has at least one arrowhead touching it. But what happens if we have both? Well, then every element in the codomain would have at most and at least one arrowhead touching it.... that means EXACTLY one arrowhead. This is really convenient, since it gives us an obvious way to go back to the domain; just reverse every arrow! Because every element has exactly one arrowhead, this will yield a well-defined function (commonly called the inverse). Let's formalize some of these ideas.

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. We say that $f$ is {\it bijective} if $f$ is both injective and surjective.
\end{definition}

Another way of seeing this is that every element has exactly one preimage under $f$, as discussed above. To express that, we introduce the unique existential quantifier, hitherto unseen:

\begin{definition}
Let $p(x)$ be a proposition with range $X$. The proposition $\exists! x\in X, p(x)$ is true if $\exists x\in X, p(x)$ is true, and $\forall x_1, x_2\in X$, $x_1\neq x_2\ra \neg (p(x_1)\wedge p(x_2))$. That is to say, $p(x)$ cannot be true for two different values of $x$, so there is only one choice of $x\in X$ for which $p(x)$ is true. The symbol $\exists!$ is called the {\it unique existential quantifier}.
\end{definition}

\begin{prop}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. Then $f$ is bijective if and only if $\forall y\in Y, \exists! x\in X$ such that $f(x)=y$.
\end{prop}

The proof of this proposition is left as an exercise, but the two pieces of the unique existential quantifier appear due to the two properties we have. The fact of existence is given to us by surjectivity; the fact of uniqueness is given by injectivity. Without both, the statement falls apart.

By taking Theorems \ref{T:compinj} and \ref{T:compsur} together, we immediately have the following theorem:

\begin{theorem}
Let $X, Y, Z$ be sets, and let $f:X\to Y$ and $g:Y\to Z$ be functions. If $f$ and $g$ are bijective, then $g\circ f$ is bijective.
\end{theorem}

Of course, the converse is false, as the example seen in Examples \ref{ex:notinj} and \ref{ex:notsur} shows. In that case, we have that $g\circ f$ is both injective and surjective (hence bijective) even though neither $f$ nor $g$ is bijective. 

Now, as we hinted at the beginning of this section, our goal is really to construct a notion of inverse; we'd like to be able to reverse the direction of our arrows. Formally speaking, given a function $f$, we would like to be able to construct a function $g$ so that when we perform $f$ and then $g$ (aka $g\circ f$), we get back to where we started.

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. A function $g:Y\to X$ is called a {\it left inverse} to $f$ if $g\circ f\equiv\iota_X$. A function $h:Y\to X$ is called a {\it right inverse} to $f$ if $f\circ h \equiv \iota_Y$. A function from $Y$ to $X$ is called a {\it two-sided inverse}, or sometimes just {\it inverse}, to $f$ if it is both a left and right inverse.
\end{definition}


\begin{figure}[htp]
\centering
\begin{subfigure}{.45\textwidth}
\includegraphics[scale=.4]{leftinverse.pdf}
\caption{Here, $g$ is a left inverse to $f$. We can imagine that if we performed the red function, and then the blue, we would end up back where we started from. This is equivalent to the composition $g\circ f$. Hence, $g\circ f \equiv\iota_X$, meeting the definition of left inverse.}
\end{subfigure}
\hspace{.35in}
\begin{subfigure}{.45\textwidth}
\includegraphics[scale=.5]{rightinverse.pdf}
\caption{Here, $g$ is a right inverse to $f$. We can imagine that if we performed the blue function, and then the red, we would end up back where we started from. This is equivalent to the composition $f\circ g$. Hence, $f\circ g \equiv\iota_Y$, meeting the definition of right inverse.}
\end{subfigure}
\caption{}\label{fig:lrinv}
\end{figure}

\ex{\label{ex:linv}Let $f:\N\to\N$ be the function $f(x)=3x$. Then $f$ has a left inverse.

\begin{proof}
We wish to find a function $g$ so that $g\circ f\equiv \iota_\N$. Since $f$ maps any $x$ to $3x$, we would like that $g$ maps any $y$ that is divisible by 3 to $\frac y 3$. So we construct $g$ as follows: \[g(y)=\left\{\begin{array}{ll} \frac y 3 & \hbox{ if }3|y\\ 1 & \hbox{ if }3\not|y\end{array}\right.\]
Notice, then, that for any $x\in\N$, we have $g\circ f(x)=g(f(x))=g(3x)=x$, so $g\circ f\equiv \iota_\N$. Therefore, $g$ is a left inverse to $f$.
\end{proof}

Note that here, all we need to prove that a left inverse exists is to demonstrate it. Moreover, it's clear that this left inverse is not a right inverse: if we think about $f\circ g(4)$, we have that $g(4)=1$, since $4$ is not divisible by 3, so $f\circ g(4)=f(1)=3\neq 4$. Thus, $f\circ g \not\equiv \iota_\N$.
}

The approach for constructing a right inverse is similar; given a function $f:X\to Y$, we can construct a right inverse $g:Y\to X$ by trying to assign $g(y)=x$ in such a way that $f(x)=y$, that is, $g(y)\in \inv f(y)$.

The difference between a left and right inverse is illustrated in Figure \ref{fig:lrinv}. Notice the distinction: for a left inverse to exist, we can have extra points in $Y$ that $f$ does not interact with, so long as every point in the image of $f$ has the correct preimage. Notice also that we can't have more than one point in $X$ have the same image; if $f(x_1)=f(x_2)=y$, then how can we choose $g(y)$ to yield both $x_1$ and $x_2$? That is to say, in order that a left inverse exists, clearly we require that $f$ is an injective function.

In the same way, for the right inverse to exist, we want to be able to construct some $g$ so that $f\circ g\equiv\iota_Y$. In order that this is possible, we must have that all of $Y$ is part of the image of $f$, so that we can get to everywhere upon performing the composition. That is to say, in order that a right inverse exists, we clearly require that $f$ is a surjective function. 

Both of these characterizations are biconditional, and we have the following lemma:

\begin{lemma}\label{L:lrinv}
Let $X, Y$ be nonempty sets, and let $f:X\to Y$ be a function. Then
\begin{enumerate}
\item $f$ has a left inverse if and only if $f$ is injective
\item $f$ has a right inverse if and only if $f$ is surjective.
\end{enumerate}
\end{lemma}

\begin{proof}
Let $X, Y, f$ be as described. We prove the two properties separately.

\begin{enumerate}
\item As this is a biconditional, we consider each direction.

For the forward direction, suppose that $f$ has a left inverse $g$. Let $x_1, x_2\in X$ such that $f(x_1)=f(x_2)=y$. Let $x=g(y)$. Since $g$ is a left inverse to $f$, we have that $g\circ f \equiv \iota_X$, and hence $g\circ f(x_1)=x_1$, and $g\circ f(x_2)=x_2$. On the other hand, $g\circ f(x_1)=g(f(x_1))=g(y)$, and $g\circ f(x_2)=g(f(x_2))=g(y)$. Hence $x_1=g\circ f(x_1)=g(y)=g\circ f(x_2)=x_2$. Therefore, by definition, $f$ is injective.

For the backward direction, suppose that $f$ is injective. Let $x_0\in X$ be any point; note that some such $x_0$ exists since $X$ is presumed to be nonempty. Define a function $g:Y\to X$ as follows: for all $y\in Y$, if there exists $x\in X$ such that $f(x)=y$, then $g(y)=x$. If no such $x$ exists, then $g(y)=x_0$.

We first verify that $g$ is a well-defined function. Note that for all $y\in Y$, either there exists $x\in X$ with $f(x)=y$, or there does not; hence $g$ is totally defined. Since $g(y)$ is a member of $X$ for each $y$ by definition, we satisfy the existence property. Finally, since $f$ is injective, for each $y$ there is at most one choice of $x$ for which $f(x)=y$, and thus $g$ satisfies the uniqueness property. Therefore, $g$ is a well-defined function.

Moreover, $\forall x\in X,\ g\circ f(x)=g(f(x))=x$, by definition of $g$, so $g\circ f\equiv\iota_X$. Therefore, $g$ is a left inverse to $f$, so a left inverse therefore exists.

As both directions hold, we therefore have that $f$ has a left inverse if and only if $f$ is injective.

\item As with part 1, we consider the two directions.

For the forward direction, suppose that $f$ has a right inverse $g$. Let $y\in Y$, and let $x=g(y)$. Then we have $f(x)=f(g(y))=f\circ g(y)=\iota_Y(y)=y$, and hence for every $y\in Y$ there is an $x\in X$ with $f(x)=y$. Therefore, $f$ is surjective.

For the backward direction\footnote{WARNING! The following argument relies on the Axiom of Choice. In fact, the statement we claim here cannot be proven without the Axiom of Choice. At some point, I will go into the details about this, probably, but that point is not here and now.}, suppose that $f$ is surjective. Define a function $g:Y\to X$ as follows. For any $y\in Y$, define $g(y)$ to be any member of $f^{-1}(y)$. Again, we verify the well-definedness of $g$.

Since for each $y\in Y$, there is at least one $x\in X$ having $f(x)=y$, we have that for every $y\in Y$, $\inv f(y)$ is nonempty, and hence there is a point in $\inv f(y)$ that can be chosen as the image of $y$ under $g$. Hence, $g$ is totally defined, and existence is also verified. Since we explicitly choose one such point, uniqueness is implied by definition (that is not to say this functio is the only possible right inverse, but it is to say that once we choose the image of $y$ under $g$, it is uniquely chosen).

Hence, $g$ is a well-defined function. Moreover, for any $y\in Y$, we have that $f\circ g(y) = y$, since $g(y)\in f^{-1}(y)$. Therefore, $g$ is a right inverse to $f$, so a right inverse therefore exists.

As both directions hold, we therefore have that $f$ has a right inverse if and only if $f$ is surjective.
\end{enumerate}
\end{proof}

Using this lemma, we have two options for showing if something has a left or right inverse. We could work as in Example \ref{ex:linv}, and demonstrate the actual left/right inverse. Or, we could simply check if the function is injective or surjective, respectively, and conclude from the lemma that it is sufficient to guarantee the existence of a left/right inverse, without actually demonstrating what the inverse might look like. Consider the following example.

\ex{Let $h:\Q\to\Q$ be defined by $h(q)=2q$. Then $h$ has a left inverse and a right inverse.

\begin{proof}
First, for the left inverse, we consider injectivity of $h$. Suppose that $q_1, q_2\in \Q$ with $h(q_1)=h(q_2)$. Then $2q_1=2q_2\ra q_1=q_2$, and hence $h$ is injective. By Lemma \ref{L:lrinv}, then, $h$ has a left inverse.

Second, for the right inverse, we consider surjectivity of $h$. Suppose that $r\in \Q$. Then $h(\frac r 2)=r$, and hence $h$ is surjective. Therefore, by Lemma \ref{L:lrinv}, $h$ has a right inverse.
\end{proof}}

By using injectivity and surjectivity, we can verify that the left and right inverse exist, without having to explicitly construct them. This can be very useful, as sometimes explicit constructions of inverses are hard.

Now, what we'd truly like is a two-sided inverse: a function $g$ so that $g\circ f\equiv \iota_X$ and $f\circ g\equiv \iota_Y$. Then we could go back and forth between $X$ and $Y$ willy-nilly. Lemma \ref{L:lrinv} tells us that in order that $f$ has both a left and right inverse, we need that $f$ is both injective and surjective; that is, we need that $f$ is bijective. Indeed, we have the following theorem:

\begin{theorem}\label{T:bijinv}
Let $X$ and $Y$ be sets, and let $f:X\to Y$ be a function. Then $f$ has a two-sided inverse if and only if $f$ is bijective.
\end{theorem}

Lemma \ref{L:lrinv} is almost enough to give us this theorem, but we need one more piece of information. In order to have an inverse, we must have that the left and right inverse are the same; that is, we need the SAME function to work as both a left and right inverse. Lemma \ref{L:lrinv} only tells us that there are functions for each side, so we will also require the following lemma, that these two functions are in fact the same.

\begin{lemma}\label{L:lrequal}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function. If $f$ has a left inverse $g$ and a right inverse $h$, then $g\equiv h$.
\end{lemma}

\begin{proof}
Suppose that $f$ has a left inverse $g$ and a right inverse $h$. Then we have
\begin{eqnarray*}
g & \equiv & g\circ \iota_Y\\
& \equiv & g\circ (f\circ h)\quad \hbox{ (since $h$ is a right inverse to $f$, so $f\circ h\equiv \iota_Y$)}\\
& \equiv & (g\circ f)\circ h\quad\hbox{ (by Theorem \ref{T:associativity})}\\
& \equiv & \iota_X\circ h\quad\hbox{ (since $g$ is a left inverse to $f$, so $g\circ f\equiv \iota_X$)}\\
& \equiv & h.
\end{eqnarray*}
\end{proof}

We are now ready to combine these properties to prove Theorem \ref{T:bijinv}.

\begin{proof}[Proof of Theorem \ref{T:bijinv}]
Let $X$ and $Y$ be sets, and let $f:X\to Y$ be a function. We consider each direction.

First, suppose that $f$ is bijective. Then by definition, $f$ is both injective and surjective, so by Lemma \ref{L:lrinv}, we have that $f$ has a left inverse $g$ and $f$ has a right inverse $h$. By Lemma \ref{L:lrequal}, we have that $g\equiv h$, and hence $g$ is both a left and right inverse to $f$. But then, by definition, $f$ has a two-sided inverse.

On the other hand, suppose that $f$ has a two-sided inverse $g$. But then by definition, $g$ is both a left and right inverse, and hence by Lemma \ref{L:lrinv}, we have that $f$ is both injective and surjective. Therefore, $f$ is bijective.
\end{proof}

Now, to determine if a function $f$ has an inverse, we have two options. We can either explicitly demonstrate an inverse $g$, and show that both $f\circ g$ and $g\circ f$ are equivalent to identity functions, or we can show that $f$ is bijective.

\ex{Show that $f:\R\to\R$ defined by $f(x)=(x-2)^3$ has an inverse.

We shall show this in two ways, as described above.

\begin{proof}[Proof 1]
Define $g:\R\to\R$ by $g(x)=\sqrt[3]x+2$. Recalling that the cube root of any real number is both defined and unique, we have that $g$ is a well-defined function. Moreover, $g\circ f(x)=g((x-2)^3) = \sqrt[3]{(x-2)^3}+2 = x$, so $g\circ f \equiv \iota_\R$. Also, $f\circ g(x)=f(\sqrt[3]x+2)=(\sqrt[3]x+2-2)^3 = x$, so $f\circ g \equiv \iota_\R$.

Therefore, since $g$ is an inverse to $f$, we must have that $f$ has an inverse.
\end{proof}

\begin{proof}[Proof 2]
We prove that $f$ is invertible by demonstrating that $f$ is bijective.

For injectivity, suppose that $x_1, x_2\in\R$ and $f(x_1)=f(x_2)$. Then $(x_1-2)^3=(x_2-2)^3$. Since the cube root of any real number is defined and unique, we can take a cube root on both sides of this equation to conclude $x_1-2=x_2-2$, and hence $x_1=x_2$. Therefore, $f$ is injective.

For surjectivity, suppose that $y\in\R$. Let $x=\sqrt[3]y+2$. Then $f(x)=y$, and hence $f$ is surjective.

As $f$ is both injective and surjective, it has an inverse.
\end{proof}
}

Finally, a bit more notation.

\begin{definition}
Let $X, Y$ be sets, and let $f:X\to Y$ be a function having an inverse. We say that $f$ is {\it invertible}, and we use the notation $\inv f$ to denote the inverse of $f$.
\end{definition}

We note that in order to define ``the'' inverse of $f$, we should be careful that there is only one such number. This is a corollary of Lemma \ref{L:lrequal}; if $f$ has two different inverses, we can show they are the same by treating one of them as a left inverse and the other as a right inverse.

\begin{cor}
Let $f:X\to Y$ be an invertible function. If $g, h$ are both inverses of $f$, then $g\equiv h$.
\end{cor}

Lastly, just a word about notation. It is true that we use the same notation to denote the inverse function of $f$ and the inverse image of subsets of $Y$. This is, of course, awful. From context, though, the two should be distinguishable; one of them takes only sets as input, and the other takes only elements as input. The reason that the notation repeats is that these two things look very similar on singleton sets (if the inverse exists). Indeed, if $f:X\to Y$ is an invertible function, then we have that $\forall y\in Y$, $\inv f(\{y\}) = \{\inv f(y)\}$; that is, the preimage on the singleton set $\{y\}$ is the set containing the single element which is $\inv f(y)$. Note the distinction on the inputs as well; when we mean to take a preimage, we input a set into $\inv f$. When we mean to take it as a function, we input an element.

\end{document}