Average Error: 15.0 → 0.0
Time: 2.3s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{-2}{{x}^{6}} + \left(\mathsf{fma}\left({x}^{-4}, -2, -2 \cdot {x}^{-2}\right) + \frac{-2}{{x}^{8}}\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 100000:\\ \;\;\;\;\frac{\left(1 - x\right) + \left(x + 1\right)}{\left(1 - x\right) \cdot \left(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 (pow x 6.0))
          (+
           (fma (pow x -4.0) -2.0 (* -2.0 (pow x -2.0)))
           (/ -2.0 (pow x 8.0))))))
   (if (<= x -1e+15)
     t_0
     (if (<= x 100000.0)
       (/ (+ (- 1.0 x) (+ x 1.0)) (* (- 1.0 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 / pow(x, 6.0)) + (fma(pow(x, -4.0), -2.0, (-2.0 * pow(x, -2.0))) + (-2.0 / pow(x, 8.0)));
	double tmp;
	if (x <= -1e+15) {
		tmp = t_0;
	} else if (x <= 100000.0) {
		tmp = ((1.0 - x) + (x + 1.0)) / ((1.0 - x) * (x + 1.0));
	} else {
		tmp = t_0;
	}
	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(Float64(-2.0 / (x ^ 6.0)) + Float64(fma((x ^ -4.0), -2.0, Float64(-2.0 * (x ^ -2.0))) + Float64(-2.0 / (x ^ 8.0))))
	tmp = 0.0
	if (x <= -1e+15)
		tmp = t_0;
	elseif (x <= 100000.0)
		tmp = Float64(Float64(Float64(1.0 - x) + Float64(x + 1.0)) / Float64(Float64(1.0 - x) * Float64(x + 1.0)));
	else
		tmp = t_0;
	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[(N[(-2.0 / N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, -4.0], $MachinePrecision] * -2.0 + N[(-2.0 * N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 / N[Power[x, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1e+15], t$95$0, If[LessEqual[x, 100000.0], N[(N[(N[(1.0 - x), $MachinePrecision] + N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 - x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{-2}{{x}^{6}} + \left(\mathsf{fma}\left({x}^{-4}, -2, -2 \cdot {x}^{-2}\right) + \frac{-2}{{x}^{8}}\right)\\
\mathbf{if}\;x \leq -1 \cdot 10^{+15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq 100000:\\
\;\;\;\;\frac{\left(1 - x\right) + \left(x + 1\right)}{\left(1 - x\right) \cdot \left(x + 1\right)}\\

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


\end{array}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -1e15 or 1e5 < x

    1. Initial program 30.0

      \[\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}} + \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.8

      \[\leadsto \color{blue}{\frac{-2}{{x}^{6}} + \left(\left(\frac{-2}{{x}^{4}} + \frac{-2}{x \cdot x}\right) + \frac{-2}{{x}^{8}}\right)} \]
    4. Applied egg-rr0.0

      \[\leadsto \frac{-2}{{x}^{6}} + \left(\left(\frac{-2}{{x}^{4}} + \color{blue}{-2 \cdot {x}^{-2}}\right) + \frac{-2}{{x}^{8}}\right) \]
    5. Applied egg-rr0.0

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

    if -1e15 < x < 1e5

    1. Initial program 0.7

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

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

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

Reproduce

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