7.4. distnorm — Mathematical distances and norms

This module defines tag types that represent mathematical distances and norms. These tags can be used to specify which distance or norm should be used when computing functions such as a vector norm, a matrix norm or the distance between two geometric entities. The module is divided in two namespaces: math::dist and math::norm.

7.4.1. Distance tag types

All of the following tag types live in the namespace math::dist:

type math::dist::manhattan

Tag for the Manhattan distance: \(d(\mathbf{p}, \mathbf{q}) = \sum\limits_{i=1}^n |p_i - q_i|\).

type math::dist::euclidean

Tag for the Euclidean distance: \(d(\mathbf{p}, \mathbf{q}) = \sqrt{\sum\limits_{i=1}^n (p_i - q_i)^2}\).

type math::dist::chebyshev

Tag for the Chebyshev distance: \(d(\mathbf{p}, \mathbf{q}) = \max_i(|p_i - q_i|)\).

type math::dist::minkowski

Tag for the Minkowski distance: \(d(\mathbf{p}, \mathbf{q}) = \left(\sum\limits_{i=1}^n |p_i - q_i|^p\right)^{1/p}\).

type math::dist::canberra

Tag for the Canberra distance: \(d(\mathbf{p}, \mathbf{q}) = \sum_{i=1}^n \frac{|p_i-q_i|}{|p_i|+|q_i|}\).

7.4.2. Norm tag types

All of the following tag types live in the namespace math::norm:

type math::norm::manhattan

Tag for the Manhattan norm: \(\|x\|_1 = \sum\limits_{i=1}^n |x_i|\).

type math::norm::euclidean

Tag for the Euclidean norm: \(\|x\|_2 = \sqrt{\sum\limits_{i=1}^n x_i^2}\).

type math::norm::uniform

Tag for the uniform norm: \(\|x\|_\infty = \max \left(|x_1|, \ldots ,|x_n| \right)\).

type math::norm::p

Tag for the p norm: \(\|x\|_p = \left(\sum\limits_{i=1}^n |x_i|^p\right)^{1/p}\).

7.4.3. Equivalence of tags

For every existing norm, there is an equivalent distance. Therefore, the tag types in math::norm are implemented as type aliases of the tag types in math::dist. Therefore, it is possible to use the math::dist and math::norm tag types can be used interchangeably. Here is a table of the equivalent tag types:

Norm Distance
math::norm::manhattan math::dist::manhattan
math::norm::euclidean math::dist::euclidean
math::norm::uniform math::dist::chebyshev
math::norm::p math::dist::minkowski