Average Error: 29.7 → 0.1
Time: 20.2s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -10772.01231732761152670718729496002197266 \lor \neg \left(x \le 12102.13419773719942895695567131042480469\right):\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(-\left(\frac{1}{x \cdot x} + \left(\frac{3}{x} + \frac{3}{{x}^{3}}\right)\right)\right)\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left(\frac{x}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right) - \frac{x + 1}{x - 1}\right)}\right)\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -10772.01231732761152670718729496002197266 \lor \neg \left(x \le 12102.13419773719942895695567131042480469\right):\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(-\left(\frac{1}{x \cdot x} + \left(\frac{3}{x} + \frac{3}{{x}^{3}}\right)\right)\right)\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left(\frac{x}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right) - \frac{x + 1}{x - 1}\right)}\right)\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\\

\end{array}
double f(double x) {
        double r121661 = x;
        double r121662 = 1.0;
        double r121663 = r121661 + r121662;
        double r121664 = r121661 / r121663;
        double r121665 = r121661 - r121662;
        double r121666 = r121663 / r121665;
        double r121667 = r121664 - r121666;
        return r121667;
}

double f(double x) {
        double r121668 = x;
        double r121669 = -10772.012317327612;
        bool r121670 = r121668 <= r121669;
        double r121671 = 12102.1341977372;
        bool r121672 = r121668 <= r121671;
        double r121673 = !r121672;
        bool r121674 = r121670 || r121673;
        double r121675 = 1.0;
        double r121676 = r121668 * r121668;
        double r121677 = r121675 / r121676;
        double r121678 = 3.0;
        double r121679 = r121678 / r121668;
        double r121680 = 3.0;
        double r121681 = pow(r121668, r121680);
        double r121682 = r121678 / r121681;
        double r121683 = r121679 + r121682;
        double r121684 = r121677 + r121683;
        double r121685 = -r121684;
        double r121686 = expm1(r121685);
        double r121687 = log1p(r121686);
        double r121688 = r121668 + r121675;
        double r121689 = -r121688;
        double r121690 = r121689 + r121688;
        double r121691 = r121675 * r121675;
        double r121692 = r121676 - r121691;
        double r121693 = r121688 / r121692;
        double r121694 = r121690 * r121693;
        double r121695 = r121687 + r121694;
        double r121696 = r121668 / r121692;
        double r121697 = r121668 - r121675;
        double r121698 = r121696 * r121697;
        double r121699 = r121688 / r121697;
        double r121700 = r121698 - r121699;
        double r121701 = expm1(r121700);
        double r121702 = exp(r121701);
        double r121703 = log(r121702);
        double r121704 = log1p(r121703);
        double r121705 = r121704 + r121694;
        double r121706 = r121674 ? r121695 : r121705;
        return r121706;
}

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 < -10772.012317327612 or 12102.1341977372 < x

    1. Initial program 59.4

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied flip--60.6

      \[\leadsto \frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}\]
    4. Applied associate-/r/60.6

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)}\]
    5. Applied flip-+59.4

      \[\leadsto \frac{x}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}} - \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)\]
    6. Applied associate-/r/59.4

      \[\leadsto \color{blue}{\frac{x}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)} - \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)\]
    7. Applied prod-diff59.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \mathsf{fma}\left(-\left(x + 1\right), \frac{x + 1}{x \cdot x - 1 \cdot 1}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)}\]
    8. Simplified59.2

      \[\leadsto \mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \color{blue}{\left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}}\]
    9. Using strategy rm
    10. Applied log1p-expm1-u59.2

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)\right)\right)} + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\]
    11. Simplified60.6

      \[\leadsto \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\frac{x}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right) - \frac{x + 1}{x - 1}\right)}\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\]
    12. Taylor expanded around inf 0.3

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

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

    if -10772.012317327612 < x < 12102.1341977372

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied flip--0.1

      \[\leadsto \frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}\]
    4. Applied associate-/r/0.1

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)}\]
    5. Applied flip-+0.1

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

      \[\leadsto \color{blue}{\frac{x}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)} - \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)\]
    7. Applied prod-diff0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \mathsf{fma}\left(-\left(x + 1\right), \frac{x + 1}{x \cdot x - 1 \cdot 1}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)}\]
    8. Simplified0.1

      \[\leadsto \mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \color{blue}{\left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}}\]
    9. Using strategy rm
    10. Applied log1p-expm1-u0.1

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, -\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)\right)\right)} + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\]
    11. Simplified0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -10772.01231732761152670718729496002197266 \lor \neg \left(x \le 12102.13419773719942895695567131042480469\right):\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(-\left(\frac{1}{x \cdot x} + \left(\frac{3}{x} + \frac{3}{{x}^{3}}\right)\right)\right)\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\log \left(e^{\mathsf{expm1}\left(\frac{x}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right) - \frac{x + 1}{x - 1}\right)}\right)\right) + \left(\left(-\left(x + 1\right)\right) + \left(x + 1\right)\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 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))))