TITLE: Computing the residue of $\frac{\cot(\pi z)}{z^2}$ at pole $z=0$
QUESTION [6 upvotes]: To find the residue I used the residue theorem that states:
$$Res(f,z_0)=\frac{1}{(m-1)!}\lim_{z\to0}\frac{\mathrm{d}^{m-1}}{\mathrm{d}z^{m-1}}(z-z_0)^m f(z)$$ where $m$ is the order 
Computing the Residue of $\dfrac{\cot(\pi z)}{z^2}$ 
This is what I thought I was supposed to do for the singularity at $z_0=0$ of order $3$.
$$Res(f;0)=\frac{1}{2!}\lim_{z\to 0} \frac{\mathrm{d}^2}{\mathrm{d}z^2}z^2 \sin(\pi z)f(z)=-\frac{1}{2}\lim_{z \to 0} \pi^2 \cos(\pi z) =-\frac{\pi^2}{2}$$
However the answer is $-\dfrac{\pi}{3}$
I'd really appreciate any guidance in where I went wrong.

REPLY [2 votes]: There is not quite enough shown of your work to figure out where the error is. However, I have used the same approach below, so perhaps you can find the step that differs.
$$
\begin{align}
&\frac12\frac{\mathrm{d}^2}{\mathrm{d}z^2}\left(z^3\frac{\cot(\pi z)}{z^2}\right)\\
&=\frac12\frac{\mathrm{d}^2}{\mathrm{d}z^2}\left(\frac{z\cos(\pi z)}{\sin(\pi z)}\right)\tag1\\
&=\frac12\frac{\mathrm{d}}{\mathrm{d}z}\left(\frac{\sin(\pi z)\cos(\pi z)-\pi z}{\sin^2(\pi z)}\right)\tag2\\
&=\pi\left(\frac{\pi z\cos(\pi z)-\sin(\pi z)}{\sin^3(\pi z)}\right)\tag3\\
&=\pi\left(\frac{\pi z\cos^2(\pi z)-\sin(\pi z)\cos(\pi z)}{\sin(\pi z)\cos(\pi z)\left(1-\cos^2(\pi z)\right)}\right)\tag4\\
&=\pi\left(\frac{\pi z\left(\cos^2(\pi z)\color{#C00}{-1}\right)+\pi z(\color{#C00}{1}-\color{#090}{\cos(\pi z)})-(\sin(\pi z)-\color{#090}{\pi z})\cos(\pi z)}{\sin(\pi z)\cos(\pi z)\left(1-\cos^2(\pi z)\right)}\right)\tag5\\
&=\pi\left(-\frac{\pi z}{\sin(\pi z)\cos(\pi z)}+\frac{\pi z}{\sin(\pi z)\cos(\pi z)(1+\cos(\pi z))}+\frac{\pi z-\sin(\pi z)}{\sin^3(\pi z)}\right)\tag6\\
&\to\pi\left(-1+\frac12+\frac16\right)\tag7\\[6pt]
&=-\frac\pi3\tag8
\end{align}
$$
Explanation:
$(1)$: simplify
$(2)$: take the derivative
$(3)$: take another derivative
$(4)$: apply $\sin^2(\pi z)=1-\cos^2(\pi z)$ and multiply by $\frac{\cos(\pi z)}{\cos(\pi z)}$
$(5)$: add and subtract the red and green terms
$(6)$: separate and simplify the summands in the numerator
$(7)$: evaluate the limits using $\lim\limits_{x\to0}\frac{x}{\sin(x)}=1$ from this answer
$\phantom{\text{(7):}}$ and $\lim\limits_{x\to0}\frac{x-\sin(x)}{x^3}=\frac16$ from this answer