Average Error: 29.3 → 0.2
Time: 24.9s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0028494934768706:\\ \;\;\;\;-\left(\mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{1}{x \cdot x}\right) + \frac{3}{x}\right)\\ \mathbf{elif}\;x \le 10076.446968341284:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + x}}, \frac{x}{\sqrt{1 + x}}, \frac{-1}{x - 1} \cdot \left(1 + x\right)\right) + \mathsf{fma}\left(\frac{-1}{x - 1}, 1 + x, \frac{1}{x - 1} \cdot \left(1 + x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\left(\mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{1}{x \cdot x}\right) + \frac{3}{x}\right)\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -1.0028494934768706:\\
\;\;\;\;-\left(\mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{1}{x \cdot x}\right) + \frac{3}{x}\right)\\

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

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

\end{array}
double f(double x) {
        double r5489988 = x;
        double r5489989 = 1.0;
        double r5489990 = r5489988 + r5489989;
        double r5489991 = r5489988 / r5489990;
        double r5489992 = r5489988 - r5489989;
        double r5489993 = r5489990 / r5489992;
        double r5489994 = r5489991 - r5489993;
        return r5489994;
}

double f(double x) {
        double r5489995 = x;
        double r5489996 = -1.0028494934768706;
        bool r5489997 = r5489995 <= r5489996;
        double r5489998 = 3.0;
        double r5489999 = r5489998 / r5489995;
        double r5490000 = 1.0;
        double r5490001 = r5489995 * r5489995;
        double r5490002 = r5490000 / r5490001;
        double r5490003 = fma(r5489999, r5490002, r5490002);
        double r5490004 = r5490003 + r5489999;
        double r5490005 = -r5490004;
        double r5490006 = 10076.446968341284;
        bool r5490007 = r5489995 <= r5490006;
        double r5490008 = r5490000 + r5489995;
        double r5490009 = sqrt(r5490008);
        double r5490010 = r5490000 / r5490009;
        double r5490011 = r5489995 / r5490009;
        double r5490012 = -1.0;
        double r5490013 = r5489995 - r5490000;
        double r5490014 = r5490012 / r5490013;
        double r5490015 = r5490014 * r5490008;
        double r5490016 = fma(r5490010, r5490011, r5490015);
        double r5490017 = r5490000 / r5490013;
        double r5490018 = r5490017 * r5490008;
        double r5490019 = fma(r5490014, r5490008, r5490018);
        double r5490020 = r5490016 + r5490019;
        double r5490021 = r5490007 ? r5490020 : r5490005;
        double r5490022 = r5489997 ? r5490005 : r5490021;
        return r5490022;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -1.0028494934768706 or 10076.446968341284 < x

    1. Initial program 58.8

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube58.8

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

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

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

    if -1.0028494934768706 < x < 10076.446968341284

    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 add-sqr-sqrt0.1

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

      \[\leadsto \frac{\color{blue}{1 \cdot x}}{\sqrt{x + 1} \cdot \sqrt{x + 1}} - \left(x + 1\right) \cdot \frac{1}{x - 1}\]
    6. Applied times-frac0.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{x + 1}}, \frac{x}{\sqrt{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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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