Average Error: 31.4 → 0.3
Time: 6.0s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.6606336791038125:\\ \;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \leq 0.00033956055970997177:\\ \;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{x}^{-2} - {x}^{-2} \cdot \cos x\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (if (<= x -1.6606336791038125)
   (* (pow x -2.0) (- 1.0 (cos x)))
   (if (<= x 0.00033956055970997177)
     (fma
      0.001388888888888889
      (pow x 4.0)
      (fma -0.041666666666666664 (* x x) 0.5))
     (- (pow x -2.0) (* (pow x -2.0) (cos x))))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double tmp;
	if (x <= -1.6606336791038125) {
		tmp = pow(x, -2.0) * (1.0 - cos(x));
	} else if (x <= 0.00033956055970997177) {
		tmp = fma(0.001388888888888889, pow(x, 4.0), fma(-0.041666666666666664, (x * x), 0.5));
	} else {
		tmp = pow(x, -2.0) - (pow(x, -2.0) * cos(x));
	}
	return tmp;
}
function code(x)
	return Float64(Float64(1.0 - cos(x)) / Float64(x * x))
end
function code(x)
	tmp = 0.0
	if (x <= -1.6606336791038125)
		tmp = Float64((x ^ -2.0) * Float64(1.0 - cos(x)));
	elseif (x <= 0.00033956055970997177)
		tmp = fma(0.001388888888888889, (x ^ 4.0), fma(-0.041666666666666664, Float64(x * x), 0.5));
	else
		tmp = Float64((x ^ -2.0) - Float64((x ^ -2.0) * cos(x)));
	end
	return tmp
end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -1.6606336791038125], N[(N[Power[x, -2.0], $MachinePrecision] * N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.00033956055970997177], N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision] + N[(-0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -2.0], $MachinePrecision] - N[(N[Power[x, -2.0], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -1.6606336791038125:\\
\;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\

\mathbf{elif}\;x \leq 0.00033956055970997177:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right)\right)\\

\mathbf{else}:\\
\;\;\;\;{x}^{-2} - {x}^{-2} \cdot \cos x\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if x < -1.6606336791038125

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Applied egg-rr1.2

      \[\leadsto \frac{\color{blue}{\frac{\sin x \cdot \sin x}{1 + \cos x}}}{x \cdot x} \]
    3. Applied egg-rr0.6

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

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

      \[\leadsto \color{blue}{{x}^{-2} \cdot \left(1 - \cos x\right)} \]

    if -1.6606336791038125 < x < 3.3956055970997177e-4

    1. Initial program 62.4

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Taylor expanded in x around 0 0.1

      \[\leadsto \color{blue}{0.5 + \left(-0.041666666666666664 \cdot {x}^{2} + 0.001388888888888889 \cdot {x}^{4}\right)} \]
    3. Simplified0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.001388888888888889, {x}^{4}, \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right)\right)} \]

    if 3.3956055970997177e-4 < x

    1. Initial program 1.3

      \[\frac{1 - \cos x}{x \cdot x} \]
    2. Applied egg-rr0.6

      \[\leadsto \color{blue}{{x}^{-2} - \cos x \cdot {x}^{-2}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.6606336791038125:\\ \;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \leq 0.00033956055970997177:\\ \;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{x}^{-2} - {x}^{-2} \cdot \cos x\\ \end{array} \]

Reproduce

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