Average Error: 14.4 → 0.2
Time: 7.3s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{2}{{x}^{6}}\\ \mathbf{if}\;x \leq -0.9981121859939434:\\ \;\;\;\;\left(\frac{-2}{x \cdot x} - \frac{2}{{x}^{4}}\right) - t_0\\ \mathbf{elif}\;x \leq 55.498538329832456:\\ \;\;\;\;e^{-\mathsf{log1p}\left(x\right)} - \frac{1}{x - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{{x}^{4}} - \left(t_0 + \left(\frac{\frac{2}{x}}{x} + \frac{2}{{x}^{8}}\right)\right)\\ \end{array} \]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{2}{{x}^{6}}\\
\mathbf{if}\;x \leq -0.9981121859939434:\\
\;\;\;\;\left(\frac{-2}{x \cdot x} - \frac{2}{{x}^{4}}\right) - t_0\\

\mathbf{elif}\;x \leq 55.498538329832456:\\
\;\;\;\;e^{-\mathsf{log1p}\left(x\right)} - \frac{1}{x - 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{{x}^{4}} - \left(t_0 + \left(\frac{\frac{2}{x}}{x} + \frac{2}{{x}^{8}}\right)\right)\\


\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 (pow x 6.0))))
   (if (<= x -0.9981121859939434)
     (- (- (/ -2.0 (* x x)) (/ 2.0 (pow x 4.0))) t_0)
     (if (<= x 55.498538329832456)
       (- (exp (- (log1p x))) (/ 1.0 (- x 1.0)))
       (-
        (/ -2.0 (pow x 4.0))
        (+ t_0 (+ (/ (/ 2.0 x) x) (/ 2.0 (pow x 8.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 / pow(x, 6.0);
	double tmp;
	if (x <= -0.9981121859939434) {
		tmp = ((-2.0 / (x * x)) - (2.0 / pow(x, 4.0))) - t_0;
	} else if (x <= 55.498538329832456) {
		tmp = exp(-log1p(x)) - (1.0 / (x - 1.0));
	} else {
		tmp = (-2.0 / pow(x, 4.0)) - (t_0 + (((2.0 / x) / x) + (2.0 / pow(x, 8.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 3 regimes
  2. if x < -0.998112185993943357

    1. Initial program 29.1

      \[\frac{1}{x + 1} - \frac{1}{x - 1} \]
    2. Applied expm1-log1p-u_binary6429.1

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{x + 1}\right)\right)} - \frac{1}{x - 1} \]
    3. Taylor expanded in x around inf 0.8

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

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

    if -0.998112185993943357 < x < 55.498538329832456

    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} \]

    if 55.498538329832456 < x

    1. Initial program 29.1

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

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

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

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

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

Reproduce

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