\frac{1 - \cos x}{x \cdot x}
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin x}{x} \cdot \frac{\sin \left(\frac{x}{2}\right)}{x \cdot \cos \left(\frac{x}{2}\right)}\right)\right)
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x) :precision binary64 (expm1 (log1p (* (/ (sin x) x) (/ (sin (/ x 2.0)) (* x (cos (/ x 2.0))))))))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
return expm1(log1p((sin(x) / x) * (sin(x / 2.0) / (x * cos(x / 2.0)))));
}



Bits error versus x
Results
Initial program 31.5
Applied flip--_binary6431.7
Simplified16.3
Applied expm1-log1p-u_binary6416.3
Simplified0.1
Applied tan-quot_binary640.1
Applied associate-/l/_binary640.1
Applied pow1_binary640.1
Final simplification0.1
herbie shell --seed 2022095
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))