Solution (source code)

= Solution

Factor out the same half-angle phase from the numerator and denominator:
$$
\frac{1+e^{-i\theta}}{1-e^{-i\theta}}
=\frac{e^{-i\theta/2}(e^{i\theta/2}+e^{-i\theta/2})}{e^{-i\theta/2}(e^{i\theta/2}-e^{-i\theta/2})}
=\boxed{-i\cot\frac\theta2}.
$$
Here <Euler's formula> converts the bracketed sums to cosine and sine. Both sides require $\theta\notin2\pi\mathbb Z$; at the excluded angles the original denominator vanishes.