Average Error: 14.1 → 0.3
Time: 4.1s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x - 1} \leq 0:\\ \;\;\;\;\frac{-2}{{x}^{4}} - \left(\frac{2}{{x}^{6}} + \left(\frac{\frac{2}{x}}{x} + \frac{2}{{x}^{8}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, x \cdot x, 2\right)\\ \end{array} \]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x - 1} \leq 0:\\
\;\;\;\;\frac{-2}{{x}^{4}} - \left(\frac{2}{{x}^{6}} + \left(\frac{\frac{2}{x}}{x} + \frac{2}{{x}^{8}}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, x \cdot x, 2\right)\\


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

Error

Bits error versus x

Derivation

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

    1. Initial program 28.4

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

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{4}} - \left(\frac{2}{{x}^{6}} + \left(\frac{2}{x \cdot x} + \frac{2}{{x}^{8}}\right)\right)} \]
    4. Applied associate-/r*_binary640.3

      \[\leadsto \frac{-2}{{x}^{4}} - \left(\frac{2}{{x}^{6}} + \left(\color{blue}{\frac{\frac{2}{x}}{x}} + \frac{2}{{x}^{8}}\right)\right) \]

    if 0.0 < (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{2 + 2 \cdot {x}^{2}} \]
    3. Simplified0.4

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

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

Reproduce

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