Average Error: 31.3 → 0.4
Time: 4.4s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0330594120648614667:\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{x \cdot x}\\ \mathbf{elif}\;x \le 0.034074837610598666:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x} \cdot \frac{\sqrt{\frac{\frac{{\left(1 \cdot 1\right)}^{3} - {\left(\cos x \cdot \cos x\right)}^{3}}{\left({1}^{4} + 1 \cdot \left(1 \cdot {\left(\cos x\right)}^{2}\right)\right) + {\left(\cos x\right)}^{4}}}{1 + \cos x}}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0330594120648614667:\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{x \cdot x}\\

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

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

\end{array}
double f(double x) {
        double r27428 = 1.0;
        double r27429 = x;
        double r27430 = cos(r27429);
        double r27431 = r27428 - r27430;
        double r27432 = r27429 * r27429;
        double r27433 = r27431 / r27432;
        return r27433;
}

double f(double x) {
        double r27434 = x;
        double r27435 = -0.03305941206486147;
        bool r27436 = r27434 <= r27435;
        double r27437 = 1.0;
        double r27438 = 3.0;
        double r27439 = pow(r27437, r27438);
        double r27440 = cos(r27434);
        double r27441 = pow(r27440, r27438);
        double r27442 = r27439 - r27441;
        double r27443 = r27440 + r27437;
        double r27444 = r27440 * r27443;
        double r27445 = r27437 * r27437;
        double r27446 = r27444 + r27445;
        double r27447 = r27442 / r27446;
        double r27448 = r27434 * r27434;
        double r27449 = r27447 / r27448;
        double r27450 = 0.034074837610598666;
        bool r27451 = r27434 <= r27450;
        double r27452 = 0.001388888888888889;
        double r27453 = 4.0;
        double r27454 = pow(r27434, r27453);
        double r27455 = r27452 * r27454;
        double r27456 = 0.5;
        double r27457 = r27455 + r27456;
        double r27458 = 0.041666666666666664;
        double r27459 = 2.0;
        double r27460 = pow(r27434, r27459);
        double r27461 = r27458 * r27460;
        double r27462 = r27457 - r27461;
        double r27463 = r27437 - r27440;
        double r27464 = exp(r27463);
        double r27465 = log(r27464);
        double r27466 = sqrt(r27465);
        double r27467 = r27466 / r27434;
        double r27468 = pow(r27445, r27438);
        double r27469 = r27440 * r27440;
        double r27470 = pow(r27469, r27438);
        double r27471 = r27468 - r27470;
        double r27472 = pow(r27437, r27453);
        double r27473 = pow(r27440, r27459);
        double r27474 = r27437 * r27473;
        double r27475 = r27437 * r27474;
        double r27476 = r27472 + r27475;
        double r27477 = pow(r27440, r27453);
        double r27478 = r27476 + r27477;
        double r27479 = r27471 / r27478;
        double r27480 = r27437 + r27440;
        double r27481 = r27479 / r27480;
        double r27482 = sqrt(r27481);
        double r27483 = r27482 / r27434;
        double r27484 = r27467 * r27483;
        double r27485 = r27451 ? r27462 : r27484;
        double r27486 = r27436 ? r27449 : r27485;
        return r27486;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if x < -0.03305941206486147

    1. Initial program 1.0

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

      \[\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. Simplified1.0

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

    if -0.03305941206486147 < x < 0.034074837610598666

    1. Initial program 62.1

      \[\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}}\]

    if 0.034074837610598666 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.1

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.5

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.5

      \[\leadsto \frac{\sqrt{1 - \color{blue}{\log \left(e^{\cos x}\right)}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    7. Applied add-log-exp0.5

      \[\leadsto \frac{\sqrt{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    8. Applied diff-log0.6

      \[\leadsto \frac{\sqrt{\color{blue}{\log \left(\frac{e^{1}}{e^{\cos x}}\right)}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    9. Simplified0.5

      \[\leadsto \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    10. Using strategy rm
    11. Applied flip--0.6

      \[\leadsto \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x} \cdot \frac{\sqrt{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}}{x}\]
    12. Using strategy rm
    13. Applied flip3--0.6

      \[\leadsto \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x} \cdot \frac{\sqrt{\frac{\color{blue}{\frac{{\left(1 \cdot 1\right)}^{3} - {\left(\cos x \cdot \cos x\right)}^{3}}{\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right) + \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \cos x\right)\right)}}}{1 + \cos x}}}{x}\]
    14. Simplified0.6

      \[\leadsto \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x} \cdot \frac{\sqrt{\frac{\frac{{\left(1 \cdot 1\right)}^{3} - {\left(\cos x \cdot \cos x\right)}^{3}}{\color{blue}{\left({1}^{4} + 1 \cdot \left(1 \cdot {\left(\cos x\right)}^{2}\right)\right) + {\left(\cos x\right)}^{4}}}}{1 + \cos x}}}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Reproduce

herbie shell --seed 2020057 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))