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

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

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

\end{array}
double f(double x) {
        double r28526 = 1.0;
        double r28527 = x;
        double r28528 = cos(r28527);
        double r28529 = r28526 - r28528;
        double r28530 = r28527 * r28527;
        double r28531 = r28529 / r28530;
        return r28531;
}

double f(double x) {
        double r28532 = x;
        double r28533 = -0.03305941206486147;
        bool r28534 = r28532 <= r28533;
        double r28535 = 1.0;
        double r28536 = 3.0;
        double r28537 = pow(r28535, r28536);
        double r28538 = cos(r28532);
        double r28539 = pow(r28538, r28536);
        double r28540 = r28537 - r28539;
        double r28541 = r28535 + r28538;
        double r28542 = r28535 * r28535;
        double r28543 = fma(r28538, r28541, r28542);
        double r28544 = r28540 / r28543;
        double r28545 = r28532 * r28532;
        double r28546 = r28544 / r28545;
        double r28547 = 0.034074837610598666;
        bool r28548 = r28532 <= r28547;
        double r28549 = 4.0;
        double r28550 = pow(r28532, r28549);
        double r28551 = 0.001388888888888889;
        double r28552 = 0.5;
        double r28553 = 0.041666666666666664;
        double r28554 = 2.0;
        double r28555 = pow(r28532, r28554);
        double r28556 = r28553 * r28555;
        double r28557 = r28552 - r28556;
        double r28558 = fma(r28550, r28551, r28557);
        double r28559 = r28535 - r28538;
        double r28560 = exp(r28559);
        double r28561 = log(r28560);
        double r28562 = sqrt(r28561);
        double r28563 = r28562 / r28532;
        double r28564 = pow(r28542, r28536);
        double r28565 = r28538 * r28538;
        double r28566 = pow(r28565, r28536);
        double r28567 = r28564 - r28566;
        double r28568 = pow(r28538, r28554);
        double r28569 = fma(r28535, r28535, r28568);
        double r28570 = pow(r28535, r28549);
        double r28571 = fma(r28569, r28568, r28570);
        double r28572 = r28567 / r28571;
        double r28573 = r28572 / r28541;
        double r28574 = sqrt(r28573);
        double r28575 = r28574 / r28532;
        double r28576 = r28563 * r28575;
        double r28577 = r28548 ? r28558 : r28576;
        double r28578 = r28534 ? r28546 : r28577;
        return r28578;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.0

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

      \[\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. Simplified1.0

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

    if -0.03305941206486147 < x < 0.034074837610598666

    1. Initial program 62.1

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

    if 0.034074837610598666 < x

    1. Initial program 1.0

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.5

      \[\leadsto \frac{\sqrt{1 - \color{blue}{\log \left(e^{\cos x}\right)}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    7. Applied add-log-exp0.5

      \[\leadsto \frac{\sqrt{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    8. Applied diff-log0.6

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

      \[\leadsto \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    10. Using strategy rm
    11. Applied flip--0.6

      \[\leadsto \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x} \cdot \frac{\sqrt{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}}{x}\]
    12. Using strategy rm
    13. Applied flip3--0.6

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

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

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

Reproduce

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