5 Metric Spaces and Distance Functions
Highlights
- The definitions of “metric space” and “distance function”
- The usual distance functions on \(\R^n,\) including \(\R=\R^1.\)
- Properties of absolute values
5.1 Preparation
The limits that you learn about in calculus are often described in terms of a variable getting “closer and closer” or “arbitrarily close” to some quantity. In order to say more precisely what it means to be “close”, though, we need to be precise about what we mean by “distance” in the first place.
In this chapter we’ll talk about a fundamental construction in the theory of real analysis, which is the concept of a metric space. Basically, a metric space will be any set with a reasonable (and we’ll make precise what we mean by “reasonable”) notion of distance.
You are likely familiar with the distance formulas in \(\R^2\) and \(\R^3,\) and we will use these two spaces as our mental model for how to think about metric spaces. We’ll see that distance can reasonably be defined in other contexts as well, including in the real number system.
For the moment, play around with the applet below to see if you can think about what formula would give us the distance between the real numbers \(a\) and \(b.\)
Our philosophy will be that we will:
- Gain intuition from \(\R^2\) and \(\R^3,\)
- Write our proofs for any metric space, and
- Apply what we learn to \(\R.\)
For whatever reason, it’s easy for our brains to think about geometry in two and three dimensions than it is in one dimension. And proving theorems about general metric spaces is sometimes easier than proving the corresponding theorems in \(\R\) since there are fewer tools to keep track of1.
As a side benefit to this approach, the theory of metric spaces is useful more broadly in pure and applied math since we often want to think about how to define the “distance” between objects in a reasonable way. As a teaser of this concept, what is a reasonable way to define the distance between two functions?
Try and answer this for yourself in your mind, and then see if you can adjust the sliders for \(a\) and \(b\) to make the blue function as “close” as possible to the red one (whatever that means to you).
As we said earlier, we will define a metric space to be any set in which we can reasonably define distance. We begin by making the idea of “reasonableness” precise here.
Definition 5.1 A metric space is a nonempty set \(X\) equipped with a function \(d:X\times X\rightarrow\R\) called a distance function with the following properties.
- (Positivity) For any \(a,b\in X,\) \(d(a,b)\geq 0.\)
- (Positive Definiteness) For any \(a,b\in X,\) \(d(a,b)=0\) if and only if \(a=b.\)
- (Symmetry) For any \(a,b\in X,\) \(d(a,b)=d(b,a).\)
- (Triangle Inequality) For any \(a,b,c\in X,\) \(d(a,b)+d(b,c)\geq d(a,c).\)
Exercise 5.2 Explain why the usual distance formula in \(\R^2,\)
\[d((x_1,y_1),(x_2,y_2))=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2},\]
satisfies the properties in Definition 5.1. Give a proof for Positivity, Positive-Definiteness, and Symmetry, and provide a picture with an intuitive explanation for the triangle inequality.
While we are used to measuring distances in two and three dimensions, we can define distances in other contexts as well.
Exercise 5.3 Let \(S\) be any set. Prove that \(d:S\times S\rightarrow\R\) defined for any \(x,y\in S\) by
\[d(x,y)=\begin{cases} 0 & x=y \\ 1 & x\neq y \end{cases}\]
is a distance function for \(S\) (i.e. that it satisfies the four properties). We call this the trivial metric for \(S.\)
To talk about a metric space, we really ought to specify both the set \(X\) and the distance function \(d.\) For example, it’s technically possible to equip \(\R^2\) with the trivial metric from Exercise 5.3 (although I’m hard-pressed to think of why this would be useful). A somewhat more practical alternative metric on \(\R^2\) is the subject of Exercise 5.11, but we’ll refer to the distance function from Exercise 5.2 as the “standard” distance function for \(\R^2.\)
Before reading further, take just a moment to reflect on the question raised in Desmos Applet 5.1.
Exercise 5.4 Make a guess about how we will define the “standard” distance function that will turn \(\R\) into a metric space.
5.2 Distances in \(\R^n\)
You are likely familiar with the distance formulas in \(\R^2\) and \(\R^3.\) Generalizing those formulas, the standard distance function in \(\R^n\) is given by
\[ d((a_1,\ldots,a_n),(b_1,\ldots,b_n))=\sqrt{(b_1-a_1)^2+\cdots+(b_n-a_n)^2}. \tag{5.1}\]
The proofs that this distance function satisfies Positivity, Positive-Definiteness, and Symmetry are straightforward generalizations of what you did in Exercise 5.2. The proof that the standard distance function satisfies the Triangle Inequality is much more involved, and we defer it to Theorem 3.1 in Appendix C.
More important to us at the moment, though, is how to define distances in \(\R.\) If we apply the formula (5.1) to the case where \(n=1\) we get3 \(d(a,b)=\sqrt{(b-a)^2}.\) This ends up simplifying to \(|b-a|,\) which hopefully matches your guess in Exercise 5.4.
Thus we define the standard distance function on \(\R\) to be \[d(a,b)=|b-a|.\]
From now until the end of your days, whenever you see an absolute value—especially the absolute value of a difference—you should think “distance”.
Now that we see absolute values will be our main tool for talking about distances in the real numbers, it will be worthwhile to review some key properties of absolute values.
5.3 Absolute Values
Since distances in \(\R\) are measured using the absolute value function, we’ll want to make sure we understand this function and its basic properties well before going much further. The absolute value function is defined for any \(x\in\R\) via \[|x|=\begin{cases} x & x\geq 0 \\ -x & x<0 \end{cases}\] Make sure you understand how the second case matches what you know about absolute values before moving on!
Theorem 5.5 Suppose \(a,b\in\R.\)
- \(|a|\geq0.\)
- \(|a|=\max\{a,-a\}.\)
- \(|-a|=|a|.\)
- \(|a|\geq a.\)
- \(|ab|=|a||b|.\)
- \(|a+b|\leq|a|+|b|.\)
- \(|a-b|\geq\big||a|-|b|\big|.\)
Proof. We will prove parts 1–5. Since the definition of absolute value is piecewise, we need to do some case-by-case proofs here.
If \(a\geq 0\), then \(|a|=a\geq0\). If \(a<0\), then \(|a|=-a>0\).
If \(a\geq0\), then \(a\geq0\geq-a\), so \(|a|=a=\max\{a,-a\}\). If \(a<0\), then \(-a>0>a\), so \(|a|=-a=\max\{a,-a\}\).
By the previous part, \(|a|=\max\{a,-a\}=|-a|\).
Follows from the previous part.
This can be proven by considering each of the three cases where \(a,b\) are both positive, \(a,b\) are both negative, and where one of \(a,b\) is positive and the other is negative.
Exercise 5.6 Prove the remaining parts of Theorem 5.5. As a hint for Part 6, try breaking into two cases: one where \(a+b\geq0\) (so that \(|a+b|=a+b\)) and one where \(a+b<0\) (so that \(|a+b|=(-a)+(-b)\)) and then apply Part 4 to both \(a\) and \(b.\)
Exercise 5.7 Prove that the standard distance function \(d(x,y)=|y-x|\) for \(\R\) satisfies the Triangle Inequality.
5.4 More Exercises
Exercise 5.8 Let \(X\) be a metric space with distance function \(d\) and let \(x,y\in X.\) Suppose that for all \(\epsilon>0,\) \(d(x,y)\leq \epsilon.\) Prove that \(x=y.\)
In this section, you should cite Positivity, Positive-Definiteness, and the Triangle Inequalities whenever you use them (don’t bother with Symmetry). After this section, you need only cite the Triangle Inequality.
Exercise 5.9 Let \(X\) be a metric space with distance function \(d.\) Prove that for any \(a,b,c\in X,\) \[|d(a,b)-d(b,c)|\leq d(a,c).\]
Exercise 5.10 Prove the “polygon inequality”, which says that for any \(x_1,\ldots,x_n\) with \(n\geq 3\) in a metric space \(X\) with distance function \(d,\) \[d(x_1,x_2)+d(x_2,x_3)+\cdots+d(x_{n-1},x_n)\geq d(x_1,x_n)\] Hint: this is a good candidate for mathematical induction. It’s also a good example of how drawing a picture in two dimensions can help give you intuition about what happens in any metric space.
Exercise 5.11 Here we will consider \(\R^2\) with a different distance function. Define \[d_1((x_1,y_1),(x_2,y_2))=|x_2-x_1|+|y_2-y_1|\] Prove that \(d_1\) does in fact satisfy the four conditions of being a metric space.
Exercise 5.12 Here we will consider \(\R\) with a different purported distance function. Define \[d_{\mathrm{inv}}(a,b)=\begin{cases} \frac{1}{|a-b|} & a\neq b \\ 0 & a=b \end{cases}\] Show that \(d_{\mathrm{inv}}\) is not a distance function.
Exercise 5.13 If \(X\) is a metric space with distance function \(d,\) and \(S\subseteq X\) is nonempty, then we can think of \(S\) itself as a metric space using the same distance function restricted to \(S.\) In this case we say \(S\) is a subspace of \(X.\)
- If we treat \(\Q\) as a subspace of \(\R,\) prove that the distance between any two points in \(\Q\) is a rational number.
- If we treat \(\Z^2\) (the set of points in \(\R^2\) both of whose entries are integers), as a subspace of \(\R^2,\) is the distance between two points in \(\Z^2\) always an integer? Explain.
Review Questions
- State the four conditions a distance function on a metric space must satisfy.
- What is the standard distance function in \(\R^n\)? What about in \(\R\)?
- Which properties of absolute value from Theorem 5.5 did you already know? Which were new to you?
For instance, most metric spaces don’t have arithmetic or inequalities, so we won’t be distracted by these features of \(\R\) in contexts where they aren’t relevant.↩︎
The \(L^2\) norm is one that you may see in a differential equations or functional analysis course, but if you haven’t heard of it, it won’t be important for this course.↩︎
Here we set \(a=(a_1),\) and \(b=(b_1)\) to simplify the notation.↩︎