Average Error: 31.3 → 0.4
Time: 8.8s
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 r36268 = 1.0;
        double r36269 = x;
        double r36270 = cos(r36269);
        double r36271 = r36268 - r36270;
        double r36272 = r36269 * r36269;
        double r36273 = r36271 / r36272;
        return r36273;
}

double f(double x) {
        double r36274 = x;
        double r36275 = -0.03315307006442389;
        bool r36276 = r36274 <= r36275;
        double r36277 = 1.0;
        double r36278 = cos(r36274);
        double r36279 = r36277 - r36278;
        double r36280 = log(r36279);
        double r36281 = exp(r36280);
        double r36282 = r36274 * r36274;
        double r36283 = r36281 / r36282;
        double r36284 = 0.03157722500580303;
        bool r36285 = r36274 <= r36284;
        double r36286 = 0.001388888888888889;
        double r36287 = 4.0;
        double r36288 = pow(r36274, r36287);
        double r36289 = r36286 * r36288;
        double r36290 = 0.5;
        double r36291 = r36289 + r36290;
        double r36292 = 0.041666666666666664;
        double r36293 = 2.0;
        double r36294 = pow(r36274, r36293);
        double r36295 = r36292 * r36294;
        double r36296 = r36291 - r36295;
        double r36297 = sqrt(r36279);
        double r36298 = r36297 / r36274;
        double r36299 = r36298 * r36298;
        double r36300 = r36285 ? r36296 : r36299;
        double r36301 = r36276 ? r36283 : r36300;
        return r36301;
}

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)))