John Isbell defined a notion of a median algebra (although the original idea is due to Birkhoff). A median algebra is a set $S$ with a ternary operation $[x,y,z]$ satisfying a set of [axioms](https://en.wikipedia.org/wiki/Median_algebra). The example to have in mind comes from lattice theory. Suppose $(L, \wedge, \vee, 0, 1)$ is a lattice. Then, we can define $[x, y, z] = (x \vee y) \wedge (y \vee z) \wedge (x \vee z)$ (with a little work, you can show it satisfies said axioms). The intuition is clear: if, for example $x \preceq y \preceq z$, then $[x,y,z] = y$. More interesting things can happen if $x, y, z$ do not lie in a chain.


My question is this: is there a nice notion of median of a) a finite subset of elements of a lattice or b) and arbitrary subset of a complete lattice. In order for said notion to be considered a median, it must, at the bare minimum, satisfy the property that if $C$ is a chain, then $\mathrm{median} (C)$ is a median (maybe there are two) of the chain.



Medians in lattice theory
Yes. There is a nice notion of an $n$-ary median term in a distributive lattice and in a median algebra as long as $n$ is odd.


Proposition: Suppose that $1\leq k\leq n$.


1. There is a term $t$ in the language of lattices such that if $x\_{1}\leq\dots\leq x\_{n}$, then $t(x\_{1},\dots,x\_{n})=x\_{k}$ and where $t$ satisfies the identity $t(z\_{1},\dots,z\_{n})=t(z\_{\sigma(1)},\dots,z\_{\sigma(n)})$ for each permutation $\sigma\in S\_{n}$.
2. If $s,t$ are terms in the language of lattices such that if
$x\_{1}\leq\dots\leq x\_{n}$, then $s(x\_{1},\dots,x\_{n})=t(x\_{1},\dots,x\_{n})=x\_{k}$ and where $s(z\_{1},\dots,z\_{n})=s(z\_{\sigma(1)},\dots,z\_{\sigma(n)})$ and
$t(z\_{1},\dots,z\_{n})=t(z\_{\sigma(1)},\dots,z\_{\sigma(n)})$ for each permutation $\sigma\in S\_{n}$, then
$s(u\_{1},\dots,u\_{n})=t(u\_{1},\dots,u\_{n})$ whenever $u\_{1},\dots,u\_{n}$ are elements of some distributive lattice.


For example, suppose that $m\_{n,k}^{+}(z\_{1},\dots,z\_{n})=\bigwedge\_{R\in[n]^{k}}(\bigvee\_{r\in R}z\_{r})$, and suppose that
$m\_{n,k}^{-}(z\_{1},\dots,z\_{n})=\bigvee\_{R\in[n]^{n+1-k}}(\bigwedge\_{r\in R}z\_{r})$. Then the terms $m\_{n,k}^{-},m\_{n,k}^{+}$ satisfy $1$ in the above proposition.


To prove $2$, we observe that $2$ holds for the $2$ element distributive lattice, and that the variety of all distributive lattices is generated by the $2$ element distributive lattice.


For distributive lattices, we may just write $m\_{n,k}$ for $m\_{n,k}^{-}$ or $m\_{n,k}^{+}$ since $m\_{n,k}^{-}$ and $m\_{n,k}^{+}$ are logically equivalent for distributive lattices.


By the next proposition, we see that the for distributive lattice, the medians $m\_{n,k}$ are precisely the terms which are symmetric with respect to all permutations in $S\_{n}$.


Proposition: If $t$ is a term in the language of distributive lattices such that $t(z\_{1},\dots,z\_{n})=t(z\_{\sigma(1)},\dots,z\_{\sigma(n)})$ for each permutation $\sigma$, then there is some $k$ with $1\leq k\leq n$ such that
$t(z\_{1},\dots,z\_{n})=m\_{n,k}(z\_{1},\dots,z\_{n})$ whenever $z\_{1},\dots,z\_{n}$ belong to some distributive lattice.


If $t$ is a term in the language of all distributive lattices, then let $t^{d}$ be the term obtained from $t$ by replacing every instance of $\wedge$ with $\vee$ and every instance of $\vee$ with $\wedge$.


Proposition: If $n=2r-1$, then the median $m\_{2r-1,r}$ is (up-to-logical equivalence) the only $2r-1$-ary term $t$ in the language of Boolean algebras where
$t(z\_{1},\dots,z\_{n})=t(z\_{\sigma(1)},\dots,z\_{\sigma(n)})$ for each permutation $\sigma$ and where $t=t^{d}$.


The term $m\_{2r-1,r}(x\_{1},\dots,x\_{2r-1})$ can actually be defined in terms of the ternary median operator. The theory of $2r-1$ median operations has been studied in the paper "The algebra of majority consensus" by Hans-Jorgen Bandelt and Gerasimos C. Meletiou.


Define terms $$(w\_{1},\dots,w\_{i+1},x^{i})=m(m(m(w\_{1},w\_{2},x),w\_{3},x),\dots,w\_{i+1},x).$$


The following proposition reconstructs the $2r-1$-ary median $m\_{2r-1,r}$ from
the $2r-3$-ary median $m\_{2r-3,r-1}$ and the ternary median $m$.


Proposition: In a distributive lattice, we have
$$m\_{2r-1,r}(x\_{1},\dots,x\_{2r-1})$$
$$=m\_{2r-3,r-1}(x\_{1},\dots,x\_{r-2},(x\_{r-1},x\_{r},x\_{r+1}),(x\_{r-1},x\_{r},x\_{r+1},x\_{r+2}^{2}))\dots(x\_{r-1}\dots,x\_{2r-2},x\_{2r-1}^{r-1})).$$


There are other ways of constructing the $2r-1$-median operator from the ternary median. The $2r-1$-median operator is the only $2r-1$-ary term $t$ up to logical equivalence in the language of ternary median algebras such that $t(z\_{1},\dots,z\_{2r-1})=t(z\_{\sigma(1)},\dots,z\_{\sigma(2r-1)})$ for all permutations $\sigma\in S\_{2r-1}$.


