Average Error: 31.2 → 0.3
Time: 4.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0354696748040020729 \lor \neg \left(x \le 0.0298852972788701925\right):\\ \;\;\;\;\frac{\frac{\frac{{1}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)} - \frac{\frac{{\left(\cos x\right)}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}}{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.0354696748040020729 \lor \neg \left(x \le 0.0298852972788701925\right):\\
\;\;\;\;\frac{\frac{\frac{{1}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)} - \frac{\frac{{\left(\cos x\right)}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}}{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 r35092 = 1.0;
        double r35093 = x;
        double r35094 = cos(r35093);
        double r35095 = r35092 - r35094;
        double r35096 = r35093 * r35093;
        double r35097 = r35095 / r35096;
        return r35097;
}

double f(double x) {
        double r35098 = x;
        double r35099 = -0.03546967480400207;
        bool r35100 = r35098 <= r35099;
        double r35101 = 0.029885297278870192;
        bool r35102 = r35098 <= r35101;
        double r35103 = !r35102;
        bool r35104 = r35100 || r35103;
        double r35105 = 1.0;
        double r35106 = 3.0;
        double r35107 = pow(r35105, r35106);
        double r35108 = r35107 / r35098;
        double r35109 = cos(r35098);
        double r35110 = r35109 + r35105;
        double r35111 = r35109 * r35110;
        double r35112 = fma(r35105, r35105, r35111);
        double r35113 = r35108 / r35112;
        double r35114 = pow(r35109, r35106);
        double r35115 = r35114 / r35098;
        double r35116 = r35115 / r35112;
        double r35117 = r35113 - r35116;
        double r35118 = r35117 / r35098;
        double r35119 = 4.0;
        double r35120 = pow(r35098, r35119);
        double r35121 = 0.001388888888888889;
        double r35122 = 0.5;
        double r35123 = 0.041666666666666664;
        double r35124 = 2.0;
        double r35125 = pow(r35098, r35124);
        double r35126 = r35123 * r35125;
        double r35127 = r35122 - r35126;
        double r35128 = fma(r35120, r35121, r35127);
        double r35129 = r35104 ? r35118 : r35128;
        return r35129;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03546967480400207 or 0.029885297278870192 < x

    1. Initial program 0.9

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

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

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. Using strategy rm
    6. Applied associate-*r/0.5

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

      \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x}\]
    8. Using strategy rm
    9. Applied flip3--0.5

      \[\leadsto \frac{\frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{x}}{x}\]
    10. Applied associate-/l/0.5

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}}{x}\]
    11. Simplified0.5

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}}}{x}\]
    12. Using strategy rm
    13. Applied div-sub0.5

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}}}{x}\]
    14. Simplified0.5

      \[\leadsto \frac{\color{blue}{\frac{\frac{{1}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}}{x}\]
    15. Simplified0.5

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

    if -0.03546967480400207 < x < 0.029885297278870192

    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}^{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.0354696748040020729 \lor \neg \left(x \le 0.0298852972788701925\right):\\ \;\;\;\;\frac{\frac{\frac{{1}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)} - \frac{\frac{{\left(\cos x\right)}^{3}}{x}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}}{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 2020024 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))