<s>[INST] Getting different values of the integral when integrating with different order I want to determine the volume of the shape given by the following
$$ K = \{(x,y,z): x^2+y^2+z^2 \leq 2 \, \, , x+y>0 \, \, , \, z\leq 1\} $$
I thought that i can integrate with respect to $xy$-plane first by using polar coordinates
$$ \int_{-\sqrt{2}}^1 \biggl( \int_{-\frac{\pi}{4}}^{\frac{3 \pi}{4}} \int_0^{\sqrt{2-z^2}} r \, \, drd\theta \biggr) \, dz \quad=\quad \frac{\pi}{2} \int_{-\sqrt{2}}^1 2-z^2 \, dz \quad=\quad ..... \quad=\quad \frac{\pi}{2} \biggl( \frac{5-2\sqrt{2}}{3} + 2\sqrt{2} \biggr) $$
But if I integrate with respect to $z$ first I get the following
$$ \iint_D \biggl( \int_{-\sqrt{2-(x^2+y^2)}}^1 \, dz \biggr) \, dxdy \quad=\quad \int_{-\frac{\pi}{4}}^{\frac{3 \pi}{4}} \int_0^{\sqrt{2}} \biggl(1+\sqrt{2-r^2} \biggr) r \, \, drd\theta  = \, \, ...... \, \, = \quad \frac{\pi}{3} \biggl( 3 + 2 \sqrt{2} \biggr) $$
Which is very confusing since the value of the integral should be the same regardless of the order of integration! Can anyone see where I missed up?
 [/INST] The first integral is correct. As regards the second integral note that $z=\sqrt{2-x^2-y^2}\leq 1$ for $1\leq x^2+y^2\leq \sqrt{2}$.

Therefore we need to split the $xy$-domain $D$ in two parts:
$$V=\iint_{D_1} \biggl( \int_{-\sqrt{2-(x^2+y^2)}}^1 \, dz \biggr) \, dxdy 
+\iint_{D_2} \biggl( \int_{-\sqrt{2-(x^2+y^2)}}^{\sqrt{2-(x^2+y^2)}} \, dz \biggr) \, dxdy $$
where
$D_1=\{(x,y,0): x^2+y^2\leq 1, x+y>0\}$ and $D_2=\{(x,y,0): 1<x^2+y^2\leq 2, x+y>0\}.$
Hence
$$V=\pi\int_{0}^1\Big(1+\sqrt{2-r^2}\Big)r\,dr+\pi\int_{1}^{\sqrt{2}}\Big(2\sqrt{2-r^2}\Big)r\,dr=\frac{(5+4\sqrt{2})\pi}{6}$$
as we expected.
</s>