Average Error: 29.5 → 0.1
Time: 17.4s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -10395.82115050408719980623573064804077148:\\ \;\;\;\;\left(\frac{-3}{x} - \frac{1}{x \cdot x}\right) - \frac{3}{\left(x \cdot x\right) \cdot x}\\ \mathbf{elif}\;x \le 9252.756593940759557881392538547515869141:\\ \;\;\;\;\log \left(e^{\frac{x}{x + 1}} \cdot e^{\frac{-\left(x + 1\right)}{x - 1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{-3}{x} - \frac{1}{x \cdot x}\right) - \frac{3}{\left(x \cdot x\right) \cdot x}\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -10395.82115050408719980623573064804077148:\\
\;\;\;\;\left(\frac{-3}{x} - \frac{1}{x \cdot x}\right) - \frac{3}{\left(x \cdot x\right) \cdot x}\\

\mathbf{elif}\;x \le 9252.756593940759557881392538547515869141:\\
\;\;\;\;\log \left(e^{\frac{x}{x + 1}} \cdot e^{\frac{-\left(x + 1\right)}{x - 1}}\right)\\

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

\end{array}
double f(double x) {
        double r4691248 = x;
        double r4691249 = 1.0;
        double r4691250 = r4691248 + r4691249;
        double r4691251 = r4691248 / r4691250;
        double r4691252 = r4691248 - r4691249;
        double r4691253 = r4691250 / r4691252;
        double r4691254 = r4691251 - r4691253;
        return r4691254;
}

double f(double x) {
        double r4691255 = x;
        double r4691256 = -10395.821150504087;
        bool r4691257 = r4691255 <= r4691256;
        double r4691258 = 3.0;
        double r4691259 = -r4691258;
        double r4691260 = r4691259 / r4691255;
        double r4691261 = 1.0;
        double r4691262 = r4691255 * r4691255;
        double r4691263 = r4691261 / r4691262;
        double r4691264 = r4691260 - r4691263;
        double r4691265 = r4691262 * r4691255;
        double r4691266 = r4691258 / r4691265;
        double r4691267 = r4691264 - r4691266;
        double r4691268 = 9252.75659394076;
        bool r4691269 = r4691255 <= r4691268;
        double r4691270 = r4691255 + r4691261;
        double r4691271 = r4691255 / r4691270;
        double r4691272 = exp(r4691271);
        double r4691273 = -r4691270;
        double r4691274 = r4691255 - r4691261;
        double r4691275 = r4691273 / r4691274;
        double r4691276 = exp(r4691275);
        double r4691277 = r4691272 * r4691276;
        double r4691278 = log(r4691277);
        double r4691279 = r4691269 ? r4691278 : r4691267;
        double r4691280 = r4691257 ? r4691267 : r4691279;
        return r4691280;
}

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 < -10395.821150504087 or 9252.75659394076 < x

    1. Initial program 59.3

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

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

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

    if -10395.821150504087 < x < 9252.75659394076

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp0.1

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

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

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{x}{x + 1} - \frac{x + 1}{x - 1}}\right)}\]
    7. Using strategy rm
    8. Applied sub-neg0.1

      \[\leadsto \log \left(e^{\color{blue}{\frac{x}{x + 1} + \left(-\frac{x + 1}{x - 1}\right)}}\right)\]
    9. Applied exp-sum0.1

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

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

Reproduce

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