Metric induces topology

Statement
Suppose $$(X,d)$$ is a metric space. Then, the collection of subsets:

$$B(x,r) := \{ y \in X \mid d(x,y) < r \}$$

form a basis for a topology on $$X$$. These are often called the open balls of $$X$$.

Metric space
A metric space $$(X,d)$$ is a set $$X$$ with a function $$d:X \times X \to \R$$ satisfying the following:


 * $$d(x,y) \ge 0 \ \forall \ x,y \in X$$ (non-negativity)
 * $$d(x,y) = 0 \iff x = y$$ (identity of indiscernibles)
 * $$d(x,y) = d(y,x)$$ (symmetry)
 * $$d(x,y) + d(y,z) \ge d(x,z) \ \forall \ x,y,z \in X$$ (triangle inequality)

Basis for a topological space
A collection of subsets $$\{ U_i \}_{i \in I}$$ of a set $$X$$ is said to form a basis for a topological space if the following two conditions are satisfied:


 * $$\bigcap_{i \in I} U_i = X$$
 * For any $$i,j \in I$$, and any $$p \in U_i \cap U_j$$, there exists $$U_k \subset U_i \cap U_j$$ such that $$p \in U_k$$.

Note that this is the definition for a collection of subsets that can form the basis for some topology.

Proof
It suffices to show the following two things:


 * The space $$X$$ is the union of subsets of the form $$B(x,r)$$
 * Given two sets $$B(x,r)$$ and $$B(y,s)$$, and any $$z \in B(x,r) \cap B(y,s)$$, there exists $$t > 0$$ such that $$B(z,t) \subset B(x,r) \cap B(y,s)$$ (this suffices because $$z \in B(z,t)$$ for any $$t$$, since $$d(z,z) = 0$$).

Proof that the union is the whole space
For any $$x \in X$$, and any $$r > 0$$, we have, because $$d(x,x) = 0$$:

$$x \in B(x,r)$$

Thus, in particular, we have:

$$x \in \bigcup_{r > 0} B(x,r)$$

Taking the union over all $$x$$, we get:

$$X = \bigcup_{x \in X, r > 0} B(x,r)$$

Proof for intersection of two
Consider two balls $$B(x,r)$$ and $$B(y,s)$$, where $$r,s >0$$ and $$x,y \in X$$. (Note that $$x,y$$ may be equal). Suppose $$z \in B(x,r) \cap B(y,s)$$. Then, by definition of the balls, we have:

$$d(x,z) < r, d(y,z) < s$$

Define:

$$t := \min \{ r - d(x,z), s - d(y,z) \}$$

Then, $$t > 0$$. We want to claim that $$B(z,t)$$ lies completely inside $$B(x,r) \cap B(y,s)$$.

Let's prove this. Suppose $$p \in B(z.t)$$. Then:

$$d(z,p) < t \le r - d(x,z)$$

By the triangle inequality and an application of the above we have:

$$d(x,p) \le d(x,z) + d(z,p) < d(x,z) + r - d(x,z) = r$$

Thus, $$p \in B(x.r)$$. Analogously, $$p \in B(y,s)$$. This completes the proof.