Average Error: 15.2 → 0.0
Time: 12.3s
Precision: 64
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.90036294001547 \cdot 10^{+25}:\\ \;\;\;\;\left(\frac{1}{x} - \frac{\frac{1}{x}}{x \cdot x}\right) + \frac{1}{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)}\\ \mathbf{elif}\;x \le 415.7689475654002:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(x, x, 1\right)} \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} - \frac{\frac{1}{x}}{x \cdot x}\right) + \frac{1}{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)}\\ \end{array}\]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -8.90036294001547 \cdot 10^{+25}:\\
\;\;\;\;\left(\frac{1}{x} - \frac{\frac{1}{x}}{x \cdot x}\right) + \frac{1}{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)}\\

\mathbf{elif}\;x \le 415.7689475654002:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, x, 1\right)} \cdot x\\

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

\end{array}
double f(double x) {
        double r1782542 = x;
        double r1782543 = r1782542 * r1782542;
        double r1782544 = 1.0;
        double r1782545 = r1782543 + r1782544;
        double r1782546 = r1782542 / r1782545;
        return r1782546;
}

double f(double x) {
        double r1782547 = x;
        double r1782548 = -8.90036294001547e+25;
        bool r1782549 = r1782547 <= r1782548;
        double r1782550 = 1.0;
        double r1782551 = r1782550 / r1782547;
        double r1782552 = r1782547 * r1782547;
        double r1782553 = r1782551 / r1782552;
        double r1782554 = r1782551 - r1782553;
        double r1782555 = r1782552 * r1782547;
        double r1782556 = r1782555 * r1782552;
        double r1782557 = r1782550 / r1782556;
        double r1782558 = r1782554 + r1782557;
        double r1782559 = 415.7689475654002;
        bool r1782560 = r1782547 <= r1782559;
        double r1782561 = fma(r1782547, r1782547, r1782550);
        double r1782562 = r1782550 / r1782561;
        double r1782563 = r1782562 * r1782547;
        double r1782564 = r1782560 ? r1782563 : r1782558;
        double r1782565 = r1782549 ? r1782558 : r1782564;
        return r1782565;
}

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 < -8.90036294001547e+25 or 415.7689475654002 < x

    1. Initial program 31.8

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

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(x, x, 1\right)}}\]
    3. Using strategy rm
    4. Applied div-inv31.8

      \[\leadsto \color{blue}{x \cdot \frac{1}{\mathsf{fma}\left(x, x, 1\right)}}\]
    5. Taylor expanded around inf 0.0

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

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

    if -8.90036294001547e+25 < x < 415.7689475654002

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{x}{\mathsf{fma}\left(x, x, 1\right)}}\]
    3. Using strategy rm
    4. Applied div-inv0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.90036294001547 \cdot 10^{+25}:\\ \;\;\;\;\left(\frac{1}{x} - \frac{\frac{1}{x}}{x \cdot x}\right) + \frac{1}{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)}\\ \mathbf{elif}\;x \le 415.7689475654002:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(x, x, 1\right)} \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{x} - \frac{\frac{1}{x}}{x \cdot x}\right) + \frac{1}{\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)}\\ \end{array}\]

Reproduce

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

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

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