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



Bits error versus x
Results
Initial program 31.8
Applied flip--_binary6431.9
Simplified15.6
Applied *-un-lft-identity_binary6415.6
Applied times-frac_binary6415.1
Simplified0.2
Applied div-inv_binary640.3
Applied associate-*l*_binary640.3
Simplified0.2
Applied expm1-log1p-u_binary640.2
Simplified0.1
Final simplification0.1
herbie shell --seed 2022068
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))