Asymptote C

Percentage Accurate: 53.4% → 99.7%
Time: 6.7s
Alternatives: 9
Speedup: 0.7×

Specification

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

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

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

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

Alternative 1: 99.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x - 1}{1 + x}\\ \mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 10^{-5}:\\ \;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{t\_0}{1 + x}, \frac{x}{t\_0}, \frac{-1 - x}{x - 1}\right)\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ (- x 1.0) (+ 1.0 x))))
   (if (<= (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0))) 1e-5)
     (/ (- -3.0 (/ (- (/ 3.0 x) -1.0) x)) x)
     (fma (/ t_0 (+ 1.0 x)) (/ x t_0) (/ (- -1.0 x) (- x 1.0))))))
double code(double x) {
	double t_0 = (x - 1.0) / (1.0 + x);
	double tmp;
	if (((x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))) <= 1e-5) {
		tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
	} else {
		tmp = fma((t_0 / (1.0 + x)), (x / t_0), ((-1.0 - x) / (x - 1.0)));
	}
	return tmp;
}
function code(x)
	t_0 = Float64(Float64(x - 1.0) / Float64(1.0 + x))
	tmp = 0.0
	if (Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0))) <= 1e-5)
		tmp = Float64(Float64(-3.0 - Float64(Float64(Float64(3.0 / x) - -1.0) / x)) / x);
	else
		tmp = fma(Float64(t_0 / Float64(1.0 + x)), Float64(x / t_0), Float64(Float64(-1.0 - x) / Float64(x - 1.0)));
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[(N[(x - 1.0), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-5], N[(N[(-3.0 - N[(N[(N[(3.0 / x), $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[(t$95$0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * N[(x / t$95$0), $MachinePrecision] + N[(N[(-1.0 - x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x - 1}{1 + x}\\
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 10^{-5}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t\_0}{1 + x}, \frac{x}{t\_0}, \frac{-1 - x}{x - 1}\right)\\


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

    1. Initial program 8.5%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}} \]
    4. Applied rewrites99.7%

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

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

    1. Initial program 99.9%

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot \frac{x - 1}{x + 1} - \color{blue}{\left(x + 1\right)} \cdot 1}{\left(x + 1\right) \cdot \frac{x - 1}{x + 1}} \]
      8. distribute-rgt1-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.7% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 3 \cdot 10^{-14}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(\mathsf{fma}\left(-3, x, 2\right), x, 1\right)}{\mathsf{fma}\left(x, x, -1\right)}}{x - 1}\\


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

    1. Initial program 7.2%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}} \]
    4. Applied rewrites99.7%

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

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

    1. Initial program 99.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot \frac{x - 1}{x + 1} - \color{blue}{\left(x + 1\right)} \cdot 1}{\left(x + 1\right) \cdot \frac{x - 1}{x + 1}} \]
      8. distribute-rgt1-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\left(\frac{x \cdot \left(x - 1\right)}{\color{blue}{1 + x}} + -1\right) - x}{x - 1} \]
      7. associate-*r/N/A

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

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

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

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

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

        \[\leadsto \frac{x \cdot \frac{\color{blue}{x - 1}}{1 + x} - \left(1 + x\right)}{x - 1} \]
      13. associate-*r/N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{1 + x} - \frac{1 + x}{x - 1}\\ \mathbf{if}\;t\_0 \leq 10^{-5}:\\ \;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0)))))
   (if (<= t_0 1e-5) (/ (- -3.0 (/ (- (/ 3.0 x) -1.0) x)) x) t_0)))
double code(double x) {
	double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
	double tmp;
	if (t_0 <= 1e-5) {
		tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x / (1.0d0 + x)) - ((1.0d0 + x) / (x - 1.0d0))
    if (t_0 <= 1d-5) then
        tmp = ((-3.0d0) - (((3.0d0 / x) - (-1.0d0)) / x)) / x
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
	double tmp;
	if (t_0 <= 1e-5) {
		tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))
	tmp = 0
	if t_0 <= 1e-5:
		tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0)))
	tmp = 0.0
	if (t_0 <= 1e-5)
		tmp = Float64(Float64(-3.0 - Float64(Float64(Float64(3.0 / x) - -1.0) / x)) / x);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
	tmp = 0.0;
	if (t_0 <= 1e-5)
		tmp = (-3.0 - (((3.0 / x) - -1.0) / x)) / x;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(N[(-3.0 - N[(N[(N[(3.0 / x), $MachinePrecision] - -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], t$95$0]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{1 + x} - \frac{1 + x}{x - 1}\\
\mathbf{if}\;t\_0 \leq 10^{-5}:\\
\;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 8.5%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot \frac{1 + 3 \cdot \frac{1}{x}}{x} - 3}{x}} \]
    4. Applied rewrites99.7%

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

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

    1. Initial program 99.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification99.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 10^{-5}:\\ \;\;\;\;\frac{-3 - \frac{\frac{3}{x} - -1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{1 + x} - \frac{1 + x}{x - 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{1 + x} - \frac{1 + x}{x - 1}\\ \mathbf{if}\;t\_0 \leq 10^{-5}:\\ \;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (/ x (+ 1.0 x)) (/ (+ 1.0 x) (- x 1.0)))))
   (if (<= t_0 1e-5) (/ (- (/ 2.0 x) 3.0) (- x 1.0)) t_0)))
