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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot x + 1}} \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{x}{\sqrt{x \cdot x + 1}}\right)\right)\\

\end{array}
double f(double x) {
        double r76969 = x;
        double r76970 = r76969 * r76969;
        double r76971 = 1.0;
        double r76972 = r76970 + r76971;
        double r76973 = r76969 / r76972;
        return r76973;
}

double f(double x) {
        double r76974 = x;
        double r76975 = -449777.982748373;
        bool r76976 = r76974 <= r76975;
        double r76977 = 462.7532167774703;
        bool r76978 = r76974 <= r76977;
        double r76979 = !r76978;
        bool r76980 = r76976 || r76979;
        double r76981 = 1.0;
        double r76982 = 1.0;
        double r76983 = 5.0;
        double r76984 = pow(r76974, r76983);
        double r76985 = r76982 / r76984;
        double r76986 = 3.0;
        double r76987 = pow(r76974, r76986);
        double r76988 = r76982 / r76987;
        double r76989 = r76985 - r76988;
        double r76990 = r76982 / r76974;
        double r76991 = fma(r76981, r76989, r76990);
        double r76992 = r76974 * r76974;
        double r76993 = r76992 + r76981;
        double r76994 = sqrt(r76993);
        double r76995 = r76982 / r76994;
        double r76996 = r76974 / r76994;
        double r76997 = expm1(r76996);
        double r76998 = log1p(r76997);
        double r76999 = r76995 * r76998;
        double r77000 = r76980 ? r76991 : r76999;
        return r77000;
}

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 < -449777.982748373 or 462.7532167774703 < x

    1. Initial program 30.5

      \[\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 -449777.982748373 < x < 462.7532167774703

    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 log1p-expm1-u0.0

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

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

Reproduce

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

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

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