Average Error: 29.7 → 0.3
Time: 22.6s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \le 4.962696920074449735693633556365966796875 \cdot 10^{-13}:\\ \;\;\;\;-\left(\left(\frac{1}{x \cdot x} + \frac{3}{x}\right) + \frac{3}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1} - \frac{x + 1}{x - 1}\\ \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} \le 4.962696920074449735693633556365966796875 \cdot 10^{-13}:\\
\;\;\;\;-\left(\left(\frac{1}{x \cdot x} + \frac{3}{x}\right) + \frac{3}{{x}^{3}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1} - \frac{x + 1}{x - 1}\\

\end{array}
double f(double x) {
        double r94763 = x;
        double r94764 = 1.0;
        double r94765 = r94763 + r94764;
        double r94766 = r94763 / r94765;
        double r94767 = r94763 - r94764;
        double r94768 = r94765 / r94767;
        double r94769 = r94766 - r94768;
        return r94769;
}

double f(double x) {
        double r94770 = x;
        double r94771 = 1.0;
        double r94772 = r94770 + r94771;
        double r94773 = r94770 / r94772;
        double r94774 = r94770 - r94771;
        double r94775 = r94772 / r94774;
        double r94776 = r94773 - r94775;
        double r94777 = 4.96269692007445e-13;
        bool r94778 = r94776 <= r94777;
        double r94779 = r94770 * r94770;
        double r94780 = r94771 / r94779;
        double r94781 = 3.0;
        double r94782 = r94781 / r94770;
        double r94783 = r94780 + r94782;
        double r94784 = 3.0;
        double r94785 = pow(r94770, r94784);
        double r94786 = r94781 / r94785;
        double r94787 = r94783 + r94786;
        double r94788 = -r94787;
        double r94789 = r94778 ? r94788 : r94776;
        return r94789;
}

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 (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) < 4.96269692007445e-13

    1. Initial program 59.4

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

      \[\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}{-\left(\left(\frac{1}{x \cdot x} + \frac{3}{x}\right) + \frac{3}{{x}^{3}}\right)}\]

    if 4.96269692007445e-13 < (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0)))

    1. Initial program 0.3

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

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

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

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

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

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

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

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

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

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

Reproduce

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