Asymptote B

Percentage Accurate: 100.0% → 100.0%
Time: 5.6s
Alternatives: 6
Speedup: N/A×

Specification

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

\\
\frac{1}{x - 1} + \frac{x}{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 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: 100.0% accurate, 1.0× speedup?

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

\\
\frac{1}{x - 1} + \frac{x}{x + 1}
\end{array}

Alternative 1: 100.0% accurate, 0.3× speedup?

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

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

    \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
  2. Add Preprocessing
  3. Final simplification100.0%

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

Alternative 2: 99.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{fma}\left(x, x, -1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{x \cdot x} + 1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (+ (pow (- x 1.0) -1.0) (/ x (+ x 1.0))) -1.0)
   (/ (fma x x 1.0) (fma x x -1.0))
   (+ (/ 2.0 (* x x)) 1.0)))
double code(double x) {
	double tmp;
	if ((pow((x - 1.0), -1.0) + (x / (x + 1.0))) <= -1.0) {
		tmp = fma(x, x, 1.0) / fma(x, x, -1.0);
	} else {
		tmp = (2.0 / (x * x)) + 1.0;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64((Float64(x - 1.0) ^ -1.0) + Float64(x / Float64(x + 1.0))) <= -1.0)
		tmp = Float64(fma(x, x, 1.0) / fma(x, x, -1.0));
	else
		tmp = Float64(Float64(2.0 / Float64(x * x)) + 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[Power[N[(x - 1.0), $MachinePrecision], -1.0], $MachinePrecision] + N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], N[(N[(x * x + 1.0), $MachinePrecision] / N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{fma}\left(x, x, -1\right)}\\

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


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

    1. Initial program 100.0%

      \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1} + \frac{x}{x + 1}} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1}} + \frac{x}{x + 1} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{1}{x - 1} + \color{blue}{\frac{x}{x + 1}} \]
      4. frac-addN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x - 1\right) \cdot \left(x + 1\right)}} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      6. lift-+.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right)} \cdot \left(x - 1\right)} \]
      7. lift--.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x + 1\right) \cdot \color{blue}{\left(x - 1\right)}} \]
      8. difference-of-squares-revN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{x \cdot x - 1 \cdot 1}} \]
      9. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1}} \]
      10. *-lft-identityN/A

        \[\leadsto \frac{\color{blue}{\left(x + 1\right)} + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1} \]
      11. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot x + \left(x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      12. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x, x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      13. difference-of-squares-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      14. difference-of-sqr--1-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{x \cdot x + -1}} \]
      15. lower-fma.f64100.0

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    4. Applied rewrites100.0%

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

      \[\leadsto \frac{\color{blue}{1 + {x}^{2}}}{\mathsf{fma}\left(x, x, -1\right)} \]
    6. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{{x}^{2} + 1}}{\mathsf{fma}\left(x, x, -1\right)} \]
      2. unpow2N/A

        \[\leadsto \frac{\color{blue}{x \cdot x} + 1}{\mathsf{fma}\left(x, x, -1\right)} \]
      3. lower-fma.f64100.0

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, x, 1\right)}}{\mathsf{fma}\left(x, x, -1\right)} \]
    7. Applied rewrites100.0%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x, x, 1\right)}}{\mathsf{fma}\left(x, x, -1\right)} \]

    if -1 < (+.f64 (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64))) (/.f64 x (+.f64 x #s(literal 1 binary64))))

    1. Initial program 100.0%

      \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{1 + 2 \cdot \frac{1}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{2}} + 1} \]
      2. lower-+.f64N/A

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

        \[\leadsto \color{blue}{\frac{2 \cdot 1}{{x}^{2}}} + 1 \]
      4. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{2}}{{x}^{2}} + 1 \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{2}{{x}^{2}}} + 1 \]
      6. unpow2N/A

        \[\leadsto \frac{2}{\color{blue}{x \cdot x}} + 1 \]
      7. lower-*.f6499.4

        \[\leadsto \frac{2}{\color{blue}{x \cdot x}} + 1 \]
    5. Applied rewrites99.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{fma}\left(x, x, -1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{x \cdot x} + 1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.1% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;\mathsf{fma}\left(-2, x \cdot x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{x \cdot x} + 1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (+ (pow (- x 1.0) -1.0) (/ x (+ x 1.0))) -1.0)
   (fma -2.0 (* x x) -1.0)
   (+ (/ 2.0 (* x x)) 1.0)))
