Average Error: 14.3 → 0.1
Time: 7.3s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{\frac{-2}{x}}{x} - \frac{2}{{x}^{4}}\\ \mathbf{if}\;x \leq -17920075928339632:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 8254.748494483338:\\ \;\;\;\;\frac{x - \left(x + 2\right)}{\mathsf{fma}\left(x, x, -1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{\frac{-2}{x}}{x} - \frac{2}{{x}^{4}}\\
\mathbf{if}\;x \leq -17920075928339632:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 8254.748494483338:\\
\;\;\;\;\frac{x - \left(x + 2\right)}{\mathsf{fma}\left(x, x, -1\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -17920075928339632 or 8254.7484944833377 < x

    1. Initial program 29.2

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

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

      \[\leadsto \color{blue}{\frac{-2}{x \cdot x} - \frac{2}{{x}^{4}}} \]
    4. Applied associate-/r*_binary640.1

      \[\leadsto \color{blue}{\frac{\frac{-2}{x}}{x}} - \frac{2}{{x}^{4}} \]

    if -17920075928339632 < x < 8254.7484944833377

    1. Initial program 0.7

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

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

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

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

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

Reproduce

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