Average Error: 14.5 → 0.3
Time: 2.2s
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:\\ \;\;\;\;\mathsf{fma}\left(-2, {x}^{-2}, -2 \cdot {x}^{-4}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left({x}^{4} + \mathsf{fma}\left(x, x, 1\right)\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)
   (fma -2.0 (pow x -2.0) (* -2.0 (pow x -4.0)))
   (* 2.0 (+ (pow x 4.0) (fma x x 1.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 = fma(-2.0, pow(x, -2.0), (-2.0 * pow(x, -4.0)));
	} else {
		tmp = 2.0 * (pow(x, 4.0) + fma(x, x, 1.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)
	tmp = 0.0
	if (Float64(Float64(1.0 / Float64(1.0 + x)) + Float64(-1.0 / Float64(x + -1.0))) <= 0.0)
		tmp = fma(-2.0, (x ^ -2.0), Float64(-2.0 * (x ^ -4.0)));
	else
		tmp = Float64(2.0 * Float64((x ^ 4.0) + fma(x, x, 1.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_] := If[LessEqual[N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(-2.0 * N[Power[x, -2.0], $MachinePrecision] + N[(-2.0 * N[Power[x, -4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Power[x, 4.0], $MachinePrecision] + N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{1}{1 + x} + \frac{-1}{x + -1} \leq 0:\\
\;\;\;\;\mathsf{fma}\left(-2, {x}^{-2}, -2 \cdot {x}^{-4}\right)\\

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


\end{array}

Error

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

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{4}} + \frac{-2}{x \cdot x}} \]
    4. Applied egg-rr0.5

      \[\leadsto \frac{-2}{{x}^{4}} + \color{blue}{\frac{-2}{x} \cdot \frac{1}{x}} \]
    5. Applied egg-rr0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(-2, {x}^{-2}, -2 \cdot {x}^{-4}\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.3

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

      \[\leadsto \color{blue}{2 \cdot \left({x}^{4} + \mathsf{fma}\left(x, x, 1\right)\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:\\ \;\;\;\;\mathsf{fma}\left(-2, {x}^{-2}, -2 \cdot {x}^{-4}\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left({x}^{4} + \mathsf{fma}\left(x, x, 1\right)\right)\\ \end{array} \]

Reproduce

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