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

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

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

\end{array}
double f(double x) {
        double r22245 = 1.0;
        double r22246 = x;
        double r22247 = cos(r22246);
        double r22248 = r22245 - r22247;
        double r22249 = r22246 * r22246;
        double r22250 = r22248 / r22249;
        return r22250;
}

double f(double x) {
        double r22251 = x;
        double r22252 = -0.03315307006442389;
        bool r22253 = r22251 <= r22252;
        double r22254 = 1.0;
        double r22255 = cos(r22251);
        double r22256 = r22254 - r22255;
        double r22257 = log(r22256);
        double r22258 = exp(r22257);
        double r22259 = r22251 * r22251;
        double r22260 = r22258 / r22259;
        double r22261 = 0.03157722500580303;
        bool r22262 = r22251 <= r22261;
        double r22263 = 2.0;
        double r22264 = pow(r22251, r22263);
        double r22265 = -0.041666666666666664;
        double r22266 = 0.001388888888888889;
        double r22267 = 4.0;
        double r22268 = pow(r22251, r22267);
        double r22269 = 0.5;
        double r22270 = fma(r22266, r22268, r22269);
        double r22271 = fma(r22264, r22265, r22270);
        double r22272 = sqrt(r22256);
        double r22273 = r22272 / r22251;
        double r22274 = r22273 * r22273;
        double r22275 = r22262 ? r22271 : r22274;
        double r22276 = r22253 ? r22260 : r22275;
        return r22276;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-exp-log0.9

      \[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{x \cdot x}\]

    if -0.03315307006442389 < x < 0.03157722500580303

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

    if 0.03157722500580303 < x

    1. Initial program 1.0

      \[\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}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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