My target is to find a representation of the $\max$ (and $\min$, though they are similar enough that i'm mostly sure if i'd found one i can get the other) function that's nice enough to do manipulations without much annoyance (something like a "linear function" of absolutes, as is the 2 inputs version, would be great).
The 2 inputs version being the known relation $\max\left(x,y\right)=\frac{x+y+\left|x-y\right|}{2}$ (the $\min$ analogue being $\min\left(x,y\right)=\frac{x+y-\left|x-y\right|}{2}$).
I have found a 3 inputs $\max\left(x,y,z\right)$ by first rewrting $\max\left(x,y\right)$ using the "switch multiplier" relation for piecewise functions
$\begin{cases}
x<a:f(x) \\
x>a:g(x)\\
\end{cases}=\left(\frac{1}{2}-\frac{\left|x-a\right|}{2\left(x-a\right)}\right)f\left(x\right)+\left(\frac{1}{2}+\frac{\left|x-a\right|}{2\left(x-a\right)}\right)g\left(x\right)$
with $a=y=f(x),g(x)=x$, that gives $\max\left(x,y\right)=\left(\frac{1}{2}-\frac{\left|x-y\right|}{2\left(x-y\right)}\right)y+\left(\frac{1}{2}+\frac{\left|x-y\right|}{2\left(x-y\right)}\right)x$ to then create a nested form as
$\begin{cases}
x<y:\begin{cases}
y<z:z \\
y>z:y\\
\end{cases}\\
x>y:\begin{cases}
x<z:z \\
x>z:x\\
\end{cases}
\end{cases}=\left(\frac{1}{2}-\frac{\left|x-y\right|}{2\left(x-y\right)}\right)\begin{cases}
y<z:z \\
y>z:y\\
\end{cases}+\left(\frac{1}{2}+\frac{\left|x-y\right|}{2\left(x-y\right)}\right)\begin{cases}
x<z:z \\
x>z:x\\
\end{cases}=$
$=\left(\frac{1}{2}-\frac{\left|x-y\right|}{2\left(x-y\right)}\right)\frac{y+z+\left|y-z\right|}{2}+\left(\frac{1}{2}+\frac{\left|x-y\right|}{2\left(x-y\right)}\right)\frac{x+z+\left|x-z\right|}{2}=\frac{x+y+2z+\left|x-y\right|+\left|y-z\right|+\left|x-z\right|}{4}+\frac{\left|x-y\right|\left|x-z\right|-\left|x-y\right|\left|y-z\right|}{4\left(x-y\right)}=h(x,y,z)$
Which is not bad, but also is not immediately generalizable at 40 inputs (technically it is, one can generalize the procedure and get the functional equation $\max\left(x_{1},...,x_{n}\right)=\left(\frac{1}{2}-\frac{\left|x_{1}-x_{n}\right|}{2\left(x_{1}-x_{n}\right)}\right)\max\left(x_{2},...,x_{n}\right)+\left(\frac{1}{2}+\frac{\left|x_{1}-x_{n}\right|}{2\left(x_{1}-x_{n}\right)}\right)\max\left(x_{1},...,x_{n-1}\right)$, but i don't see how i could solve that product tree to get a sum), though i can replace the absolute products on the right by summing and cycling $h$'s inputs to get a more "simmetric" function $\frac{h(x,y,z)+h(y,z,x)+h(z,x,y)}{3}=\frac{4\left(x+y+z\right)+3\left(\left|x-y\right|+\left|y-z\right|+\left|z-x\right|\right)}{12}+\frac{-2x+y+z}{12}\frac{\left|x-y\right|\left|z-x\right|}{\left(x-y\right)\left(z-x\right)}+\frac{x-2y+z}{12}\frac{\left|x-y\right|\left|y-z\right|}{\left(x-y\right)\left(y-z\right)}+\frac{x+y-2z}{12}\frac{\left|y-z\right|\left|z-x\right|}{\left(y-z\right)\left(z-x\right)}$.
And this is all i know: i wouldn't be surprised if the 3 inputs $\max$ i derived was not the most elegant, nor i'll be surprised if there's some trick with symmetries to get a straightforward answer to my main question, but for the love of me i can't see it. If you can help i'll be very thankful.
- 59
-
1https://math.stackexchange.com/q/13253/42969 – Martin R Mar 31 '25 at 20:29
-
3I'd be interested to know what advantages you are hoping to get from such a representation. What do you mean by `a "linear function' of absolutes"? ($\max(x, y)$ is not a linear function of the absolute values of $x$ and $y$). – Rob Arthan Mar 31 '25 at 22:58
-
@Rob Ideally something i can drop in an equation where i find $\max$ and have it simplify with other expressions; obviously there's no "do-it-all" one, but empirically i've found addition to be the rather common (at least in the more geometric problems i care about), so like a big sum of "small" smilar-looking products (which are either going to be made of absolutes or some non-continuous function). – 6572726f72 Apr 01 '25 at 08:13
-
Thanks a lot @Martin , i don't know how i all my search i missed that post (even if it doesn't provide any "too nice" solution, the methods employed were not known to me). – 6572726f72 Apr 01 '25 at 08:18
2 Answers
Update: I simplified the final expression for $\max(x,y,z)$ somewhat.
Well, one fairly straightforward (albeit not very nice) method is the following.
Define $g(a,b)$ to be $1$ if $a>b$ and $0$ if $a<b$ (and undefined when $a=b$, sadly). It has an explicit formula
$$g(a,b)=\frac{1}{2}+\frac{1}{2}\operatorname{sgn}(a-b)=\frac{1}{2}+\frac{1}{2}\frac{a-b}{|a-b|}$$
This is a sort of a ternary operator common to programming languages. Then, we can use it to write the $\max$ function as "x if x is greater than y and z, otherwise y if y is greater than x and z, ...". For example, for three values,
$$\max(x,y,z)= x\cdot g(x,y)g(x,z)+y\cdot g(y,x)g(y,z)+z\cdot g(z,x)g(z,y)$$
We can expand the $g(\dots)$ terms and get a messy, but symmetric expression:
$$x\cdot g(x,y)g(x,z) = \frac{x}{4}\left(1+\frac{x-y}{|x-y|}+\frac{x-z}{|x-z|}+\frac{(x-y)(x-z)}{|x-y||x-z|}\right)$$
$$y\cdot g(y,x)g(y,z) = \frac{y}{4}\left(1+\frac{y-x}{|y-x|}+\frac{y-z}{|y-z|}+\frac{(y-x)(y-z)}{|y-x||y-z|}\right)$$
$$z\cdot g(z,x)g(z,y) = \frac{z}{4}\left(1+\frac{z-x}{|z-x|}+\frac{z-y}{|z-y|}+\frac{(z-x)(z-y)}{|z-x||z-y|}\right)$$
When summing these up, some stuff cancels, e.g. $x\frac{x-y}{|x-y|}$ and $y\frac{y-x}{|y-x|}$ together give
$$\frac{x(x-y)+y(y-x)}{|x-y|}=\frac{(x-y)^2}{|x-y|}=|x-y|$$
which together procudes the formula
$$\max(x,y,z) = \frac{1}{4}\left(x+y+z+|x-y|+|x-z|+|y-z|+ \\ + x\frac{(x-y)(x-z)}{|x-y||x-z|} + y\frac{(y-x)(y-z)}{|y-x||y-z|} + z\frac{(z-x)(z-y)}{|z-x||z-y|} \right)$$
I couldn't figure out how to simplify the remaining terms. They have quite a special form, though: e.g. the factor $\frac{(x-y)(x-z)}{|x-y||x-z|}$ is equal to $1$ exactly if $x$ is the largest or the smallest, otherwise it equals $-1$, and same for the other factors. So the three last terms are actually equal to either $x+y-z$, $x+z-y$, or $y+z-x$, depending on which element is in the middle.
Combined with the $x+y+z$, it gives e.g. $2x+2z$ if $y$ is between min and max, etc. Together with the $\frac{1}{4}$ factor, this is just $\frac{x+z}{2}$, i.e. the exact middle of the whole range of values $\{x,y,z\}$ (the middle between min and max). Then, in any case $|x-y|+|x-z|+|y-z|$ is equal to twice the length of this range (one of them is $\max-\min$, the two others are two distances from some point to min and max), and after dividing by $4$ it becomes half the length of this range. So, the formula can be interpreted the same way as with the 2-element case: take the middle, then add half the length, and you get the maximum value.
Sadly, even though it does easily generalize for the maximum of $n$ values, the resulting formula contains quite a lot of terms (specifically, something of the order $n\cdot 2^{n-1}$ terms).
- 17,012
interesting question, and interesting concept for two values. so I used it in my answer: $\sum_{k=1}^{n}x_{k}\left\lfloor \left|{ \frac{1}{n+1}+\sum_{l=1,l≠k}^{n}\frac{\left|{x_{k}-x_{l}}\right|}{(x_{k}-x_{l})(n-1)} }\right| \right\rfloor$
so first of all look at the inner sum. the terms are $\frac{1}{n-1}$ or $-\frac{1}{n-1}$ and if $x_{k}$ really is the largest of all xs than there are n-1 terms of $\frac{1}{n-1}$ so the solution to the sum is equal to 1 and we want this to be the only non negative answer. so we are going to add a tiny amount here: $\frac{1}{n+1}$ just to make sure it is still the only term larger then 1 but also making sure that the minimum of all numbers doesn't get in our way, since it is now bigger than -1. we then take the absolute valu, which keeps this property, and round down to the nearest integer. this is only going to give one 1 and that at the k with the largest $x_{k}$ now we just multiply 1 with $x_{k}$ and sum up all of the zero terms and we are done. hope you find this solution "nice"
- 31