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

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\

\end{array}
double f(double x) {
        double r16847 = 1.0;
        double r16848 = x;
        double r16849 = cos(r16848);
        double r16850 = r16847 - r16849;
        double r16851 = r16848 * r16848;
        double r16852 = r16850 / r16851;
        return r16852;
}

double f(double x) {
        double r16853 = x;
        double r16854 = -0.03315307006442389;
        bool r16855 = r16853 <= r16854;
        double r16856 = 1.0;
        double r16857 = cos(r16853);
        double r16858 = r16856 - r16857;
        double r16859 = log(r16858);
        double r16860 = exp(r16859);
        double r16861 = r16853 * r16853;
        double r16862 = r16860 / r16861;
        double r16863 = 0.03157722500580303;
        bool r16864 = r16853 <= r16863;
        double r16865 = 0.001388888888888889;
        double r16866 = 4.0;
        double r16867 = pow(r16853, r16866);
        double r16868 = r16865 * r16867;
        double r16869 = 0.5;
        double r16870 = r16868 + r16869;
        double r16871 = 0.041666666666666664;
        double r16872 = 2.0;
        double r16873 = pow(r16853, r16872);
        double r16874 = r16871 * r16873;
        double r16875 = r16870 - r16874;
        double r16876 = sqrt(r16858);
        double r16877 = r16876 / r16853;
        double r16878 = r16877 * r16877;
        double r16879 = r16864 ? r16875 : r16878;
        double r16880 = r16855 ? r16862 : r16879;
        return r16880;
}

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

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-exp-log0.9

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

    if -0.03315307006442389 < x < 0.03157722500580303

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

    if 0.03157722500580303 < x

    1. Initial program 1.0

      \[\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}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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