Numerical Computation of arcsin and arctan for real numbers [closed]

I'm coding some numerical methods and I do not know what the correct analysis would be for choosing the implementation for $arcsin$ and $arctan$ for real numbers. Here's what I know:

Both functions have Taylor series about the origin that converge in $(-1, 1)$. The actual domain of $\arcsin$ is $[1, 1]$, and the domain of $\arctan$ is $(-\infty, \infty)$.

1. For $\arcsin$, I can cover the whole domain by using $\arcsin(x) = \frac{\pi}2 - \arcsin\sqrt{1 - x^2}$. This guarantees $x^2 < \frac 12$, and the Taylor series can be used.

2. For $\arctan$, I can reduce $|x|$ by a factor greater than $2$ by using $\arctan(x) = 2\arctan\left(\frac x{1 + \sqrt{1 + x^2}}\right)$. This reduction can be repeated until $|x|$ is smaller than a prespecified value, but one reduction is enough to get inside the convergent region. Note also that the Taylor series of $\arctan$ has alternating signs, but the Taylor series of $arcsin$ has only one sign.

I also know that

• $\arctan(x) = \arcsin\left(\frac x{\sqrt{x^2 + 1}}\right)$
• $\arcsin(x) = 2\arctan\left(\frac x{1 + \sqrt{1 - x^2}}\right)$

That means I can use the first equation to reduce $\arctan$ to $\arcsin$ then use method 1, or use the second equation to reduce $\arcsin$ to $\arctan$ then use method 2.

My question is what should I use? I am under the impression that the Taylor series of $\arcsin(x)$ converges a little faster than $\arctan(x)$ termwise, so method 1 may be better. But method 2 allows arbitrary reduction of $|x|$ (at the cost of one square root per reduction), so convergence could be made faster(?). I'm a bit concerned about alternating signs in the Taylor series of $\arctan$ too.

-

closed as off topic by Gerry Myerson, Andy Putman, Suvrit, Andrés E. Caicedo, Lee MosherAug 9 '12 at 16:12

Questions on MathOverflow are expected to relate to research level mathematics within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

I don't think this question has a research angle, and research is what this website is about. – Gerry Myerson Aug 9 '12 at 5:30
Any decent numerical mathematical functions library should have implementations of arctan and arcsin. Don't try to reinvent the wheel. – Robert Israel Aug 9 '12 at 6:53
I second Robert's advice 200% :-) – Suvrit Aug 9 '12 at 8:44
Standard libraries normally use Chebyshev polynomials, not Taylor series. Taylor series have undersirable properties. With Chebyshev polynomials, you have the same upper bound on the error throughout its domain. A useful book covering this sort of thing is Numerical Recipes: The Art of Scientific Computing, by Press et al. – Ben Crowell Aug 9 '12 at 15:19

What is your actual goal? To get a fixed accuracy? Arbitrary accuracy? An interesting method is CORDIC. It involves a limited amount of table lookup, addition and division by 2 (so bit shift if computations are in binary) but no multiplication. You seem willing to store $\pi$ so at least some lookup seems allowed. This is most directly used for $\tan$ or $\sin$ but you can as easily run it in reverse to find inverse functions.

Still, with a hardware multiply a power series may be more efficient.

I'd guess that the series $\arcsin(x)=x+{\frac {1}{6}}{x}^{3}+{\frac {3}{40}}{x}^{5}+{\frac {5}{112}}{x}^{7 }+{\frac {35}{1152}}{x}^{9}+{\frac {63}{2816}}{x}^{11}+ \dots$ with all coefficients positive and rapidly decreasing is better than the alternating $\arctan(x)=x-{\frac {1}{3}}{x}^{3}+{\frac {1}{5}}{x}^{5}-{\frac {1}{7}}{x}^{7}+{ \frac {1}{9}}{x}^{9}-{\frac {1}{11}}{x}^{11}+\dots.$

Then there are Pade series such as $$\arcsin(x) \approx \frac{ {\frac {69049}{922320}}{x}^{5}-{\frac {1709}{2196}}{x}^{3} +x }{ {\frac {1075}{6832} }{x}^{4}-{\frac {2075}{2196}}{x}^{2}+1 }$$

which can be more accurate for some values (Perhaps $x \gt 0.2$ compared to the Taylor series above.)

-

If you want a competitive implementation you have to know what you're doing. This book looks good, though I haven't read it myself:

http://perso.ens-lyon.fr/jean-michel.muller/SecondEdition.html

-