Average Error: 29.4 → 0.4
Time: 3.0s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -60568178728272.734:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-3 + \frac{2}{x}}{x + -1}\right)\right)\\ \mathbf{elif}\;x \leq 0.3392509774779934:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(x, \frac{x + -1}{x + 1}, \mathsf{fma}\left(-1, x, -1\right)\right)}{x + -1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{x \cdot x} + \frac{-3}{x}\right)\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= x -60568178728272.734)
   (expm1 (log1p (/ (+ -3.0 (/ 2.0 x)) (+ x -1.0))))
   (if (<= x 0.3392509774779934)
     (expm1
      (log1p
       (/ (fma x (/ (+ x -1.0) (+ x 1.0)) (fma -1.0 x -1.0)) (+ x -1.0))))
     (expm1 (log1p (+ (/ -1.0 (* x x)) (/ -3.0 x)))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -60568178728272.734) {
		tmp = expm1(log1p(((-3.0 + (2.0 / x)) / (x + -1.0))));
	} else if (x <= 0.3392509774779934) {
		tmp = expm1(log1p((fma(x, ((x + -1.0) / (x + 1.0)), fma(-1.0, x, -1.0)) / (x + -1.0))));
	} else {
		tmp = expm1(log1p(((-1.0 / (x * x)) + (-3.0 / x))));
	}
	return tmp;
}
function code(x)
	return Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0)))
end
function code(x)
	tmp = 0.0
	if (x <= -60568178728272.734)
		tmp = expm1(log1p(Float64(Float64(-3.0 + Float64(2.0 / x)) / Float64(x + -1.0))));
	elseif (x <= 0.3392509774779934)
		tmp = expm1(log1p(Float64(fma(x, Float64(Float64(x + -1.0) / Float64(x + 1.0)), fma(-1.0, x, -1.0)) / Float64(x + -1.0))));
	else
		tmp = expm1(log1p(Float64(Float64(-1.0 / Float64(x * x)) + Float64(-3.0 / x))));
	end
	return tmp
end
code[x_] := N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -60568178728272.734], N[(Exp[N[Log[1 + N[(N[(-3.0 + N[(2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision], If[LessEqual[x, 0.3392509774779934], N[(Exp[N[Log[1 + N[(N[(x * N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 * x + -1.0), $MachinePrecision]), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision], N[(Exp[N[Log[1 + N[(N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(-3.0 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \leq -60568178728272.734:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-3 + \frac{2}{x}}{x + -1}\right)\right)\\

\mathbf{elif}\;x \leq 0.3392509774779934:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(x, \frac{x + -1}{x + 1}, \mathsf{fma}\left(-1, x, -1\right)\right)}{x + -1}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{x \cdot x} + \frac{-3}{x}\right)\right)\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if x < -60568178728272.734

    1. Initial program 60.3

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, \frac{x + -1}{x + 1}, \mathsf{fma}\left(-1, x, -1\right)\right)}{\left(x + 1\right) \cdot \frac{x + -1}{x + 1}}} \]
    3. Applied egg-rr60.3

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{2 \cdot \frac{1}{x} - 3}}{x + -1}\right)\right) \]
    5. Simplified0.0

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\color{blue}{-3 + \frac{2}{x}}}{x + -1}\right)\right) \]

    if -60568178728272.734 < x < 0.33925097747799338

    1. Initial program 0.4

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(x, \frac{x + -1}{x + 1}, \mathsf{fma}\left(-1, x, -1\right)\right)}{x + -1}\right)\right)} \]

    if 0.33925097747799338 < x

    1. Initial program 58.9

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, \frac{x + -1}{x + 1}, \mathsf{fma}\left(-1, x, -1\right)\right)}{\left(x + 1\right) \cdot \frac{x + -1}{x + 1}}} \]
    3. Applied egg-rr58.9

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{-\left(\frac{1}{{x}^{2}} + 3 \cdot \frac{1}{x}\right)}\right)\right) \]
    5. Simplified0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -60568178728272.734:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-3 + \frac{2}{x}}{x + -1}\right)\right)\\ \mathbf{elif}\;x \leq 0.3392509774779934:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\mathsf{fma}\left(x, \frac{x + -1}{x + 1}, \mathsf{fma}\left(-1, x, -1\right)\right)}{x + -1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-1}{x \cdot x} + \frac{-3}{x}\right)\right)\\ \end{array} \]

Reproduce

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