Let $u$, $v\in W^{1,2}(\Omega)$ be two non-negative sobolev functions. We define $$ w:= \begin{cases} u&\text{ if }u\leq v\\ v&\text{ if }v\leq u \end{cases} $$ Let $$ P:=\{x\in\Omega,\, u\leq v\}\,\,Q:=\{x\in\Omega,\,v>u\} $$ Then, can we have $w\in W^{1,2}(\Omega)$ as well? Moreover, can we have $$ \|\nabla w\|^2_{L^2(\Omega)}=\|\nabla u\|^2_{L^2(P)}+\|\nabla v\|^2_{L^2(Q)} $$ too?
Here my $\Omega\subset \mathbb R^N$ is open bounded with smooth boundary. And my $N=1$ or $N=2$.
We just need Stampacchia's theorem:
The proof should be straightforward if one knows something about absolutely continuous functions. See for example the book Partial Differential Equations by Evans for the $C^1$ case and Weakly Differentiable Functions by Ziemer for the general case.
Now, if $G(x)=\max\{x,0\}$ then, $G$ is Lipschitz with derivative bounded by $1$ therefore, if $u\in W^{1,p}(\Omega)$ then $G(u)=\max\{u,0\}\in W^{1,p}(\Omega)$ and
$$\nabla (G(u)) = \begin{cases} \nabla u & \mbox{if } u\ge0 \\ 0 & \mbox{if } u\le0 \end{cases}.$$
To conclude, note that $\min\{u,v\}=-\max\{u-v,0\}+u$ which implies that
$$\nabla (\min\{u,v\}) = \begin{cases} \nabla v & \mbox{if } u\ge v \\ \nabla u & \mbox{if } u\le v \end{cases}.$$