TITLE: Calculate: $\sum_{k=0}^{n-2} 2^{k} \tan \left(\frac{\pi}{2^{n-k}}\right)$
QUESTION [11 upvotes]: Calculate the following sum for integers $n\ge2$:
$$\sum_{k=0}^{n-2} 2^{k} \tan \left(\frac{\pi}{2^{n-k}}\right)$$ 
I'm trying to obtain a closed form if that is possible.

REPLY [10 votes]: Consider
$$\prod_{k = 0}^{n - 2}\cos(2^k \theta)$$
Multiplying numerator and denominator by $2\sin(\theta)$ we get,
$$\frac{2\sin(\theta)\cos(\theta)}{2\sin(\theta)}\prod_{k = 1}^{n - 2} \cos(2^k\theta) = \frac{\sin(2\theta)}{2\sin(\theta)}\prod_{k = 1}^{n - 2} \cos(2^k\theta)$$
Now, repeatedly multiplying and dividing by 2, we can reduce the above to,
$$\prod_{k = 0}^{n - 2}\cos(2^k \theta) = \frac{\sin(2^{n - 1} \theta)}{2^{n - 1} \sin(\theta)}$$
Take logs on both sides,
$$\sum_{k = 0}^{n - 2}\ln(\cos(2^k \theta)) = \ln(\sin(2^{n - 1} \theta)) - \ln(2^{n - 1}) - \ln(\sin(\theta))$$
Differentiating both sides w.r.t $\theta$ we get,
$$-\sum_{k = 0}^{n - 2}2^k\tan(2^k \theta) = 2^{n - 1}\cot(2^{n - 1} \theta) - \cot(\theta)$$
Substitute $\theta = \frac{\pi}{2^n}$ above to get,
$$\sum_{k = 0}^{n - 2}2^k\tan\left(\frac{\pi}{2^{n - k}}\right) = \cot\left(\frac{\pi}{2^n}\right)$$