Average Error: 31.4 → 0.3
Time: 4.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.033021090300861429 \lor \neg \left(x \le 0.0281293960182661361\right):\\ \;\;\;\;\frac{\sqrt{\sqrt[3]{{\left(\sqrt[3]{\left(1 - \cos x\right) \cdot \left(1 - \cos x\right)} \cdot \sqrt[3]{1 - \cos x}\right)}^{3}}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.033021090300861429 \lor \neg \left(x \le 0.0281293960182661361\right):\\
\;\;\;\;\frac{\sqrt{\sqrt[3]{{\left(\sqrt[3]{\left(1 - \cos x\right) \cdot \left(1 - \cos x\right)} \cdot \sqrt[3]{1 - \cos x}\right)}^{3}}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\

\end{array}
double f(double x) {
        double r30309 = 1.0;
        double r30310 = x;
        double r30311 = cos(r30310);
        double r30312 = r30309 - r30311;
        double r30313 = r30310 * r30310;
        double r30314 = r30312 / r30313;
        return r30314;
}

double f(double x) {
        double r30315 = x;
        double r30316 = -0.03302109030086143;
        bool r30317 = r30315 <= r30316;
        double r30318 = 0.028129396018266136;
        bool r30319 = r30315 <= r30318;
        double r30320 = !r30319;
        bool r30321 = r30317 || r30320;
        double r30322 = 1.0;
        double r30323 = cos(r30315);
        double r30324 = r30322 - r30323;
        double r30325 = r30324 * r30324;
        double r30326 = cbrt(r30325);
        double r30327 = cbrt(r30324);
        double r30328 = r30326 * r30327;
        double r30329 = 3.0;
        double r30330 = pow(r30328, r30329);
        double r30331 = cbrt(r30330);
        double r30332 = sqrt(r30331);
        double r30333 = r30332 / r30315;
        double r30334 = sqrt(r30324);
        double r30335 = r30334 / r30315;
        double r30336 = r30333 * r30335;
        double r30337 = 4.0;
        double r30338 = pow(r30315, r30337);
        double r30339 = 0.001388888888888889;
        double r30340 = 0.5;
        double r30341 = 0.041666666666666664;
        double r30342 = 2.0;
        double r30343 = pow(r30315, r30342);
        double r30344 = r30341 * r30343;
        double r30345 = r30340 - r30344;
        double r30346 = fma(r30338, r30339, r30345);
        double r30347 = r30321 ? r30336 : r30346;
        return r30347;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03302109030086143 or 0.028129396018266136 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.1

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.6

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied add-cbrt-cube0.6

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

      \[\leadsto \frac{\sqrt{\sqrt[3]{\color{blue}{{\left(1 - \cos x\right)}^{3}}}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt0.7

      \[\leadsto \frac{\sqrt{\sqrt[3]{{\color{blue}{\left(\left(\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}\right) \cdot \sqrt[3]{1 - \cos x}\right)}}^{3}}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    10. Simplified0.6

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

    if -0.03302109030086143 < x < 0.028129396018266136

    1. Initial program 62.2

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. 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}}\]
    3. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.033021090300861429 \lor \neg \left(x \le 0.0281293960182661361\right):\\ \;\;\;\;\frac{\sqrt{\sqrt[3]{{\left(\sqrt[3]{\left(1 - \cos x\right) \cdot \left(1 - \cos x\right)} \cdot \sqrt[3]{1 - \cos x}\right)}^{3}}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020036 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))