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

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

\end{array}
double f(double x) {
        double r94846 = x;
        double r94847 = r94846 * r94846;
        double r94848 = 1.0;
        double r94849 = r94847 + r94848;
        double r94850 = r94846 / r94849;
        return r94850;
}

double f(double x) {
        double r94851 = x;
        double r94852 = -1049.3432188499771;
        bool r94853 = r94851 <= r94852;
        double r94854 = 462.8155035723357;
        bool r94855 = r94851 <= r94854;
        double r94856 = !r94855;
        bool r94857 = r94853 || r94856;
        double r94858 = 1.0;
        double r94859 = r94858 / r94851;
        double r94860 = 1.0;
        double r94861 = 5.0;
        double r94862 = pow(r94851, r94861);
        double r94863 = r94860 / r94862;
        double r94864 = 3.0;
        double r94865 = pow(r94851, r94864);
        double r94866 = r94860 / r94865;
        double r94867 = r94863 - r94866;
        double r94868 = r94859 + r94867;
        double r94869 = -r94860;
        double r94870 = 4.0;
        double r94871 = pow(r94851, r94870);
        double r94872 = fma(r94869, r94860, r94871);
        double r94873 = r94865 / r94872;
        double r94874 = r94851 / r94872;
        double r94875 = r94874 * r94869;
        double r94876 = r94873 + r94875;
        double r94877 = r94857 ? r94868 : r94876;
        return r94877;
}

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 < -1049.3432188499771 or 462.8155035723357 < x

    1. Initial program 30.7

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

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

      \[\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. Simplified47.8

      \[\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 -1049.3432188499771 < x < 462.8155035723357

    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)\]
    6. Using strategy rm
    7. Applied sub-neg0.0

      \[\leadsto \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \color{blue}{\left(x \cdot x + \left(-1\right)\right)}\]
    8. Applied distribute-lft-in0.0

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(x \cdot x\right) + \frac{x}{\mathsf{fma}\left(-1, 1, {x}^{4}\right)} \cdot \left(-1\right)}\]
    9. Simplified0.0

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

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

Reproduce

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

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

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