Average Error: 31.3 → 0.3
Time: 5.6s
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 - \cos x}}{x} \cdot \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)}}\\ \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 - \cos x}}{x} \cdot \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)}}\\

\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 r34986 = 1.0;
        double r34987 = x;
        double r34988 = cos(r34987);
        double r34989 = r34986 - r34988;
        double r34990 = r34987 * r34987;
        double r34991 = r34989 / r34990;
        return r34991;
}

double f(double x) {
        double r34992 = x;
        double r34993 = -0.02708053868306139;
        bool r34994 = r34992 <= r34993;
        double r34995 = 0.031819146549010704;
        bool r34996 = r34992 <= r34995;
        double r34997 = !r34996;
        bool r34998 = r34994 || r34997;
        double r34999 = 1.0;
        double r35000 = cos(r34992);
        double r35001 = r34999 - r35000;
        double r35002 = sqrt(r35001);
        double r35003 = r35002 / r34992;
        double r35004 = 3.0;
        double r35005 = pow(r34999, r35004);
        double r35006 = pow(r35000, r35004);
        double r35007 = exp(r35006);
        double r35008 = log(r35007);
        double r35009 = log1p(r35008);
        double r35010 = expm1(r35009);
        double r35011 = r35005 - r35010;
        double r35012 = sqrt(r35011);
        double r35013 = r34999 * r34999;
        double r35014 = r35000 * r35000;
        double r35015 = r34999 * r35000;
        double r35016 = r35014 + r35015;
        double r35017 = r35013 + r35016;
        double r35018 = sqrt(r35017);
        double r35019 = r34992 * r35018;
        double r35020 = r35012 / r35019;
        double r35021 = r35003 * r35020;
        double r35022 = 4.0;
        double r35023 = pow(r34992, r35022);
        double r35024 = 0.001388888888888889;
        double r35025 = 0.5;
        double r35026 = 0.041666666666666664;
        double r35027 = 2.0;
        double r35028 = pow(r34992, r35027);
        double r35029 = r35026 * r35028;
        double r35030 = r35025 - r35029;
        double r35031 = fma(r35023, r35024, r35030);
        double r35032 = r34998 ? r35021 : r35031;
        return r35032;
}

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{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.5

      \[\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.5

      \[\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 add-log-exp0.5

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

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

    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 - \cos x}}{x} \cdot \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)}}\\ \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)))