Average Error: 15.2 → 0.0
Time: 1.9s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.22741385849907756 \cdot 10^{28} \lor \neg \left(x \le 747.668589388476107\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 -4.22741385849907756 \cdot 10^{28} \lor \neg \left(x \le 747.668589388476107\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 r51940 = x;
        double r51941 = r51940 * r51940;
        double r51942 = 1.0;
        double r51943 = r51941 + r51942;
        double r51944 = r51940 / r51943;
        return r51944;
}

double f(double x) {
        double r51945 = x;
        double r51946 = -4.227413858499078e+28;
        bool r51947 = r51945 <= r51946;
        double r51948 = 747.6685893884761;
        bool r51949 = r51945 <= r51948;
        double r51950 = !r51949;
        bool r51951 = r51947 || r51950;
        double r51952 = 1.0;
        double r51953 = 1.0;
        double r51954 = 5.0;
        double r51955 = pow(r51945, r51954);
        double r51956 = r51953 / r51955;
        double r51957 = r51953 / r51945;
        double r51958 = 3.0;
        double r51959 = pow(r51945, r51958);
        double r51960 = r51953 / r51959;
        double r51961 = r51952 * r51960;
        double r51962 = r51957 - r51961;
        double r51963 = fma(r51952, r51956, r51962);
        double r51964 = r51945 * r51945;
        double r51965 = r51964 + r51952;
        double r51966 = r51945 / r51965;
        double r51967 = r51951 ? r51963 : r51966;
        return r51967;
}

Error

Bits error versus x

Target

Original15.2
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -4.227413858499078e+28 or 747.6685893884761 < x

    1. Initial program 31.3

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt31.3

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied associate-/r*31.2

      \[\leadsto \color{blue}{\frac{\frac{x}{\sqrt{x \cdot x + 1}}}{\sqrt{x \cdot x + 1}}}\]
    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 -4.227413858499078e+28 < x < 747.6685893884761

    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 -4.22741385849907756 \cdot 10^{28} \lor \neg \left(x \le 747.668589388476107\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 2020025 +o rules:numerics
(FPCore (x)
  :name "x / (x^2 + 1)"
  :precision binary64

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

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