Mathematically, sin(arcsin(x)) equals x for x between -1 and 1. In floating point, both functions are approximations. If I keep feeding the result back in, how many iterations might it take to lose eight digits of accuracy?
How many times can I repeat sin(arcsin(x)) before precision gets noticeably worse?
Answers
There isn't a general iteration count. It depends on the starting value, floating-point format and math library. A round trip might change the last bit, return the same value immediately, or move through a sequence of representable values before settling or cycling.
It is tempting to assume each pass adds another bit of error, but the rounding errors are deterministic and can cancel or stop changing the result. So even a billion iterations won't necessarily produce a noticeable loss.
Reply to this answer
Try a loop and measure it, but define the target first. Losing eight significant digits means something different from having an absolute error of 0.00000001. Near zero, relative error also needs special handling.
Compare each result with the original floating-point input, not just the previous result. Record whether it stops changing or repeats, and try several inputs, including zero and values close to both endpoints. Print enough digits to distinguish nearby floating-point numbers.
sAfeToSkipIntro:
Good distinction. I'll compare against the original input and check for a fixed point rather than assuming the error keeps growing.
Reply to this answer
Watch the order of the calls. sin(arcsin(x)) is an identity on the domain of arcsin. arcsin(sin(x)) is also an identity on the principal interval from minus pi over two to pi over two, but not for arbitrary x. The latter can change a value substantially even in exact arithmetic.
Repeatedly applying several sine calls followed by several arcsine calls is a different experiment from alternating them. Those intermediate operations don't cancel in the same way.
Reply to this answer
Values near 1 and -1 are worth testing, since arcsin has a steep slope there. A small error in its input can make a larger change in the intermediate angle. But the following sine also has a small slope near those angles, so that observation alone doesn't tell you how much the full round trip will drift.
Binary double precision has roughly 15 to 17 decimal digits of precision. That describes the format, not a guaranteed number of digits lost per iteration. The actual math function implementations matter too.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Vozzi:
A fixed point doesn't have to be the original input. The result could change once and then stay at that nearby value.