Average Error: 29.4 → 0.2
Time: 5.1s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -12739.391686969833 \lor \neg \left(x \le 9138.442026599892\right):\\ \;\;\;\;\frac{-1}{{x}^{2}} - \mathsf{fma}\left(3, \frac{1}{x}, 3 \cdot \frac{1}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right)\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -12739.391686969833 \lor \neg \left(x \le 9138.442026599892\right):\\
\;\;\;\;\frac{-1}{{x}^{2}} - \mathsf{fma}\left(3, \frac{1}{x}, 3 \cdot \frac{1}{{x}^{3}}\right)\\

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

\end{array}
double code(double x) {
	return ((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0)));
}
double code(double x) {
	double VAR;
	if (((x <= -12739.391686969833) || !(x <= 9138.442026599892))) {
		VAR = ((-1.0 / pow(x, 2.0)) - fma(3.0, (1.0 / x), (3.0 * (1.0 / pow(x, 3.0)))));
	} else {
		VAR = (fma((x / ((x * x) - (1.0 * 1.0))), (x - 1.0), -((x + 1.0) * ((x + 1.0) / ((x * x) - (1.0 * 1.0))))) + (((x + 1.0) / ((x * x) - (1.0 * 1.0))) * (-(x + 1.0) + (x + 1.0))));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -12739.391686969833 or 9138.442026599892 < x

    1. Initial program 59.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Taylor expanded around inf 0.3

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

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

    if -12739.391686969833 < x < 9138.442026599892

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied flip--0.1

      \[\leadsto \frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}\]
    4. Applied associate-/r/0.1

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

      \[\leadsto \frac{x}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}} - \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)\]
    6. Applied associate-/r/0.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -12739.391686969833 \lor \neg \left(x \le 9138.442026599892\right):\\ \;\;\;\;\frac{-1}{{x}^{2}} - \mathsf{fma}\left(3, \frac{1}{x}, 3 \cdot \frac{1}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020078 +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))