Average Error: 29.6 → 0.1
Time: 28.3s
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 r4858358 = x;
        double r4858359 = 1.0;
        double r4858360 = r4858358 + r4858359;
        double r4858361 = r4858358 / r4858360;
        double r4858362 = r4858358 - r4858359;
        double r4858363 = r4858360 / r4858362;
        double r4858364 = r4858361 - r4858363;
        return r4858364;
}

double f(double x) {
        double r4858365 = x;
        double r4858366 = -12705.479066605956;
        bool r4858367 = r4858365 <= r4858366;
        double r4858368 = 1.0;
        double r4858369 = r4858365 * r4858365;
        double r4858370 = r4858368 / r4858369;
        double r4858371 = 1.0;
        double r4858372 = 3.0;
        double r4858373 = r4858372 / r4858365;
        double r4858374 = fma(r4858373, r4858370, r4858373);
        double r4858375 = fma(r4858370, r4858371, r4858374);
        double r4858376 = -r4858375;
        double r4858377 = 8811.972647140785;
        bool r4858378 = r4858365 <= r4858377;
        double r4858379 = r4858365 + r4858371;
        double r4858380 = -r4858379;
        double r4858381 = r4858371 * r4858371;
        double r4858382 = r4858369 - r4858381;
        double r4858383 = r4858365 - r4858371;
        double r4858384 = r4858383 * r4858382;
        double r4858385 = r4858382 / r4858384;
        double r4858386 = r4858379 / r4858382;
        double r4858387 = r4858379 * r4858386;
        double r4858388 = fma(r4858380, r4858385, r4858387);
        double r4858389 = r4858365 / r4858382;
        double r4858390 = r4858380 / r4858382;
        double r4858391 = r4858379 * r4858390;
        double r4858392 = fma(r4858389, r4858383, r4858391);
        double r4858393 = r4858388 + r4858392;
        double r4858394 = r4858378 ? r4858393 : r4858376;
        double r4858395 = r4858367 ? r4858376 : r4858394;
        return r4858395;
}

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))))