Asymptote C

Percentage Accurate: 54.4% → 99.7%
Time: 16.1s
Alternatives: 15
Speedup: 1.0×

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 15 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: 54.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.0× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x + -1}\\
\mathbf{if}\;t\_0 - t\_1 \leq 0.0001:\\
\;\;\;\;\frac{-3}{{x}^{3}} + \left(\left(\frac{-1}{{x}^{2}} + \frac{-1}{{x}^{4}}\right) - \frac{3}{x}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000005e-4

    1. Initial program 6.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000005e-4 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-inv99.9%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{1}{x + 1}, -\frac{1}{x - 1} \cdot \left(x + 1\right)\right) + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right)} \]
      4. associate-/r/99.9%

        \[\leadsto \mathsf{fma}\left(x, \frac{1}{x + 1}, -\color{blue}{\frac{1}{\frac{x - 1}{x + 1}}}\right) + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
      5. clear-num99.9%

        \[\leadsto \mathsf{fma}\left(x, \frac{1}{x + 1}, -\color{blue}{\frac{x + 1}{x - 1}}\right) + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
      6. fma-neg99.9%

        \[\leadsto \color{blue}{\left(x \cdot \frac{1}{x + 1} - \frac{x + 1}{x - 1}\right)} + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
      7. div-inv99.9%

        \[\leadsto \left(\color{blue}{\frac{x}{x + 1}} - \frac{x + 1}{x - 1}\right) + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
      8. flip--100.0%

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \frac{x}{x + 1} - \frac{x + 1}{x - 1} \cdot \frac{x + 1}{x - 1}}{\frac{x}{x + 1} + \frac{x + 1}{x - 1}}} + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
      9. div-inv99.9%

        \[\leadsto \color{blue}{\left(\frac{x}{x + 1} \cdot \frac{x}{x + 1} - \frac{x + 1}{x - 1} \cdot \frac{x + 1}{x - 1}\right) \cdot \frac{1}{\frac{x}{x + 1} + \frac{x + 1}{x - 1}}} + \mathsf{fma}\left(-\frac{1}{x - 1}, x + 1, \frac{1}{x - 1} \cdot \left(x + 1\right)\right) \]
      10. fma-define99.9%

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

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

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

Alternative 2: 99.7% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{x + 1}\\ t_1 := \frac{x + 1}{x + -1}\\ \mathbf{if}\;t\_0 - t\_1 \leq 0.0001:\\ \;\;\;\;\frac{-3}{{x}^{3}} + \left(\left(\frac{-1}{{x}^{2}} + \frac{-1}{{x}^{4}}\right) - \frac{3}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{t\_0}^{2} - {t\_1}^{2}}{t\_1 + x \cdot \frac{1}{x + 1}}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ x (+ x 1.0))) (t_1 (/ (+ x 1.0) (+ x -1.0))))
   (if (<= (- t_0 t_1) 0.0001)
     (+
      (/ -3.0 (pow x 3.0))
      (- (+ (/ -1.0 (pow x 2.0)) (/ -1.0 (pow x 4.0))) (/ 3.0 x)))
     (/ (- (pow t_0 2.0) (pow t_1 2.0)) (+ t_1 (* x (/ 1.0 (+ x 1.0))))))))
