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

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}}{x} \cdot \frac{\frac{\sqrt[3]{{1}^{3} - {\left(\cos x\right)}^{3}}}{\sqrt[3]{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{x}\\

\end{array}
double f(double x) {
        double r25595 = 1.0;
        double r25596 = x;
        double r25597 = cos(r25596);
        double r25598 = r25595 - r25597;
        double r25599 = r25596 * r25596;
        double r25600 = r25598 / r25599;
        return r25600;
}

double f(double x) {
        double r25601 = x;
        double r25602 = -0.03018149556589929;
        bool r25603 = r25601 <= r25602;
        double r25604 = 1.0;
        double r25605 = cos(r25601);
        double r25606 = r25604 - r25605;
        double r25607 = exp(r25606);
        double r25608 = log(r25607);
        double r25609 = cbrt(r25608);
        double r25610 = cbrt(r25606);
        double r25611 = r25609 * r25610;
        double r25612 = r25611 / r25601;
        double r25613 = 3.0;
        double r25614 = pow(r25604, r25613);
        double r25615 = pow(r25605, r25613);
        double r25616 = r25614 - r25615;
        double r25617 = cbrt(r25616);
        double r25618 = r25604 * r25604;
        double r25619 = r25605 * r25605;
        double r25620 = r25604 * r25605;
        double r25621 = r25619 + r25620;
        double r25622 = r25618 + r25621;
        double r25623 = cbrt(r25622);
        double r25624 = r25617 / r25623;
        double r25625 = r25624 / r25601;
        double r25626 = r25612 * r25625;
        double r25627 = 0.03173609678414467;
        bool r25628 = r25601 <= r25627;
        double r25629 = 4.0;
        double r25630 = pow(r25601, r25629);
        double r25631 = 0.001388888888888889;
        double r25632 = 0.5;
        double r25633 = 0.041666666666666664;
        double r25634 = 2.0;
        double r25635 = pow(r25601, r25634);
        double r25636 = r25633 * r25635;
        double r25637 = r25632 - r25636;
        double r25638 = fma(r25630, r25631, r25637);
        double r25639 = r25610 * r25610;
        double r25640 = r25639 / r25601;
        double r25641 = r25640 * r25625;
        double r25642 = r25628 ? r25638 : r25641;
        double r25643 = r25603 ? r25626 : r25642;
        return r25643;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 0.9

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

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}\right) \cdot \sqrt[3]{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.8

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}}{x} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied flip3--0.8

      \[\leadsto \frac{\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}}{x} \cdot \frac{\sqrt[3]{\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}\]
    7. Applied cbrt-div0.8

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

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

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

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

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

    if -0.03018149556589929 < x < 0.03173609678414467

    1. Initial program 62.4

      \[\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.03173609678414467 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt1.5

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}\right) \cdot \sqrt[3]{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.8

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}}{x} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied flip3--0.8

      \[\leadsto \frac{\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}}{x} \cdot \frac{\sqrt[3]{\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}\]
    7. Applied cbrt-div0.8

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

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

Reproduce

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