Average Error: 9.8 → 0.3
Time: 2.9m
Precision: 64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -111.1378599360788115291143185459077358246:\\ \;\;\;\;2 \cdot \frac{1}{{x}^{7}} + \left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 144.7677165249174038308410672470927238464:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{{x}^{7}} + \left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{5}}\right)\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -111.1378599360788115291143185459077358246:\\
\;\;\;\;2 \cdot \frac{1}{{x}^{7}} + \left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{5}}\right)\\

\mathbf{elif}\;x \le 144.7677165249174038308410672470927238464:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\\

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

\end{array}
double f(double x) {
        double r23207997 = 1.0;
        double r23207998 = x;
        double r23207999 = r23207998 + r23207997;
        double r23208000 = r23207997 / r23207999;
        double r23208001 = 2.0;
        double r23208002 = r23208001 / r23207998;
        double r23208003 = r23208000 - r23208002;
        double r23208004 = r23207998 - r23207997;
        double r23208005 = r23207997 / r23208004;
        double r23208006 = r23208003 + r23208005;
        return r23208006;
}

double f(double x) {
        double r23208007 = x;
        double r23208008 = -111.13785993607881;
        bool r23208009 = r23208007 <= r23208008;
        double r23208010 = 2.0;
        double r23208011 = 1.0;
        double r23208012 = 7.0;
        double r23208013 = pow(r23208007, r23208012);
        double r23208014 = r23208011 / r23208013;
        double r23208015 = r23208010 * r23208014;
        double r23208016 = 3.0;
        double r23208017 = pow(r23208007, r23208016);
        double r23208018 = r23208011 / r23208017;
        double r23208019 = r23208010 * r23208018;
        double r23208020 = 5.0;
        double r23208021 = pow(r23208007, r23208020);
        double r23208022 = r23208011 / r23208021;
        double r23208023 = r23208010 * r23208022;
        double r23208024 = r23208019 + r23208023;
        double r23208025 = r23208015 + r23208024;
        double r23208026 = 144.7677165249174;
        bool r23208027 = r23208007 <= r23208026;
        double r23208028 = 1.0;
        double r23208029 = r23208007 + r23208028;
        double r23208030 = r23208028 / r23208029;
        double r23208031 = r23208011 / r23208007;
        double r23208032 = r23208031 * r23208010;
        double r23208033 = -r23208032;
        double r23208034 = fma(r23208011, r23208030, r23208033);
        double r23208035 = -r23208031;
        double r23208036 = fma(r23208035, r23208010, r23208032);
        double r23208037 = r23208007 - r23208028;
        double r23208038 = r23208028 / r23208037;
        double r23208039 = r23208036 + r23208038;
        double r23208040 = r23208034 + r23208039;
        double r23208041 = r23208027 ? r23208040 : r23208025;
        double r23208042 = r23208009 ? r23208025 : r23208041;
        return r23208042;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -111.13785993607881 or 144.7677165249174 < x

    1. Initial program 19.5

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied div-inv19.5

      \[\leadsto \left(\frac{1}{x + 1} - \color{blue}{2 \cdot \frac{1}{x}}\right) + \frac{1}{x - 1}\]
    4. Applied *-un-lft-identity19.5

      \[\leadsto \left(\color{blue}{1 \cdot \frac{1}{x + 1}} - 2 \cdot \frac{1}{x}\right) + \frac{1}{x - 1}\]
    5. Applied prod-diff19.5

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right)\right)} + \frac{1}{x - 1}\]
    6. Applied associate-+l+19.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)}\]
    7. Using strategy rm
    8. Applied add-cbrt-cube19.5

      \[\leadsto \color{blue}{\sqrt[3]{\left(\left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\right) \cdot \left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\right)\right) \cdot \left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\right)}}\]
    9. Simplified19.5

      \[\leadsto \sqrt[3]{\color{blue}{\left(\left(\frac{1}{x - 1} + \left(\left(-\frac{2}{x}\right) + \frac{2}{x}\right)\right) + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right) \cdot \left(\left(\left(\frac{1}{x - 1} + \left(\left(-\frac{2}{x}\right) + \frac{2}{x}\right)\right) + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right) \cdot \left(\left(\frac{1}{x - 1} + \left(\left(-\frac{2}{x}\right) + \frac{2}{x}\right)\right) + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\right)\right)}}\]
    10. Taylor expanded around inf 0.5

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

    if -111.13785993607881 < x < 144.7677165249174

    1. Initial program 0.1

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied div-inv0.1

      \[\leadsto \left(\frac{1}{x + 1} - \color{blue}{2 \cdot \frac{1}{x}}\right) + \frac{1}{x - 1}\]
    4. Applied *-un-lft-identity0.1

      \[\leadsto \left(\color{blue}{1 \cdot \frac{1}{x + 1}} - 2 \cdot \frac{1}{x}\right) + \frac{1}{x - 1}\]
    5. Applied prod-diff0.1

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right)\right)} + \frac{1}{x - 1}\]
    6. Applied associate-+l+0.1

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

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

Reproduce

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

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))