Let $p(x)$ be a polynomial, and assume that $ \int_{a}^{b} p(x) \cot \left(\frac{ax}{2} \right) \, \mathrm dx $ converges.
How do you prove that $$ \int_{a}^{b} p(x) \cot \left(\frac{ax}{2} \right) \, \mathrm dx = 2 \sum_{n=0}^{\infty} \int_{a}^{b} p(x) \sin(anx) \, \mathrm dx? $$
I can verify that this identity is true in particular cases, but I'm not sure how to prove it.
EDIT:
The lower limit of the integral and the integrand parameter don't need to be the same.
So the identity could be written as $$ \int_{a}^{b} p(x) \cot \left(\frac{ r x}{2} \right) \, \mathrm dx = 2 \sum_{n=0}^{\infty} \int_{a}^{b} p(x) \sin( r nx) \, \mathrm dx .$$
And as was mentioned below, $p(x)$ doesn't need to be a polynomial.
There are three other similar identities:
$$ \begin{align*} &\int_{a}^{b} p(x) \tan \left(\frac{rx}{2} \right) \, \mathrm dx = -2 \sum_{n=0}^{\infty} (-1)^{k} \int_{a}^{b} p(x) \sin(rnx) \, \mathrm dx \\ &\int_{a}^{b} p(x) \csc \left(rx \right) \, \mathrm dx = 2 \sum_{n=0}^{\infty} \int_{a}^{b} p(x) \sin[(2n+1)rx] \, \mathrm dx \\ &\int_{a}^{b} p(x) \sec \left(rx \right) \, \mathrm dx = 2 \sum_{n=0}^{\infty} (-1)^{k} \int_{a}^{b} p(x) \cos[(2n+1)rx] \, \mathrm dx \end{align*} $$
They can all be derived in the way Daniel Fischer derived the original one by using the following finite sums:
$$ \begin{align} &\sum_{n=0}^{N} (-1)^{n} \sin(rnx) = - \frac{1}{2} \tan \left(\frac{rx}{2}\right) + \frac{(-1)^{N} \sin [(N+\frac{1}{2})rx]}{2\cos (\frac{rx}{2})} \\ &\sum_{n=0}^{N} \sin [(2n+1)rx] = \frac{1}{2} \csc (rx) - \frac{\cos [2(N+1)rx]}{2 \sin (rx)} \\ &\sum_{n=0}^{N} (-1)^{n} \cos [(2n+1)rx] = \frac{1}{2} \sec(rx) + \frac{(-1)^{N}\cos [2(N+1)rx]}{2 \cos (rx)} \end{align}$$