double code(double x) {
	double tmp;
	if ((pow((x - 1.0), -1.0) + (x / (x + 1.0))) <= -1.0) {
		tmp = fma(-2.0, (x * x), -1.0);
	} else {
		tmp = (2.0 / (x * x)) + 1.0;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64((Float64(x - 1.0) ^ -1.0) + Float64(x / Float64(x + 1.0))) <= -1.0)
		tmp = fma(-2.0, Float64(x * x), -1.0);
	else
		tmp = Float64(Float64(2.0 / Float64(x * x)) + 1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[Power[N[(x - 1.0), $MachinePrecision], -1.0], $MachinePrecision] + N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], N[(-2.0 * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\
\;\;\;\;\mathsf{fma}\left(-2, x \cdot x, -1\right)\\

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


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

    1. Initial program 100.0%

      \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1} + \frac{x}{x + 1}} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1}} + \frac{x}{x + 1} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{1}{x - 1} + \color{blue}{\frac{x}{x + 1}} \]
      4. frac-addN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x - 1\right) \cdot \left(x + 1\right)}} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      6. lift-+.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right)} \cdot \left(x - 1\right)} \]
      7. lift--.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x + 1\right) \cdot \color{blue}{\left(x - 1\right)}} \]
      8. difference-of-squares-revN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{x \cdot x - 1 \cdot 1}} \]
      9. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1}} \]
      10. *-lft-identityN/A

        \[\leadsto \frac{\color{blue}{\left(x + 1\right)} + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1} \]
      11. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot x + \left(x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      12. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x, x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      13. difference-of-squares-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      14. difference-of-sqr--1-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{x \cdot x + -1}} \]
      15. lower-fma.f64100.0

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    4. Applied rewrites100.0%

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

      \[\leadsto \color{blue}{-2 \cdot {x}^{2} - 1} \]
    6. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot {x}^{2} - 1 \]
      2. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot {x}^{2}\right)\right)} - 1 \]
      3. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2} \cdot 2}\right)\right) - 1 \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot 2} - 1 \]
      5. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{x \cdot x}\right)\right) \cdot 2 - 1 \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot x\right)} \cdot 2 - 1 \]
      7. mul-1-negN/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot x\right)} \cdot x\right) \cdot 2 - 1 \]
      8. rgt-mult-inverseN/A

        \[\leadsto \left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 - \color{blue}{{x}^{2} \cdot \frac{1}{{x}^{2}}} \]
      9. fp-cancel-sub-signN/A

        \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}}} \]
      10. mul-1-negN/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      11. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)} \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      12. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      13. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot 2\right)\right)} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot {x}^{2}}\right)\right) + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      15. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right) \cdot {x}^{2}} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      16. metadata-evalN/A

        \[\leadsto \color{blue}{-2} \cdot {x}^{2} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      17. distribute-lft-neg-outN/A

        \[\leadsto -2 \cdot {x}^{2} + \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot \frac{1}{{x}^{2}}\right)\right)} \]
      18. rgt-mult-inverseN/A

        \[\leadsto -2 \cdot {x}^{2} + \left(\mathsf{neg}\left(\color{blue}{1}\right)\right) \]
      19. metadata-evalN/A

        \[\leadsto -2 \cdot {x}^{2} + \color{blue}{-1} \]
      20. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(-2, {x}^{2}, -1\right)} \]
    7. Applied rewrites99.3%

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

    if -1 < (+.f64 (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64))) (/.f64 x (+.f64 x #s(literal 1 binary64))))

    1. Initial program 100.0%

      \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf

      \[\leadsto \color{blue}{1 + 2 \cdot \frac{1}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{2}} + 1} \]
      2. lower-+.f64N/A

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

        \[\leadsto \color{blue}{\frac{2 \cdot 1}{{x}^{2}}} + 1 \]
      4. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{2}}{{x}^{2}} + 1 \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{2}{{x}^{2}}} + 1 \]
      6. unpow2N/A

        \[\leadsto \frac{2}{\color{blue}{x \cdot x}} + 1 \]
      7. lower-*.f6499.4

        \[\leadsto \frac{2}{\color{blue}{x \cdot x}} + 1 \]
    5. Applied rewrites99.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;\mathsf{fma}\left(-2, x \cdot x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{x \cdot x} + 1\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 98.9% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;\mathsf{fma}\left(-2, x \cdot x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (+ (pow (- x 1.0) -1.0) (/ x (+ x 1.0))) -1.0)
   (fma -2.0 (* x x) -1.0)
   1.0))
