Average Error: 31.4 → 0.3
Time: 4.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03408999554764362976966296514547138940543:\\ \;\;\;\;\frac{\frac{\frac{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right) \cdot \left(1 - \cos x\right)}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}}{x}\\ \mathbf{elif}\;x \le 0.03229563109066735382413071420160122215748:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{x} - \frac{\frac{\cos x}{x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03408999554764362976966296514547138940543:\\
\;\;\;\;\frac{\frac{\frac{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right) \cdot \left(1 - \cos x\right)}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}}{x}\\

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

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

\end{array}
double f(double x) {
        double r31045 = 1.0;
        double r31046 = x;
        double r31047 = cos(r31046);
        double r31048 = r31045 - r31047;
        double r31049 = r31046 * r31046;
        double r31050 = r31048 / r31049;
        return r31050;
}

double f(double x) {
        double r31051 = x;
        double r31052 = -0.03408999554764363;
        bool r31053 = r31051 <= r31052;
        double r31054 = cos(r31051);
        double r31055 = 1.0;
        double r31056 = r31055 + r31054;
        double r31057 = r31055 * r31055;
        double r31058 = fma(r31054, r31056, r31057);
        double r31059 = r31055 - r31054;
        double r31060 = r31058 * r31059;
        double r31061 = r31060 / r31058;
        double r31062 = r31061 / r31051;
        double r31063 = r31062 / r31051;
        double r31064 = 0.032295631090667354;
        bool r31065 = r31051 <= r31064;
        double r31066 = 4.0;
        double r31067 = pow(r31051, r31066);
        double r31068 = 0.001388888888888889;
        double r31069 = 0.5;
        double r31070 = 0.041666666666666664;
        double r31071 = 2.0;
        double r31072 = pow(r31051, r31071);
        double r31073 = r31070 * r31072;
        double r31074 = r31069 - r31073;
        double r31075 = fma(r31067, r31068, r31074);
        double r31076 = r31055 / r31051;
        double r31077 = r31076 / r31051;
        double r31078 = r31054 / r31051;
        double r31079 = r31078 / r31051;
        double r31080 = r31077 - r31079;
        double r31081 = r31065 ? r31075 : r31080;
        double r31082 = r31053 ? r31063 : r31081;
        return r31082;
}

Error

Bits error versus x

Derivation

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

    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 flip3--0.5

      \[\leadsto \frac{\frac{\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}}{x}\]
    6. Simplified0.5

      \[\leadsto \frac{\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{x}}{x}\]
    7. Using strategy rm
    8. Applied difference-cubes0.5

      \[\leadsto \frac{\frac{\frac{\color{blue}{\left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right) \cdot \left(1 - \cos x\right)}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}}{x}\]
    9. Simplified0.5

      \[\leadsto \frac{\frac{\frac{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} \cdot \left(1 - \cos x\right)}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}}{x}\]

    if -0.03408999554764363 < x < 0.032295631090667354

    1. Initial program 62.4

      \[\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)}\]

    if 0.032295631090667354 < x

    1. Initial program 1.0

      \[\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}\]
    6. Applied div-sub0.6

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

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

Reproduce

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