Average Error: 31.8 → 0.2
Time: 15.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03306643978524941018815042070855270139873 \lor \neg \left(x \le 0.02855355443278343591240187038238218519837\right):\\ \;\;\;\;\frac{\left(1 - \cos x\right) \cdot \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03306643978524941018815042070855270139873 \lor \neg \left(x \le 0.02855355443278343591240187038238218519837\right):\\
\;\;\;\;\frac{\left(1 - \cos x\right) \cdot \frac{1}{x}}{x}\\

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

\end{array}
double f(double x) {
        double r19560 = 1.0;
        double r19561 = x;
        double r19562 = cos(r19561);
        double r19563 = r19560 - r19562;
        double r19564 = r19561 * r19561;
        double r19565 = r19563 / r19564;
        return r19565;
}

double f(double x) {
        double r19566 = x;
        double r19567 = -0.03306643978524941;
        bool r19568 = r19566 <= r19567;
        double r19569 = 0.028553554432783436;
        bool r19570 = r19566 <= r19569;
        double r19571 = !r19570;
        bool r19572 = r19568 || r19571;
        double r19573 = 1.0;
        double r19574 = cos(r19566);
        double r19575 = r19573 - r19574;
        double r19576 = 1.0;
        double r19577 = r19576 / r19566;
        double r19578 = r19575 * r19577;
        double r19579 = r19578 / r19566;
        double r19580 = r19566 * r19566;
        double r19581 = -0.041666666666666664;
        double r19582 = 0.001388888888888889;
        double r19583 = 4.0;
        double r19584 = pow(r19566, r19583);
        double r19585 = 0.5;
        double r19586 = fma(r19582, r19584, r19585);
        double r19587 = fma(r19580, r19581, r19586);
        double r19588 = r19572 ? r19579 : r19587;
        return r19588;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03306643978524941 or 0.028553554432783436 < 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 *-un-lft-identity0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{\color{blue}{1 \cdot x}}\]
    7. Applied *-un-lft-identity0.6

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

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

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \color{blue}{\left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1 - \cos x}}{x}\right)}\]
    10. Applied *-un-lft-identity0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{\color{blue}{1 \cdot x}} \cdot \left(\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{1 - \cos x}}{x}\right)\]
    11. Applied *-un-lft-identity0.6

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

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

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

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

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

      \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    17. Using strategy rm
    18. Applied div-inv0.5

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

    if -0.03306643978524941 < x < 0.028553554432783436

    1. Initial program 62.3

      \[\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 \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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