I have noticed a certain analogy between subgroups of a group $G$ and equivalence relations on a set $X$. I would like to know if there's an explanation for this analogy or a common generalization of the two facts I have in mind.
Here are the facts.
Fact 1. Let $G$ be a group. Then we can multiply subsets of $G$ in a standard way. For two subgroups $R$ and $S$ of $G$, the product $RS$ is a subgroup of $G$ iff $RS=SR$. If that is the case, $RS=SR$ is the join of $R$ and $S$ in the lattice of subgroups of $G$.
Fact 2. Let $X$ be a set. Then we can compose binary relations on $X$ in a standard way. For two equivalence relations $\rho$ and $\sigma$, the composition $\rho\circ\sigma$ is an equivalence relation on $X$ iff $\rho\circ\sigma=\sigma\circ\rho$. If that is the case, $\rho\circ\sigma=\sigma\circ\rho$ is the join of $\rho$ and $\sigma$ in the lattice of equivalence relations on $X$.