Average Error: 31.6 → 0.4
Time: 5.2s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0338582795407828333:\\ \;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{x \cdot x}\\ \mathbf{elif}\;x \le 0.025388615584991975:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1}}{\frac{x}{\sqrt{1 - \cos x}}} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0338582795407828333:\\
\;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{x \cdot x}\\

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

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

\end{array}
double f(double x) {
        double r31468 = 1.0;
        double r31469 = x;
        double r31470 = cos(r31469);
        double r31471 = r31468 - r31470;
        double r31472 = r31469 * r31469;
        double r31473 = r31471 / r31472;
        return r31473;
}

double f(double x) {
        double r31474 = x;
        double r31475 = -0.03385827954078283;
        bool r31476 = r31474 <= r31475;
        double r31477 = 1.0;
        double r31478 = cos(r31474);
        double r31479 = r31477 - r31478;
        double r31480 = exp(r31479);
        double r31481 = log(r31480);
        double r31482 = r31474 * r31474;
        double r31483 = r31481 / r31482;
        double r31484 = 0.025388615584991975;
        bool r31485 = r31474 <= r31484;
        double r31486 = 4.0;
        double r31487 = pow(r31474, r31486);
        double r31488 = 0.001388888888888889;
        double r31489 = 0.5;
        double r31490 = 0.041666666666666664;
        double r31491 = 2.0;
        double r31492 = pow(r31474, r31491);
        double r31493 = r31490 * r31492;
        double r31494 = r31489 - r31493;
        double r31495 = fma(r31487, r31488, r31494);
        double r31496 = 1.0;
        double r31497 = sqrt(r31496);
        double r31498 = sqrt(r31479);
        double r31499 = r31474 / r31498;
        double r31500 = r31497 / r31499;
        double r31501 = r31498 / r31474;
        double r31502 = r31500 * r31501;
        double r31503 = r31485 ? r31495 : r31502;
        double r31504 = r31476 ? r31483 : r31503;
        return r31504;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.9

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

      \[\leadsto \frac{1 - \color{blue}{\log \left(e^{\cos x}\right)}}{x \cdot x}\]
    4. Applied add-log-exp1.1

      \[\leadsto \frac{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}{x \cdot x}\]
    5. Applied diff-log1.2

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{1}}{e^{\cos x}}\right)}}{x \cdot x}\]
    6. Simplified1.1

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

    if -0.03385827954078283 < x < 0.025388615584991975

    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)}\]

    if 0.025388615584991975 < x

    1. Initial program 1.2

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

      \[\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 *-un-lft-identity0.6

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

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1 - \cos x}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    8. Applied associate-/l*0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0338582795407828333:\\ \;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{x \cdot x}\\ \mathbf{elif}\;x \le 0.025388615584991975:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1}}{\frac{x}{\sqrt{1 - \cos x}}} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \end{array}\]

Reproduce

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