Average Error: 31.2 → 0.4
Time: 17.8s
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 r20292 = 1.0;
        double r20293 = x;
        double r20294 = cos(r20293);
        double r20295 = r20292 - r20294;
        double r20296 = r20293 * r20293;
        double r20297 = r20295 / r20296;
        return r20297;
}

double f(double x) {
        double r20298 = x;
        double r20299 = -0.030846791202208904;
        bool r20300 = r20298 <= r20299;
        double r20301 = 1.0;
        double r20302 = cos(r20298);
        double r20303 = r20301 - r20302;
        double r20304 = sqrt(r20303);
        double r20305 = r20304 / r20298;
        double r20306 = r20298 / r20305;
        double r20307 = r20304 / r20306;
        double r20308 = 0.03981852127604897;
        bool r20309 = r20298 <= r20308;
        double r20310 = r20298 * r20298;
        double r20311 = -0.041666666666666664;
        double r20312 = 0.001388888888888889;
        double r20313 = 4.0;
        double r20314 = pow(r20298, r20313);
        double r20315 = 0.5;
        double r20316 = fma(r20312, r20314, r20315);
        double r20317 = fma(r20310, r20311, r20316);
        double r20318 = r20301 / r20298;
        double r20319 = r20302 / r20298;
        double r20320 = r20318 - r20319;
        double r20321 = r20320 / r20298;
        double r20322 = r20309 ? r20317 : r20321;
        double r20323 = r20300 ? r20307 : r20322;
        return r20323;
}

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)))