Average Error: 31.2 → 0.3
Time: 5.2s
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 r30268 = 1.0;
        double r30269 = x;
        double r30270 = cos(r30269);
        double r30271 = r30268 - r30270;
        double r30272 = r30269 * r30269;
        double r30273 = r30271 / r30272;
        return r30273;
}

double f(double x) {
        double r30274 = x;
        double r30275 = -0.03339438899281232;
        bool r30276 = r30274 <= r30275;
        double r30277 = 0.029805544534800093;
        bool r30278 = r30274 <= r30277;
        double r30279 = !r30278;
        bool r30280 = r30276 || r30279;
        double r30281 = 1.0;
        double r30282 = cos(r30274);
        double r30283 = r30281 - r30282;
        double r30284 = r30283 / r30274;
        double r30285 = 1.0;
        double r30286 = r30285 / r30274;
        double r30287 = r30284 * r30286;
        double r30288 = 0.001388888888888889;
        double r30289 = 4.0;
        double r30290 = pow(r30274, r30289);
        double r30291 = r30288 * r30290;
        double r30292 = 0.5;
        double r30293 = r30291 + r30292;
        double r30294 = 0.041666666666666664;
        double r30295 = 2.0;
        double r30296 = pow(r30274, r30295);
        double r30297 = r30294 * r30296;
        double r30298 = r30293 - r30297;
        double r30299 = r30280 ? r30287 : r30298;
        return r30299;
}

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. 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)))