?

Average Error: 14.3 → 0.4
Time: 19.8s
Precision: binary64
Cost: 13768

?

\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \left(\frac{1}{{x}^{4}} + \frac{1}{{x}^{2}}\right) \cdot -2\\ t_1 := \frac{1}{1 + x}\\ \mathbf{if}\;x \leq -1750:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2000:\\ \;\;\;\;\left(1 + x\right) \cdot \left(t_1 \cdot t_1\right) - \frac{1}{x - 1}\\ \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 (* (+ (/ 1.0 (pow x 4.0)) (/ 1.0 (pow x 2.0))) -2.0))
        (t_1 (/ 1.0 (+ 1.0 x))))
   (if (<= x -1750.0)
     t_0
     (if (<= x 2000.0) (- (* (+ 1.0 x) (* t_1 t_1)) (/ 1.0 (- 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 = ((1.0 / pow(x, 4.0)) + (1.0 / pow(x, 2.0))) * -2.0;
	double t_1 = 1.0 / (1.0 + x);
	double tmp;
	if (x <= -1750.0) {
		tmp = t_0;
	} else if (x <= 2000.0) {
		tmp = ((1.0 + x) * (t_1 * t_1)) - (1.0 / (x - 1.0));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / (x + 1.0d0)) - (1.0d0 / (x - 1.0d0))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((1.0d0 / (x ** 4.0d0)) + (1.0d0 / (x ** 2.0d0))) * (-2.0d0)
    t_1 = 1.0d0 / (1.0d0 + x)
    if (x <= (-1750.0d0)) then
        tmp = t_0
    else if (x <= 2000.0d0) then
        tmp = ((1.0d0 + x) * (t_1 * t_1)) - (1.0d0 / (x - 1.0d0))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
}
public static double code(double x) {
	double t_0 = ((1.0 / Math.pow(x, 4.0)) + (1.0 / Math.pow(x, 2.0))) * -2.0;
	double t_1 = 1.0 / (1.0 + x);
	double tmp;
	if (x <= -1750.0) {
		tmp = t_0;
	} else if (x <= 2000.0) {
		tmp = ((1.0 + x) * (t_1 * t_1)) - (1.0 / (x - 1.0));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	return (1.0 / (x + 1.0)) - (1.0 / (x - 1.0))
def code(x):
	t_0 = ((1.0 / math.pow(x, 4.0)) + (1.0 / math.pow(x, 2.0))) * -2.0
	t_1 = 1.0 / (1.0 + x)
	tmp = 0
	if x <= -1750.0:
		tmp = t_0
	elif x <= 2000.0:
		tmp = ((1.0 + x) * (t_1 * t_1)) - (1.0 / (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(Float64(1.0 / (x ^ 4.0)) + Float64(1.0 / (x ^ 2.0))) * -2.0)
	t_1 = Float64(1.0 / Float64(1.0 + x))
	tmp = 0.0
	if (x <= -1750.0)
		tmp = t_0;
	elseif (x <= 2000.0)
		tmp = Float64(Float64(Float64(1.0 + x) * Float64(t_1 * t_1)) - Float64(1.0 / Float64(x - 1.0)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 / (x + 1.0)) - (1.0 / (x - 1.0));
end
function tmp_2 = code(x)
	t_0 = ((1.0 / (x ^ 4.0)) + (1.0 / (x ^ 2.0))) * -2.0;
	t_1 = 1.0 / (1.0 + x);
	tmp = 0.0;
	if (x <= -1750.0)
		tmp = t_0;
	elseif (x <= 2000.0)
		tmp = ((1.0 + x) * (t_1 * t_1)) - (1.0 / (x - 1.0));
	else
		tmp = t_0;
	end
	tmp_2 = 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[(N[(1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1750.0], t$95$0, If[LessEqual[x, 2000.0], N[(N[(N[(1.0 + x), $MachinePrecision] * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\frac{1}{x + 1} - \frac{1}{x - 1}
\begin{array}{l}
t_0 := \left(\frac{1}{{x}^{4}} + \frac{1}{{x}^{2}}\right) \cdot -2\\
t_1 := \frac{1}{1 + x}\\
\mathbf{if}\;x \leq -1750:\\
\;\;\;\;t_0\\

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

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


\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 x < -1750 or 2e3 < x

    1. Initial program 29.1

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

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{1}{1 + x} - \frac{1}{x + -1}}}{\left(\frac{1}{x + -1} - \frac{1}{1 + x}\right) \cdot \left(\frac{1}{x + -1} - \frac{1}{1 + x}\right)} \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{1 + x} - \frac{1}{x + -1}\right) \cdot \left(\left(\frac{1}{x + -1} - \frac{1}{1 + x}\right) \cdot \left(\frac{1}{x + -1} - \frac{1}{1 + x}\right)\right)\right)\right)} \]
    3. Taylor expanded in x around inf 0.9

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

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

      [Start]0.9

      \[ -\left(2 \cdot \frac{1}{{x}^{4}} + 2 \cdot \frac{1}{{x}^{2}}\right) \]

      rational_best-simplify-13 [=>]0.9

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

      rational_best-simplify-2 [=>]0.9

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

      rational_best-simplify-47 [=>]0.9

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

      rational_best-simplify-2 [=>]0.9

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

      rational_best-simplify-44 [=>]0.9

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

      rational_best-simplify-1 [=>]0.9

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

      metadata-eval [=>]0.9

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

    if -1750 < x < 2e3

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{1 + x}} \cdot \left(\frac{1}{1 + x} \cdot \frac{1}{1 + x}\right)} - \frac{1}{x - 1} \]
    3. Taylor expanded in x around 0 0.0

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

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

Alternatives

Alternative 1
Error0.5
Cost7496
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \frac{-2}{{x}^{2}}\\ t_2 := \frac{1}{x + -1}\\ t_3 := t_0 - t_2\\ t_4 := t_3 \cdot t_3\\ t_5 := t_2 - t_0\\ \mathbf{if}\;x \leq -350000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 400000:\\ \;\;\;\;\frac{1}{\left(t_4 \cdot t_4\right) \cdot \left(\frac{1}{t_3} \cdot \frac{1}{t_4}\right)} \cdot \left(t_5 \cdot t_5\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.5
Cost6920
\[\begin{array}{l} t_0 := \frac{1}{x + -1}\\ t_1 := \frac{-2}{{x}^{2}}\\ t_2 := \frac{1}{1 + x}\\ t_3 := t_0 - t_2\\ t_4 := \frac{1}{t_3}\\ \mathbf{if}\;x \leq -350000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 400000:\\ \;\;\;\;\frac{1}{t_4 \cdot \left(t_3 \cdot \left(t_4 \cdot \left(t_3 \cdot \left(t_2 - t_0\right)\right)\right)\right)} \cdot \left(t_3 \cdot t_3\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error15.5
Cost840
\[\begin{array}{l} t_0 := \frac{1}{x} - \frac{1}{x - 1}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\left(1 - \frac{1}{x + -1}\right) - x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error15.5
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -0.6:\\ \;\;\;\;\frac{1}{x + 1} - \frac{1}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\left(1 - \frac{1}{x + -1}\right) - x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} - \frac{1}{x - 1}\\ \end{array} \]
Alternative 5
Error14.3
Cost704
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
Alternative 6
Error57.1
Cost64
\[1 \]
Alternative 7
Error31.4
Cost64
\[2 \]

Error

Reproduce?

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