Mathwords logoMathwords

Metric Space — Definition, Formula & Examples

A metric space is a set paired with a distance function (called a metric) that tells you how far apart any two elements are. The metric must satisfy specific rules: distances are non-negative, the distance from a point to itself is zero, distance is symmetric, and the triangle inequality holds.

A metric space is an ordered pair (X,d)(X, d) where XX is a non-empty set and d:X×XRd: X \times X \to \mathbb{R} is a function satisfying, for all x,y,zXx, y, z \in X: (1) d(x,y)0d(x, y) \geq 0 with d(x,y)=0d(x, y) = 0 if and only if x=yx = y, (2) d(x,y)=d(y,x)d(x, y) = d(y, x), and (3) d(x,z)d(x,y)+d(y,z)d(x, z) \leq d(x, y) + d(y, z).

Key Formula

d(x,z)d(x,y)+d(y,z)d(x, z) \leq d(x, y) + d(y, z)
Where:
  • dd = The metric (distance function) on the set
  • x,y,zx, y, z = Arbitrary elements of the set $X$

How It Works

To verify that a set and a proposed distance function form a metric space, you check all four axioms against arbitrary elements. Non-negativity and identity of indiscernibles ensure that distance behaves like a meaningful measurement. Symmetry guarantees that the distance from xx to yy equals the distance from yy to xx. The triangle inequality prevents shortcuts — going directly from xx to zz is never longer than a detour through yy. Once these axioms are confirmed, the full machinery of convergence, continuity, open sets, and completeness becomes available in that space.

Worked Example

Problem: Show that the Euclidean distance in R2\mathbb{R}^2 satisfies the triangle inequality for points A=(0,0)A = (0,0), B=(3,0)B = (3,0), and C=(3,4)C = (3,4).
Compute d(A, B): Find the Euclidean distance from A to B.
d(A,B)=(30)2+(00)2=3d(A,B) = \sqrt{(3-0)^2 + (0-0)^2} = 3
Compute d(B, C): Find the Euclidean distance from B to C.
d(B,C)=(33)2+(40)2=4d(B,C) = \sqrt{(3-3)^2 + (4-0)^2} = 4
Compute d(A, C): Find the Euclidean distance from A to C.
d(A,C)=(30)2+(40)2=5d(A,C) = \sqrt{(3-0)^2 + (4-0)^2} = 5
Verify the triangle inequality: Check that the direct distance does not exceed the sum of the other two.
d(A,C)=53+4=d(A,B)+d(B,C)d(A,C) = 5 \leq 3 + 4 = d(A,B) + d(B,C)
Answer: The triangle inequality holds: 575 \leq 7. This is consistent with (R2,d)(\mathbb{R}^2, d) being a metric space under the Euclidean metric.

Why It Matters

Metric spaces provide the rigorous foundation for defining convergence, continuity, and compactness in real analysis and topology courses. They also underpin applied fields: machine learning algorithms like k-nearest neighbors depend on choosing an appropriate metric, and functional analysis uses metric spaces to study solution spaces of differential equations.

Common Mistakes

Mistake: Assuming every distance-like function is a metric, even if it fails an axiom.
Correction: Always verify all four axioms. For instance, the discrete function d(x,y)=0d(x,y) = 0 for all x,yx,y fails identity of indiscernibles when xyx \neq y, so it is not a metric.