Average Error: 29.8 → 0.1
Time: 38.8s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9487.53105400853:\\ \;\;\;\;\frac{-3}{\left(x \cdot x\right) \cdot x} - \left(\frac{3}{x} + \frac{1}{x \cdot x}\right)\\ \mathbf{elif}\;x \le 8293.699788933664:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x + 1, \sqrt[3]{\left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right) \cdot \left(\left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right) \cdot \left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right)\right)}\right) + \mathsf{fma}\left(1, \frac{x}{x + 1}, \frac{-1}{x - 1} \cdot \left(x + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{\left(x \cdot x\right) \cdot x} - \left(\frac{3}{x} + \frac{1}{x \cdot x}\right)\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -9487.53105400853:\\
\;\;\;\;\frac{-3}{\left(x \cdot x\right) \cdot x} - \left(\frac{3}{x} + \frac{1}{x \cdot x}\right)\\

\mathbf{elif}\;x \le 8293.699788933664:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x + 1, \sqrt[3]{\left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right) \cdot \left(\left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right) \cdot \left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right)\right)}\right) + \mathsf{fma}\left(1, \frac{x}{x + 1}, \frac{-1}{x - 1} \cdot \left(x + 1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{-3}{\left(x \cdot x\right) \cdot x} - \left(\frac{3}{x} + \frac{1}{x \cdot x}\right)\\

\end{array}
double f(double x) {
        double r3308699 = x;
        double r3308700 = 1.0;
        double r3308701 = r3308699 + r3308700;
        double r3308702 = r3308699 / r3308701;
        double r3308703 = r3308699 - r3308700;
        double r3308704 = r3308701 / r3308703;
        double r3308705 = r3308702 - r3308704;
        return r3308705;
}

double f(double x) {
        double r3308706 = x;
        double r3308707 = -9487.53105400853;
        bool r3308708 = r3308706 <= r3308707;
        double r3308709 = -3.0;
        double r3308710 = r3308706 * r3308706;
        double r3308711 = r3308710 * r3308706;
        double r3308712 = r3308709 / r3308711;
        double r3308713 = 3.0;
        double r3308714 = r3308713 / r3308706;
        double r3308715 = 1.0;
        double r3308716 = r3308715 / r3308710;
        double r3308717 = r3308714 + r3308716;
        double r3308718 = r3308712 - r3308717;
        double r3308719 = 8293.699788933664;
        bool r3308720 = r3308706 <= r3308719;
        double r3308721 = -1.0;
        double r3308722 = r3308706 - r3308715;
        double r3308723 = r3308721 / r3308722;
        double r3308724 = r3308706 + r3308715;
        double r3308725 = r3308715 / r3308722;
        double r3308726 = r3308725 * r3308724;
        double r3308727 = r3308726 * r3308726;
        double r3308728 = r3308726 * r3308727;
        double r3308729 = cbrt(r3308728);
        double r3308730 = fma(r3308723, r3308724, r3308729);
        double r3308731 = r3308706 / r3308724;
        double r3308732 = r3308723 * r3308724;
        double r3308733 = fma(r3308715, r3308731, r3308732);
        double r3308734 = r3308730 + r3308733;
        double r3308735 = r3308720 ? r3308734 : r3308718;
        double r3308736 = r3308708 ? r3308718 : r3308735;
        return r3308736;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -9487.53105400853 or 8293.699788933664 < x

    1. Initial program 59.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Taylor expanded around -inf 0.3

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

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

    if -9487.53105400853 < x < 8293.699788933664

    1. Initial program 0.1

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9487.53105400853:\\ \;\;\;\;\frac{-3}{\left(x \cdot x\right) \cdot x} - \left(\frac{3}{x} + \frac{1}{x \cdot x}\right)\\ \mathbf{elif}\;x \le 8293.699788933664:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{x - 1}, x + 1, \sqrt[3]{\left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right) \cdot \left(\left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right) \cdot \left(\frac{1}{x - 1} \cdot \left(x + 1\right)\right)\right)}\right) + \mathsf{fma}\left(1, \frac{x}{x + 1}, \frac{-1}{x - 1} \cdot \left(x + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{\left(x \cdot x\right) \cdot x} - \left(\frac{3}{x} + \frac{1}{x \cdot x}\right)\\ \end{array}\]

Reproduce

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