Topology usually starts with the idea of a *metric space*. A metric space is a set of values with some concept of *distance*. We need to define that first, before we can get into anything really interesting.

### Metric Spaces and Distance

What does *distance* mean?

Let’s look at a set, S, consisting of elements s_{1}, s_{2}, s_{3},…,s_{n}. What does it mean to measure a *distance* from s_{i} to s_{j}?

We’ll start by looking at a simple number-line, with the set of real numbers. What’s the distance between two numbers x and y? It’s a measure of *how far* over the number-line you have to go to get from x to y. But that’s really circular; we’ve defined distance as “how far you have to go”, which is defined by distance. Let’s try again. Take a blank ruler, and put it next to the numberline, so that the left edge of the ruler is on X, and then draw a mark on the ruler where it touches Y. The length of the ruler up to that mark is the distance from x to y. The reason that this one isn’t circular is because now, you can take that ruler, and use it to answer the question: is the number v farther from the number w than x is from y? Because the ruler gives you a *metric* that you can use *that is separate from* the number-line itself.

A *metric* over S is a function that takes two elements s_{i} and s_{j}, and returns a *real number* which measure the distance between those two elements. To be a proper metric, it needs to have a set of required properties. To be formal, a function d : S × S → ℜ is a *metric function over S* if/f:

- ∀ s
_{i}, s_{j}∈ S: d(s_{i},s_{j}) = 0 if/f i=j.*(the identity property)* - ∀ s
_{i}, s_{j}∈ S: d(s_{i},s_{j}) = d(s_{j},s_{i})*(the symmetry property)* - ∀ s
_{i}, s_{j}, s_{k}∈ S: d(s_{i},s_{k}) ≤ d(s_{i},s_{j}) + d(s_{j},s_{j})*(the triangle inequality property)*

Some people also add a fourth property, called the*non-negativity*property; I prefer to leave it out, because it can be inferred from the others. But for completeness, here it is: ∀ s_{i}, s_{j}∈ S: d(s_{i},s_{j}) ≥ 0.

A*metric space*is just the pair (S,d) of a set S, and a metric function d over the set.

For example: - The real numbers are a
*metric space*with the ruler-metric function. You can easily verify that properties of a metric function all work with the ruler-metric. In fact, they are are all things that you can easily check with a ruler and a number-line, to see that they work. The function that you’re creating with the ruler is: d(x,y) = |x-y| (the absolute value of x – y). So the ruler-metric distance from 1 to 3 is 2. - A cartesian plane is a metric space whose distance function is the euclidean distance:

d((a_{x},a_{y}), (b_{x},b_{y})) = ((a_{x}-b_{x})^{2}+ (a_{y}-b_{y})^{2})^{1/2}. - In fact, for every n, the euclidean n-space is a metric space using the euclidean distance.
- A checkerboard is a metric space if you use the
*number of kings moves*as the distance function. - The Manhattan street grid is a metric space where the distance function between two intersections is the sum of the number of horizontal blocks and the number of vertical blocks between them.

## Open and Closed Sets in Metric Spaces

You can start moving from metric spaces to topological spaces by looking at *open sets*. Take a metric space, (S,d), and a point p∈S. An *open ball* B(p,r) (a ball of radius *r* around point p) in S is the set of points x such that d(p,x) 0, B(p,r)∩T≠∅. The *closure* of T (usually written as T with a horizontal line over it; sometimes written as T^{}* by computer scientists, because that’s the closure notation in many CS subjects). is the set of all points adherent to T. *(note: a typo was corrected in this paragraph. Thanks to the commenter who caught it!)*

A subset T of S is called a *closed* subset if/f T=T^{}*. Intuitively, T is closed if it *contains* the surface that forms its boundary. So in 3-space, a solid sphere is a closed space. The *contents* of the sphere (think of the shape formed by the air in a spherical balloon) is *not* a closed space; it’s bounded by a surface, but that surface is not part of the space.