Average Error: 14.9 → 0.2
Time: 8.8s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0108746280769982 \lor \neg \left(x \le 1.0073267373299459\right):\\ \;\;\;\;\left(\frac{1}{x} - \frac{1}{{x}^{3}}\right) + \frac{1}{{x}^{5}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\left(x + {x}^{5}\right) - {x}^{3}\right)\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.0108746280769982 \lor \neg \left(x \le 1.0073267373299459\right):\\
\;\;\;\;\left(\frac{1}{x} - \frac{1}{{x}^{3}}\right) + \frac{1}{{x}^{5}}\\

\mathbf{else}:\\
\;\;\;\;1 \cdot \left(\left(x + {x}^{5}\right) - {x}^{3}\right)\\

\end{array}
double f(double x) {
        double r57577 = x;
        double r57578 = r57577 * r57577;
        double r57579 = 1.0;
        double r57580 = r57578 + r57579;
        double r57581 = r57577 / r57580;
        return r57581;
}

double f(double x) {
        double r57582 = x;
        double r57583 = -1.0108746280769982;
        bool r57584 = r57582 <= r57583;
        double r57585 = 1.007326737329946;
        bool r57586 = r57582 <= r57585;
        double r57587 = !r57586;
        bool r57588 = r57584 || r57587;
        double r57589 = 1.0;
        double r57590 = r57589 / r57582;
        double r57591 = 1.0;
        double r57592 = 3.0;
        double r57593 = pow(r57582, r57592);
        double r57594 = r57591 / r57593;
        double r57595 = r57590 - r57594;
        double r57596 = 5.0;
        double r57597 = pow(r57582, r57596);
        double r57598 = r57591 / r57597;
        double r57599 = r57595 + r57598;
        double r57600 = r57582 + r57597;
        double r57601 = r57600 - r57593;
        double r57602 = r57591 * r57601;
        double r57603 = r57588 ? r57599 : r57602;
        return r57603;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.9
Target0.1
Herbie0.2
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -1.0108746280769982 or 1.007326737329946 < x

    1. Initial program 29.3

      \[\frac{x}{x \cdot x + 1}\]
    2. Taylor expanded around inf 0.2

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

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

    if -1.0108746280769982 < x < 1.007326737329946

    1. Initial program 0.0

      \[\frac{x}{x \cdot x + 1}\]
    2. Taylor expanded around 0 0.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.0108746280769982 \lor \neg \left(x \le 1.0073267373299459\right):\\ \;\;\;\;\left(\frac{1}{x} - \frac{1}{{x}^{3}}\right) + \frac{1}{{x}^{5}}\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\left(x + {x}^{5}\right) - {x}^{3}\right)\\ \end{array}\]

Reproduce

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

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

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