Average Error: 29.5 → 0.1
Time: 4.7s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \sqrt[3]{\frac{x}{x + 1}}\\ t_1 := \frac{1}{x - 1}\\ t_2 := t_1 \cdot \left(x + 1\right)\\ t_3 := \frac{3}{{x}^{3}}\\ \mathbf{if}\;x \leq -357154.3964769983:\\ \;\;\;\;-\left(\frac{3}{x} + \left(\frac{1}{x \cdot x} + \left|t_3\right|\right)\right)\\ \mathbf{elif}\;x \leq 8938.077962000918:\\ \;\;\;\;\mathsf{fma}\left(t_0, {t_0}^{2}, -t_2\right) + \mathsf{fma}\left(-t_1, x + 1, t_2\right)\\ \mathbf{else}:\\ \;\;\;\;-\left(\frac{3}{x} + \left(\left({x}^{-2} + 0\right) + t_3\right)\right)\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \sqrt[3]{\frac{x}{x + 1}}\\
t_1 := \frac{1}{x - 1}\\
t_2 := t_1 \cdot \left(x + 1\right)\\
t_3 := \frac{3}{{x}^{3}}\\
\mathbf{if}\;x \leq -357154.3964769983:\\
\;\;\;\;-\left(\frac{3}{x} + \left(\frac{1}{x \cdot x} + \left|t_3\right|\right)\right)\\

\mathbf{elif}\;x \leq 8938.077962000918:\\
\;\;\;\;\mathsf{fma}\left(t_0, {t_0}^{2}, -t_2\right) + \mathsf{fma}\left(-t_1, x + 1, t_2\right)\\

\mathbf{else}:\\
\;\;\;\;-\left(\frac{3}{x} + \left(\left({x}^{-2} + 0\right) + t_3\right)\right)\\


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (cbrt (/ x (+ x 1.0))))
        (t_1 (/ 1.0 (- x 1.0)))
        (t_2 (* t_1 (+ x 1.0)))
        (t_3 (/ 3.0 (pow x 3.0))))
   (if (<= x -357154.3964769983)
     (- (+ (/ 3.0 x) (+ (/ 1.0 (* x x)) (fabs t_3))))
     (if (<= x 8938.077962000918)
       (+ (fma t_0 (pow t_0 2.0) (- t_2)) (fma (- t_1) (+ x 1.0) t_2))
       (- (+ (/ 3.0 x) (+ (+ (pow x -2.0) 0.0) t_3)))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = cbrt((x / (x + 1.0)));
	double t_1 = 1.0 / (x - 1.0);
	double t_2 = t_1 * (x + 1.0);
	double t_3 = 3.0 / pow(x, 3.0);
	double tmp;
	if (x <= -357154.3964769983) {
		tmp = -((3.0 / x) + ((1.0 / (x * x)) + fabs(t_3)));
	} else if (x <= 8938.077962000918) {
		tmp = fma(t_0, pow(t_0, 2.0), -t_2) + fma(-t_1, (x + 1.0), t_2);
	} else {
		tmp = -((3.0 / x) + ((pow(x, -2.0) + 0.0) + t_3));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 59.5

      \[\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}{-\left(\frac{3}{x} + \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\right)} \]
    4. Applied egg-rr0.1

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

    if -357154.396476998285 < x < 8938.07796200091798

    1. Initial program 0.1

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

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

    if 8938.07796200091798 < x

    1. Initial program 59.6

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

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

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

Reproduce

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