Average Error: 29.1 → 0.1
Time: 6.1s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -452149.06294381135 \lor \neg \left(x \leq 387887.6914731773\right):\\ \;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{-1}{-1 - x}, \frac{-1 - x}{x + -1}\right)\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -452149.06294381135 \lor \neg \left(x \leq 387887.6914731773\right):\\
\;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{-1}{-1 - x}, \frac{-1 - 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 -452149.06294381135) (not (<= x 387887.6914731773)))
   (/ (+ -3.0 (/ -1.0 x)) x)
   (fma x (/ -1.0 (- -1.0 x)) (/ (- -1.0 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 <= -452149.06294381135) || !(x <= 387887.6914731773)) {
		tmp = (-3.0 + (-1.0 / x)) / x;
	} else {
		tmp = fma(x, (-1.0 / (-1.0 - x)), ((-1.0 - x) / (x + -1.0)));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -452149.062943811354 or 387887.69147317728 < x

    1. Initial program 59.5

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

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

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

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

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

    if -452149.062943811354 < x < 387887.69147317728

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{x \cdot \frac{1}{x + 1}} - \frac{x + 1}{x - 1} \]
    3. Applied fma-neg_binary640.1

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

      \[\leadsto \mathsf{fma}\left(x, \frac{1}{x + 1}, \color{blue}{\frac{-1 - x}{x + -1}}\right) \]
    5. Applied frac-2neg_binary640.1

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

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

      \[\leadsto \mathsf{fma}\left(x, \frac{-1}{\color{blue}{-1 - x}}, \frac{-1 - x}{x + -1}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

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

Reproduce

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