Average Error: 30.9 → 0.3
Time: 11.9s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.031832610611401149 \lor \neg \left(x \le 0.0280789751943332118\right):\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{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.031832610611401149 \lor \neg \left(x \le 0.0280789751943332118\right):\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{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 r27972 = 1.0;
        double r27973 = x;
        double r27974 = cos(r27973);
        double r27975 = r27972 - r27974;
        double r27976 = r27973 * r27973;
        double r27977 = r27975 / r27976;
        return r27977;
}

double f(double x) {
        double r27978 = x;
        double r27979 = -0.03183261061140115;
        bool r27980 = r27978 <= r27979;
        double r27981 = 0.028078975194333212;
        bool r27982 = r27978 <= r27981;
        double r27983 = !r27982;
        bool r27984 = r27980 || r27983;
        double r27985 = 1.0;
        double r27986 = cos(r27978);
        double r27987 = r27985 - r27986;
        double r27988 = sqrt(r27987);
        double r27989 = r27988 / r27978;
        double r27990 = exp(r27987);
        double r27991 = log(r27990);
        double r27992 = sqrt(r27991);
        double r27993 = r27992 / r27978;
        double r27994 = r27989 * r27993;
        double r27995 = 0.001388888888888889;
        double r27996 = 4.0;
        double r27997 = pow(r27978, r27996);
        double r27998 = r27995 * r27997;
        double r27999 = 0.5;
        double r28000 = r27998 + r27999;
        double r28001 = 0.041666666666666664;
        double r28002 = 2.0;
        double r28003 = pow(r27978, r28002);
        double r28004 = r28001 * r28003;
        double r28005 = r28000 - r28004;
        double r28006 = r27984 ? r27994 : r28005;
        return r28006;
}

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.03183261061140115 or 0.028078975194333212 < 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.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}\]

    if -0.03183261061140115 < x < 0.028078975194333212

    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.031832610611401149 \lor \neg \left(x \le 0.0280789751943332118\right):\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{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 2020043 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))