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 r62862 = x;
        double r62863 = r62862 * r62862;
        double r62864 = 1.0;
        double r62865 = r62863 + r62864;
        double r62866 = r62862 / r62865;
        return r62866;
}

double f(double x) {
        double r62867 = x;
        double r62868 = -1.2413175172469135e+31;
        bool r62869 = r62867 <= r62868;
        double r62870 = 447.85106598207193;
        bool r62871 = r62867 <= r62870;
        double r62872 = !r62871;
        bool r62873 = r62869 || r62872;
        double r62874 = 1.0;
        double r62875 = 1.0;
        double r62876 = 5.0;
        double r62877 = pow(r62867, r62876);
        double r62878 = r62875 / r62877;
        double r62879 = 3.0;
        double r62880 = pow(r62867, r62879);
        double r62881 = r62875 / r62880;
        double r62882 = r62878 - r62881;
        double r62883 = r62875 / r62867;
        double r62884 = fma(r62874, r62882, r62883);
        double r62885 = r62867 * r62867;
        double r62886 = r62885 + r62874;
        double r62887 = r62867 / r62886;
        double r62888 = r62873 ? r62884 : r62887;
        return r62888;
}

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)))