double code(double x) {
	double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
	double tmp;
	if (t_0 <= 1e-5) {
		tmp = ((2.0 / x) - 3.0) / (x - 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x / (1.0d0 + x)) - ((1.0d0 + x) / (x - 1.0d0))
    if (t_0 <= 1d-5) then
        tmp = ((2.0d0 / x) - 3.0d0) / (x - 1.0d0)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
	double tmp;
	if (t_0 <= 1e-5) {
		tmp = ((2.0 / x) - 3.0) / (x - 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0))
	tmp = 0
	if t_0 <= 1e-5:
		tmp = ((2.0 / x) - 3.0) / (x - 1.0)
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(Float64(x / Float64(1.0 + x)) - Float64(Float64(1.0 + x) / Float64(x - 1.0)))
	tmp = 0.0
	if (t_0 <= 1e-5)
		tmp = Float64(Float64(Float64(2.0 / x) - 3.0) / Float64(x - 1.0));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (x / (1.0 + x)) - ((1.0 + x) / (x - 1.0));
	tmp = 0.0;
	if (t_0 <= 1e-5)
		tmp = ((2.0 / x) - 3.0) / (x - 1.0);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 + x), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-5], N[(N[(N[(2.0 / x), $MachinePrecision] - 3.0), $MachinePrecision] / N[(x - 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{1 + x} - \frac{1 + x}{x - 1}\\
\mathbf{if}\;t\_0 \leq 10^{-5}:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


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

    1. Initial program 8.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot \frac{x - 1}{x + 1} - \color{blue}{\left(x + 1\right)} \cdot 1}{\left(x + 1\right) \cdot \frac{x - 1}{x + 1}} \]
      8. distribute-rgt1-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{1}{x} - 3}}{x - 1} \]
    7. Step-by-step derivation
      1. lower--.f64N/A

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

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

        \[\leadsto \frac{\frac{\color{blue}{2}}{x} - 3}{x - 1} \]
      4. lower-/.f6499.3

        \[\leadsto \frac{\color{blue}{\frac{2}{x}} - 3}{x - 1} \]
    8. Applied rewrites99.3%

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

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

    1. Initial program 99.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 10^{-5}:\\ \;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{1 + x} - \frac{1 + x}{x - 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{\frac{2}{x} - 3}{x - 1}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right) \cdot \mathsf{fma}\left(x, x, 1\right)\\


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

    1. Initial program 9.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{x \cdot \frac{x - 1}{x + 1} - \color{blue}{\left(x + 1\right)} \cdot 1}{\left(x + 1\right) \cdot \frac{x - 1}{x + 1}} \]
      8. distribute-rgt1-inN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{1}{x} - 3}}{x - 1} \]
    7. Step-by-step derivation
      1. lower--.f64N/A

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

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

        \[\leadsto \frac{\frac{\color{blue}{2}}{x} - 3}{x - 1} \]
      4. lower-/.f6498.9

        \[\leadsto \frac{\color{blue}{\frac{2}{x}} - 3}{x - 1} \]
    8. Applied rewrites98.9%

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

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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-inN/A

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

        \[\leadsto 1 + \left(\color{blue}{3 \cdot x} + x \cdot \left(x \cdot \left(1 + 3 \cdot x\right)\right)\right) \]
      3. associate-+r+N/A

        \[\leadsto \color{blue}{\left(1 + 3 \cdot x\right) + x \cdot \left(x \cdot \left(1 + 3 \cdot x\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{\left(x \cdot x\right) \cdot \left(1 + 3 \cdot x\right)} \]
      5. unpow2N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{{x}^{2}} \cdot \left(1 + 3 \cdot x\right) \]
      6. distribute-rgt1-inN/A

        \[\leadsto \color{blue}{\left({x}^{2} + 1\right) \cdot \left(1 + 3 \cdot x\right)} \]
      7. lower-*.f64N/A

        \[\leadsto \color{blue}{\left({x}^{2} + 1\right) \cdot \left(1 + 3 \cdot x\right)} \]
      8. unpow2N/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 1\right)} \cdot \left(1 + 3 \cdot x\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \color{blue}{\left(3 \cdot x + 1\right)} \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(\color{blue}{x \cdot 3} + 1\right) \]
      12. lower-fma.f6499.7

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

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

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

