Average Error: 15.1 → 0.0
Time: 2.0s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.72333196099679316 \cdot 10^{30} \lor \neg \left(x \le 450.713600203325484\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 -7.72333196099679316 \cdot 10^{30} \lor \neg \left(x \le 450.713600203325484\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 r53051 = x;
        double r53052 = r53051 * r53051;
        double r53053 = 1.0;
        double r53054 = r53052 + r53053;
        double r53055 = r53051 / r53054;
        return r53055;
}

double f(double x) {
        double r53056 = x;
        double r53057 = -7.723331960996793e+30;
        bool r53058 = r53056 <= r53057;
        double r53059 = 450.7136002033255;
        bool r53060 = r53056 <= r53059;
        double r53061 = !r53060;
        bool r53062 = r53058 || r53061;
        double r53063 = 1.0;
        double r53064 = 1.0;
        double r53065 = 5.0;
        double r53066 = pow(r53056, r53065);
        double r53067 = r53064 / r53066;
        double r53068 = 3.0;
        double r53069 = pow(r53056, r53068);
        double r53070 = r53064 / r53069;
        double r53071 = r53067 - r53070;
        double r53072 = r53064 / r53056;
        double r53073 = fma(r53063, r53071, r53072);
        double r53074 = r53056 * r53056;
        double r53075 = r53074 + r53063;
        double r53076 = r53056 / r53075;
        double r53077 = r53062 ? r53073 : r53076;
        return r53077;
}

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 < -7.723331960996793e+30 or 450.7136002033255 < x

    1. Initial program 31.9

      \[\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 -7.723331960996793e+30 < x < 450.7136002033255

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

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

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