Average Error: 14.8 → 0.0
Time: 2.8s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0335386412362911 \cdot 10^{25} \lor \neg \left(x \le 23741.194574337824\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{1}{\mathsf{fma}\left(x, x, 1\right)}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.0335386412362911 \cdot 10^{25} \lor \neg \left(x \le 23741.194574337824\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\\

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

\end{array}
double f(double x) {
        double r82215 = x;
        double r82216 = r82215 * r82215;
        double r82217 = 1.0;
        double r82218 = r82216 + r82217;
        double r82219 = r82215 / r82218;
        return r82219;
}

double f(double x) {
        double r82220 = x;
        double r82221 = -1.033538641236291e+25;
        bool r82222 = r82220 <= r82221;
        double r82223 = 23741.194574337824;
        bool r82224 = r82220 <= r82223;
        double r82225 = !r82224;
        bool r82226 = r82222 || r82225;
        double r82227 = 1.0;
        double r82228 = 1.0;
        double r82229 = 5.0;
        double r82230 = pow(r82220, r82229);
        double r82231 = r82228 / r82230;
        double r82232 = r82228 / r82220;
        double r82233 = 3.0;
        double r82234 = pow(r82220, r82233);
        double r82235 = r82228 / r82234;
        double r82236 = r82227 * r82235;
        double r82237 = r82232 - r82236;
        double r82238 = fma(r82227, r82231, r82237);
        double r82239 = fma(r82220, r82220, r82227);
        double r82240 = r82228 / r82239;
        double r82241 = r82220 * r82240;
        double r82242 = r82226 ? r82238 : r82241;
        return r82242;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -1.033538641236291e+25 or 23741.194574337824 < x

    1. Initial program 31.3

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied div-inv31.4

      \[\leadsto \color{blue}{x \cdot \frac{1}{x \cdot x + 1}}\]
    4. Simplified31.4

      \[\leadsto x \cdot \color{blue}{\frac{1}{\mathsf{fma}\left(x, x, 1\right)}}\]
    5. 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}}}\]
    6. Simplified0.0

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

    if -1.033538641236291e+25 < x < 23741.194574337824

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied div-inv0.0

      \[\leadsto \color{blue}{x \cdot \frac{1}{x \cdot x + 1}}\]
    4. Simplified0.0

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

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

Reproduce

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

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

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