I'm looking for a closed-form expression for tan (q\*pi) for q rational, or an algorithm that generates one, or some other means of compactly describing the closed-form without referencing an infinite series.


It seems to me that tan(q\*pi) should at least be algebraic for q rational. So, it seems like a closed form could exist, using e.g. a facorization-dependent mix of the double-angle, half-angle, one-third-angle, etc, formulas.



Is there a closed form for tan(q*pi) with q rational?
$$\tan x = \frac{\exp(i x) - \exp(-i x)}{\exp(i x) + \exp(- i x)}.$$
In your case, 


$$\tan (p \pi/q) = \tan (p 2\pi / (2 q).$$ 
Which equals
$$\frac{\omega^{2p} - 1}{\omega^{2p} + 1},$$
where $\omega$ is the primitive $2q$-th root of unity.


