\part{Fundamentals}
\chapter{Metric spaces}



The notion of distance is extremely powerful and intuitive; it is the basis of many ideas in analysis such as limits and continuous functions. We model this by a \emph{metric space}; a set and a function over that set that states the distance between any 2 elements called a \emph{metric}. Metrics must obey certain properties that reflect our intuition of how distance should act (an element always has distance 0 from itself, distance from a to b is the same as the distance from b to a, etc.), and from this construction we can generalize a range of results from real analysis to hold in metric spaces.


Eventually, we will study \emph{topological spaces}; a space that seeks to generalize metric spaces. Such spaces may not have an associated metric, however may still be able to capture some properties to metric spaces by the means of \emph{open sets}. Our study of metric spaces will provide a natural motivation for studying such spaces.


Many definitions of topology will make much more sense once we see how they generalize and relate to metric spaces. Admittedly, topology seems kind of strange without the context of how it was derived.



\section{Metric space}




\begin{definition}[Metric space]
A \emph{metric space}is an ordered pair $(X,d)$.
\begin{itemize}
	\item $X$ is a set
	\item $ d : X \times X \to \mathbb{R}^{+} $ is a \emph{distance function} or \emph{metric} that defines the notion of distance.
\end{itemize}
The metric must satisfy the following properties.
\begin{itemize}
	\item $ d(x,y) \in [0,\infty ) $
	\item $ d(x,y)=0 \iff x=y $
	\item $ d(x,y)= d(y,x) $
	\item $ d(x,y) \leq d(x,z) + d(z,y) $
\end{itemize}
An element of $X$ is called a \emph{point}.
When the metric is apparent, one may denote the metric space $(X,d)$ as just $X$.
\end{definition}


This last condition for the distance function is known as \emph{the triangle inequality}; it is an incredibly useful tool in proofs.

Here are some examples to familiarize us with metrics; the first of which is already known to us.

\begin{example}[Euclidean metric]
The \emph{Euclidean metric} is the following metric defined on $\mathbb{R}^n$.
\[d(\mathbf{x},\mathbf{y}) = \sqrt{ \sum^{n}_{i=1} (\mathbf{x}_i - \mathbf{y}_i)^2 } \]
Notice that for $\mathbb{R}$, this is just $d(x,y)=|x-y|$, and higher dimensions are variations of the Pythagorean theorem.
\end{example}

\begin{example}[Chebyshev metric]
The \emph{Chebyshev metric} is the following metric defined on $\mathbb{R}^n$.
\[d(\mathbf{x},\mathbf{y})= \max_{i} ( |\mathbf{x}_i-\mathbf{y}_i | )\]
This metric represents the largest difference between two points on an axis. 
\end{example}

\begin{example}[Taxicab metric]
The \emph{taxicab metric} is the following metric defined on $\mathbb{R}^n$.
\[d(\mathbf{x},\mathbf{y})=\sum^{n}_{i=1} |\mathbf{x}_i-\mathbf{y}_i | \]
This metric represents the distance of the smallest path between the points if one could only 'walk' along the axises.
\end{example}



\section{Open balls}


Given any point $p$, it may be useful to consider the set of all other points within distance $r$ from $p$. This is the idea of a \emph{ball}; a set of all points in a radius of $r$ from $p$

We now introduce a useful tool in the analysis of metric spaces; the open ball. Since we can measure distance, we can construct sets with everything within a certain distance of some element. One decision we will have to make is whether or not to include elements that are exactly the specified distance away; this decision will indeed change many properties of these special sets. Open balls are defined not to include elements with exactly the specified distance.
\begin{definition}[Open ball]
Let $(X,d)$ be a metric space, $p$be an element in $X$ and $r \in (0,\infty)$ a nonnegative real number. An \emph{open ball centered at $p$ with radius $r$} is a set $B(p,r)$ defined as such.
\[ B(p,r) = \{x \in X : d(x,p) < r \} \]
\end{definition}

