Average Error: 31.5 → 0.4
Time: 20.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03305631426271166128927347926946822553873:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \mathsf{fma}\left(\cos x, \left(\sqrt[3]{1 + \cos x} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{1 + \cos x}\right)\right)\right) \cdot \sqrt[3]{1 + \cos x}, 1 \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.03330291426620153594218010084659908898175:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot \frac{1}{720}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03305631426271166128927347926946822553873:\\
\;\;\;\;\frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \mathsf{fma}\left(\cos x, \left(\sqrt[3]{1 + \cos x} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{1 + \cos x}\right)\right)\right) \cdot \sqrt[3]{1 + \cos x}, 1 \cdot 1\right)}\\

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

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

\end{array}
double f(double x) {
        double r878256 = 1.0;
        double r878257 = x;
        double r878258 = cos(r878257);
        double r878259 = r878256 - r878258;
        double r878260 = r878257 * r878257;
        double r878261 = r878259 / r878260;
        return r878261;
}

double f(double x) {
        double r878262 = x;
        double r878263 = -0.03305631426271166;
        bool r878264 = r878262 <= r878263;
        double r878265 = 1.0;
        double r878266 = r878265 / r878262;
        double r878267 = 1.0;
        double r878268 = 3.0;
        double r878269 = pow(r878267, r878268);
        double r878270 = cos(r878262);
        double r878271 = pow(r878270, r878268);
        double r878272 = r878269 - r878271;
        double r878273 = r878267 + r878270;
        double r878274 = cbrt(r878273);
        double r878275 = log1p(r878274);
        double r878276 = expm1(r878275);
        double r878277 = r878274 * r878276;
        double r878278 = r878277 * r878274;
        double r878279 = r878267 * r878267;
        double r878280 = fma(r878270, r878278, r878279);
        double r878281 = r878262 * r878280;
        double r878282 = r878272 / r878281;
        double r878283 = r878266 * r878282;
        double r878284 = 0.033302914266201536;
        bool r878285 = r878262 <= r878284;
        double r878286 = r878262 * r878262;
        double r878287 = -0.041666666666666664;
        double r878288 = 0.001388888888888889;
        double r878289 = r878286 * r878288;
        double r878290 = 0.5;
        double r878291 = fma(r878286, r878289, r878290);
        double r878292 = fma(r878286, r878287, r878291);
        double r878293 = r878267 - r878270;
        double r878294 = r878293 / r878286;
        double r878295 = r878285 ? r878292 : r878294;
        double r878296 = r878264 ? r878283 : r878295;
        return r878296;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.3

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity1.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{x \cdot x}\]
    4. Applied times-frac0.5

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. Using strategy rm
    6. Applied flip3--0.6

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Applied associate-/l/0.6

      \[\leadsto \frac{1}{x} \cdot \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}\]
    8. Simplified0.6

      \[\leadsto \frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, \cos x + 1, 1 \cdot 1\right) \cdot x}}\]
    9. Using strategy rm
    10. Applied add-cube-cbrt0.6

      \[\leadsto \frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, \color{blue}{\left(\sqrt[3]{\cos x + 1} \cdot \sqrt[3]{\cos x + 1}\right) \cdot \sqrt[3]{\cos x + 1}}, 1 \cdot 1\right) \cdot x}\]
    11. Using strategy rm
    12. Applied expm1-log1p-u0.6

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

    if -0.03305631426271166 < x < 0.033302914266201536

    1. Initial program 62.3

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity62.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{x \cdot x}\]
    4. Applied times-frac61.3

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. 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}}\]
    6. Simplified0.0

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

    if 0.033302914266201536 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity1.1

      \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{x \cdot x}\]
    4. Applied times-frac0.5

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

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{x}\right)} \cdot \frac{1 - \cos x}{x}\]
    7. Applied associate-*l*0.5

      \[\leadsto \color{blue}{1 \cdot \left(\frac{1}{x} \cdot \frac{1 - \cos x}{x}\right)}\]
    8. Simplified1.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.03305631426271166128927347926946822553873:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \mathsf{fma}\left(\cos x, \left(\sqrt[3]{1 + \cos x} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{1 + \cos x}\right)\right)\right) \cdot \sqrt[3]{1 + \cos x}, 1 \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.03330291426620153594218010084659908898175:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot \frac{1}{720}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \cos x}{x \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1.0 (cos x)) (* x x)))