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

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

\end{array}
double f(double x) {
        double r74133 = x;
        double r74134 = r74133 * r74133;
        double r74135 = 1.0;
        double r74136 = r74134 + r74135;
        double r74137 = r74133 / r74136;
        return r74137;
}

double f(double x) {
        double r74138 = x;
        double r74139 = -2777649326.315958;
        bool r74140 = r74138 <= r74139;
        double r74141 = 50461.05920151082;
        bool r74142 = r74138 <= r74141;
        double r74143 = !r74142;
        bool r74144 = r74140 || r74143;
        double r74145 = 1.0;
        double r74146 = 1.0;
        double r74147 = 5.0;
        double r74148 = pow(r74138, r74147);
        double r74149 = r74146 / r74148;
        double r74150 = r74146 / r74138;
        double r74151 = 3.0;
        double r74152 = pow(r74138, r74151);
        double r74153 = r74146 / r74152;
        double r74154 = r74145 * r74153;
        double r74155 = r74150 - r74154;
        double r74156 = fma(r74145, r74149, r74155);
        double r74157 = r74138 * r74138;
        double r74158 = r74157 + r74145;
        double r74159 = r74138 / r74158;
        double r74160 = r74144 ? r74156 : r74159;
        return r74160;
}

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 < -2777649326.315958 or 50461.05920151082 < x

    1. Initial program 30.8

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

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

      \[\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 -2777649326.315958 < x < 50461.05920151082

    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 -2777649326.315958 \lor \neg \left(x \le 50461.0592015108195\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x \cdot x + 1}\\ \end{array}\]

Reproduce

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

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

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