Average Error: 31.4 → 0.4
Time: 6.5s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x} \]
\[\begin{array}{l} t_0 := 1 - \cos x\\ \mathbf{if}\;x \leq -0.10095045016015487:\\ \;\;\;\;\frac{{\left({t_0}^{3}\right)}^{0.3333333333333333}}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.10469358202942775:\\ \;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, 0.5\right) - \mathsf{fma}\left(0.041666666666666664, x \cdot x, 2.48015873015873 \cdot 10^{-5} \cdot {x}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{e^{\log t_0 \cdot 0.5}}{x}\right)}^{2}\\ \end{array} \]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.10095045016015487:\\
\;\;\;\;\frac{{\left({t_0}^{3}\right)}^{0.3333333333333333}}{x \cdot x}\\

\mathbf{elif}\;x \leq 0.10469358202942775:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, 0.5\right) - \mathsf{fma}\left(0.041666666666666664, x \cdot x, 2.48015873015873 \cdot 10^{-5} \cdot {x}^{6}\right)\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{e^{\log t_0 \cdot 0.5}}{x}\right)}^{2}\\


\end{array}
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- 1.0 (cos x))))
   (if (<= x -0.10095045016015487)
     (/ (pow (pow t_0 3.0) 0.3333333333333333) (* x x))
     (if (<= x 0.10469358202942775)
       (-
        (fma 0.001388888888888889 (pow x 4.0) 0.5)
        (fma 0.041666666666666664 (* x x) (* 2.48015873015873e-5 (pow x 6.0))))
       (pow (/ (exp (* (log t_0) 0.5)) x) 2.0)))))
double code(double x) {
	return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
	double t_0 = 1.0 - cos(x);
	double tmp;
	if (x <= -0.10095045016015487) {
		tmp = pow(pow(t_0, 3.0), 0.3333333333333333) / (x * x);
	} else if (x <= 0.10469358202942775) {
		tmp = fma(0.001388888888888889, pow(x, 4.0), 0.5) - fma(0.041666666666666664, (x * x), (2.48015873015873e-5 * pow(x, 6.0)));
	} else {
		tmp = pow((exp((log(t_0) * 0.5)) / x), 2.0);
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.0

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

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

    if -0.100950450160154873 < x < 0.10469358202942775

    1. Initial program 62.1

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

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

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

    if 0.10469358202942775 < x

    1. Initial program 1.0

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

      \[\leadsto \color{blue}{{\left(\frac{\sqrt{1 - \cos x}}{x}\right)}^{2}} \]
    3. Applied egg-rr0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.10095045016015487:\\ \;\;\;\;\frac{{\left({\left(1 - \cos x\right)}^{3}\right)}^{0.3333333333333333}}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.10469358202942775:\\ \;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, 0.5\right) - \mathsf{fma}\left(0.041666666666666664, x \cdot x, 2.48015873015873 \cdot 10^{-5} \cdot {x}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{e^{\log \left(1 - \cos x\right) \cdot 0.5}}{x}\right)}^{2}\\ \end{array} \]

Reproduce

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