Average Error: 31.3 → 0.6
Time: 15.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03224345637809938186491010014833591412753:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(\left(1 + \cos x\right) \cdot \cos x + 1 \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.02880979041531033998935207307567907264456:\\ \;\;\;\;\left(\frac{1}{720} \cdot \left(x \cdot x\right) - \frac{1}{24}\right) \cdot \left(x \cdot x\right) + \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(\left(1 + \cos x\right) \cdot \cos x + 1 \cdot 1\right)}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03224345637809938186491010014833591412753:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(\left(1 + \cos x\right) \cdot \cos x + 1 \cdot 1\right)}\\

\mathbf{elif}\;x \le 0.02880979041531033998935207307567907264456:\\
\;\;\;\;\left(\frac{1}{720} \cdot \left(x \cdot x\right) - \frac{1}{24}\right) \cdot \left(x \cdot x\right) + \frac{1}{2}\\

\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(\left(1 + \cos x\right) \cdot \cos x + 1 \cdot 1\right)}\\

\end{array}
double f(double x) {
        double r754406 = 1.0;
        double r754407 = x;
        double r754408 = cos(r754407);
        double r754409 = r754406 - r754408;
        double r754410 = r754407 * r754407;
        double r754411 = r754409 / r754410;
        return r754411;
}

double f(double x) {
        double r754412 = x;
        double r754413 = -0.03224345637809938;
        bool r754414 = r754412 <= r754413;
        double r754415 = 1.0;
        double r754416 = 3.0;
        double r754417 = pow(r754415, r754416);
        double r754418 = cos(r754412);
        double r754419 = pow(r754418, r754416);
        double r754420 = r754417 - r754419;
        double r754421 = r754412 * r754412;
        double r754422 = r754415 + r754418;
        double r754423 = r754422 * r754418;
        double r754424 = r754415 * r754415;
        double r754425 = r754423 + r754424;
        double r754426 = r754421 * r754425;
        double r754427 = r754420 / r754426;
        double r754428 = 0.02880979041531034;
        bool r754429 = r754412 <= r754428;
        double r754430 = 0.001388888888888889;
        double r754431 = r754430 * r754421;
        double r754432 = 0.041666666666666664;
        double r754433 = r754431 - r754432;
        double r754434 = r754433 * r754421;
        double r754435 = 0.5;
        double r754436 = r754434 + r754435;
        double r754437 = r754429 ? r754436 : r754427;
        double r754438 = r754414 ? r754427 : r754437;
        return r754438;
}

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.03224345637809938 or 0.02880979041531034 < x

    1. Initial program 1.0

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

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{x \cdot x}\]
    4. Applied associate-/l/1.1

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}\]
    5. Simplified1.1

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(x \cdot x\right) \cdot \left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right)}}\]

    if -0.03224345637809938 < x < 0.02880979041531034

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

      \[\leadsto \color{blue}{\frac{1}{2} + \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \frac{1}{720} - \frac{1}{24}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.03224345637809938186491010014833591412753:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(\left(1 + \cos x\right) \cdot \cos x + 1 \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.02880979041531033998935207307567907264456:\\ \;\;\;\;\left(\frac{1}{720} \cdot \left(x \cdot x\right) - \frac{1}{24}\right) \cdot \left(x \cdot x\right) + \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(\left(1 + \cos x\right) \cdot \cos x + 1 \cdot 1\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1.0 (cos x)) (* x x)))