Is it a Sobolev function? Let $U=(-1,1)\times(-1,1)$. Define
$$
u(x)=\begin{cases}1-x_1 \;\;\text{if}\;\;x_1>0,|x_2|<x_1
\\1+x_1\;\;\text{if}\;\;x_1<0, |x_2|<-x_1\\1-x_2\;\;\text{if}\;\;x_2>0,|x_1|<x_2\\1+x_2\;\;\text{if}\;\;x_2>0,|x_1|<-x_2\end{cases}
$$
I have to find for which $p$ I have $u\in W^{1,p}(U)$. I want to show that the weak derivative coincide with the classical derivative (which is defined everywhere except for $\{|x_1|=|x_2|\}$). I'm trying to integrate $\int_Uu\frac{\partial \phi}{\partial x_i}dx$, but I can't.
 A: Your function is indeed in $W^{1,p}(U)$ for any $p\in[1,\infty]$.
Let me present two ways to see this.
(1) Let $u_1,u_2,u_3,u_4:U\to\mathbb R$ be the four linear functions that appear in the definition of $u$.
Now $u=\min\{u_1,u_2,u_3,u_4\}$.
The linear functions are clearly Sobolev functions, and the pointwise minimum of finitely many functions in $W^{1,p}(U)$ is still in the same space.
(This is an instance of a more general and useful fact: The Sobolev spaces $W^{1,p}$ are closed under pointwise minimum, maximum and absolute value. But this fails for the spaces $W^{2,p}$.)
(2) There is an obvious candidate for the weak derivative.
Let me only do it in the first coordinate direction.
Let
$$
v(x)
=
\begin{cases}
-1 \;\;\text{if}\;\;x_1>0,|x_2|<x_1\\
1\;\;\text{if}\;\;x_1<0, |x_2|<-x_1\\
0\;\;\text{if}\;\;x_2>0,|x_1|<x_2\\
0\;\;\text{if}\;\;x_2>0,|x_1|<-x_2.
\end{cases}
$$
Take any $\phi\in C^\infty_0(U)$.
We want to show that $\int_Uu\partial_1\phi=-\int_Uv\phi$.
By Fubini's theorem it suffices to show that $\int_{-1}^1u(x,y)\partial_1\phi(x,y)dx=-\int_{-1}^1v(x,y)\phi(x,y)dx$ for all $y\in(-1,1)$.
Suppose $y\in(0,1)$; the other case is similar.
Now
\begin{eqnarray}
\int_{-1}^1u(x,y)\partial_1\phi(x,y)dx
&=&
\int_{-1}^{-y}u(x,y)\partial_1\phi(x,y)dx
\\&&\quad+
\int_{-y}^{y}u(x,y)\partial_1\phi(x,y)dx
\\&&\quad+
\int_{y}^{1}u(x,y)\partial_1\phi(x,y)dx
\\&=&
\int_{-1}^{-y}(1+x)\partial_1\phi(x,y)dx
\\&&\quad+
\int_{-y}^{y}(1-y)\partial_1\phi(x,y)dx
\\&&\quad+
\int_{y}^{1}(1-x)\partial_1\phi(x,y)dx
\\&=&
\int_{-1}^{-y}(-1)\phi(x,y)dx+(1-y)\phi(-y,y)
\\&&\quad+
(1-y)\phi(y,y)-(1-y)\phi(-y,y)
\\&&\quad+
\int_{y}^{1}\phi(x,y)dx-(1-y)\phi(y,y)
\\&=&
\int_{-1}^{-y}(-1)\phi(x,y)dx
\\&&\quad+
\int_{y}^{1}\phi(x,y)dx
\\&=&
-\int_{-1}^1v(x,y)\phi(x,y)dx.
\end{eqnarray}
The weak derivative is obviously in $L^p(U)$ for any $p$.
