Average Error: 9.5 → 0.0
Time: 5.1s
Precision: 64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -110.3639962943735213229956571012735366821 \lor \neg \left(x \le 108.2804405523375663733531837351620197296\right):\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, 2 \cdot {x}^{\left(-3\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{2}{x}\right) + \frac{1}{x - 1}\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -110.3639962943735213229956571012735366821 \lor \neg \left(x \le 108.2804405523375663733531837351620197296\right):\\
\;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, 2 \cdot {x}^{\left(-3\right)}\right)\right)\\

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

\end{array}
double f(double x) {
        double r128548 = 1.0;
        double r128549 = x;
        double r128550 = r128549 + r128548;
        double r128551 = r128548 / r128550;
        double r128552 = 2.0;
        double r128553 = r128552 / r128549;
        double r128554 = r128551 - r128553;
        double r128555 = r128549 - r128548;
        double r128556 = r128548 / r128555;
        double r128557 = r128554 + r128556;
        return r128557;
}

double f(double x) {
        double r128558 = x;
        double r128559 = -110.36399629437352;
        bool r128560 = r128558 <= r128559;
        double r128561 = 108.28044055233757;
        bool r128562 = r128558 <= r128561;
        double r128563 = !r128562;
        bool r128564 = r128560 || r128563;
        double r128565 = 2.0;
        double r128566 = 1.0;
        double r128567 = 7.0;
        double r128568 = pow(r128558, r128567);
        double r128569 = r128566 / r128568;
        double r128570 = 5.0;
        double r128571 = pow(r128558, r128570);
        double r128572 = r128566 / r128571;
        double r128573 = 3.0;
        double r128574 = -r128573;
        double r128575 = pow(r128558, r128574);
        double r128576 = r128565 * r128575;
        double r128577 = fma(r128565, r128572, r128576);
        double r128578 = fma(r128565, r128569, r128577);
        double r128579 = 1.0;
        double r128580 = r128558 + r128579;
        double r128581 = r128579 / r128580;
        double r128582 = r128565 / r128558;
        double r128583 = -r128582;
        double r128584 = fma(r128566, r128581, r128583);
        double r128585 = r128558 - r128579;
        double r128586 = r128579 / r128585;
        double r128587 = r128584 + r128586;
        double r128588 = r128564 ? r128578 : r128587;
        return r128588;
}

Error

Bits error versus x

Target

Original9.5
Target0.3
Herbie0.0
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -110.36399629437352 or 108.28044055233757 < x

    1. Initial program 19.2

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity19.2

      \[\leadsto \left(\color{blue}{1 \cdot \frac{1}{x + 1}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    4. Applied fma-neg19.2

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, 2 \cdot \frac{1}{{x}^{3}}\right)\right)}\]
    7. Using strategy rm
    8. Applied pow-flip0.0

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

    if -110.36399629437352 < x < 108.28044055233757

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.0

      \[\leadsto \left(\color{blue}{1 \cdot \frac{1}{x + 1}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    4. Applied fma-neg0.0

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

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

Reproduce

herbie shell --seed 2019347 +o rules:numerics
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2 (* x (- (* x x) 1)))

  (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))))