Average Error: 31.8 → 0.3
Time: 22.9s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03354637559076366348786990556618547998369 \lor \neg \left(x \le 0.03201386298905525146230033328720310237259\right):\\ \;\;\;\;\frac{1}{x} \cdot \frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03354637559076366348786990556618547998369 \lor \neg \left(x \le 0.03201386298905525146230033328720310237259\right):\\
\;\;\;\;\frac{1}{x} \cdot \frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}\\

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

\end{array}
double f(double x) {
        double r21222 = 1.0;
        double r21223 = x;
        double r21224 = cos(r21223);
        double r21225 = r21222 - r21224;
        double r21226 = r21223 * r21223;
        double r21227 = r21225 / r21226;
        return r21227;
}

double f(double x) {
        double r21228 = x;
        double r21229 = -0.033546375590763663;
        bool r21230 = r21228 <= r21229;
        double r21231 = 0.03201386298905525;
        bool r21232 = r21228 <= r21231;
        double r21233 = !r21232;
        bool r21234 = r21230 || r21233;
        double r21235 = 1.0;
        double r21236 = r21235 / r21228;
        double r21237 = 1.0;
        double r21238 = 3.0;
        double r21239 = pow(r21237, r21238);
        double r21240 = cos(r21228);
        double r21241 = pow(r21240, r21238);
        double r21242 = r21239 - r21241;
        double r21243 = exp(r21242);
        double r21244 = log(r21243);
        double r21245 = r21240 + r21237;
        double r21246 = r21240 * r21245;
        double r21247 = fma(r21237, r21237, r21246);
        double r21248 = r21228 * r21247;
        double r21249 = r21244 / r21248;
        double r21250 = r21236 * r21249;
        double r21251 = -0.041666666666666664;
        double r21252 = r21228 * r21228;
        double r21253 = 0.001388888888888889;
        double r21254 = 4.0;
        double r21255 = pow(r21228, r21254);
        double r21256 = 0.5;
        double r21257 = fma(r21253, r21255, r21256);
        double r21258 = fma(r21251, r21252, r21257);
        double r21259 = r21234 ? r21250 : r21258;
        return r21259;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.033546375590763663 or 0.03201386298905525 < x

    1. Initial program 1.0

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

      \[\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. Applied associate-/l/0.5

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

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

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

      \[\leadsto \frac{1}{x} \cdot \frac{\color{blue}{\log \left(e^{{1}^{3}}\right)} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}\]
    12. Applied diff-log0.6

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

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

    if -0.033546375590763663 < x < 0.03201386298905525

    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(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

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

Reproduce

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