Average Error: 29.8 → 0.0
Time: 4.9s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(-1, \mathsf{fma}\left(3, {x}^{-3}, {x}^{-2}\right), \frac{-3}{x}\right)\\ \mathbf{if}\;x \leq -18424.40926304694:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 11995.028539617728:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{x + -1}{x + 1}\\ t_2 := \frac{x + 1}{x}\\ \frac{t_1 - t_2}{t_1 \cdot t_2} \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \mathsf{fma}\left(-1, \mathsf{fma}\left(3, {x}^{-3}, {x}^{-2}\right), \frac{-3}{x}\right)\\
\mathbf{if}\;x \leq -18424.40926304694:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 11995.028539617728:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{x + -1}{x + 1}\\
t_2 := \frac{x + 1}{x}\\
\frac{t_1 - t_2}{t_1 \cdot t_2}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;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 (fma -1.0 (fma 3.0 (pow x -3.0) (pow x -2.0)) (/ -3.0 x))))
   (if (<= x -18424.40926304694)
     t_0
     (if (<= x 11995.028539617728)
       (let* ((t_1 (/ (+ x -1.0) (+ x 1.0))) (t_2 (/ (+ x 1.0) x)))
         (/ (- t_1 t_2) (* t_1 t_2)))
       t_0))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = fma(-1.0, fma(3.0, pow(x, -3.0), pow(x, -2.0)), (-3.0 / x));
	double tmp;
	if (x <= -18424.40926304694) {
		tmp = t_0;
	} else if (x <= 11995.028539617728) {
		double t_1 = (x + -1.0) / (x + 1.0);
		double t_2 = (x + 1.0) / x;
		tmp = (t_1 - t_2) / (t_1 * t_2);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -18424.409263046939 or 11995.028539617728 < 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(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 egg0.0

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

    if -18424.409263046939 < x < 11995.028539617728

    1. Initial program 0.1

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

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

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

Reproduce

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