3frac (problem 3.3.3)

Percentage Accurate: 69.1% → 99.6%
Time: 22.2s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[\left|x\right| > 1\]
\[\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: 69.1% 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.0× speedup?

\[\begin{array}{l} \\ \left(2 + 2 \cdot \left({x}^{-4} + {x}^{-2}\right)\right) \cdot {x}^{-3} \end{array} \]
(FPCore (x)
 :precision binary64
 (* (+ 2.0 (* 2.0 (+ (pow x -4.0) (pow x -2.0)))) (pow x -3.0)))
double code(double x) {
	return (2.0 + (2.0 * (pow(x, -4.0) + pow(x, -2.0)))) * pow(x, -3.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (2.0d0 + (2.0d0 * ((x ** (-4.0d0)) + (x ** (-2.0d0))))) * (x ** (-3.0d0))
end function
public static double code(double x) {
	return (2.0 + (2.0 * (Math.pow(x, -4.0) + Math.pow(x, -2.0)))) * Math.pow(x, -3.0);
}
def code(x):
	return (2.0 + (2.0 * (math.pow(x, -4.0) + math.pow(x, -2.0)))) * math.pow(x, -3.0)
function code(x)
	return Float64(Float64(2.0 + Float64(2.0 * Float64((x ^ -4.0) + (x ^ -2.0)))) * (x ^ -3.0))
end
function tmp = code(x)
	tmp = (2.0 + (2.0 * ((x ^ -4.0) + (x ^ -2.0)))) * (x ^ -3.0);
end
code[x_] := N[(N[(2.0 + N[(2.0 * N[(N[Power[x, -4.0], $MachinePrecision] + N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(2 + 2 \cdot \left({x}^{-4} + {x}^{-2}\right)\right) \cdot {x}^{-3}
\end{array}
Derivation
  1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{\color{blue}{-4}}, \frac{2}{{x}^{2}}\right)\right) \cdot \frac{1}{{x}^{3}} \]
    7. div-inv98.5%

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

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

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{\color{blue}{-2}}\right)\right) \cdot \frac{1}{{x}^{3}} \]
    10. pow-flip99.8%

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{-2}\right)\right) \cdot \color{blue}{{x}^{\left(-3\right)}} \]
    11. metadata-eval99.8%

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{-2}\right)\right) \cdot {x}^{\color{blue}{-3}} \]
  9. Applied egg-rr99.8%

    \[\leadsto \color{blue}{\left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{-2}\right)\right) \cdot {x}^{-3}} \]
  10. Step-by-step derivation
    1. fma-undefine99.8%

      \[\leadsto \left(2 + \color{blue}{\left(2 \cdot {x}^{-4} + 2 \cdot {x}^{-2}\right)}\right) \cdot {x}^{-3} \]
    2. distribute-lft-out99.8%

      \[\leadsto \left(2 + \color{blue}{2 \cdot \left({x}^{-4} + {x}^{-2}\right)}\right) \cdot {x}^{-3} \]
  11. Simplified99.8%

    \[\leadsto \color{blue}{\left(2 + 2 \cdot \left({x}^{-4} + {x}^{-2}\right)\right) \cdot {x}^{-3}} \]
  12. Add Preprocessing

