Average Error: 31.3 → 0.3
Time: 4.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.032095584675305884 \lor \neg \left(x \le 0.0314197047704342439\right):\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}\\ \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.032095584675305884 \lor \neg \left(x \le 0.0314197047704342439\right):\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}}{x \cdot \sqrt{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}\\

\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 r28509 = 1.0;
        double r28510 = x;
        double r28511 = cos(r28510);
        double r28512 = r28509 - r28511;
        double r28513 = r28510 * r28510;
        double r28514 = r28512 / r28513;
        return r28514;
}

double f(double x) {
        double r28515 = x;
        double r28516 = -0.032095584675305884;
        bool r28517 = r28515 <= r28516;
        double r28518 = 0.031419704770434244;
        bool r28519 = r28515 <= r28518;
        double r28520 = !r28519;
        bool r28521 = r28517 || r28520;
        double r28522 = 1.0;
        double r28523 = cos(r28515);
        double r28524 = r28522 - r28523;
        double r28525 = sqrt(r28524);
        double r28526 = r28525 / r28515;
        double r28527 = 3.0;
        double r28528 = pow(r28522, r28527);
        double r28529 = pow(r28523, r28527);
        double r28530 = log1p(r28529);
        double r28531 = expm1(r28530);
        double r28532 = r28528 - r28531;
        double r28533 = sqrt(r28532);
        double r28534 = r28522 * r28522;
        double r28535 = r28523 * r28523;
        double r28536 = r28522 * r28523;
        double r28537 = r28535 + r28536;
        double r28538 = r28534 + r28537;
        double r28539 = sqrt(r28538);
        double r28540 = r28515 * r28539;
        double r28541 = r28533 / r28540;
        double r28542 = r28526 * r28541;
        double r28543 = 4.0;
        double r28544 = pow(r28515, r28543);
        double r28545 = 0.001388888888888889;
        double r28546 = 0.5;
        double r28547 = 0.041666666666666664;
        double r28548 = 2.0;
        double r28549 = pow(r28515, r28548);
        double r28550 = r28547 * r28549;
        double r28551 = r28546 - r28550;
        double r28552 = fma(r28544, r28545, r28551);
        double r28553 = r28521 ? r28542 : r28552;
        return r28553;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.032095584675305884 or 0.031419704770434244 < 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.6

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

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \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}\]
    8. Applied associate-/l/0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \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)}}}\]
    9. Using strategy rm
    10. Applied expm1-log1p-u0.6

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

    if -0.032095584675305884 < x < 0.031419704770434244

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