Average Error: 31.4 → 0.4
Time: 14.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.034013493959747065:\\ \;\;\;\;\frac{\mathsf{fma}\left(1, 1, -\cos x\right)}{x \cdot x}\\ \mathbf{elif}\;x \le 0.029815137429186504:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{1}{2}, x, \mathsf{fma}\left(\frac{1}{720}, {x}^{5}, {x}^{3} \cdot \frac{-1}{24}\right)\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{e}^{\left(\log \left(\log \left(e^{1 - \cos x}\right)\right)\right)}}{x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.034013493959747065:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, 1, -\cos x\right)}{x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{{e}^{\left(\log \left(\log \left(e^{1 - \cos x}\right)\right)\right)}}{x}}{x}\\

\end{array}
double f(double x) {
        double r23615 = 1.0;
        double r23616 = x;
        double r23617 = cos(r23616);
        double r23618 = r23615 - r23617;
        double r23619 = r23616 * r23616;
        double r23620 = r23618 / r23619;
        return r23620;
}

double f(double x) {
        double r23621 = x;
        double r23622 = -0.034013493959747065;
        bool r23623 = r23621 <= r23622;
        double r23624 = 1.0;
        double r23625 = 1.0;
        double r23626 = cos(r23621);
        double r23627 = -r23626;
        double r23628 = fma(r23624, r23625, r23627);
        double r23629 = r23621 * r23621;
        double r23630 = r23628 / r23629;
        double r23631 = 0.029815137429186504;
        bool r23632 = r23621 <= r23631;
        double r23633 = 0.5;
        double r23634 = 0.001388888888888889;
        double r23635 = 5.0;
        double r23636 = pow(r23621, r23635);
        double r23637 = 3.0;
        double r23638 = pow(r23621, r23637);
        double r23639 = -0.041666666666666664;
        double r23640 = r23638 * r23639;
        double r23641 = fma(r23634, r23636, r23640);
        double r23642 = fma(r23633, r23621, r23641);
        double r23643 = r23642 / r23621;
        double r23644 = exp(1.0);
        double r23645 = r23625 - r23626;
        double r23646 = exp(r23645);
        double r23647 = log(r23646);
        double r23648 = log(r23647);
        double r23649 = pow(r23644, r23648);
        double r23650 = r23649 / r23621;
        double r23651 = r23650 / r23621;
        double r23652 = r23632 ? r23643 : r23651;
        double r23653 = r23623 ? r23630 : r23652;
        return r23653;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.1

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

      \[\leadsto \frac{\color{blue}{1 \cdot 1} - \cos x}{x \cdot x}\]
    4. Applied fma-neg1.1

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

    if -0.034013493959747065 < x < 0.029815137429186504

    1. Initial program 62.3

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*61.4

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

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\frac{1}{2}, x, \mathsf{fma}\left(\frac{1}{720}, {x}^{5}, {x}^{3} \cdot \frac{-1}{24}\right)\right)}}{x}\]

    if 0.029815137429186504 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.5

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied add-exp-log0.5

      \[\leadsto \frac{\frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{x}}{x}\]
    6. Using strategy rm
    7. Applied pow10.5

      \[\leadsto \frac{\frac{e^{\log \color{blue}{\left({\left(1 - \cos x\right)}^{1}\right)}}}{x}}{x}\]
    8. Applied log-pow0.5

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

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

      \[\leadsto \frac{\frac{{\color{blue}{e}}^{\left(\log \left(1 - \cos x\right)\right)}}{x}}{x}\]
    11. Using strategy rm
    12. Applied add-log-exp0.6

      \[\leadsto \frac{\frac{{e}^{\left(\log \left(1 - \color{blue}{\log \left(e^{\cos x}\right)}\right)\right)}}{x}}{x}\]
    13. Applied add-log-exp0.6

      \[\leadsto \frac{\frac{{e}^{\left(\log \left(\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)\right)\right)}}{x}}{x}\]
    14. Applied diff-log0.7

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

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

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

Reproduce

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