3frac (problem 3.3.3)

?

Percentage Accurate: 85.0% → 99.1%
Time: 13.0s
Precision: binary64
Cost: 15433

?

\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\ t_1 := x \cdot x - x\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-5} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;\frac{t_1 + \left(1 + x\right) \cdot \left(x + -2 \cdot \left(x + -1\right)\right)}{\left(1 + x\right) \cdot t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\\ \end{array} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0))))
        (t_1 (- (* x x) x)))
   (if (or (<= t_0 -2e-5) (not (<= t_0 0.0)))
     (/ (+ t_1 (* (+ 1.0 x) (+ x (* -2.0 (+ x -1.0))))) (* (+ 1.0 x) t_1))
     (+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 3.0))))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	double t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
	double t_1 = (x * x) - x;
	double tmp;
	if ((t_0 <= -2e-5) || !(t_0 <= 0.0)) {
		tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1);
	} else {
		tmp = (2.0 / pow(x, 5.0)) + (2.0 / pow(x, 3.0));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = ((1.0d0 / (x + 1.0d0)) - (2.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) :: tmp
    t_0 = ((1.0d0 / (1.0d0 + x)) - (2.0d0 / x)) + (1.0d0 / (x + (-1.0d0)))
    t_1 = (x * x) - x
    if ((t_0 <= (-2d-5)) .or. (.not. (t_0 <= 0.0d0))) then
        tmp = (t_1 + ((1.0d0 + x) * (x + ((-2.0d0) * (x + (-1.0d0)))))) / ((1.0d0 + x) * t_1)
    else
        tmp = (2.0d0 / (x ** 5.0d0)) + (2.0d0 / (x ** 3.0d0))
    end if
    code = tmp
end function
public static double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
public static double code(double x) {
	double t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
	double t_1 = (x * x) - x;
	double tmp;
	if ((t_0 <= -2e-5) || !(t_0 <= 0.0)) {
		tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1);
	} else {
		tmp = (2.0 / Math.pow(x, 5.0)) + (2.0 / Math.pow(x, 3.0));
	}
	return tmp;
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
def code(x):
	t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0))
	t_1 = (x * x) - x
	tmp = 0
	if (t_0 <= -2e-5) or not (t_0 <= 0.0):
		tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1)
	else:
		tmp = (2.0 / math.pow(x, 5.0)) + (2.0 / math.pow(x, 3.0))
	return tmp
function code(x)
	return Float64(Float64(Float64(1.0 / Float64(x + 1.0)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x - 1.0)))
end
function code(x)
	t_0 = Float64(Float64(Float64(1.0 / Float64(1.0 + x)) - Float64(2.0 / x)) + Float64(1.0 / Float64(x + -1.0)))
	t_1 = Float64(Float64(x * x) - x)
	tmp = 0.0
	if ((t_0 <= -2e-5) || !(t_0 <= 0.0))
		tmp = Float64(Float64(t_1 + Float64(Float64(1.0 + x) * Float64(x + Float64(-2.0 * Float64(x + -1.0))))) / Float64(Float64(1.0 + x) * t_1));
	else
		tmp = Float64(Float64(2.0 / (x ^ 5.0)) + Float64(2.0 / (x ^ 3.0)));
	end
	return tmp
end
function tmp = code(x)
	tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
