TITLE: RELU representation of $\max(x,y,z)$
QUESTION [6 upvotes]: Here is a question that occurred to me while learning about neural networks.  For $t\in\mathbb{R}$ put $t_+=\max(0,t)$, so $t_+=t$ if $t\geq 0$ and $t_+=0$ if $t\leq 0$. (This is RELU=rectified linear unit in neural network language.) Note that $t=t_+-(-t)_+$ and $|t|=t_++(-t)_+$.
For the maximum of two variables we have
\begin{align*}
 \max(x,y) &= x + (y-x)_+ \\
 &= \left(x+y+(x-y)_++(y-x)_+\right) /2 \\
 &= \left((x+y)_+-(-x-y)_++(x-y)_++(y-x)_+\right)/2
\end{align*}
Is there a similar expression for $\max(x,y,z)$ as a linear combination of terms $\phi(x,y,z)_+$ with $\phi$ linear?  I suspect not, but I have not found a proof.  More generally, is there a nice characterisation of the functions of several variables that do admit such a representation?

REPLY [2 votes]: Here is a simpler proof, inspired by YCor's approach.  Fix a finite-dimensional vector space $V$ and let $F$ be the class of functions $V\to\mathbb{R}$ in question.  First, by using the rule $t_+=(t+|t|)/2$ and combining terms appropriately, we see that any $f\in F$ can be represented as
$$ f(x) = L_0(x) + |L_1(x)| + \dotsb + |L_n(x)| - |L_{n+1}(x)| - \dotsb - |L_{n+m}(x)|, $$
where $L_0,\dotsc,L_{n+m}$ are linear and $L_1,\dotsc,L_{n+m}$ are pairwise linearly independent.  As $f(x)-L_0(x)$ is even, it follows that $f$ is differentiable at $x$ iff it is differentiable at $-x$.  The $\max$ function is differentiable at $(1,0,0)$ but not at $(-1,0,0)$, so it does not lie in $F$.
For a sharper statement, we can proceed as follows.  Let $P$ be the set of piecewise-linear maps $f\colon V\to\mathbb{R}$.  For $f\in P$ and $x,v\in V$ put
$$ Q(f,x)(v) = \lim_{t\to 0^+} t^{-1}\left(f(x+tv)+f(x-tv)-2f(x))\right). $$
Then $f\in F$ iff there are distinct hyperplanes $W_1,\dotsc,W_p<V$ such that

$Q(f,x)=0$ for $x\not\in W_1,\dotsc,W_p$
For each $i$ there is a linear map $L_i$ with kernel $W_i$ and $\epsilon_i\in\{1,-1\}$ such that $Q(f,x)(v)=\epsilon_i|L_i(v)|$ for all $x\in W_i\setminus\bigcup_{j\neq i}W_j$ and $v\in V$.