Average Error: 30.7 → 0.3
Time: 9.8s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.034342488507809403:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{elif}\;x \le 0.033493863120598724:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, 0.5, 0.00138888888888887 \cdot {x}^{5} - 0.041666666666666685 \cdot {x}^{3}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x} - \frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right)}}{x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.034342488507809403:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\

\mathbf{elif}\;x \le 0.033493863120598724:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, 0.5, 0.00138888888888887 \cdot {x}^{5} - 0.041666666666666685 \cdot {x}^{3}\right)}{x}\\

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

\end{array}
double f(double x) {
        double r141 = 1.0;
        double r142 = x;
        double r143 = cos(r142);
        double r144 = r141 - r143;
        double r145 = r142 * r142;
        double r146 = r144 / r145;
        return r146;
}

double f(double x) {
        double r147 = x;
        double r148 = -0.0343424885078094;
        bool r149 = r147 <= r148;
        double r150 = 1.0;
        double r151 = cos(r147);
        double r152 = r150 - r151;
        double r153 = r152 / r147;
        double r154 = r153 / r147;
        double r155 = 0.033493863120598724;
        bool r156 = r147 <= r155;
        double r157 = 0.5;
        double r158 = 0.00138888888888887;
        double r159 = 5.0;
        double r160 = pow(r147, r159);
        double r161 = r158 * r160;
        double r162 = 0.041666666666666685;
        double r163 = 3.0;
        double r164 = pow(r147, r163);
        double r165 = r162 * r164;
        double r166 = r161 - r165;
        double r167 = fma(r147, r157, r166);
        double r168 = r167 / r147;
        double r169 = pow(r150, r163);
        double r170 = r150 * r151;
        double r171 = fma(r151, r151, r170);
        double r172 = fma(r150, r150, r171);
        double r173 = r172 * r147;
        double r174 = r169 / r173;
        double r175 = pow(r151, r163);
        double r176 = r175 / r172;
        double r177 = r176 / r147;
        double r178 = r174 - r177;
        double r179 = r178 / r147;
        double r180 = r156 ? r168 : r179;
        double r181 = r149 ? r154 : r180;
        return r181;
}

Error

Bits error versus x

Derivation

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

    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}}\]

    if -0.0343424885078094 < x < 0.033493863120598724

    1. Initial program 62.2

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*61.3

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

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

      \[\leadsto \frac{\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)}}}{x}\]
    7. Simplified61.3

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}}}{x}\]
    8. Using strategy rm
    9. Applied expm1-log1p-u61.3

      \[\leadsto \frac{\frac{{1}^{3} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}}{x}\]
    10. Taylor expanded around 0 0.0

      \[\leadsto \frac{\color{blue}{\left(0.5 \cdot x + 0.00138888888888887 \cdot {x}^{5}\right) - 0.041666666666666685 \cdot {x}^{3}}}{x}\]
    11. Simplified0.0

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, 0.5, 0.00138888888888887 \cdot {x}^{5} - 0.041666666666666685 \cdot {x}^{3}\right)}}{x}\]

    if 0.033493863120598724 < x

    1. Initial program 1.3

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.5

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

      \[\leadsto \frac{\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)}}}{x}\]
    7. Simplified0.5

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.034342488507809403:\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{elif}\;x \le 0.033493863120598724:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, 0.5, 0.00138888888888887 \cdot {x}^{5} - 0.041666666666666685 \cdot {x}^{3}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x} - \frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right)}}{x}}{x}\\ \end{array}\]

Reproduce

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