?

Average Error: 14.6 → 0.4
Time: 17.8s
Precision: binary64
Cost: 20420

?

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

\mathbf{elif}\;x \leq 380000:\\
\;\;\;\;t_2 \cdot \left(\left(t_2 \cdot \left(t_0 \cdot t_3\right) - t_1 \cdot \left(t_2 \cdot t_3\right)\right) \cdot t_3\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{{x}^{2}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

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

    1. Initial program 29.4

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

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

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

      [Start]0.7

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

      rational_best_oopsla_all_46_json_45_simplify-82 [=>]0.7

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.7

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

      rational_best_oopsla_all_46_json_45_simplify-23 [=>]0.7

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

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

    if -240 < x < 3.8e5

    1. Initial program 0.1

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

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

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

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

      [Start]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-85 [<=]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-35 [<=]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-108 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-85 [=>]0.1

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

      rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.1

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

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

    if 3.8e5 < x

    1. Initial program 28.4

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

      \[\leadsto \color{blue}{\frac{-2}{{x}^{2}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Alternatives

Alternative 1
Error0.4
Cost13700
\[\begin{array}{l} t_0 := \frac{1}{1 + x}\\ t_1 := \frac{1}{x + -1}\\ t_2 := t_0 - t_1\\ t_3 := \frac{1}{t_2}\\ \mathbf{if}\;x \leq -2200:\\ \;\;\;\;-2 \cdot \left(\frac{1}{{x}^{4}} + \frac{1}{{x}^{2}}\right)\\ \mathbf{elif}\;x \leq 380000:\\ \;\;\;\;t_2 \cdot \left(\left(t_2 \cdot \left(t_0 \cdot t_3\right) - t_1 \cdot \left(t_2 \cdot t_3\right)\right) \cdot t_3\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{{x}^{2}}\\ \end{array} \]
Alternative 2
Error0.4
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_2 - t_0\\ t_4 := \frac{1}{t_3}\\ \mathbf{if}\;x \leq -260000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 380000:\\ \;\;\;\;t_3 \cdot \left(\left(t_3 \cdot \left(t_2 \cdot t_4\right) - t_0 \cdot \left(t_3 \cdot t_4\right)\right) \cdot t_4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error15.7
Cost840
\[\begin{array}{l} t_0 := \frac{1}{x} - \frac{1}{x - 1}\\ \mathbf{if}\;x \leq -2.1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.6:\\ \;\;\;\;1 + \left(\frac{1}{1 + x} + x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error14.6
Cost704
\[\frac{1}{x + 1} - \frac{1}{x - 1} \]
Alternative 5
Error57.3
Cost64
\[1 \]
Alternative 6
Error32.1
Cost64
\[2 \]

Error

Reproduce?

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