Average Error: 30.9 → 0.6
Time: 4.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0309273812351459031 \lor \neg \left(x \le 0.023960596481684263\right):\\ \;\;\;\;\frac{1 - \cos x}{{x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0309273812351459031 \lor \neg \left(x \le 0.023960596481684263\right):\\
\;\;\;\;\frac{1 - \cos x}{{x}^{2}}\\

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

\end{array}
double f(double x) {
        double r23743 = 1.0;
        double r23744 = x;
        double r23745 = cos(r23744);
        double r23746 = r23743 - r23745;
        double r23747 = r23744 * r23744;
        double r23748 = r23746 / r23747;
        return r23748;
}

double f(double x) {
        double r23749 = x;
        double r23750 = -0.030927381235145903;
        bool r23751 = r23749 <= r23750;
        double r23752 = 0.023960596481684263;
        bool r23753 = r23749 <= r23752;
        double r23754 = !r23753;
        bool r23755 = r23751 || r23754;
        double r23756 = 1.0;
        double r23757 = cos(r23749);
        double r23758 = r23756 - r23757;
        double r23759 = 2.0;
        double r23760 = pow(r23749, r23759);
        double r23761 = r23758 / r23760;
        double r23762 = 4.0;
        double r23763 = pow(r23749, r23762);
        double r23764 = 0.001388888888888889;
        double r23765 = 0.5;
        double r23766 = 0.041666666666666664;
        double r23767 = r23766 * r23760;
        double r23768 = r23765 - r23767;
        double r23769 = fma(r23763, r23764, r23768);
        double r23770 = r23755 ? r23761 : r23769;
        return r23770;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.030927381235145903 or 0.023960596481684263 < x

    1. Initial program 1.1

      \[\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}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.6

      \[\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.6

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

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

      \[\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 frac-times1.2

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

      \[\leadsto \frac{\color{blue}{1 - \cos x}}{x \cdot x}\]
    13. Simplified1.1

      \[\leadsto \frac{1 - \cos x}{\color{blue}{{x}^{2}}}\]

    if -0.030927381235145903 < x < 0.023960596481684263

    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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0309273812351459031 \lor \neg \left(x \le 0.023960596481684263\right):\\ \;\;\;\;\frac{1 - \cos x}{{x}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \end{array}\]

Reproduce

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