Average Error: 29.3 → 0.1
Time: 2.9s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ \mathbf{if}\;t_0 + \frac{-1 - x}{x + -1} \leq 0.001:\\ \;\;\;\;\frac{-1}{x \cdot x} + \left(\left(\frac{-3}{x} + \frac{-1}{{x}^{4}}\right) + \frac{-3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 - \log \left(e^{\frac{x + 1}{x + -1}}\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ x (+ x 1.0))))
   (if (<= (+ t_0 (/ (- -1.0 x) (+ x -1.0))) 0.001)
     (+
      (/ -1.0 (* x x))
      (+ (+ (/ -3.0 x) (/ -1.0 (pow x 4.0))) (/ -3.0 (pow x 3.0))))
     (- t_0 (log (exp (/ (+ x 1.0) (+ x -1.0))))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = x / (x + 1.0);
	double tmp;
	if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 0.001) {
		tmp = (-1.0 / (x * x)) + (((-3.0 / x) + (-1.0 / pow(x, 4.0))) + (-3.0 / pow(x, 3.0)));
	} else {
		tmp = t_0 - log(exp(((x + 1.0) / (x + -1.0))));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x / (x + 1.0d0)
    if ((t_0 + (((-1.0d0) - x) / (x + (-1.0d0)))) <= 0.001d0) then
        tmp = ((-1.0d0) / (x * x)) + ((((-3.0d0) / x) + ((-1.0d0) / (x ** 4.0d0))) + ((-3.0d0) / (x ** 3.0d0)))
    else
        tmp = t_0 - log(exp(((x + 1.0d0) / (x + (-1.0d0)))))
    end if
    code = tmp
end function
public static double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
public static double code(double x) {
	double t_0 = x / (x + 1.0);
	double tmp;
	if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 0.001) {
		tmp = (-1.0 / (x * x)) + (((-3.0 / x) + (-1.0 / Math.pow(x, 4.0))) + (-3.0 / Math.pow(x, 3.0)));
	} else {
		tmp = t_0 - Math.log(Math.exp(((x + 1.0) / (x + -1.0))));
	}
	return tmp;
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x):
	t_0 = x / (x + 1.0)
	tmp = 0
	if (t_0 + ((-1.0 - x) / (x + -1.0))) <= 0.001:
		tmp = (-1.0 / (x * x)) + (((-3.0 / x) + (-1.0 / math.pow(x, 4.0))) + (-3.0 / math.pow(x, 3.0)))
	else:
		tmp = t_0 - math.log(math.exp(((x + 1.0) / (x + -1.0))))
	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)
	t_0 = Float64(x / Float64(x + 1.0))
	tmp = 0.0
	if (Float64(t_0 + Float64(Float64(-1.0 - x) / Float64(x + -1.0))) <= 0.001)
		tmp = Float64(Float64(-1.0 / Float64(x * x)) + Float64(Float64(Float64(-3.0 / x) + Float64(-1.0 / (x ^ 4.0))) + Float64(-3.0 / (x ^ 3.0))));
	else
		tmp = Float64(t_0 - log(exp(Float64(Float64(x + 1.0) / Float64(x + -1.0)))));
	end
	return tmp
end
function tmp = code(x)
	tmp = (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
end
function tmp_2 = code(x)
	t_0 = x / (x + 1.0);
	tmp = 0.0;
	if ((t_0 + ((-1.0 - x) / (x + -1.0))) <= 0.001)
		tmp = (-1.0 / (x * x)) + (((-3.0 / x) + (-1.0 / (x ^ 4.0))) + (-3.0 / (x ^ 3.0)));
	else
		tmp = t_0 - log(exp(((x + 1.0) / (x + -1.0))));
	end
	tmp_2 = 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_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(-1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-3.0 / x), $MachinePrecision] + N[(-1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-3.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[Log[N[Exp[N[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
\mathbf{if}\;t_0 + \frac{-1 - x}{x + -1} \leq 0.001:\\
\;\;\;\;\frac{-1}{x \cdot x} + \left(\left(\frac{-3}{x} + \frac{-1}{{x}^{4}}\right) + \frac{-3}{{x}^{3}}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0 - \log \left(e^{\frac{x + 1}{x + -1}}\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1e-3

    1. Initial program 58.8

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

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

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

    if 1e-3 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 0.001:\\ \;\;\;\;\frac{-1}{x \cdot x} + \left(\left(\frac{-3}{x} + \frac{-1}{{x}^{4}}\right) + \frac{-3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1} - \log \left(e^{\frac{x + 1}{x + -1}}\right)\\ \end{array} \]

Reproduce

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