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

\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(x, x, 1\right)}\\

\end{array}
double f(double x) {
        double r64968 = x;
        double r64969 = r64968 * r64968;
        double r64970 = 1.0;
        double r64971 = r64969 + r64970;
        double r64972 = r64968 / r64971;
        return r64972;
}

double f(double x) {
        double r64973 = x;
        double r64974 = -24215928678.961597;
        bool r64975 = r64973 <= r64974;
        double r64976 = 3500.8467687195057;
        bool r64977 = r64973 <= r64976;
        double r64978 = !r64977;
        bool r64979 = r64975 || r64978;
        double r64980 = 1.0;
        double r64981 = 1.0;
        double r64982 = 5.0;
        double r64983 = pow(r64973, r64982);
        double r64984 = r64981 / r64983;
        double r64985 = 3.0;
        double r64986 = pow(r64973, r64985);
        double r64987 = r64981 / r64986;
        double r64988 = r64984 - r64987;
        double r64989 = r64981 / r64973;
        double r64990 = fma(r64980, r64988, r64989);
        double r64991 = fma(r64973, r64973, r64980);
        double r64992 = r64973 / r64991;
        double r64993 = r64979 ? r64990 : r64992;
        return r64993;
}

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 < -24215928678.961597 or 3500.8467687195057 < x

    1. Initial program 30.8

      \[\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 -24215928678.961597 < x < 3500.8467687195057

    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 associate-/r*0.0

      \[\leadsto \color{blue}{\frac{\frac{x}{\sqrt{x \cdot x + 1}}}{\sqrt{x \cdot x + 1}}}\]
    5. Using strategy rm
    6. Applied div-inv0.0

      \[\leadsto \frac{\color{blue}{x \cdot \frac{1}{\sqrt{x \cdot x + 1}}}}{\sqrt{x \cdot x + 1}}\]
    7. Applied associate-/l*0.0

      \[\leadsto \color{blue}{\frac{x}{\frac{\sqrt{x \cdot x + 1}}{\frac{1}{\sqrt{x \cdot x + 1}}}}}\]
    8. Simplified0.0

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

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

Reproduce

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

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

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