It is called a 'ball' because open balls made with the $\mathbb{R}^3$ Euclidean metric forms a set in space that geometrically look like a ball. As mentioned, the idea is that these sets cover any points strictly closer than $r$ units away. The 'open' part of the name corresponds to the strict inequality $<$ rather than $\leq$, so that the ball doesn't contain any 'outermost' surface points of the ball. 

It is only because open balls exclude these "outermost" points that we can prove the following fundamental result.

\begin{proposition}
If $x \in B(p,r)$, then there exists some $B(x,s)$ such that $B(x,s)$ is contained completely in $B(p,r)$. Elements in open balls of $p$ have their own open balls completely contained in that open ball of $p$.
\[ x\in B(p,r) \implies \exists s \in (0,\infty) [ B(x,s) \subseteq B(p,r)  ] \]
\end{proposition}



\section{Open and closed sets}


We may be acutely aware that open balls exclude the 'endpoints' and closed balls keep them, this is essentially the notion of a \emph{boundary}.

\begin{definition}[Boundary (metric space)]
Let $(X,d)$ be a metric space. The \emph{boundary of $S$} is the set  $\partial S$ of all elements $p\in X$ (called boundary points) such that all their open and closed balls have intersections with $S$ and $X \setminus S$. 
\[\partial S = \{p \in X : \forall r \in \mathbb{R}_{+} [ B_{p}(r) \cap S \neq \emptyset \land   B_{p}(r) \cap (X \setminus S) \neq \emptyset  ]  \}\]
\end{definition}

Due to those 2 findamental results, we can translate what they mean using the language of boundaries.

\begin{proposition}
Open balls are disjoint from their boundary. Closed balls contain their boundary.
\end{proposition}


There a more types of sets that don't contain their boundary rather than just open balls, so let's consider them.

\begin{definition}[Open set (metric space)]
Let $(X,d)$ be a metric space. A \emph{open set of $X$} is a set $U$ that is disjoint to $\partial U$. We say that $U$ \emph{ is open in $X$}.
\end{definition}

The same can be said about sets completely containing their boundary.

\begin{definition}[Closed set (metric space)]
Let $(X,d)$ be a metric space. A \emph{closed set of $X$} is a set $F$ that completely contains $\partial F$. We say that $F$ \emph{ is closed in $X$}.
\end{definition}



Noting that $\partial S = \partial (X \setminus S)$, we can prove the following curious proposition.

\begin{proposition}
$F$ is closed iff $X \setminus F$ is open.
\end{proposition}

This gives us a nice set theoretic representation for closed sets that doesn't include a metric; we'll make this the prime definition once we've defined what topologies are!


\begin{theorem}
Let $(X,d)$ be a metric space. If $U$ is open in $X$ then any element in $U$ has an open ball completely contained in $U$.
\end{theorem}


This brings us 2 corollaries that may be intuitive, but extremely important.

\begin{corollary}
Let $(X,d)$ be a metric space. Open balls are open sets. 
\end{corollary}

\begin{corollary}
Let $(X,d)$ be a metric space. Open sets are unions of open balls. 
\end{corollary}










































\section{Convergence in metric spaces}

\subsection{Convergent sequences}

%Though convergence of sequences may be established without a metric space, metric spaces provide a more intuitive definition for convergence.

Recall in real analysis that we define convergent seqeuences of $x$ as sequences that 'eventually' remain within any arbitrarily small distance from $x$. 

Reflecting on our work in real analysis, we can essentially port the exact definition to metric spaces, swapping the Euclidean metric for a generic one.

\begin{definition}[Convergent sequence]
In a metric space $(X,d)$, a \emph{limit} of a sequence is a point $p \in X$ that is arbitrarily close all remaining terms of a sequence. A \emph{convergent sequence} is a sequence with a limit.
\[ (X,d) \]
\[ x_n \to p  \iff \forall \varepsilon \in (0,\infty) [ \exists N \in \mathbb{N} [ n > N \implies d(x_n , p) < \varepsilon  ]  ]\]
\[ x_n \to p  \iff \forall \varepsilon \in (0,\infty) [ \exists N \in \mathbb{N} [ n > N \implies x_n \in B(p,\varepsilon )  ]  ]\]
\end{definition}