double code(double x) {
	double t_0 = x / (x + 1.0);
	double t_1 = (x + 1.0) / (x + -1.0);
	double tmp;
	if ((t_0 - t_1) <= 0.0001) {
		tmp = (-3.0 / pow(x, 3.0)) + (((-1.0 / pow(x, 2.0)) + (-1.0 / pow(x, 4.0))) - (3.0 / x));
	} else {
		tmp = (pow(t_0, 2.0) - pow(t_1, 2.0)) / (t_1 + (x * (1.0 / (x + 1.0))));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x / (x + 1.0d0)
    t_1 = (x + 1.0d0) / (x + (-1.0d0))
    if ((t_0 - t_1) <= 0.0001d0) then
        tmp = ((-3.0d0) / (x ** 3.0d0)) + ((((-1.0d0) / (x ** 2.0d0)) + ((-1.0d0) / (x ** 4.0d0))) - (3.0d0 / x))
    else
        tmp = ((t_0 ** 2.0d0) - (t_1 ** 2.0d0)) / (t_1 + (x * (1.0d0 / (x + 1.0d0))))
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = x / (x + 1.0);
	double t_1 = (x + 1.0) / (x + -1.0);
	double tmp;
	if ((t_0 - t_1) <= 0.0001) {
		tmp = (-3.0 / Math.pow(x, 3.0)) + (((-1.0 / Math.pow(x, 2.0)) + (-1.0 / Math.pow(x, 4.0))) - (3.0 / x));
	} else {
		tmp = (Math.pow(t_0, 2.0) - Math.pow(t_1, 2.0)) / (t_1 + (x * (1.0 / (x + 1.0))));
	}
	return tmp;
}
def code(x):
	t_0 = x / (x + 1.0)
	t_1 = (x + 1.0) / (x + -1.0)
	tmp = 0
	if (t_0 - t_1) <= 0.0001:
		tmp = (-3.0 / math.pow(x, 3.0)) + (((-1.0 / math.pow(x, 2.0)) + (-1.0 / math.pow(x, 4.0))) - (3.0 / x))
	else:
		tmp = (math.pow(t_0, 2.0) - math.pow(t_1, 2.0)) / (t_1 + (x * (1.0 / (x + 1.0))))
	return tmp
function code(x)
	t_0 = Float64(x / Float64(x + 1.0))
	t_1 = Float64(Float64(x + 1.0) / Float64(x + -1.0))
	tmp = 0.0
	if (Float64(t_0 - t_1) <= 0.0001)
		tmp = Float64(Float64(-3.0 / (x ^ 3.0)) + Float64(Float64(Float64(-1.0 / (x ^ 2.0)) + Float64(-1.0 / (x ^ 4.0))) - Float64(3.0 / x)));
	else
		tmp = Float64(Float64((t_0 ^ 2.0) - (t_1 ^ 2.0)) / Float64(t_1 + Float64(x * Float64(1.0 / Float64(x + 1.0)))));
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = x / (x + 1.0);
	t_1 = (x + 1.0) / (x + -1.0);
	tmp = 0.0;
	if ((t_0 - t_1) <= 0.0001)
		tmp = (-3.0 / (x ^ 3.0)) + (((-1.0 / (x ^ 2.0)) + (-1.0 / (x ^ 4.0))) - (3.0 / x));
	else
		tmp = ((t_0 ^ 2.0) - (t_1 ^ 2.0)) / (t_1 + (x * (1.0 / (x + 1.0))));
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 - t$95$1), $MachinePrecision], 0.0001], N[(N[(-3.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(3.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision] / N[(t$95$1 + N[(x * N[(1.0 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x + -1}\\
\mathbf{if}\;t\_0 - t\_1 \leq 0.0001:\\
\;\;\;\;\frac{-3}{{x}^{3}} + \left(\left(\frac{-1}{{x}^{2}} + \frac{-1}{{x}^{4}}\right) - \frac{3}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{{t\_0}^{2} - {t\_1}^{2}}{t\_1 + x \cdot \frac{1}{x + 1}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000005e-4

    1. Initial program 6.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000005e-4 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--99.9%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.7% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x + -1}\\
\mathbf{if}\;t\_0 - t\_1 \leq 0.0001:\\
\;\;\;\;\frac{-3}{{x}^{3}} + \left(\frac{-3}{x} + \frac{-1}{{x}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{{t\_0}^{2} - {t\_1}^{2}}{t\_1 + x \cdot \frac{1}{x + 1}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000005e-4

    1. Initial program 6.2%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{-3}{x} + \frac{-1}{{x}^{2}}\right) + \left(-\frac{\color{blue}{3}}{{x}^{3}}\right) \]
      12. distribute-neg-frac99.9%

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

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

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

    if 1.00000000000000005e-4 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--99.9%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 99.7% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x + -1}\\
\mathbf{if}\;t\_0 - t\_1 \leq 0.0001:\\
\;\;\;\;\frac{-3}{{x}^{3}} + \left(\frac{-3}{x} + \frac{-1}{{x}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{\frac{x + 1}{x}} - {t\_1}^{2}}{t\_0 + t\_1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 1.00000000000000005e-4

    1. Initial program 6.2%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{-3}{x} + \frac{-1}{{x}^{2}}\right) + \left(-\frac{\color{blue}{3}}{{x}^{3}}\right) \]
      12. distribute-neg-frac99.9%

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

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

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

    if 1.00000000000000005e-4 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 99.2% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x + -1}\\
\mathbf{if}\;t\_0 - t\_1 \leq 0:\\
\;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_0}{\frac{x + 1}{x}} - {t\_1}^{2}}{t\_0 + t\_1}\\


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

    1. Initial program 5.6%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg5.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in99.5%

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

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

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

        \[\leadsto \left(-\frac{\color{blue}{3}}{x}\right) - \frac{1}{{x}^{2}} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-3}{x}} - \frac{1}{{x}^{2}} \]
      6. metadata-eval100.0%

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow100.0%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \frac{1}{x} \cdot \color{blue}{\frac{1}{x}} \]
    9. Applied egg-rr100.0%

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

    if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.8%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 99.1% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x}\\
\mathbf{if}\;t\_0 - \frac{x + 1}{x + -1} \leq 0:\\
\;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\

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


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

    1. Initial program 5.6%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg5.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in99.5%

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

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

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

        \[\leadsto \left(-\frac{\color{blue}{3}}{x}\right) - \frac{1}{{x}^{2}} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-3}{x}} - \frac{1}{{x}^{2}} \]
      6. metadata-eval100.0%

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow100.0%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \frac{1}{x} \cdot \color{blue}{\frac{1}{x}} \]
    9. Applied egg-rr100.0%

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

    if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.8%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{\frac{x}{x + 1}}{\frac{x + 1}{x}} - \frac{x + 1}{x + -1} \cdot \color{blue}{\frac{1}{\frac{x + -1}{x + 1}}}}{\frac{x}{x + 1} + \frac{x + 1}{x + -1}} \]
      3. un-div-inv99.8%

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

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

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

