Average Error: 15.3 → 0.0
Time: 1.0m
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -59804148335181976.0:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \mathbf{elif}\;x \le 12790649.36660592:\\ \;\;\;\;\frac{x}{(x \cdot x + 1)_*}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -59804148335181976.0:\\
\;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\

\mathbf{elif}\;x \le 12790649.36660592:\\
\;\;\;\;\frac{x}{(x \cdot x + 1)_*}\\

\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 r4397251 = x;
        double r4397252 = r4397251 * r4397251;
        double r4397253 = 1.0;
        double r4397254 = r4397252 + r4397253;
        double r4397255 = r4397251 / r4397254;
        return r4397255;
}

double f(double x) {
        double r4397256 = x;
        double r4397257 = -59804148335181976.0;
        bool r4397258 = r4397256 <= r4397257;
        double r4397259 = 1.0;
        double r4397260 = 5.0;
        double r4397261 = pow(r4397256, r4397260);
        double r4397262 = r4397259 / r4397261;
        double r4397263 = r4397259 / r4397256;
        double r4397264 = r4397262 + r4397263;
        double r4397265 = r4397256 * r4397256;
        double r4397266 = r4397265 * r4397256;
        double r4397267 = r4397259 / r4397266;
        double r4397268 = r4397264 - r4397267;
        double r4397269 = 12790649.36660592;
        bool r4397270 = r4397256 <= r4397269;
        double r4397271 = fma(r4397256, r4397256, r4397259);
        double r4397272 = r4397256 / r4397271;
        double r4397273 = r4397270 ? r4397272 : r4397268;
        double r4397274 = r4397258 ? r4397268 : r4397273;
        return r4397274;
}

Error

Bits error versus x

Target

Original15.3
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -59804148335181976.0 or 12790649.36660592 < x

    1. Initial program 31.6

      \[\frac{x}{x \cdot x + 1}\]
    2. Simplified31.6

      \[\leadsto \color{blue}{\frac{x}{(x \cdot x + 1)_*}}\]
    3. Taylor expanded around -inf 0.0

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

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

    if -59804148335181976.0 < x < 12790649.36660592

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -59804148335181976.0:\\ \;\;\;\;\left(\frac{1}{{x}^{5}} + \frac{1}{x}\right) - \frac{1}{\left(x \cdot x\right) \cdot x}\\ \mathbf{elif}\;x \le 12790649.36660592:\\ \;\;\;\;\frac{x}{(x \cdot x + 1)_*}\\ \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 2019119 +o rules:numerics
(FPCore (x)
  :name "x / (x^2 + 1)"

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

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