It will be extremely worthwhile to note that we can write our definition in terms of open neighborhoods. Perhaps this seems trivial at the moment, when we explore topology we will be forced to deal with neighborhoods (a special type of set) rather than a metric (a special type of function).

\begin{proposition}
	For all open neighborhoods of $p$ (denote this as $V_p$),  there exists some $N$ such that any term after $N$ is in $V_p$.
\[ x_n \to p  \iff \forall V_p  [ \exists N \in \mathbb{N} [ n > N \implies x_n \in V_p  ]  ]\]
\end{proposition}




\begin{proposition}
In metric spaces, the limit of a convergent sequence is unique.
\[ (X,d) \]
\[x_n \to x \land x_n \to y \implies x = y \]
\end{proposition}

Due to the uniqueness of limits of convergent sequences in Metric spaces, we introduce the following notation for limits.
\[x_n \to x \iff \lim_{n \to \infty} x_n = x\]



%\begin{proposition}only 4 metric spaces this holds
%\[ \exists x_n \subseteq A ( \lim_{n \to \infty} x_n = p  ) \iff p \in \mathrm{cl}(A)\]
%\end{proposition}


\subsection{Cauchy sequences}

Imagine we're considering an embedded space not containing its boundary (like $\mathbb{Q}$ in $\mathbb{R}$, an open interval in $\mathbb{R}$, etc.); we can construct sequences that limit towards something outside the space. We can't call them convergent sequences since it requires that the limit be in the space, however we now recognise another (actually more general) class of sequences with 'convergent-like' behaviour.

\begin{definition}[Cauchy sequence]
In a metric space $(X,d)$, a \emph{Cauchy sequence} is a sequence where the absolute difference of terms are eventually bounded by any arbitrary positive number.
\[ (X,d) \]
\[  (x_n)_{n \in \mathbb{N}} \text{ is Cauchy} \iff \forall \varepsilon \in (0,\infty) [ \exists N \in \mathbb{N} [ n,m > N \implies d(x_n , x_m) < \varepsilon  ]  ]\]
\[  (x_n)_{n \in \mathbb{N}} \text{ is Cauchy} \iff \forall \varepsilon \in (0,\infty) [ \exists N \in \mathbb{N} [ n,m > N \implies x_n \in B(x_m , \varepsilon)   ]  ]\]
\end{definition}


\begin{proposition}
Convergent sequences are Cauchy sequences.
\end{proposition}


\subsection{Complete metric spaces}


A natural follow up question is whether Cauchy sequences are convergent sequences; in general this is not the case! Though this does occur for $\mathbb{R}^n$ with the Euclidean metric (as real analysis students are aware of), it is not true for any metric space.
Consider the Euclidean metric with $\mathbb{Q}$; the sequence $x_n = \sum^{n}_{k=0} \frac{(-1)^k 4}{2k+1}$ is Cauchy but not convergent since its limit $\pi$ is not in the space $\mathbb{Q}$.


\begin{definition}[Complete metric space]
A \emph{complete metric space} is a metric space $(X,d)$ where all Cauchy sequences are convergent.
\end{definition}

The real numbers are sometimes synthetically defined as a totally ordered field with the least upper bound property. From this, one can prove that the Euclidean space $\mathbb{R}$ is complete.

Another equivalent way of constructing the real numbers is by defining them as the completion of $\mathbb{Q}$; in this case $\mathbb{R}$ is complete by definition!



\begin{proposition}
A set $S$ is closed in the induced topology of a metric spaces iff any sequence in $S$ converges to some $p \in S$
\end{proposition}


\begin{proposition}
Any metric space can be completed by creating elements by forminh an equivalence classes of Cauchy sequences with $ \lim_{n\to \infty}d(x_n,y_n) =0$
\end{proposition}





\section{Connected metric spaces}


\section{Compact metric spaces}


\begin{definition}[Compact metric space]
A compact metric space is a metric space $(X,d)$ such that any sequence has a convergent subsequence
\end{definition}


\begin{definition}[Compact set (metric space)]
A compact set of $(X,d)$ is a set $S$ whose metric subspace is a compact metric space.
\end{definition}


