2frac (problem 3.3.1)

Percentage Accurate: 77.7% → 99.9%
Time: 6.0s
Alternatives: 6
Speedup: 1.3×

Specification

?
\[\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}

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 6 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: 77.7% accurate, 1.0× 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}

Alternative 1: 99.9% accurate, 1.3× speedup?

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

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

    \[\frac{1}{x + 1} - \frac{1}{x} \]
  2. Step-by-step derivation
    1. frac-2neg76.6%

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

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

      \[\leadsto \color{blue}{\frac{\left(-1\right) \cdot \left(-x\right) - \left(-\left(x + 1\right)\right) \cdot \left(-1\right)}{\left(-\left(x + 1\right)\right) \cdot \left(-x\right)}} \]
    4. distribute-rgt-neg-in77.0%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{x + \left(x + 1\right) \cdot \left(-1\right)}}{\left(-\left(x + 1\right)\right) \cdot \left(-x\right)} \]
    10. distribute-rgt-neg-in77.0%

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

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

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

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

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

      \[\leadsto \frac{x + \left(\color{blue}{-1} - x\right)}{\left(-\left(x + 1\right)\right) \cdot \left(-x\right)} \]
    16. *-commutative77.0%

      \[\leadsto \frac{x + \left(-1 - x\right)}{\color{blue}{\left(-x\right) \cdot \left(-\left(x + 1\right)\right)}} \]
    17. neg-sub077.0%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-1 + \left(x - x\right)}{\color{blue}{-x \cdot \left(-1 - x\right)}} \]
    5. distribute-rgt-neg-in99.4%

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{-\frac{1}{x}}}{-\left(-1 - x\right)} \]
    6. clear-num99.3%

      \[\leadsto \color{blue}{\frac{1}{\frac{-\left(-1 - x\right)}{-\frac{1}{x}}}} \]
    7. associate-/r/99.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{x + 1} \cdot \frac{\color{blue}{-1}}{x} \]
  7. Applied egg-rr99.8%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x + 1} \cdot -1}{x}} \]
    2. *-commutative99.9%

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{-1 + x}}{x}} \]
  10. Step-by-step derivation
    1. div-inv47.7%

      \[\leadsto \color{blue}{\frac{-1}{-1 + x} \cdot \frac{1}{x}} \]
    2. add-sqr-sqrt21.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{-1}{-1 + x} \cdot \color{blue}{\frac{-1}{x}} \]
    10. div-inv74.6%

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

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

      \[\leadsto \color{blue}{-\frac{-1}{-1 + x} \cdot \frac{1}{x}} \]
    13. add-sqr-sqrt35.6%

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

      \[\leadsto -\color{blue}{\left(\frac{-1}{-1 + x} \cdot \sqrt{\frac{1}{x}}\right) \cdot \sqrt{\frac{1}{x}}} \]
    15. distribute-rgt-neg-in35.6%

      \[\leadsto \color{blue}{\left(\frac{-1}{-1 + x} \cdot \sqrt{\frac{1}{x}}\right) \cdot \left(-\sqrt{\frac{1}{x}}\right)} \]
  11. Applied egg-rr46.6%

    \[\leadsto \color{blue}{\left(\frac{1}{1 + x} \cdot {x}^{-0.5}\right) \cdot \left(-{x}^{-0.5}\right)} \]
  12. Step-by-step derivation
    1. associate-*l/46.6%

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

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

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

      \[\leadsto \frac{\color{blue}{-{x}^{-0.5} \cdot {x}^{-0.5}}}{1 + x} \]
    5. pow-sqr99.9%

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

      \[\leadsto \frac{-{x}^{\color{blue}{-1}}}{1 + x} \]
    7. unpow-199.9%

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

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{-1}{x}}{x + 1}} \]
  14. Final simplification99.9%

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

