Given an algebraic number $a$, find the closed form of $\arctan (a)$ More precisely:
Given an algebraic number $a\ge0$, can we determine if there exists a rational number $b$ such that
$$\arctan (a)=\int_0^a \frac{dx}{x^2+1}=\pi b?$$
If so, can we find the rational number $b$?
Examples:
$$\arctan (2-\sqrt{3})=\frac{\pi}{12}$$
$$\arctan \left(\sqrt{5-2\sqrt{5}}\right)=\frac{\pi}{5}$$
Note: I know how to do the "reverse procedure" (i.e. given a rational number $b$, find the algebraic number $\tan (\pi b)$).
 A: If $a=\tan\theta$, then
$$e^{i\theta}=\cos\theta+i\sin\theta=\pm\frac{1+ia}{\sqrt{a^2+1}}.$$
Now, note that $\theta$ is a rational multiple of $\pi$ if and only if $\omega=e^{i\theta}$ is a root of unity, i.e. if and only if it satisfies $\omega^n=1$ for some positive integer $n$. Furthermore, in this case, $\omega$ will be a root of the $n$th cyclotomic polynomial, which has degree $\varphi(n)$, which satisfies the inequality $\varphi(n)\geq \sqrt{n/2}$. So, we can follow the following procedure:

*

*Given $a$, compute $\omega=\frac{1+ia}{\sqrt{a^2+1}}$.

*If $\omega$ has minimal polynomial with degree $d$, compute $\omega^1,\omega^2,\dots,\omega^{2d^2}$. If none of these is $1$, then $\omega$ is not a root of unity, and $a\neq\tan(\pi b)$ for any rational $b$.

*If one of them, say $\omega^n$, is $1$, then $\omega$ is an $n$th root of unity, and $a=\tan\left(\frac{2\pi k}{n}\right)$ for some integer $0\leq k<n$. Compute $k$ by computing each of these values and checking them against $a$.

