Average Error: 30.9 → 0.5
Time: 3.8s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0289755674093477682:\\ \;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{x \cdot x}\\ \mathbf{elif}\;x \le 0.0323653638594900775:\\ \;\;\;\;\frac{1}{720} \cdot {x}^{4} + \left(\frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0289755674093477682:\\
\;\;\;\;\frac{\log \left(e^{1 - \cos x}\right)}{x \cdot x}\\

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

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

\end{array}
double f(double x) {
        double r24610 = 1.0;
        double r24611 = x;
        double r24612 = cos(r24611);
        double r24613 = r24610 - r24612;
        double r24614 = r24611 * r24611;
        double r24615 = r24613 / r24614;
        return r24615;
}

double f(double x) {
        double r24616 = x;
        double r24617 = -0.028975567409347768;
        bool r24618 = r24616 <= r24617;
        double r24619 = 1.0;
        double r24620 = cos(r24616);
        double r24621 = r24619 - r24620;
        double r24622 = exp(r24621);
        double r24623 = log(r24622);
        double r24624 = r24616 * r24616;
        double r24625 = r24623 / r24624;
        double r24626 = 0.03236536385949008;
        bool r24627 = r24616 <= r24626;
        double r24628 = 0.001388888888888889;
        double r24629 = 4.0;
        double r24630 = pow(r24616, r24629);
        double r24631 = r24628 * r24630;
        double r24632 = 0.5;
        double r24633 = 0.041666666666666664;
        double r24634 = 2.0;
        double r24635 = pow(r24616, r24634);
        double r24636 = r24633 * r24635;
        double r24637 = r24632 - r24636;
        double r24638 = r24631 + r24637;
        double r24639 = sqrt(r24621);
        double r24640 = r24639 / r24616;
        double r24641 = sqrt(r24623);
        double r24642 = r24641 / r24616;
        double r24643 = r24640 * r24642;
        double r24644 = r24627 ? r24638 : r24643;
        double r24645 = r24618 ? r24625 : r24644;
        return r24645;
}

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

    1. Initial program 1.0

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

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

      \[\leadsto \frac{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}{x \cdot x}\]
    5. Applied diff-log1.3

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{1}}{e^{\cos x}}\right)}}{x \cdot x}\]
    6. Simplified1.2

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

    if -0.028975567409347768 < x < 0.03236536385949008

    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. Using strategy rm
    4. Applied associate--l+0.0

      \[\leadsto \color{blue}{\frac{1}{720} \cdot {x}^{4} + \left(\frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)}\]

    if 0.03236536385949008 < x

    1. Initial program 1.1

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

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

      \[\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.6

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

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

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

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

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

Reproduce

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