TITLE: How to do a very long division: continued fraction for tan
QUESTION [20 upvotes]: I want to compute $$\tan(r) = \cfrac{r}{1 - \cfrac{r^2}{3 - \cfrac{r^2}{5 - \cfrac{r^2}{7 - {}\ddots}}}}$$ by dividing the power series for sin and cos as it is said can be done in http://arxiv.org/abs/0911.1929.

When I try it I get $$\frac{\sin(r)}{\cos(r)} = \frac{r}{1 + r^2\cdot\frac{\frac{2}{3!} - r^2 \frac{4}{5!} + r^4 \frac{6}{7!} - r^6 \frac{8}{9!} + \cdots}{\cos(r)}}$$ which has sign wrong and the series in the numerator gets mor and more complicated. The next term of the continued fraction comes up as $\frac{2}{3!}$ instead of $3$ and the next series is even more complicated (3 factorials in each summand).
I was using $A = BQ+R$ for the long division and picking $Q$ the leading coefficient of the series.

REPLY [6 votes]: I found this http://www.pi314.net/eng/lambert.php and it works: here it is worked out with details for 3 iterations
$$\begin{eqnarray}
\tan(r) &=& r \Big/
\frac
{1 - \frac{r^2}{2!} + \frac{r^4}{4!} - \frac{r^6}{6!} + \frac{r^8}{8!}+\cdots}
{1 - \frac{r^2}{3!} + \frac{r^4}{5!} - \frac{r^6}{7!} + \frac{r^8}{9!}+\cdots} \\
&=&  r \Big/ 1 - r^2 \Big/
\frac
{1 - \frac{r^2}{3!} + \frac{r^4}{5!} - \frac{r^6}{7!} + \frac{r^8}{9!}+\cdots} {\frac{2}{3!} + \frac{4 \cdot r^2}{5!} - \frac{6\cdot r^4}{7!} + \frac{8\cdot r^6}{9!} + \frac{10\cdot r^8}{11!}+\cdots} &\text{by (1)}
\\
&=&  r \Big/ 1 - r^2 \Big/ 3 - r^2 \Big/
\frac
{\frac{2}{3!} + \frac{4 \cdot r^2}{5!} - \frac{6\cdot r^4}{7!} + \frac{8\cdot r^6}{9!} + \frac{10\cdot r^8}{11!} +\cdots}
{\frac{2 \cdot 4}{5!} + \frac{4 \cdot 6 \cdot r^2}{7!} - \frac{6\cdot 8 \cdot r^4}{9!} + \frac{8 \cdot 10 \cdot r^6}{11!}+ \frac{10 \cdot 12 \cdot r^6}{13!}+\cdots}  &\text{by (2)} \\
&=&  r \Big/ 1 - r^2 \Big/ 3 - r^2 \Big/ 5  - r^2 \Big/
\frac
{\frac{2 \cdot 4}{5!} + \frac{4 \cdot 6 \cdot r^2}{7!} - \frac{6\cdot 8 \cdot r^4}{9!} + \frac{8 \cdot 10 \cdot r^6}{11!}+ \frac{10 \cdot 12 \cdot r^6}{13!}+\cdots}
{\frac{2 \cdot 4 \cdot 6}{7!} - \frac{4 \cdot 6 \cdot 8 \cdot r^2}{9!} + \frac{6 \cdot 8 \cdot 10 \cdot r^4}{11!} - \frac{8 \cdot 10 \cdot 12 \cdot r^6}{13!} + \frac{10 \cdot 12 \cdot 14 \cdot r^8}{15!} + \cdots}  &\text{by (3)} \\
\end{eqnarray}$$
and you can see the next will be $7 - r^2$ by $\frac{2 \cdot 4}{5!} - 7 \cdot \frac{2 \cdot 4 \cdot 6}{5! \cdot 6 \cdot 7} = 0$

For each of the divisions we are doing $A/B = Q + R/B$ we pick $Q$ to make the unit terms 0 and find $R = A - QB$ then use it to get the next part of the continued fraction.
$(1)$ $Q=1$
$$\begin{eqnarray}
1 - 1 &=& 0 \\
-r^2 [\frac{1}{2!} - \frac{1}{3!}] && -r^2 \cdot \frac{2}{3!} \\
+r^4 [\frac{1}{4!} - \frac{1}{5!}] && +r^4 \cdot \frac{4}{5!} \\
-r^6 [\frac{1}{6!} - \frac{1}{7!}] && -r^6 \cdot \frac{6}{7!} \\
&\vdots&
\end{eqnarray}
$$
$(2)$ $Q=3$
$$\begin{eqnarray}
1 - 3\cdot\frac{2}{3!} &=& 0 \\
-r^2 [\frac{1}{3!} - \frac{3\cdot 4}{5!}] && -r^2 \cdot \frac{2 \cdot 4}{5!} \\
+r^4 [\frac{1}{5!} - \frac{3\cdot 6}{7!}] && +r^4 \cdot \frac{4 \cdot 6}{7!} \\
-r^6 [\frac{1}{7!} - \frac{3 \cdot 8}{9!}] && -r^6 \cdot \frac{6 \cdot 8}{9!} \\
&\vdots&
\end{eqnarray}
$$
$(3)$ $Q=5$
$$\begin{eqnarray}
\frac{2}{3!} - \frac{2 \cdot 4 \cdot 5}{2\cdot 3 \cdot 4 \cdot 5} &=& 0 \\
-r^2 [\frac{4}{5!} - \frac{5 \cdot 4 \cdot 6}{7!}] && -r^2 \cdot \frac{2 \cdot 4 \cdot 6}{7!} \\
+r^4 [\frac{6}{7!} - \frac{5 \cdot 6 \cdot 8}{9!}] && +r^4 \cdot \frac{4 \cdot 6 \cdot 8}{9!} \\
-r^6 [\frac{8}{9!} - \frac{5 \cdot 8 \cdot 10}{11!}] && -r^6 \cdot \frac{6 \cdot 8 \cdot 10}{11!} \\
&\vdots&
\end{eqnarray}
$$
and continue to infinty.