Alternative 2: 99.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ 2 \cdot {x}^{-3} \end{array} \]
(FPCore (x) :precision binary64 (* 2.0 (pow x -3.0)))
double code(double x) {
	return 2.0 * pow(x, -3.0);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 2.0d0 * (x ** (-3.0d0))
end function
public static double code(double x) {
	return 2.0 * Math.pow(x, -3.0);
}
def code(x):
	return 2.0 * math.pow(x, -3.0)
function code(x)
	return Float64(2.0 * (x ^ -3.0))
end
function tmp = code(x)
	tmp = 2.0 * (x ^ -3.0);
end
code[x_] := N[(2.0 * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot {x}^{-3}
\end{array}
Derivation
  1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{\color{blue}{-4}}, \frac{2}{{x}^{2}}\right)\right) \cdot \frac{1}{{x}^{3}} \]
    7. div-inv98.5%

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

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

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{\color{blue}{-2}}\right)\right) \cdot \frac{1}{{x}^{3}} \]
    10. pow-flip99.8%

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{-2}\right)\right) \cdot \color{blue}{{x}^{\left(-3\right)}} \]
    11. metadata-eval99.8%

      \[\leadsto \left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{-2}\right)\right) \cdot {x}^{\color{blue}{-3}} \]
  9. Applied egg-rr99.8%

    \[\leadsto \color{blue}{\left(2 + \mathsf{fma}\left(2, {x}^{-4}, 2 \cdot {x}^{-2}\right)\right) \cdot {x}^{-3}} \]
  10. Step-by-step derivation
    1. fma-undefine99.8%

      \[\leadsto \left(2 + \color{blue}{\left(2 \cdot {x}^{-4} + 2 \cdot {x}^{-2}\right)}\right) \cdot {x}^{-3} \]
    2. distribute-lft-out99.8%

      \[\leadsto \left(2 + \color{blue}{2 \cdot \left({x}^{-4} + {x}^{-2}\right)}\right) \cdot {x}^{-3} \]
  11. Simplified99.8%

    \[\leadsto \color{blue}{\left(2 + 2 \cdot \left({x}^{-4} + {x}^{-2}\right)\right) \cdot {x}^{-3}} \]
  12. Taylor expanded in x around inf 99.2%

    \[\leadsto \color{blue}{2} \cdot {x}^{-3} \]
  13. Add Preprocessing

Alternative 3: 69.0% accurate, 1.0× speedup?

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

\\
\frac{-2}{x} - \frac{2}{-1 - x} \cdot \frac{x}{x + -1}
\end{array}
Derivation
  1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-2}{x} - \color{blue}{\frac{2}{-1 - x} \cdot \frac{x}{x + -1}} \]
  12. Applied egg-rr79.0%

    \[\leadsto \frac{-2}{x} - \color{blue}{\frac{2}{-1 - x} \cdot \frac{x}{x + -1}} \]
  13. Add Preprocessing

Alternative 4: 69.1% 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}
Derivation
  1. Initial program 79.1%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Add Preprocessing
  3. Final simplification79.1%

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

Alternative 5: 67.7% accurate, 1.4× speedup?

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

\\
\frac{1 + \frac{1}{x}}{x} + \frac{-1}{x}
\end{array}
Derivation
  1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1 + \frac{1}{x}}{x}} + \frac{-1}{x} \]
  7. Add Preprocessing

Alternative 6: 67.7% accurate, 1.7× speedup?

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

\\
\frac{-1}{x} + \frac{1}{x + -1}
\end{array}
Derivation
  1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{x + -1} + \color{blue}{\frac{-1}{x}} \]
  6. Final simplification78.0%

    \[\leadsto \frac{-1}{x} + \frac{1}{x + -1} \]
  7. Add Preprocessing

Alternative 7: 67.9% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{x + -1} + \color{blue}{\frac{-1}{x}} \]
  6. Taylor expanded in x around 0 5.4%

    \[\leadsto \color{blue}{\frac{-1}{x}} \]
  7. Step-by-step derivation
    1. add-sqr-sqrt2.7%

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

      \[\leadsto \color{blue}{\sqrt{\frac{-1}{x} \cdot \frac{-1}{x}}} \]
    3. frac-times55.1%

      \[\leadsto \sqrt{\color{blue}{\frac{-1 \cdot -1}{x \cdot x}}} \]
    4. metadata-eval55.1%

      \[\leadsto \sqrt{\frac{\color{blue}{1}}{x \cdot x}} \]
    5. metadata-eval55.1%

      \[\leadsto \sqrt{\frac{\color{blue}{1 \cdot 1}}{x \cdot x}} \]
    6. frac-times53.3%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{x} \cdot \frac{1}{x}}} \]
    7. sqrt-prod3.0%

      \[\leadsto \color{blue}{\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}} \]
    8. expm1-log1p-u3.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}\right)\right)} \]
    9. add-sqr-sqrt6.1%

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{1}{x}}\right)\right) \]
    10. log1p-define78.1%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\log \left(1 + \frac{1}{x}\right)}\right) \]
    11. expm1-undefine78.1%

      \[\leadsto \color{blue}{e^{\log \left(1 + \frac{1}{x}\right)} - 1} \]
    12. add-exp-log78.1%

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

    \[\leadsto \color{blue}{\left(1 + \frac{1}{x}\right) - 1} \]
  9. Step-by-step derivation
    1. associate--l+78.1%

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

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

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

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

    \[\leadsto 1 + \left(-1 + \frac{1}{x}\right) \]
  12. Add Preprocessing

