Average Error: 29.7 → 0.8
Time: 5.5s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 1.8052226380405045 \cdot 10^{-13}:\\ \;\;\;\;\left(\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\ \mathbf{else}:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 1.8052226380405045e-13)
   (- (- (/ -3.0 x) (+ (pow x -2.0) (/ 3.0 (pow x 3.0)))) (/ 1.0 (pow x 4.0)))
   (+ 1.0 (* x (+ x 3.0)))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1.8052226380405045e-13) {
		tmp = ((-3.0 / x) - (pow(x, -2.0) + (3.0 / pow(x, 3.0)))) - (1.0 / pow(x, 4.0));
	} else {
		tmp = 1.0 + (x * (x + 3.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) :: tmp
    if (((x / (x + 1.0d0)) - ((x + 1.0d0) / (x - 1.0d0))) <= 1.8052226380405045d-13) then
        tmp = (((-3.0d0) / x) - ((x ** (-2.0d0)) + (3.0d0 / (x ** 3.0d0)))) - (1.0d0 / (x ** 4.0d0))
    else
        tmp = 1.0d0 + (x * (x + 3.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 tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1.8052226380405045e-13) {
		tmp = ((-3.0 / x) - (Math.pow(x, -2.0) + (3.0 / Math.pow(x, 3.0)))) - (1.0 / Math.pow(x, 4.0));
	} else {
		tmp = 1.0 + (x * (x + 3.0));
	}
	return tmp;
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x):
	tmp = 0
	if ((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1.8052226380405045e-13:
		tmp = ((-3.0 / x) - (math.pow(x, -2.0) + (3.0 / math.pow(x, 3.0)))) - (1.0 / math.pow(x, 4.0))
	else:
		tmp = 1.0 + (x * (x + 3.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)
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x - 1.0))) <= 1.8052226380405045e-13)
		tmp = Float64(Float64(Float64(-3.0 / x) - Float64((x ^ -2.0) + Float64(3.0 / (x ^ 3.0)))) - Float64(1.0 / (x ^ 4.0)));
	else
		tmp = Float64(1.0 + Float64(x * Float64(x + 3.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)
	tmp = 0.0;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 1.8052226380405045e-13)
		tmp = ((-3.0 / x) - ((x ^ -2.0) + (3.0 / (x ^ 3.0)))) - (1.0 / (x ^ 4.0));
	else
		tmp = 1.0 + (x * (x + 3.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_] := If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.8052226380405045e-13], N[(N[(N[(-3.0 / x), $MachinePrecision] - N[(N[Power[x, -2.0], $MachinePrecision] + N[(3.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 1.8052226380405045 \cdot 10^{-13}:\\
\;\;\;\;\left(\frac{-3}{x} - \left({x}^{-2} + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}\\

\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\


\end{array}

Error

Bits error versus x

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))) < 1.80522e-13

    1. Initial program 59.4

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

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

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

      \[\leadsto \left(\frac{-3}{x} - \left(\frac{1}{\color{blue}{{x}^{2}}} + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}} \]
    5. Applied pow-flip_binary640.2

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

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

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

    1. Initial program 0.4

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

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

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

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

Reproduce

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