Average Error: 31.4 → 0.3
Time: 12.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.034013493959747065 \lor \neg \left(x \le 0.0281843105629446845\right):\\ \;\;\;\;\frac{\frac{e^{\log \left(1 - \cos x\right)}}{x}}{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.034013493959747065 \lor \neg \left(x \le 0.0281843105629446845\right):\\
\;\;\;\;\frac{\frac{e^{\log \left(1 - \cos x\right)}}{x}}{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 r23000 = 1.0;
        double r23001 = x;
        double r23002 = cos(r23001);
        double r23003 = r23000 - r23002;
        double r23004 = r23001 * r23001;
        double r23005 = r23003 / r23004;
        return r23005;
}

double f(double x) {
        double r23006 = x;
        double r23007 = -0.034013493959747065;
        bool r23008 = r23006 <= r23007;
        double r23009 = 0.028184310562944685;
        bool r23010 = r23006 <= r23009;
        double r23011 = !r23010;
        bool r23012 = r23008 || r23011;
        double r23013 = 1.0;
        double r23014 = cos(r23006);
        double r23015 = r23013 - r23014;
        double r23016 = log(r23015);
        double r23017 = exp(r23016);
        double r23018 = r23017 / r23006;
        double r23019 = r23018 / r23006;
        double r23020 = 0.001388888888888889;
        double r23021 = 4.0;
        double r23022 = pow(r23006, r23021);
        double r23023 = r23020 * r23022;
        double r23024 = 0.5;
        double r23025 = r23023 + r23024;
        double r23026 = 0.041666666666666664;
        double r23027 = 2.0;
        double r23028 = pow(r23006, r23027);
        double r23029 = r23026 * r23028;
        double r23030 = r23025 - r23029;
        double r23031 = r23012 ? r23019 : r23030;
        return r23031;
}

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.034013493959747065 or 0.028184310562944685 < 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 add-exp-log0.5

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

    if -0.034013493959747065 < x < 0.028184310562944685

    1. Initial program 62.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.034013493959747065 \lor \neg \left(x \le 0.0281843105629446845\right):\\ \;\;\;\;\frac{\frac{e^{\log \left(1 - \cos x\right)}}{x}}{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 2019198 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1.0 (cos x)) (* x x)))