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

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

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

\end{array}
double f(double x) {
        double r22539 = 1.0;
        double r22540 = x;
        double r22541 = cos(r22540);
        double r22542 = r22539 - r22541;
        double r22543 = r22540 * r22540;
        double r22544 = r22542 / r22543;
        return r22544;
}

double f(double x) {
        double r22545 = x;
        double r22546 = -0.03237572141906872;
        bool r22547 = r22545 <= r22546;
        double r22548 = 1.0;
        double r22549 = cos(r22545);
        double r22550 = r22548 - r22549;
        double r22551 = r22550 / r22545;
        double r22552 = r22551 / r22545;
        double r22553 = 0.03382760307135756;
        bool r22554 = r22545 <= r22553;
        double r22555 = -0.041666666666666664;
        double r22556 = r22545 * r22545;
        double r22557 = 0.001388888888888889;
        double r22558 = 4.0;
        double r22559 = pow(r22545, r22558);
        double r22560 = 0.5;
        double r22561 = fma(r22557, r22559, r22560);
        double r22562 = fma(r22555, r22556, r22561);
        double r22563 = 3.0;
        double r22564 = pow(r22548, r22563);
        double r22565 = 2.0;
        double r22566 = pow(r22549, r22565);
        double r22567 = r22549 * r22566;
        double r22568 = exp(r22567);
        double r22569 = log(r22568);
        double r22570 = r22564 - r22569;
        double r22571 = r22549 + r22548;
        double r22572 = r22549 * r22571;
        double r22573 = fma(r22548, r22548, r22572);
        double r22574 = r22570 / r22573;
        double r22575 = r22574 / r22545;
        double r22576 = r22575 / r22545;
        double r22577 = r22554 ? r22562 : r22576;
        double r22578 = r22547 ? r22552 : r22577;
        return r22578;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.1

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

    if -0.03237572141906872 < x < 0.03382760307135756

    1. Initial program 62.2

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

    if 0.03382760307135756 < x

    1. Initial program 0.9

      \[\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. Simplified0.5

      \[\leadsto \frac{\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}}}{x}}{x}\]
    7. Using strategy rm
    8. Applied add-log-exp0.6

      \[\leadsto \frac{\frac{\frac{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x + 1\right)\right)}}{x}}{x}\]
    9. Using strategy rm
    10. Applied cube-mult0.6

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

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

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

Reproduce

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