Average Error: 29.5 → 0.0
Time: 9.0s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{1}{x \cdot x}\\ \mathbf{if}\;x \leq -13732.497392152165:\\ \;\;\;\;\left(\frac{-3}{x} - \left(t_0 + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\ \mathbf{elif}\;x \leq 22131881926.828556:\\ \;\;\;\;\frac{x \cdot -3 + -1}{\mathsf{fma}\left(x, x, -1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x} - t_0\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{x \cdot x}\\
\mathbf{if}\;x \leq -13732.497392152165:\\
\;\;\;\;\left(\frac{-3}{x} - \left(t_0 + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{-3}{x} - t_0\\


\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 x))))
   (if (<= x -13732.497392152165)
     (- (- (/ -3.0 x) (+ t_0 (/ 3.0 (pow x 3.0)))) (/ 1.0 (pow x 4.0)))
     (if (<= x 22131881926.828556)
       (/ (+ (* x -3.0) -1.0) (fma x x -1.0))
       (- (/ -3.0 x) t_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 * x);
	double tmp;
	if (x <= -13732.497392152165) {
		tmp = ((-3.0 / x) - (t_0 + (3.0 / pow(x, 3.0)))) - (1.0 / pow(x, 4.0));
	} else if (x <= 22131881926.828556) {
		tmp = ((x * -3.0) + -1.0) / fma(x, x, -1.0);
	} else {
		tmp = (-3.0 / x) - t_0;
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 3 regimes
  2. if x < -13732.497392152165

    1. Initial program 59.2

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

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

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

    if -13732.497392152165 < x < 22131881926.8285561

    1. Initial program 0.2

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

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

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

      \[\leadsto \frac{\mathsf{fma}\left(x, x + -1, \left(1 + x\right) \cdot \left(-1 - x\right)\right)}{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    5. Taylor expanded in x around 0 0.0

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, -3, -1\right)}}{\mathsf{fma}\left(x, x, -1\right)} \]
    7. Applied fma-udef_binary640.0

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

    if 22131881926.8285561 < x

    1. Initial program 60.3

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

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

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{x \cdot x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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