Average Error: 31.2 → 0.4
Time: 17.5s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03084679120220890427561677427092945436016:\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{\frac{x}{\frac{\sqrt{1 - \cos x}}{x}}}\\ \mathbf{elif}\;x \le 0.03981852127604897095825009500913438387215:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03084679120220890427561677427092945436016:\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{\frac{x}{\frac{\sqrt{1 - \cos x}}{x}}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\

\end{array}
double f(double x) {
        double r20254 = 1.0;
        double r20255 = x;
        double r20256 = cos(r20255);
        double r20257 = r20254 - r20256;
        double r20258 = r20255 * r20255;
        double r20259 = r20257 / r20258;
        return r20259;
}

double f(double x) {
        double r20260 = x;
        double r20261 = -0.030846791202208904;
        bool r20262 = r20260 <= r20261;
        double r20263 = 1.0;
        double r20264 = cos(r20260);
        double r20265 = r20263 - r20264;
        double r20266 = sqrt(r20265);
        double r20267 = r20266 / r20260;
        double r20268 = r20260 / r20267;
        double r20269 = r20266 / r20268;
        double r20270 = 0.03981852127604897;
        bool r20271 = r20260 <= r20270;
        double r20272 = r20260 * r20260;
        double r20273 = -0.041666666666666664;
        double r20274 = 0.001388888888888889;
        double r20275 = 4.0;
        double r20276 = pow(r20260, r20275);
        double r20277 = 0.5;
        double r20278 = fma(r20274, r20276, r20277);
        double r20279 = fma(r20272, r20273, r20278);
        double r20280 = r20263 / r20260;
        double r20281 = r20264 / r20260;
        double r20282 = r20280 - r20281;
        double r20283 = r20282 / r20260;
        double r20284 = r20271 ? r20279 : r20283;
        double r20285 = r20262 ? r20269 : r20284;
        return r20285;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.5

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity0.5

      \[\leadsto \frac{\frac{1 - \cos x}{\color{blue}{1 \cdot x}}}{x}\]
    6. Applied add-sqr-sqrt0.6

      \[\leadsto \frac{\frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{1 \cdot x}}{x}\]
    7. Applied times-frac0.6

      \[\leadsto \frac{\color{blue}{\frac{\sqrt{1 - \cos x}}{1} \cdot \frac{\sqrt{1 - \cos x}}{x}}}{x}\]
    8. Applied associate-/l*1.1

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{1 - \cos x}}{1}}{\frac{x}{\frac{\sqrt{1 - \cos x}}{x}}}}\]

    if -0.030846791202208904 < x < 0.03981852127604897

    1. Initial program 62.2

      \[\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 \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)}\]

    if 0.03981852127604897 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.4

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied div-sub0.5

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - \frac{\cos x}{x}}}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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