Average Error: 31.2 → 0.3
Time: 17.1s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03339438899281232248084094749174255412072 \lor \neg \left(x \le 0.02980554453480009288734997596748144133016\right):\\ \;\;\;\;\frac{1 - \cos x}{x} \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03339438899281232248084094749174255412072 \lor \neg \left(x \le 0.02980554453480009288734997596748144133016\right):\\
\;\;\;\;\frac{1 - \cos x}{x} \cdot \frac{1}{x}\\

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

\end{array}
double f(double x) {
        double r18861 = 1.0;
        double r18862 = x;
        double r18863 = cos(r18862);
        double r18864 = r18861 - r18863;
        double r18865 = r18862 * r18862;
        double r18866 = r18864 / r18865;
        return r18866;
}

double f(double x) {
        double r18867 = x;
        double r18868 = -0.03339438899281232;
        bool r18869 = r18867 <= r18868;
        double r18870 = 0.029805544534800093;
        bool r18871 = r18867 <= r18870;
        double r18872 = !r18871;
        bool r18873 = r18869 || r18872;
        double r18874 = 1.0;
        double r18875 = cos(r18867);
        double r18876 = r18874 - r18875;
        double r18877 = r18876 / r18867;
        double r18878 = 1.0;
        double r18879 = r18878 / r18867;
        double r18880 = r18877 * r18879;
        double r18881 = 0.001388888888888889;
        double r18882 = 4.0;
        double r18883 = pow(r18867, r18882);
        double r18884 = r18881 * r18883;
        double r18885 = 0.5;
        double r18886 = r18884 + r18885;
        double r18887 = 0.041666666666666664;
        double r18888 = 2.0;
        double r18889 = pow(r18867, r18888);
        double r18890 = r18887 * r18889;
        double r18891 = r18886 - r18890;
        double r18892 = r18873 ? r18880 : r18891;
        return r18892;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03339438899281232 or 0.029805544534800093 < x

    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}}\]
    4. Using strategy rm
    5. Applied div-inv0.5

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

    if -0.03339438899281232 < x < 0.029805544534800093

    1. Initial program 62.4

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

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - \frac{\cos x}{x}}}{x}\]
    6. 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. Recombined 2 regimes into one program.
  4. Final simplification0.3

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

Reproduce

herbie shell --seed 2019322 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))