?

Average Error: 46.67% → 0.35%
Time: 8.5s
Precision: binary64
Cost: 43204

?

\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{-1 - x}{x + -1}\\ t_1 := {t_0}^{2}\\ t_2 := \frac{x}{-1 - x}\\ t_3 := {t_2}^{2}\\ \mathbf{if}\;\frac{x}{x + 1} + t_0 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{3 + \frac{-2}{x}}{1 - x}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 \cdot t_1 - t_3 \cdot t_3}{\left(t_0 + t_2\right) \cdot \left(t_1 + t_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 (/ (- -1.0 x) (+ x -1.0)))
        (t_1 (pow t_0 2.0))
        (t_2 (/ x (- -1.0 x)))
        (t_3 (pow t_2 2.0)))
   (if (<= (+ (/ x (+ x 1.0)) t_0) 5e-8)
     (/ (+ 3.0 (/ -2.0 x)) (- 1.0 x))
     (/ (- (* t_1 t_1) (* t_3 t_3)) (* (+ t_0 t_2) (+ t_1 t_3))))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = (-1.0 - x) / (x + -1.0);
	double t_1 = pow(t_0, 2.0);
	double t_2 = x / (-1.0 - x);
	double t_3 = pow(t_2, 2.0);
	double tmp;
	if (((x / (x + 1.0)) + t_0) <= 5e-8) {
		tmp = (3.0 + (-2.0 / x)) / (1.0 - x);
	} else {
		tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3));
	}
	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
    t_0 = ((-1.0d0) - x) / (x + (-1.0d0))
    t_1 = t_0 ** 2.0d0
    t_2 = x / ((-1.0d0) - x)
    t_3 = t_2 ** 2.0d0
    if (((x / (x + 1.0d0)) + t_0) <= 5d-8) then
        tmp = (3.0d0 + ((-2.0d0) / x)) / (1.0d0 - x)
    else
        tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3))
    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 = (-1.0 - x) / (x + -1.0);
	double t_1 = Math.pow(t_0, 2.0);
	double t_2 = x / (-1.0 - x);
	double t_3 = Math.pow(t_2, 2.0);
	double tmp;
	if (((x / (x + 1.0)) + t_0) <= 5e-8) {
		tmp = (3.0 + (-2.0 / x)) / (1.0 - x);
	} else {
		tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3));
	}
	return tmp;
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x):
	t_0 = (-1.0 - x) / (x + -1.0)
	t_1 = math.pow(t_0, 2.0)
	t_2 = x / (-1.0 - x)
	t_3 = math.pow(t_2, 2.0)
	tmp = 0
	if ((x / (x + 1.0)) + t_0) <= 5e-8:
		tmp = (3.0 + (-2.0 / x)) / (1.0 - x)
	else:
		tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3))
	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(-1.0 - x) / Float64(x + -1.0))
	t_1 = t_0 ^ 2.0
	t_2 = Float64(x / Float64(-1.0 - x))
	t_3 = t_2 ^ 2.0
	tmp = 0.0
	if (Float64(Float64(x / Float64(x + 1.0)) + t_0) <= 5e-8)
		tmp = Float64(Float64(3.0 + Float64(-2.0 / x)) / Float64(1.0 - x));
	else
		tmp = Float64(Float64(Float64(t_1 * t_1) - Float64(t_3 * t_3)) / Float64(Float64(t_0 + t_2) * Float64(t_1 + t_3)));
	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 = (-1.0 - x) / (x + -1.0);
	t_1 = t_0 ^ 2.0;
	t_2 = x / (-1.0 - x);
	t_3 = t_2 ^ 2.0;
	tmp = 0.0;
	if (((x / (x + 1.0)) + t_0) <= 5e-8)
		tmp = (3.0 + (-2.0 / x)) / (1.0 - x);
	else
		tmp = ((t_1 * t_1) - (t_3 * t_3)) / ((t_0 + t_2) * (t_1 + t_3));
	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[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[t$95$2, 2.0], $MachinePrecision]}, If[LessEqual[N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], 5e-8], N[(N[(3.0 + N[(-2.0 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$1 * t$95$1), $MachinePrecision] - N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$0 + t$95$2), $MachinePrecision] * N[(t$95$1 + t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{-1 - x}{x + -1}\\
t_1 := {t_0}^{2}\\
t_2 := \frac{x}{-1 - x}\\
t_3 := {t_2}^{2}\\
\mathbf{if}\;\frac{x}{x + 1} + t_0 \leq 5 \cdot 10^{-8}:\\
\;\;\;\;\frac{3 + \frac{-2}{x}}{1 - x}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1 \cdot t_1 - t_3 \cdot t_3}{\left(t_0 + t_2\right) \cdot \left(t_1 + t_3\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))) < 4.9999999999999998e-8

    1. Initial program 92.48

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Simplified92.48

      \[\leadsto \color{blue}{\frac{-1 - x}{x + -1} - \frac{x}{-1 - x}} \]
      Proof

      [Start]92.48

      \[ \frac{x}{x + 1} - \frac{x + 1}{x - 1} \]

      sub-neg [=>]92.48

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

      +-commutative [=>]92.48

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

      remove-double-neg [<=]92.48

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

      sub-neg [<=]92.48

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

      distribute-neg-frac [=>]92.48

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

      neg-sub0 [=>]92.48

      \[ \frac{\color{blue}{0 - \left(x + 1\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right) \]

      +-commutative [=>]92.48

      \[ \frac{0 - \color{blue}{\left(1 + x\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right) \]

      associate--r+ [=>]92.48

      \[ \frac{\color{blue}{\left(0 - 1\right) - x}}{x - 1} - \left(-\frac{x}{x + 1}\right) \]

      metadata-eval [=>]92.48

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

      sub-neg [=>]92.48

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

      metadata-eval [=>]92.48

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

      /-rgt-identity [<=]92.48

      \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{-\frac{x}{x + 1}}{1}} \]

      neg-mul-1 [=>]92.48

      \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{-1 \cdot \frac{x}{x + 1}}}{1} \]

      metadata-eval [<=]92.48

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

      *-commutative [=>]92.48

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

      associate-/l* [=>]92.48

      \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{\frac{x}{x + 1}}{\frac{1}{-1}}} \]

      metadata-eval [=>]92.48

      \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\frac{1}{\color{blue}{-1}}} \]

      metadata-eval [=>]92.48

      \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}} \]

      metadata-eval [<=]92.48

      \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}} \]

      associate-/l/ [=>]92.48

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

      metadata-eval [=>]92.48

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

      neg-mul-1 [<=]92.48

      \[ \frac{-1 - x}{x + -1} - \frac{x}{\color{blue}{-\left(x + 1\right)}} \]
    3. Applied egg-rr91.5

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

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

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

      [Start]0.51

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

      associate-*r/ [=>]0.51

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

      metadata-eval [=>]0.51

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

      \[\leadsto \frac{3 - \frac{2}{x}}{\color{blue}{1 + -1 \cdot x}} \]
    7. Simplified0.51

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

      [Start]0.51

      \[ \frac{3 - \frac{2}{x}}{1 + -1 \cdot x} \]

      mul-1-neg [=>]0.51

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

      sub-neg [<=]0.51

      \[ \frac{3 - \frac{2}{x}}{\color{blue}{1 - x}} \]

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

    1. Initial program 0.18

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Simplified0.18

      \[\leadsto \color{blue}{\frac{-1 - x}{x + -1} - \frac{x}{-1 - x}} \]
      Proof

      [Start]0.18

      \[ \frac{x}{x + 1} - \frac{x + 1}{x - 1} \]

      sub-neg [=>]0.18

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

      +-commutative [=>]0.18

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

      remove-double-neg [<=]0.18

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

      sub-neg [<=]0.18

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

      distribute-neg-frac [=>]0.18

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

      neg-sub0 [=>]0.18

      \[ \frac{\color{blue}{0 - \left(x + 1\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right) \]

      +-commutative [=>]0.18

      \[ \frac{0 - \color{blue}{\left(1 + x\right)}}{x - 1} - \left(-\frac{x}{x + 1}\right) \]

      associate--r+ [=>]0.18

      \[ \frac{\color{blue}{\left(0 - 1\right) - x}}{x - 1} - \left(-\frac{x}{x + 1}\right) \]

      metadata-eval [=>]0.18

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

      sub-neg [=>]0.18

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

      metadata-eval [=>]0.18

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

      /-rgt-identity [<=]0.18

      \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{-\frac{x}{x + 1}}{1}} \]

      neg-mul-1 [=>]0.18

      \[ \frac{-1 - x}{x + -1} - \frac{\color{blue}{-1 \cdot \frac{x}{x + 1}}}{1} \]

      metadata-eval [<=]0.18

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

      *-commutative [=>]0.18

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

      associate-/l* [=>]0.18

      \[ \frac{-1 - x}{x + -1} - \color{blue}{\frac{\frac{x}{x + 1}}{\frac{1}{-1}}} \]

      metadata-eval [=>]0.18

      \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\frac{1}{\color{blue}{-1}}} \]

      metadata-eval [=>]0.18

      \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}} \]

      metadata-eval [<=]0.18

      \[ \frac{-1 - x}{x + -1} - \frac{\frac{x}{x + 1}}{\color{blue}{-1}} \]

      associate-/l/ [=>]0.18

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

      metadata-eval [=>]0.18

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

      neg-mul-1 [<=]0.18

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

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

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

Alternatives

Alternative 1
Error0.35%
Cost14532
\[\begin{array}{l} t_0 := \frac{-1 - x}{x + -1}\\ \mathbf{if}\;\frac{x}{x + 1} + t_0 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{3 + \frac{-2}{x}}{1 - x}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{t_0 - \frac{x}{-1 - x}}\right)\\ \end{array} \]
Alternative 2
Error0.34%
Cost1732
\[\begin{array}{l} t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\frac{3 + \frac{-2}{x}}{1 - x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.77%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \end{array} \]
Alternative 4
Error0.76%
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{3 + \frac{-2}{x}}{1 - x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \end{array} \]
Alternative 5
Error0.77%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \end{array} \]
Alternative 6
Error1.21%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 7
Error1.36%
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.92%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 9
Error49.91%
Cost64
\[1 \]

Error

Reproduce?

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