3frac (problem 3.3.3)

Percentage Accurate: 9.9% → 98.9%
Time: 8.7s
Alternatives: 8
Speedup: 0.6×

Specification

?
\[\left|x\right| > 1 \land \left|x\right| < 10^{+100}\]
\[\begin{array}{l} \\ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \end{array} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
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
public static double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
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 tmp = code(x)
	tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
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]
\begin{array}{l}

\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}

Sampling outcomes in binary64 precision:

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.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 9.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \end{array} \]
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
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
public static double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
def code(x):
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0))
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 tmp = code(x)
	tmp = ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
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]
\begin{array}{l}

\\
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\end{array}

Alternative 1: 98.9% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := \left(x_m + 1\right) \cdot \left(1 - x_m\right)\\ x_s \cdot \begin{array}{l} \mathbf{if}\;\left(\frac{1}{x_m + 1} - \frac{2}{x_m}\right) + \frac{1}{x_m + -1} \leq 10^{-27}:\\ \;\;\;\;2 \cdot {x_m}^{-3}\\ \mathbf{else}:\\ \;\;\;\;\frac{x_m \cdot \left(x_m \cdot -2\right) + -2 \cdot t_0}{x_m \cdot t_0}\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (let* ((t_0 (* (+ x_m 1.0) (- 1.0 x_m))))
   (*
    x_s
    (if (<= (+ (- (/ 1.0 (+ x_m 1.0)) (/ 2.0 x_m)) (/ 1.0 (+ x_m -1.0))) 1e-27)
      (* 2.0 (pow x_m -3.0))
      (/ (+ (* x_m (* x_m -2.0)) (* -2.0 t_0)) (* x_m t_0))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	double t_0 = (x_m + 1.0) * (1.0 - x_m);
	double tmp;
	if ((((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27) {
		tmp = 2.0 * pow(x_m, -3.0);
	} else {
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x_m + 1.0d0) * (1.0d0 - x_m)
    if ((((1.0d0 / (x_m + 1.0d0)) - (2.0d0 / x_m)) + (1.0d0 / (x_m + (-1.0d0)))) <= 1d-27) then
        tmp = 2.0d0 * (x_m ** (-3.0d0))
    else
        tmp = ((x_m * (x_m * (-2.0d0))) + ((-2.0d0) * t_0)) / (x_m * t_0)
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	double t_0 = (x_m + 1.0) * (1.0 - x_m);
	double tmp;
	if ((((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27) {
		tmp = 2.0 * Math.pow(x_m, -3.0);
	} else {
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	t_0 = (x_m + 1.0) * (1.0 - x_m)
	tmp = 0
	if (((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27:
		tmp = 2.0 * math.pow(x_m, -3.0)
	else:
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0)
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	t_0 = Float64(Float64(x_m + 1.0) * Float64(1.0 - x_m))
	tmp = 0.0
	if (Float64(Float64(Float64(1.0 / Float64(x_m + 1.0)) - Float64(2.0 / x_m)) + Float64(1.0 / Float64(x_m + -1.0))) <= 1e-27)
		tmp = Float64(2.0 * (x_m ^ -3.0));
	else
		tmp = Float64(Float64(Float64(x_m * Float64(x_m * -2.0)) + Float64(-2.0 * t_0)) / Float64(x_m * t_0));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m)
	t_0 = (x_m + 1.0) * (1.0 - x_m);
	tmp = 0.0;
	if ((((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))) <= 1e-27)
		tmp = 2.0 * (x_m ^ -3.0);
	else
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[(N[(x$95$m + 1.0), $MachinePrecision] * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[N[(N[(N[(1.0 / N[(x$95$m + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x$95$m), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-27], N[(2.0 * N[Power[x$95$m, -3.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(x$95$m * N[(x$95$m * -2.0), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x$95$m * t$95$0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := \left(x_m + 1\right) \cdot \left(1 - x_m\right)\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;\left(\frac{1}{x_m + 1} - \frac{2}{x_m}\right) + \frac{1}{x_m + -1} \leq 10^{-27}:\\
\;\;\;\;2 \cdot {x_m}^{-3}\\

\mathbf{else}:\\
\;\;\;\;\frac{x_m \cdot \left(x_m \cdot -2\right) + -2 \cdot t_0}{x_m \cdot t_0}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1e-27

    1. Initial program 7.9%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Step-by-step derivation
      1. sub-neg7.9%

        \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
      2. distribute-neg-frac7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
      3. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
      4. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      5. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      6. associate-/r*7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
      7. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
      8. neg-mul-17.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
      9. +-commutative7.9%

        \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
      10. associate-+l+7.8%

        \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      11. +-commutative7.8%

        \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
      12. neg-mul-17.8%

        \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      13. metadata-eval7.8%

        \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      14. associate-/r*7.8%

        \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      15. metadata-eval7.8%

        \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      16. metadata-eval7.8%

        \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      17. +-commutative7.8%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      18. +-commutative7.8%

        \[\leadsto \frac{-2}{x} + \left(\frac{1}{\color{blue}{1 + x}} + \frac{1}{x - 1}\right) \]
    3. Simplified7.8%

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{3}}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u97.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{{x}^{3}}\right)\right)} \]
      2. expm1-udef5.9%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{2}{{x}^{3}}\right)} - 1} \]
      3. div-inv5.9%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{2 \cdot \frac{1}{{x}^{3}}}\right)} - 1 \]
      4. pow-flip5.9%

        \[\leadsto e^{\mathsf{log1p}\left(2 \cdot \color{blue}{{x}^{\left(-3\right)}}\right)} - 1 \]
      5. metadata-eval5.9%

        \[\leadsto e^{\mathsf{log1p}\left(2 \cdot {x}^{\color{blue}{-3}}\right)} - 1 \]
    6. Applied egg-rr5.9%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(2 \cdot {x}^{-3}\right)} - 1} \]
    7. Step-by-step derivation
      1. expm1-def98.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot {x}^{-3}\right)\right)} \]
      2. expm1-log1p98.3%

        \[\leadsto \color{blue}{2 \cdot {x}^{-3}} \]
    8. Simplified98.3%

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

    if 1e-27 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 55.1%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Step-by-step derivation
      1. sub-neg55.1%

        \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
      2. distribute-neg-frac55.1%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
      3. metadata-eval55.1%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
      4. metadata-eval55.1%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      5. metadata-eval55.1%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      6. associate-/r*55.1%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
      7. metadata-eval55.1%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
      8. neg-mul-155.1%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
      9. +-commutative55.1%

        \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
      10. associate-+l+53.5%

        \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      11. +-commutative53.5%

        \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
      12. neg-mul-153.5%

        \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      13. metadata-eval53.5%

        \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      14. associate-/r*53.5%

        \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      15. metadata-eval53.5%

        \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      16. metadata-eval53.5%

        \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      17. +-commutative53.5%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      18. +-commutative53.5%

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left(1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x}} \]
      4. *-un-lft-identity82.8%

        \[\leadsto \frac{\left(\color{blue}{\left(1 - x\right)} + \left(1 + x\right) \cdot -1\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      5. *-commutative82.8%

        \[\leadsto \frac{\left(\left(1 - x\right) + \color{blue}{-1 \cdot \left(1 + x\right)}\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      6. neg-mul-182.8%

        \[\leadsto \frac{\left(\left(1 - x\right) + \color{blue}{\left(-\left(1 + x\right)\right)}\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      7. distribute-neg-in82.8%

        \[\leadsto \frac{\left(\left(1 - x\right) + \color{blue}{\left(\left(-1\right) + \left(-x\right)\right)}\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      8. metadata-eval82.8%

        \[\leadsto \frac{\left(\left(1 - x\right) + \left(\color{blue}{-1} + \left(-x\right)\right)\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      9. +-commutative82.8%

        \[\leadsto \frac{\left(\left(1 - x\right) + \left(-1 + \left(-x\right)\right)\right) \cdot x + \left(\color{blue}{\left(x + 1\right)} \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      10. +-commutative82.8%

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

      \[\leadsto \color{blue}{\frac{\left(\left(1 - x\right) + \left(-1 + \left(-x\right)\right)\right) \cdot x + \left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot x}} \]
    6. Taylor expanded in x around 0 83.2%

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

        \[\leadsto \frac{\color{blue}{\left(x \cdot -2\right)} \cdot x + \left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot x} \]
    8. Simplified83.2%

      \[\leadsto \frac{\color{blue}{\left(x \cdot -2\right)} \cdot x + \left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.0%

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

Alternative 2: 99.0% accurate, 0.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \left(\frac{2}{{x_m}^{5}} + \left(2 \cdot {x_m}^{-3} + \frac{2}{{x_m}^{7}}\right)\right) \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (*
  x_s
  (+ (/ 2.0 (pow x_m 5.0)) (+ (* 2.0 (pow x_m -3.0)) (/ 2.0 (pow x_m 7.0))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * ((2.0 / pow(x_m, 5.0)) + ((2.0 * pow(x_m, -3.0)) + (2.0 / pow(x_m, 7.0))));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * ((2.0d0 / (x_m ** 5.0d0)) + ((2.0d0 * (x_m ** (-3.0d0))) + (2.0d0 / (x_m ** 7.0d0))))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * ((2.0 / Math.pow(x_m, 5.0)) + ((2.0 * Math.pow(x_m, -3.0)) + (2.0 / Math.pow(x_m, 7.0))));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * ((2.0 / math.pow(x_m, 5.0)) + ((2.0 * math.pow(x_m, -3.0)) + (2.0 / math.pow(x_m, 7.0))))
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(Float64(2.0 / (x_m ^ 5.0)) + Float64(Float64(2.0 * (x_m ^ -3.0)) + Float64(2.0 / (x_m ^ 7.0)))))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * ((2.0 / (x_m ^ 5.0)) + ((2.0 * (x_m ^ -3.0)) + (2.0 / (x_m ^ 7.0))));
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(2.0 / N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 * N[Power[x$95$m, -3.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 / N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot \left(\frac{2}{{x_m}^{5}} + \left(2 \cdot {x_m}^{-3} + \frac{2}{{x_m}^{7}}\right)\right)
\end{array}
Derivation
  1. Initial program 9.0%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. sub-neg9.0%

      \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
    2. distribute-neg-frac9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
    3. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
    4. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
    5. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
    6. associate-/r*9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
    7. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
    8. neg-mul-19.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
    9. +-commutative9.0%

      \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
    10. associate-+l+8.8%

      \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
    11. +-commutative8.8%

      \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
    12. neg-mul-18.8%

      \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    13. metadata-eval8.8%

      \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    14. associate-/r*8.8%

      \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    15. metadata-eval8.8%

      \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    16. metadata-eval8.8%

      \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    17. +-commutative8.8%

      \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
    18. +-commutative8.8%

      \[\leadsto \frac{-2}{x} + \left(\frac{1}{\color{blue}{1 + x}} + \frac{1}{x - 1}\right) \]
  3. Simplified8.8%

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

    \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{5}} + \left(2 \cdot \frac{1}{{x}^{7}} + 2 \cdot \frac{1}{{x}^{3}}\right)} \]
  5. Step-by-step derivation
    1. associate-*r/98.2%

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

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

      \[\leadsto \frac{2}{{x}^{5}} + \color{blue}{\left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{7}}\right)} \]
    4. associate-*r/98.2%

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

      \[\leadsto \frac{2}{{x}^{5}} + \left(\frac{\color{blue}{2}}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{7}}\right) \]
    6. associate-*r/98.2%

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

      \[\leadsto \frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{\color{blue}{2}}{{x}^{7}}\right) \]
  6. Simplified98.2%

    \[\leadsto \color{blue}{\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{2}{{x}^{7}}\right)} \]
  7. Step-by-step derivation
    1. expm1-log1p-u97.1%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{{x}^{3}}\right)\right)} \]
    2. expm1-udef6.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{2}{{x}^{3}}\right)} - 1} \]
    3. div-inv6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{2 \cdot \frac{1}{{x}^{3}}}\right)} - 1 \]
    4. pow-flip6.2%

      \[\leadsto e^{\mathsf{log1p}\left(2 \cdot \color{blue}{{x}^{\left(-3\right)}}\right)} - 1 \]
    5. metadata-eval6.2%

      \[\leadsto e^{\mathsf{log1p}\left(2 \cdot {x}^{\color{blue}{-3}}\right)} - 1 \]
  8. Applied egg-rr8.1%

    \[\leadsto \frac{2}{{x}^{5}} + \left(\color{blue}{\left(e^{\mathsf{log1p}\left(2 \cdot {x}^{-3}\right)} - 1\right)} + \frac{2}{{x}^{7}}\right) \]
  9. Step-by-step derivation
    1. expm1-def97.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(2 \cdot {x}^{-3}\right)\right)} \]
    2. expm1-log1p97.6%

      \[\leadsto \color{blue}{2 \cdot {x}^{-3}} \]
  10. Simplified98.6%

    \[\leadsto \frac{2}{{x}^{5}} + \left(\color{blue}{2 \cdot {x}^{-3}} + \frac{2}{{x}^{7}}\right) \]
  11. Final simplification98.6%

    \[\leadsto \frac{2}{{x}^{5}} + \left(2 \cdot {x}^{-3} + \frac{2}{{x}^{7}}\right) \]

Alternative 3: 98.5% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \left(2 \cdot \left({x_m}^{-3} + {x_m}^{-5}\right)\right) \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (* x_s (* 2.0 (+ (pow x_m -3.0) (pow x_m -5.0)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * (2.0 * (pow(x_m, -3.0) + pow(x_m, -5.0)));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * (2.0d0 * ((x_m ** (-3.0d0)) + (x_m ** (-5.0d0))))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * (2.0 * (Math.pow(x_m, -3.0) + Math.pow(x_m, -5.0)));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * (2.0 * (math.pow(x_m, -3.0) + math.pow(x_m, -5.0)))
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(2.0 * Float64((x_m ^ -3.0) + (x_m ^ -5.0))))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * (2.0 * ((x_m ^ -3.0) + (x_m ^ -5.0)));
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(2.0 * N[(N[Power[x$95$m, -3.0], $MachinePrecision] + N[Power[x$95$m, -5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot \left(2 \cdot \left({x_m}^{-3} + {x_m}^{-5}\right)\right)
\end{array}
Derivation
  1. Initial program 9.0%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. sub-neg9.0%

      \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
    2. distribute-neg-frac9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
    3. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
    4. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
    5. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
    6. associate-/r*9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
    7. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
    8. neg-mul-19.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
    9. +-commutative9.0%

      \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
    10. associate-+l+8.8%

      \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
    11. +-commutative8.8%

      \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
    12. neg-mul-18.8%

      \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    13. metadata-eval8.8%

      \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    14. associate-/r*8.8%

      \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    15. metadata-eval8.8%

      \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    16. metadata-eval8.8%

      \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    17. +-commutative8.8%

      \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
    18. +-commutative8.8%

      \[\leadsto \frac{-2}{x} + \left(\frac{1}{\color{blue}{1 + x}} + \frac{1}{x - 1}\right) \]
  3. Simplified8.8%

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

    \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{5}} + \left(2 \cdot \frac{1}{{x}^{7}} + 2 \cdot \frac{1}{{x}^{3}}\right)} \]
  5. Step-by-step derivation
    1. associate-*r/98.2%

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

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

      \[\leadsto \frac{2}{{x}^{5}} + \color{blue}{\left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{7}}\right)} \]
    4. associate-*r/98.2%

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

      \[\leadsto \frac{2}{{x}^{5}} + \left(\frac{\color{blue}{2}}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{7}}\right) \]
    6. associate-*r/98.2%

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

      \[\leadsto \frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{\color{blue}{2}}{{x}^{7}}\right) \]
  6. Simplified98.2%

    \[\leadsto \color{blue}{\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{2}{{x}^{7}}\right)} \]
  7. Taylor expanded in x around inf 98.0%

    \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{5}}} \]
  8. Step-by-step derivation
    1. +-commutative98.0%

      \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}}} \]
    2. associate-*r/98.0%

      \[\leadsto \color{blue}{\frac{2 \cdot 1}{{x}^{5}}} + 2 \cdot \frac{1}{{x}^{3}} \]
    3. metadata-eval98.0%

      \[\leadsto \frac{\color{blue}{2}}{{x}^{5}} + 2 \cdot \frac{1}{{x}^{3}} \]
    4. associate-*r/98.0%

      \[\leadsto \frac{2}{{x}^{5}} + \color{blue}{\frac{2 \cdot 1}{{x}^{3}}} \]
    5. metadata-eval98.0%

      \[\leadsto \frac{2}{{x}^{5}} + \frac{\color{blue}{2}}{{x}^{3}} \]
  9. Simplified98.0%

    \[\leadsto \color{blue}{\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}} \]
  10. Step-by-step derivation
    1. expm1-log1p-u98.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)\right)} \]
    2. expm1-udef6.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)} - 1} \]
    3. div-inv6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{2 \cdot \frac{1}{{x}^{5}}} + \frac{2}{{x}^{3}}\right)} - 1 \]
    4. fma-def6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)}\right)} - 1 \]
    5. pow-flip6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, \color{blue}{{x}^{\left(-5\right)}}, \frac{2}{{x}^{3}}\right)\right)} - 1 \]
    6. metadata-eval6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, {x}^{\color{blue}{-5}}, \frac{2}{{x}^{3}}\right)\right)} - 1 \]
    7. div-inv6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, {x}^{-5}, \color{blue}{2 \cdot \frac{1}{{x}^{3}}}\right)\right)} - 1 \]
    8. pow-flip6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, {x}^{-5}, 2 \cdot \color{blue}{{x}^{\left(-3\right)}}\right)\right)} - 1 \]
    9. metadata-eval6.2%

      \[\leadsto e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, {x}^{-5}, 2 \cdot {x}^{\color{blue}{-3}}\right)\right)} - 1 \]
  11. Applied egg-rr6.2%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\mathsf{fma}\left(2, {x}^{-5}, 2 \cdot {x}^{-3}\right)\right)} - 1} \]
  12. Step-by-step derivation
    1. expm1-def98.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(2, {x}^{-5}, 2 \cdot {x}^{-3}\right)\right)\right)} \]
    2. expm1-log1p98.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, {x}^{-5}, 2 \cdot {x}^{-3}\right)} \]
    3. fma-udef98.4%

      \[\leadsto \color{blue}{2 \cdot {x}^{-5} + 2 \cdot {x}^{-3}} \]
    4. distribute-lft-out98.4%

      \[\leadsto \color{blue}{2 \cdot \left({x}^{-5} + {x}^{-3}\right)} \]
  13. Simplified98.4%

    \[\leadsto \color{blue}{2 \cdot \left({x}^{-5} + {x}^{-3}\right)} \]
  14. Final simplification98.4%

    \[\leadsto 2 \cdot \left({x}^{-3} + {x}^{-5}\right) \]

