While trying to evaluate for $n \ge 2$ integer the sum $$\sum_{r=0}^{n-2} 2^r \tan \frac{\pi}{2^{n-r}}$$ I remembered that, for any $k\in\mathbb{N}$, the following identity holds $$\sin x=2^k \sin \frac{x}{2^k} \prod_{j=1}^k \cos \frac{x}{2^j}$$ So, for $k=n-r$, with $n\ge 2$, I get that $$2^{n-r} \sin \frac{x}{2^{n-r}}=\sin x \left(\prod_{j=1}^{n-r} \cos \frac{x}{2^j}\right)^{-1}\iff 2^r \sin \frac{x}{2^{n-r}}=2^{2r-n}\sin x \left(\prod_{j=1}^{n-r} \cos \frac{x}{2^j}\right)^{-1}$$ Substitung $x=\pi$, the right hand side is $0$ and so I get that $$0=2^r \sin \frac{\pi}{2^{n-r}}$$ And this implies that $2^r \tan \frac{\pi}{2^{n-r}}=0$ and so the sum is $0$.
However this is surely wrong, for two reasons: because it is not true that it is always $0=2^r \sin \frac{\pi}{2^{n-r}}$ (it is enough to substitute $r=0$ and $n=2$) and, if I'm not wrong, for any $0 \le r \le n-2$ and for any $n \ge 2$ it is $0<\frac{\pi}{2^{n-r}}<\frac{\pi}{2}$ and so for any $0 \le r \le n-2$ and for any $n \ge 2$ it is $2^r \tan \frac{\pi}{2^{n-r}}>0$, hence the sum is surely positive being a sum of positive numbers.
Indeed, using the identity $\tan \theta=\cot \theta -2\cot 2\theta$, is it possible to prove that for any $n \ge 2$ integer $$\sum_{r=0}^{n-2} 2^r \tan \frac{\pi}{2^{n-r}}=\cot \frac{\pi}{2^n}$$
I suspect that the problem is when I divide both sides for $\prod_{j=1}^{n-r} \cos \frac{x}{2^j}$, because it can be $0$ and so the identity doesn't hold anymore: $$\prod_{j=1}^{n-r} \cos \frac{x}{2^j}=0 \iff \cos \frac{x}{2^j}=0, \ j\in\{1,...,n-r\} \iff x=2^{j-1} \pi+2^j h\pi, \ j\in\{1,...,n-r\}, h\in\mathbb{Z}$$ And, for example, for $j=1$ and $h=0$ the product is indeed $0$ and so I've divided by $0$ at least one time. Is this the reason why my reasoning doesn't work?
Moreover, I would like to ask what really is $$\lim_{n \to \infty} \sum_{r=0}^{n-2} 2^r \tan \frac{\pi}{2^{n-r}}$$ Can this be considered a series? I'm unsure because usually in a series the index that goes to infinity is not both in the upper summation bound and in the sequence we are summing, like in this case. So I don't know if I can use any criteria I know to study it, instead of just hoping that, like in this situation, I can evaluate explicitly the sum and say that $$\sum_{r=0}^{n-2} 2^r \tan \frac{\pi}{2^{n-r}}=\lim_{n\to\infty} \cot \frac{\pi}{2^n}=\infty$$