Average Error: 29.7 → 0.2
Time: 5.4s
Precision: binary64
Cost: 8068
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 \leq 10^{-9}:\\ \;\;\;\;\frac{-3}{{x}^{3}} + \frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (/ x (+ x 1.0)) (/ (- -1.0 x) (+ x -1.0)))))
   (if (<= t_0 1e-9) (+ (/ -3.0 (pow x 3.0)) (/ (+ -3.0 (/ -1.0 x)) x)) t_0)))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double t_0 = (x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0));
	double tmp;
	if (t_0 <= 1e-9) {
		tmp = (-3.0 / pow(x, 3.0)) + ((-3.0 + (-1.0 / x)) / x);
	} else {
		tmp = t_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 / (x + 1.0d0)) + (((-1.0d0) - x) / (x + (-1.0d0)))
    if (t_0 <= 1d-9) then
        tmp = ((-3.0d0) / (x ** 3.0d0)) + (((-3.0d0) + ((-1.0d0) / x)) / x)
    else
        tmp = t_0
    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 / (x + 1.0)) + ((-1.0 - x) / (x + -1.0));
	double tmp;
	if (t_0 <= 1e-9) {
		tmp = (-3.0 / Math.pow(x, 3.0)) + ((-3.0 + (-1.0 / x)) / x);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))
