Canonical: https://knowlpedia.com/convex-analysis/metric-metric-space/

# Metric and metric space

A distance function satisfying positivity, symmetry, and the triangle inequality

Let \(X\) be a nonempty set. A function \(d:X\times X\to\mathbb{R}\) is a **metric** on \(X\) if for all \(x,y,z\in X\):

1. \(d(x,y)\ge 0\), and \(d(x,y)=0\) if and only if \(x=y\).
2. \(d(x,y)=d(y,x)\).
3. \(d(x,z)\le d(x,y)+d(y,z)\) (triangle inequality).

The pair \((X,d)\) is called a **metric space**.

Metrics allow one to define [balls](https://knowlpedia.com/convex-analysis/open-and-closed-balls-in-a-metric-space/), [open sets](https://knowlpedia.com/convex-analysis/open-subset/), and notions of [convergence](https://knowlpedia.com/convex-analysis/convergence-of-a-sequence/) and completeness.

## Examples

- On \(\mathbb{R}^n\), the Euclidean metric \(d(x,y)=\|x-y\|_2\).
- The discrete metric: \(d(x,y)=0\) if \(x=y\) and \(d(x,y)=1\) otherwise.
- On a normed vector space \((X,\|\cdot\|)\), \(d(x,y)=\|x-y\|\) is a metric.
