<s>[INST] Prove $ \sum_{n=1}^{2q-1}\frac{n}{q}\sin\left(\frac{\pi np}{q}\right)=-\cot\left(\frac{\pi p}{q}\right)-\csc\left(\frac{\pi p}{q}\right) $ For $p$ and $q$ are positive integers, $p < q$.
How to prove this identity?
$$
\sum_{n=1}^{2q-1}\frac{n}{q}\sin\left(\frac{n\pi p}{q}\right)=-\cot\left(\frac{\pi p}{q}\right)-\csc\left(\frac{\pi p}{q}\right)=-\cot\left(\frac{\pi p}{2q}\right)
$$
This identity is comprised by two parts.
$$
\sum_{n=1}^{q-1}\frac{2n}{q}\sin\left(\frac{2n\pi p}{q}\right)=-\cot\left(\frac{\pi p}{q}\right)\\
\sum_{n=1}^{q}\frac{(2n-1)}{q}\sin\left(\frac{(2n-1)\pi p}{q}\right)=-\csc\left(\frac{\pi p}{q}\right)
$$
I found these identities during the calculations when proving the other identity in my previous question by comparison. I am curious how to prove the identities in general ways.
I also found some other identities all by comparison like:
For $q$ is odd
$$
\sum_{n=1}^{(q-1)/2}\frac{2n}{q}\sin\left ( \frac{2n\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\csc\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{(q-1)/2}\frac{(2n-1)}{q}\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\cot\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{(q-1)/2}2\sin\left ( \frac{2n\pi p}{q} \right )=\cot\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\csc\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{(q-1)/2}2\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\csc\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\cot\left( \frac{\pi p}{q} \right )
$$
For $q$ is even
$$
\sum_{n=1}^{q/2}\frac{2n}{q}\sin\left ( \frac{2n\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\cot\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{q/2}\frac{(2n-1)}{q}\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\frac{(-1)^{p-1}}{2}\csc\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{q/2}2\sin\left ( \frac{2n\pi p}{q} \right )=\cot\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\cot\left( \frac{\pi p}{q} \right ) \\
\sum_{n=1}^{q/2}2\sin\left ( \frac{(2n-1)\pi p}{q} \right )=\csc\left( \frac{\pi p}{q} \right )+(-1)^{p-1}\csc\left( \frac{\pi p}{q} \right )
$$
How to prove them in general ways?
 [/INST] Thanks to Mr. metamorphy's answer. I rearrange the proof to make it suitable for my question.
Let $\omega =e^{2\pi pi/q}$
\begin{align}
(\omega-1)\sum_{n=1}^{q}n\omega^n&=(\omega-1)\left(\sum_{n=1}^{q}\omega^n+\sum_{n=2}^{q}\omega^n+\sum_{n=3}^{q}\omega^n+\cdots \sum_{n=q}^{q}\omega^n  \right) \\
&=\omega(\omega^q-1)+\omega^2(\omega^{q-1}-1)+\omega^3(\omega^{q-2}-1)-1)+\cdots+\omega^q(\omega-1) \\
&=q\omega^{q+1}-\sum_{n=1}^{q}\omega^n=q\omega,\quad\text{since }\omega^q=1\text{ and }\sum_{n=1}^{q}\omega^n=0 \\
\sum_{n=1}^{q}\frac{n}{q}\omega^n&=\frac{\omega}{\omega-1},\quad\sum_{n=1}^{q}\frac{n}{q}\omega^{-n}=\frac{\omega^{-1}}{\omega^{-1}-1} \\
\sum_{n=1}^{q}\frac{2n}{q}\sin\left(\frac{2n\pi p}{q}\right)&=\sum_{n=1}^{q}\frac{2n}{q}\left(\frac{\omega^n-\omega^{-n}}{2i}\right)=\frac{1}{i}\left(\frac{\omega}{\omega-1}-\frac{\omega^{-1}}{\omega^{-1}-1}\right) \\
&=-\frac{1}{i}\left(\frac{1+\omega}{1-\omega}\right)=-\cot\left(\frac{\pi p}{q}\right) \\
\sum_{n=1}^{q}\frac{2n}{q}\cos\left(\frac{2n\pi p}{q}\right)&=\sum_{n=1}^{q}\frac{2n}{q}\left(\frac{\omega^n+\omega^{-n}}{2}\right)=\frac{\omega}{\omega-1}+\frac{\omega^{-1}}{\omega^{-1}-1} \\
&=\frac{\omega-1}{\omega-1}=1
\end{align}
Replace $q$ with $2q$,
$$
\sum_{n=1}^{2q}\frac{n}{q}\sin\left(\frac{n\pi p}{q}\right)=-\cot\left(\frac{\pi p}{2q}\right)=-\cot\left(\frac{\pi p}{q}\right)-\csc\left(\frac{\pi p}{q}\right)
$$
</s>