Average Error: 31.9 → 0.3
Time: 18.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03115379972147733905751820771001803223044:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{elif}\;x \le 0.02739005695178562543867784029316680971533:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{720}, x \cdot x, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03115379972147733905751820771001803223044:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\

\mathbf{elif}\;x \le 0.02739005695178562543867784029316680971533:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{720}, x \cdot x, \frac{1}{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\

\end{array}
double f(double x) {
        double r857002 = 1.0;
        double r857003 = x;
        double r857004 = cos(r857003);
        double r857005 = r857002 - r857004;
        double r857006 = r857003 * r857003;
        double r857007 = r857005 / r857006;
        return r857007;
}

double f(double x) {
        double r857008 = x;
        double r857009 = -0.03115379972147734;
        bool r857010 = r857008 <= r857009;
        double r857011 = 1.0;
        double r857012 = cos(r857008);
        double r857013 = r857011 - r857012;
        double r857014 = r857013 / r857008;
        double r857015 = r857014 / r857008;
        double r857016 = 0.027390056951785625;
        bool r857017 = r857008 <= r857016;
        double r857018 = -0.041666666666666664;
        double r857019 = r857008 * r857008;
        double r857020 = 0.001388888888888889;
        double r857021 = r857019 * r857020;
        double r857022 = 0.5;
        double r857023 = fma(r857021, r857019, r857022);
        double r857024 = fma(r857018, r857019, r857023);
        double r857025 = r857017 ? r857024 : r857015;
        double r857026 = r857010 ? r857015 : r857025;
        return r857026;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03115379972147734 or 0.027390056951785625 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity1.0

      \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{x \cdot x}\]
    4. Applied times-frac0.5

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. Using strategy rm
    6. Applied associate-*r/0.5

      \[\leadsto \color{blue}{\frac{\frac{1}{x} \cdot \left(1 - \cos x\right)}{x}}\]
    7. Simplified0.5

      \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x}\]

    if -0.03115379972147734 < x < 0.027390056951785625

    1. Initial program 62.4

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity62.4

      \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{x \cdot x}\]
    4. Applied times-frac61.5

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\]
    6. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\frac{1}{720} \cdot \left(x \cdot x\right), x \cdot x, \frac{1}{2}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.03115379972147733905751820771001803223044:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{elif}\;x \le 0.02739005695178562543867784029316680971533:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{720}, x \cdot x, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1.0 (cos x)) (* x x)))