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

\mathbf{else}:\\
\;\;\;\;\frac{x}{x \cdot x + 1}\\

\end{array}
double f(double x) {
        double r62922 = x;
        double r62923 = r62922 * r62922;
        double r62924 = 1.0;
        double r62925 = r62923 + r62924;
        double r62926 = r62922 / r62925;
        return r62926;
}

double f(double x) {
        double r62927 = x;
        double r62928 = -1.2413175172469135e+31;
        bool r62929 = r62927 <= r62928;
        double r62930 = 447.85106598207193;
        bool r62931 = r62927 <= r62930;
        double r62932 = !r62931;
        bool r62933 = r62929 || r62932;
        double r62934 = 1.0;
        double r62935 = 1.0;
        double r62936 = 5.0;
        double r62937 = pow(r62927, r62936);
        double r62938 = r62935 / r62937;
        double r62939 = 3.0;
        double r62940 = pow(r62927, r62939);
        double r62941 = r62935 / r62940;
        double r62942 = r62938 - r62941;
        double r62943 = r62935 / r62927;
        double r62944 = fma(r62934, r62942, r62943);
        double r62945 = r62927 * r62927;
        double r62946 = r62945 + r62934;
        double r62947 = r62927 / r62946;
        double r62948 = r62933 ? r62944 : r62947;
        return r62948;
}

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 < -1.2413175172469135e+31 or 447.85106598207193 < x

    1. Initial program 32.0

      \[\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 -1.2413175172469135e+31 < x < 447.85106598207193

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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

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

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