Average Error: 32.0 → 0.3
Time: 10.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03040591614705374229332690561022900510579:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\ \mathbf{elif}\;x \le 0.03397543731978374531577102857227146159858:\\ \;\;\;\;\left(\log \left(e^{\frac{1}{720} \cdot {x}^{4}}\right) + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{e^{\log \left(1 - \cos x\right)}}{x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03040591614705374229332690561022900510579:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\

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

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

\end{array}
double f(double x) {
        double r19174 = 1.0;
        double r19175 = x;
        double r19176 = cos(r19175);
        double r19177 = r19174 - r19176;
        double r19178 = r19175 * r19175;
        double r19179 = r19177 / r19178;
        return r19179;
}

double f(double x) {
        double r19180 = x;
        double r19181 = -0.030405916147053742;
        bool r19182 = r19180 <= r19181;
        double r19183 = 1.0;
        double r19184 = r19183 / r19180;
        double r19185 = cos(r19180);
        double r19186 = r19185 / r19180;
        double r19187 = r19184 - r19186;
        double r19188 = r19187 / r19180;
        double r19189 = 0.033975437319783745;
        bool r19190 = r19180 <= r19189;
        double r19191 = 0.001388888888888889;
        double r19192 = 4.0;
        double r19193 = pow(r19180, r19192);
        double r19194 = r19191 * r19193;
        double r19195 = exp(r19194);
        double r19196 = log(r19195);
        double r19197 = 0.5;
        double r19198 = r19196 + r19197;
        double r19199 = 0.041666666666666664;
        double r19200 = 2.0;
        double r19201 = pow(r19180, r19200);
        double r19202 = r19199 * r19201;
        double r19203 = r19198 - r19202;
        double r19204 = r19183 - r19185;
        double r19205 = log(r19204);
        double r19206 = exp(r19205);
        double r19207 = r19206 / r19180;
        double r19208 = r19207 / r19180;
        double r19209 = r19190 ? r19203 : r19208;
        double r19210 = r19182 ? r19188 : r19209;
        return r19210;
}

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

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.4

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied div-sub0.6

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - \frac{\cos x}{x}}}{x}\]

    if -0.030405916147053742 < x < 0.033975437319783745

    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}}\]
    3. Using strategy rm
    4. Applied add-log-exp0.0

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

    if 0.033975437319783745 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.5

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied add-exp-log0.5

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

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

Reproduce

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