# Category with a “metric” for arrow composition

Consider a category $\mathcal C$ with a "distance" function $d:\mathcal C^2 \to \mathbb{R}_{\geq 0}$ satisfying the "triangle inequality"

$$d(x \to z)\leq d(x \to y) + d(y \to z)$$

for every pair of composable arrows $(x\to z)=(x \to y \to z)$.

Let's call $(\mathcal C,d)$ a "metric" category.

The first example is to take any category $\mathcal{C}$, and define

$$d(f)=\begin{cases} 0 & \text{ if f is an isomorphism} \\\ 1 & \text{ otherwise.}\end{cases}$$

Then the triangle inequality simply translates the statement : "If $f=gh$, then $f$ is an isomorphism if $g$ and $h$ are isomorphisms."

Also, it's clear that every metric space can be made into a metric category in a canonical way.

We can define "open balls" in $\mathcal{C}$: for $c \in \mathcal{C}$, $r\geq 0$, let

$$B(c, r) = \{d \in \mathcal{C} | \text{ there exists }f: c \to d\text{ such that }d(f) < r \}.$$

In the category of number fields and monomorphisms, we can let $d(K \hookrightarrow L)=\log ([L:K])$. Then the triangle inequality is actually an equality. It's clear that $d$ is a good measure of "how far" $L$ is from consisting of just $K$. The open ball of radius $r$ around $K$ is the set of extensions of $K$ of degree $< e^r$.

Is it possible to endow a big category like $\text{Top}$ or $\text{Grp}$ with a meaningful distance?

-
@David: No Bruno considers ordinary categories with an additional structure; this is not the same as a Lawvere metric space. @Bruno: 1+ –  Martin Brandenburg Jul 21 '11 at 7:40
Surely for any category the function: d(f) = 0 if f is an identity; d(f) = 1 otherwise, satisfies the triangle inequality. So it is always possible to have a (trivial) distance vanishing on identity arrows. Am I missing something? –  Alex Simpson Jul 21 '11 at 7:55
@Martin: No, I meant a category over the category $\mathbf{B}\mathbb{R}_+$, as in: equipped with a functor $C \to \mathbf{B}\mathbb{R}_+$, not a category enriched over $\mathbb{R}_+$. I would have mentioned Lawvere and/or the word metric space otherwise :) –  David Roberts Jul 21 '11 at 8:11
Re David R's first comment. We have (not terribly successfully) thought about distances between finite groupoids golem.ph.utexas.edu/category/2008/12/…. Attaching distances to measure-preserving maps has been actively pursued: ncatlab.org/johnbaez/show/Entropy+as+a+functor. –  David Corfield Jul 21 '11 at 8:45
In Goodwillie calculus there's a heuristic notion of distance one uses fairly often: you can define it as something (more or less) inversely proportional to the connectnedness of a map $f: X \to Y$. So if $f$ is a weak homotopy equivalence, it's distance zero, for instance. It can also be used to talk about the radius of convergence of functors, but perhaps the metric in this example is too discrete for your interests. (And by the way, you can do the same thing for non-negatively graded chain complexes, or for connective spectra, more generally.) –  Hiro Lee Tanaka May 5 '13 at 23:13

1) In the category of finite sets (or finite groups or finite topological spaces....) let $d(f)$ be the cardinality of the image of $f$. This satisfies the strong triangle condition $$d(x\rightarrow z)\le\text{min }(d(x\rightarrow y),d(y\rightarrow z))$$
2) In any category, for each object $x$, let $\xi(x)$ be an (arbitrarily assigned) positive real number and define $$d(f)=\text{min }\lbrace{\xi(c)|f \hbox{ factors through } c}\rbrace$$ This also satisfies $$d(x\rightarrow z)\le \text{min }(d(x\rightarrow y),d(y\rightarrow z))$$
3) Fix a formal language for describing arrows in your category, let $l(f)$ be the length of the shortest description of $f$, and let $d(f)=l(f)+5$. The triangle inequality follows because $g\circ h$ always has a formal description just slightly longer than the sum of the shortest formal descriptions of $g$ and $h$ (say by putting each of these descriptions between parentheses and inserting a $\circ$ between them, which adds five characters).
In case 3), you have to allow $d$ to take the value infinity, or restrict to categories in which everything has a finite description.
Edited to add: 4) For the category of topological spaces, you can fix a non-negative integer $r$ and let $d(f)= \hbox{rank} (H^r(f,{\mathbb Q}))$ . This requires either allowing $d$ to take the value infinity or restricting to some subcategory where the homology groups are finite dimensional.