Average Error: 28.7 → 0.2
Time: 9.2s
Precision: binary64
Cost: 14280
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x + -1}{x + 1}\\ \mathbf{if}\;x \leq -230000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 2400:\\ \;\;\;\;\frac{t_0 + \frac{-1 - x}{x}}{t_0 \cdot \frac{x + 1}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{{x}^{4}} + \left(\left(\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\right) + \frac{-3}{{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))))
   (if (<= x -230000000.0)
     (/ -3.0 x)
     (if (<= x 2400.0)
       (/ (+ t_0 (/ (- -1.0 x) x)) (* t_0 (/ (+ x 1.0) x)))
       (+
        (/ -1.0 (pow x 4.0))
        (+ (+ (/ -3.0 x) (/ (/ -1.0 x) x)) (/ -3.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 tmp;
	if (x <= -230000000.0) {
		tmp = -3.0 / x;
	} else if (x <= 2400.0) {
		tmp = (t_0 + ((-1.0 - x) / x)) / (t_0 * ((x + 1.0) / x));
	} else {
		tmp = (-1.0 / pow(x, 4.0)) + (((-3.0 / x) + ((-1.0 / x) / x)) + (-3.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) :: tmp
    t_0 = (x + (-1.0d0)) / (x + 1.0d0)
    if (x <= (-230000000.0d0)) then
        tmp = (-3.0d0) / x
    else if (x <= 2400.0d0) then
        tmp = (t_0 + (((-1.0d0) - x) / x)) / (t_0 * ((x + 1.0d0) / x))
    else
        tmp = ((-1.0d0) / (x ** 4.0d0)) + ((((-3.0d0) / x) + (((-1.0d0) / x) / x)) + ((-3.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 tmp;
	if (x <= -230000000.0) {
		tmp = -3.0 / x;
	} else if (x <= 2400.0) {
		tmp = (t_0 + ((-1.0 - x) / x)) / (t_0 * ((x + 1.0) / x));
	} else {
		tmp = (-1.0 / Math.pow(x, 4.0)) + (((-3.0 / x) + ((-1.0 / x) / x)) + (-3.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)
	tmp = 0
	if x <= -230000000.0:
		tmp = -3.0 / x
	elif x <= 2400.0:
		tmp = (t_0 + ((-1.0 - x) / x)) / (t_0 * ((x + 1.0) / x))
	else:
		tmp = (-1.0 / math.pow(x, 4.0)) + (((-3.0 / x) + ((-1.0 / x) / x)) + (-3.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))
	tmp = 0.0
	if (x <= -230000000.0)
		tmp = Float64(-3.0 / x);
	elseif (x <= 2400.0)
		tmp = Float64(Float64(t_0 + Float64(Float64(-1.0 - x) / x)) / Float64(t_0 * Float64(Float64(x + 1.0) / x)));
	else
		tmp = Float64(Float64(-1.0 / (x ^ 4.0)) + Float64(Float64(Float64(-3.0 / x) + Float64(Float64(-1.0 / x) / x)) + Float64(-3.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_2 = code(x)
	t_0 = (x + -1.0) / (x + 1.0);
	tmp = 0.0;
	if (x <= -230000000.0)
		tmp = -3.0 / x;
	elseif (x <= 2400.0)
		tmp = (t_0 + ((-1.0 - x) / x)) / (t_0 * ((x + 1.0) / x));
	else
		tmp = (-1.0 / (x ^ 4.0)) + (((-3.0 / x) + ((-1.0 / x) / x)) + (-3.0 / (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_] := Block[{t$95$0 = N[(N[(x + -1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -230000000.0], N[(-3.0 / x), $MachinePrecision], If[LessEqual[x, 2400.0], N[(N[(t$95$0 + N[(N[(-1.0 - x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-3.0 / x), $MachinePrecision] + N[(N[(-1.0 / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] + N[(-3.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x + -1}{x + 1}\\
\mathbf{if}\;x \leq -230000000:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{elif}\;x \leq 2400:\\
\;\;\;\;\frac{t_0 + \frac{-1 - x}{x}}{t_0 \cdot \frac{x + 1}{x}}\\

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


\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 < -2.3e8

    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 -2.3e8 < x < 2400

    1. Initial program 0.2

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

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

    if 2400 < x

    1. Initial program 59.0

      \[\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.0

      \[\leadsto \color{blue}{\frac{-1}{{x}^{4}} + \left(\left(\frac{-3}{x} - \frac{\frac{1}{x}}{x}\right) + \frac{-3}{{x}^{3}}\right)} \]
      Proof
      (+.f64 (/.f64 -1 (pow.f64 x 4)) (+.f64 (-.f64 (/.f64 -3 x) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 1)) (pow.f64 x 4)) (+.f64 (-.f64 (/.f64 -3 x) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 1 (pow.f64 x 4)))) (+.f64 (-.f64 (/.f64 -3 x) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (-.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 3)) x) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (-.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 3 x))) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (-.f64 (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 3 1)) x)) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (-.f64 (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 3 (/.f64 1 x)))) (/.f64 (/.f64 1 x) x)) (/.f64 -3 (pow.f64 x 3)))): 43 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (-.f64 (neg.f64 (*.f64 3 (/.f64 1 x))) (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 x x)))) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (-.f64 (neg.f64 (*.f64 3 (/.f64 1 x))) (/.f64 1 (Rewrite<= unpow2_binary64 (pow.f64 x 2)))) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 3 (/.f64 1 x))) (neg.f64 (/.f64 1 (pow.f64 x 2))))) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 2))) (neg.f64 (*.f64 3 (/.f64 1 x))))) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x))))) (/.f64 -3 (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))) (/.f64 (Rewrite<= metadata-eval (neg.f64 3)) (pow.f64 x 3)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 3 (pow.f64 x 3)))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))) (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 3 1)) (pow.f64 x 3))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (+.f64 (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))) (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 3 (/.f64 1 (pow.f64 x 3))))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x))) (*.f64 3 (/.f64 1 (pow.f64 x 3))))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (neg.f64 (Rewrite=> associate-+l+_binary64 (+.f64 (/.f64 1 (pow.f64 x 2)) (+.f64 (*.f64 3 (/.f64 1 x)) (*.f64 3 (/.f64 1 (pow.f64 x 3)))))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 4))) (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3))) (*.f64 3 (/.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 4)) (+.f64 (/.f64 1 (pow.f64 x 2)) (+.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3))) (*.f64 3 (/.f64 1 x))))))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error0.2
