\chapter{Metric spaces}
\label{ch:metric_space}
At the time of writing, I'm convinced that metric topology is
the morally correct way to motivate point-set topology
as well as to generalize normal calculus.\footnote{Also,
``metric'' is a fun word to say.}
So here is my best attempt.

The concept of a metric space is very ``concrete'', and lends itself easily to visualization.
Hence throughout this chapter you should draw lots of pictures as you learn about new objects,
like convergent sequences, open sets, closed sets, and so on.

\section{Definition and examples of metric spaces}
\prototype{$\RR^2$, with the Euclidean metric.}
\begin{definition}
	A \vocab{metric space} is a pair $(M, d)$ consisting of
	a set of points $M$
	and a \vocab{metric} $d \colon M \times M \to \mathbb R_{\ge 0}$.
	The distance function must obey:
	\begin{itemize}
		\ii For any $x,y \in M$, we have $d(x,y) = d(y,x)$; i.e.\ $d$ is symmetric.
		\ii The function $d$ must be \vocab{positive definite}
		which means that $d(x,y) \ge 0$ with equality if and only if $x=y$.
		\ii The function $d$ should satisfy the \vocab{triangle inequality}: for all $x,y,z \in M$,
		\[ d(x,z) + d(z,y) \ge d(x,y). \]
	\end{itemize}
\end{definition}
\begin{abuse}
	Just like with groups, we will abbreviate $(M,d)$ as just $M$.
\end{abuse}
\begin{example}[Metric spaces of $\RR$]
	\listhack
	\begin{enumerate}[(a)]
		\ii The real line $\RR$ is a metric space under the metric $d(x,y) = \left\lvert x-y \right\rvert$.
		\ii The interval $[0,1]$ is also a metric space with the same distance function.
		\ii In fact, any subset $S$ of $\RR$ can be made into a metric space in this way.
	\end{enumerate}
\end{example}
\begin{example}[Metric spaces of $\RR^2$]
	\listhack
	\begin{enumerate}[(a)]
		\ii We can make $\RR^2$ into a metric space by imposing the Euclidean distance function
		\[ d\left( (x_1, y_1), (x_2, y_2) \right) = \sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}. \]
		\ii Just like with the first example, any subset of $\RR^2$ also becomes a metric space after we inherit it.
		The unit disk, unit circle, and the unit square $[0,1]^2$
		are special cases.
	\end{enumerate}
\end{example}
\begin{example}[Taxicab on $\RR^2$]
	It is also possible to place the \vocab{taxicab distance} on $\RR^2$:
	\[ d\left( (x_1, y_1), (x_2, y_2) \right) =
		\left\lvert x_1-x_2 \right\rvert + \left\lvert y_1-y_2 \right\rvert.
		\]
	For now, we will use the more natural Euclidean metric.
\end{example}

\begin{example}[Metric spaces of $\RR^n$]
	We can generalize the above examples easily.
	Let $n$ be a positive integer.
	\begin{enumerate}[(a)]
		\ii We let $\RR^n$ be the metric space whose points are points in $n$-dimensional Euclidean space,
		and whose metric is the Euclidean metric
		\[
			d\left(
			\left( a_1, \dots, a_n \right), \left( b_1, \dots, b_n \right)
			\right)
			= \sqrt{(a_1-b_1)^2 + \dots + (a_n-b_n)^2}.
		\]
		This is the $n$-dimensional \vocab{Euclidean space}.
		\ii The open \vocab{unit ball} $B^{n}$ is the subset of $\RR^n$
		consisting of those points $\left( x_1, \dots, x_n \right)$
		such that $x_1^2 + \dots + x_n^2 < 1$.
		\ii The \vocab{unit sphere} $S^{n-1}$ is the subset of $\RR^n$
		consisting of those points $\left( x_1, \dots, x_n \right)$
		such that $x_1^2 + \dots + x_n^2 = 1$, with the inherited metric.
		(The superscript $n-1$ indicates that $S^{n-1}$ is an $n-1$ dimensional space,
		even though it lives in $n$-dimensional space.)
		For example, $S^1 \subseteq \RR^2$ is the unit circle,
		whose distance between two points is the length of the chord joining them.
		You can also think of it as the ``boundary'' of the unit ball $B^n$.
	\end{enumerate}
