Average Error: 31.7 → 0.3
Time: 5.2s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03020423764333628538492071413656958611682:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\mathsf{fma}\left(\cos x, \sqrt{1 + \cos x} \cdot \sqrt{1 + \cos x}, 1 \cdot 1\right)}}{x}\\ \mathbf{elif}\;x \le 0.03141600742422194503244980978706735186279:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03020423764333628538492071413656958611682:\\
\;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\mathsf{fma}\left(\cos x, \sqrt{1 + \cos x} \cdot \sqrt{1 + \cos x}, 1 \cdot 1\right)}}{x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\

\end{array}
double f(double x) {
        double r35196 = 1.0;
        double r35197 = x;
        double r35198 = cos(r35197);
        double r35199 = r35196 - r35198;
        double r35200 = r35197 * r35197;
        double r35201 = r35199 / r35200;
        return r35201;
}

double f(double x) {
        double r35202 = x;
        double r35203 = -0.030204237643336285;
        bool r35204 = r35202 <= r35203;
        double r35205 = 1.0;
        double r35206 = r35205 / r35202;
        double r35207 = 1.0;
        double r35208 = 3.0;
        double r35209 = pow(r35207, r35208);
        double r35210 = cos(r35202);
        double r35211 = pow(r35210, r35208);
        double r35212 = exp(r35211);
        double r35213 = log(r35212);
        double r35214 = r35209 - r35213;
        double r35215 = r35207 + r35210;
        double r35216 = sqrt(r35215);
        double r35217 = r35216 * r35216;
        double r35218 = r35207 * r35207;
        double r35219 = fma(r35210, r35217, r35218);
        double r35220 = r35214 / r35219;
        double r35221 = r35220 / r35202;
        double r35222 = r35206 * r35221;
        double r35223 = 0.031416007424221945;
        bool r35224 = r35202 <= r35223;
        double r35225 = 4.0;
        double r35226 = pow(r35202, r35225);
        double r35227 = 0.001388888888888889;
        double r35228 = 0.5;
        double r35229 = 0.041666666666666664;
        double r35230 = 2.0;
        double r35231 = pow(r35202, r35230);
        double r35232 = r35229 * r35231;
        double r35233 = r35228 - r35232;
        double r35234 = fma(r35226, r35227, r35233);
        double r35235 = pow(r35211, r35208);
        double r35236 = cbrt(r35235);
        double r35237 = r35209 - r35236;
        double r35238 = fma(r35210, r35215, r35218);
        double r35239 = r35237 / r35238;
        double r35240 = r35239 / r35202;
        double r35241 = r35206 * r35240;
        double r35242 = r35224 ? r35234 : r35241;
        double r35243 = r35204 ? r35222 : r35242;
        return r35243;
}

Error

Bits error versus x

Derivation

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

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

      \[\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. Simplified0.5

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

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt0.5

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

    if -0.030204237643336285 < x < 0.031416007424221945

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

    if 0.031416007424221945 < x

    1. Initial program 1.2

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

      \[\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.5

      \[\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. Simplified0.5

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

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

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - \sqrt[3]{\color{blue}{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

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

Reproduce

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