Cost8072
\[\begin{array}{l} t_0 := \frac{x + -1}{x + 1}\\ \mathbf{if}\;x \leq -230000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 2400:\\ \;\;\;\;\frac{t_0 + \frac{-1 - x}{x}}{t_0 \cdot \frac{x + 1}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(3 + \frac{2}{x \cdot x}\right) + \left(\frac{-2}{x} - \frac{2}{{x}^{3}}\right)}{\frac{x + -1}{-1}}\\ \end{array} \]
Alternative 2
Error0.2
Cost1992
\[\begin{array}{l} t_0 := \frac{x + -1}{x + 1}\\ \mathbf{if}\;x \leq -230000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 12500:\\ \;\;\;\;\frac{t_0 + \frac{-1 - x}{x}}{t_0 \cdot \frac{x + 1}{x}}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\right) + \frac{\frac{-3}{x}}{x \cdot x}\\ \end{array} \]
Alternative 3
Error0.2
Cost1352
\[\begin{array}{l} \mathbf{if}\;x \leq -195000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 13500:\\ \;\;\;\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\right) + \frac{\frac{-3}{x}}{x \cdot x}\\ \end{array} \]
Alternative 4
Error0.2
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -195000000:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 450000:\\ \;\;\;\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{else}:\\ \;\;\;\;\frac{-3 + \frac{2}{x}}{x + -1}\\ \end{array} \]
Alternative 5
Error0.6
Cost840
\[\begin{array}{l} t_0 := \frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x \cdot \left(x + \left(\frac{1}{x} + 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.6
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x \cdot \left(x + \left(\frac{1}{x} + 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x} + \frac{\frac{-1}{x}}{x}\\ \end{array} \]
Alternative 7
Error0.6
Cost840
\[\begin{array}{l} t_0 := \frac{-3 + \frac{2}{x}}{x + -1}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 0.85:\\ \;\;\;\;x \cdot \left(x + \left(\frac{1}{x} + 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error0.9
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x + \left(1 + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 9
Error0.6
Cost712
\[\begin{array}{l} t_0 := \frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x + \left(1 + x \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
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 11
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 12
Error30.9
Cost64
\[1 \]

Error

Reproduce

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