Average Error: 15.3 → 0.0
Time: 3.5s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.01915671757898777 \cdot 10^{31} \lor \neg \left(x \le 7097.135133098112\right):\\ \;\;\;\;{\left(\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\frac{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{3}\right)}{\sqrt{\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)}}}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.01915671757898777 \cdot 10^{31} \lor \neg \left(x \le 7097.135133098112\right):\\
\;\;\;\;{\left(\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\right)}^{1}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\frac{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{3}\right)}{\sqrt{\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)}}}\\

\end{array}
double f(double x) {
        double r89346 = x;
        double r89347 = r89346 * r89346;
        double r89348 = 1.0;
        double r89349 = r89347 + r89348;
        double r89350 = r89346 / r89349;
        return r89350;
}

double f(double x) {
        double r89351 = x;
        double r89352 = -1.0191567175789878e+31;
        bool r89353 = r89351 <= r89352;
        double r89354 = 7097.135133098112;
        bool r89355 = r89351 <= r89354;
        double r89356 = !r89355;
        bool r89357 = r89353 || r89356;
        double r89358 = 1.0;
        double r89359 = 1.0;
        double r89360 = 5.0;
        double r89361 = pow(r89351, r89360);
        double r89362 = r89359 / r89361;
        double r89363 = r89359 / r89351;
        double r89364 = 3.0;
        double r89365 = pow(r89351, r89364);
        double r89366 = r89359 / r89365;
        double r89367 = r89358 * r89366;
        double r89368 = r89363 - r89367;
        double r89369 = fma(r89358, r89362, r89368);
        double r89370 = pow(r89369, r89359);
        double r89371 = r89351 * r89351;
        double r89372 = r89371 + r89358;
        double r89373 = sqrt(r89372);
        double r89374 = r89359 / r89373;
        double r89375 = 1.5;
        double r89376 = pow(r89358, r89375);
        double r89377 = hypot(r89376, r89365);
        double r89378 = r89371 * r89371;
        double r89379 = r89358 * r89358;
        double r89380 = r89371 * r89358;
        double r89381 = r89379 - r89380;
        double r89382 = r89378 + r89381;
        double r89383 = sqrt(r89382);
        double r89384 = r89377 / r89383;
        double r89385 = r89351 / r89384;
        double r89386 = r89374 * r89385;
        double r89387 = r89357 ? r89370 : r89386;
        return r89387;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -1.0191567175789878e+31 or 7097.135133098112 < x

    1. Initial program 32.4

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt32.4

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied *-un-lft-identity32.4

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac32.3

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
    6. Using strategy rm
    7. Applied pow132.3

      \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}\right)}^{1}}\]
    8. Taylor expanded around inf 0.0

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

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

    if -1.0191567175789878e+31 < x < 7097.135133098112

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.0

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied *-un-lft-identity0.0

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac0.0

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
    6. Using strategy rm
    7. Applied flip3-+0.0

      \[\leadsto \frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{\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)}}}}\]
    8. Applied sqrt-div0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.01915671757898777 \cdot 10^{31} \lor \neg \left(x \le 7097.135133098112\right):\\ \;\;\;\;{\left(\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\right)}^{1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\frac{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{3}\right)}{\sqrt{\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)}}}\\ \end{array}\]

Reproduce

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

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

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