Average Error: 30.9 → 0.6
Time: 4.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0309273812351459031 \lor \neg \left(x \le 0.023960596481684263\right):\\ \;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{1 - \cos x}{{x}^{2}}\\ \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.0309273812351459031 \lor \neg \left(x \le 0.023960596481684263\right):\\
\;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{1 - \cos x}{{x}^{2}}\\

\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 r27544 = 1.0;
        double r27545 = x;
        double r27546 = cos(r27545);
        double r27547 = r27544 - r27546;
        double r27548 = r27545 * r27545;
        double r27549 = r27547 / r27548;
        return r27549;
}

double f(double x) {
        double r27550 = x;
        double r27551 = -0.030927381235145903;
        bool r27552 = r27550 <= r27551;
        double r27553 = 0.023960596481684263;
        bool r27554 = r27550 <= r27553;
        double r27555 = !r27554;
        bool r27556 = r27552 || r27555;
        double r27557 = 1.0;
        double r27558 = sqrt(r27557);
        double r27559 = r27558 / r27557;
        double r27560 = 1.0;
        double r27561 = cos(r27550);
        double r27562 = r27560 - r27561;
        double r27563 = 2.0;
        double r27564 = pow(r27550, r27563);
        double r27565 = r27562 / r27564;
        double r27566 = r27559 * r27565;
        double r27567 = 4.0;
        double r27568 = pow(r27550, r27567);
        double r27569 = 0.001388888888888889;
        double r27570 = 0.5;
        double r27571 = 0.041666666666666664;
        double r27572 = r27571 * r27564;
        double r27573 = r27570 - r27572;
        double r27574 = fma(r27568, r27569, r27573);
        double r27575 = r27556 ? r27566 : r27574;
        return r27575;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.030927381235145903 or 0.023960596481684263 < x

    1. Initial program 1.1

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

      \[\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-log-exp0.6

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

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

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

      \[\leadsto \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    10. Using strategy rm
    11. Applied *-un-lft-identity0.6

      \[\leadsto \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{\color{blue}{1 \cdot x}} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    12. Applied pow10.6

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

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

      \[\leadsto \frac{\color{blue}{\sqrt{1} \cdot \sqrt{\log \left(e^{1 - \cos x}\right)}}}{1 \cdot x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    15. Applied times-frac0.6

      \[\leadsto \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\right)} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    16. Applied associate-*l*0.6

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

      \[\leadsto \frac{\sqrt{1}}{1} \cdot \color{blue}{\frac{1 - \cos x}{{x}^{2}}}\]

    if -0.030927381235145903 < x < 0.023960596481684263

    1. Initial program 62.4

      \[\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.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0309273812351459031 \lor \neg \left(x \le 0.023960596481684263\right):\\ \;\;\;\;\frac{\sqrt{1}}{1} \cdot \frac{1 - \cos x}{{x}^{2}}\\ \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 2020060 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))