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

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

\end{array}
double f(double x) {
        double r89709 = x;
        double r89710 = 1.0;
        double r89711 = r89709 + r89710;
        double r89712 = r89709 / r89711;
        double r89713 = r89709 - r89710;
        double r89714 = r89711 / r89713;
        double r89715 = r89712 - r89714;
        return r89715;
}

double f(double x) {
        double r89716 = x;
        double r89717 = -41855320.47834496;
        bool r89718 = r89716 <= r89717;
        double r89719 = 125882.07557923895;
        bool r89720 = r89716 <= r89719;
        double r89721 = !r89720;
        bool r89722 = r89718 || r89721;
        double r89723 = 1.0;
        double r89724 = 1.0;
        double r89725 = 2.0;
        double r89726 = pow(r89716, r89725);
        double r89727 = r89724 / r89726;
        double r89728 = 3.0;
        double r89729 = r89728 / r89716;
        double r89730 = fma(r89723, r89727, r89729);
        double r89731 = -r89730;
        double r89732 = 3.0;
        double r89733 = pow(r89716, r89732);
        double r89734 = r89728 / r89733;
        double r89735 = -r89734;
        double r89736 = r89731 + r89735;
        double r89737 = 2.0;
        double r89738 = r89728 * r89726;
        double r89739 = r89723 - r89738;
        double r89740 = fma(r89716, r89737, r89739);
        double r89741 = r89716 + r89723;
        double r89742 = r89737 * r89716;
        double r89743 = r89723 - r89742;
        double r89744 = fma(r89716, r89716, r89743);
        double r89745 = r89741 * r89744;
        double r89746 = r89740 / r89745;
        double r89747 = r89722 ? r89736 : r89746;
        return r89747;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -41855320.47834496 or 125882.07557923895 < x

    1. Initial program 59.6

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied div-inv59.8

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\left(x + 1\right) \cdot \frac{1}{x - 1}}\]
    4. Using strategy rm
    5. Applied flip-+61.9

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}} \cdot \frac{1}{x - 1}\]
    6. Applied frac-times61.9

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

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x \cdot \left(x - 1\right), \left(-\left(x + 1\right)\right) \cdot \left(x \cdot x - 1 \cdot 1\right)\right)}}{\left(x + 1\right) \cdot \left(\left(x - 1\right) \cdot \left(x - 1\right)\right)}\]
    9. Taylor expanded around 0 43.6

      \[\leadsto \frac{\color{blue}{\left(2 \cdot x + 1\right) - 3 \cdot {x}^{2}}}{\left(x + 1\right) \cdot \left(\left(x - 1\right) \cdot \left(x - 1\right)\right)}\]
    10. Simplified43.6

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, 2, 1 - 3 \cdot {x}^{2}\right)}}{\left(x + 1\right) \cdot \left(\left(x - 1\right) \cdot \left(x - 1\right)\right)}\]
    11. Taylor expanded around inf 0.3

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

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

    if -41855320.47834496 < x < 125882.07557923895

    1. Initial program 0.2

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

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\left(x + 1\right) \cdot \frac{1}{x - 1}}\]
    4. Using strategy rm
    5. Applied flip-+0.2

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}} \cdot \frac{1}{x - 1}\]
    6. Applied frac-times0.2

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

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x \cdot \left(x - 1\right), \left(-\left(x + 1\right)\right) \cdot \left(x \cdot x - 1 \cdot 1\right)\right)}}{\left(x + 1\right) \cdot \left(\left(x - 1\right) \cdot \left(x - 1\right)\right)}\]
    9. Taylor expanded around 0 0.1

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, 2, 1 - 3 \cdot {x}^{2}\right)}}{\left(x + 1\right) \cdot \left(\left(x - 1\right) \cdot \left(x - 1\right)\right)}\]
    11. Taylor expanded around 0 0.0

      \[\leadsto \frac{\mathsf{fma}\left(x, 2, 1 - 3 \cdot {x}^{2}\right)}{\left(x + 1\right) \cdot \color{blue}{\left(\left({x}^{2} + 1\right) - 2 \cdot x\right)}}\]
    12. Simplified0.0

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

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

Reproduce

herbie shell --seed 2020039 +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))