Average Error: 29.6 → 0.2
Time: 4.3s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 2.6303332268939883 \cdot 10^{-6}:\\ \;\;\;\;\frac{-3}{x} - \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;{e}^{\log \left(\mathsf{fma}\left(x, \frac{1}{x + 1}, \frac{-1 - x}{x - 1}\right)\right)}\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 2.6303332268939883 \cdot 10^{-6}:\\
\;\;\;\;\frac{-3}{x} - \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\\

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


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 2.6303332268939883e-6)
   (- (/ -3.0 x) (+ (/ 1.0 (* x x)) (/ 3.0 (pow x 3.0))))
   (pow E (log (fma x (/ 1.0 (+ x 1.0)) (/ (- -1.0 x) (- x 1.0)))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 2.6303332268939883e-6) {
		tmp = (-3.0 / x) - ((1.0 / (x * x)) + (3.0 / pow(x, 3.0)));
	} else {
		tmp = pow(((double) M_E), log(fma(x, (1.0 / (x + 1.0)), ((-1.0 - x) / (x - 1.0)))));
	}
	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))) < 2.63033322689e-6

    1. Initial program 58.9

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

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

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

    if 2.63033322689e-6 < (-.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 div-inv_binary640.1

      \[\leadsto \color{blue}{x \cdot \frac{1}{x + 1}} - \frac{x + 1}{x - 1} \]
    3. Applied fma-neg_binary640.1

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

      \[\leadsto \mathsf{fma}\left(x, \frac{1}{x + 1}, \color{blue}{\frac{-1 - x}{x + -1}}\right) \]
    5. Applied add-exp-log_binary640.1

      \[\leadsto \color{blue}{e^{\log \left(\mathsf{fma}\left(x, \frac{1}{x + 1}, \frac{-1 - x}{x + -1}\right)\right)}} \]
    6. Applied pow1_binary640.1

      \[\leadsto e^{\log \color{blue}{\left({\left(\mathsf{fma}\left(x, \frac{1}{x + 1}, \frac{-1 - x}{x + -1}\right)\right)}^{1}\right)}} \]
    7. Applied log-pow_binary640.1

      \[\leadsto e^{\color{blue}{1 \cdot \log \left(\mathsf{fma}\left(x, \frac{1}{x + 1}, \frac{-1 - x}{x + -1}\right)\right)}} \]
    8. Applied exp-prod_binary640.1

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

      \[\leadsto {\color{blue}{e}}^{\log \left(\mathsf{fma}\left(x, \frac{1}{x + 1}, \frac{-1 - x}{x + -1}\right)\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 2.6303332268939883 \cdot 10^{-6}:\\ \;\;\;\;\frac{-3}{x} - \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;{e}^{\log \left(\mathsf{fma}\left(x, \frac{1}{x + 1}, \frac{-1 - x}{x - 1}\right)\right)}\\ \end{array} \]

Reproduce

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