?

Average Error: 29.7 → 0.2
Time: 13.0s
Precision: binary64
Cost: 20808

?

\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x + 1}{x + -1}\\ t_1 := \frac{x + 1}{1 - x}\\ t_2 := \frac{x}{x + 1}\\ t_3 := t_2 + t_0\\ \mathbf{if}\;x \leq -98000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 2000:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_3 \ne 0:\\ \;\;\;\;\frac{t_2 \cdot t_2 - t_1 \cdot t_1}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_2 - t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{-3}{x} - \frac{1}{{x}^{2}}\right) + \left(\left(-\frac{1}{{x}^{4}}\right) + -3 \cdot \frac{1}{{x}^{3}}\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 1.0) (+ x -1.0)))
        (t_1 (/ (+ x 1.0) (- 1.0 x)))
        (t_2 (/ x (+ x 1.0)))
        (t_3 (+ t_2 t_0)))
   (if (<= x -98000000.0)
     (/ -3.0 x)
     (if (<= x 2000.0)
       (if (!= t_3 0.0) (/ (- (* t_2 t_2) (* t_1 t_1)) t_3) (- t_2 t_0))
       (+
        (- (/ -3.0 x) (/ 1.0 (pow x 2.0)))
        (+ (- (/ 1.0 (pow x 4.0))) (* -3.0 (/ 1.0 (pow x 3.0)))))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = (x + 1.0) / (x + -1.0);
	double t_1 = (x + 1.0) / (1.0 - x);
	double t_2 = x / (x + 1.0);
	double t_3 = t_2 + t_0;
	double tmp;
	if (x <= -98000000.0) {
		tmp = -3.0 / x;
	} else if (x <= 2000.0) {
		double tmp_1;
		if (t_3 != 0.0) {
			tmp_1 = ((t_2 * t_2) - (t_1 * t_1)) / t_3;
		} else {
			tmp_1 = t_2 - t_0;
		}
		tmp = tmp_1;
	} else {
		tmp = ((-3.0 / x) - (1.0 / pow(x, 2.0))) + (-(1.0 / pow(x, 4.0)) + (-3.0 * (1.0 / pow(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) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    real(8) :: tmp_1
    t_0 = (x + 1.0d0) / (x + (-1.0d0))
    t_1 = (x + 1.0d0) / (1.0d0 - x)
    t_2 = x / (x + 1.0d0)
    t_3 = t_2 + t_0
    if (x <= (-98000000.0d0)) then
        tmp = (-3.0d0) / x
    else if (x <= 2000.0d0) then
        if (t_3 /= 0.0d0) then
            tmp_1 = ((t_2 * t_2) - (t_1 * t_1)) / t_3
        else
            tmp_1 = t_2 - t_0
        end if
        tmp = tmp_1
    else
        tmp = (((-3.0d0) / x) - (1.0d0 / (x ** 2.0d0))) + (-(1.0d0 / (x ** 4.0d0)) + ((-3.0d0) * (1.0d0 / (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 t_0 = (x + 1.0) / (x + -1.0);
	double t_1 = (x + 1.0) / (1.0 - x);
	double t_2 = x / (x + 1.0);
	double t_3 = t_2 + t_0;
	double tmp;
	if (x <= -98000000.0) {
		tmp = -3.0 / x;
	} else if (x <= 2000.0) {
		double tmp_1;
		if (t_3 != 0.0) {
			tmp_1 = ((t_2 * t_2) - (t_1 * t_1)) / t_3;
		} else {
			tmp_1 = t_2 - t_0;
		}
		tmp = tmp_1;
	} else {
		tmp = ((-3.0 / x) - (1.0 / Math.pow(x, 2.0))) + (-(1.0 / Math.pow(x, 4.0)) + (-3.0 * (1.0 / Math.pow(x, 3.0))));
	}
	return tmp;
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x):
	t_0 = (x + 1.0) / (x + -1.0)
	t_1 = (x + 1.0) / (1.0 - x)
	t_2 = x / (x + 1.0)
	t_3 = t_2 + t_0
	tmp = 0
	if x <= -98000000.0:
		tmp = -3.0 / x
	elif x <= 2000.0:
		tmp_1 = 0
		if t_3 != 0.0:
			tmp_1 = ((t_2 * t_2) - (t_1 * t_1)) / t_3
		else:
			tmp_1 = t_2 - t_0
		tmp = tmp_1
	else:
		tmp = ((-3.0 / x) - (1.0 / math.pow(x, 2.0))) + (-(1.0 / math.pow(x, 4.0)) + (-3.0 * (1.0 / math.pow(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)
	t_0 = Float64(Float64(x + 1.0) / Float64(x + -1.0))
	t_1 = Float64(Float64(x + 1.0) / Float64(1.0 - x))
	t_2 = Float64(x / Float64(x + 1.0))
	t_3 = Float64(t_2 + t_0)
	tmp = 0.0
	if (x <= -98000000.0)
		tmp = Float64(-3.0 / x);
	elseif (x <= 2000.0)
		tmp_1 = 0.0
		if (t_3 != 0.0)
			tmp_1 = Float64(Float64(Float64(t_2 * t_2) - Float64(t_1 * t_1)) / t_3);
		else
			tmp_1 = Float64(t_2 - t_0);
		end
		tmp = tmp_1;
	else
		tmp = Float64(Float64(Float64(-3.0 / x) - Float64(1.0 / (x ^ 2.0))) + Float64(Float64(-Float64(1.0 / (x ^ 4.0))) + Float64(-3.0 * Float64(1.0 / (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_3 = code(x)
	t_0 = (x + 1.0) / (x + -1.0);
	t_1 = (x + 1.0) / (1.0 - x);
	t_2 = x / (x + 1.0);
	t_3 = t_2 + t_0;
	tmp = 0.0;
	if (x <= -98000000.0)
		tmp = -3.0 / x;
	elseif (x <= 2000.0)
		tmp_2 = 0.0;
		if (t_3 ~= 0.0)
			tmp_2 = ((t_2 * t_2) - (t_1 * t_1)) / t_3;
		else
			tmp_2 = t_2 - t_0;
		end
		tmp = tmp_2;
	else
		tmp = ((-3.0 / x) - (1.0 / (x ^ 2.0))) + (-(1.0 / (x ^ 4.0)) + (-3.0 * (1.0 / (x ^ 3.0))));
	end
	tmp_3 = 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[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + 1.0), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$2 + t$95$0), $MachinePrecision]}, If[LessEqual[x, -98000000.0], N[(-3.0 / x), $MachinePrecision], If[LessEqual[x, 2000.0], If[Unequal[t$95$3, 0.0], N[(N[(N[(t$95$2 * t$95$2), $MachinePrecision] - N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] / t$95$3), $MachinePrecision], N[(t$95$2 - t$95$0), $MachinePrecision]], N[(N[(N[(-3.0 / x), $MachinePrecision] - N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[((-N[(1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]) + N[(-3.0 * N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x + 1}{x + -1}\\
t_1 := \frac{x + 1}{1 - x}\\
t_2 := \frac{x}{x + 1}\\
t_3 := t_2 + t_0\\
\mathbf{if}\;x \leq -98000000:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{elif}\;x \leq 2000:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;t_3 \ne 0:\\
\;\;\;\;\frac{t_2 \cdot t_2 - t_1 \cdot t_1}{t_3}\\

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


\end{array}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{-3}{x} - \frac{1}{{x}^{2}}\right) + \left(\left(-\frac{1}{{x}^{4}}\right) + -3 \cdot \frac{1}{{x}^{3}}\right)\\


\end{array}

Error?

Derivation?

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

    1. Initial program 59.9

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

      \[\leadsto \color{blue}{\frac{-3}{x}} \]

    if -9.8e7 < x < 2e3

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\frac{x}{x + 1} + \frac{x + 1}{x + -1} \ne 0:\\ \;\;\;\;\frac{\frac{x}{x + 1} \cdot \frac{x}{x + 1} - \frac{x + 1}{1 - x} \cdot \frac{x + 1}{1 - x}}{\frac{x}{x + 1} + \frac{x + 1}{x + -1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1} - \frac{x + 1}{x + -1}\\ } \end{array}} \]

    if 2e3 < x

    1. Initial program 59.2

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

      \[\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}{\left(-\frac{1}{{x}^{4}}\right) - \left(\left(\frac{1}{{x}^{2}} + 3 \cdot \frac{1}{x}\right) - -3 \cdot \frac{1}{{x}^{3}}\right)} \]
      Proof

      [Start]0.3

      \[ -\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) \]

      rational_best-simplify-115 [=>]0.3

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

      rational_best-simplify-1 [<=]0.3

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

      rational_best-simplify-62 [=>]0.3

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

      rational_best-simplify-64 [=>]0.3

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

      rational_best-simplify-62 [=>]0.3

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

      rational_best-simplify-52 [=>]0.3

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

      metadata-eval [=>]0.3

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

      rational_best-simplify-3 [=>]0.3

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

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

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

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

Alternatives

Alternative 1
Error0.3
Cost9168
\[\begin{array}{l} t_0 := \frac{x + 1}{x + -1}\\ t_1 := t_0 \cdot t_0\\ t_2 := \frac{x}{x + 1}\\ t_3 := t_2 \cdot t_2\\ t_4 := t_3 + t_1\\ t_5 := t_2 + t_0\\ \mathbf{if}\;x \leq -280000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 160000000:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_5 \ne 0:\\ \;\;\;\;\frac{\begin{array}{l} \mathbf{if}\;t_4 \ne 0:\\ \;\;\;\;\frac{t_2 \cdot \frac{\frac{x \cdot x}{x + 1} \cdot x}{\left(x + 1\right) \cdot \left(x + 1\right)} - t_1 \cdot t_1}{t_4}\\ \mathbf{else}:\\ \;\;\;\;t_3 - t_1\\ \end{array}}{t_5}\\ \mathbf{else}:\\ \;\;\;\;t_2 - t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 2
Error0.3
Cost8016
\[\begin{array}{l} t_0 := \frac{x + 1}{x + -1}\\ t_1 := \frac{x}{-1 - x}\\ t_2 := \frac{x + 1}{1 - x}\\ t_3 := t_2 \cdot \left(-t_2\right)\\ t_4 := \frac{x}{x + 1}\\ t_5 := t_4 + t_0\\ t_6 := \frac{-1 - x}{x + -1}\\ t_7 := t_6 \cdot t_6\\ \mathbf{if}\;x \leq -90000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 160000000:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_5 \ne 0:\\ \;\;\;\;\frac{\begin{array}{l} \mathbf{if}\;t_3 \ne 0:\\ \;\;\;\;\frac{t_7 \cdot t_7 - t_7 \cdot \left(t_1 \cdot t_1\right)}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_4 \cdot t_4 - t_0 \cdot t_0\\ \end{array}}{t_5}\\ \mathbf{else}:\\ \;\;\;\;t_4 - t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 3
Error0.3
Cost3788
\[\begin{array}{l} t_0 := \frac{x + 1}{x + -1}\\ t_1 := \frac{x + 1}{1 - x}\\ t_2 := \frac{x}{x + 1}\\ t_3 := t_2 + t_0\\ \mathbf{if}\;x \leq -98000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 170000000:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_3 \ne 0:\\ \;\;\;\;\frac{t_2 \cdot t_2 - t_1 \cdot t_1}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_2 - t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 4
Error0.3
Cost3788
\[\begin{array}{l} t_0 := \frac{x + 1}{x + -1}\\ t_1 := \frac{x + 1}{1 - x}\\ t_2 := \frac{x}{x + 1}\\ t_3 := t_2 + t_0\\ \mathbf{if}\;x \leq -124000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 165000000:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t_3 \ne 0:\\ \;\;\;\;\frac{\frac{\frac{x \cdot x}{x + 1}}{x + 1} - t_1 \cdot t_1}{t_3}\\ \mathbf{else}:\\ \;\;\;\;t_2 - t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 5
Error0.3
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -115000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 165000000:\\ \;\;\;\;\frac{x}{x + 1} - \frac{x + 1}{x - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 6
Error0.9
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x - \left(-2 \cdot x - 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 7
Error0.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 - x \cdot -3\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 8
Error1.3
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x - -1\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 9
Error31.9
Cost64
\[1 \]

Error

Reproduce?

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