Average Error: 30.1 → 0.7
Time: 3.5s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 4.651956326118256 \cdot 10^{-5}:\\ \;\;\;\;\frac{-3}{x} - \left({x}^{-4} + \left(\frac{3}{{x}^{3}} + \frac{1}{x \cdot x}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 + x \cdot 3\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \leq 4.651956326118256 \cdot 10^{-5}:\\
\;\;\;\;\frac{-3}{x} - \left({x}^{-4} + \left(\frac{3}{{x}^{3}} + \frac{1}{x \cdot x}\right)\right)\\

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


\end{array}
(FPCore (x) :precision binary64 (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))
(FPCore (x)
 :precision binary64
 (if (<= (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) 4.651956326118256e-5)
   (- (/ -3.0 x) (+ (pow x -4.0) (+ (/ 3.0 (pow x 3.0)) (/ 1.0 (* x x)))))
   (+ 1.0 (* x 3.0))))
double code(double x) {
	return (x / (x + 1.0)) - ((x + 1.0) / (x - 1.0));
}
double code(double x) {
	double tmp;
	if (((x / (x + 1.0)) - ((x + 1.0) / (x - 1.0))) <= 4.651956326118256e-5) {
		tmp = (-3.0 / x) - (pow(x, -4.0) + ((3.0 / pow(x, 3.0)) + (1.0 / (x * x))));
	} else {
		tmp = 1.0 + (x * 3.0);
	}
	return tmp;
}

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 (-.f64 (/.f64 x (+.f64 x 1)) (/.f64 (+.f64 x 1) (-.f64 x 1))) < 4.6519563261183e-5

    1. Initial program 58.9

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

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

      \[\leadsto \color{blue}{\left(\frac{-3}{x} - \left(\frac{1}{x \cdot x} + \frac{3}{{x}^{3}}\right)\right) - \frac{1}{{x}^{4}}} \]
    4. Using strategy rm
    5. Applied associate--l-_binary640.3

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

      \[\leadsto \frac{-3}{x} - \color{blue}{\left(\frac{1}{{x}^{4}} + \left(\frac{3}{{x}^{3}} + \frac{1}{x \cdot x}\right)\right)} \]
    7. Using strategy rm
    8. Applied pow-flip_binary640.3

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

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

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

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Taylor expanded around 0 1.1

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

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

Reproduce

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