On the Wolfram Research Reference page for the cotangent function (<https://functions.wolfram.com/ElementaryFunctions/Cot/23/01/>), I saw the following partial sum formula


$$\sum\_{k=0}^{n-1}(-1)^k\cot\Big(\frac{\pi}{4n}(2k+1)\Big)=n.$$
I was unable to find a reference for it but eventually proved it as described below.


**My Question**


1. A reference for the equation above?
2. Naturally, I wondered what was known about the regular sum of the cotangents above, not the alternating sums. I found no related equation but instead was able to empirically derive the following limit


\begin{align\*}
\lim\_{n\to\infty}\Big[\sum\_{k=0}^{n-1}\frac{1}{2k+1}-\sum\_{k=0}^{n-1}\frac{\pi}{4n}\cot\Big(\frac{\pi}{4n}(2k+1)\Big)\Big]&=\lim\_{n\to\infty}\Big[\Big(H\_{2n}-\frac{1}{2}H\_{n}\Big)-\sum\_{k=0}^{n-1}\frac{\pi}{4n}\cot\Big(\frac{\pi}{4n}(2k+1)\Big)\Big]\\
&=\ln(\sqrt{\pi/2}).
\end{align\*}


Yet, I am stuck on proving this limit and would appreciate any advice on where to begin.


**My Proof for the Equation in the Beginning:**


Consider the well-known partial fraction expansion for the cotangent function,


$$\pi\cot(\pi x)=\frac{1}{x}+\sum\_{k=1}^{\infty}\frac{1}{x-k}+\frac{1}{x+k}$$


excluding integral $x$. Rather unconventionally, let us expand the summation of the RHS and reindex it, getting
\begin{align\*}
\frac{1}{x}+\frac{1}{x-1}+\frac{1}{x+1}+\frac{1}{x-2}+\frac{1}{x+2}+\cdots&=\frac{1}{x}-\frac{1}{1-x}+\frac{1}{x+1}-\frac{1}{2-x}+\frac{1}{x+2}-\cdots\\
&=\sum\_{k=0}^{\infty}\frac{1}{k+x}-\frac{1}{k+1-x}.
\end{align\*}
By letting $x=b/a$ for positive integers $a,b$ such that $a>b\geq1,$ we get


$$\frac{\pi}{a}\cot\Big(\pi\cdot\frac{b}{a}\Big)=\sum\_{k=0}^{\infty}\frac{1}{ak+b}-\frac{1}{ak+a-b}.$$


Consider the equation for $a=4n$ and $b$ from $1$ to $2n-1$. Then,
$$\frac{\pi}{4n}\cot\Big(\pi\cdot\frac{1}{4n}\Big)=\sum\_{k=0}^{\infty}\frac{1}{(4n)k+1}-\frac{1}{(4n)k+4n-1},$$
$$\frac{\pi}{4n}\cot\Big(\pi\cdot\frac{3}{4n}\Big)=\sum\_{k=0}^{\infty}\frac{1}{(4n)k+3}-\frac{1}{(4n)k+4n-3},$$
$$\cdots$$
$$\frac{\pi}{4n}\cot\Big(\pi\cdot\frac{2n-1}{4n}\Big)=\sum\_{k=0}^{\infty}\frac{1}{(4n)k+2n-1}-\frac{1}{(4n)k+2n+1}.$$


By summing up the equations in an alternating fashion (adding the first, subtracting the second, and so on,) the summed $LHS$ equals
$$\frac{\pi}{4n}\sum\_{k=0}^{n-1}(-1)^k\cot\Big(\frac{\pi}{4n}(2k+1)\Big)$$
while the summed RHS is simply the alternating series of the reciprocals of odd numbers, which is well-known by Leibniz to be $\frac{\pi}{4}.$ Hence, we get the initial formula.



The cotangent sum $\sum_{k=0}^{n-1}(-1)^k\cot\Big(\frac{\pi}{4n}(2k+1)\Big)=n$
The expression under the limit sign in question is just a Riemann sum for
$$\int\_0^{\pi/2} \frac12\,\Big(\frac1x-\cot x\Big)\,dx=\frac12\,\ln\frac\pi2,$$
which therefore is the value of the limit.


