If one has an expression of the form $c \cdot \arctan(\frac{n}{d})$, it can be converted to an equivalent expression of the form $\arctan(\frac{n'}{d'})$ fairly easily, using
$c \cdot \arctan(\frac{n}{d}) = \underbrace{\arctan(\frac{n}{d}) + \arctan(\frac{n}{d}) + \dots + \arctan(\frac{n}{d})}_{\text{c}}$
with the identity
$\arctan(\frac{a}{b}) + \arctan(\frac{c}{d}) = \arctan(\frac{a \cdot d + c \cdot b}{b \cdot d - a \cdot c})$
It can be seen, for example, that $4 \cdot \arctan(\frac{1}{5}) = \arctan(\frac{120}{119})$.
The inverse conversion seems to be a bit more complicated. If one is given, for example $\arctan(\frac{237}{3116})$, what would the best method to determine its 'simplest representation'? I will define this as the form $c \cdot \arctan(\frac{n}{d})$, such that $c \in \mathbb{Z}$; $n, d \in \mathbb{N}$, and $d$ has the smallest value possible. For the example above, the simplest representation would be $2 \cdot \arctan(\frac{3}{79})$.
My current method is the following:
- Approximate the fraction $\frac{n}{d}$ as a decimal value.
- Take the $\tan$ of this value, and divide by a small integer factor $q$.
- Take the $\arctan$ of this quotient, and approximate to the nearest fraction with denominator no larger than ~$10^{12}$ (or a few orders of magnitude less than floating point precision).
- Continue until a simplification is found, or give up after $q$ becomes 'too large'.
This method works, sort of, but it has a lot of problems. It's very slow computationally, it's non-deterministic, and it often finds simplifications that are only approximations, and not exact identities.
I'm quite sure that there must be a better method for this, but I've been unable to find one. Thanks in advance.