Average Error: 14.9 → 0.0
Time: 39.7s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.1506420898789893 \cdot 10^{+18}:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \mathbf{elif}\;x \le 406.4066931201251:\\ \;\;\;\;\frac{x}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1} \cdot \left(x \cdot x - 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \end{array}\]
double f(double x) {
        double r3764738 = x;
        double r3764739 = r3764738 * r3764738;
        double r3764740 = 1.0;
        double r3764741 = r3764739 + r3764740;
        double r3764742 = r3764738 / r3764741;
        return r3764742;
}

double f(double x) {
        double r3764743 = x;
        double r3764744 = -2.1506420898789893e+18;
        bool r3764745 = r3764743 <= r3764744;
        double r3764746 = 1.0;
        double r3764747 = 5.0;
        double r3764748 = pow(r3764743, r3764747);
        double r3764749 = r3764746 / r3764748;
        double r3764750 = r3764746 / r3764743;
        double r3764751 = r3764749 + r3764750;
        double r3764752 = r3764743 * r3764743;
        double r3764753 = r3764752 * r3764743;
        double r3764754 = r3764746 / r3764753;
        double r3764755 = r3764751 - r3764754;
        double r3764756 = 406.4066931201251;
        bool r3764757 = r3764743 <= r3764756;
        double r3764758 = r3764752 * r3764752;
        double r3764759 = r3764758 - r3764746;
        double r3764760 = r3764743 / r3764759;
        double r3764761 = r3764752 - r3764746;
        double r3764762 = r3764760 * r3764761;
        double r3764763 = r3764757 ? r3764762 : r3764755;
        double r3764764 = r3764745 ? r3764755 : r3764763;
        return r3764764;
}

\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -2.1506420898789893 \cdot 10^{+18}:\\
\;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\

\mathbf{elif}\;x \le 406.4066931201251:\\
\;\;\;\;\frac{x}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1} \cdot \left(x \cdot x - 1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\

\end{array}

Error

Bits error versus x

Target

Original14.9
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -2.1506420898789893e+18 or 406.4066931201251 < x

    1. Initial program 30.6

      \[\frac{x}{x \cdot x + 1}\]
    2. Taylor expanded around -inf 0.0

      \[\leadsto \color{blue}{\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{{x}^{3}}}\]
    3. Simplified0.0

      \[\leadsto \color{blue}{\left(\frac{1}{x} + \frac{1}{{x}^{5}}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}}\]

    if -2.1506420898789893e+18 < x < 406.4066931201251

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Using strategy rm
    3. Applied flip-+0.0

      \[\leadsto \frac{x}{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1 \cdot 1}{x \cdot x - 1}}}\]
    4. Applied associate-/r/0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.1506420898789893 \cdot 10^{+18}:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \mathbf{elif}\;x \le 406.4066931201251:\\ \;\;\;\;\frac{x}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - 1} \cdot \left(x \cdot x - 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019102 
(FPCore (x)
  :name "x / (x^2 + 1)"

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

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