Average Error: 14.5 → 0.8
Time: 2.8s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{1}{x + -1}\\ t_1 := -\frac{\frac{2}{x} + \frac{2}{{x}^{3}}}{x}\\ \mathbf{if}\;x \leq -41108431.41060643:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.6458904718769783 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(t_0, -2, t_0 + \frac{1}{1 + x}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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)))
        (t_1 (- (/ (+ (/ 2.0 x) (/ 2.0 (pow x 3.0))) x))))
   (if (<= x -41108431.41060643)
     t_1
     (if (<= x 1.6458904718769783e-11)
       (fma t_0 -2.0 (+ t_0 (/ 1.0 (+ 1.0 x))))
       t_1))))
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 t_1 = -(((2.0 / x) + (2.0 / pow(x, 3.0))) / x);
	double tmp;
	if (x <= -41108431.41060643) {
		tmp = t_1;
	} else if (x <= 1.6458904718769783e-11) {
		tmp = fma(t_0, -2.0, (t_0 + (1.0 / (1.0 + x))));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x)
	return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / Float64(x - 1.0)))
end
function code(x)
	t_0 = Float64(1.0 / Float64(x + -1.0))
	t_1 = Float64(-Float64(Float64(Float64(2.0 / x) + Float64(2.0 / (x ^ 3.0))) / x))
	tmp = 0.0
	if (x <= -41108431.41060643)
		tmp = t_1;
	elseif (x <= 1.6458904718769783e-11)
		tmp = fma(t_0, -2.0, Float64(t_0 + Float64(1.0 / Float64(1.0 + x))));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = (-N[(N[(N[(2.0 / x), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision])}, If[LessEqual[x, -41108431.41060643], t$95$1, If[LessEqual[x, 1.6458904718769783e-11], N[(t$95$0 * -2.0 + N[(t$95$0 + N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{1}{x + -1}\\
t_1 := -\frac{\frac{2}{x} + \frac{2}{{x}^{3}}}{x}\\
\mathbf{if}\;x \leq -41108431.41060643:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x \leq 1.6458904718769783 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(t_0, -2, t_0 + \frac{1}{1 + x}\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -41108431.410606429 or 1.6458904718769783e-11 < x

    1. Initial program 28.7

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

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

      \[\leadsto \color{blue}{-\frac{2 + \frac{2}{x \cdot x}}{x \cdot x}} \]
    4. Applied egg-rr1.6

      \[\leadsto -\color{blue}{\frac{2 + \frac{2}{x \cdot x}}{x} \cdot \frac{1}{x}} \]
    5. Applied egg-rr1.5

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

    if -41108431.410606429 < x < 1.6458904718769783e-11

    1. Initial program 0.1

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

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

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

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

Reproduce

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