Average Error: 15.1 → 0.0
Time: 3.7s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -38320489792.49410247802734375 \lor \neg \left(x \le 373.9008368767135266352852340787649154663\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}} - \frac{1}{{x}^{3}}, \frac{1}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(1 \cdot 1, 1, {x}^{6}\right)} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -38320489792.49410247802734375 \lor \neg \left(x \le 373.9008368767135266352852340787649154663\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}} - \frac{1}{{x}^{3}}, \frac{1}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(1 \cdot 1, 1, {x}^{6}\right)} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)\\

\end{array}
double f(double x) {
        double r79425 = x;
        double r79426 = r79425 * r79425;
        double r79427 = 1.0;
        double r79428 = r79426 + r79427;
        double r79429 = r79425 / r79428;
        return r79429;
}

double f(double x) {
        double r79430 = x;
        double r79431 = -38320489792.4941;
        bool r79432 = r79430 <= r79431;
        double r79433 = 373.9008368767135;
        bool r79434 = r79430 <= r79433;
        double r79435 = !r79434;
        bool r79436 = r79432 || r79435;
        double r79437 = 1.0;
        double r79438 = 1.0;
        double r79439 = 5.0;
        double r79440 = pow(r79430, r79439);
        double r79441 = r79438 / r79440;
        double r79442 = 3.0;
        double r79443 = pow(r79430, r79442);
        double r79444 = r79438 / r79443;
        double r79445 = r79441 - r79444;
        double r79446 = r79438 / r79430;
        double r79447 = fma(r79437, r79445, r79446);
        double r79448 = r79437 * r79437;
        double r79449 = 6.0;
        double r79450 = pow(r79430, r79449);
        double r79451 = fma(r79448, r79437, r79450);
        double r79452 = r79430 / r79451;
        double r79453 = r79430 * r79430;
        double r79454 = r79453 * r79453;
        double r79455 = r79453 * r79437;
        double r79456 = r79448 - r79455;
        double r79457 = r79454 + r79456;
        double r79458 = r79452 * r79457;
        double r79459 = r79436 ? r79447 : r79458;
        return r79459;
}

Error

Bits error versus x

Target

Original15.1
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -38320489792.4941 or 373.9008368767135 < x

    1. Initial program 30.7

      \[\frac{x}{x \cdot x + 1}\]
    2. Taylor expanded around inf 0.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{{x}^{5}} - \frac{1}{{x}^{3}}, \frac{1}{x}\right)}\]

    if -38320489792.4941 < x < 373.9008368767135

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied flip3-+0.0

      \[\leadsto \frac{x}{\color{blue}{\frac{{\left(x \cdot x\right)}^{3} + {1}^{3}}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)}}}\]
    4. Applied associate-/r/0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -38320489792.49410247802734375 \lor \neg \left(x \le 373.9008368767135266352852340787649154663\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}} - \frac{1}{{x}^{3}}, \frac{1}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(1 \cdot 1, 1, {x}^{6}\right)} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019354 +o rules:numerics
(FPCore (x)
  :name "x / (x^2 + 1)"
  :precision binary64

  :herbie-target
  (/ 1 (+ x (/ 1 x)))

  (/ x (+ (* x x) 1)))