Average Error: 29.2 → 0.2
Time: 6.2s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ \mathbf{if}\;t_0 - \frac{x + 1}{x - 1} \leq 3.8877992514230186 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{x + 1}{x \cdot x - 1}\\ t_2 := \left(x + 1\right) \cdot t_1\\ \log \left(e^{t_0 - t_2}\right) + \mathsf{fma}\left(-1 - x, t_1, t_2\right) \end{array}\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;t_0 - \frac{x + 1}{x - 1} \leq 3.8877992514230186 \cdot 10^{-7}:\\
\;\;\;\;\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{x + 1}{x \cdot x - 1}\\
t_2 := \left(x + 1\right) \cdot t_1\\
\log \left(e^{t_0 - t_2}\right) + \mathsf{fma}\left(-1 - x, t_1, t_2\right)
\end{array}\\


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ x (+ x 1.0))))
   (if (<= (- t_0 (/ (+ x 1.0) (- x 1.0))) 3.8877992514230186e-7)
     (- (/ -3.0 x) (+ (pow x -2.0) (/ 3.0 (pow x 3.0))))
     (let* ((t_1 (/ (+ x 1.0) (- (* x x) 1.0))) (t_2 (* (+ x 1.0) t_1)))
       (+ (log (exp (- t_0 t_2))) (fma (- -1.0 x) t_1 t_2))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = x / (x + 1.0);
	double tmp;
	if ((t_0 - ((x + 1.0) / (x - 1.0))) <= 3.8877992514230186e-7) {
		tmp = (-3.0 / x) - (pow(x, -2.0) + (3.0 / pow(x, 3.0)));
	} else {
		double t_1 = (x + 1.0) / ((x * x) - 1.0);
		double t_2 = (x + 1.0) * t_1;
		tmp = log(exp(t_0 - t_2)) + fma((-1.0 - x), t_1, t_2);
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 3.8877992514e-7

    1. Initial program 59.2

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

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

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

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

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

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

    if 3.8877992514e-7 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied flip--_binary640.1

      \[\leadsto \frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}} \]
    3. Applied associate-/r/_binary640.2

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

      \[\leadsto \frac{x}{\color{blue}{1 \cdot \left(x + 1\right)}} - \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right) \]
    5. Applied add-cube-cbrt_binary640.2

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{1}, \frac{\sqrt[3]{x}}{x + 1}, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \mathsf{fma}\left(-\left(x + 1\right), \frac{x + 1}{x \cdot x - 1 \cdot 1}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)} \]
    8. Applied add-log-exp_binary640.2

      \[\leadsto \color{blue}{\log \left(e^{\mathsf{fma}\left(\frac{\sqrt[3]{x} \cdot \sqrt[3]{x}}{1}, \frac{\sqrt[3]{x}}{x + 1}, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)}\right)} + \mathsf{fma}\left(-\left(x + 1\right), \frac{x + 1}{x \cdot x - 1 \cdot 1}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) \]
    9. Applied fma-udef_binary640.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 3.8877992514230186 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x}{x + 1} - \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1}}\right) + \mathsf{fma}\left(-1 - x, \frac{x + 1}{x \cdot x - 1}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022088 
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))