end
function tmp_2 = code(x)
	t_0 = ((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0));
	t_1 = (x * x) - x;
	tmp = 0.0;
	if ((t_0 <= -2e-5) || ~((t_0 <= 0.0)))
		tmp = (t_1 + ((1.0 + x) * (x + (-2.0 * (x + -1.0))))) / ((1.0 + x) * t_1);
	else
		tmp = (2.0 / (x ^ 5.0)) + (2.0 / (x ^ 3.0));
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[(N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e-5], N[Not[LessEqual[t$95$0, 0.0]], $MachinePrecision]], N[(N[(t$95$1 + N[(N[(1.0 + x), $MachinePrecision] * N[(x + N[(-2.0 * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + x), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\
t_1 := x \cdot x - x\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{-5} \lor \neg \left(t_0 \leq 0\right):\\
\;\;\;\;\frac{t_1 + \left(1 + x\right) \cdot \left(x + -2 \cdot \left(x + -1\right)\right)}{\left(1 + x\right) \cdot t_1}\\

\mathbf{else}:\\
\;\;\;\;\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\\


\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original85.0%
Target99.5%
Herbie99.1%
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation?

  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -2.00000000000000016e-5 or 0.0 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 99.4%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Simplified99.4%

      \[\leadsto \color{blue}{\frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)} \]
      Step-by-step derivation

      [Start]99.4%

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

      associate-+l- [=>]99.4%

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

      sub-neg [=>]99.4%

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

      neg-mul-1 [=>]99.4%

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

      metadata-eval [<=]99.4%

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

      cancel-sign-sub-inv [<=]99.4%

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

      +-commutative [=>]99.4%

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

      *-lft-identity [=>]99.4%

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

      sub-neg [=>]99.4%

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

      metadata-eval [=>]99.4%

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

      \[\leadsto \frac{1}{1 + x} - \color{blue}{\frac{-2 \cdot \left(1 - x\right) - \left(-x\right) \cdot -1}{\left(-x\right) \cdot \left(1 - x\right)}} \]
      Step-by-step derivation

      [Start]99.4%

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

      frac-2neg [=>]99.4%

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

      frac-2neg [=>]99.4%

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

      metadata-eval [=>]99.4%

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

      frac-sub [=>]99.3%

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

      metadata-eval [=>]99.3%

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

      +-commutative [=>]99.3%

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

      distribute-neg-in [=>]99.3%

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

      metadata-eval [=>]99.3%

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

      sub-neg [<=]99.3%

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

      +-commutative [=>]99.3%

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

      distribute-neg-in [=>]99.3%

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

      metadata-eval [=>]99.3%

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

      sub-neg [<=]99.3%

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

      \[\leadsto \frac{1}{1 + x} - \color{blue}{\frac{-2 \cdot \left(1 - x\right) - x}{x \cdot x - x}} \]
      Step-by-step derivation

      [Start]99.3%

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

      cancel-sign-sub [=>]99.3%

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

      *-commutative [<=]99.3%

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

      neg-mul-1 [<=]99.3%

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

      unsub-neg [=>]99.3%

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

      sub-neg [=>]99.3%

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

      +-commutative [=>]99.3%

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

      distribute-lft-in [=>]99.3%

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

      sqr-neg [=>]99.3%

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

      unpow2 [<=]99.3%

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

      *-rgt-identity [=>]99.3%

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

      sub-neg [<=]99.3%

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

      unpow2 [=>]99.3%

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

      \[\leadsto \color{blue}{\frac{\left(x \cdot x - x\right) - \left(1 + x\right) \cdot \left(\left(1 - x\right) \cdot -2 - x\right)}{\left(1 + x\right) \cdot \left(x \cdot x - x\right)}} \]
      Step-by-step derivation

      [Start]99.3%

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

      frac-sub [=>]100.0%

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

      *-un-lft-identity [<=]100.0%

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

      *-commutative [=>]100.0%

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

    if -2.00000000000000016e-5 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0

    1. Initial program 65.2%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Simplified65.2%

      \[\leadsto \color{blue}{\frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + -1}\right)} \]
      Step-by-step derivation

      [Start]65.2%

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

      associate-+l- [=>]65.2%

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

      sub-neg [=>]65.2%

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

      neg-mul-1 [=>]65.2%

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

      metadata-eval [<=]65.2%

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

      cancel-sign-sub-inv [<=]65.2%

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

      +-commutative [=>]65.2%

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

      *-lft-identity [=>]65.2%

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

      sub-neg [=>]65.2%

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

      metadata-eval [=>]65.2%

      \[ \frac{1}{1 + x} - \left(\frac{2}{x} - \frac{1}{x + \color{blue}{-1}}\right) \]
    3. Taylor expanded in x around inf 99.1%

      \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}} \]
    4. Simplified99.1%

      \[\leadsto \color{blue}{\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}} \]
      Step-by-step derivation

      [Start]99.1%

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

      associate-*r/ [=>]99.1%

      \[ \color{blue}{\frac{2 \cdot 1}{{x}^{5}}} + 2 \cdot \frac{1}{{x}^{3}} \]

      metadata-eval [=>]99.1%

      \[ \frac{\color{blue}{2}}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}} \]

      associate-*r/ [=>]99.1%

      \[ \frac{2}{{x}^{5}} + \color{blue}{\frac{2 \cdot 1}{{x}^{3}}} \]

      metadata-eval [=>]99.1%

      \[ \frac{2}{{x}^{5}} + \frac{\color{blue}{2}}{{x}^{3}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

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

Alternatives

Alternative 1
Accuracy99.1%
Cost15433
\[\begin{array}{l} t_0 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\ t_1 := x \cdot x - x\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-5} \lor \neg \left(t_0 \leq 0\right):\\ \;\;\;\;\frac{t_1 + \left(1 + x\right) \cdot \left(x + -2 \cdot \left(x + -1\right)\right)}{\left(1 + x\right) \cdot t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\\ \end{array} \]
Alternative 2
Accuracy99.1%
Cost8712
\[\begin{array}{l} t_0 := \left(1 - x\right) \cdot \left(x \cdot 0.5\right)\\ t_1 := x \cdot x - x\\ t_2 := \left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1}\\ \mathbf{if}\;t_2 \leq -4 \cdot 10^{-21}:\\ \;\;\;\;\frac{t_0 + \left(1 + x\right) \cdot \left(x \cdot -0.5 + \left(x + -1\right)\right)}{\left(1 + x\right) \cdot t_0}\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;\frac{2}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1 + \left(1 + x\right) \cdot \left(x + -2 \cdot \left(x + -1\right)\right)}{\left(1 + x\right) \cdot t_1}\\ \end{array} \]
Alternative 3
Accuracy85.0%
Cost960
\[\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1} \]
Alternative 4
Accuracy76.6%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-2}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x} - x\\ \end{array} \]
Alternative 5
Accuracy83.8%
Cost448
\[1 + \left(-1 - \frac{2}{x}\right) \]
Alternative 6
Accuracy51.7%
Cost192
\[\frac{-2}{x} \]
Alternative 7
Accuracy3.3%
Cost64
\[1 \]
Alternative 8
Accuracy3.3%
Cost64
\[2 \]

Reproduce?

herbie shell --seed 2023271 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))