definition example

A metric space consists of a Set of points and a function , the distance, such that for all :

(a) ; (b) if then ; (c) (symmetry); (d) (triangle inequality).

Allowing gives an extended metric space.

Sources: 7 Sketches Definition 2.51, Example 2.54, Exercises 2.52, 2.73; §2.3.3.

The triangle inequality says that a route never costs more than going via an intermediate ; in a triangle with sides it can be invoked six ways (, , …). Example 2.54. with .

Conditions (a) and (d) “wonderfully capture something about distance”, but (b) and (c) are too restrictive:

  • effort to travel in a hilly neighbourhood is asymmetric;
  • regions (US, Spain, Boston) with “worst-case distance to get from somewhere in to anywhere in ” (, the asymmetric Hausdorff Distance): (7S Exercise 2.52) and ;
  • infinite distances: “from here to Pluto is “.

Dropping (b), (c) and allowing yields the Lawvere Metric Space — a category enriched in Cost. Extended metric spaces are exactly the skeletal dagger -categories (7S Exercise 2.73), just as sets are skeletal dagger preorders: “preorders are to sets as Lawvere metric spaces are to extended metric spaces”.

#check MetricSpace          -- dist : α → α → ℝ with dist_self, eq_of_dist_eq_zero, dist_comm, dist_triangle
#check EMetricSpace         -- extended: edist : α → α → ℝ≥0∞
#check PseudoEMetricSpace   -- drops (b): the symmetric Lawvere case
example : MetricSpace ℝ := inferInstance
example (x y : ℝ) : dist x y = |x - y| := Real.dist_eq x y
-- a metric space as a distance function (laws unenforced)
newtype Metric a = Metric (a -> a -> Double)
 
realLine :: Metric Double
realLine = Metric (\x y -> abs (y - x))