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

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


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

    1. Initial program 59.4

      \[\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)} \]
    4. Applied egg-rr0.3

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

    if 5.53872836e-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 egg-rr0.2

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

Reproduce

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