A curious similarity between metric and equivalence relations: Is there a pattern behind this? As is well known, the axioms for a metric are:

  
*
  
*Positivity: $d(x,y)\ge 0$ and $d(x,y)=0$ iff $x=y$.
  
*Symmetry: $d(x,y)=d(y,x)$
  
*Triangle inequality: $d(x,z) \le d(x,y) + d(y,z)$

Now I notice that the second and third axiom can be replaced by a single axiom, let's call it the "thirds distance inequality" (the reason for this name will be obvious later):

Thirds distance inequality: $d(x,y) \le d(x,z) + d(y,z)$

It is immediately obvious that the thirds distance inequality can be derived from symmetry and triangle inequality. For the reverse direction, we need to use the property that $d(x,x)=0$.
Now, this fact reminded me of another fact, about the definition of equivalence relations. The usual axioms are:

  
*
  
*Reflexivity: $a=a$.
  
*Symmetry: $a=b \iff b=a$.
  
*Transitivity: $a=b \land b=c \implies a=c$.

Now symmetry and transitivity can be replaced by a single axiom, whose English name I don't know, but the German name is "Drittengleichheit", which I'd translate as "thirds equality":

Thirds equality: $a=c \land b=c \implies a=b$.

And again, you can prove thirds equality from symmetry and transitivity, but to prove symmetry and transitivity from thirds equality, you need to use reflexivity.
There is a striking similarity between the distance and the equivalence case: In both cases, we have the following ingredients:


*

*Some entity applied to two objects (metric, equivalence relation)

*An axiom that says something about applying the entity to an object and itself ($d(a,a)$, $a=a$)

*An axiom stating symmetry.

*An axiom relating the entity applied to $(a,c)$ to a combination of the entity applied to $(a,b)$ and $(b,c)$. This involves some combination operation ($+$, $\land$) and an operation relating the two sides ($\le$, $\implies$).

*A replacement axiom for the latter two that just reverses one of the two combined entities by its symmetric reverse.

*In both cases, you can derive the replacement axiom directly from symmetry and the original third axiom, but to do the reverse, you need the first, reflexive axiom.
So there seems to be a common pattern here. Is there a way to formally describe that pattern, and are there other cases where it also applies?
 A: Here is a possible answer. The pattern in your question is essentially what defines a groupoid. Groupoids can be thought of as a kind of category where every morphism has an inverse.
Let's go through each point in your list:

  
*
  
*Some entity applied to two objects (metric, equivalence relation)
  

The "entity" is just a morphism between two objects (I'm allowing the possibility of multiple "entities" for the sake of generality).

  
*
  
*An axiom that says something about applying the entity to an object
  and itself ($d(a,a)$, $a=a$)
  

This is the axiom that asserts the existence of an identity morphism $1_a : a \to a$ from any object to itself.

  
*
  
*An axiom stating symmetry.
  

This is the axiom saying that every morphism $\varphi : a \to b$ has an inverse $\varphi^{-1} : b \to a$.

  
*
  
*An axiom relating the entity applied to $(a,c)$ to a combination of
  the entity applied to $(a,b)$ and $(b,c)$. This involves some
  combination operation ($+$, $\land$) and an operation relating the two
  sides ($\le$, $\implies$).
  

This just says that given two morphisms $\varphi : a \to b$ and $\psi : b \to c$ we can multiply (or compose) them giving a new morphism $$\psi\cdot\varphi : a \to c.$$

  
*
  
*A replacement axiom for the latter two that just reverses one of
  the two combined entities by its symmetric reverse.
  

An alternate axiomatization of a groupoid includes just the identity axiom and a "division axiom", which says that given $\varphi : a \to b$ and $\chi : a \to c$ we can define a division $$\chi/\varphi : b \to c$$ satisfying the appropriate rules (akin to associativity of multiplication).

  
*
  
*In both cases, you can derive the replacement axiom directly from
  symmetry and the original third axiom, but to do the reverse, you need
  the first, reflexive axiom.
  

On the one hand, we can obviously define $\chi/\varphi = \chi\cdot(\varphi)^{-1}$. On the other hand, only when we have identity elements can we define (dropping subscripts) 
$$\varphi^{-1} = 1/\varphi, \quad \psi\cdot\varphi = \psi/(1/\varphi).$$

Thus, one way to formally express the pattern for the given examples would be:


*

*Given an equivalence relation $=$ on a set $S$, there exists a groupoid where objects are elements from $S$ and there is a morphism between two objects $a,b$ if and only if $a=b$. (By the way, what you called the "thirds equality" axiom seems to be called Euclidean property in this context).

*Given a metric space $X$, there is a groupoid enriched in the monoidal poset $([0,\infty),\ge)$ where the objects are points in $X$ and morphisms are nonnegative real numbers representing the distance between points (the tensor product is $+$ and the tensor unit is $0$). This example was more difficult to express because the $+$ and $0$ in the axioms have to be translated to categorical operations, I adapted it from section 3 here.
There are lots of additional examples, as seen e.g. in this page. It could be interesting to work out what division means in some of them.
