Average Error: 31.4 → 0.3
Time: 4.3s
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:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \frac{1}{2}, \frac{1}{720} \cdot {x}^{5} - \frac{1}{24} \cdot {x}^{3}\right)}{x}\\ \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:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, \frac{1}{2}, \frac{1}{720} \cdot {x}^{5} - \frac{1}{24} \cdot {x}^{3}\right)}{x}\\

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

\end{array}
double f(double x) {
        double r31099 = 1.0;
        double r31100 = x;
        double r31101 = cos(r31100);
        double r31102 = r31099 - r31101;
        double r31103 = r31100 * r31100;
        double r31104 = r31102 / r31103;
        return r31104;
}

double f(double x) {
        double r31105 = x;
        double r31106 = -0.03408999554764363;
        bool r31107 = r31105 <= r31106;
        double r31108 = cos(r31105);
        double r31109 = 1.0;
        double r31110 = r31109 + r31108;
        double r31111 = r31109 * r31109;
        double r31112 = fma(r31108, r31110, r31111);
        double r31113 = r31109 - r31108;
        double r31114 = r31112 * r31113;
        double r31115 = r31114 / r31112;
        double r31116 = r31115 / r31105;
        double r31117 = r31116 / r31105;
        double r31118 = 0.032295631090667354;
        bool r31119 = r31105 <= r31118;
        double r31120 = 0.5;
        double r31121 = 0.001388888888888889;
        double r31122 = 5.0;
        double r31123 = pow(r31105, r31122);
        double r31124 = r31121 * r31123;
        double r31125 = 0.041666666666666664;
        double r31126 = 3.0;
        double r31127 = pow(r31105, r31126);
        double r31128 = r31125 * r31127;
        double r31129 = r31124 - r31128;
        double r31130 = fma(r31105, r31120, r31129);
        double r31131 = r31130 / r31105;
        double r31132 = r31109 / r31105;
        double r31133 = r31132 / r31105;
        double r31134 = r31108 / r31105;
        double r31135 = r31134 / r31105;
        double r31136 = r31133 - r31135;
        double r31137 = r31119 ? r31131 : r31136;
        double r31138 = r31107 ? r31117 : r31137;
        return r31138;
}

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. Using strategy rm
    3. Applied associate-/r*61.4

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Taylor expanded around 0 0.0

      \[\leadsto \frac{\color{blue}{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}}{x}\]
    5. Simplified0.0

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, \frac{1}{2}, \frac{1}{720} \cdot {x}^{5} - \frac{1}{24} \cdot {x}^{3}\right)}}{x}\]

    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:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \frac{1}{2}, \frac{1}{720} \cdot {x}^{5} - \frac{1}{24} \cdot {x}^{3}\right)}{x}\\ \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)))