Average Error: 31.3 → 0.6
Time: 15.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03224345637809938186491010014833591412753:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(\cos x, \cos x, \left(1 + \cos x\right) \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.02880979041531033998935207307567907264456:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{1}{720} \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(\cos x, \cos x, \left(1 + \cos x\right) \cdot 1\right)}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03224345637809938186491010014833591412753:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(\cos x, \cos x, \left(1 + \cos x\right) \cdot 1\right)}\\

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

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

\end{array}
double f(double x) {
        double r1125591 = 1.0;
        double r1125592 = x;
        double r1125593 = cos(r1125592);
        double r1125594 = r1125591 - r1125593;
        double r1125595 = r1125592 * r1125592;
        double r1125596 = r1125594 / r1125595;
        return r1125596;
}

double f(double x) {
        double r1125597 = x;
        double r1125598 = -0.03224345637809938;
        bool r1125599 = r1125597 <= r1125598;
        double r1125600 = 1.0;
        double r1125601 = 3.0;
        double r1125602 = pow(r1125600, r1125601);
        double r1125603 = cos(r1125597);
        double r1125604 = pow(r1125603, r1125601);
        double r1125605 = r1125602 - r1125604;
        double r1125606 = r1125597 * r1125597;
        double r1125607 = r1125600 + r1125603;
        double r1125608 = r1125607 * r1125600;
        double r1125609 = fma(r1125603, r1125603, r1125608);
        double r1125610 = r1125606 * r1125609;
        double r1125611 = r1125605 / r1125610;
        double r1125612 = 0.02880979041531034;
        bool r1125613 = r1125597 <= r1125612;
        double r1125614 = 0.001388888888888889;
        double r1125615 = r1125614 * r1125606;
        double r1125616 = -0.041666666666666664;
        double r1125617 = 0.5;
        double r1125618 = fma(r1125616, r1125606, r1125617);
        double r1125619 = fma(r1125606, r1125615, r1125618);
        double r1125620 = r1125613 ? r1125619 : r1125611;
        double r1125621 = r1125599 ? r1125611 : r1125620;
        return r1125621;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03224345637809938 or 0.02880979041531034 < x

    1. Initial program 1.0

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

      \[\leadsto \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 \cdot x}\]
    4. Applied associate-/l/1.1

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

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

    if -0.03224345637809938 < x < 0.02880979041531034

    1. Initial program 62.3

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

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

Reproduce

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