# $\arctan$ identities: converting $c \cdot \arctan(\frac{n}{d}) \iff \arctan(\frac{n'}{d'})$

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:

1. Approximate the fraction $\frac{n}{d}$ as a decimal value.
2. Take the $\tan$ of this value, and divide by a small integer factor $q$.
3. 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).
4. 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.

-
It might be worth noting that $c \; \arctan \frac{n}{d} = \arctan \frac{p(n,d)}{q(n,d)}$ with $p$, $q$ such that $p+q$ echoes $r := (d+n)^c$. The (abs.value of) terms in $q$ are "every other" term of $r$, starting with $d^c$; the (abs.value of) terms of $p$ are the remaining terms of $r$. Terms of $q$ alternate sign (with $d^c$ positive), as do those of $p$ (with $d^{c-1}n$ positive), which keeps $p+q$ (or $p-q$) from matching $r$ exactly. (See Vieta's multiple angle formulas.) –  Blue Jun 19 '13 at 8:31

Suppose you want to simplify $X = \arctan(n/d)$. Using complex numbers, $$\exp(iX) = \dfrac{d+in}{\sqrt{d^2 + n^2}}$$ Now factor $d+in$ over the Gaussian integers. If you get a result like $$d + in = (a_1 + i b_1)^{c_1} \ldots (a_k + i b_k)^{c_k}$$ (with $a_i$ and $b_i$ integers and $c_i$ positive integers) you can conclude that $X = c_1 \arctan(b_1/a_1) + \ldots + c_k \arctan(b_k/a_k) + n \pi$ for a suitable integer $n$. Factoring over the Gaussian integers can be done in Maple with the function GIfactor in the GaussInt package.
For example, $3116 + 237 i$ factors as $i (1+2i)^{10}$, so $\arctan(237/3116) = \pi/2 + 10 \arctan(2/1) + n \pi$: in this case $n=-4$ to put it in the interval $(-\pi/2, \pi/2)$.
Another random example: $237 + 524 i = (1+2i)(5+2i)(45-16i)$ (and in this case $n=0$) so $$\arctan\left(\frac{524}{237}\right) = \arctan(2) + \arctan\left(\frac{2}{5}\right) - \arctan\left(\frac{16}{45}\right)$$
Thanks for your answer. It doesn't answer the question exactly as stated, but it has pointed me in the correct direction - what I would need is not a prime factorization, but rather a factorization containing only one factor; an $n^{th}$ root. To use the example above, $\sqrt{3116 + 237i} = \frac{79\sqrt{2}}{2} + \frac{3\sqrt{2}}{2}i$, indicating that $2 \cdot \arctan(\frac{3}{79})$ is a valid simplification. –  primo Jun 19 '13 at 10:00