Let M {\displaystyle {}M} be a set. A mapping d : M × M → R {\displaystyle {}d\colon M\times M\rightarrow \mathbb {R} } is called a metric (or a distance function), if for all x , y , z ∈ M {\displaystyle {}x,y,z\in M} the following conditions hold:
A metric space is a pair ( M , d ) {\displaystyle {}(M,d)} , where M {\displaystyle {}M} is a set and d : M × M → R {\displaystyle {}d\colon M\times M\rightarrow \mathbb {R} } is a metric.