Alternative 6: 99.1% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{\frac{-1}{x} - 3}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right) \cdot \mathsf{fma}\left(x, x, 1\right)\\


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

    1. Initial program 9.1%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{3 + \frac{1}{x}}{x}} \]
    4. Step-by-step derivation
      1. associate-*r/N/A

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

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(3 + \frac{1}{x}\right)}{x}} \]
      3. neg-mul-1N/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(\left(3 + \frac{1}{x}\right)\right)}}{x} \]
      4. +-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\left(\frac{1}{x} + 3\right)}\right)}{x} \]
      5. distribute-neg-inN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right) + \left(\mathsf{neg}\left(3\right)\right)}}{x} \]
      6. sub-negN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right) - 3}}{x} \]
      7. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{x}\right)\right) - 3}}{x} \]
      8. distribute-neg-fracN/A

        \[\leadsto \frac{\color{blue}{\frac{\mathsf{neg}\left(1\right)}{x}} - 3}{x} \]
      9. metadata-evalN/A

        \[\leadsto \frac{\frac{\color{blue}{-1}}{x} - 3}{x} \]
      10. lower-/.f6498.8

        \[\leadsto \frac{\color{blue}{\frac{-1}{x}} - 3}{x} \]
    5. Applied rewrites98.8%

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

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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-inN/A

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

        \[\leadsto 1 + \left(\color{blue}{3 \cdot x} + x \cdot \left(x \cdot \left(1 + 3 \cdot x\right)\right)\right) \]
      3. associate-+r+N/A

        \[\leadsto \color{blue}{\left(1 + 3 \cdot x\right) + x \cdot \left(x \cdot \left(1 + 3 \cdot x\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{\left(x \cdot x\right) \cdot \left(1 + 3 \cdot x\right)} \]
      5. unpow2N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{{x}^{2}} \cdot \left(1 + 3 \cdot x\right) \]
      6. distribute-rgt1-inN/A

        \[\leadsto \color{blue}{\left({x}^{2} + 1\right) \cdot \left(1 + 3 \cdot x\right)} \]
      7. lower-*.f64N/A

        \[\leadsto \color{blue}{\left({x}^{2} + 1\right) \cdot \left(1 + 3 \cdot x\right)} \]
      8. unpow2N/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 1\right)} \cdot \left(1 + 3 \cdot x\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \color{blue}{\left(3 \cdot x + 1\right)} \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(\color{blue}{x \cdot 3} + 1\right) \]
      12. lower-fma.f6499.7

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

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

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

Alternative 7: 98.6% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 3, 1\right) \cdot \mathsf{fma}\left(x, x, 1\right)\\


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

    1. Initial program 9.1%

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

      \[\leadsto \color{blue}{\frac{-3}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f6497.8

        \[\leadsto \color{blue}{\frac{-3}{x}} \]
    5. Applied rewrites97.8%

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

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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x \cdot \left(1 + 3 \cdot x\right)\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-inN/A

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

        \[\leadsto 1 + \left(\color{blue}{3 \cdot x} + x \cdot \left(x \cdot \left(1 + 3 \cdot x\right)\right)\right) \]
      3. associate-+r+N/A

        \[\leadsto \color{blue}{\left(1 + 3 \cdot x\right) + x \cdot \left(x \cdot \left(1 + 3 \cdot x\right)\right)} \]
      4. associate-*r*N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{\left(x \cdot x\right) \cdot \left(1 + 3 \cdot x\right)} \]
      5. unpow2N/A

        \[\leadsto \left(1 + 3 \cdot x\right) + \color{blue}{{x}^{2}} \cdot \left(1 + 3 \cdot x\right) \]
      6. distribute-rgt1-inN/A

        \[\leadsto \color{blue}{\left({x}^{2} + 1\right) \cdot \left(1 + 3 \cdot x\right)} \]
      7. lower-*.f64N/A

        \[\leadsto \color{blue}{\left({x}^{2} + 1\right) \cdot \left(1 + 3 \cdot x\right)} \]
      8. unpow2N/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 1\right)} \cdot \left(1 + 3 \cdot x\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \color{blue}{\left(3 \cdot x + 1\right)} \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(x, x, 1\right) \cdot \left(\color{blue}{x \cdot 3} + 1\right) \]
      12. lower-fma.f6499.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 1\right) \cdot \mathsf{fma}\left(x, 3, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

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

Alternative 8: 98.5% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \leq 0.005:\\
\;\;\;\;\frac{-3}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(3 + x, x, 1\right)\\


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

    1. Initial program 9.1%

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

      \[\leadsto \color{blue}{\frac{-3}{x}} \]
    4. Step-by-step derivation
      1. lower-/.f6497.8

        \[\leadsto \color{blue}{\frac{-3}{x}} \]
    5. Applied rewrites97.8%

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

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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(3 + x, x, 1\right)} \]
      4. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{x + 3}, x, 1\right) \]
      5. lower-+.f6499.6

        \[\leadsto \mathsf{fma}\left(\color{blue}{x + 3}, x, 1\right) \]
    5. Applied rewrites99.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x + 3, x, 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

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

Alternative 9: 49.8% accurate, 35.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 55.6%

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

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

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

    Reproduce

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