Average Error: 30.7 → 0.3
Time: 5.4s
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 r41649 = 1.0;
        double r41650 = x;
        double r41651 = cos(r41650);
        double r41652 = r41649 - r41651;
        double r41653 = r41650 * r41650;
        double r41654 = r41652 / r41653;
        return r41654;
}

double f(double x) {
        double r41655 = x;
        double r41656 = -0.0343424885078094;
        bool r41657 = r41655 <= r41656;
        double r41658 = 1.0;
        double r41659 = cos(r41655);
        double r41660 = r41658 - r41659;
        double r41661 = r41660 / r41655;
        double r41662 = r41661 / r41655;
        double r41663 = 0.033493863120598724;
        bool r41664 = r41655 <= r41663;
        double r41665 = 0.5;
        double r41666 = 0.00138888888888887;
        double r41667 = 5.0;
        double r41668 = pow(r41655, r41667);
        double r41669 = r41666 * r41668;
        double r41670 = 0.041666666666666685;
        double r41671 = 3.0;
        double r41672 = pow(r41655, r41671);
        double r41673 = r41670 * r41672;
        double r41674 = r41669 - r41673;
        double r41675 = fma(r41655, r41665, r41674);
        double r41676 = r41675 / r41655;
        double r41677 = pow(r41658, r41671);
        double r41678 = r41658 * r41659;
        double r41679 = fma(r41659, r41659, r41678);
        double r41680 = fma(r41658, r41658, r41679);
        double r41681 = r41680 * r41655;
        double r41682 = r41677 / r41681;
        double r41683 = pow(r41659, r41671);
        double r41684 = r41683 / r41680;
        double r41685 = r41684 / r41655;
        double r41686 = r41682 - r41685;
        double r41687 = r41686 / r41655;
        double r41688 = r41664 ? r41676 : r41687;
        double r41689 = r41657 ? r41662 : r41688;
        return r41689;
}

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. 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}\]
    9. 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)))