Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have need to compute the functions: $$ f(x) = \frac{\sin^{-1}x}{x}$$ and $$ g(x) = \frac{\sin a x}{\sin x} $$ where $a\in[0,1]$ and $ x\in[0,\frac{\pi}{2}]$ and is often very small ($x\ll 1$). Are there any general ways of generating highly accurate algorithms for "special" functions like these?

share|improve this question
up vote 9 down vote accepted

Do a polynomial expansion (a la l'Hopital's rule) for both enumerator and denominator and you get a rational function that, for small $x$, will approximate the function well.

As an example: $$ \frac{\sin ax}{\sin x} \approx \frac{ax-\tfrac 1{3!}(ax)^3 + \ldots}{x-\tfrac 1{3!}x^3 + \ldots} = \frac{a-\tfrac 1{3!}a^3x^2 + \ldots}{1-\tfrac 1{3!}x^2 + \ldots}. $$

You can do better if you have an idea of the range of values $x$ at which you want to evaluate. You can then replace the Taylor expansion around $x_0=0$ above by a better suited interpolation of projection approach for the range of $x$.

share|improve this answer

My approach is to use software like SymPy as follows:

from sympy import var, sin, S
var("x a")
g = sin(a*x)/sin(x)
gseries = g.series(x, 0, 10).removeO()
s = {x: S(1)/100, a: S(1)/2}
print gseries.subs(s).n(30)
print g.subs(s).n(30)
print "%.17f" % g.subs({x: 1./100, a: 1./2})

which prints:


The first number is a Taylor series expansion truncated at 10 terms, the second number is the exact evaluation. SymPy uses exact arithmetic, in this example I used x = 1/100 and a = 1/2, but you can play with that. Finally, I evaluate it to 30 decimal digits so that one can easily compare the numbers. The third number is a double precision evaluation using Python's floats.

In this case, it seems to me that there is no cancellation. But for other expressions the direct double precision evaluation might no be accurate enough and then series expansion is one way to evaluate it. The other is rational approximation, I have used MiniMaxApproximation in Mathematica in the past with great success.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.