def code(x):
	t_0 = (x / (x + 1.0)) + ((-1.0 - x) / (x + -1.0))
	tmp = 0
	if t_0 <= 1e-9:
		tmp = (-3.0 / math.pow(x, 3.0)) + ((-3.0 + (-1.0 / x)) / x)
	else:
		tmp = t_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 / Float64(x + 1.0)) + Float64(Float64(-1.0 - x) / Float64(x + -1.0)))
	tmp = 0.0
	if (t_0 <= 1e-9)
		tmp = Float64(Float64(-3.0 / (x ^ 3.0)) + Float64(Float64(-3.0 + Float64(-1.0 / x)) / x));
	else
		tmp = t_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 / (x + 1.0)) + ((-1.0 - x) / (x + -1.0));
	tmp = 0.0;
	if (t_0 <= 1e-9)
		tmp = (-3.0 / (x ^ 3.0)) + ((-3.0 + (-1.0 / x)) / x);
	else
		tmp = t_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 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-9], N[(N[(-3.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-3.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], t$95$0]]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\
\mathbf{if}\;t_0 \leq 10^{-9}:\\
\;\;\;\;\frac{-3}{{x}^{3}} + \frac{-3 + \frac{-1}{x}}{x}\\

\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 (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000006e-9

    1. Initial program 59.2

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

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

      \[\leadsto \color{blue}{\left(\frac{\frac{-1}{x}}{x} + \frac{-3}{x}\right) + \frac{-3}{{x}^{3}}} \]
      Proof
      (+.f64 (+.f64 (/.f64 (/.f64 -1 x) x) (/.f64 -3 x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (/.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 1)) x) x) (/.f64 -3 x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (/.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 1 x))) x) (/.f64 -3 x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (/.f64 1 x) x))) (/.f64 -3 x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 x x)))) (/.f64 -3 x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (/.f64 1 (Rewrite<= unpow2_binary64 (pow.f64 x 2)))) (/.f64 -3 x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 2))) (/.f64 (Rewrite<= metadata-eval (neg.f64 3)) x)) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 2))) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 3 x)))) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 2))) (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 3 1)) x))) (/.f64 -3 (pow.f64 x 3))): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (/.f64 1 (pow.f64 x 2))) (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 3 (/.f64 1 x))))) (/.f64 -3 (pow.f64 x 3))): 41 points increase in error, 1 points decrease in error
      (+.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 (/.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 (/.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 (/.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 (/.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)))))): 3 points increase in error, 6 points decrease in error
      (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
      (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3))) (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))))): 0 points increase in error, 0 points decrease in error
    4. Taylor expanded in x around 0 0.5

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

      \[\leadsto \color{blue}{\frac{-3}{{x}^{3}} - \frac{3 + \frac{1}{x}}{x}} \]
      Proof
      (-.f64 (/.f64 -3 (pow.f64 x 3)) (/.f64 (+.f64 3 (/.f64 1 x)) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 3)) (pow.f64 x 3)) (/.f64 (+.f64 3 (/.f64 1 x)) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 3 (pow.f64 x 3)))) (/.f64 (+.f64 3 (/.f64 1 x)) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 3 1)) (pow.f64 x 3))) (/.f64 (+.f64 3 (/.f64 1 x)) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 3 (/.f64 1 (pow.f64 x 3))))) (/.f64 (+.f64 3 (/.f64 1 x)) x)): 3 points increase in error, 6 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (/.f64 (+.f64 (Rewrite<= metadata-eval (neg.f64 -3)) (/.f64 1 x)) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (/.f64 (+.f64 (neg.f64 -3) (/.f64 (Rewrite<= metadata-eval (neg.f64 -1)) x)) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (/.f64 (+.f64 (neg.f64 -3) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 -1 x)))) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (/.f64 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 -3 (/.f64 -1 x)))) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (/.f64 (neg.f64 (Rewrite=> +-commutative_binary64 (+.f64 (/.f64 -1 x) -3))) x)): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (+.f64 (/.f64 -1 x) -3) x)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (neg.f64 (/.f64 (Rewrite<= *-lft-identity_binary64 (*.f64 1 (+.f64 (/.f64 -1 x) -3))) x))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (neg.f64 (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 1 x) (+.f64 (/.f64 -1 x) -3))))): 42 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (Rewrite=> distribute-rgt-neg-in_binary64 (*.f64 (/.f64 1 x) (neg.f64 (+.f64 (/.f64 -1 x) -3))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (*.f64 (/.f64 1 x) (Rewrite=> distribute-neg-in_binary64 (+.f64 (neg.f64 (/.f64 -1 x)) (neg.f64 -3))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (*.f64 (/.f64 1 x) (+.f64 (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 -1) x)) (neg.f64 -3)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (*.f64 (/.f64 1 x) (+.f64 (/.f64 (Rewrite=> metadata-eval 1) x) (neg.f64 -3)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (*.f64 (/.f64 1 x) (+.f64 (/.f64 1 x) (Rewrite=> metadata-eval 3)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 (/.f64 1 x) (/.f64 1 x)) (*.f64 3 (/.f64 1 x))))): 1 points increase in error, 3 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (+.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 1 (/.f64 1 x)) x)) (*.f64 3 (/.f64 1 x)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (+.f64 (/.f64 (Rewrite=> *-lft-identity_binary64 (/.f64 1 x)) x) (*.f64 3 (/.f64 1 x)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (+.f64 (Rewrite<= associate-/r*_binary64 (/.f64 1 (*.f64 x x))) (*.f64 3 (/.f64 1 x)))): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (+.f64 (/.f64 1 (Rewrite<= unpow2_binary64 (pow.f64 x 2))) (*.f64 3 (/.f64 1 x)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3)))) (neg.f64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3))) (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 x)))))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite=> associate-+r+_binary64 (+.f64 (+.f64 (*.f64 3 (/.f64 1 (pow.f64 x 3))) (/.f64 1 (pow.f64 x 2))) (*.f64 3 (/.f64 1 x))))): 2 points increase in error, 0 points decrease in error
      (neg.f64 (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 (pow.f64 x 3))))) (*.f64 3 (/.f64 1 x)))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 3 (/.f64 1 x)) (+.f64 (/.f64 1 (pow.f64 x 2)) (*.f64 3 (/.f64 1 (pow.f64 x 3))))))): 0 points increase in error, 0 points decrease in error

    if 1.00000000000000006e-9 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 0.2

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 10^{-9}:\\ \;\;\;\;\frac{-3}{{x}^{3}} + \frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost1732
\[\begin{array}{l} t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 \leq 10^{-9}:\\ \;\;\;\;\frac{\frac{-1}{x}}{x} + \frac{-3}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.6
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3 + \frac{-1}{x}}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-1}{x}}{x} + \frac{-3}{x}\\ \end{array} \]
Alternative 3
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:\\ \;\;\;\;1 + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
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 5
Error1.2
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 6
Error31.7
Cost64
\[1 \]

Error

Reproduce

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