Average Error: 29.6 → 0.1
Time: 28.9s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -12705.47906660595617722719907760620117188:\\ \;\;\;\;-\mathsf{fma}\left(\frac{1}{x \cdot x}, 1, \mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{3}{x}\right)\right)\\ \mathbf{elif}\;x \le 8811.972647140784829389303922653198242188:\\ \;\;\;\;\mathsf{fma}\left(-\left(x + 1\right), \frac{x \cdot x - 1 \cdot 1}{\left(x - 1\right) \cdot \left(x \cdot x - 1 \cdot 1\right)}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, \left(x + 1\right) \cdot \frac{-\left(x + 1\right)}{x \cdot x - 1 \cdot 1}\right)\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(\frac{1}{x \cdot x}, 1, \mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{3}{x}\right)\right)\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -12705.47906660595617722719907760620117188:\\
\;\;\;\;-\mathsf{fma}\left(\frac{1}{x \cdot x}, 1, \mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{3}{x}\right)\right)\\

\mathbf{elif}\;x \le 8811.972647140784829389303922653198242188:\\
\;\;\;\;\mathsf{fma}\left(-\left(x + 1\right), \frac{x \cdot x - 1 \cdot 1}{\left(x - 1\right) \cdot \left(x \cdot x - 1 \cdot 1\right)}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, \left(x + 1\right) \cdot \frac{-\left(x + 1\right)}{x \cdot x - 1 \cdot 1}\right)\\

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

\end{array}
double f(double x) {
        double r4031010 = x;
        double r4031011 = 1.0;
        double r4031012 = r4031010 + r4031011;
        double r4031013 = r4031010 / r4031012;
        double r4031014 = r4031010 - r4031011;
        double r4031015 = r4031012 / r4031014;
        double r4031016 = r4031013 - r4031015;
        return r4031016;
}

double f(double x) {
        double r4031017 = x;
        double r4031018 = -12705.479066605956;
        bool r4031019 = r4031017 <= r4031018;
        double r4031020 = 1.0;
        double r4031021 = r4031017 * r4031017;
        double r4031022 = r4031020 / r4031021;
        double r4031023 = 1.0;
        double r4031024 = 3.0;
        double r4031025 = r4031024 / r4031017;
        double r4031026 = fma(r4031025, r4031022, r4031025);
        double r4031027 = fma(r4031022, r4031023, r4031026);
        double r4031028 = -r4031027;
        double r4031029 = 8811.972647140785;
        bool r4031030 = r4031017 <= r4031029;
        double r4031031 = r4031017 + r4031023;
        double r4031032 = -r4031031;
        double r4031033 = r4031023 * r4031023;
        double r4031034 = r4031021 - r4031033;
        double r4031035 = r4031017 - r4031023;
        double r4031036 = r4031035 * r4031034;
        double r4031037 = r4031034 / r4031036;
        double r4031038 = r4031031 / r4031034;
        double r4031039 = r4031031 * r4031038;
        double r4031040 = fma(r4031032, r4031037, r4031039);
        double r4031041 = r4031017 / r4031034;
        double r4031042 = r4031032 / r4031034;
        double r4031043 = r4031031 * r4031042;
        double r4031044 = fma(r4031041, r4031035, r4031043);
        double r4031045 = r4031040 + r4031044;
        double r4031046 = r4031030 ? r4031045 : r4031028;
        double r4031047 = r4031019 ? r4031028 : r4031046;
        return r4031047;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -12705.479066605956 or 8811.972647140785 < 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(1 \cdot \frac{1}{{x}^{2}} + \left(3 \cdot \frac{1}{x} + 3 \cdot \frac{1}{{x}^{3}}\right)\right)}\]
    3. Simplified0.0

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

    if -12705.479066605956 < x < 8811.972647140785

    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. Using strategy rm
    9. Applied flip-+0.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) + \mathsf{fma}\left(-\left(x + 1\right), \frac{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}}{x \cdot x - 1 \cdot 1}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)\]
    10. Applied associate-/l/0.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) + \mathsf{fma}\left(-\left(x + 1\right), \color{blue}{\frac{x \cdot x - 1 \cdot 1}{\left(x \cdot x - 1 \cdot 1\right) \cdot \left(x - 1\right)}}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -12705.47906660595617722719907760620117188:\\ \;\;\;\;-\mathsf{fma}\left(\frac{1}{x \cdot x}, 1, \mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{3}{x}\right)\right)\\ \mathbf{elif}\;x \le 8811.972647140784829389303922653198242188:\\ \;\;\;\;\mathsf{fma}\left(-\left(x + 1\right), \frac{x \cdot x - 1 \cdot 1}{\left(x - 1\right) \cdot \left(x \cdot x - 1 \cdot 1\right)}, \left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \mathsf{fma}\left(\frac{x}{x \cdot x - 1 \cdot 1}, x - 1, \left(x + 1\right) \cdot \frac{-\left(x + 1\right)}{x \cdot x - 1 \cdot 1}\right)\\ \mathbf{else}:\\ \;\;\;\;-\mathsf{fma}\left(\frac{1}{x \cdot x}, 1, \mathsf{fma}\left(\frac{3}{x}, \frac{1}{x \cdot x}, \frac{3}{x}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))