3frac (problem 3.3.3)

Percentage Accurate: 69.7% → 99.5%
Time: 8.6s
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.7% 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.5% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(2, {x}^{-2}, 2\right) \cdot {x}^{-3} \end{array} \]
(FPCore (x) :precision binary64 (* (fma 2.0 (pow x -2.0) 2.0) (pow x -3.0)))
double code(double x) {
	return fma(2.0, pow(x, -2.0), 2.0) * pow(x, -3.0);
}
function code(x)
	return Float64(fma(2.0, (x ^ -2.0), 2.0) * (x ^ -3.0))
end
code[x_] := N[(N[(2.0 * N[Power[x, -2.0], $MachinePrecision] + 2.0), $MachinePrecision] * N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(2, {x}^{-2}, 2\right) \cdot {x}^{-3}
\end{array}
Derivation
  1. Initial program 66.1%

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

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

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

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

      \[\leadsto \frac{2 + \frac{\color{blue}{2}}{{x}^{2}}}{{x}^{3}} \]
  6. Simplified99.0%

    \[\leadsto \color{blue}{\frac{2 + \frac{2}{{x}^{2}}}{{x}^{3}}} \]
  7. Step-by-step derivation
    1. div-inv99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, {x}^{-2}, 2\right) \cdot {x}^{-3}} \]
  9. Add Preprocessing

Alternative 2: 98.9% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 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 66.1%

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

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

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

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

      \[\leadsto \frac{2 + \frac{\color{blue}{2}}{{x}^{2}}}{{x}^{3}} \]
  6. Simplified99.0%

    \[\leadsto \color{blue}{\frac{2 + \frac{2}{{x}^{2}}}{{x}^{3}}} \]
  7. Step-by-step derivation
    1. div-inv99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(2, {x}^{-2}, 2\right) \cdot {x}^{-3}} \]
  9. Taylor expanded in x around inf 99.1%

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

Alternative 4: 69.7% accurate, 0.8× speedup?

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

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

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

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

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

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

Alternative 5: 69.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{1}{x + 1} + \left(\frac{-2}{x} + \frac{1}{x + -1}\right) \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(1.0 / Float64(x + 1.0)) + Float64(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[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 / x), $MachinePrecision] + N[(1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

Alternative 6: 69.7% accurate, 1.0× speedup?

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

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

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

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

Alternative 7: 68.3% accurate, 1.7× speedup?

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{x}} + \left(\frac{-2}{x} + \frac{1}{x + -1}\right) \]
  5. Step-by-step derivation
    1. *-un-lft-identity64.9%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{x + -1} + \color{blue}{-1} \cdot \frac{1}{x} \]
    7. associate-*r/64.9%

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

      \[\leadsto \frac{1}{x + -1} + \frac{\color{blue}{-1}}{x} \]
  8. Simplified64.9%

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

Alternative 8: 68.1% accurate, 2.1× speedup?

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

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

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

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

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

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

Alternative 9: 52.1% accurate, 2.1× speedup?

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

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

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

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

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

    \[\leadsto \frac{1}{x} + \color{blue}{\frac{\frac{1}{x} - 1}{x}} \]
  6. Step-by-step derivation
    1. *-un-lft-identity64.9%

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

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

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

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

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

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

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

      \[\leadsto 1 \cdot \left(\color{blue}{\sqrt{\frac{-1}{x}} \cdot \sqrt{\frac{-1}{x}}} + \frac{\frac{1}{x} - 1}{x}\right) \]
    9. add-sqr-sqrt5.0%

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

      \[\leadsto 1 \cdot \left(\frac{-1}{x} + \color{blue}{\left(\frac{\frac{1}{x}}{x} - \frac{1}{x}\right)}\right) \]
    11. inv-pow5.0%

      \[\leadsto 1 \cdot \left(\frac{-1}{x} + \left(\frac{\color{blue}{{x}^{-1}}}{x} - \frac{1}{x}\right)\right) \]
    12. pow15.0%

      \[\leadsto 1 \cdot \left(\frac{-1}{x} + \left(\frac{{x}^{-1}}{\color{blue}{{x}^{1}}} - \frac{1}{x}\right)\right) \]
    13. pow-div5.0%

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

      \[\leadsto 1 \cdot \left(\frac{-1}{x} + \left({x}^{\color{blue}{-2}} - \frac{1}{x}\right)\right) \]
    15. add-sqr-sqrt3.0%

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

      \[\leadsto 1 \cdot \left(\frac{-1}{x} + \left({x}^{-2} - \color{blue}{\sqrt{\frac{1}{x} \cdot \frac{1}{x}}}\right)\right) \]
    17. frac-times8.9%

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

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

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

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

      \[\leadsto 1 \cdot \left(\frac{-1}{x} + \left({x}^{-2} - \color{blue}{\sqrt{\frac{-1}{x}} \cdot \sqrt{\frac{-1}{x}}}\right)\right) \]
    22. add-sqr-sqrt64.9%

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

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

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

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

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

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

      \[\leadsto \left(e^{\color{blue}{-2 \cdot \log x}} + \left(-\frac{-1}{x}\right)\right) + \frac{-1}{x} \]
    6. metadata-eval39.3%

      \[\leadsto \left(e^{\color{blue}{\left(-2\right)} \cdot \log x} + \left(-\frac{-1}{x}\right)\right) + \frac{-1}{x} \]
    7. distribute-lft-neg-in39.3%

      \[\leadsto \left(e^{\color{blue}{-2 \cdot \log x}} + \left(-\frac{-1}{x}\right)\right) + \frac{-1}{x} \]
    8. exp-neg39.3%

      \[\leadsto \left(\color{blue}{\frac{1}{e^{2 \cdot \log x}}} + \left(-\frac{-1}{x}\right)\right) + \frac{-1}{x} \]
    9. *-commutative39.3%

      \[\leadsto \left(\frac{1}{e^{\color{blue}{\log x \cdot 2}}} + \left(-\frac{-1}{x}\right)\right) + \frac{-1}{x} \]
    10. exp-to-pow64.9%

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

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

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

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

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

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

      \[\leadsto \left(\frac{-1}{x} \cdot \frac{-1}{x} + \color{blue}{-1 \cdot \frac{-1}{x}}\right) + \frac{-1}{x} \]
    17. distribute-rgt-in64.9%

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

      \[\leadsto \frac{-1}{x} \cdot \left(\frac{-1}{x} + -1\right) + \color{blue}{\frac{-1}{x} \cdot 1} \]
    19. distribute-lft-out64.9%

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

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

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

    \[\leadsto \frac{-1}{x} \cdot \color{blue}{\frac{-1}{x}} \]
  11. Final simplification53.4%

    \[\leadsto \frac{1}{x} \cdot \frac{1}{x} \]
  12. Add Preprocessing

Alternative 10: 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 66.1%

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

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

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

    \[\leadsto \color{blue}{\frac{-1}{x}} \]
  6. Step-by-step derivation
    1. div-inv5.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{1}{x}} \]
    2. add-sqr-sqrt3.0%

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

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

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

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

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

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

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

      \[\leadsto -1 \cdot \color{blue}{\frac{-1}{x}} \]
  7. Applied egg-rr6.3%

    \[\leadsto \color{blue}{-1 \cdot \frac{-1}{x}} \]
  8. Taylor expanded in x around 0 6.3%

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

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

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

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

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

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

Alternative 12: 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 66.1%

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

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

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

Developer Target 1: 99.2% 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 2024139 
(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))))