Average Error: 29.7 → 0.3
Time: 18.7s
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{3}{x} + \frac{1}{x \cdot 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{3}{x} + \frac{1}{x \cdot 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 r95754 = x;
        double r95755 = 1.0;
        double r95756 = r95754 + r95755;
        double r95757 = r95754 / r95756;
        double r95758 = r95754 - r95755;
        double r95759 = r95756 / r95758;
        double r95760 = r95757 - r95759;
        return r95760;
}

double f(double x) {
        double r95761 = x;
        double r95762 = 1.0;
        double r95763 = r95761 + r95762;
        double r95764 = r95761 / r95763;
        double r95765 = r95761 - r95762;
        double r95766 = r95763 / r95765;
        double r95767 = r95764 - r95766;
        double r95768 = 4.96269692007445e-13;
        bool r95769 = r95767 <= r95768;
        double r95770 = 3.0;
        double r95771 = r95770 / r95761;
        double r95772 = r95761 * r95761;
        double r95773 = r95762 / r95772;
        double r95774 = r95771 + r95773;
        double r95775 = 3.0;
        double r95776 = pow(r95761, r95775);
        double r95777 = r95770 / r95776;
        double r95778 = r95774 + r95777;
        double r95779 = -r95778;
        double r95780 = r95769 ? r95779 : r95767;
        return r95780;
}

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. Using strategy rm
    3. Applied add-log-exp59.4

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

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

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

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

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

      \[\leadsto \log \left(e^{\frac{{\left(\frac{x}{x + 1}\right)}^{3} - {\left(\frac{x + 1}{x - 1}\right)}^{3}}{\color{blue}{\frac{x \cdot x}{\left(x + 1\right) \cdot \left(x + 1\right)} + \frac{\left(x + 1\right) \cdot \frac{x + 1}{x - 1} + x}{x - 1}}}}\right)\]
    10. 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)}\]
    11. Simplified0.3

      \[\leadsto \color{blue}{-\left(\left(\frac{3}{x} + \frac{1}{x \cdot 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 pow10.3

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

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

      \[\leadsto 1 \cdot \color{blue}{\left(\frac{x}{x + 1} - \frac{x + 1}{x - 1}\right)}\]
  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{3}{x} + \frac{1}{x \cdot 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 
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))