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

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

\end{array}
double f(double x) {
        double r70954 = x;
        double r70955 = r70954 * r70954;
        double r70956 = 1.0;
        double r70957 = r70955 + r70956;
        double r70958 = r70954 / r70957;
        return r70958;
}

double f(double x) {
        double r70959 = x;
        double r70960 = -3.030132556445137e+19;
        bool r70961 = r70959 <= r70960;
        double r70962 = 447.21006186250656;
        bool r70963 = r70959 <= r70962;
        double r70964 = !r70963;
        bool r70965 = r70961 || r70964;
        double r70966 = 1.0;
        double r70967 = 1.0;
        double r70968 = 5.0;
        double r70969 = pow(r70959, r70968);
        double r70970 = r70967 / r70969;
        double r70971 = r70967 / r70959;
        double r70972 = 3.0;
        double r70973 = pow(r70959, r70972);
        double r70974 = r70967 / r70973;
        double r70975 = r70966 * r70974;
        double r70976 = r70971 - r70975;
        double r70977 = fma(r70966, r70970, r70976);
        double r70978 = r70966 * r70966;
        double r70979 = 6.0;
        double r70980 = pow(r70959, r70979);
        double r70981 = fma(r70978, r70966, r70980);
        double r70982 = r70959 / r70981;
        double r70983 = r70959 * r70959;
        double r70984 = r70983 * r70983;
        double r70985 = r70983 * r70966;
        double r70986 = r70978 - r70985;
        double r70987 = r70984 + r70986;
        double r70988 = r70982 * r70987;
        double r70989 = r70965 ? r70977 : r70988;
        return r70989;
}

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 < -3.030132556445137e+19 or 447.21006186250656 < x

    1. Initial program 31.5

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

      \[\leadsto \frac{x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}\]
    4. Applied *-un-lft-identity31.5

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac31.4

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
    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}{\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)}\]

    if -3.030132556445137e+19 < x < 447.21006186250656

    1. Initial program 0.0

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

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

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

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

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

Reproduce

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

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

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