Average Error: 31.4 → 0.7
Time: 7.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le \frac{-8125101272480133}{288230376151711744} \lor \neg \left(x \le \frac{4966243528841673}{144115188075855872}\right):\\ \;\;\;\;\frac{1}{x \cdot x} - \frac{\cos x}{x \cdot 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 \frac{-8125101272480133}{288230376151711744} \lor \neg \left(x \le \frac{4966243528841673}{144115188075855872}\right):\\
\;\;\;\;\frac{1}{x \cdot x} - \frac{\cos x}{x \cdot 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 r19610 = 1.0;
        double r19611 = x;
        double r19612 = cos(r19611);
        double r19613 = r19610 - r19612;
        double r19614 = r19611 * r19611;
        double r19615 = r19613 / r19614;
        return r19615;
}

double f(double x) {
        double r19616 = x;
        double r19617 = -8125101272480133.0;
        double r19618 = 2.8823037615171174e+17;
        double r19619 = r19617 / r19618;
        bool r19620 = r19616 <= r19619;
        double r19621 = 4966243528841673.0;
        double r19622 = 1.4411518807585587e+17;
        double r19623 = r19621 / r19622;
        bool r19624 = r19616 <= r19623;
        double r19625 = !r19624;
        bool r19626 = r19620 || r19625;
        double r19627 = 1.0;
        double r19628 = r19616 * r19616;
        double r19629 = r19627 / r19628;
        double r19630 = cos(r19616);
        double r19631 = r19630 / r19628;
        double r19632 = r19629 - r19631;
        double r19633 = 0.001388888888888889;
        double r19634 = 4.0;
        double r19635 = pow(r19616, r19634);
        double r19636 = r19633 * r19635;
        double r19637 = 0.5;
        double r19638 = r19636 + r19637;
        double r19639 = 0.041666666666666664;
        double r19640 = 2.0;
        double r19641 = pow(r19616, r19640);
        double r19642 = r19639 * r19641;
        double r19643 = r19638 - r19642;
        double r19644 = r19626 ? r19632 : r19643;
        return r19644;
}

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.02818960784412063 or 0.034460236947598206 < x

    1. Initial program 1.2

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied div-sub1.3

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

    if -0.02818960784412063 < x < 0.034460236947598206

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le \frac{-8125101272480133}{288230376151711744} \lor \neg \left(x \le \frac{4966243528841673}{144115188075855872}\right):\\ \;\;\;\;\frac{1}{x \cdot x} - \frac{\cos x}{x \cdot 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 197574269 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))