[Haskell-cafe] Sinus in Haskell

jerzy.karczmarczuk at info.unicaen.fr jerzy.karczmarczuk at info.unicaen.fr
Sat Nov 10 05:42:37 EST 2007

Carl Witty writes: 

> On Sat, 2007-11-10 at 01:29 +0100, Daniel Fischer wrote:
>> ... do you know 
>> how these functions are actually implemented? Do they use Taylor 
>> series or other techniques?
> I don't really know that much about it; 
> ... It seems likely that this instruction (and library
> implementations on architectures where sin is not built into the
> processor) use Taylor series, but I don't know for sure.


No, Gentlemen, nobody rational would use Taylor nowadays! It is lousy. 

First, Chebyshev approximations give better *uniform convergence*.
Then, a *rational* approximation gives you the same precision with
less coeffs. Nowadays the division is not sooo much more expensive
than the multiplication, so the efficiency doesn't suffer much. 

Then, you have plenty of recursive formulae, for example: 

sin 3x = 3*sin x - 4*(sin x)^3 

which converges as it does, x -> x/3 for one step... There are more
complicated as well. Of course, for x sufficiently small use other
approx., e.g. sin x =  x. 

Finally, you have CORDIC (Volder, 1959).
Original CORDIC may be used for tan(x), then sin=tan/sqrt(1+tan^2), and
the square root can be obtained by Newton, *real fast*. 

CORDIC is explained everywhere, if you want to learn it. Start with
Wikipedia, of course... 

Jerzy Karczmarczuk 

More information about the Haskell-Cafe mailing list