(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x) :precision binary64 (expm1 (log1p (* (/ (tan (/ x 2.0)) x) (/ (sin x) x)))))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
return expm1(log1p(((tan((x / 2.0)) / x) * (sin(x) / x))));
}
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
public static double code(double x) {
return Math.expm1(Math.log1p(((Math.tan((x / 2.0)) / x) * (Math.sin(x) / x))));
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
def code(x): return math.expm1(math.log1p(((math.tan((x / 2.0)) / x) * (math.sin(x) / x))))
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function code(x) return expm1(log1p(Float64(Float64(tan(Float64(x / 2.0)) / x) * Float64(sin(x) / x)))) end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(Exp[N[Log[1 + N[(N[(N[Tan[N[(x / 2.0), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision] * N[(N[Sin[x], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]
\frac{1 - \cos x}{x \cdot x}
\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\tan \left(\frac{x}{2}\right)}{x} \cdot \frac{\sin x}{x}\right)\right)



Bits error versus x
Results
Initial program 31.6
Applied flip--_binary6431.7
Simplified15.5
Taylor expanded in x around inf 15.4
Simplified0.1
Applied expm1-log1p-u_binary640.1
Simplified0.1
Final simplification0.1
herbie shell --seed 2022129
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))