Calculating triple integral over volume common to 2 surfaces In one of my assignments, I have a question which asks you for the triple integral of $z^2$ over the volume common to a given sphere and a cylinder. 

I need to transform the equation to cylindrical polar form. Also I am not able to get the limits. In the polar form limit of $\varphi$ would be $2\pi$ but I am not understanding the limit of $\rho$ and $z$.
 A: The tricky part here is figuring out how the volume is described in cylindrical coordinates (with $\rho$, $\varphi$ and $z$).
The volume is bounded below and above by the sphere. Using the equation of the sphere, $x^2+y^2+z^2=a^2$, we get:
\begin{align*}
&x^2+y^2+z^2=a^2\\
\iff\quad&z^2=a^2-x^2-y^2\\
\iff\quad&z=\pm\sqrt{a^2-x^2-y^2}\\
\iff\quad&z=\pm\sqrt{a^2-\rho^2},
\end{align*}
since $x^2+y^2=\rho^2$. The lower part of the sphere is $z=-\sqrt{a^2-\rho^2}$ and the upper is $z=\sqrt{a^2-\rho^2}$, thus the limits of $z$ will be $-\sqrt{a^2-\rho^2}\leq z \leq\sqrt{a^2-\rho^2}$.
The limits in $\rho$ and $\varphi$ are determined by the cylinder $x^2+y^2=ax$. Using the equation and assuming $a\geq0$, we get
\begin{align*}
&x^2+y^2=ax\\
\iff\quad&\rho^2=a\rho\cos(\varphi)\\
\iff\quad&\rho=a\cos(\varphi)
\end{align*}
The limits of $\rho$ must then be $0\leq\rho\leq a\cos(\varphi)$ (the lower limit $\rho=0$ is by definition of cylindrical coordinates). We also notice that in order for the upper limit to be non-negative (which it must be, otherwise the inequality has no solutions), we require
$$a\cos(\varphi)\geq0\iff\cos(\varphi)\geq0\iff-\frac{\pi}{2}\leq\varphi\leq\frac{\pi}{2}.$$
Notice now that if $a<0$, in order to get a positive radius we want $a\cos(\varphi)\geq0$, which in this case is equivalent to
$$\cos(\varphi)\leq0\iff\frac{\pi}{2}\leq\varphi\leq\frac{3\pi}{2}.$$
Now we have our limits. The differential is transformed by $dxdydz=\rho\ d\rho d\varphi dz$, finally giving us
$$\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\int_0^{a\cos(\varphi)}\int_{-\sqrt{a^2-\rho^2}}^{\sqrt{a^2-\rho^2}}\rho z^2\ dzd\rho d\varphi\quad\text{if}\ a\geq0$$
and
$$\int_{\frac{\pi}{2}}^{\frac{3\pi}{2}}\int_0^{a\cos(\varphi)}\int_{-\sqrt{a^2-\rho^2}}^{\sqrt{a^2-\rho^2}}\rho z^2\ dzd\rho d\varphi\quad\text{if}\ a<0.$$
Notice however that letting $\theta=\varphi-\pi$ in the integral for $a<0$ yields
$$\int_{\frac{-\pi}{2}}^{\frac{\pi}{2}}\int_0^{a\cos(\theta+\pi)}\int_{-\sqrt{a^2-\rho^2}}^{\sqrt{a^2-\rho^2}}\rho z^2\ dzd\rho d\theta=\int_{\frac{-\pi}{2}}^{\frac{\pi}{2}}\int_0^{-a\cos(\theta)}\int_{-\sqrt{a^2-\rho^2}}^{\sqrt{a^2-\rho^2}}\rho z^2\ dzd\rho d\theta.$$
Since the integrand is odd in terms of $\rho$, and in general for odd $f(x)$ we have
$$\int_0^{-a}f(x)\ dx=-\int_{-a}^0f(x)\ dx=\int_0^a f(x)\ dx,$$
we then obtain
$$\int_{\frac{\pi}{2}}^{\frac{3\pi}{2}}\int_0^{a\cos(\varphi)}\int_{-\sqrt{a^2-\rho^2}}^{\sqrt{a^2-\rho^2}}\rho z^2\ dzd\rho d\varphi=\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\int_0^{a\cos(\theta)}\int_{-\sqrt{a^2-\rho^2}}^{\sqrt{a^2-\rho^2}}\rho z^2\ dzd\rho d\theta.$$
Therefore the two cases $a\geq0$ and $a<0$ are really the same. We can also simplify further by noticing that the function is even in terms of $z$ and $\varphi$, giving us the final transformed integral as
$$4\int_0^{\frac{\pi}{2}}\int_0^{a\cos(\varphi)}\int_0^{\sqrt{a^2-\rho^2}} \rho z^2\ dzd\rho d\varphi.$$
