Average Error: 29.2 → 0.2
Time: 9.4s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 4.865807035070446 \cdot 10^{-8}:\\ \;\;\;\;\left(\frac{-3}{x} - \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \frac{1}{x - 1}\\ {\left(\sqrt{\mathsf{fma}\left(x, \frac{1}{x + 1}, t_0 \cdot \left(-1 - x\right)\right)}\right)}^{2} + \mathsf{fma}\left(\frac{-1}{x - 1}, x + 1, \left(x + 1\right) \cdot t_0\right) \end{array}\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 4.865807035070446 \cdot 10^{-8}:\\
\;\;\;\;\left(\frac{-3}{x} - \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \frac{1}{x - 1}\\
{\left(\sqrt{\mathsf{fma}\left(x, \frac{1}{x + 1}, t_0 \cdot \left(-1 - x\right)\right)}\right)}^{2} + \mathsf{fma}\left(\frac{-1}{x - 1}, x + 1, \left(x + 1\right) \cdot t_0\right)
\end{array}\\


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 4.865807035070446e-8)
   (-
    (- (/ -3.0 x) (+ (/ 1.0 (* x x)) (/ 3.0 (pow x 3.0))))
    (/ 1.0 (pow x 4.0)))
   (let* ((t_0 (/ 1.0 (- x 1.0))))
     (+
      (pow (sqrt (fma x (/ 1.0 (+ x 1.0)) (* t_0 (- -1.0 x)))) 2.0)
      (fma (/ -1.0 (- x 1.0)) (+ x 1.0) (* (+ x 1.0) t_0))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 4.865807035070446e-8) {
		tmp = ((-3.0 / x) - ((1.0 / (x * x)) + (3.0 / pow(x, 3.0)))) - (1.0 / pow(x, 4.0));
	} else {
		double t_0 = 1.0 / (x - 1.0);
		tmp = pow(sqrt(fma(x, (1.0 / (x + 1.0)), (t_0 * (-1.0 - x)))), 2.0) + fma((-1.0 / (x - 1.0)), (x + 1.0), ((x + 1.0) * t_0));
	}
	return tmp;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 4.8658070351e-8

    1. Initial program 59.0

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

      \[\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.2

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

    if 4.8658070351e-8 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 0.2

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

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

      \[\leadsto \color{blue}{x \cdot \frac{1}{x + 1}} - \left(x + 1\right) \cdot \frac{1}{x - 1} \]
    4. Applied prod-diff_binary640.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{1}{x + 1}, -\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)} \]
    5. Applied add-sqr-sqrt_binary640.2

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(x, \frac{1}{x + 1}, -\frac{1}{x - 1} \cdot \left(x + 1\right)\right)} \cdot \sqrt{\mathsf{fma}\left(x, \frac{1}{x + 1}, -\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) \]
    6. Applied pow1_binary640.2

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

      \[\leadsto \color{blue}{{\left(\sqrt{\mathsf{fma}\left(x, \frac{1}{x + 1}, -\frac{1}{x - 1} \cdot \left(x + 1\right)\right)}\right)}^{1}} \cdot {\left(\sqrt{\mathsf{fma}\left(x, \frac{1}{x + 1}, -\frac{1}{x - 1} \cdot \left(x + 1\right)\right)}\right)}^{1} + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
    8. Applied pow-prod-up_binary640.2

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

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

Reproduce

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