Average Error: 9.4 → 0.2
Time: 9.5s
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 r170421 = 1.0;
        double r170422 = x;
        double r170423 = r170422 + r170421;
        double r170424 = r170421 / r170423;
        double r170425 = 2.0;
        double r170426 = r170425 / r170422;
        double r170427 = r170424 - r170426;
        double r170428 = r170422 - r170421;
        double r170429 = r170421 / r170428;
        double r170430 = r170427 + r170429;
        return r170430;
}

double f(double x) {
        double r170431 = x;
        double r170432 = -111.02026224228146;
        bool r170433 = r170431 <= r170432;
        double r170434 = 1.0;
        double r170435 = 2.0;
        double r170436 = 7.0;
        double r170437 = pow(r170431, r170436);
        double r170438 = r170434 / r170437;
        double r170439 = 5.0;
        double r170440 = pow(r170431, r170439);
        double r170441 = r170434 / r170440;
        double r170442 = r170435 / r170431;
        double r170443 = r170431 * r170431;
        double r170444 = r170442 / r170443;
        double r170445 = fma(r170435, r170441, r170444);
        double r170446 = fma(r170435, r170438, r170445);
        double r170447 = r170434 * r170446;
        double r170448 = 109.89750468235896;
        bool r170449 = r170431 <= r170448;
        double r170450 = 1.0;
        double r170451 = r170431 + r170450;
        double r170452 = r170450 / r170451;
        double r170453 = r170452 - r170442;
        double r170454 = r170431 - r170450;
        double r170455 = r170450 / r170454;
        double r170456 = r170453 + r170455;
        double r170457 = r170434 * r170456;
        double r170458 = 3.0;
        double r170459 = pow(r170431, r170458);
        double r170460 = r170435 / r170459;
        double r170461 = fma(r170435, r170441, r170460);
        double r170462 = fma(r170435, r170438, r170461);
        double r170463 = r170434 * r170462;
        double r170464 = r170449 ? r170457 : r170463;
        double r170465 = r170433 ? r170447 : r170464;
        return r170465;
}

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))))