Average Error: 14.4 → 0.2
Time: 2.6s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x} \]
\[\begin{array}{l} t_0 := \frac{1}{1 + x} - \frac{1}{x}\\ \mathbf{if}\;t_0 \leq -0.00137820529123793:\\ \;\;\;\;\frac{x + \left(-1 - x\right)}{x \cdot \left(1 + x\right)}\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;{x}^{-3} - {x}^{-2}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(1 + x\right)}^{-3}} - \frac{1}{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (/ 1.0 (+ 1.0 x)) (/ 1.0 x))))
   (if (<= t_0 -0.00137820529123793)
     (/ (+ x (- -1.0 x)) (* x (+ 1.0 x)))
     (if (<= t_0 0.0)
       (- (pow x -3.0) (pow x -2.0))
       (- (cbrt (pow (+ 1.0 x) -3.0)) (/ 1.0 x))))))
double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / x);
}
double code(double x) {
	double t_0 = (1.0 / (1.0 + x)) - (1.0 / x);
	double tmp;
	if (t_0 <= -0.00137820529123793) {
		tmp = (x + (-1.0 - x)) / (x * (1.0 + x));
	} else if (t_0 <= 0.0) {
		tmp = pow(x, -3.0) - pow(x, -2.0);
	} else {
		tmp = cbrt(pow((1.0 + x), -3.0)) - (1.0 / x);
	}
	return tmp;
}
public static double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / x);
}
public static double code(double x) {
	double t_0 = (1.0 / (1.0 + x)) - (1.0 / x);
	double tmp;
	if (t_0 <= -0.00137820529123793) {
		tmp = (x + (-1.0 - x)) / (x * (1.0 + x));
	} else if (t_0 <= 0.0) {
		tmp = Math.pow(x, -3.0) - Math.pow(x, -2.0);
	} else {
		tmp = Math.cbrt(Math.pow((1.0 + x), -3.0)) - (1.0 / x);
	}
	return tmp;
}
function code(x)
	return Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(1.0 / x))
end
function code(x)
	t_0 = Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(1.0 / x))
	tmp = 0.0
	if (t_0 <= -0.00137820529123793)
		tmp = Float64(Float64(x + Float64(-1.0 - x)) / Float64(x * Float64(1.0 + x)));
	elseif (t_0 <= 0.0)
		tmp = Float64((x ^ -3.0) - (x ^ -2.0));
	else
		tmp = Float64(cbrt((Float64(1.0 + x) ^ -3.0)) - Float64(1.0 / x));
	end
	return tmp
end
code[x_] := N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.00137820529123793], N[(N[(x + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[Power[x, -3.0], $MachinePrecision] - N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[Power[N[(1.0 + x), $MachinePrecision], -3.0], $MachinePrecision], 1/3], $MachinePrecision] - N[(1.0 / x), $MachinePrecision]), $MachinePrecision]]]]
\frac{1}{x + 1} - \frac{1}{x}
\begin{array}{l}
t_0 := \frac{1}{1 + x} - \frac{1}{x}\\
\mathbf{if}\;t_0 \leq -0.00137820529123793:\\
\;\;\;\;\frac{x + \left(-1 - x\right)}{x \cdot \left(1 + x\right)}\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;{x}^{-3} - {x}^{-2}\\

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


\end{array}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 x)) < -0.00137820529123793

    1. Initial program 0.0

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

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

    if -0.00137820529123793 < (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 x)) < 0.0

    1. Initial program 29.0

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

      \[\leadsto \color{blue}{\frac{1}{{x}^{3}} - \frac{1}{{x}^{2}}} \]
    3. Applied egg-rr0.5

      \[\leadsto \color{blue}{{x}^{-3} - {x}^{-2}} \]

    if 0.0 < (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 x))

    1. Initial program 0.0

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

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

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

Reproduce

herbie shell --seed 2022133 
(FPCore (x)
  :name "2frac (problem 3.3.1)"
  :precision binary64
  (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))