integrating overlapping function I have been given a question to integrate $\int_{-\infty}^{\infty}( \int_{-\infty}^{\infty}$f(x,y)dx )dy  and interchange them to see what happens
given \
\begin{equation}
f(x) =
\begin{cases}
1, & \text{if} \ 0<x \ ,0<y \ & \ 0 \leq x-y \leq 1 \\
-1, & \text{if} \ 0<x \ ,0<y \ & \ 0 < y-x \leq 1 \\
0 & \text{otherwise}
\end{cases}
\end{equation}
I tried to sketch the graph and I noticed that the  1 and -1 regions intercect, how do I go on to write $f(x,y)$
please assist
 A: You can write it using indicator functions, that is
$$
f(x,y)=(\mathbf{1}_{[0,1]}(x-y)-\mathbf{1}_{(0,1]}(y-x))\mathbf{1}_{(0,\infty )^2}(x,y)
$$
Therefore
$$
\begin{align*}
\iint_{-\infty }^{\infty } f(x,y)\,\mathrm d x\,\mathrm d y&=\iint_0^{\infty }(\mathbf{1}_{[0,1]}(x-y)-\mathbf{1}_{(0,1]}(y-x))\mathrm d x\,\mathrm d y\\
&=\iint_0^{\infty }\big(\mathbf{1}_{[0,1]}(x-y)-\mathbf{1}_{[-1,0)}(x-y)\big)\,\mathrm d x\,\mathrm d y
\end{align*}
$$
Now for fixed $y$ we have that
$$
\int_0^\infty \mathbf{1}_{[0,1]}(x-y)\,\mathrm d x=\int_{\max\{0,y\}}^{\max\{0,y+1\}}\,\mathrm d x=\max\{0,y+1\}-\max\{y,0\}
$$
Can you finish from here?
A: I first did the problem geometrically. Notice that $f$ bounds two regions in quadrant I bounded by the lines $x-1,x,x+1$. In these regions, $f$ is constant and either $+1$ or $-1$. Fix $y=y_0$ as constant and observe how this horizontal line intersects with the two regions. If $y_0\geq 1$, the line runs the same distance over both $+1$ and $-1$ regions so the integral of $f$ wrt. $x$ cancels out and is simply $0$. But in the case of $0<y_0<1$, the region bounded by $x+1$ and $x$ reaches a corner and is truncated by the $y$ axis. Hence, the $\pm1$ regions don't cancel out and the value of $\iint f\ \mathrm{d}x\,\mathrm{d}y$ is determined by the area of the right triangle and parallelogram in the $\pm1$ regions, which is a simple geometry problem since $f$ is constant there (but note the sign of $f$). In the case of $\iint f\ \mathrm{d}y\,\mathrm{d}x$, the variables are flipped, as is our perspective. So now $x=x_0$ is held constant and it is the region bounded by $x$ and $x-1$ that meets the corner. In this case, the triangle and parallelogram are in opposite $\pm1$ regions to what they were before so the integral's sign is inverted. 

Figure: the two regions determined by $f$ and a line $y=y_0$.
Looking at the problem algebraically, the statement that, when $y_0$ is fixed and assumed positive,

$\int f\ \mathrm{d}x$ is either $0$, for $y_0>1$ or $1-y_0$, for $0<y_0<1$

is equivalent to saying $\int f\ \mathrm{d}x=\max\{1-y_0,0\}$, or $1-\min\{y_{0},1\}$ or $[1-\max\{0,y_0\}+\max\{0,y_0-1\}]$, as you'd get from Masacroso's answer. Any of these should be easy to integrate over $y$.
So, all that's left is to show which regions integrated over when we fix $x$ first or $y$ first and you can complete the proof.
