Average Error: 9.4 → 0.2
Time: 9.6s
Precision: 64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -111.0202622422814613400987582281231880188:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{\frac{2}{x}}{x \cdot x}\right)\right)\\ \mathbf{elif}\;x \le 109.8975046823589565292422776110470294952:\\ \;\;\;\;1 \cdot \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -111.0202622422814613400987582281231880188:\\
\;\;\;\;1 \cdot \mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{\frac{2}{x}}{x \cdot x}\right)\right)\\

\mathbf{elif}\;x \le 109.8975046823589565292422776110470294952:\\
\;\;\;\;1 \cdot \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)\\

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

\end{array}
double f(double x) {
        double r154018 = 1.0;
        double r154019 = x;
        double r154020 = r154019 + r154018;
        double r154021 = r154018 / r154020;
        double r154022 = 2.0;
        double r154023 = r154022 / r154019;
        double r154024 = r154021 - r154023;
        double r154025 = r154019 - r154018;
        double r154026 = r154018 / r154025;
        double r154027 = r154024 + r154026;
        return r154027;
}

double f(double x) {
        double r154028 = x;
        double r154029 = -111.02026224228146;
        bool r154030 = r154028 <= r154029;
        double r154031 = 1.0;
        double r154032 = 2.0;
        double r154033 = 7.0;
        double r154034 = pow(r154028, r154033);
        double r154035 = r154031 / r154034;
        double r154036 = 5.0;
        double r154037 = pow(r154028, r154036);
        double r154038 = r154031 / r154037;
        double r154039 = r154032 / r154028;
        double r154040 = r154028 * r154028;
        double r154041 = r154039 / r154040;
        double r154042 = fma(r154032, r154038, r154041);
        double r154043 = fma(r154032, r154035, r154042);
        double r154044 = r154031 * r154043;
        double r154045 = 109.89750468235896;
        bool r154046 = r154028 <= r154045;
        double r154047 = 1.0;
        double r154048 = r154028 + r154047;
        double r154049 = r154047 / r154048;
        double r154050 = r154049 - r154039;
        double r154051 = r154028 - r154047;
        double r154052 = r154047 / r154051;
        double r154053 = r154050 + r154052;
        double r154054 = r154031 * r154053;
        double r154055 = 3.0;
        double r154056 = pow(r154028, r154055);
        double r154057 = r154032 / r154056;
        double r154058 = fma(r154032, r154038, r154057);
        double r154059 = fma(r154032, r154035, r154058);
        double r154060 = r154031 * r154059;
        double r154061 = r154046 ? r154054 : r154060;
        double r154062 = r154030 ? r154044 : r154061;
        return r154062;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -111.02026224228146

    1. Initial program 18.3

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-exp-log18.9

      \[\leadsto \color{blue}{e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity18.9

      \[\leadsto e^{\log \color{blue}{\left(1 \cdot \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)\right)}}\]
    6. Applied log-prod18.9

      \[\leadsto e^{\color{blue}{\log 1 + \log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    7. Applied exp-sum18.9

      \[\leadsto \color{blue}{e^{\log 1} \cdot e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    8. Simplified18.9

      \[\leadsto \color{blue}{1} \cdot e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}\]
    9. Simplified18.3

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

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

      \[\leadsto 1 \cdot \color{blue}{\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)}\]
    12. Using strategy rm
    13. Applied cube-mult0.5

      \[\leadsto 1 \cdot \mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{\color{blue}{x \cdot \left(x \cdot x\right)}}\right)\right)\]
    14. Applied associate-/r*0.1

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

    if -111.02026224228146 < x < 109.89750468235896

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-exp-log35.6

      \[\leadsto \color{blue}{e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity35.6

      \[\leadsto e^{\log \color{blue}{\left(1 \cdot \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)\right)}}\]
    6. Applied log-prod35.6

      \[\leadsto e^{\color{blue}{\log 1 + \log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    7. Applied exp-sum35.6

      \[\leadsto \color{blue}{e^{\log 1} \cdot e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    8. Simplified35.6

      \[\leadsto \color{blue}{1} \cdot e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}\]
    9. Simplified0.0

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

    if 109.89750468235896 < x

    1. Initial program 19.4

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-exp-log19.4

      \[\leadsto \color{blue}{e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity19.4

      \[\leadsto e^{\log \color{blue}{\left(1 \cdot \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)\right)}}\]
    6. Applied log-prod19.4

      \[\leadsto e^{\color{blue}{\log 1 + \log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    7. Applied exp-sum19.4

      \[\leadsto \color{blue}{e^{\log 1} \cdot e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}}\]
    8. Simplified19.4

      \[\leadsto \color{blue}{1} \cdot e^{\log \left(\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\right)}\]
    9. Simplified19.4

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

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

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

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

Reproduce

herbie shell --seed 2019353 +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))))