Alternative 2: 98.5% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 51.4%

      \[\frac{1}{x + 1} - \frac{1}{x} \]
    2. Step-by-step derivation
      1. frac-2neg51.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{x + \left(x + 1\right) \cdot \left(-1\right)}}{\left(-\left(x + 1\right)\right) \cdot \left(-x\right)} \]
      10. distribute-rgt-neg-in52.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-1 + \left(x - x\right)}}{\left(-x\right) \cdot \left(-1 - x\right)} \]
      4. distribute-lft-neg-out98.8%

        \[\leadsto \frac{-1 + \left(x - x\right)}{\color{blue}{-x \cdot \left(-1 - x\right)}} \]
      5. distribute-rgt-neg-in98.8%

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

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

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

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

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

        \[\leadsto \frac{\frac{\color{blue}{-1}}{x}}{-\left(-1 - x\right)} \]
      5. distribute-neg-frac99.8%

        \[\leadsto \frac{\color{blue}{-\frac{1}{x}}}{-\left(-1 - x\right)} \]
      6. clear-num98.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{x + 1} \cdot \color{blue}{\frac{-1}{x}} \]
      19. metadata-eval99.6%

        \[\leadsto \frac{1}{x + 1} \cdot \frac{\color{blue}{-1}}{x} \]
    7. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{1}{x + 1} \cdot \frac{-1}{x}} \]
    8. Step-by-step derivation
      1. associate-*r/99.8%

        \[\leadsto \color{blue}{\frac{\frac{1}{x + 1} \cdot -1}{x}} \]
      2. *-commutative99.8%

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

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

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

    if -1 < x < 1

    1. Initial program 100.0%

      \[\frac{1}{x + 1} - \frac{1}{x} \]
    2. Taylor expanded in x around 0 99.6%

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

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

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

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

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

Alternative 3: 98.4% accurate, 1.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1 + \frac{-1}{x}\\


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

    1. Initial program 51.4%

      \[\frac{1}{x + 1} - \frac{1}{x} \]
    2. Step-by-step derivation
      1. frac-2neg51.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{x + \left(x + 1\right) \cdot \left(-1\right)}}{\left(-\left(x + 1\right)\right) \cdot \left(-x\right)} \]
      10. distribute-rgt-neg-in52.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-1 + \left(x - x\right)}}{\left(-x\right) \cdot \left(-1 - x\right)} \]
      4. distribute-lft-neg-out98.8%

        \[\leadsto \frac{-1 + \left(x - x\right)}{\color{blue}{-x \cdot \left(-1 - x\right)}} \]
      5. distribute-rgt-neg-in98.8%

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

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

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

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

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

        \[\leadsto \frac{\frac{\color{blue}{-1}}{x}}{-\left(-1 - x\right)} \]
      5. distribute-neg-frac99.8%

        \[\leadsto \frac{\color{blue}{-\frac{1}{x}}}{-\left(-1 - x\right)} \]
      6. clear-num98.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{x + 1} \cdot \color{blue}{\frac{-1}{x}} \]
      19. metadata-eval99.6%

        \[\leadsto \frac{1}{x + 1} \cdot \frac{\color{blue}{-1}}{x} \]
    7. Applied egg-rr99.6%

      \[\leadsto \color{blue}{\frac{1}{x + 1} \cdot \frac{-1}{x}} \]
    8. Step-by-step derivation
      1. associate-*r/99.8%

        \[\leadsto \color{blue}{\frac{\frac{1}{x + 1} \cdot -1}{x}} \]
      2. *-commutative99.8%

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

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

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

    if -1 < x < 0.75

    1. Initial program 100.0%

      \[\frac{1}{x + 1} - \frac{1}{x} \]
    2. Taylor expanded in x around 0 99.5%

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

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

Alternative 4: 51.3% accurate, 3.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 76.6%

    \[\frac{1}{x + 1} - \frac{1}{x} \]
  2. Taylor expanded in x around 0 53.8%

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

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

Alternative 5: 3.1% accurate, 4.5× speedup?

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

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

    \[\frac{1}{x + 1} - \frac{1}{x} \]
  2. Taylor expanded in x around 0 52.9%

    \[\leadsto \color{blue}{\left(1 + -1 \cdot x\right) - \frac{1}{x}} \]
  3. Step-by-step derivation
    1. mul-1-neg52.9%

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

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

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

    \[\leadsto \color{blue}{-1 \cdot x} \]
  6. Step-by-step derivation
    1. mul-1-neg3.1%

      \[\leadsto \color{blue}{-x} \]
  7. Simplified3.1%

    \[\leadsto \color{blue}{-x} \]
  8. Final simplification3.1%

    \[\leadsto -x \]

Alternative 6: 2.0% accurate, 9.0× speedup?

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

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

    \[\frac{1}{x + 1} - \frac{1}{x} \]
  2. Taylor expanded in x around 0 52.9%

    \[\leadsto \color{blue}{\left(1 + -1 \cdot x\right) - \frac{1}{x}} \]
  3. Step-by-step derivation
    1. mul-1-neg52.9%

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

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

    \[\leadsto \color{blue}{\left(1 - x\right) - \frac{1}{x}} \]
  5. Step-by-step derivation
    1. sub-neg52.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{x} \]
  8. Final simplification2.0%

    \[\leadsto x \]

Reproduce

?
herbie shell --seed 2023305 
(FPCore (x)
  :name "2frac (problem 3.3.1)"
  :precision binary64
  (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))