Average Error: 31.3 → 0.3
Time: 5.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02708053868306138992072540361277788178995 \lor \neg \left(x \le 0.03181914654901070449444233645408530719578\right):\\ \;\;\;\;\frac{\sqrt{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{{\left(\cos x\right)}^{3}}\right)\right)\right)}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}} \cdot \frac{\sqrt{1 - \cos x}}{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.02708053868306138992072540361277788178995 \lor \neg \left(x \le 0.03181914654901070449444233645408530719578\right):\\
\;\;\;\;\frac{\sqrt{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{{\left(\cos x\right)}^{3}}\right)\right)\right)}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}} \cdot \frac{\sqrt{1 - \cos x}}{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 r25395 = 1.0;
        double r25396 = x;
        double r25397 = cos(r25396);
        double r25398 = r25395 - r25397;
        double r25399 = r25396 * r25396;
        double r25400 = r25398 / r25399;
        return r25400;
}

double f(double x) {
        double r25401 = x;
        double r25402 = -0.02708053868306139;
        bool r25403 = r25401 <= r25402;
        double r25404 = 0.031819146549010704;
        bool r25405 = r25401 <= r25404;
        double r25406 = !r25405;
        bool r25407 = r25403 || r25406;
        double r25408 = 1.0;
        double r25409 = 3.0;
        double r25410 = pow(r25408, r25409);
        double r25411 = cos(r25401);
        double r25412 = pow(r25411, r25409);
        double r25413 = exp(r25412);
        double r25414 = log(r25413);
        double r25415 = log1p(r25414);
        double r25416 = expm1(r25415);
        double r25417 = r25410 - r25416;
        double r25418 = sqrt(r25417);
        double r25419 = r25408 * r25408;
        double r25420 = r25411 * r25411;
        double r25421 = r25408 * r25411;
        double r25422 = r25420 + r25421;
        double r25423 = r25419 + r25422;
        double r25424 = sqrt(r25423);
        double r25425 = r25401 * r25424;
        double r25426 = r25418 / r25425;
        double r25427 = r25408 - r25411;
        double r25428 = sqrt(r25427);
        double r25429 = r25428 / r25401;
        double r25430 = r25426 * r25429;
        double r25431 = 4.0;
        double r25432 = pow(r25401, r25431);
        double r25433 = 0.001388888888888889;
        double r25434 = 0.5;
        double r25435 = 0.041666666666666664;
        double r25436 = 2.0;
        double r25437 = pow(r25401, r25436);
        double r25438 = r25435 * r25437;
        double r25439 = r25434 - r25438;
        double r25440 = fma(r25432, r25433, r25439);
        double r25441 = r25407 ? r25430 : r25440;
        return r25441;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.02708053868306139 or 0.031819146549010704 < 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 flip3--0.5

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{{1}^{3} - {\left(\cos x\right)}^{3}}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    9. Using strategy rm
    10. Applied add-log-exp0.5

      \[\leadsto \frac{\sqrt{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    11. Using strategy rm
    12. Applied expm1-log1p-u0.5

      \[\leadsto \frac{\sqrt{{1}^{3} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{{\left(\cos x\right)}^{3}}\right)\right)\right)}}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}} \cdot \frac{\sqrt{1 - \cos x}}{x}\]

    if -0.02708053868306139 < x < 0.031819146549010704

    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.02708053868306138992072540361277788178995 \lor \neg \left(x \le 0.03181914654901070449444233645408530719578\right):\\ \;\;\;\;\frac{\sqrt{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{{\left(\cos x\right)}^{3}}\right)\right)\right)}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}} \cdot \frac{\sqrt{1 - \cos x}}{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 2019353 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))