Average Error: 31.6 → 0.1
Time: 4.6s
Precision: binary64
\[\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) \]
(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)

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 31.6

    \[\frac{1 - \cos x}{x \cdot x} \]
  2. Applied flip--_binary6431.7

    \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x} \]
  3. Simplified15.5

    \[\leadsto \frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{x \cdot x} \]
  4. Taylor expanded in x around inf 15.4

    \[\leadsto \color{blue}{\frac{{\sin x}^{2}}{\left(1 + \cos x\right) \cdot {x}^{2}}} \]
  5. Simplified0.1

    \[\leadsto \color{blue}{\frac{\sin x}{x} \cdot \frac{\tan \left(\frac{x}{2}\right)}{x}} \]
  6. Applied expm1-log1p-u_binary640.1

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin x}{x} \cdot \frac{\tan \left(\frac{x}{2}\right)}{x}\right)\right)} \]
  7. Simplified0.1

    \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\frac{\tan \left(\frac{x}{2}\right)}{x} \cdot \frac{\sin x}{x}\right)}\right) \]
  8. Final simplification0.1

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\tan \left(\frac{x}{2}\right)}{x} \cdot \frac{\sin x}{x}\right)\right) \]

Reproduce

herbie shell --seed 2022129 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1.0 (cos x)) (* x x)))