Alternative 7: 99.2% accurate, 0.2× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x + -1}\\
\mathbf{if}\;t\_0 - t\_1 \leq 0:\\
\;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\

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


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

    1. Initial program 5.6%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg5.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in99.5%

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

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

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

        \[\leadsto \left(-\frac{\color{blue}{3}}{x}\right) - \frac{1}{{x}^{2}} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-3}{x}} - \frac{1}{{x}^{2}} \]
      6. metadata-eval100.0%

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow100.0%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \frac{1}{x} \cdot \color{blue}{\frac{1}{x}} \]
    9. Applied egg-rr100.0%

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

    if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.8%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{\frac{x}{x + 1}}{\frac{x + 1}{x}} - \frac{x + 1}{x + -1} \cdot \color{blue}{\frac{1}{\frac{x + -1}{x + 1}}}}{\frac{x}{x + 1} + \frac{x + 1}{x + -1}} \]
      3. un-div-inv99.8%

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

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

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

Alternative 8: 99.4% accurate, 0.3× speedup?

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

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

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


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

    1. Initial program 5.6%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg5.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in99.5%

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

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

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

        \[\leadsto \left(-\frac{\color{blue}{3}}{x}\right) - \frac{1}{{x}^{2}} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-3}{x}} - \frac{1}{{x}^{2}} \]
      6. metadata-eval100.0%

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow100.0%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \frac{1}{x} \cdot \color{blue}{\frac{1}{x}} \]
    9. Applied egg-rr100.0%

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

    if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.8%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. clear-num99.8%

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

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

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

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

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

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

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

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

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

Alternative 9: 99.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{x + 1} - \frac{x + 1}{x + -1}\\ \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (+ x -1.0)))))
   (if (<= t_0 0.0) (+ (/ -3.0 x) (* (/ 1.0 x) (/ -1.0 x))) t_0)))
double code(double x) {
	double t_0 = (x / (x + 1.0)) - ((x + 1.0) / (x + -1.0));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / 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 / (x + 1.0d0)) - ((x + 1.0d0) / (x + (-1.0d0)))
    if (t_0 <= 0.0d0) then
        tmp = ((-3.0d0) / x) + ((1.0d0 / x) * ((-1.0d0) / x))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = (x / (x + 1.0)) - ((x + 1.0) / (x + -1.0));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = (x / (x + 1.0)) - ((x + 1.0) / (x + -1.0))
	tmp = 0
	if t_0 <= 0.0:
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x))
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(Float64(x / Float64(x + 1.0)) - Float64(Float64(x + 1.0) / Float64(x + -1.0)))
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = Float64(Float64(-3.0 / x) + Float64(Float64(1.0 / x) * Float64(-1.0 / x)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = (x / (x + 1.0)) - ((x + 1.0) / (x + -1.0));
	tmp = 0.0;
	if (t_0 <= 0.0)
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(x + 1.0), $MachinePrecision] / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(-3.0 / x), $MachinePrecision] + N[(N[(1.0 / x), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}

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

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


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

    1. Initial program 5.6%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg5.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in99.5%

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

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

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

        \[\leadsto \left(-\frac{\color{blue}{3}}{x}\right) - \frac{1}{{x}^{2}} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-3}{x}} - \frac{1}{{x}^{2}} \]
      6. metadata-eval100.0%

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow100.0%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \frac{1}{x} \cdot \color{blue}{\frac{1}{x}} \]
    9. Applied egg-rr100.0%

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

    if 0.0 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 99.8%

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

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

