Not exactly elegant, but no worse than best-so-far, and one fewer
kind of operator:
median(a,b,c,d,e) =
min( max(abc),max(abd),max(abe),max(acd),max(ace),
max(ade),max(bcd),max(bce),max(bde),max(cde) )
Another puzzle:
It turns out that median-of-5 (Med5) can be constructed from
the median-of-3 (Med3) function. One way is
Med5(A,B,C,D,E) = Med3( A, Med3(B,C,D), Med3(B,E, Med3(A,C,D)) ).
[All median-of-odd functions can be built out of any single one.
In fact, any non-trival, 0-1 symmetric, monotone-nondecreasing,
boolean function can be built from Med3, and vice versa.
This includes weighted medians, and many others.]
The expression above for Med5 in terms of Med3 is minimal.
But it's far from obvious that the expression is right, and it
sure doesn't look symmetrical. Even though Med5 is symmetrical
in all permutations of the arguments, the expression has only
the C:D swap symmetry.
The puzzle is to come up with a better expression. Ideally it
would exhibit full symmetry and be obviously correct. But even
just having some additional symmetry would be an improvement.
[My proof of the formula above is by cases in the boolean
environment: The cases are C/=D, and C=D=0. Plus the lifting
principle, that boolean -> also true for total ordering.
Also less than elegant.]
Rich rcs(a)cs.arizona.edu