Average Error: 31.2 → 0.2
Time: 5.7s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := {x}^{-2} \cdot \cos x\\ \mathbf{if}\;x \leq -0.00485777750271224:\\ \;\;\;\;\mathsf{fma}\left(1, {x}^{-2}, -t_0\right) + \mathsf{fma}\left(-{x}^{-2}, \cos x, t_0\right)\\ \mathbf{elif}\;x \leq 4.021636854798944 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \left({x}^{-2} \cdot \sin x\right)\\ \end{array} \]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := {x}^{-2} \cdot \cos x\\
\mathbf{if}\;x \leq -0.00485777750271224:\\
\;\;\;\;\mathsf{fma}\left(1, {x}^{-2}, -t_0\right) + \mathsf{fma}\left(-{x}^{-2}, \cos x, t_0\right)\\

\mathbf{elif}\;x \leq 4.021636854798944 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \left({x}^{-2} \cdot \sin x\right)\\


\end{array}
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (pow x -2.0) (cos x))))
   (if (<= x -0.00485777750271224)
     (+ (fma 1.0 (pow x -2.0) (- t_0)) (fma (- (pow x -2.0)) (cos x) t_0))
     (if (<= x 4.021636854798944e-12)
       (fma x (* x -0.041666666666666664) 0.5)
       (* (tan (/ x 2.0)) (* (pow x -2.0) (sin x)))))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = pow(x, -2.0) * cos(x);
	double tmp;
	if (x <= -0.00485777750271224) {
		tmp = fma(1.0, pow(x, -2.0), -t_0) + fma(-pow(x, -2.0), cos(x), t_0);
	} else if (x <= 4.021636854798944e-12) {
		tmp = fma(x, (x * -0.041666666666666664), 0.5);
	} else {
		tmp = tan((x / 2.0)) * (pow(x, -2.0) * sin(x));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.0

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

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

    if -0.00485777750271223965 < x < 4.0216368547989441e-12

    1. Initial program 62.7

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

      \[\leadsto \color{blue}{0.5 - 0.041666666666666664 \cdot {x}^{2}} \]
    3. Simplified0.0

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

    if 4.0216368547989441e-12 < x

    1. Initial program 2.4

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

      \[\leadsto \frac{\color{blue}{\left(\sin x \cdot \sin x\right) \cdot \frac{1}{1 + \cos x}}}{x \cdot x} \]
    3. Taylor expanded in x around inf 1.2

      \[\leadsto \frac{\color{blue}{\frac{{\sin x}^{2}}{1 + \cos x}}}{x \cdot x} \]
    4. Simplified0.9

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

      \[\leadsto \color{blue}{\tan \left(\frac{x}{2}\right) \cdot \left(\sin x \cdot {x}^{-2}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.00485777750271224:\\ \;\;\;\;\mathsf{fma}\left(1, {x}^{-2}, -{x}^{-2} \cdot \cos x\right) + \mathsf{fma}\left(-{x}^{-2}, \cos x, {x}^{-2} \cdot \cos x\right)\\ \mathbf{elif}\;x \leq 4.021636854798944 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{fma}\left(x, x \cdot -0.041666666666666664, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \left({x}^{-2} \cdot \sin x\right)\\ \end{array} \]

Reproduce

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