Average Error: 28.7 → 0.3
Time: 4.7s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{-1}{x - 1}\\ \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 2.860045533736866 \cdot 10^{-10}:\\ \;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{-1 + x \cdot x}, x - 1, \left(x + 1\right) \cdot t_0\right) + \mathsf{fma}\left(t_0, x + 1, \left(x + 1\right) \cdot \frac{1}{x - 1}\right)\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{-1}{x - 1}\\
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 2.860045533736866 \cdot 10^{-10}:\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\

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


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ -1.0 (- x 1.0))))
   (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 2.860045533736866e-10)
     (/ (+ -3.0 (/ -1.0 x)) x)
     (+
      (fma (/ x (+ -1.0 (* x x))) (- x 1.0) (* (+ x 1.0) t_0))
      (fma t_0 (+ x 1.0) (* (+ x 1.0) (/ 1.0 (- x 1.0))))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = -1.0 / (x - 1.0);
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 2.860045533736866e-10) {
		tmp = (-3.0 + (-1.0 / x)) / x;
	} else {
		tmp = fma((x / (-1.0 + (x * x))), (x - 1.0), ((x + 1.0) * t_0)) + fma(t_0, (x + 1.0), ((x + 1.0) * (1.0 / (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.8600455e-10

    1. Initial program 59.2

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

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

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{x \cdot x}} \]
    4. Taylor expanded in x around 0 0.7

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

      \[\leadsto \color{blue}{\frac{-3 + \frac{-1}{x}}{x}} \]

    if 2.8600455e-10 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 0.2

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied div-inv_binary640.2

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

      \[\leadsto \frac{x}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}} - \left(x + 1\right) \cdot \frac{1}{x - 1} \]
    4. Applied associate-/r/_binary640.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, 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.3

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

Reproduce

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