Alternative 4: 11.7% accurate, 0.5× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := \left(\frac{1}{x_m + 1} - \frac{2}{x_m}\right) + \frac{1}{x_m + -1}\\ x_s \cdot \begin{array}{l} \mathbf{if}\;t_0 \leq 0:\\ \;\;\;\;\frac{-2}{x_m \cdot \left(1 - x_m\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (let* ((t_0 (+ (- (/ 1.0 (+ x_m 1.0)) (/ 2.0 x_m)) (/ 1.0 (+ x_m -1.0)))))
   (* x_s (if (<= t_0 0.0) (/ -2.0 (* x_m (- 1.0 x_m))) t_0))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	double t_0 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = -2.0 / (x_m * (1.0 - x_m));
	} else {
		tmp = t_0;
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((1.0d0 / (x_m + 1.0d0)) - (2.0d0 / x_m)) + (1.0d0 / (x_m + (-1.0d0)))
    if (t_0 <= 0.0d0) then
        tmp = (-2.0d0) / (x_m * (1.0d0 - x_m))
    else
        tmp = t_0
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	double t_0 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = -2.0 / (x_m * (1.0 - x_m));
	} else {
		tmp = t_0;
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	t_0 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0))
	tmp = 0
	if t_0 <= 0.0:
		tmp = -2.0 / (x_m * (1.0 - x_m))
	else:
		tmp = t_0
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	t_0 = Float64(Float64(Float64(1.0 / Float64(x_m + 1.0)) - Float64(2.0 / x_m)) + Float64(1.0 / Float64(x_m + -1.0)))
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = Float64(-2.0 / Float64(x_m * Float64(1.0 - x_m)));
	else
		tmp = t_0;
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m)
	t_0 = ((1.0 / (x_m + 1.0)) - (2.0 / x_m)) + (1.0 / (x_m + -1.0));
	tmp = 0.0;
	if (t_0 <= 0.0)
		tmp = -2.0 / (x_m * (1.0 - x_m));
	else
		tmp = t_0;
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[(N[(N[(1.0 / N[(x$95$m + 1.0), $MachinePrecision]), $MachinePrecision] - N[(2.0 / x$95$m), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, 0.0], N[(-2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := \left(\frac{1}{x_m + 1} - \frac{2}{x_m}\right) + \frac{1}{x_m + -1}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;\frac{-2}{x_m \cdot \left(1 - x_m\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 0.0

    1. Initial program 7.9%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Step-by-step derivation
      1. sub-neg7.9%

        \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
      2. distribute-neg-frac7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
      3. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
      4. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      5. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      6. associate-/r*7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
      7. metadata-eval7.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
      8. neg-mul-17.9%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
      9. +-commutative7.9%

        \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
      10. associate-+l+7.8%

        \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      11. +-commutative7.8%

        \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
      12. neg-mul-17.8%

        \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      13. metadata-eval7.8%

        \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      14. associate-/r*7.8%

        \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      15. metadata-eval7.8%

        \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      16. metadata-eval7.8%

        \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      17. +-commutative7.8%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      18. +-commutative7.8%

        \[\leadsto \frac{-2}{x} + \left(\frac{1}{\color{blue}{1 + x}} + \frac{1}{x - 1}\right) \]
    3. Simplified7.8%

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

        \[\leadsto \frac{-2}{x} + \color{blue}{\frac{1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1}{\left(1 + x\right) \cdot \left(1 - x\right)}} \]
      2. div-inv7.5%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)}} \]
      3. *-un-lft-identity7.5%

        \[\leadsto \frac{-2}{x} + \left(\color{blue}{\left(1 - x\right)} + \left(1 + x\right) \cdot -1\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      4. *-commutative7.5%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{-1 \cdot \left(1 + x\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      5. neg-mul-17.5%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(-\left(1 + x\right)\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      6. distribute-neg-in7.5%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(\left(-1\right) + \left(-x\right)\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      7. metadata-eval7.5%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \left(\color{blue}{-1} + \left(-x\right)\right)\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      8. +-commutative7.5%

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

      \[\leadsto \frac{-2}{x} + \color{blue}{\left(\left(1 - x\right) + \left(-1 + \left(-x\right)\right)\right) \cdot \frac{1}{\left(x + 1\right) \cdot \left(1 - x\right)}} \]
    6. Step-by-step derivation
      1. unsub-neg7.5%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(-1 - x\right)}\right) \cdot \frac{1}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
      2. associate-/r*7.7%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \color{blue}{\frac{\frac{1}{x + 1}}{1 - x}} \]
    7. Simplified7.7%

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

        \[\leadsto \color{blue}{\left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \frac{\frac{1}{x + 1}}{1 - x} + \frac{-2}{x}} \]
      2. associate-*r/7.8%

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

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

        \[\leadsto \frac{\left(\left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \frac{1}{\color{blue}{1 + x}}\right) \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      5. un-div-inv7.8%

        \[\leadsto \frac{\color{blue}{\frac{\left(1 - x\right) + \left(-1 - x\right)}{1 + x}} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      6. associate-+l-7.8%

        \[\leadsto \frac{\frac{\color{blue}{1 - \left(x - \left(-1 - x\right)\right)}}{1 + x} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      7. +-commutative7.8%

        \[\leadsto \frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{\color{blue}{x + 1}} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      8. *-commutative7.8%

        \[\leadsto \frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{x + 1} \cdot x + \left(1 - x\right) \cdot -2}{\color{blue}{x \cdot \left(1 - x\right)}} \]
    9. Applied egg-rr7.8%

      \[\leadsto \color{blue}{\frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{x + 1} \cdot x + \left(1 - x\right) \cdot -2}{x \cdot \left(1 - x\right)}} \]
    10. Taylor expanded in x around 0 4.9%

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

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

    1. Initial program 34.8%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.0%

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

Alternative 5: 14.7% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ \begin{array}{l} t_0 := \left(x_m + 1\right) \cdot \left(1 - x_m\right)\\ x_s \cdot \begin{array}{l} \mathbf{if}\;x_m \leq 130000000:\\ \;\;\;\;\frac{x_m \cdot \left(x_m \cdot -2\right) + -2 \cdot t_0}{x_m \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x_m \cdot \left(1 - x_m\right)}\\ \end{array} \end{array} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
 :precision binary64
 (let* ((t_0 (* (+ x_m 1.0) (- 1.0 x_m))))
   (*
    x_s
    (if (<= x_m 130000000.0)
      (/ (+ (* x_m (* x_m -2.0)) (* -2.0 t_0)) (* x_m t_0))
      (/ -2.0 (* x_m (- 1.0 x_m)))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	double t_0 = (x_m + 1.0) * (1.0 - x_m);
	double tmp;
	if (x_m <= 130000000.0) {
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
	} else {
		tmp = -2.0 / (x_m * (1.0 - x_m));
	}
	return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x_m + 1.0d0) * (1.0d0 - x_m)
    if (x_m <= 130000000.0d0) then
        tmp = ((x_m * (x_m * (-2.0d0))) + ((-2.0d0) * t_0)) / (x_m * t_0)
    else
        tmp = (-2.0d0) / (x_m * (1.0d0 - x_m))
    end if
    code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	double t_0 = (x_m + 1.0) * (1.0 - x_m);
	double tmp;
	if (x_m <= 130000000.0) {
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
	} else {
		tmp = -2.0 / (x_m * (1.0 - x_m));
	}
	return x_s * tmp;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	t_0 = (x_m + 1.0) * (1.0 - x_m)
	tmp = 0
	if x_m <= 130000000.0:
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0)
	else:
		tmp = -2.0 / (x_m * (1.0 - x_m))
	return x_s * tmp
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	t_0 = Float64(Float64(x_m + 1.0) * Float64(1.0 - x_m))
	tmp = 0.0
	if (x_m <= 130000000.0)
		tmp = Float64(Float64(Float64(x_m * Float64(x_m * -2.0)) + Float64(-2.0 * t_0)) / Float64(x_m * t_0));
	else
		tmp = Float64(-2.0 / Float64(x_m * Float64(1.0 - x_m)));
	end
	return Float64(x_s * tmp)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp_2 = code(x_s, x_m)
	t_0 = (x_m + 1.0) * (1.0 - x_m);
	tmp = 0.0;
	if (x_m <= 130000000.0)
		tmp = ((x_m * (x_m * -2.0)) + (-2.0 * t_0)) / (x_m * t_0);
	else
		tmp = -2.0 / (x_m * (1.0 - x_m));
	end
	tmp_2 = x_s * tmp;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[(N[(x$95$m + 1.0), $MachinePrecision] * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[x$95$m, 130000000.0], N[(N[(N[(x$95$m * N[(x$95$m * -2.0), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x$95$m * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
\begin{array}{l}
t_0 := \left(x_m + 1\right) \cdot \left(1 - x_m\right)\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 130000000:\\
\;\;\;\;\frac{x_m \cdot \left(x_m \cdot -2\right) + -2 \cdot t_0}{x_m \cdot t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{x_m \cdot \left(1 - x_m\right)}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.3e8

    1. Initial program 11.6%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Step-by-step derivation
      1. sub-neg11.6%

        \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
      2. distribute-neg-frac11.6%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
      3. metadata-eval11.6%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
      4. metadata-eval11.6%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      5. metadata-eval11.6%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      6. associate-/r*11.6%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
      7. metadata-eval11.6%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
      8. neg-mul-111.6%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
      9. +-commutative11.6%

        \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
      10. associate-+l+11.3%

        \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      11. +-commutative11.3%

        \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
      12. neg-mul-111.3%

        \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      13. metadata-eval11.3%

        \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      14. associate-/r*11.3%

        \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      15. metadata-eval11.3%

        \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      16. metadata-eval11.3%

        \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      17. +-commutative11.3%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      18. +-commutative11.3%

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{1 + x} + \frac{-1}{1 - x}\right) + \frac{-2}{x}} \]
      2. frac-add10.9%

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

        \[\leadsto \color{blue}{\frac{\left(1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x}} \]
      4. *-un-lft-identity16.6%

        \[\leadsto \frac{\left(\color{blue}{\left(1 - x\right)} + \left(1 + x\right) \cdot -1\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      5. *-commutative16.6%

        \[\leadsto \frac{\left(\left(1 - x\right) + \color{blue}{-1 \cdot \left(1 + x\right)}\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      6. neg-mul-116.6%

        \[\leadsto \frac{\left(\left(1 - x\right) + \color{blue}{\left(-\left(1 + x\right)\right)}\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      7. distribute-neg-in16.6%

        \[\leadsto \frac{\left(\left(1 - x\right) + \color{blue}{\left(\left(-1\right) + \left(-x\right)\right)}\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      8. metadata-eval16.6%

        \[\leadsto \frac{\left(\left(1 - x\right) + \left(\color{blue}{-1} + \left(-x\right)\right)\right) \cdot x + \left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      9. +-commutative16.6%

        \[\leadsto \frac{\left(\left(1 - x\right) + \left(-1 + \left(-x\right)\right)\right) \cdot x + \left(\color{blue}{\left(x + 1\right)} \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(1 + x\right) \cdot \left(1 - x\right)\right) \cdot x} \]
      10. +-commutative16.6%

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

      \[\leadsto \color{blue}{\frac{\left(\left(1 - x\right) + \left(-1 + \left(-x\right)\right)\right) \cdot x + \left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot x}} \]
    6. Taylor expanded in x around 0 16.6%

      \[\leadsto \frac{\color{blue}{\left(-2 \cdot x\right)} \cdot x + \left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot x} \]
    7. Step-by-step derivation
      1. *-commutative16.6%

        \[\leadsto \frac{\color{blue}{\left(x \cdot -2\right)} \cdot x + \left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot -2}{\left(\left(x + 1\right) \cdot \left(1 - x\right)\right) \cdot x} \]
    8. Simplified16.6%

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

    if 1.3e8 < x

    1. Initial program 5.4%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Step-by-step derivation
      1. sub-neg5.4%

        \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
      2. distribute-neg-frac5.4%

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

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
      4. metadata-eval5.4%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      5. metadata-eval5.4%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
      6. associate-/r*5.4%

        \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
      7. metadata-eval5.4%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
      8. neg-mul-15.4%

        \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
      9. +-commutative5.4%

        \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
      10. associate-+l+5.4%

        \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      11. +-commutative5.4%

        \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
      12. neg-mul-15.4%

        \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      13. metadata-eval5.4%

        \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      14. associate-/r*5.4%

        \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      15. metadata-eval5.4%

        \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      16. metadata-eval5.4%

        \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
      17. +-commutative5.4%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
      18. +-commutative5.4%

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

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

        \[\leadsto \frac{-2}{x} + \color{blue}{\frac{1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1}{\left(1 + x\right) \cdot \left(1 - x\right)}} \]
      2. div-inv5.1%

        \[\leadsto \frac{-2}{x} + \color{blue}{\left(1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)}} \]
      3. *-un-lft-identity5.1%

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

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{-1 \cdot \left(1 + x\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      5. neg-mul-15.1%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(-\left(1 + x\right)\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      6. distribute-neg-in5.1%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(\left(-1\right) + \left(-x\right)\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      7. metadata-eval5.1%

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \left(\color{blue}{-1} + \left(-x\right)\right)\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
      8. +-commutative5.1%

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

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

        \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(-1 - x\right)}\right) \cdot \frac{1}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
      2. associate-/r*5.4%

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

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

        \[\leadsto \color{blue}{\left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \frac{\frac{1}{x + 1}}{1 - x} + \frac{-2}{x}} \]
      2. associate-*r/5.3%

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

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

        \[\leadsto \frac{\left(\left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \frac{1}{\color{blue}{1 + x}}\right) \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      5. un-div-inv5.3%

        \[\leadsto \frac{\color{blue}{\frac{\left(1 - x\right) + \left(-1 - x\right)}{1 + x}} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      6. associate-+l-5.4%

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

        \[\leadsto \frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{\color{blue}{x + 1}} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
      8. *-commutative5.4%

        \[\leadsto \frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{x + 1} \cdot x + \left(1 - x\right) \cdot -2}{\color{blue}{x \cdot \left(1 - x\right)}} \]
    9. Applied egg-rr5.4%

      \[\leadsto \color{blue}{\frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{x + 1} \cdot x + \left(1 - x\right) \cdot -2}{x \cdot \left(1 - x\right)}} \]
    10. Taylor expanded in x around 0 7.4%

      \[\leadsto \frac{\color{blue}{-2}}{x \cdot \left(1 - x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification12.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 130000000:\\ \;\;\;\;\frac{x \cdot \left(x \cdot -2\right) + -2 \cdot \left(\left(x + 1\right) \cdot \left(1 - x\right)\right)}{x \cdot \left(\left(x + 1\right) \cdot \left(1 - x\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x \cdot \left(1 - x\right)}\\ \end{array} \]

Alternative 6: 7.9% accurate, 2.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \frac{-2}{x_m \cdot \left(1 - x_m\right)} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m) :precision binary64 (* x_s (/ -2.0 (* x_m (- 1.0 x_m)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * (-2.0 / (x_m * (1.0 - x_m)));
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * ((-2.0d0) / (x_m * (1.0d0 - x_m)))
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * (-2.0 / (x_m * (1.0 - x_m)));
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * (-2.0 / (x_m * (1.0 - x_m)))
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(-2.0 / Float64(x_m * Float64(1.0 - x_m))))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * (-2.0 / (x_m * (1.0 - x_m)));
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(-2.0 / N[(x$95$m * N[(1.0 - x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot \frac{-2}{x_m \cdot \left(1 - x_m\right)}
\end{array}
Derivation
  1. Initial program 9.0%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. sub-neg9.0%

      \[\leadsto \color{blue}{\left(\frac{1}{x + 1} + \left(-\frac{2}{x}\right)\right)} + \frac{1}{x - 1} \]
    2. distribute-neg-frac9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{-2}{x}}\right) + \frac{1}{x - 1} \]
    3. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{-2}}{x}\right) + \frac{1}{x - 1} \]
    4. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\color{blue}{\frac{2}{-1}}}{x}\right) + \frac{1}{x - 1} \]
    5. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{\frac{2}{\color{blue}{-1}}}{x}\right) + \frac{1}{x - 1} \]
    6. associate-/r*9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \color{blue}{\frac{2}{\left(-1\right) \cdot x}}\right) + \frac{1}{x - 1} \]
    7. metadata-eval9.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-1} \cdot x}\right) + \frac{1}{x - 1} \]
    8. neg-mul-19.0%

      \[\leadsto \left(\frac{1}{x + 1} + \frac{2}{\color{blue}{-x}}\right) + \frac{1}{x - 1} \]
    9. +-commutative9.0%

      \[\leadsto \color{blue}{\left(\frac{2}{-x} + \frac{1}{x + 1}\right)} + \frac{1}{x - 1} \]
    10. associate-+l+8.8%

      \[\leadsto \color{blue}{\frac{2}{-x} + \left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
    11. +-commutative8.8%

      \[\leadsto \frac{2}{-x} + \color{blue}{\left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)} \]
    12. neg-mul-18.8%

      \[\leadsto \frac{2}{\color{blue}{-1 \cdot x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    13. metadata-eval8.8%

      \[\leadsto \frac{2}{\color{blue}{\left(-1\right)} \cdot x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    14. associate-/r*8.8%

      \[\leadsto \color{blue}{\frac{\frac{2}{-1}}{x}} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    15. metadata-eval8.8%

      \[\leadsto \frac{\frac{2}{\color{blue}{-1}}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    16. metadata-eval8.8%

      \[\leadsto \frac{\color{blue}{-2}}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) \]
    17. +-commutative8.8%

      \[\leadsto \frac{-2}{x} + \color{blue}{\left(\frac{1}{x + 1} + \frac{1}{x - 1}\right)} \]
    18. +-commutative8.8%

      \[\leadsto \frac{-2}{x} + \left(\frac{1}{\color{blue}{1 + x}} + \frac{1}{x - 1}\right) \]
  3. Simplified8.8%

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

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

      \[\leadsto \frac{-2}{x} + \color{blue}{\left(1 \cdot \left(1 - x\right) + \left(1 + x\right) \cdot -1\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)}} \]
    3. *-un-lft-identity8.4%

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

      \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{-1 \cdot \left(1 + x\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
    5. neg-mul-18.4%

      \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(-\left(1 + x\right)\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
    6. distribute-neg-in8.4%

      \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(\left(-1\right) + \left(-x\right)\right)}\right) \cdot \frac{1}{\left(1 + x\right) \cdot \left(1 - x\right)} \]
    7. metadata-eval8.4%

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

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

    \[\leadsto \frac{-2}{x} + \color{blue}{\left(\left(1 - x\right) + \left(-1 + \left(-x\right)\right)\right) \cdot \frac{1}{\left(x + 1\right) \cdot \left(1 - x\right)}} \]
  6. Step-by-step derivation
    1. unsub-neg8.4%

      \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \color{blue}{\left(-1 - x\right)}\right) \cdot \frac{1}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    2. associate-/r*8.7%

      \[\leadsto \frac{-2}{x} + \left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \color{blue}{\frac{\frac{1}{x + 1}}{1 - x}} \]
  7. Simplified8.7%

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

      \[\leadsto \color{blue}{\left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \frac{\frac{1}{x + 1}}{1 - x} + \frac{-2}{x}} \]
    2. associate-*r/8.7%

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

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

      \[\leadsto \frac{\left(\left(\left(1 - x\right) + \left(-1 - x\right)\right) \cdot \frac{1}{\color{blue}{1 + x}}\right) \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
    5. un-div-inv8.8%

      \[\leadsto \frac{\color{blue}{\frac{\left(1 - x\right) + \left(-1 - x\right)}{1 + x}} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
    6. associate-+l-8.8%

      \[\leadsto \frac{\frac{\color{blue}{1 - \left(x - \left(-1 - x\right)\right)}}{1 + x} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
    7. +-commutative8.8%

      \[\leadsto \frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{\color{blue}{x + 1}} \cdot x + \left(1 - x\right) \cdot -2}{\left(1 - x\right) \cdot x} \]
    8. *-commutative8.8%

      \[\leadsto \frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{x + 1} \cdot x + \left(1 - x\right) \cdot -2}{\color{blue}{x \cdot \left(1 - x\right)}} \]
  9. Applied egg-rr8.8%

    \[\leadsto \color{blue}{\frac{\frac{1 - \left(x - \left(-1 - x\right)\right)}{x + 1} \cdot x + \left(1 - x\right) \cdot -2}{x \cdot \left(1 - x\right)}} \]
  10. Taylor expanded in x around 0 5.0%

    \[\leadsto \frac{\color{blue}{-2}}{x \cdot \left(1 - x\right)} \]
  11. Final simplification5.0%

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

Alternative 7: 6.4% accurate, 5.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot \frac{1}{x_m} \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m) :precision binary64 (* x_s (/ 1.0 x_m)))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * (1.0 / x_m);
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * (1.0d0 / x_m)
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * (1.0 / x_m);
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * (1.0 / x_m)
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * Float64(1.0 / x_m))
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * (1.0 / x_m);
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(1.0 / x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot \frac{1}{x_m}
\end{array}
Derivation
  1. Initial program 9.0%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. associate-+l-9.0%

      \[\leadsto \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)} \]
    2. sub-neg9.0%

      \[\leadsto \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)} \]
    3. +-commutative9.0%

      \[\leadsto \frac{1}{\color{blue}{1 + x}} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right) \]
    4. sub-neg9.0%

      \[\leadsto \frac{1}{1 + x} + \left(-\color{blue}{\left(\frac{2}{x} + \left(-\frac{1}{x - 1}\right)\right)}\right) \]
    5. distribute-neg-in9.0%

      \[\leadsto \frac{1}{1 + x} + \color{blue}{\left(\left(-\frac{2}{x}\right) + \left(-\left(-\frac{1}{x - 1}\right)\right)\right)} \]
    6. distribute-neg-frac9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\color{blue}{\frac{-2}{x}} + \left(-\left(-\frac{1}{x - 1}\right)\right)\right) \]
    7. metadata-eval9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{\color{blue}{-2}}{x} + \left(-\left(-\frac{1}{x - 1}\right)\right)\right) \]
    8. remove-double-neg9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \color{blue}{\frac{1}{x - 1}}\right) \]
    9. sub-neg9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{1}{\color{blue}{x + \left(-1\right)}}\right) \]
    10. metadata-eval9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{1}{x + \color{blue}{-1}}\right) \]
  3. Simplified9.0%

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

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \color{blue}{\frac{-1}{-\left(x + -1\right)}}\right) \]
    2. metadata-eval9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{\color{blue}{-1}}{-\left(x + -1\right)}\right) \]
    3. frac-add8.9%

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

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(-\color{blue}{\left(-1 + x\right)}\right) + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    5. distribute-neg-in8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \color{blue}{\left(\left(--1\right) + \left(-x\right)\right)} + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    6. metadata-eval8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(\color{blue}{1} + \left(-x\right)\right) + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    7. sub-neg8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \color{blue}{\left(1 - x\right)} + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    8. *-commutative8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \color{blue}{-1 \cdot x}}{x \cdot \left(-\left(x + -1\right)\right)} \]
    9. neg-mul-18.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \color{blue}{\left(-x\right)}}{x \cdot \left(-\left(x + -1\right)\right)} \]
    10. +-commutative8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \left(-\color{blue}{\left(-1 + x\right)}\right)} \]
    11. distribute-neg-in8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \color{blue}{\left(\left(--1\right) + \left(-x\right)\right)}} \]
    12. metadata-eval8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \left(\color{blue}{1} + \left(-x\right)\right)} \]
    13. sub-neg8.9%

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

    \[\leadsto \frac{1}{1 + x} + \color{blue}{\frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \left(1 - x\right)}} \]
  6. Taylor expanded in x around 0 6.4%

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

    \[\leadsto \color{blue}{\frac{1}{x}} \]
  8. Final simplification6.3%

    \[\leadsto \frac{1}{x} \]

Alternative 8: 5.4% accurate, 15.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_s = \mathsf{copysign}\left(1, x\right) \\ x_s \cdot 2 \end{array} \]
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m) :precision binary64 (* x_s 2.0))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
	return x_s * 2.0;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: x_m
    code = x_s * 2.0d0
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
	return x_s * 2.0;
}
x_m = math.fabs(x)
x_s = math.copysign(1.0, x)
def code(x_s, x_m):
	return x_s * 2.0
x_m = abs(x)
x_s = copysign(1.0, x)
function code(x_s, x_m)
	return Float64(x_s * 2.0)
end
x_m = abs(x);
x_s = sign(x) * abs(1.0);
function tmp = code(x_s, x_m)
	tmp = x_s * 2.0;
end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * 2.0), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)

\\
x_s \cdot 2
\end{array}
Derivation
  1. Initial program 9.0%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. associate-+l-9.0%

      \[\leadsto \color{blue}{\frac{1}{x + 1} - \left(\frac{2}{x} - \frac{1}{x - 1}\right)} \]
    2. sub-neg9.0%

      \[\leadsto \color{blue}{\frac{1}{x + 1} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right)} \]
    3. +-commutative9.0%

      \[\leadsto \frac{1}{\color{blue}{1 + x}} + \left(-\left(\frac{2}{x} - \frac{1}{x - 1}\right)\right) \]
    4. sub-neg9.0%

      \[\leadsto \frac{1}{1 + x} + \left(-\color{blue}{\left(\frac{2}{x} + \left(-\frac{1}{x - 1}\right)\right)}\right) \]
    5. distribute-neg-in9.0%

      \[\leadsto \frac{1}{1 + x} + \color{blue}{\left(\left(-\frac{2}{x}\right) + \left(-\left(-\frac{1}{x - 1}\right)\right)\right)} \]
    6. distribute-neg-frac9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\color{blue}{\frac{-2}{x}} + \left(-\left(-\frac{1}{x - 1}\right)\right)\right) \]
    7. metadata-eval9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{\color{blue}{-2}}{x} + \left(-\left(-\frac{1}{x - 1}\right)\right)\right) \]
    8. remove-double-neg9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \color{blue}{\frac{1}{x - 1}}\right) \]
    9. sub-neg9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{1}{\color{blue}{x + \left(-1\right)}}\right) \]
    10. metadata-eval9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{1}{x + \color{blue}{-1}}\right) \]
  3. Simplified9.0%

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

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \color{blue}{\frac{-1}{-\left(x + -1\right)}}\right) \]
    2. metadata-eval9.0%

      \[\leadsto \frac{1}{1 + x} + \left(\frac{-2}{x} + \frac{\color{blue}{-1}}{-\left(x + -1\right)}\right) \]
    3. frac-add8.9%

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

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(-\color{blue}{\left(-1 + x\right)}\right) + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    5. distribute-neg-in8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \color{blue}{\left(\left(--1\right) + \left(-x\right)\right)} + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    6. metadata-eval8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(\color{blue}{1} + \left(-x\right)\right) + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    7. sub-neg8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \color{blue}{\left(1 - x\right)} + x \cdot -1}{x \cdot \left(-\left(x + -1\right)\right)} \]
    8. *-commutative8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \color{blue}{-1 \cdot x}}{x \cdot \left(-\left(x + -1\right)\right)} \]
    9. neg-mul-18.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \color{blue}{\left(-x\right)}}{x \cdot \left(-\left(x + -1\right)\right)} \]
    10. +-commutative8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \left(-\color{blue}{\left(-1 + x\right)}\right)} \]
    11. distribute-neg-in8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \color{blue}{\left(\left(--1\right) + \left(-x\right)\right)}} \]
    12. metadata-eval8.9%

      \[\leadsto \frac{1}{1 + x} + \frac{-2 \cdot \left(1 - x\right) + \left(-x\right)}{x \cdot \left(\color{blue}{1} + \left(-x\right)\right)} \]
    13. sub-neg8.9%

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

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

    \[\leadsto \frac{1}{1 + x} + \frac{\color{blue}{x}}{x \cdot \left(1 - x\right)} \]
  7. Taylor expanded in x around 0 3.5%

    \[\leadsto \color{blue}{2} \]
  8. Final simplification3.5%

    \[\leadsto 2 \]

Developer target: 99.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \frac{2}{x \cdot \left(x \cdot x - 1\right)} \end{array} \]
(FPCore (x) :precision binary64 (/ 2.0 (* x (- (* x x) 1.0))))
double code(double x) {
	return 2.0 / (x * ((x * x) - 1.0));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 2.0d0 / (x * ((x * x) - 1.0d0))
end function
public static double code(double x) {
	return 2.0 / (x * ((x * x) - 1.0));
}
def code(x):
	return 2.0 / (x * ((x * x) - 1.0))
function code(x)
	return Float64(2.0 / Float64(x * Float64(Float64(x * x) - 1.0)))
end
function tmp = code(x)
	tmp = 2.0 / (x * ((x * x) - 1.0));
end
code[x_] := N[(2.0 / N[(x * N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{2}{x \cdot \left(x \cdot x - 1\right)}
\end{array}

Reproduce

?
herbie shell --seed 2023334 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64
  :pre (and (> (fabs x) 1.0) (< (fabs x) 1e+100))

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

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