Average Error: 29.1 → 0.0
Time: 5.2s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1476318468044825000 \lor \neg \left(x \leq 2483722.563740262\right):\\ \;\;\;\;\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, -3, -1\right)}{\mathsf{fma}\left(x, x, -1\right)}\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -1476318468044825000 \lor \neg \left(x \leq 2483722.563740262\right):\\
\;\;\;\;\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\\

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


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (or (<= x -1476318468044825000.0) (not (<= x 2483722.563740262)))
   (- (/ -3.0 x) (+ (pow x -2.0) (/ 3.0 (pow x 3.0))))
   (/ (fma x -3.0 -1.0) (fma 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 <= -1476318468044825000.0) || !(x <= 2483722.563740262)) {
		tmp = (-3.0 / x) - (pow(x, -2.0) + (3.0 / pow(x, 3.0)));
	} else {
		tmp = fma(x, -3.0, -1.0) / fma(x, x, -1.0);
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -1476318468044825100 or 2483722.5637402618 < x

    1. Initial program 60.0

      \[\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} + \left(3 \cdot \frac{1}{{x}^{3}} + \frac{1}{{x}^{2}}\right)\right)} \]
    3. Simplified0.0

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

      \[\leadsto \frac{-3}{x} - \left(\frac{1}{\color{blue}{{x}^{2}}} + \frac{3}{{x}^{3}}\right) \]
    5. Applied pow-flip_binary640.0

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

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

    if -1476318468044825100 < x < 2483722.5637402618

    1. Initial program 1.0

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

      \[\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. Simplified1.0

      \[\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. Simplified1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1476318468044825000 \lor \neg \left(x \leq 2483722.563740262\right):\\ \;\;\;\;\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, -3, -1\right)}{\mathsf{fma}\left(x, x, -1\right)}\\ \end{array} \]

Reproduce

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