Average Error: 31.7 → 0.3
Time: 10.1s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03309682507506567228361404886527452617884 \lor \neg \left(x \le 0.03227596253233405709792691595794167369604\right):\\ \;\;\;\;\frac{1 - \cos x}{x} \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03309682507506567228361404886527452617884 \lor \neg \left(x \le 0.03227596253233405709792691595794167369604\right):\\
\;\;\;\;\frac{1 - \cos x}{x} \cdot \frac{1}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\

\end{array}
double f(double x) {
        double r27516 = 1.0;
        double r27517 = x;
        double r27518 = cos(r27517);
        double r27519 = r27516 - r27518;
        double r27520 = r27517 * r27517;
        double r27521 = r27519 / r27520;
        return r27521;
}

double f(double x) {
        double r27522 = x;
        double r27523 = -0.03309682507506567;
        bool r27524 = r27522 <= r27523;
        double r27525 = 0.03227596253233406;
        bool r27526 = r27522 <= r27525;
        double r27527 = !r27526;
        bool r27528 = r27524 || r27527;
        double r27529 = 1.0;
        double r27530 = cos(r27522);
        double r27531 = r27529 - r27530;
        double r27532 = r27531 / r27522;
        double r27533 = 1.0;
        double r27534 = r27533 / r27522;
        double r27535 = r27532 * r27534;
        double r27536 = r27522 * r27522;
        double r27537 = -0.041666666666666664;
        double r27538 = 0.001388888888888889;
        double r27539 = 4.0;
        double r27540 = pow(r27522, r27539);
        double r27541 = 0.5;
        double r27542 = fma(r27538, r27540, r27541);
        double r27543 = fma(r27536, r27537, r27542);
        double r27544 = r27528 ? r27535 : r27543;
        return r27544;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03309682507506567 or 0.03227596253233406 < 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 div-inv0.5

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

    if -0.03309682507506567 < x < 0.03227596253233406

    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. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.03309682507506567228361404886527452617884 \lor \neg \left(x \le 0.03227596253233405709792691595794167369604\right):\\ \;\;\;\;\frac{1 - \cos x}{x} \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019351 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))