Average Error: 31.1 → 0.3
Time: 53.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02826034963706557101570382428690209053457:\\ \;\;\;\;\sqrt{\frac{\frac{\log \left(e^{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - \cos x\right)\right)}\right)}{x}}{x}} \cdot \sqrt{\frac{\frac{1 - \cos x}{x}}{x}}\\ \mathbf{elif}\;x \le 0.02946672320662404448432525327916664537042:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{720}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{x} \cdot \left(1 - \cos x\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02826034963706557101570382428690209053457:\\
\;\;\;\;\sqrt{\frac{\frac{\log \left(e^{\mathsf{expm1}\left(\mathsf{log1p}\left(1 - \cos x\right)\right)}\right)}{x}}{x}} \cdot \sqrt{\frac{\frac{1 - \cos x}{x}}{x}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{x} \cdot \left(1 - \cos x\right)\\

\end{array}
double f(double x) {
        double r718801 = 1.0;
        double r718802 = x;
        double r718803 = cos(r718802);
        double r718804 = r718801 - r718803;
        double r718805 = r718802 * r718802;
        double r718806 = r718804 / r718805;
        return r718806;
}

double f(double x) {
        double r718807 = x;
        double r718808 = -0.02826034963706557;
        bool r718809 = r718807 <= r718808;
        double r718810 = 1.0;
        double r718811 = cos(r718807);
        double r718812 = r718810 - r718811;
        double r718813 = log1p(r718812);
        double r718814 = expm1(r718813);
        double r718815 = exp(r718814);
        double r718816 = log(r718815);
        double r718817 = r718816 / r718807;
        double r718818 = r718817 / r718807;
        double r718819 = sqrt(r718818);
        double r718820 = r718812 / r718807;
        double r718821 = r718820 / r718807;
        double r718822 = sqrt(r718821);
        double r718823 = r718819 * r718822;
        double r718824 = 0.029466723206624044;
        bool r718825 = r718807 <= r718824;
        double r718826 = r718807 * r718807;
        double r718827 = -0.041666666666666664;
        double r718828 = r718826 * r718826;
        double r718829 = 0.001388888888888889;
        double r718830 = 0.5;
        double r718831 = fma(r718828, r718829, r718830);
        double r718832 = fma(r718826, r718827, r718831);
        double r718833 = 1.0;
        double r718834 = r718833 / r718807;
        double r718835 = r718834 / r718807;
        double r718836 = r718835 * r718812;
        double r718837 = r718825 ? r718832 : r718836;
        double r718838 = r718809 ? r718823 : r718837;
        return r718838;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.4

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt0.5

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

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

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

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

      \[\leadsto \sqrt{\frac{\frac{1 - \cos x}{x}}{x}} \cdot \sqrt{\frac{\frac{\log \color{blue}{\left(e^{1 - \cos x}\right)}}{x}}{x}}\]
    11. Using strategy rm
    12. Applied expm1-log1p-u0.6

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

    if -0.02826034963706557 < x < 0.029466723206624044

    1. Initial program 62.3

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*61.3

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. 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}}\]
    5. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{720}, \frac{1}{2}\right)\right)}\]

    if 0.029466723206624044 < x

    1. Initial program 1.0

      \[\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 *-un-lft-identity0.5

      \[\leadsto \frac{\frac{1 - \cos x}{x}}{\color{blue}{1 \cdot x}}\]
    6. Applied div-inv0.5

      \[\leadsto \frac{\color{blue}{\left(1 - \cos x\right) \cdot \frac{1}{x}}}{1 \cdot x}\]
    7. Applied times-frac0.5

      \[\leadsto \color{blue}{\frac{1 - \cos x}{1} \cdot \frac{\frac{1}{x}}{x}}\]
    8. Simplified0.5

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

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

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1.0 (cos x)) (* x x)))