Gauss's Digamma Theorem generalization This website shares a proof for Gauss' Digamma Theorem. Which is
$$
ψ\left(\frac{p}{q}\right) = -\gamma - \frac{\pi}{2}\cot\left(\pi\frac{p}{q}\right) - \ln(q) + \frac{1}{2}\sum_{k=1}^{q-1} \cos\left(2\pi p\frac{k}{q}\right)\ln\left(2-2\cos\left(2\pi\frac{k}{q}\right)\right)
$$
Variables aren't defined there, but Wikipedia states that it holds for positive integers $p, q$, with $p < q$ which I verified numerically. Since I'm not familiar with the concepts used in  the proof and since it is ill-justified, I couldn't locate where those assumptions were used and hence, couldn't find out if there were any generalization via this proof for every integer $p, q$, which is what I need.
 A: Gauss' Digamma Theorem gives a formula for the value of the digamma function, denoted by $\psi(x)$, at a rational number $x = \frac{p}{q}$, where $p$ and $q$ are positive integers with $p < q$. The theorem states that:
$$\psi\left(\frac{p}{q}\right) = -\gamma - \frac{\pi}{2}\cot\left(\pi\frac{p}{q}\right) - \ln(q) + \frac{1}{2}\sum_{k=1}^{q-1} \cos\left(2\pi p\frac{k}{q}\right)\ln\left(2-2\cos\left(2\pi\frac{k}{q}\right)\right)$$
where $\gamma$ is the Euler-Mascheroni constant. The proof of this theorem involves complex analysis and the properties of the digamma function and the cotangent function.
It is not clear if the formula given by Gauss' Digamma Theorem holds for all integers $p$ and $q$. In general, the digamma function can be extended to a function on the complex plane, but its behavior at irrational numbers or non-positive integers is more complicated and not covered by this theorem.
A: You may indeed start with Gauss's_digamma_theorem for the integers $\,0<p<q\,$ :
$$\tag{1}\psi\left(\frac pq\right) = -\gamma -\ln(2q) -\frac{\pi}{2}\cot\left(\frac{\pi p}{q}\right) +2\sum_{n=1}^{\left\lfloor \frac{q-1}{2} \right\rfloor} \cos\left(\frac{2\pi np}q \right) \ln\sin\left(\frac{\pi n}q\right)$$
complete it for negative fractions with $$\tag{2}\psi(-r)=\psi(r)+\pi\cot(\pi r)+\frac 1r$$
and for larger positive fractions use the formula : $$\tag{3}\psi(r)=\psi\left(r-\lfloor r\rfloor\right)+\sum_{k=1}^{\lfloor r\rfloor}\frac 1{r-k}$$
(deduced from the recurrence $\;\displaystyle\psi(r+1)=\psi(r)+\frac 1r\;$)
while the remaining defined cases, i.e. the positive integers, will be provided by $$\tag{4}\psi(n)=H_{n-1}-\gamma$$
$$-$$
I'll add that the reason why the proof for $(1)$ is invalid for the case $p>q>0$ is simply because its starting point is the general formula :
$$\tag{5} \psi\left(\frac pq\right)=-\gamma -\ln(q) +\sum_{n=1}^{q-1} \omega^{-np}\ln(1-\omega^n),\quad \omega:=\exp(2\pi i/q)$$
which is not valid for $p>q$. More exactly the effect of the sum at the right is precisely to remove the effect of the integer part of $\dfrac pq$ (there are only powers of $\omega$ and $\;\displaystyle\omega^q=1$).
In general, for any positive integers $p$ and $q$, we should have :
$$\tag{5'} \psi\left(\frac pq-\left\lfloor\frac pq\right\rfloor\right)=-\gamma -\ln(q) +\sum_{n=1}^{q-1} \omega^{-np}\ln(1-\omega^n),\quad \omega:=\exp(2\pi i/q)$$
