3frac (problem 3.3.3)

Percentage Accurate: 84.5% → 99.6%
Time: 15.6s
Alternatives: 12
Speedup: 0.8×

Specification

?
\[\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 12 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: 84.5% 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: 99.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot x - x\\ t_1 := \frac{2 - x}{1 - x}\\ \mathbf{if}\;x \leq -65000000:\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot t_1\\ \mathbf{elif}\;x \leq 1050000:\\ \;\;\;\;\frac{t_0 + \left(x + 1\right) \cdot \left(x - \left(1 - x\right) \cdot -2\right)}{t_0 \cdot \left(x + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \frac{\frac{\frac{2}{x} + \frac{4}{x \cdot x}}{x + 1}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (* x x) x)) (t_1 (/ (- 2.0 x) (- 1.0 x))))
   (if (<= x -65000000.0)
     (* (/ (/ 2.0 (* x x)) x) t_1)
     (if (<= x 1050000.0)
       (/ (+ t_0 (* (+ x 1.0) (- x (* (- 1.0 x) -2.0)))) (* t_0 (+ x 1.0)))
       (* t_1 (/ (/ (+ (/ 2.0 x) (/ 4.0 (* x x))) (+ x 1.0)) x))))))
double code(double x) {
	double t_0 = (x * x) - x;
	double t_1 = (2.0 - x) / (1.0 - x);
	double tmp;
	if (x <= -65000000.0) {
		tmp = ((2.0 / (x * x)) / x) * t_1;
	} else if (x <= 1050000.0) {
		tmp = (t_0 + ((x + 1.0) * (x - ((1.0 - x) * -2.0)))) / (t_0 * (x + 1.0));
	} else {
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (x * x) - x
    t_1 = (2.0d0 - x) / (1.0d0 - x)
    if (x <= (-65000000.0d0)) then
        tmp = ((2.0d0 / (x * x)) / x) * t_1
    else if (x <= 1050000.0d0) then
        tmp = (t_0 + ((x + 1.0d0) * (x - ((1.0d0 - x) * (-2.0d0))))) / (t_0 * (x + 1.0d0))
    else
        tmp = t_1 * ((((2.0d0 / x) + (4.0d0 / (x * x))) / (x + 1.0d0)) / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = (x * x) - x;
	double t_1 = (2.0 - x) / (1.0 - x);
	double tmp;
	if (x <= -65000000.0) {
		tmp = ((2.0 / (x * x)) / x) * t_1;
	} else if (x <= 1050000.0) {
		tmp = (t_0 + ((x + 1.0) * (x - ((1.0 - x) * -2.0)))) / (t_0 * (x + 1.0));
	} else {
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	}
	return tmp;
}
def code(x):
	t_0 = (x * x) - x
	t_1 = (2.0 - x) / (1.0 - x)
	tmp = 0
	if x <= -65000000.0:
		tmp = ((2.0 / (x * x)) / x) * t_1
	elif x <= 1050000.0:
		tmp = (t_0 + ((x + 1.0) * (x - ((1.0 - x) * -2.0)))) / (t_0 * (x + 1.0))
	else:
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x)
	return tmp
function code(x)
	t_0 = Float64(Float64(x * x) - x)
	t_1 = Float64(Float64(2.0 - x) / Float64(1.0 - x))
	tmp = 0.0
	if (x <= -65000000.0)
		tmp = Float64(Float64(Float64(2.0 / Float64(x * x)) / x) * t_1);
	elseif (x <= 1050000.0)
		tmp = Float64(Float64(t_0 + Float64(Float64(x + 1.0) * Float64(x - Float64(Float64(1.0 - x) * -2.0)))) / Float64(t_0 * Float64(x + 1.0)));
	else
		tmp = Float64(t_1 * Float64(Float64(Float64(Float64(2.0 / x) + Float64(4.0 / Float64(x * x))) / Float64(x + 1.0)) / x));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (x * x) - x;
	t_1 = (2.0 - x) / (1.0 - x);
	tmp = 0.0;
	if (x <= -65000000.0)
		tmp = ((2.0 / (x * x)) / x) * t_1;
	elseif (x <= 1050000.0)
		tmp = (t_0 + ((x + 1.0) * (x - ((1.0 - x) * -2.0)))) / (t_0 * (x + 1.0));
	else
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 - x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -65000000.0], N[(N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[x, 1050000.0], N[(N[(t$95$0 + N[(N[(x + 1.0), $MachinePrecision] * N[(x - N[(N[(1.0 - x), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(N[(N[(N[(2.0 / x), $MachinePrecision] + N[(4.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot x - x\\
t_1 := \frac{2 - x}{1 - x}\\
\mathbf{if}\;x \leq -65000000:\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot t_1\\

\mathbf{elif}\;x \leq 1050000:\\
\;\;\;\;\frac{t_0 + \left(x + 1\right) \cdot \left(x - \left(1 - x\right) \cdot -2\right)}{t_0 \cdot \left(x + 1\right)}\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \frac{\frac{\frac{2}{x} + \frac{4}{x \cdot x}}{x + 1}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -6.5e7

    1. Initial program 75.8%

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

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

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

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

        \[\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. +-commutative19.3%

        \[\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-in19.3%

        \[\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-eval19.3%

        \[\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-neg19.3%

        \[\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. *-commutative19.3%

        \[\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-119.3%

        \[\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. +-commutative19.3%

        \[\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-in19.3%

        \[\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-eval19.3%

        \[\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-neg19.3%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{x \cdot \left(1 - x\right)}{2 - x} - \left(1 + x\right) \cdot 1}{\left(1 + x\right) \cdot \frac{x \cdot \left(1 - x\right)}{2 - x}}} \]
    10. Step-by-step derivation
      1. /-rgt-identity18.5%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow299.9%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.9%

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

    if -6.5e7 < x < 1.05e6

    1. Initial program 99.6%

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

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

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

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

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

        \[\leadsto \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)}} \]
      5. metadata-eval99.7%

        \[\leadsto \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)} \]
      6. +-commutative99.7%

        \[\leadsto \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)} \]
      7. distribute-neg-in99.7%

        \[\leadsto \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)} \]
      8. metadata-eval99.7%

        \[\leadsto \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)} \]
      9. sub-neg99.7%

        \[\leadsto \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)} \]
      10. +-commutative99.7%

        \[\leadsto \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)} \]
      11. distribute-neg-in99.7%

        \[\leadsto \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)}} \]
      12. metadata-eval99.7%

        \[\leadsto \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)} \]
      13. sub-neg99.7%

        \[\leadsto \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. Applied egg-rr99.7%

      \[\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)}} \]
    5. Step-by-step derivation
      1. cancel-sign-sub99.7%

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

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

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

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

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

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

        \[\leadsto \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}} \]
      8. sqr-neg99.7%

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

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

        \[\leadsto \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{{x}^{\left(\frac{2}{2}\right)} \cdot {x}^{\left(\frac{2}{2}\right)}} + \left(-x\right) \cdot 1} \]
      11. *-rgt-identity99.7%

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

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

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

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

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

        \[\leadsto \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)}} \]
      2. *-un-lft-identity100.0%

        \[\leadsto \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)} \]
      3. *-commutative100.0%

        \[\leadsto \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)} \]
    8. 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)}} \]

    if 1.05e6 < x

    1. Initial program 69.7%

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

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

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

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

        \[\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. +-commutative13.7%

        \[\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-in13.7%

        \[\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-eval13.7%

        \[\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-neg13.7%

        \[\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. *-commutative13.7%

        \[\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-113.7%

        \[\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. +-commutative13.7%

        \[\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-in13.7%

        \[\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-eval13.7%

        \[\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-neg13.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{2 \cdot \frac{1}{x} + 4 \cdot \frac{1}{{x}^{2}}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. associate-*r/99.9%

        \[\leadsto \frac{\frac{\color{blue}{\frac{2 \cdot 1}{x}} + 4 \cdot \frac{1}{{x}^{2}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      2. metadata-eval99.9%

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

        \[\leadsto \frac{\frac{\frac{2}{x} + \color{blue}{\frac{4 \cdot 1}{{x}^{2}}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\frac{\frac{2}{x} + \frac{\color{blue}{4}}{{x}^{2}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      5. unpow299.9%

        \[\leadsto \frac{\frac{\frac{2}{x} + \frac{4}{\color{blue}{x \cdot x}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.9%

      \[\leadsto \frac{\frac{\color{blue}{\frac{2}{x} + \frac{4}{x \cdot x}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

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

Alternative 2: 99.0% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_0 \leq -0.0002 \lor \neg \left(t_0 \leq 10^{-24}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot \frac{2 - x}{1 - x}\\


\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))) < -2.0000000000000001e-4 or 9.99999999999999924e-25 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 99.6%

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

    if -2.0000000000000001e-4 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 9.99999999999999924e-25

    1. Initial program 72.6%

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

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

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

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

        \[\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. +-commutative16.3%

        \[\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-in16.3%

        \[\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-eval16.3%

        \[\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-neg16.3%

        \[\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. *-commutative16.3%

        \[\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-116.3%

        \[\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. +-commutative16.3%

        \[\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-in16.3%

        \[\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-eval16.3%

        \[\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-neg16.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow299.3%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.3%

      \[\leadsto \frac{\color{blue}{\frac{2}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

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

Alternative 3: 99.0% accurate, 0.3× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{1}{x + 1}\\
t_1 := \left(t_0 - \frac{2}{x}\right) + \frac{1}{x + -1}\\
\mathbf{if}\;t_1 \leq -0.0002 \lor \neg \left(t_1 \leq 10^{-24}\right):\\
\;\;\;\;t_0 + \frac{x - 2}{x \cdot \left(1 - x\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot \frac{2 - x}{1 - x}\\


\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))) < -2.0000000000000001e-4 or 9.99999999999999924e-25 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 99.6%

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

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

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

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

        \[\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. +-commutative99.7%

        \[\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-in99.7%

        \[\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-eval99.7%

        \[\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-neg99.7%

        \[\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. *-commutative99.7%

        \[\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-199.7%

        \[\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. +-commutative99.7%

        \[\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-in99.7%

        \[\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-eval99.7%

        \[\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-neg99.7%

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

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

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

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

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

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

    if -2.0000000000000001e-4 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 9.99999999999999924e-25

    1. Initial program 72.6%

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

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

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

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

        \[\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. +-commutative16.3%

        \[\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-in16.3%

        \[\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-eval16.3%

        \[\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-neg16.3%

        \[\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. *-commutative16.3%

        \[\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-116.3%

        \[\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. +-commutative16.3%

        \[\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-in16.3%

        \[\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-eval16.3%

        \[\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-neg16.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow299.3%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.3%

      \[\leadsto \frac{\color{blue}{\frac{2}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

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

Alternative 4: 99.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{2 - x}{1 - x}\\ \mathbf{if}\;x \leq -350000:\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot t_0\\ \mathbf{elif}\;x \leq 17000:\\ \;\;\;\;\frac{1}{x + 1} + \frac{x - \left(1 - x\right) \cdot -2}{x \cdot x - x}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \frac{\frac{\frac{2}{x} + \frac{4}{x \cdot x}}{x + 1}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ (- 2.0 x) (- 1.0 x))))
   (if (<= x -350000.0)
     (* (/ (/ 2.0 (* x x)) x) t_0)
     (if (<= x 17000.0)
       (+ (/ 1.0 (+ x 1.0)) (/ (- x (* (- 1.0 x) -2.0)) (- (* x x) x)))
       (* t_0 (/ (/ (+ (/ 2.0 x) (/ 4.0 (* x x))) (+ x 1.0)) x))))))
double code(double x) {
	double t_0 = (2.0 - x) / (1.0 - x);
	double tmp;
	if (x <= -350000.0) {
		tmp = ((2.0 / (x * x)) / x) * t_0;
	} else if (x <= 17000.0) {
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x));
	} else {
		tmp = t_0 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (2.0d0 - x) / (1.0d0 - x)
    if (x <= (-350000.0d0)) then
        tmp = ((2.0d0 / (x * x)) / x) * t_0
    else if (x <= 17000.0d0) then
        tmp = (1.0d0 / (x + 1.0d0)) + ((x - ((1.0d0 - x) * (-2.0d0))) / ((x * x) - x))
    else
        tmp = t_0 * ((((2.0d0 / x) + (4.0d0 / (x * x))) / (x + 1.0d0)) / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = (2.0 - x) / (1.0 - x);
	double tmp;
	if (x <= -350000.0) {
		tmp = ((2.0 / (x * x)) / x) * t_0;
	} else if (x <= 17000.0) {
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x));
	} else {
		tmp = t_0 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	}
	return tmp;
}
def code(x):
	t_0 = (2.0 - x) / (1.0 - x)
	tmp = 0
	if x <= -350000.0:
		tmp = ((2.0 / (x * x)) / x) * t_0
	elif x <= 17000.0:
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x))
	else:
		tmp = t_0 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x)
	return tmp
function code(x)
	t_0 = Float64(Float64(2.0 - x) / Float64(1.0 - x))
	tmp = 0.0
	if (x <= -350000.0)
		tmp = Float64(Float64(Float64(2.0 / Float64(x * x)) / x) * t_0);
	elseif (x <= 17000.0)
		tmp = Float64(Float64(1.0 / Float64(x + 1.0)) + Float64(Float64(x - Float64(Float64(1.0 - x) * -2.0)) / Float64(Float64(x * x) - x)));
	else
		tmp = Float64(t_0 * Float64(Float64(Float64(Float64(2.0 / x) + Float64(4.0 / Float64(x * x))) / Float64(x + 1.0)) / x));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (2.0 - x) / (1.0 - x);
	tmp = 0.0;
	if (x <= -350000.0)
		tmp = ((2.0 / (x * x)) / x) * t_0;
	elseif (x <= 17000.0)
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x));
	else
		tmp = t_0 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(2.0 - x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -350000.0], N[(N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[x, 17000.0], N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x - N[(N[(1.0 - x), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(N[(N[(2.0 / x), $MachinePrecision] + N[(4.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{2 - x}{1 - x}\\
\mathbf{if}\;x \leq -350000:\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot t_0\\

\mathbf{elif}\;x \leq 17000:\\
\;\;\;\;\frac{1}{x + 1} + \frac{x - \left(1 - x\right) \cdot -2}{x \cdot x - x}\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{\frac{\frac{2}{x} + \frac{4}{x \cdot x}}{x + 1}}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.5e5

    1. Initial program 75.8%

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

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

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

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

        \[\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. +-commutative19.3%

        \[\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-in19.3%

        \[\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-eval19.3%

        \[\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-neg19.3%

        \[\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. *-commutative19.3%

        \[\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-119.3%

        \[\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. +-commutative19.3%

        \[\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-in19.3%

        \[\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-eval19.3%

        \[\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-neg19.3%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{x \cdot \left(1 - x\right)}{2 - x} - \left(1 + x\right) \cdot 1}{\left(1 + x\right) \cdot \frac{x \cdot \left(1 - x\right)}{2 - x}}} \]
    10. Step-by-step derivation
      1. /-rgt-identity18.5%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow299.9%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.9%

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

    if -3.5e5 < x < 17000

    1. Initial program 99.6%

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

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

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

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

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

        \[\leadsto \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)}} \]
      5. metadata-eval99.7%

        \[\leadsto \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)} \]
      6. +-commutative99.7%

        \[\leadsto \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)} \]
      7. distribute-neg-in99.7%

        \[\leadsto \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)} \]
      8. metadata-eval99.7%

        \[\leadsto \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)} \]
      9. sub-neg99.7%

        \[\leadsto \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)} \]
      10. +-commutative99.7%

        \[\leadsto \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)} \]
      11. distribute-neg-in99.7%

        \[\leadsto \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)}} \]
      12. metadata-eval99.7%

        \[\leadsto \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)} \]
      13. sub-neg99.7%

        \[\leadsto \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. Applied egg-rr99.7%

      \[\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)}} \]
    5. Step-by-step derivation
      1. cancel-sign-sub99.7%

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

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

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

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

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

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

        \[\leadsto \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}} \]
      8. sqr-neg99.7%

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

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

        \[\leadsto \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{{x}^{\left(\frac{2}{2}\right)} \cdot {x}^{\left(\frac{2}{2}\right)}} + \left(-x\right) \cdot 1} \]
      11. *-rgt-identity99.7%

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

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

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

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

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

    if 17000 < x

    1. Initial program 69.7%

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

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

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

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

        \[\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. +-commutative13.7%

        \[\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-in13.7%

        \[\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-eval13.7%

        \[\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-neg13.7%

        \[\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. *-commutative13.7%

        \[\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-113.7%

        \[\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. +-commutative13.7%

        \[\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-in13.7%

        \[\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-eval13.7%

        \[\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-neg13.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{2 \cdot \frac{1}{x} + 4 \cdot \frac{1}{{x}^{2}}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. associate-*r/99.9%

        \[\leadsto \frac{\frac{\color{blue}{\frac{2 \cdot 1}{x}} + 4 \cdot \frac{1}{{x}^{2}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      2. metadata-eval99.9%

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

        \[\leadsto \frac{\frac{\frac{2}{x} + \color{blue}{\frac{4 \cdot 1}{{x}^{2}}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\frac{\frac{2}{x} + \frac{\color{blue}{4}}{{x}^{2}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      5. unpow299.9%

        \[\leadsto \frac{\frac{\frac{2}{x} + \frac{4}{\color{blue}{x \cdot x}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.9%

      \[\leadsto \frac{\frac{\color{blue}{\frac{2}{x} + \frac{4}{x \cdot x}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.8%

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

Alternative 5: 99.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \left(1 - x\right)\\ t_1 := \frac{2 - x}{1 - x}\\ \mathbf{if}\;x \leq -135000000:\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot t_1\\ \mathbf{elif}\;x \leq 140000000:\\ \;\;\;\;\frac{t_0 + \left(2 - x\right) \cdot \left(-1 - x\right)}{\left(x + 1\right) \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \frac{\frac{\frac{2}{x} + \frac{4}{x \cdot x}}{x + 1}}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* x (- 1.0 x))) (t_1 (/ (- 2.0 x) (- 1.0 x))))
   (if (<= x -135000000.0)
     (* (/ (/ 2.0 (* x x)) x) t_1)
     (if (<= x 140000000.0)
       (/ (+ t_0 (* (- 2.0 x) (- -1.0 x))) (* (+ x 1.0) t_0))
       (* t_1 (/ (/ (+ (/ 2.0 x) (/ 4.0 (* x x))) (+ x 1.0)) x))))))
double code(double x) {
	double t_0 = x * (1.0 - x);
	double t_1 = (2.0 - x) / (1.0 - x);
	double tmp;
	if (x <= -135000000.0) {
		tmp = ((2.0 / (x * x)) / x) * t_1;
	} else if (x <= 140000000.0) {
		tmp = (t_0 + ((2.0 - x) * (-1.0 - x))) / ((x + 1.0) * t_0);
	} else {
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x * (1.0d0 - x)
    t_1 = (2.0d0 - x) / (1.0d0 - x)
    if (x <= (-135000000.0d0)) then
        tmp = ((2.0d0 / (x * x)) / x) * t_1
    else if (x <= 140000000.0d0) then
        tmp = (t_0 + ((2.0d0 - x) * ((-1.0d0) - x))) / ((x + 1.0d0) * t_0)
    else
        tmp = t_1 * ((((2.0d0 / x) + (4.0d0 / (x * x))) / (x + 1.0d0)) / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = x * (1.0 - x);
	double t_1 = (2.0 - x) / (1.0 - x);
	double tmp;
	if (x <= -135000000.0) {
		tmp = ((2.0 / (x * x)) / x) * t_1;
	} else if (x <= 140000000.0) {
		tmp = (t_0 + ((2.0 - x) * (-1.0 - x))) / ((x + 1.0) * t_0);
	} else {
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	}
	return tmp;
}
def code(x):
	t_0 = x * (1.0 - x)
	t_1 = (2.0 - x) / (1.0 - x)
	tmp = 0
	if x <= -135000000.0:
		tmp = ((2.0 / (x * x)) / x) * t_1
	elif x <= 140000000.0:
		tmp = (t_0 + ((2.0 - x) * (-1.0 - x))) / ((x + 1.0) * t_0)
	else:
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x)
	return tmp
function code(x)
	t_0 = Float64(x * Float64(1.0 - x))
	t_1 = Float64(Float64(2.0 - x) / Float64(1.0 - x))
	tmp = 0.0
	if (x <= -135000000.0)
		tmp = Float64(Float64(Float64(2.0 / Float64(x * x)) / x) * t_1);
	elseif (x <= 140000000.0)
		tmp = Float64(Float64(t_0 + Float64(Float64(2.0 - x) * Float64(-1.0 - x))) / Float64(Float64(x + 1.0) * t_0));
	else
		tmp = Float64(t_1 * Float64(Float64(Float64(Float64(2.0 / x) + Float64(4.0 / Float64(x * x))) / Float64(x + 1.0)) / x));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = x * (1.0 - x);
	t_1 = (2.0 - x) / (1.0 - x);
	tmp = 0.0;
	if (x <= -135000000.0)
		tmp = ((2.0 / (x * x)) / x) * t_1;
	elseif (x <= 140000000.0)
		tmp = (t_0 + ((2.0 - x) * (-1.0 - x))) / ((x + 1.0) * t_0);
	else
		tmp = t_1 * ((((2.0 / x) + (4.0 / (x * x))) / (x + 1.0)) / x);
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(x * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 - x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -135000000.0], N[(N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[x, 140000000.0], N[(N[(t$95$0 + N[(N[(2.0 - x), $MachinePrecision] * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(N[(N[(N[(2.0 / x), $MachinePrecision] + N[(4.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \left(1 - x\right)\\
t_1 := \frac{2 - x}{1 - x}\\
\mathbf{if}\;x \leq -135000000:\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot t_1\\

\mathbf{elif}\;x \leq 140000000:\\
\;\;\;\;\frac{t_0 + \left(2 - x\right) \cdot \left(-1 - x\right)}{\left(x + 1\right) \cdot t_0}\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \frac{\frac{\frac{2}{x} + \frac{4}{x \cdot x}}{x + 1}}{x}\\


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

    1. Initial program 75.8%

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

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

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

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

        \[\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. +-commutative19.3%

        \[\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-in19.3%

        \[\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-eval19.3%

        \[\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-neg19.3%

        \[\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. *-commutative19.3%

        \[\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-119.3%

        \[\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. +-commutative19.3%

        \[\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-in19.3%

        \[\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-eval19.3%

        \[\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-neg19.3%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{x \cdot \left(1 - x\right)}{2 - x} - \left(1 + x\right) \cdot 1}{\left(1 + x\right) \cdot \frac{x \cdot \left(1 - x\right)}{2 - x}}} \]
    10. Step-by-step derivation
      1. /-rgt-identity18.5%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow299.9%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.9%

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

    if -1.35e8 < x < 1.4e8

    1. Initial program 99.6%

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

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

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

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

        \[\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. +-commutative99.7%

        \[\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-in99.7%

        \[\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-eval99.7%

        \[\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-neg99.7%

        \[\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. *-commutative99.7%

        \[\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-199.7%

        \[\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. +-commutative99.7%

        \[\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-in99.7%

        \[\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-eval99.7%

        \[\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-neg99.7%

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

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

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

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

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

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

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

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

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

    if 1.4e8 < x

    1. Initial program 69.7%

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

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

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

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

        \[\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. +-commutative13.7%

        \[\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-in13.7%

        \[\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-eval13.7%

        \[\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-neg13.7%

        \[\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. *-commutative13.7%

        \[\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-113.7%

        \[\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. +-commutative13.7%

        \[\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-in13.7%

        \[\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-eval13.7%

        \[\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-neg13.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{\color{blue}{2 \cdot \frac{1}{x} + 4 \cdot \frac{1}{{x}^{2}}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. associate-*r/99.9%

        \[\leadsto \frac{\frac{\color{blue}{\frac{2 \cdot 1}{x}} + 4 \cdot \frac{1}{{x}^{2}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      2. metadata-eval99.9%

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

        \[\leadsto \frac{\frac{\frac{2}{x} + \color{blue}{\frac{4 \cdot 1}{{x}^{2}}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\frac{\frac{2}{x} + \frac{\color{blue}{4}}{{x}^{2}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
      5. unpow299.9%

        \[\leadsto \frac{\frac{\frac{2}{x} + \frac{4}{\color{blue}{x \cdot x}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.9%

      \[\leadsto \frac{\frac{\color{blue}{\frac{2}{x} + \frac{4}{x \cdot x}}}{x + 1}}{x} \cdot \frac{2 - x}{1 - x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.9%

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

Alternative 6: 99.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -350000 \lor \neg \left(x \leq 250000\right):\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot \frac{2 - x}{1 - x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x + 1} + \frac{x - \left(1 - x\right) \cdot -2}{x \cdot x - x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -350000.0) (not (<= x 250000.0)))
   (* (/ (/ 2.0 (* x x)) x) (/ (- 2.0 x) (- 1.0 x)))
   (+ (/ 1.0 (+ x 1.0)) (/ (- x (* (- 1.0 x) -2.0)) (- (* x x) x)))))
double code(double x) {
	double tmp;
	if ((x <= -350000.0) || !(x <= 250000.0)) {
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x));
	} else {
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-350000.0d0)) .or. (.not. (x <= 250000.0d0))) then
        tmp = ((2.0d0 / (x * x)) / x) * ((2.0d0 - x) / (1.0d0 - x))
    else
        tmp = (1.0d0 / (x + 1.0d0)) + ((x - ((1.0d0 - x) * (-2.0d0))) / ((x * x) - x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -350000.0) || !(x <= 250000.0)) {
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x));
	} else {
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -350000.0) or not (x <= 250000.0):
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x))
	else:
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x))
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -350000.0) || !(x <= 250000.0))
		tmp = Float64(Float64(Float64(2.0 / Float64(x * x)) / x) * Float64(Float64(2.0 - x) / Float64(1.0 - x)));
	else
		tmp = Float64(Float64(1.0 / Float64(x + 1.0)) + Float64(Float64(x - Float64(Float64(1.0 - x) * -2.0)) / Float64(Float64(x * x) - x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -350000.0) || ~((x <= 250000.0)))
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x));
	else
		tmp = (1.0 / (x + 1.0)) + ((x - ((1.0 - x) * -2.0)) / ((x * x) - x));
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -350000.0], N[Not[LessEqual[x, 250000.0]], $MachinePrecision]], N[(N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[(N[(2.0 - x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(x - N[(N[(1.0 - x), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -350000 \lor \neg \left(x \leq 250000\right):\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot \frac{2 - x}{1 - x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.5e5 or 2.5e5 < x

    1. Initial program 72.6%

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

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

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

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

        \[\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. +-commutative16.3%

        \[\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-in16.3%

        \[\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-eval16.3%

        \[\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-neg16.3%

        \[\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. *-commutative16.3%

        \[\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-116.3%

        \[\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. +-commutative16.3%

        \[\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-in16.3%

        \[\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-eval16.3%

        \[\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-neg16.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow299.3%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified99.3%

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

    if -3.5e5 < x < 2.5e5

    1. Initial program 99.6%

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

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

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

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

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

        \[\leadsto \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)}} \]
      5. metadata-eval99.7%

        \[\leadsto \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)} \]
      6. +-commutative99.7%

        \[\leadsto \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)} \]
      7. distribute-neg-in99.7%

        \[\leadsto \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)} \]
      8. metadata-eval99.7%

        \[\leadsto \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)} \]
      9. sub-neg99.7%

        \[\leadsto \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)} \]
      10. +-commutative99.7%

        \[\leadsto \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)} \]
      11. distribute-neg-in99.7%

        \[\leadsto \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)}} \]
      12. metadata-eval99.7%

        \[\leadsto \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)} \]
      13. sub-neg99.7%

        \[\leadsto \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. Applied egg-rr99.7%

      \[\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)}} \]
    5. Step-by-step derivation
      1. cancel-sign-sub99.7%

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

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

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

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

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

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

        \[\leadsto \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}} \]
      8. sqr-neg99.7%

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

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

        \[\leadsto \frac{1}{1 + x} - \frac{-2 \cdot \left(1 - x\right) - x}{\color{blue}{{x}^{\left(\frac{2}{2}\right)} \cdot {x}^{\left(\frac{2}{2}\right)}} + \left(-x\right) \cdot 1} \]
      11. *-rgt-identity99.7%

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

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

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

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

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

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

Alternative 7: 98.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1.2\right):\\ \;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot \frac{2 - x}{1 - x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2 - \frac{2}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -1.0) (not (<= x 1.2)))
   (* (/ (/ 2.0 (* x x)) x) (/ (- 2.0 x) (- 1.0 x)))
   (- (* x -2.0) (/ 2.0 x))))
double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.2)) {
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x));
	} else {
		tmp = (x * -2.0) - (2.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-1.0d0)) .or. (.not. (x <= 1.2d0))) then
        tmp = ((2.0d0 / (x * x)) / x) * ((2.0d0 - x) / (1.0d0 - x))
    else
        tmp = (x * (-2.0d0)) - (2.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.2)) {
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x));
	} else {
		tmp = (x * -2.0) - (2.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -1.0) or not (x <= 1.2):
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x))
	else:
		tmp = (x * -2.0) - (2.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 1.2))
		tmp = Float64(Float64(Float64(2.0 / Float64(x * x)) / x) * Float64(Float64(2.0 - x) / Float64(1.0 - x)));
	else
		tmp = Float64(Float64(x * -2.0) - Float64(2.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -1.0) || ~((x <= 1.2)))
		tmp = ((2.0 / (x * x)) / x) * ((2.0 - x) / (1.0 - x));
	else
		tmp = (x * -2.0) - (2.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.2]], $MachinePrecision]], N[(N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[(N[(2.0 - x), $MachinePrecision] / N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * -2.0), $MachinePrecision] - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1.2\right):\\
\;\;\;\;\frac{\frac{2}{x \cdot x}}{x} \cdot \frac{2 - x}{1 - x}\\

\mathbf{else}:\\
\;\;\;\;x \cdot -2 - \frac{2}{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 1.19999999999999996 < x

    1. Initial program 72.6%

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

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

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

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

        \[\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. +-commutative17.3%

        \[\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-in17.3%

        \[\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-eval17.3%

        \[\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-neg17.3%

        \[\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. *-commutative17.3%

        \[\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-117.3%

        \[\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. +-commutative17.3%

        \[\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-in17.3%

        \[\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-eval17.3%

        \[\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-neg17.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{2}{{x}^{2}}}}{x} \cdot \frac{2 - x}{1 - x} \]
    13. Step-by-step derivation
      1. unpow298.3%

        \[\leadsto \frac{\frac{2}{\color{blue}{x \cdot x}}}{x} \cdot \frac{2 - x}{1 - x} \]
    14. Simplified98.3%

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

    if -1 < x < 1.19999999999999996

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{-2 \cdot x - 2 \cdot \frac{1}{x}} \]
    4. Step-by-step derivation
      1. associate-*r/100.0%

        \[\leadsto -2 \cdot x - \color{blue}{\frac{2 \cdot 1}{x}} \]
      2. metadata-eval100.0%

        \[\leadsto -2 \cdot x - \frac{\color{blue}{2}}{x} \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{-2 \cdot x - \frac{2}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.1%

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

Alternative 8: 75.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-0.3333333333333333}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) - \frac{2}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -1.0) (not (<= x 1.0)))
   (/ -0.3333333333333333 (* x x))
   (- (- x) (/ 2.0 x))))
double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = -0.3333333333333333 / (x * x);
	} else {
		tmp = -x - (2.0 / x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
        tmp = (-0.3333333333333333d0) / (x * x)
    else
        tmp = -x - (2.0d0 / x)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = -0.3333333333333333 / (x * x);
	} else {
		tmp = -x - (2.0 / x);
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -1.0) or not (x <= 1.0):
		tmp = -0.3333333333333333 / (x * x)
	else:
		tmp = -x - (2.0 / x)
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 1.0))
		tmp = Float64(-0.3333333333333333 / Float64(x * x));
	else
		tmp = Float64(Float64(-x) - Float64(2.0 / x));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -1.0) || ~((x <= 1.0)))
		tmp = -0.3333333333333333 / (x * x);
	else
		tmp = -x - (2.0 / x);
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-0.3333333333333333 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[((-x) - N[(2.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-0.3333333333333333}{x \cdot x}\\

\mathbf{else}:\\
\;\;\;\;\left(-x\right) - \frac{2}{x}\\


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

    1. Initial program 72.6%

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

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

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

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

      \[\leadsto \frac{1}{1 + x} - \color{blue}{\frac{\frac{4}{x \cdot x} - \frac{1}{1 - x} \cdot \frac{1}{1 - x}}{\frac{2}{x} - \frac{1}{1 - x}}} \]
    5. Taylor expanded in x around inf 11.0%

      \[\leadsto \frac{1}{1 + x} - \frac{\frac{4}{x \cdot x} - \frac{1}{1 - x} \cdot \frac{1}{1 - x}}{\color{blue}{\frac{3}{x}}} \]
    6. Taylor expanded in x around inf 59.0%

      \[\leadsto \color{blue}{\frac{-0.3333333333333333}{{x}^{2}}} \]
    7. Step-by-step derivation
      1. unpow259.0%

        \[\leadsto \frac{-0.3333333333333333}{\color{blue}{x \cdot x}} \]
    8. Simplified59.0%

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

    if -1 < x < 1

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot x - 2 \cdot \frac{1}{x}} \]
    5. Step-by-step derivation
      1. neg-mul-199.6%

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

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

        \[\leadsto \left(-x\right) - \frac{\color{blue}{2}}{x} \]
    6. Simplified99.6%

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

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

Alternative 9: 75.6% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-0.3333333333333333}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (or (<= x -1.0) (not (<= x 1.0)))
   (/ -0.3333333333333333 (* x x))
   (/ -2.0 x)))
double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = -0.3333333333333333 / (x * x);
	} else {
		tmp = -2.0 / x;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
        tmp = (-0.3333333333333333d0) / (x * x)
    else
        tmp = (-2.0d0) / x
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = -0.3333333333333333 / (x * x);
	} else {
		tmp = -2.0 / x;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if (x <= -1.0) or not (x <= 1.0):
		tmp = -0.3333333333333333 / (x * x)
	else:
		tmp = -2.0 / x
	return tmp
function code(x)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 1.0))
		tmp = Float64(-0.3333333333333333 / Float64(x * x));
	else
		tmp = Float64(-2.0 / x);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if ((x <= -1.0) || ~((x <= 1.0)))
		tmp = -0.3333333333333333 / (x * x);
	else
		tmp = -2.0 / x;
	end
	tmp_2 = tmp;
end
code[x_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(-0.3333333333333333 / N[(x * x), $MachinePrecision]), $MachinePrecision], N[(-2.0 / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\frac{-0.3333333333333333}{x \cdot x}\\

\mathbf{else}:\\
\;\;\;\;\frac{-2}{x}\\


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

    1. Initial program 72.6%

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

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

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

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

      \[\leadsto \frac{1}{1 + x} - \color{blue}{\frac{\frac{4}{x \cdot x} - \frac{1}{1 - x} \cdot \frac{1}{1 - x}}{\frac{2}{x} - \frac{1}{1 - x}}} \]
    5. Taylor expanded in x around inf 11.0%

      \[\leadsto \frac{1}{1 + x} - \frac{\frac{4}{x \cdot x} - \frac{1}{1 - x} \cdot \frac{1}{1 - x}}{\color{blue}{\frac{3}{x}}} \]
    6. Taylor expanded in x around inf 59.0%

      \[\leadsto \color{blue}{\frac{-0.3333333333333333}{{x}^{2}}} \]
    7. Step-by-step derivation
      1. unpow259.0%

        \[\leadsto \frac{-0.3333333333333333}{\color{blue}{x \cdot x}} \]
    8. Simplified59.0%

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

    if -1 < x < 1

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{\frac{-2}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.5%

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

Alternative 10: 83.1% accurate, 2.1× speedup?

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

\\
1 + \left(-1 - \frac{2}{x}\right)
\end{array}
Derivation
  1. Initial program 85.8%

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

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

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

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

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

Alternative 11: 51.9% accurate, 5.0× speedup?

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

\\
\frac{-2}{x}
\end{array}
Derivation
  1. Initial program 85.8%

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

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

    \[\leadsto \color{blue}{\frac{-2}{x}} \]
  4. Final simplification50.6%

    \[\leadsto \frac{-2}{x} \]

Alternative 12: 3.3% accurate, 15.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
	return -1.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = -1.0d0
end function
public static double code(double x) {
	return -1.0;
}
def code(x):
	return -1.0
function code(x)
	return -1.0
end
function tmp = code(x)
	tmp = -1.0;
end
code[x_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 85.8%

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

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

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

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

    \[\leadsto -1 \]

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 2023285 
(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))))