Average Error: 31.8 → 0.3
Time: 14.9s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03354637559076366348786990556618547998369 \lor \neg \left(x \le 0.03201386298905525146230033328720310237259\right):\\ \;\;\;\;\frac{1}{x} \cdot \frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right) \cdot 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.03354637559076366348786990556618547998369 \lor \neg \left(x \le 0.03201386298905525146230033328720310237259\right):\\
\;\;\;\;\frac{1}{x} \cdot \frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right) \cdot 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 r19970 = 1.0;
        double r19971 = x;
        double r19972 = cos(r19971);
        double r19973 = r19970 - r19972;
        double r19974 = r19971 * r19971;
        double r19975 = r19973 / r19974;
        return r19975;
}

double f(double x) {
        double r19976 = x;
        double r19977 = -0.033546375590763663;
        bool r19978 = r19976 <= r19977;
        double r19979 = 0.03201386298905525;
        bool r19980 = r19976 <= r19979;
        double r19981 = !r19980;
        bool r19982 = r19978 || r19981;
        double r19983 = 1.0;
        double r19984 = r19983 / r19976;
        double r19985 = 1.0;
        double r19986 = 3.0;
        double r19987 = pow(r19985, r19986);
        double r19988 = cos(r19976);
        double r19989 = pow(r19988, r19986);
        double r19990 = r19987 - r19989;
        double r19991 = exp(r19990);
        double r19992 = log(r19991);
        double r19993 = r19985 + r19988;
        double r19994 = r19988 * r19993;
        double r19995 = r19985 * r19985;
        double r19996 = r19994 + r19995;
        double r19997 = r19996 * r19976;
        double r19998 = r19992 / r19997;
        double r19999 = r19984 * r19998;
        double r20000 = 0.001388888888888889;
        double r20001 = 4.0;
        double r20002 = pow(r19976, r20001);
        double r20003 = r20000 * r20002;
        double r20004 = 0.5;
        double r20005 = r20003 + r20004;
        double r20006 = 0.041666666666666664;
        double r20007 = 2.0;
        double r20008 = pow(r19976, r20007);
        double r20009 = r20006 * r20008;
        double r20010 = r20005 - r20009;
        double r20011 = r19982 ? r19999 : r20010;
        return r20011;
}

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.033546375590763663 or 0.03201386298905525 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity1.0

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

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. Using strategy rm
    6. Applied flip3--0.5

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Applied associate-/l/0.5

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

      \[\leadsto \frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right) \cdot x}}\]
    9. Using strategy rm
    10. Applied add-log-exp0.5

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

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

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

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

    if -0.033546375590763663 < x < 0.03201386298905525

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