Alternative 10: 99.0% accurate, 0.6× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\


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

    1. Initial program 6.9%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg6.9%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x + 1, -\frac{1}{x - 1}, \frac{x}{x + 1}\right)} \]
      6. sub-neg5.4%

        \[\leadsto \mathsf{fma}\left(x + 1, -\frac{1}{\color{blue}{x + \left(-1\right)}}, \frac{x}{x + 1}\right) \]
      7. metadata-eval5.4%

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in98.8%

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified99.3%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow99.3%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down99.3%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow99.3%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow99.3%

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

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

    if -3 < x < 1

    1. Initial program 100.0%

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

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

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

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

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

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

Alternative 11: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -0.33:\\ \;\;\;\;\frac{1}{0.1111111111111111 + \left(x \cdot -0.3333333333333333 + \frac{0.2962962962962963}{x}\right)}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x -0.33)
   (/
    1.0
    (+
     0.1111111111111111
     (+ (* x -0.3333333333333333) (/ 0.2962962962962963 x))))
   (if (<= x 1.0)
     (+ 1.0 (* x (+ x 3.0)))
     (+ (/ -3.0 x) (* (/ 1.0 x) (/ -1.0 x))))))
double code(double x) {
	double tmp;
	if (x <= -0.33) {
		tmp = 1.0 / (0.1111111111111111 + ((x * -0.3333333333333333) + (0.2962962962962963 / x)));
	} else if (x <= 1.0) {
		tmp = 1.0 + (x * (x + 3.0));
	} else {
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= (-0.33d0)) then
        tmp = 1.0d0 / (0.1111111111111111d0 + ((x * (-0.3333333333333333d0)) + (0.2962962962962963d0 / x)))
    else if (x <= 1.0d0) then
        tmp = 1.0d0 + (x * (x + 3.0d0))
    else
        tmp = ((-3.0d0) / x) + ((1.0d0 / x) * ((-1.0d0) / x))
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= -0.33) {
		tmp = 1.0 / (0.1111111111111111 + ((x * -0.3333333333333333) + (0.2962962962962963 / x)));
	} else if (x <= 1.0) {
		tmp = 1.0 + (x * (x + 3.0));
	} else {
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= -0.33:
		tmp = 1.0 / (0.1111111111111111 + ((x * -0.3333333333333333) + (0.2962962962962963 / x)))
	elif x <= 1.0:
		tmp = 1.0 + (x * (x + 3.0))
	else:
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x))
	return tmp
