I am having trouble figuring out how to avoid subtractive cancellation without using Taylor series expansion for this problem:
$x − \sin x$
My initial thought is to use trig identities but I cannot figure out how to manipulate this properly.
I am having trouble figuring out how to avoid subtractive cancellation without using Taylor series expansion for this problem:
$x − \sin x$
My initial thought is to use trig identities but I cannot figure out how to manipulate this properly.
Better than Taylor series would be the simplest Padé approximant $$x-\sin(x)\sim\frac {10 \,x^3}{3(20+x^2)}$$ whose error is $\frac {11x^7}{50400}$.
More accurate would be $$x-\sin(x)\sim\frac {28x^3(990-17x^2)}{15(11088+364x^2+5x^4 ) }$$ whose error is $\frac {11x^{11}}{457228800}$.
If you want to use Taylor series, there is a way to know exactly how many terms must be added for a given accuracy. If $n$ is the number of terms, you need to find $n$ such that $$\frac{x^{2n+3}}{(2n+3)!} \leq 10^{-k}\quad \implies \quad (2n+3)! \geq x^{2n+3}\,10^k$$ and, using the approximation proposed by @robjohn here,
$$n\sim \frac {ex}2\exp\left(\operatorname{W}\left(\frac k{ex}\log(10)-\frac1{2ex}\log(2\pi x)\right)\right)-\frac74$$ where $W(.)$ is Lambert function.