Let $p$ and $q$ be two positive coprime integers. I found in a research paper the following identity $$\sum_{m=1}^{q-1}\left\{\frac{mp}{q}\right\}\cot\left(\frac{\pi m}{q}\right)=\sum_{m=1}^{q-1}\frac{m}{q}\cot\left(\frac{\pi m \bar{p}}{q}\right)$$ where $1\le\bar{p}\le q$ is the inverse of $p$ modulo $q$ and $\{\cdot\}$ denotes the fractional part.
I have trouble understanding how they pass from the left-hand side to the right-hand side of the displayed equation. Any clarification would be appreciated.
It's due to both $\{x\}$ and $\cot(\pi x)$ being periodical with period $1$, so $\{\frac xq\}$ and $\cot(\pi \frac xq)$ have period $q$. Instead of going over the $m$'s, we just go over $m\bar{p}\mod q$.