Average Error: 30.7 → 0.5
Time: 16.5s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.011260686584555396:\\ \;\;\;\;\frac{\sin x}{\frac{x \cdot x}{\tan \left(\frac{x}{2}\right)}}\\ \mathbf{elif}\;x \le 1.8753012792971286 \cdot 10^{-156}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot \frac{1}{720} - \frac{1}{24}, \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x \cdot x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.011260686584555396:\\
\;\;\;\;\frac{\sin x}{\frac{x \cdot x}{\tan \left(\frac{x}{2}\right)}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x \cdot x}\\

\end{array}
double f(double x) {
        double r814103 = 1.0;
        double r814104 = x;
        double r814105 = cos(r814104);
        double r814106 = r814103 - r814105;
        double r814107 = r814104 * r814104;
        double r814108 = r814106 / r814107;
        return r814108;
}

double f(double x) {
        double r814109 = x;
        double r814110 = -0.011260686584555396;
        bool r814111 = r814109 <= r814110;
        double r814112 = sin(r814109);
        double r814113 = r814109 * r814109;
        double r814114 = 2.0;
        double r814115 = r814109 / r814114;
        double r814116 = tan(r814115);
        double r814117 = r814113 / r814116;
        double r814118 = r814112 / r814117;
        double r814119 = 1.8753012792971286e-156;
        bool r814120 = r814109 <= r814119;
        double r814121 = 0.001388888888888889;
        double r814122 = r814113 * r814121;
        double r814123 = 0.041666666666666664;
        double r814124 = r814122 - r814123;
        double r814125 = 0.5;
        double r814126 = fma(r814113, r814124, r814125);
        double r814127 = r814112 * r814116;
        double r814128 = r814127 / r814113;
        double r814129 = r814120 ? r814126 : r814128;
        double r814130 = r814111 ? r814118 : r814129;
        return r814130;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.2

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied flip--1.4

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x}\]
    4. Simplified1.3

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

      \[\leadsto \frac{\frac{\sin x \cdot \sin x}{\color{blue}{1 \cdot \left(1 + \cos x\right)}}}{x \cdot x}\]
    7. Applied times-frac1.3

      \[\leadsto \frac{\color{blue}{\frac{\sin x}{1} \cdot \frac{\sin x}{1 + \cos x}}}{x \cdot x}\]
    8. Simplified1.3

      \[\leadsto \frac{\color{blue}{\sin x} \cdot \frac{\sin x}{1 + \cos x}}{x \cdot x}\]
    9. Simplified1.0

      \[\leadsto \frac{\sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x}\]
    10. Using strategy rm
    11. Applied associate-/l*1.0

      \[\leadsto \color{blue}{\frac{\sin x}{\frac{x \cdot x}{\tan \left(\frac{x}{2}\right)}}}\]

    if -0.011260686584555396 < x < 1.8753012792971286e-156

    1. Initial program 61.6

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

    if 1.8753012792971286e-156 < x

    1. Initial program 20.6

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied flip--20.8

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x}\]
    4. Simplified0.8

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

      \[\leadsto \frac{\frac{\sin x \cdot \sin x}{\color{blue}{1 \cdot \left(1 + \cos x\right)}}}{x \cdot x}\]
    7. Applied times-frac0.8

      \[\leadsto \frac{\color{blue}{\frac{\sin x}{1} \cdot \frac{\sin x}{1 + \cos x}}}{x \cdot x}\]
    8. Simplified0.8

      \[\leadsto \frac{\color{blue}{\sin x} \cdot \frac{\sin x}{1 + \cos x}}{x \cdot x}\]
    9. Simplified0.6

      \[\leadsto \frac{\sin x \cdot \color{blue}{\tan \left(\frac{x}{2}\right)}}{x \cdot x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.011260686584555396:\\ \;\;\;\;\frac{\sin x}{\frac{x \cdot x}{\tan \left(\frac{x}{2}\right)}}\\ \mathbf{elif}\;x \le 1.8753012792971286 \cdot 10^{-156}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \left(x \cdot x\right) \cdot \frac{1}{720} - \frac{1}{24}, \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin x \cdot \tan \left(\frac{x}{2}\right)}{x \cdot x}\\ \end{array}\]

Reproduce

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