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

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

\end{array}
double f(double x) {
        double r77767 = x;
        double r77768 = r77767 * r77767;
        double r77769 = 1.0;
        double r77770 = r77768 + r77769;
        double r77771 = r77767 / r77770;
        return r77771;
}

double f(double x) {
        double r77772 = x;
        double r77773 = -96697665796.78874;
        bool r77774 = r77772 <= r77773;
        double r77775 = 466.87594167061314;
        bool r77776 = r77772 <= r77775;
        double r77777 = !r77776;
        bool r77778 = r77774 || r77777;
        double r77779 = 1.0;
        double r77780 = r77779 / r77772;
        double r77781 = 1.0;
        double r77782 = 5.0;
        double r77783 = pow(r77772, r77782);
        double r77784 = r77781 / r77783;
        double r77785 = 3.0;
        double r77786 = pow(r77772, r77785);
        double r77787 = r77781 / r77786;
        double r77788 = r77784 - r77787;
        double r77789 = r77780 + r77788;
        double r77790 = -r77781;
        double r77791 = 4.0;
        double r77792 = pow(r77772, r77791);
        double r77793 = fma(r77790, r77781, r77792);
        double r77794 = r77772 / r77793;
        double r77795 = r77772 * r77772;
        double r77796 = r77795 - r77781;
        double r77797 = r77794 * r77796;
        double r77798 = r77778 ? r77789 : r77797;
        return r77798;
}

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 < -96697665796.78874 or 466.87594167061314 < x

    1. Initial program 30.2

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

      \[\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/48.6

      \[\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)}\]
    5. Simplified48.6

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)}} \cdot \left(x \cdot x - 1\right)\]
    6. 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}}}\]
    7. Simplified0.0

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

    if -96697665796.78874 < x < 466.87594167061314

    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)}\]
    5. Simplified0.0

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

Reproduce

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

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

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