Average Error: 31.3 → 0.4
Time: 9.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03315307006442389:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{x \cdot x}\\ \mathbf{elif}\;x \le 0.0315772250058030321:\\ \;\;\;\;\mathsf{fma}\left({x}^{2}, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03315307006442389:\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\

\end{array}
double f(double x) {
        double r31588 = 1.0;
        double r31589 = x;
        double r31590 = cos(r31589);
        double r31591 = r31588 - r31590;
        double r31592 = r31589 * r31589;
        double r31593 = r31591 / r31592;
        return r31593;
}

double f(double x) {
        double r31594 = x;
        double r31595 = -0.03315307006442389;
        bool r31596 = r31594 <= r31595;
        double r31597 = 1.0;
        double r31598 = cos(r31594);
        double r31599 = r31597 - r31598;
        double r31600 = log(r31599);
        double r31601 = exp(r31600);
        double r31602 = r31594 * r31594;
        double r31603 = r31601 / r31602;
        double r31604 = 0.03157722500580303;
        bool r31605 = r31594 <= r31604;
        double r31606 = 2.0;
        double r31607 = pow(r31594, r31606);
        double r31608 = -0.041666666666666664;
        double r31609 = 0.001388888888888889;
        double r31610 = 4.0;
        double r31611 = pow(r31594, r31610);
        double r31612 = 0.5;
        double r31613 = fma(r31609, r31611, r31612);
        double r31614 = fma(r31607, r31608, r31613);
        double r31615 = sqrt(r31599);
        double r31616 = r31615 / r31594;
        double r31617 = r31616 * r31616;
        double r31618 = r31605 ? r31614 : r31617;
        double r31619 = r31596 ? r31603 : r31618;
        return r31619;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-exp-log0.9

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

    if -0.03315307006442389 < x < 0.03157722500580303

    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}^{2}, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)}\]

    if 0.03157722500580303 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.2

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.6

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.03315307006442389:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{x \cdot x}\\ \mathbf{elif}\;x \le 0.0315772250058030321:\\ \;\;\;\;\mathsf{fma}\left({x}^{2}, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \end{array}\]

Reproduce

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