Average Error: 31.4 → 0.3
Time: 5.0s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.031682751964378281:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \mathbf{elif}\;x \le 0.033639018339020957:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{e^{\log \left({1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}\right)}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.031682751964378281:\\
\;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{\frac{e^{\log \left({1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}\right)}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\

\end{array}
double f(double x) {
        double r23243 = 1.0;
        double r23244 = x;
        double r23245 = cos(r23244);
        double r23246 = r23243 - r23245;
        double r23247 = r23244 * r23244;
        double r23248 = r23246 / r23247;
        return r23248;
}

double f(double x) {
        double r23249 = x;
        double r23250 = -0.03168275196437828;
        bool r23251 = r23249 <= r23250;
        double r23252 = 1.0;
        double r23253 = r23252 / r23249;
        double r23254 = 1.0;
        double r23255 = 3.0;
        double r23256 = pow(r23254, r23255);
        double r23257 = cos(r23249);
        double r23258 = r23254 + r23257;
        double r23259 = r23254 * r23254;
        double r23260 = fma(r23257, r23258, r23259);
        double r23261 = r23256 / r23260;
        double r23262 = pow(r23257, r23255);
        double r23263 = r23262 / r23260;
        double r23264 = r23261 - r23263;
        double r23265 = r23264 / r23249;
        double r23266 = r23253 * r23265;
        double r23267 = 0.03363901833902096;
        bool r23268 = r23249 <= r23267;
        double r23269 = 4.0;
        double r23270 = pow(r23249, r23269);
        double r23271 = 0.001388888888888889;
        double r23272 = 0.5;
        double r23273 = 0.041666666666666664;
        double r23274 = 2.0;
        double r23275 = pow(r23249, r23274);
        double r23276 = r23273 * r23275;
        double r23277 = r23272 - r23276;
        double r23278 = fma(r23270, r23271, r23277);
        double r23279 = pow(r23262, r23255);
        double r23280 = cbrt(r23279);
        double r23281 = r23256 - r23280;
        double r23282 = log(r23281);
        double r23283 = exp(r23282);
        double r23284 = r23283 / r23260;
        double r23285 = r23284 / r23249;
        double r23286 = r23253 * r23285;
        double r23287 = r23268 ? r23278 : r23286;
        double r23288 = r23251 ? r23266 : r23287;
        return r23288;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.0

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

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

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

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Simplified0.5

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

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

    if -0.03168275196437828 < x < 0.03363901833902096

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

    if 0.03363901833902096 < x

    1. Initial program 1.0

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

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

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

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Simplified0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{x}\]
    8. Using strategy rm
    9. Applied add-cbrt-cube0.5

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

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - \sqrt[3]{\color{blue}{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\]
    11. Using strategy rm
    12. Applied add-exp-log0.5

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

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

Reproduce

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