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

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

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

\end{array}
double f(double x) {
        double r8093931 = x;
        double r8093932 = 1.0;
        double r8093933 = r8093931 + r8093932;
        double r8093934 = r8093931 / r8093933;
        double r8093935 = r8093931 - r8093932;
        double r8093936 = r8093933 / r8093935;
        double r8093937 = r8093934 - r8093936;
        return r8093937;
}

double f(double x) {
        double r8093938 = x;
        double r8093939 = -14927.878414639817;
        bool r8093940 = r8093938 <= r8093939;
        double r8093941 = 3.0;
        double r8093942 = r8093938 * r8093938;
        double r8093943 = r8093942 * r8093938;
        double r8093944 = r8093941 / r8093943;
        double r8093945 = 1.0;
        double r8093946 = r8093945 / r8093942;
        double r8093947 = r8093944 + r8093946;
        double r8093948 = r8093941 / r8093938;
        double r8093949 = r8093947 + r8093948;
        double r8093950 = -r8093949;
        double r8093951 = 9776.98433563854;
        bool r8093952 = r8093938 <= r8093951;
        double r8093953 = r8093938 + r8093945;
        double r8093954 = r8093938 / r8093953;
        double r8093955 = exp(r8093954);
        double r8093956 = log(r8093955);
        double r8093957 = 1.0;
        double r8093958 = r8093938 - r8093945;
        double r8093959 = r8093957 / r8093958;
        double r8093960 = r8093959 * r8093953;
        double r8093961 = r8093956 - r8093960;
        double r8093962 = r8093952 ? r8093961 : r8093950;
        double r8093963 = r8093940 ? r8093950 : r8093962;
        return r8093963;
}

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 < -14927.878414639817 or 9776.98433563854 < x

    1. Initial program 59.3

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

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

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

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

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

      \[\leadsto \log \left(e^{\frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}}\right)\]
    9. Applied associate-/r/60.4

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

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

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

    if -14927.878414639817 < x < 9776.98433563854

    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 flip--0.1

      \[\leadsto \log \left(e^{\frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}}\right)\]
    9. Applied associate-/r/0.1

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

      \[\leadsto \log \left(e^{\frac{x}{x + 1} - \color{blue}{\frac{1}{x - 1}} \cdot \left(x + 1\right)}\right)\]
    11. Using strategy rm
    12. Applied rem-log-exp0.1

      \[\leadsto \color{blue}{\frac{x}{x + 1} - \frac{1}{x - 1} \cdot \left(x + 1\right)}\]
    13. Using strategy rm
    14. Applied add-log-exp0.1

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

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

Reproduce

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