Average Error: 14.8 → 0.0
Time: 2.5s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.324933943149559 \cdot 10^{154} \lor \neg \left(x \le 7485940.54066098388\right):\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.324933943149559 \cdot 10^{154} \lor \neg \left(x \le 7485940.54066098388\right):\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}\\

\end{array}
double f(double x) {
        double r55168 = x;
        double r55169 = r55168 * r55168;
        double r55170 = 1.0;
        double r55171 = r55169 + r55170;
        double r55172 = r55168 / r55171;
        return r55172;
}

double f(double x) {
        double r55173 = x;
        double r55174 = -1.324933943149559e+154;
        bool r55175 = r55173 <= r55174;
        double r55176 = 7485940.540660984;
        bool r55177 = r55173 <= r55176;
        double r55178 = !r55177;
        bool r55179 = r55175 || r55178;
        double r55180 = 1.0;
        double r55181 = 1.0;
        double r55182 = 5.0;
        double r55183 = pow(r55173, r55182);
        double r55184 = r55181 / r55183;
        double r55185 = r55181 / r55173;
        double r55186 = 3.0;
        double r55187 = pow(r55173, r55186);
        double r55188 = r55181 / r55187;
        double r55189 = r55180 * r55188;
        double r55190 = r55185 - r55189;
        double r55191 = fma(r55180, r55184, r55190);
        double r55192 = r55173 * r55173;
        double r55193 = r55192 + r55180;
        double r55194 = sqrt(r55193);
        double r55195 = r55181 / r55194;
        double r55196 = r55173 / r55194;
        double r55197 = r55195 * r55196;
        double r55198 = r55179 ? r55191 : r55197;
        return r55198;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -1.324933943149559e+154 or 7485940.540660984 < x

    1. Initial program 40.5

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}\]
    5. Applied times-frac40.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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{{x}^{5}}, \frac{1}{x} - 1 \cdot \frac{1}{{x}^{3}}\right)}\]

    if -1.324933943149559e+154 < x < 7485940.540660984

    1. Initial program 0.1

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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

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

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