$\sum_{k=0}^\infty\frac{ (-1)^{\left\lfloor\frac kn\right\rfloor}}{k+1}$ While testing a program I came across an interesting equality:
$$
\sum_{k=0}^\infty\frac{ (-1)^{\left\lfloor\frac kn\right\rfloor}}{k+1}
=\frac1n\left[\log2+\frac\pi2\sum_{k=1}^{n-1}\tan\frac{k\pi}{2n}\right],
$$
which generalises the well-known identity for $n=1$. Is there a simple way to prove it?
 A: For $n \in \mathbb{N}$ write $k = m n + l - 1$ with $m \in \mathbb{N}_0$ and $l \in \{1,\dots,n\}$. Then $\left\lfloor \frac{k}{n} \right\rfloor = m$, so
\begin{align}
S_n &\equiv \sum \limits_{k=0}^\infty \frac{(-1)^{\left\lfloor \frac{k}{n} \right\rfloor}}{k+1} \stackrel{1.}{=} \sum \limits_{l=1}^n \sum \limits_{m=0}^\infty \frac{(-1)^m}{m n +l} = \frac{1}{n} \left[\sum \limits_{m=0}^\infty \frac{(-1)^m}{m+1} + \sum \limits_{l=1}^{n-1} \sum \limits_{m=0}^\infty \frac{(-1)^m}{m + \frac{l}{n}}\right] \\
&\equiv \frac{1}{n} \left[\log (2) + \sum \limits_{l=1}^{n-1} a_l \right] ,
\end{align}
where
$$ a_l = \sum \limits_{m=0}^\infty \frac{(-1)^m}{m + \frac{l}{n}} \stackrel{2.}{=} \sum \limits_{j=0}^\infty \left[\frac{1}{2j + \frac{l}{n}} - \frac{1}{2j+1 + \frac{l}{n}}\right] , \, l \in \{1,\dots,n-1\}.$$
For $l \in \{1,\dots,n-1\}$ consider
\begin{align}
a_l + a_{n-l} &= \sum \limits_{j=0}^\infty \left[\frac{1}{2j + \frac{l}{n}} - \frac{1}{2j+1 + \frac{l}{n}} + \frac{1}{2j+1-\frac{l}{n}} - \frac{1}{2j+2 - \frac{l}{n}}\right] \\
&\stackrel{3.}{=} \frac{\pi}{2} \left[8 \frac{l \pi}{2n} \sum \limits_{j=0}^\infty \frac{1}{(2j+1)^2 \pi^2 - 4 \left(\frac{l \pi}{2n}\right)^2} + \frac{2n}{l\pi} + 2 \frac{l\pi}{2n} \sum \limits_{j=1}^\infty \frac{1}{\left(\frac{l \pi}{2n}\right)^2 - j^2 \pi^2}\right] \\
&= \frac{\pi}{2} \left[\tan \left(\frac{l\pi}{2n}\right) + \cot \left(\frac{l\pi}{2n}\right)\right] = \frac{\pi}{2} \left[\tan \left(\frac{l\pi}{2n}\right) + \tan \left(\frac{(n-l)\pi}{2n}\right)\right] .
\end{align}
The pole expansions of $\tan$ and $\cot$ are discussed here and here, respectively. This also works for $l = \frac{n}{2}$ if $n$ is even, so we obtain
$$ S_n = \frac{1}{n}\left[\log(2) + \frac{\pi}{2} \sum \limits_{l=1}^{n-1} \tan \left(\frac{l \pi}{2n}\right)\right]$$
as conjectured.

Justification of the rearrangements:


*

*For $L \in \{1,\dots,n\}$ and $M \in \mathbb{N}_0$ we have
$$ \sum \limits_{k=0}^{M n + L - 1} \frac{(-1)^{\left\lfloor \frac{k}{n} \right\rfloor}}{k+1} = \sum \limits_{l=1}^L \sum \limits_{m=0}^M \frac{(-1)^m}{m n +l} + \sum \limits_{l=L+1}^n \sum \limits_{m=0}^{M-1} \frac{(-1)^m}{m n +l} \stackrel{M \to \infty}{\longrightarrow} \sum \limits_{l=1}^n \sum \limits_{m=0}^\infty \frac{(-1)^m}{m n +l} \, . $$
Therefore, the sequence $ \left(\sum_{k=0}^{K} \frac{(-1)^{\left\lfloor k/n \right\rfloor}}{k+1}\right)_{K \in \mathbb{N}_0}$ is bounded and has exactly one limit point (namely $\sum_{l=1}^n \sum_{m=0}^\infty \frac{(-1)^m}{m n +l}$), to which it must converge.

*For $M \in \mathbb{N}_0$ we have
\begin{align} \sum \limits_{m=0}^M \frac{(-1)^m}{m + \frac{l}{n}} &= \sum \limits_{j=0}^{\left\lfloor \frac{M}{2}\right\rfloor} \frac{1}{2j + \frac{l}{n}} - \sum \limits_{j=0}^{\left\lfloor \frac{M-1}{2}\right\rfloor} \frac{1}{2j + 1 + \frac{l}{n}} \\
&= \sum \limits_{j=0}^{\left\lfloor \frac{M}{2}\right\rfloor} \left[\frac{1}{2j + \frac{l}{n}} - \frac{1}{2j+1 + \frac{l}{n}}\right] + \frac{\mathbf{1}_{2\mathbb{N}} (M)}{M+1 + \frac{l}{n}} 
\end{align}
and letting $M \to \infty$ proves the asserted equality.

*For $J \in \mathbb{N}_0$ we can write
$$ \sum \limits_{j=0}^J \left[\frac{1}{2j + \frac{l}{n}} - \frac{1}{2j+2 - \frac{l}{n}}\right] = \frac{n}{l} - \frac{1}{2J + 2 - \frac{l}{n}} + \sum \limits_{j=1}^{J} \left[\frac{1}{2j + \frac{l}{n}} - \frac{1}{2j - \frac{l}{n}}\right] .$$
Both sides converge as $J \to \infty$ and the limits must be equal.

