Average Error: 29.8 → 0.1
Time: 7.7s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{x}{x + 1}\\ t_1 := \frac{x + 1}{x - 1}\\ \mathbf{if}\;t_0 - t_1 \leq 0.0009093093190669643:\\ \;\;\;\;\left(\frac{-3}{x} + \frac{-1 + \frac{-3}{x}}{x \cdot x}\right) + \frac{-1}{{x}^{4}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(\frac{e^{t_0}}{e^{t_1}}\right)\\ \end{array} \]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
t_0 := \frac{x}{x + 1}\\
t_1 := \frac{x + 1}{x - 1}\\
\mathbf{if}\;t_0 - t_1 \leq 0.0009093093190669643:\\
\;\;\;\;\left(\frac{-3}{x} + \frac{-1 + \frac{-3}{x}}{x \cdot x}\right) + \frac{-1}{{x}^{4}}\\

\mathbf{else}:\\
\;\;\;\;\log \left(\frac{e^{t_0}}{e^{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 (/ (+ x 1.0) (- x 1.0))))
   (if (<= (- t_0 t_1) 0.0009093093190669643)
     (+ (+ (/ -3.0 x) (/ (+ -1.0 (/ -3.0 x)) (* x x))) (/ -1.0 (pow x 4.0)))
     (log (/ (exp t_0) (exp 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 = (x + 1.0) / (x - 1.0);
	double tmp;
	if ((t_0 - t_1) <= 0.0009093093190669643) {
		tmp = ((-3.0 / x) + ((-1.0 + (-3.0 / x)) / (x * x))) + (-1.0 / pow(x, 4.0));
	} else {
		tmp = log(exp(t_0) / exp(t_1));
	}
	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))) < 9.09309319066964e-4

    1. Initial program 59.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied add-log-exp_binary6459.1

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\log \left(e^{\frac{x + 1}{x - 1}}\right)} \]
    3. Applied add-log-exp_binary6459.1

      \[\leadsto \color{blue}{\log \left(e^{\frac{x}{x + 1}}\right)} - \log \left(e^{\frac{x + 1}{x - 1}}\right) \]
    4. Applied diff-log_binary6459.1

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

      \[\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)} \]
    6. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{x \cdot x}, -1 - \frac{3}{x}, \frac{-3}{x}\right) + \frac{-1}{{x}^{4}}} \]
    7. Applied fma-udef_binary640.2

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

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

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

    1. Initial program 0.0

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1} \]
    2. Applied add-log-exp_binary640.0

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\log \left(e^{\frac{x + 1}{x - 1}}\right)} \]
    3. Applied add-log-exp_binary640.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{x}{x + 1}}\right)} - \log \left(e^{\frac{x + 1}{x - 1}}\right) \]
    4. Applied diff-log_binary640.0

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

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

Reproduce

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