function code(x)
	tmp = 0.0
	if (x <= -0.33)
		tmp = Float64(1.0 / Float64(0.1111111111111111 + Float64(Float64(x * -0.3333333333333333) + Float64(0.2962962962962963 / x))));
	elseif (x <= 1.0)
		tmp = Float64(1.0 + Float64(x * Float64(x + 3.0)));
	else
		tmp = Float64(Float64(-3.0 / x) + Float64(Float64(1.0 / x) * Float64(-1.0 / x)));
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= -0.33)
		tmp = 1.0 / (0.1111111111111111 + ((x * -0.3333333333333333) + (0.2962962962962963 / x)));
	elseif (x <= 1.0)
		tmp = 1.0 + (x * (x + 3.0));
	else
		tmp = (-3.0 / x) + ((1.0 / x) * (-1.0 / x));
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, -0.33], N[(1.0 / N[(0.1111111111111111 + N[(N[(x * -0.3333333333333333), $MachinePrecision] + N[(0.2962962962962963 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.0], N[(1.0 + N[(x * N[(x + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 / x), $MachinePrecision] + N[(N[(1.0 / x), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.33:\\
\;\;\;\;\frac{1}{0.1111111111111111 + \left(x \cdot -0.3333333333333333 + \frac{0.2962962962962963}{x}\right)}\\

\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\

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


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

    1. Initial program 7.8%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. flip--8.0%

        \[\leadsto \color{blue}{\frac{\frac{x}{x + 1} \cdot \frac{x}{x + 1} - \frac{x + 1}{x - 1} \cdot \frac{x + 1}{x - 1}}{\frac{x}{x + 1} + \frac{x + 1}{x - 1}}} \]
      2. clear-num8.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{x}{x + 1} + \frac{x + 1}{x - 1}}{\frac{x}{x + 1} \cdot \frac{x}{x + 1} - \frac{x + 1}{x - 1} \cdot \frac{x + 1}{x - 1}}}} \]
      3. sub-neg8.0%

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

        \[\leadsto \frac{1}{\frac{\frac{x}{x + 1} + \frac{x + 1}{x + \color{blue}{-1}}}{\frac{x}{x + 1} \cdot \frac{x}{x + 1} - \frac{x + 1}{x - 1} \cdot \frac{x + 1}{x - 1}}} \]
      5. pow28.0%

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{0.1111111111111111 + \left(-0.3333333333333333 \cdot x + 0.2962962962962963 \cdot \frac{1}{x}\right)}} \]
    6. Taylor expanded in x around 0 98.8%

      \[\leadsto \frac{1}{0.1111111111111111 + \left(-0.3333333333333333 \cdot x + \color{blue}{\frac{0.2962962962962963}{x}}\right)} \]

    if -0.330000000000000016 < x < 1

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{1 + x \cdot \left(3 + x\right)} \]

    if 1 < x

    1. Initial program 5.8%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. sub-neg5.8%

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x + 1, -\frac{1}{x - 1}, \frac{x}{x + 1}\right)} \]
      6. sub-neg4.4%

        \[\leadsto \mathsf{fma}\left(x + 1, -\frac{1}{\color{blue}{x + \left(-1\right)}}, \frac{x}{x + 1}\right) \]
      7. metadata-eval4.4%

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

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

      \[\leadsto \color{blue}{-\left(3 \cdot \frac{1}{x} + \frac{1}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. distribute-neg-in99.6%

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

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

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

        \[\leadsto \left(-\frac{\color{blue}{3}}{x}\right) - \frac{1}{{x}^{2}} \]
      5. distribute-neg-frac100.0%

        \[\leadsto \color{blue}{\frac{-3}{x}} - \frac{1}{{x}^{2}} \]
      6. metadata-eval100.0%

        \[\leadsto \frac{\color{blue}{-3}}{x} - \frac{1}{{x}^{2}} \]
    7. Simplified100.0%

      \[\leadsto \color{blue}{\frac{-3}{x} - \frac{1}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. inv-pow100.0%

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

        \[\leadsto \frac{-3}{x} - {\color{blue}{\left(x \cdot x\right)}}^{-1} \]
      3. unpow-prod-down100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{{x}^{-1} \cdot {x}^{-1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \color{blue}{\frac{1}{x}} \cdot {x}^{-1} \]
      5. inv-pow100.0%

        \[\leadsto \frac{-3}{x} - \frac{1}{x} \cdot \color{blue}{\frac{1}{x}} \]
    9. Applied egg-rr100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.33:\\ \;\;\;\;\frac{1}{0.1111111111111111 + \left(x \cdot -0.3333333333333333 + \frac{0.2962962962962963}{x}\right)}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 + x \cdot \left(x + 3\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x} + \frac{1}{x} \cdot \frac{-1}{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 98.6% accurate, 0.8× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(x + 3\right)\\


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

    1. Initial program 6.9%

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

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

    if -1 < x < 1

    1. Initial program 100.0%

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

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

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

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

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

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

Alternative 13: 98.5% accurate, 0.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;1 + x \cdot 3\\


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

    1. Initial program 6.9%

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

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

    if -1 < x < 1

    1. Initial program 100.0%

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

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

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

Alternative 14: 97.9% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 6.9%

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

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

    if -1 < x < 1

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.8%

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

Alternative 15: 51.0% accurate, 13.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 57.1%

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

    \[\leadsto \color{blue}{1} \]
  4. Final simplification55.1%

    \[\leadsto 1 \]
  5. Add Preprocessing

Reproduce

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