double code(double x) {
	double tmp;
	if ((pow((x - 1.0), -1.0) + (x / (x + 1.0))) <= -1.0) {
		tmp = fma(-2.0, (x * x), -1.0);
	} else {
		tmp = 1.0;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64((Float64(x - 1.0) ^ -1.0) + Float64(x / Float64(x + 1.0))) <= -1.0)
		tmp = fma(-2.0, Float64(x * x), -1.0);
	else
		tmp = 1.0;
	end
	return tmp
end
code[x_] := If[LessEqual[N[(N[Power[N[(x - 1.0), $MachinePrecision], -1.0], $MachinePrecision] + N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], N[(-2.0 * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision], 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\
\;\;\;\;\mathsf{fma}\left(-2, x \cdot x, -1\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

      \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1} + \frac{x}{x + 1}} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1}} + \frac{x}{x + 1} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{1}{x - 1} + \color{blue}{\frac{x}{x + 1}} \]
      4. frac-addN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x - 1\right) \cdot \left(x + 1\right)}} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      6. lift-+.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right)} \cdot \left(x - 1\right)} \]
      7. lift--.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x + 1\right) \cdot \color{blue}{\left(x - 1\right)}} \]
      8. difference-of-squares-revN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{x \cdot x - 1 \cdot 1}} \]
      9. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1}} \]
      10. *-lft-identityN/A

        \[\leadsto \frac{\color{blue}{\left(x + 1\right)} + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1} \]
      11. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot x + \left(x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      12. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x, x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      13. difference-of-squares-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      14. difference-of-sqr--1-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{x \cdot x + -1}} \]
      15. lower-fma.f64100.0

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    4. Applied rewrites100.0%

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

      \[\leadsto \color{blue}{-2 \cdot {x}^{2} - 1} \]
    6. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot {x}^{2} - 1 \]
      2. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot {x}^{2}\right)\right)} - 1 \]
      3. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2} \cdot 2}\right)\right) - 1 \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot 2} - 1 \]
      5. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{x \cdot x}\right)\right) \cdot 2 - 1 \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot x\right)} \cdot 2 - 1 \]
      7. mul-1-negN/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot x\right)} \cdot x\right) \cdot 2 - 1 \]
      8. rgt-mult-inverseN/A

        \[\leadsto \left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 - \color{blue}{{x}^{2} \cdot \frac{1}{{x}^{2}}} \]
      9. fp-cancel-sub-signN/A

        \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}}} \]
      10. mul-1-negN/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      11. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)} \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      12. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      13. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot 2\right)\right)} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot {x}^{2}}\right)\right) + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      15. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right) \cdot {x}^{2}} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      16. metadata-evalN/A

        \[\leadsto \color{blue}{-2} \cdot {x}^{2} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      17. distribute-lft-neg-outN/A

        \[\leadsto -2 \cdot {x}^{2} + \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot \frac{1}{{x}^{2}}\right)\right)} \]
      18. rgt-mult-inverseN/A

        \[\leadsto -2 \cdot {x}^{2} + \left(\mathsf{neg}\left(\color{blue}{1}\right)\right) \]
      19. metadata-evalN/A

        \[\leadsto -2 \cdot {x}^{2} + \color{blue}{-1} \]
      20. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(-2, {x}^{2}, -1\right)} \]
    7. Applied rewrites99.3%

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

    if -1 < (+.f64 (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64))) (/.f64 x (+.f64 x #s(literal 1 binary64))))

    1. Initial program 100.0%

      \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1} + \frac{x}{x + 1}} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{x - 1}} + \frac{x}{x + 1} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{1}{x - 1} + \color{blue}{\frac{x}{x + 1}} \]
      4. frac-addN/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x - 1\right) \cdot \left(x + 1\right)}} \]
      5. *-commutativeN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      6. lift-+.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right)} \cdot \left(x - 1\right)} \]
      7. lift--.f64N/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x + 1\right) \cdot \color{blue}{\left(x - 1\right)}} \]
      8. difference-of-squares-revN/A

        \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{x \cdot x - 1 \cdot 1}} \]
      9. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1}} \]
      10. *-lft-identityN/A

        \[\leadsto \frac{\color{blue}{\left(x + 1\right)} + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1} \]
      11. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot x + \left(x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      12. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x, x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
      13. difference-of-squares-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
      14. difference-of-sqr--1-revN/A

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{x \cdot x + -1}} \]
      15. lower-fma.f6453.5

        \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    4. Applied rewrites53.5%

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

      \[\leadsto \color{blue}{-2 \cdot {x}^{2} - 1} \]
    6. Step-by-step derivation
      1. metadata-evalN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot {x}^{2} - 1 \]
      2. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot {x}^{2}\right)\right)} - 1 \]
      3. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2} \cdot 2}\right)\right) - 1 \]
      4. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot 2} - 1 \]
      5. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{x \cdot x}\right)\right) \cdot 2 - 1 \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot x\right)} \cdot 2 - 1 \]
      7. mul-1-negN/A

        \[\leadsto \left(\color{blue}{\left(-1 \cdot x\right)} \cdot x\right) \cdot 2 - 1 \]
      8. rgt-mult-inverseN/A

        \[\leadsto \left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 - \color{blue}{{x}^{2} \cdot \frac{1}{{x}^{2}}} \]
      9. fp-cancel-sub-signN/A

        \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}}} \]
      10. mul-1-negN/A

        \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      11. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)} \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      12. unpow2N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      13. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot 2\right)\right)} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      14. *-commutativeN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot {x}^{2}}\right)\right) + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      15. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right) \cdot {x}^{2}} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      16. metadata-evalN/A

        \[\leadsto \color{blue}{-2} \cdot {x}^{2} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
      17. distribute-lft-neg-outN/A

        \[\leadsto -2 \cdot {x}^{2} + \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot \frac{1}{{x}^{2}}\right)\right)} \]
      18. rgt-mult-inverseN/A

        \[\leadsto -2 \cdot {x}^{2} + \left(\mathsf{neg}\left(\color{blue}{1}\right)\right) \]
      19. metadata-evalN/A

        \[\leadsto -2 \cdot {x}^{2} + \color{blue}{-1} \]
      20. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(-2, {x}^{2}, -1\right)} \]
    7. Applied rewrites0.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-2, x \cdot x, -1\right)} \]
    8. Step-by-step derivation
      1. Applied rewrites0.9%

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

        \[\leadsto \color{blue}{1} \]
      3. Step-by-step derivation
        1. Applied rewrites98.8%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;\mathsf{fma}\left(-2, x \cdot x, -1\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
      6. Add Preprocessing

      Alternative 5: 98.5% accurate, 0.2× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
      (FPCore (x)
       :precision binary64
       (if (<= (+ (pow (- x 1.0) -1.0) (/ x (+ x 1.0))) -1.0) -1.0 1.0))
      double code(double x) {
      	double tmp;
      	if ((pow((x - 1.0), -1.0) + (x / (x + 1.0))) <= -1.0) {
      		tmp = -1.0;
      	} else {
      		tmp = 1.0;
      	}
      	return tmp;
      }
      
      real(8) function code(x)
          real(8), intent (in) :: x
          real(8) :: tmp
          if ((((x - 1.0d0) ** (-1.0d0)) + (x / (x + 1.0d0))) <= (-1.0d0)) then
              tmp = -1.0d0
          else
              tmp = 1.0d0
          end if
          code = tmp
      end function
      
      public static double code(double x) {
      	double tmp;
      	if ((Math.pow((x - 1.0), -1.0) + (x / (x + 1.0))) <= -1.0) {
      		tmp = -1.0;
      	} else {
      		tmp = 1.0;
      	}
      	return tmp;
      }
      
      def code(x):
      	tmp = 0
      	if (math.pow((x - 1.0), -1.0) + (x / (x + 1.0))) <= -1.0:
      		tmp = -1.0
      	else:
      		tmp = 1.0
      	return tmp
      
      function code(x)
      	tmp = 0.0
      	if (Float64((Float64(x - 1.0) ^ -1.0) + Float64(x / Float64(x + 1.0))) <= -1.0)
      		tmp = -1.0;
      	else
      		tmp = 1.0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x)
      	tmp = 0.0;
      	if ((((x - 1.0) ^ -1.0) + (x / (x + 1.0))) <= -1.0)
      		tmp = -1.0;
      	else
      		tmp = 1.0;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_] := If[LessEqual[N[(N[Power[N[(x - 1.0), $MachinePrecision], -1.0], $MachinePrecision] + N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], -1.0, 1.0]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\
      \;\;\;\;-1\\
      
      \mathbf{else}:\\
      \;\;\;\;1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (+.f64 (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64))) (/.f64 x (+.f64 x #s(literal 1 binary64)))) < -1

        1. Initial program 100.0%

          \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

          \[\leadsto \color{blue}{-1} \]
        4. Step-by-step derivation
          1. Applied rewrites99.3%

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

          if -1 < (+.f64 (/.f64 #s(literal 1 binary64) (-.f64 x #s(literal 1 binary64))) (/.f64 x (+.f64 x #s(literal 1 binary64))))

          1. Initial program 100.0%

            \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-+.f64N/A

              \[\leadsto \color{blue}{\frac{1}{x - 1} + \frac{x}{x + 1}} \]
            2. lift-/.f64N/A

              \[\leadsto \color{blue}{\frac{1}{x - 1}} + \frac{x}{x + 1} \]
            3. lift-/.f64N/A

              \[\leadsto \frac{1}{x - 1} + \color{blue}{\frac{x}{x + 1}} \]
            4. frac-addN/A

              \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x - 1\right) \cdot \left(x + 1\right)}} \]
            5. *-commutativeN/A

              \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
            6. lift-+.f64N/A

              \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{\left(x + 1\right)} \cdot \left(x - 1\right)} \]
            7. lift--.f64N/A

              \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\left(x + 1\right) \cdot \color{blue}{\left(x - 1\right)}} \]
            8. difference-of-squares-revN/A

              \[\leadsto \frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{\color{blue}{x \cdot x - 1 \cdot 1}} \]
            9. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{1 \cdot \left(x + 1\right) + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1}} \]
            10. *-lft-identityN/A

              \[\leadsto \frac{\color{blue}{\left(x + 1\right)} + \left(x - 1\right) \cdot x}{x \cdot x - 1 \cdot 1} \]
            11. +-commutativeN/A

              \[\leadsto \frac{\color{blue}{\left(x - 1\right) \cdot x + \left(x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
            12. lower-fma.f64N/A

              \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(x - 1, x, x + 1\right)}}{x \cdot x - 1 \cdot 1} \]
            13. difference-of-squares-revN/A

              \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\left(x + 1\right) \cdot \left(x - 1\right)}} \]
            14. difference-of-sqr--1-revN/A

              \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{x \cdot x + -1}} \]
            15. lower-fma.f6453.5

              \[\leadsto \frac{\mathsf{fma}\left(x - 1, x, x + 1\right)}{\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
          4. Applied rewrites53.5%

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

            \[\leadsto \color{blue}{-2 \cdot {x}^{2} - 1} \]
          6. Step-by-step derivation
            1. metadata-evalN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right)} \cdot {x}^{2} - 1 \]
            2. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2 \cdot {x}^{2}\right)\right)} - 1 \]
            3. *-commutativeN/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2} \cdot 2}\right)\right) - 1 \]
            4. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot 2} - 1 \]
            5. unpow2N/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{x \cdot x}\right)\right) \cdot 2 - 1 \]
            6. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(x\right)\right) \cdot x\right)} \cdot 2 - 1 \]
            7. mul-1-negN/A

              \[\leadsto \left(\color{blue}{\left(-1 \cdot x\right)} \cdot x\right) \cdot 2 - 1 \]
            8. rgt-mult-inverseN/A

              \[\leadsto \left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 - \color{blue}{{x}^{2} \cdot \frac{1}{{x}^{2}}} \]
            9. fp-cancel-sub-signN/A

              \[\leadsto \color{blue}{\left(\left(-1 \cdot x\right) \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}}} \]
            10. mul-1-negN/A

              \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot x\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            11. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x \cdot x\right)\right)} \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            12. unpow2N/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{{x}^{2}}\right)\right) \cdot 2 + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            13. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot 2\right)\right)} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            14. *-commutativeN/A

              \[\leadsto \left(\mathsf{neg}\left(\color{blue}{2 \cdot {x}^{2}}\right)\right) + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            15. distribute-lft-neg-inN/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(2\right)\right) \cdot {x}^{2}} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            16. metadata-evalN/A

              \[\leadsto \color{blue}{-2} \cdot {x}^{2} + \left(\mathsf{neg}\left({x}^{2}\right)\right) \cdot \frac{1}{{x}^{2}} \]
            17. distribute-lft-neg-outN/A

              \[\leadsto -2 \cdot {x}^{2} + \color{blue}{\left(\mathsf{neg}\left({x}^{2} \cdot \frac{1}{{x}^{2}}\right)\right)} \]
            18. rgt-mult-inverseN/A

              \[\leadsto -2 \cdot {x}^{2} + \left(\mathsf{neg}\left(\color{blue}{1}\right)\right) \]
            19. metadata-evalN/A

              \[\leadsto -2 \cdot {x}^{2} + \color{blue}{-1} \]
            20. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(-2, {x}^{2}, -1\right)} \]
          7. Applied rewrites0.9%

            \[\leadsto \color{blue}{\mathsf{fma}\left(-2, x \cdot x, -1\right)} \]
          8. Step-by-step derivation
            1. Applied rewrites0.9%

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

              \[\leadsto \color{blue}{1} \]
            3. Step-by-step derivation
              1. Applied rewrites98.8%

                \[\leadsto \color{blue}{1} \]
            4. Recombined 2 regimes into one program.
            5. Final simplification99.0%

              \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(x - 1\right)}^{-1} + \frac{x}{x + 1} \leq -1:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
            6. Add Preprocessing

            Alternative 6: 50.5% accurate, 32.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 100.0%

              \[\frac{1}{x - 1} + \frac{x}{x + 1} \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{-1} \]
            4. Step-by-step derivation
              1. Applied rewrites45.1%

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

                \[\leadsto -1 \]
              3. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2024337 
              (FPCore (x)
                :name "Asymptote B"
                :precision binary64
                (+ (/ 1.0 (- x 1.0)) (/ x (+ x 1.0))))