Gauss's Digamma Theorem

Theorem
Let $\dfrac p q$ be a positive rational number with $p < q$.

Then:


 * $\displaystyle \psi \left({\frac p q}\right) = -\gamma - \ln 2 q - \frac \pi 2 \cot \left({\frac p q \pi}\right) + 2 \sum_{n \mathop = 1}^{\left\lceil{q / 2}\right\rceil - 1} \cos \left({\frac {2 \pi p n} q}\right) \ln\left({\sin \left({\frac {\pi n} q}\right)}\right)$

where:
 * $\psi$ is the digamma function
 * $\cot$ is the cotangent function
 * $\ln$ is the natural logarithm.