\end{example}
\begin{example}
	[Function space]
	We can let $M$ be the space of
	continuous functions $f \colon [0,1] \to \RR$ and define the metric
	by $d(f,g) = \int_0^1 \left\lvert f-g \right\rvert \; dx$.
	(It admittedly takes some work to check $d(f,g) = 0$ implies $f=g$,
	but we won't worry about that yet.)
\end{example}

Here is a slightly more pathological example.
\begin{example}
	[Discrete space]
	Let $S$ be any set of points (either finite or infinite).
	We can make $S$ into a \vocab{discrete space} by declaring
	\[
		d(x,y)
		=
		\begin{cases}
			1 & \text{if $x \neq y$} \\
			0 & \text{if $x = y$}.
		\end{cases}
	\]
	If $\left\lvert S \right\rvert = 4$ you might think of this space
	as the vertices of a regular tetrahedron, living in $\RR^3$.
	But for larger $S$ it's not so easy to visualize\dots
\end{example}
\begin{example}[Graphs are metric spaces]
	Any connected simple graph $G$ can be made into a metric space
	by defining the distance between two vertices to be the
	graph-theoretic distance between them.
	(The discrete metric is the special case when $G$ is the complete graph on $S$.)
\end{example}
\begin{ques}
	Check the conditions of a metric space for the metrics on the discrete space
	and for the connected graph.
\end{ques}

\begin{abuse}
	From now on, we will refer to $\RR^n$ with the Euclidean metric
	by just $\RR^n$.
	Moreover, if we wish to take the metric space for a subset $S \subseteq \RR^n$
	with the inherited metric, we will just write $S$.
\end{abuse}

\section{Convergence in metric spaces}
\prototype{The sequence $\frac1n$ (for $n=1,2,\dots$) in $\RR$.}

Since we can talk about the distance between two points, we can talk about what it means for a sequence of points to converge.
This is the same as the typical epsilon-delta definition, with absolute values replaced by the distance function.

\begin{definition}
	Let $(x_n)_{n \ge 1}$ be a sequence of points in a metric space $M$.
	We say that $x_n$ \vocab{converges} to $x$ if the following condition holds:
	for all $\eps > 0$, there is an integer $N$ (depending on $\eps$)
	such that $d(x_n, x) < \eps$ for each $n \ge N$.
	This is written \[ x_n \to x \] or more verbosely as \[ \lim_{n \to \infty} x_n = x. \]
	We say that a sequence converges in $M$ if it converges to a point in $M$.
\end{definition}
You should check that this definition coincides with your intuitive notion of ``converges''.
\begin{abuse}
	If the parent space $M$ is understood, we will allow ourselves
	to abbreviate ``converges in $M$'' to just ``converges''.
	However, keep in mind that convergence is defined relative to the parent space;
	the ``limit'' of the space must actually be a point in $M$ for a sequence to converge.
\end{abuse}

\begin{center}
	\begin{asy}
		size(9cm);
		Drawing("x_1", (-9,0.1), dir(90));
		Drawing("x_2", (-6,0.8), dir(90));
		Drawing("x_3", (-5,-0.3), dir(90));
		Drawing("x_4", (-2, 0.8), dir(90));
		Drawing("x_5", (-1.7, -0.7), dir(-90));
		Drawing("x_6", (-0.6, -0.3), dir(225));
		Drawing("x_7", (-0.4, 0.3), dir(90));
		Drawing("x_8", (-0.25, -0.24), dir(-90));
		Drawing("x_9", (-0.12, 0.1), dir(45));
		dot("$x$", (0,0), dir(-45), blue);
		draw(CR(origin, 1.5), blue+dashed);
	\end{asy}
\end{center}

\begin{example}
	Consider the sequence
	$x_1 = 1$, $x_2 = 1.4$, $x_3 = 1.41$, $x_4 = 1.414$, \dots.
	\begin{enumerate}[(a)]
		\ii If we view this as a sequence in $\RR$, it converges to $\sqrt 2$.
		\ii However, even though each $x_i$ is in $\QQ$,
		this sequence does NOT converge when we view it as a sequence in $\QQ$!
	\end{enumerate}
\end{example}

\begin{ques}
	What are the convergent sequences in a discrete metric space?
\end{ques}

\section{Continuous maps}
In calculus you were also told (or have at least heard)
of what it means for a function to be continuous.
Probably something like
\begin{quote}
	A function $f \colon \RR \to \RR$
	is continuous at a point $p \in \RR$
	if for every $\eps > 0$ there exists a $\delta > 0$ such that
	$\left\lvert x-p \right\rvert < \delta
		\implies
		\left\lvert f(x) - f(p) \right\rvert < \eps$.
\end{quote}
\begin{ques}
	Can you guess what the corresponding definition for metric spaces is?
\end{ques}

All we have to do is replace the absolute values with the more general distance functions:
this gives us a definition of continuity for any function $M \to N$.

\begin{definition}
	Let $M = (M, d_M)$ and $N = (N, d_N)$ be metric spaces.
	A function $f \colon M \to N$ is \vocab{continuous}
	at a point $p \in M$
	if for every $\eps > 0$ there exists a $\delta > 0$ such that
	\[ d_M(x,p) < \delta \implies d_N(f(x), f(p)) < \eps. \]
	Moreover, the entire function $f$ is continuous
	if it is continuous at every point $p \in M$.
\end{definition}
Notice that, just like in our definition of an isomorphism of a group,
we use the metric of $M$ for one condition
and the metric of $N$ for the other condition.

This generalization is nice because it tells us immediately how we could carry over continuity arguments in $\RR$ to more general spaces like $\CC$.
Nonetheless, this definition is kind of cumbersome to work with,
because it makes extensive use of the real numbers
(epsilons and deltas).
Here is an equivalent condition.
\begin{theorem}[Sequential continuity]
	\label{thm:seq_cont}
	A function $f \colon M \to N$ of metric spaces
	is continuous at a point $p \in M$
	if and only if the following property holds:
	for every sequence $x_1$, $x_2$, \dots\ in $M$ converging to $p$,
	the sequence $f(x_1)$, $f(x_2)$, \dots\ in $N$ converges to $f(p)$.
\end{theorem}
\begin{proof}
	One direction is not too hard:
	\begin{exercise}
		Show that $\eps$-$\delta$ continuity implies sequential continuity
		at each point.
	\end{exercise}
	Conversely, we will prove if $f$ is not $\eps$-$\delta$ continuous at $p$
	then it does not preserve convergence.

	If $f$ is not continuous at $p$, then there is a ``bad'' $\eps > 0$,
	which we now consider fixed.
	So for each choice of $\delta = 1/n$,
	there should be some point $x_n$ which is within $\delta$ of $p$,
	but which is mapped more than $\eps$ away from $f(p)$.
	But then the sequence $x_n$ converges to $p$,
	and $f(x_n)$ is always at least $\eps$ away from $f(p)$, contradiction.
\end{proof}

Example application showcasing the niceness of sequential continuity:
\begin{proposition}[Composition of continuous functions is continuous]
	Let $f \colon M \to N$ and $g \colon N \to L$ be continuous maps of metric spaces.
	Then their composition $g \circ f$ is continuous.
\end{proposition}
\begin{proof}
	Dead simple with sequences:
	Let $p \in M$ be arbitrary and let $x_n \to p$ in $M$.
	Then $f(x_n) \to f(p)$ in $N$ and $g(f(x_n)) \to g(f(p))$ in $L$, QED.
\end{proof}

\begin{ques}
	Let $M$ be any metric space and $D$ a discrete space.
	When is a map $f \colon D \to M$ continuous?
\end{ques}



\section{Homeomorphisms}
\prototype{The unit circle $S^1$ is homeomorphic to the boundary of the unit square.}

When do we consider two groups to be the same?
Answer: if there's a structure-preserving map
between them which is also a bijection.
For metric spaces, we do exactly the same thing,
but replace ``structure-preserving'' with ``continuous''.

\begin{definition}
	Let $M$ and $N$ be metric spaces.
	A function $f \colon M \to N$ is a
	\vocab{homeomorphism} if it is a bijection,
	and both $f \colon M \to N$
	and its inverse $f\inv \colon N \to M$ are continuous.
	We say $M$ and $N$ are \vocab{homeomorphic}.
\end{definition}
Needless to say, homeomorphism is an equivalence relation.

You might be surprised that we require $f\inv$ to also be continuous.
Here's the reason: you can show that if $\phi$ is
an isomorphism of groups, then $\phi\inv$ also preserves the group operation,
hence $\phi\inv$ is itself an isomorphism.
The same is not true for continuous bijections,
which is why we need the new condition.
\begin{example}
	[Homeomorphism $\neq$ continuous bijection]
	\listhack
	\begin{enumerate}[(a)]
		\ii There is a continuous bijection
		from $[0,1)$ to the circle, % chktex 9
		but it has no continuous inverse.
		\ii Let $M$ be a discrete space with size $|\RR|$.
		Then there is a continuous function $M \to \RR$
		which certainly has no continuous inverse.
	\end{enumerate}
\end{example}

Note that this is the topologist's definition of ``same'' --
homeomorphisms are ``continuous deformations''.
Here are some examples.

\begin{example}[Examples of homeomorphisms]
	\listhack
	\begin{enumerate}[(a)]
		\ii Any space $M$ is homeomorphic to itself
		through the identity map.
		\ii The old saying: a doughnut (torus) is
		homeomorphic to a coffee cup.
		(Look this up if you haven't heard of it.)
		\ii The unit circle $S^1$ is homeomorphic
		to the boundary of the unit square.
		Here's one bijection between them, after an appropriate scaling:
		\begin{center}
			\begin{asy}
				size(1.5cm);
				draw(unitcircle);
				pair A = (1.4, 1.4);
				pair B = rotate(90)*A;
				pair C = rotate(90)*B;
				pair D = rotate(90)*C;
				draw(A--B--C--D--cycle);
				dot(origin);
				pair P = Drawing(dir(70));
				pair Q = Drawing(extension(origin, P, A, B));
				draw(origin--Q, dashed);
			\end{asy}
		\end{center}
	\end{enumerate}
\end{example}
\begin{example}
	[Metrics on the unit circle]
	It may have seemed strange that our metric function on $S^1$
	was the one inherited from $\RR^2$,
	meaning the distance between two points
	on the circle was defined to be the length of the chord.
	Wouldn't it have made more sense to use the circumference of the
	smaller arc joining the two points?

	In fact, it doesn't matter:
	if we consider $S^1$ with the ``chord'' metric
	and the ``arc'' metric, we get two homeomorphic spaces,
	as the map between them is continuous.

	The same goes for $S^{n-1}$ for general $n$.
\end{example}

\begin{example}
	[Homeomorphisms really don't preserve size]
	Surprisingly, the open interval $(-1,1)$
	is homeomorphic to the real line $\RR$!
	One bijection is given by
	\[ x \mapsto \tan(x \pi/2) \]
	with the inverse being given by $t \mapsto \frac2\pi \arctan(t)$.

	This might come as a surprise,
	since $(-1,1)$ doesn't look that much like $\RR$;
	the former is ``bounded'' while the latter is ``unbounded''.
\end{example}

\section{Extended example/definition: product metric}
\prototype{$\RR \times \RR$ is $\RR^2$.}

Here is an extended example which will occur later on.
Let $M = (M, d_M)$ and $N = (N, d_N)$ be metric spaces (say, $M = N = \RR$).
Our goal is to define a metric space on $M \times N$.

Let $p_i = (x_i,y_i) \in M \times N$ for $i=1,2$.
Consider the following metrics on the set of points $M \times N$:
\begin{align*}
	d_{\text{max}} ( p_1, p_2 )
		&\defeq \max \left\{ d_M(x_1, x_2), d_N(y_1, y_2) \right\}  \\
	d_{\text{Euclid}} ( p_1, p_2 )
		&\defeq \sqrt{d_M(x_1,x_2)^2 + d_N(y_1, y_2)^2} \\
	d_{\text{taxicab}} \left( p_1, p_2 \right)
		&\defeq d_M(x_1, x_2) + d_N(y_1, y_2).
\end{align*}
All of these are good candidates.
We are about to see it doesn't matter which one we use:
\begin{exercise}
Verify that
\[ d_{\text{max}}(p_1,p_2)
	\le d_{\text{Euclid}}(p_1, p_2)
	\le d_{\text{taxicab}}(p_1, p_2)
	\le 2d_{\text{max}}(p_1, p_2). \]
Use this to show that the metric spaces we obtain
by imposing any of the three metrics are homeomorphic,
with the homeomorphism being just the identity map.
\end{exercise}

\begin{definition}
	Hence we will usually simply refer to
	\emph{the} metric on $M \times N$,
	called the \vocab{product metric}.
	It will not be important which of the three metrics we select.
\end{definition}

\begin{example}[$\RR^2$]
	If $M = N = \RR$, we get $\RR^2$, the Euclidean plane.
	The metric $d_{\text{Euclid}}$ is the one we started with,
	but using either of the other two metrics works fine as well.
\end{example}

The product metric plays well with convergence of sequences.
\begin{proposition}
	[Convergence in the product metric is by component]
	We have $(x_n, y_n) \to (x,y)$
	if and only if $x_n \to x$ and $y_n \to y$.
\end{proposition}
\begin{proof}
	We have $d_{\text{max}} \left( (x,y), (x_n, y_n) \right)
	= \max\left\{ d_M(x, x_n), d_N(y, y_n) \right\}$
	and the latter approaches zero as $n \to \infty$
	if and only if $d_M(x,x_n) \to 0$ and $d_N(y, y_n) \to 0$.
\end{proof}

Let's see an application of this:
\begin{proposition}
	[Addition and multiplication are continuous]
	\label{prop:arithmetic_continuous}
	The addition and multiplication maps
	are continuous maps $\RR \times \RR \to \RR$.
\end{proposition}
\begin{proof}
	For multiplication: for any $n$ we have
	\begin{align*}
		x_n y_n &= \left( x + (x_n-x) \right)
		\left( y + (y_n-y) \right) \\
		&= xy + y(x_n-x) + x(y_n-y) + (x_n-x)(y_n-y) \\
		\implies \left\lvert x_n y_n - xy \right\rvert
		&\le \left\lvert y \right\rvert
			\left\lvert x_n - x \right\rvert
		+ \left\lvert x \right\rvert
			\left\lvert y_n - y \right\rvert
		+ \left\lvert x_n - x \right\rvert
			\left\lvert y_n - y \right\rvert.
	\end{align*}
	As $n \to \infty$, all three terms on the
	right-hand side tend to zero.
	The proof that $+ \colon \RR \times \RR \to \RR$ is continuous
	is similar (and easier): one notes for any $n$ that
	\[ |(x_n + y_n) - (x+y)| \le |x_n-x| + |y_n-y| \]
	and both terms on the right-hand side
	tend to zero as $n \to \infty$.
\end{proof}
\Cref{prob:subtract_divide} covers the other two operations,
subtraction and division.
The upshot of this is that, since compositions are also continuous,
most of your naturally arising real-valued functions
will automatically be continuous as well.
For example, the function $\frac{3x}{x^2+1}$
will be a continuous function from $\RR \to \RR$,
since it can be obtained by composing $+$, $\times$, $\div$.

\section{Open sets}
\prototype{The open disk $x^2+y^2<r^2$ in $\RR^2$.}

Continuity is really about what happens ``locally'':
how a function behaves ``close to a certain point $p$''.
One way to capture this notion of ``closeness''
is to use metrics as we've done above.
In this way we can define an $r$-neighborhood of a point.

\begin{definition}
	Let $M$ be a metric space.
	For each real number $r > 0$ and point $p \in M$, we define
	\[ M_r(p) \defeq \left\{ x \in M: d(x,p) < r \right\}. \]
	The set $M_r(p)$ is called an \vocab{$r$-neighborhood} of $p$.
\end{definition}
\begin{center}
	\begin{asy}
		size(4cm);
		bigblob("$M$");
		pair p = Drawing("p", (0.3,0.1), dir(-90));
		real r = 1.8;
		draw(CR(p,r), dashed);
		label("$M_r(p)$", p+r*dir(-65), dir(-65));
		draw(p--(p+r*dir(130)));
		label("$r$", midpoint(p--(p+r*dir(130))), dir(40));
	\end{asy}
\end{center}

We can rephrase convergence more succinctly in terms of $r$-neighborhoods.
Specifically, a sequence $(x_n)$ converges to $x$
if for every $r$-neighborhood of $x$,
all terms of $x_n$ eventually stay within that $r$-neighborhood.

Let's try to do the same with functions.
\begin{ques}
	In terms of $r$-neighborhoods,
	what does it mean for a function $f \colon M \to N$
	to be continuous at a point $p \in M$?
\end{ques}

Essentially, we require that the pre-image of every $\eps$-neighborhood has
the property that some $\delta$-neighborhood exists inside it.
This motivates:
\begin{definition}
	A set $U \subseteq M$ is \vocab{open} in $M$
	if for each $p \in U$, some $r$-neighborhood of $p$
	is contained inside $U$.
	In other words, there exists $r>0$ such that $M_r(p) \subseteq U$.
\end{definition}
\begin{abuse}
	Note that a set being open is defined
	\emph{relative to} the parent space $M$.
	However, if $M$ is understood we can abbreviate
	``open in $M$'' to just ``open''.
\end{abuse}

\begin{figure}[ht]
	\centering
	\begin{asy}
		size(5cm);
		draw(unitcircle, dashed);
		pair P = Drawing("p", (0.6,0.2), dir(-90));
		draw(CR(P, 0.3), dotted);
		MP("x^2+y^2<1", dir(45), dir(45));
	\end{asy}
	\caption{The set of points $x^2+y^2<1$ in $\RR^2$ is open in $\RR^2$.}
	\label{fig:example_open}
\end{figure}

\begin{example}[Examples of open sets]
	\listhack
	\begin{enumerate}[(a)]
		\ii Any $r$-neighborhood of a point is open.
		\ii Open intervals of $\RR$ are open in $\RR$, hence the name!
		This is the prototypical example to keep in mind.
		\ii The open unit ball $B^n$ is open in $\RR^n$ for the same reason.
		\ii In particular, the open interval $(0,1)$ is open in $\RR$.
		However, if we embed it in $\RR^2$, it is no longer open!
		\ii The empty set $\varnothing$ and the whole set of points $M$ are open in $M$.
	\end{enumerate}
\end{example}
\begin{example}
	[Non-examples of open sets]
	\listhack
	\begin{enumerate}[(a)]
		\ii The closed interval $[0,1]$ is not open in $\RR$.
		There is no $\eps$-neighborhood of the point $0$
		which is contained in $[0,1]$.
		\ii The unit circle $S^1$ is not open in $\RR^2$.
	\end{enumerate}
\end{example}
\begin{ques}
	What are the open sets of the discrete space?
\end{ques}

Here are two quite important properties of open sets.
\begin{proposition}
	[Intersections and unions of open sets]
	\listhack
	\begin{enumerate}[(a)]
		\ii The intersection of finitely many open sets is open.
		\ii The union of open sets is open, even if there are infinitely many.
	\end{enumerate}
\end{proposition}
\begin{ques}
	Convince yourself this is true.
\end{ques}
\begin{exercise}
	Exhibit an infinite collection of open sets in $\RR$
	whose intersection is the set $\{0\}$.
	This implies that infinite intersections of open sets are not necessarily open.
\end{exercise}

The whole upshot of this is:
\begin{theorem}[Open set condition]
	\label{thm:open_set}
	A function $f \colon M \to N$ of metric spaces is continuous
	if and only if the pre-image of every open set in $N$ is open in $M$.
\end{theorem}
\begin{proof}
	I'll just do one direction\dots
	\begin{exercise}
		Show that $\delta$-$\eps$ continuity follows from
		the open set condition.
	\end{exercise}
	Now assume $f$ is continuous.
	First, suppose $V$ is an open subset of the metric space $N$;
	let $U = f\pre(V)$. Pick $x \in U$, so $y = f(x) \in V$; we want an
	open neighborhood of $x$ inside $U$.

	\begin{center}
		\begin{asy}
			size(12cm);
			bigblob("$N$");
			pair Y = Drawing("y", origin, dir(75));
			real eps = 1.5;
			draw(CR(Y, eps), dotted);
			label("$\varepsilon$", Drawing(Y--(Y+eps*dir(255))));
			label("$V$",
				Drawing(shift(-0.5,0)*rotate(190)*scale(3.2,2.8)*unitcircle, dashed));
			add(shift( (13,0) ) * CC());
			label("$f$", Drawing( (4.5,0)--(8,0), EndArrow));

			bigblob("$M$");
			real delta = 1.1;
			pair X = Drawing("x", (-1.5,-0.5), dir(-45));
			label("$\delta$", Drawing(X--(X+delta*dir(155))));
			draw(CR(X, delta), dotted);
			label("$U = f^{\text{pre}}(V)$",
				Drawing(shift(-1.5,-0.3)*rotate(235)*scale(2.4,1.8)*unitcircle, dashed));
		\end{asy}
	\end{center}

	As $V$ is open, there is some small $\eps$-neighborhood around $y$
	which is contained inside $V$.
	By continuity of $f$, we can find a $\delta$ such that the $\delta$-neighborhood
	of $x$ gets mapped by $f$ into the $\eps$-neighborhood in $N$,
	which in particular lives inside $V$.
	Thus the $\delta$-neighborhood lives in $U$, as desired.
\end{proof}

%From this we can get a new definition of homeomorphism
%which makes it clear why open sets are good things to consider.
%\begin{theorem}
%	[Open set formulation of homeomorphism]
%	A function $f \colon M \to N$ of metric spaces is a
%	homeomorphism if and only if
%	\begin{enumerate}[(i)]
%		\ii It is a bijection of the underlying points.
%		\ii It induces a bijection of the open sets of $M$ and $N$:
%		for any open set $U \subseteq M$ the set $f\im(U)$ is open,
%		and for any open set $V \subseteq N$ the set $f\pre(V)$ is open.
%	\end{enumerate}
%\end{theorem}

\section{Closed sets}
\prototype{The closed unit disk $x^2+y^2 \le r^2$ in $\RR^2$.}
It would be criminal for me to talk about open sets
without talking about closed sets.
The name ``closed'' comes from the definition in a metric space.
\begin{definition}
	Let $M$ be a metric space.
	A subset $S \subseteq M$ is \vocab{closed} in $M$ if the following property holds:
	let $x_1$, $x_2$, \dots\ be a sequence of points in $S$
	and suppose that $x_n$ converges to $x$ in $M$.
	Then $x \in S$ as well.
\end{definition}
\begin{abuse}
	Same caveat: we abbreviate ``closed in $M$'' to just ``closed''
	if the parent space $M$ is understood.
\end{abuse}
Here's another way to phrase it.
The \vocab{limit points} of a subset $S \subseteq M$ are defined by
\[ \lim S \defeq \left\{ p \in M :
	\exists (x_n) \in S \text{ such that } x_n \to p \right\}. \]
Thus $S$ is closed if and only if $S = \lim S$.

\begin{exercise}
	Prove that $\lim S$ is closed even if $S$ isn't closed. (Draw a picture.)
\end{exercise}
For this reason, $\lim S$ is also called the
\vocab{closure} of $S$ in $M$, and denoted $\ol S$.
It is simply the smallest closed set which contains $S$.

\begin{example}
	[Examples of closed sets]
	\listhack
	\begin{enumerate}[(a)]
		\ii The empty set $\varnothing$ is closed in $M$ for vacuous reasons:
		there are no sequences of points with elements in $\varnothing$.
		\ii The entire space $M$ is closed in $M$ for tautological reasons.
		(Verify this!)
		\ii The closed interval $[0,1]$ in $\RR$ is closed in $\RR$, hence the name.  Like with open sets, this is the prototypical example of a closed set to keep in mind!
		\ii In fact, the closed interval $[0,1]$ is even closed in $\RR^2$.
	\end{enumerate}
\end{example}
\begin{example}
	[Non-example of closed sets]
	Let $S=(0,1)$ denote the open interval.
	Then $S$ is not closed in $\RR$
	because the sequence of points
	\[
		\frac12, \;
		\frac14, \;
		\frac18, \;
		\dots
	\]
	converges to $0 \in \RR$, but $0 \notin (0,1)$.
\end{example}

I should now warn you about a confusing part of this terminology.
Firstly, \textbf{``most'' sets are neither open nor closed}.
\begin{example}[A set neither open nor closed]
	The half-open interval $[0,1)$ %chktex 9
	is neither open nor closed in $\RR$.
\end{example}
Secondly, it's \textbf{also possible for a set to be both open and closed};
this will be discussed in \Cref{ch:top_more}.

The reason for the opposing terms is the following theorem:
\begin{theorem}[Closed sets are complements of open sets]
	Let $M$ be a metric space, and $S \subseteq M$ any subset.
	Then the following are equivalent:
	\begin{itemize}
		\ii The set $S$ is closed in $M$.
		\ii The complement $M \setminus S$ is open in $M$.
	\end{itemize}
\end{theorem}
\begin{exercise}
	[Great]
	Prove this theorem!
	You'll want to draw a picture to make it clear what's happening:
	for example, you might take $M = \RR^2$ and $S$ to be the closed unit disk.
\end{exercise}

\section{\problemhead}
\begin{problem}
	Let $M = (M,d)$ be a metric space.
	Show that \[ d \colon M \times M \to \RR \]
	is itself a continuous function
	(where $M \times M$ is equipped with the product metric).
\end{problem}

\begin{problem}
  Consider $\QQ$ and $\NN$ as metric spaces (each with the obvious metric $d(x,y) = |x-y|$).
  Are these spaces homeomorphic?
	\begin{hint}
		No. There is not even a continuous injective map from $\QQ$ to $\NN$.
	\end{hint}
	\begin{sol}
		Two possible approaches, one using metric definition
		and one using open sets.

		Metric approach: I claim there is no injective map from $\QQ$ to $\NN$
		that is continuous. Indeed, suppose $f$ was such a map and $f(x) = n$.
		Then, choose $\eps = 1/2$.
		There should be a $\delta > 0$ such that everything with $\delta$ of $x$
		in $\QQ$ should land within $\eps$ of $n \in \NN$ --- i.e., is equal to $n$.
		This is a blatant contradiction of injectivity.

		Open set approach: In $\QQ$, no singleton set is open,
		whereas in $\NN$, they all are (in fact $\NN$ is discrete).
		As you'll see at the start of \Cref{ch:top_more},
		with the new and improved definition of ``homeomorphism'',
		we found out that the structure of open sets on $\QQ$ and $\NN$ are different,
		so they are not homeomorphic.
	\end{sol}
\end{problem}

\begin{problem}
	[Continuity of arithmetic continued]
	\label{prob:subtract_divide}
	Show that subtraction is a continuous map $- \colon \RR \times \RR \to \RR$,
	and division is a continuous map $\div \colon \RR \times \RR_{>0} \to \RR$.
	\begin{hint}
		You can do this with bare hands.
		You can also use composition.
	\end{hint}
	\begin{sol}
		For subtraction, the map $x \mapsto -x$ is continuous
		so you can view it as a composed map
		\begin{center}
		\begin{tikzcd}
			\RR \times \RR \ar[r, "{(\id,-x)}"]
				& \RR \times \RR \ar[r, "+"] & \RR \\[1ex]
			(a,b) \ar[r, mapsto] & (a,-b) \ar[r, mapsto] &  a-b.
		\end{tikzcd}
		\end{center}
		Similarly, if you are willing to believe $x \mapsto 1/x$
		is a continuous function, then division is composition
		\begin{center}
		\begin{tikzcd}
			\RR \times \RR_{>0} \ar[r, "{(\id, 1/x)}"]
				& \RR \times \RR_{>0} \ar[r, "\times"] & \RR \\
			(a,b) \ar[r, mapsto] & (a,1/b) \ar[r, mapsto] & a/b.
		\end{tikzcd}
		\end{center}
		If for some reason you are suspicious that $x \mapsto 1/x$ is continuous,
		then here is a proof using sequential continuity.
		Suppose $x_n \to x$ with $x_n > 0$ and $x > 0$
		(since $x$ needs to be in $\RR_{>0}$ too).
		Then \[ \left\lvert \frac{1}{x} - \frac 1{x_n} \right\rvert
			= \frac{\left\lvert x_n-x \right\rvert}{\left\lvert x x_n \right\rvert}.
		\]
		If $n$ is large enough, then $\left\lvert x_n \right\rvert > x/2$;
		so the denominator is at least $x^2/2$,
		and hence the whole fraction is at most
		$\frac{2}{x^2} \left\lvert x_n-x \right\rvert$,
		which tends to zero as $n \to \infty$.
	\end{sol}
\end{problem}

\begin{problem}
	Exhibit a function $f \colon \RR \to \RR$ such that
	$f$ is continuous at $x \in \RR$ if and only if $x=0$.
	\begin{hint}
		$\pm x$ for good choices of $\pm$.
	\end{hint}
	\begin{sol}
		Let $f(x) = x$ for $x \in \QQ$ and $f(x) = -x$ for irrational $x$.
	\end{sol}
\end{problem}

\begin{problem}
	\twochili
	Prove that a function $f \colon \RR \to \RR$ which is strictly increasing
	must be continuous at some point.
	\begin{hint}
		Project gaps onto the $y$-axis.
		Use the fact that uncountably many positive reals cannot have finite sum.
	\end{hint}
	\begin{sol}
		Assume for contradiction it is completely discontinuous;
		by scaling set $f(0) = 0$, $f(1) = 1$ and focus just on $f \colon [0,1] \to [0,1]$.
		Since it's discontinuous everywhere,
		for every $x \in [0,1]$ there's an $\eps_x > 0$
		such that the continuity condition fails.
		Since the function is strictly increasing,
		that can only happen if the
		function misses all $y$-values in the interval
		$(f(x)-\eps_x, f(x))$ or $(f(x), f(x)+\eps_x)$ (or both).

		Projecting these missing intervals to the $y$-axis you find uncountably
		many intervals (one for each $x \in [0,1]$) all of which are disjoint.
		In particular, summing the $\eps_x$ you get that a sum of uncountably
		many positive reals is at most $1$.

		But in general it isn't possible for an uncountable family $\mathcal F$
		of positive reals to have finite sum.
		Indeed, just classify the reals into buckets $\frac1k \le x < \frac1{k-1}$.
		If the sum is actually finite then each bucket is finite,
		so the collection $\mathcal F$ must be countable, contradiction.
	\end{sol}
\end{problem}

\begin{problem}
	Someone on the Internet posted the question ``is $1/x$ a continuous function?'',
	leading to great controversy on Twitter. How should you respond?
	\begin{hint}
		First answer the following question: ``is $1/x$ a function?''.
	\end{hint}
	\begin{sol}
		Like most Internet ``debates'' about math,
		the question revolves around sloppy definitions.
		The original posed question (which is ill-formed) is
		\begin{quote}
			(1) Is $1/x$ a continuous function?
		\end{quote}
		To make it well-formed, I want to \emph{first} bring up the question:
		\begin{quote}
			(2) Is $1/x$ a function?
		\end{quote}
		Technically, this question is \emph{also} ill-formed because it never specifies
		the domain of the function, which is part of the data needed to specify a function.
		One reasonable guess what the asker meant would be $\RR \setminus \{0\}$,
		i.e.\ the set of nonzero real numbers, in which case we get the question
		\begin{quote}
			(2') Does $1/x$ define a function from $\RR \setminus \{0\}$ to $\RR$?
		\end{quote}
		which has the firm answer YES.

		On the other hand, it does \emph{not} make sense to try to define $1/x$
		as a function on $\RR$.
		The definition of a function requires you to specify an output value for every input,
		so at least if you want a real-valued function\footnote{Those of you
			that know what $\mathbb{RP}^1$ is could consider it as a function
			$\mathbb{RP}^1 \to \mathbb{RP}^1$ if you insisted;
			but it's continuous in that case too.},
		there isn't any way to construe $1/x$ as a function on all of $\RR$.

		Now, returning to (1), we can now ask a well-formed question
		\begin{quote}
			(1') Does $1/x$ describe a continuous function from $\RR \setminus \{0\} \to \RR$?
		\end{quote}
		which again has the firm answer YES.

		Of course, you could also consider a question like
		``does $1/x$ describe a continuous function $\RR \to \RR$?''.
		However, this feels misleading:
		it would be like asking ``is $\sqrt{2}$ an even integer?''.
		The question doesn't make sense to begin with because $\sqrt2$ isn't an integer,
		and ``even'' is an adjective used for integers,
		so trying to ask whether it applies to $\sqrt2$ is a \href{https://qchu.wordpress.com/2013/05/28/the-type-system-of-mathematics/}{type-error}.
		Similarly, ``continuous'' is an adjective used for functions;
		it doesn't make sense to ask whether it applies to something that isn't a function.

		See \url{https://twitter.com/davidcpvm/status/1481024944830046209}
		for the Twitter post (in Spanish) and the accompanying Reddit post (one of several)
		at \url{https://www.reddit.com/r/math/comments/s82vf8}.
	\end{sol}
\end{problem}
