For which arguments in the range $0\le x\le \pi/4$ will $\cos x=(1-\sin^2x)^{1/2}$ fail to give good accuracy?

70 Views Asked by At

The question is

In floating point system, consider using the trigonometric identity $\sin^2x+\cos^2x=1$ to compute $\cos x=(1-\sin^2x)^{1/2}$. For which arguments in the range $0\le x\le \pi/4$ will this formula fail to give good accuracy?

I don't know if it is right, but my guess is when $x$ is very small, and I don't know how to exactly find a subrange in $0\le x \le \pi/4$ st. the computation fails to reach good accuracy. Thank you!

1

There are 1 best solutions below

2
On BEST ANSWER

$$ fl(fl(1-fl(fl(\sin x)^2))^{1/2}) =\sqrt{\Bigl(1-(\sin(x)(1+δ_1))^2(1+δ_2)\Bigr)(1+δ_3)}(1+δ_4) $$ which in first order can be transformed to $$ \left(\sqrt{1-\sin^2 x}-\frac12\frac{\sin^2 x(2δ_1+δ_2)}{\sqrt{1-\sin^2 x}}\right)\left(1+\frac{δ_3}2+δ_4\right) \\ =\sqrt{1-\sin^2 x}\left(1-\frac{\sin^2 x}{1-\sin^2 x}\frac{2δ_1+δ_2}2+\frac{δ_3}2+δ_4\right) $$ so that the first order (relative) error bound is $$ \frac32\frac{1}{1-\sin^2 x}\mu $$ which in the given range is problematic for no value. The only critical region is where $\sin^2 x\approx 1$.