Average Error: 29.2 → 0.0
Time: 6.7s
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 -124526734327407820:\\ \;\;\;\;\mathsf{fma}\left(t_0, -1 - \frac{3}{x}, \frac{-3}{x}\right)\\ \mathbf{elif}\;x \leq 22073.547601646904:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, -3, -1\right)}{\left(x + 1\right) \cdot \left(x + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{-3}{x} - \left(t_0 + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\ \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 -124526734327407820:\\
\;\;\;\;\mathsf{fma}\left(t_0, -1 - \frac{3}{x}, \frac{-3}{x}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\left(\frac{-3}{x} - \left(t_0 + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\


\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 -124526734327407820.0)
     (fma t_0 (- -1.0 (/ 3.0 x)) (/ -3.0 x))
     (if (<= x 22073.547601646904)
       (/ (fma x -3.0 -1.0) (* (+ x 1.0) (+ x -1.0)))
       (- (- (/ -3.0 x) (+ t_0 (/ 3.0 (pow x 3.0)))) (/ 1.0 (pow x 4.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 <= -124526734327407820.0) {
		tmp = fma(t_0, (-1.0 - (3.0 / x)), (-3.0 / x));
	} else if (x <= 22073.547601646904) {
		tmp = fma(x, -3.0, -1.0) / ((x + 1.0) * (x + -1.0));
	} else {
		tmp = ((-3.0 / x) - (t_0 + (3.0 / pow(x, 3.0)))) - (1.0 / pow(x, 4.0));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 60.5

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied add-sqr-sqrt_binary6460.5

      \[\leadsto \color{blue}{\sqrt{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \cdot \sqrt{\frac{x}{x + 1} - \frac{x + 1}{x - 1}}} \]
    3. Taylor expanded in x around inf 0.3

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

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

    if -124526734327407824 < x < 22073.547601646904

    1. Initial program 0.7

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied add-sqr-sqrt_binary641.0

      \[\leadsto \color{blue}{\sqrt{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \cdot \sqrt{\frac{x}{x + 1} - \frac{x + 1}{x - 1}}} \]
    3. Applied frac-sub_binary641.0

      \[\leadsto \sqrt{\frac{x}{x + 1} - \frac{x + 1}{x - 1}} \cdot \sqrt{\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)}}} \]
    4. Applied sqrt-div_binary6463.1

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

      \[\leadsto \sqrt{\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)}}} \cdot \frac{\sqrt{x \cdot \left(x - 1\right) - \left(x + 1\right) \cdot \left(x + 1\right)}}{\sqrt{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
    6. Applied sqrt-div_binary6463.1

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

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

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

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

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

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

    if 22073.547601646904 < x

    1. Initial program 59.4

      \[\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}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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