Average Error: 31.7 → 0.3
Time: 11.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03309682507506567228361404886527452617884 \lor \neg \left(x \le 0.03227596253233405709792691595794167369604\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.03309682507506567228361404886527452617884 \lor \neg \left(x \le 0.03227596253233405709792691595794167369604\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 r29079 = 1.0;
        double r29080 = x;
        double r29081 = cos(r29080);
        double r29082 = r29079 - r29081;
        double r29083 = r29080 * r29080;
        double r29084 = r29082 / r29083;
        return r29084;
}

double f(double x) {
        double r29085 = x;
        double r29086 = -0.03309682507506567;
        bool r29087 = r29085 <= r29086;
        double r29088 = 0.03227596253233406;
        bool r29089 = r29085 <= r29088;
        double r29090 = !r29089;
        bool r29091 = r29087 || r29090;
        double r29092 = 1.0;
        double r29093 = cos(r29085);
        double r29094 = r29092 - r29093;
        double r29095 = r29094 / r29085;
        double r29096 = 1.0;
        double r29097 = r29096 / r29085;
        double r29098 = r29095 * r29097;
        double r29099 = 0.001388888888888889;
        double r29100 = 4.0;
        double r29101 = pow(r29085, r29100);
        double r29102 = r29099 * r29101;
        double r29103 = 0.5;
        double r29104 = r29102 + r29103;
        double r29105 = 0.041666666666666664;
        double r29106 = 2.0;
        double r29107 = pow(r29085, r29106);
        double r29108 = r29105 * r29107;
        double r29109 = r29104 - r29108;
        double r29110 = r29091 ? r29098 : r29109;
        return r29110;
}

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.03309682507506567 or 0.03227596253233406 < 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 div-inv0.5

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

    if -0.03309682507506567 < x < 0.03227596253233406

    1. Initial program 62.2

      \[\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.03309682507506567228361404886527452617884 \lor \neg \left(x \le 0.03227596253233405709792691595794167369604\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 2019351 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))