Alternative 8: 67.5% accurate, 2.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{x + -1} + \color{blue}{\frac{x - 2}{x}} \]
  6. Taylor expanded in x around 0 77.8%

    \[\leadsto \color{blue}{-1} + \frac{x - 2}{x} \]
  7. Add Preprocessing

Alternative 9: 6.3% accurate, 5.0× speedup?

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

\\
\frac{1}{x}
\end{array}
Derivation
  1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-2 - -1}{x}} + \frac{1}{x + -1} \]
    3. metadata-eval78.0%

      \[\leadsto \frac{\color{blue}{-1}}{x} + \frac{1}{x + -1} \]
    4. +-commutative78.0%

      \[\leadsto \color{blue}{\frac{1}{x + -1} + \frac{-1}{x}} \]
    5. add-sqr-sqrt22.9%

      \[\leadsto \frac{1}{x + -1} + \color{blue}{\sqrt{\frac{-1}{x}} \cdot \sqrt{\frac{-1}{x}}} \]
    6. sqrt-unprod20.8%

      \[\leadsto \frac{1}{x + -1} + \color{blue}{\sqrt{\frac{-1}{x} \cdot \frac{-1}{x}}} \]
    7. frac-times17.8%

      \[\leadsto \frac{1}{x + -1} + \sqrt{\color{blue}{\frac{-1 \cdot -1}{x \cdot x}}} \]
    8. metadata-eval17.8%

      \[\leadsto \frac{1}{x + -1} + \sqrt{\frac{\color{blue}{1}}{x \cdot x}} \]
    9. metadata-eval17.8%

      \[\leadsto \frac{1}{x + -1} + \sqrt{\frac{\color{blue}{1 \cdot 1}}{x \cdot x}} \]
    10. frac-times20.8%

      \[\leadsto \frac{1}{x + -1} + \sqrt{\color{blue}{\frac{1}{x} \cdot \frac{1}{x}}} \]
    11. sqrt-prod3.0%

      \[\leadsto \frac{1}{x + -1} + \color{blue}{\sqrt{\frac{1}{x}} \cdot \sqrt{\frac{1}{x}}} \]
    12. add-sqr-sqrt6.1%

      \[\leadsto \frac{1}{x + -1} + \color{blue}{\frac{1}{x}} \]
  9. Applied egg-rr6.1%

    \[\leadsto \color{blue}{\frac{1}{x + -1} + \frac{1}{x}} \]
  10. Taylor expanded in x around 0 6.1%

    \[\leadsto \color{blue}{\frac{1}{x}} \]
  11. Add Preprocessing

Alternative 10: 5.1% accurate, 5.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{x + -1} + \color{blue}{\frac{-1}{x}} \]
  6. Taylor expanded in x around 0 5.4%

    \[\leadsto \color{blue}{\frac{-1}{x}} \]
  7. Add Preprocessing

Alternative 11: 5.1% 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 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-2}{x}} \]
  6. Add Preprocessing

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 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{x + -1} + \color{blue}{\frac{x - 2}{x}} \]
  6. Taylor expanded in x around inf 3.2%

    \[\leadsto \color{blue}{1} \]
  7. Add Preprocessing

Developer Target 1: 99.1% 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 2024143 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64
  :pre (> (fabs x) 1.0)

  :alt
  (! :herbie-platform default (/ 2 (* x (- (* x x) 1))))

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