\begin{proposition}
set is compact iff any open cover has finite subcover
\end{proposition}

This form is very useful for proving various corollaries

\begin{corollary}
	compact sets (of metric space) are closed
\end{corollary}


\begin{corollary}
	continuous functions map compact sets (of metric space) from compact sets (of metric space)
\end{corollary}




\section{Continuous function (Metric space)}



%Like limits, a topological space is also sufficient grounds to develop a general definition of a continuous function! To build up intuition, we once again commence our study in the realm of metric spaces.


\begin{definition}[Continuous function (metric space)]
	Let $(X,d_X)$ and $(Y,d_{Y})$ A function $f : X \to Y$ is \emph{continuous at $p \in X$} iff for any $\varepsilon$, there is a $\delta$ such that if $d_X (p,q) < \delta$ then $d_Y ( f(p) , f(q) ) < \varepsilon$.
\end{definition}


Let's try to derive the general topological definition of a continuous function from these insights.

As always, we have to strip away that metric to generalize our definition to topological spaces. We can start by reformulating this definition in terms of open balls, and then generalize to neighborhoods to get the final result.

\begin{proposition}
Let $(X,d_X)$ and $(Y,d_{Y})$ A function $f : X \to Y$ is \emph{continuous at $p \in X$} iff for any $B_{Y}(f(p),\varepsilon)$, there is a $B_{X}(p,\delta)$ such that if $q \in B_{X}(p,\delta)$ then $f(q) \in B_{Y}(f(p),\varepsilon)$.
Equivalently we have that $f(B_{X}(p,\delta) \subseteq B_{Y}(f(p),\varepsilon)$
\end{proposition}

%If we try and define globally continuous functions by considering continuity at every point in the metric space, we are lead back to the general topological definition of a continuous function.

\begin{proposition}
	Let $(X,d_X)$ and $(Y,d_{Y})$ A function $f : X \to Y$ is \emph{continuous at $p \in X$} iff for any $V_{f(p)}$, there is a $U_{p}$ such that f$f(U_p) \subseteq V_{f(p)}$.
\end{proposition}


Limits can be used to express continuous functions between metric spaces.

\begin{theorem}[Continuous function]
A function $f : X \to Y$ between 2 metric spaces $(X,d_X),(Y,d_Y)$ is continuous iff for any sequence $x_n$ in $(X,d)$ converging to $x$, the following holds.
\[ \lim_{n \to \infty} f(x_n) = f(x) \]
\end{theorem}

\begin{corollary}[Continuous function]
A function $f : X \to Y$ between 2 metric spaces $(X,d_X),(Y,d_Y)$ is continuous iff for each $x_0\in X$ and $\varepsilon > 0$, there  is some $\delta$ where the following holds for all $x \in X$.
\[ d(x,x_0) < \delta \implies d(f(x),f(x_0)) < \varepsilon \]
\end{corollary}

\begin{corollary}[Continuous function]
A function $f : X \to Y$ between 2 metric spaces $(X,d_X),(Y,d_Y)$ is continuous iff the following holds for any $x_0 \in X$.
\[ \lim_{x \to x_0} f(x) = f(x_0)\]
\end{corollary}



\subsection{Uniform continuity}


The real analysis student may be familiar with uniform continuity; which is a property of a function that is sufficient to permit swapping the order of taking limits and integrals.
Many of the stronger continuity classes from real analysis may also be generalized to metric spaces.



\begin{definition}[Uniformly continuous function]
\[ f : X \to Y \text{ is uniformly continuous } \iff \forall \varepsilon [ \exists \delta [ \forall p \in X [ q \in B_{X}(p,\delta) \implies f(q) \in B_{Y}(f(p),\varepsilon) ]  ] ] \]
\end{definition}

Any uniformly continuous function has an extension to a completion that is also uniformly continuous


\begin{definition}[Lipschitz continuous function]
\[ f: X \to Y \text{ is Lipschitz continuous } \iff \exists K\in \mathbb{R}_{+} [ d_{Y}(f(p),f(q)) \leq K d_{X} (p,q) ]\]
\end{definition}


\begin{definition}[$\alpha$-Hölder continuous function]
\[  f: X \to Y \text{ is } \alpha \text{-Hölder continuous }  \iff \exists K\in \mathbb{R}_{+} [ d_{Y}(f(p),f(q)) \leq K d_{X}^{\alpha} (p,q) ]\]
\end{definition}

Hölder continuity for certain $\alpha$ characterizes concepts already familiar to us.
\begin{proposition}
\[f \text{ is bounded } \iff f \text{ is 0-Hölder continuous}\]
\[f \text{ is Lipschitz continuous } \iff f \text{ is 1-Hölder continuous}\]
\end{definition}















\section{Isometries}

Topological properties are conserved under homeomorphisms; metric properties are conserved under isometries.



In many areas of mathematics, it may be useful to determine whether 2 structures exibit the exact same behaviour insofar a


\begin{definition}[Isometry]
Let $X,Y$ be two metric spaces. An \emph{isometry} is a function $f : X \to Y$ such that distance is preserved in the following way.
\[d_{X}(x,y) = d_{Y}(f(x),f(y))\]
If there exists an isometry between two metric spaces, then they are said to be \emph{isometric}.
\end{definition}


Metric properties are conserved under isometries. Since all the properties of metric spaces that we have discussed deal only with a set and its metric, all the results in this chapter are metric properties.


\begin{proposition}
Isometries are injective functions.
Isometries of $\mathbb{R}^n$ are rotations and reflections
\end{proposition}





\section{Banach fixed-point theorem}

One of my favourite objects in mathematics as a youth were convergent recursive sequences.
I had derived the sequence $x_{n+1} =x_n + \frac{a-x_{n}^2}{a} $ to calculate $\sqrt{a}$ by using the fact that $\lim_{n \to \infty} x_n = \sqrt{a}$.

I relied on heuristic arguments, however the theory of metric spaces allows us to prove the correctness of this claim.

\begin{definition}[Contraction mapping]
Given a metric space $(X,d)$, a \emph{contraction mapping} is a function $f : X \to X$ such that there exists some $r \in (0,1)$ where the following holds for any $x,y \in X$.
\[d(f(x),f(y)) \leq r d (x,y)\]
\end{definition}

It is easily seen that contraction mappings are a very special case of Lipschitz continuous functions that map to the same metric space and with a factor in $(0,1)$. Since Lipschitz functions are continuous, we have the following lemma.

\begin{lemma}
Contraction mappings are continuous functions.
\end{lemma}

\begin{theorem}[Banach fixed-point theorem]
Let $(X,d)$ be a complete metric space and $f: X \to X$ a contraction mapping then $f$ has a unique fixed point.
Furthermore, $x_{n+1}=f(x_n)$ converges to this fixed point.
\end{theorem}


The Banach fixed-point theorem was precisely the theory of why my sequence converged, specifically, the contraction mapping was $f(x)=x+\frac{a-x^2}{a}=x+1-\frac{x^2}{a}$ and it indeed had a unique fixed point $\sqrt{a}$ and convergent sequence as I had derived from philosophically concerning techniques.


\section{Baire spaces}

\begin{theorem}[Baire category theorem]
For a complete metric space $(X,d)$, let $X_n$ be a sequence of open dense subsets of $X$, then $\bigcap^{\infty}_{n=1}X_n$ is dense in $X$.
\end{theorem}



















\section{Bounded sets}

Given a metric, we can introduce the concept of bounded sets, which is otherwise undefinable in more general topological spaces.

\begin{definition}[Bounded set]
Let $(X,d)$ be a metric space, a \emph{bounded set of $X$} is some set $A$ such that for any points $p,q\in S$ we have $d(p,q) < M$.
\[ A \text{ is bounded } \iff \exists r [\forall p, q \in A [ d(p,q) \leq M ] ]\]
\end{definition}

\begin{proposition}
A set is bounded iff it is covered by a single open ball.
\end{proposition}


This will be very useful when we study compactness.



Totaally bounded iff for any $\varepsilon$, can be covered by a fininte number of open $\varepsilon$-balls



