Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

sine is easy because the series is globally convergent and fast converging


It would also be extremely inaccurate. The x^n numerators grow very quickly and digits get lost because unlimited precision isn't available. Likewise, the n! denominators also grow rapidly. Then the series is alternating which means cancellation is happening for every added term.

If you don't believe me try for x=10.


You need around 26 terms for x=10 if you do it without reduction and you want an accuratish result for double precision.

You wouldn't evaluate the terms naively from left-to-right.

x - x^3/3! + x^5/5! - ... = x * (1 - x^2/(2*3) * (1 - x^2/(4*5) * ... ) )

I just checked in python and you get a result that is around 1000*machine epsilon off. Not great, not terrible.


Did you read the article? It is specifically about how the series looks simple, but the error is actually very bad if you do things naively.


That still makes it easier compared to computing constants in which the series are not globally convergent, like inverse trig functions. Obviously, you would have to break it apart to speed convergence.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: