Asymptote C

?

Percentage Accurate: 53.8% → 99.8%
Time: 12.3s
Precision: binary64
Cost: 14660

?

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

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


\end{array}

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.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 5.00000000000000024e-5

    1. Initial program 7.4%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied egg-rr7.3%

      \[\leadsto \color{blue}{\frac{\frac{x + -1}{x + 1} - \frac{x + 1}{x} \cdot 1}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}}} \]
      Step-by-step derivation

      [Start]7.4%

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

      clear-num [=>]7.3%

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

      clear-num [=>]7.3%

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

      frac-sub [=>]7.3%

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

      *-un-lft-identity [<=]7.3%

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

      sub-neg [=>]7.3%

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

      metadata-eval [=>]7.3%

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

      sub-neg [=>]7.3%

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

      metadata-eval [=>]7.3%

      \[ \frac{\frac{x + -1}{x + 1} - \frac{x + 1}{x} \cdot 1}{\frac{x + 1}{x} \cdot \frac{x + \color{blue}{-1}}{x + 1}} \]
    3. Applied egg-rr7.3%

      \[\leadsto \frac{\color{blue}{\frac{\left(-\left(x + -1\right)\right) \cdot \frac{x}{x + 1} - \left(-\left(x + 1\right)\right) \cdot 1}{\left(-\left(x + 1\right)\right) \cdot \frac{x}{x + 1}}}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}} \]
      Step-by-step derivation

      [Start]7.3%

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

      *-rgt-identity [=>]7.3%

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

      frac-2neg [=>]7.3%

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

      clear-num [=>]7.3%

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

      frac-sub [=>]7.3%

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

      \[\leadsto \frac{\color{blue}{\frac{\mathsf{fma}\left(\frac{x}{x + 1}, 1 - x, x + 1\right)}{\frac{x}{x + 1} \cdot \left(-1 - x\right)}}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}} \]
      Step-by-step derivation

      [Start]7.3%

      \[ \frac{\frac{\left(-\left(x + -1\right)\right) \cdot \frac{x}{x + 1} - \left(-\left(x + 1\right)\right) \cdot 1}{\left(-\left(x + 1\right)\right) \cdot \frac{x}{x + 1}}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}} \]

      cancel-sign-sub [=>]7.3%

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

      *-commutative [=>]7.3%

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

      *-rgt-identity [=>]7.3%

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

      fma-def [=>]7.3%

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

      neg-sub0 [=>]7.3%

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

      +-commutative [=>]7.3%

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

      associate--r+ [=>]7.3%

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

      metadata-eval [=>]7.3%

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

      *-commutative [=>]7.3%

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

      neg-sub0 [=>]7.3%

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

      +-commutative [=>]7.3%

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

      associate--r+ [=>]7.3%

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

      metadata-eval [=>]7.3%

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

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

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

      [Start]100.0%

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

      associate--l+ [=>]100.0%

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

      associate-*r/ [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      unpow2 [=>]100.0%

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

      associate-*r/ [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      associate-*r/ [=>]100.0%

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

      metadata-eval [=>]100.0%

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

    if 5.00000000000000024e-5 < (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1)))

    1. Initial program 100.0%

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied egg-rr100.0%

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

      [Start]100.0%

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

      flip-+ [=>]100.0%

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

      associate-/r/ [=>]100.0%

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

      fma-neg [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      fma-neg [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      sub-neg [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      distribute-neg-frac [=>]100.0%

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

      distribute-neg-in [=>]100.0%

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

      neg-mul-1 [=>]100.0%

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

      metadata-eval [<=]100.0%

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

      fma-def [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      sub-neg [=>]100.0%

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

      metadata-eval [=>]100.0%

      \[ \mathsf{fma}\left(\frac{x}{\mathsf{fma}\left(x, x, -1\right)}, x + -1, \frac{\mathsf{fma}\left(-1, x, -1\right)}{x + \color{blue}{-1}}\right) \]
    3. Simplified100.0%

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

      [Start]100.0%

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

      fma-udef [=>]100.0%

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

      *-commutative [=>]100.0%

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

      fma-def [=>]100.0%

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

      fma-udef [=>]100.0%

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

      neg-mul-1 [<=]100.0%

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

      metadata-eval [<=]100.0%

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

      distribute-neg-in [<=]100.0%

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

      +-commutative [=>]100.0%

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

      distribute-neg-in [=>]100.0%

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

      metadata-eval [=>]100.0%

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

      unsub-neg [=>]100.0%

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

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

Alternatives

Alternative 1
Accuracy99.8%
Cost14660
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ t_1 := \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 + t_1 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{3 + \left(\frac{2}{x \cdot x} - \left(\frac{2}{x} + \frac{2}{{x}^{3}}\right)\right)}{t_0 \cdot \left(-1 - x\right)}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x + -1, \frac{x}{\mathsf{fma}\left(x, x, -1\right)}, t_1\right)\\ \end{array} \]
Alternative 2
Accuracy99.9%
Cost9860
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ \mathbf{if}\;t_0 + \frac{-1 - x}{x + -1} \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{3 + \left(\frac{2}{x \cdot x} - \left(\frac{2}{x} + \frac{2}{{x}^{3}}\right)\right)}{t_0 \cdot \left(-1 - x\right)}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-1 + x \cdot -3}{x \cdot \left(x + 1\right)}}{1 - \frac{1}{x}}\\ \end{array} \]
Alternative 3
Accuracy99.8%
Cost8196
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 0:\\ \;\;\;\;\left(\frac{-1}{x \cdot x} + \frac{-3}{x}\right) - \frac{3}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-1 + x \cdot -3}{x \cdot \left(x + 1\right)}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}}\\ \end{array} \]
Alternative 4
Accuracy99.8%
Cost2500
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 0:\\ \;\;\;\;\frac{\frac{2}{x \cdot x} - \frac{3}{x}}{1 - \frac{1}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-1 + x \cdot -3}{x \cdot \left(x + 1\right)}}{\frac{x + 1}{x} \cdot \frac{x + -1}{x + 1}}\\ \end{array} \]
Alternative 5
Accuracy99.8%
Cost1988
\[\begin{array}{l} t_0 := 1 - \frac{1}{x}\\ \mathbf{if}\;\frac{x}{x + 1} + \frac{-1 - x}{x + -1} \leq 0:\\ \;\;\;\;\frac{\frac{2}{x \cdot x} - \frac{3}{x}}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-1 + x \cdot -3}{x \cdot \left(x + 1\right)}}{t_0}\\ \end{array} \]
Alternative 6
Accuracy99.7%
Cost1860
\[\begin{array}{l} t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{\frac{2}{x \cdot x} - \frac{3}{x}}{1 - \frac{1}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Accuracy99.7%
Cost1732
\[\begin{array}{l} t_0 := \frac{x}{x + 1} + \frac{-1 - x}{x + -1}\\ \mathbf{if}\;t_0 \leq 5 \cdot 10^{-7}:\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Accuracy99.0%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{-3 - \frac{1}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;1 + x \cdot 3\\ \end{array} \]
Alternative 9
Accuracy98.6%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1 + x \cdot 3\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 10
Accuracy98.1%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{-3}{x}\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;x - -1\\ \mathbf{else}:\\ \;\;\;\;\frac{-3}{x}\\ \end{array} \]
Alternative 11
Accuracy50.5%
Cost64
\[1 \]

Reproduce?

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