Average Error: 14.6 → 0.5
Time: 3.5s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{1}{x - 1}\\ \mathbf{if}\;\frac{1}{1 + x} - t_0 \leq 0:\\ \;\;\;\;\frac{\frac{-2}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;e^{-\mathsf{log1p}\left(x\right)} - t_0\\ \end{array} \]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{x - 1}\\
\mathbf{if}\;\frac{1}{1 + x} - t_0 \leq 0:\\
\;\;\;\;\frac{\frac{-2}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;e^{-\mathsf{log1p}\left(x\right)} - 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 (/ 1.0 (- x 1.0))))
   (if (<= (- (/ 1.0 (+ 1.0 x)) t_0) 0.0)
     (/ (/ -2.0 x) x)
     (- (exp (- (log1p x))) t_0))))
double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
double code(double x) {
	double t_0 = 1.0 / (x - 1.0);
	double tmp;
	if (((1.0 / (1.0 + x)) - t_0) <= 0.0) {
		tmp = (-2.0 / x) / x;
	} else {
		tmp = exp(-log1p(x)) - t_0;
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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 29.0

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{2}}} \]
    3. Applied unpow2_binary641.6

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

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

    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. Applied add-exp-log_binary640.0

      \[\leadsto \frac{1}{\color{blue}{e^{\log \left(x + 1\right)}}} - \frac{1}{x - 1} \]
    3. Applied 1-exp_binary640.0

      \[\leadsto \frac{\color{blue}{e^{0}}}{e^{\log \left(x + 1\right)}} - \frac{1}{x - 1} \]
    4. Applied div-exp_binary640.0

      \[\leadsto \color{blue}{e^{0 - \log \left(x + 1\right)}} - \frac{1}{x - 1} \]
    5. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x - 1} \leq 0:\\ \;\;\;\;\frac{\frac{-2}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;e^{-\mathsf{log1p}\left(x\right)} - \frac{1}{x - 1}\\ \end{array} \]

Reproduce

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