Average Error: 29.3 → 0.1
Time: 4.8s
Precision: 64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -10207.34946242376827285625040531158447266 \lor \neg \left(x \le 8646.459775303861533757299184799194335938\right):\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{1}{x}}{x}, \frac{-3}{x}\right) - 3 \cdot \frac{1}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x}{x + 1} - \frac{x + 1}{x - 1}}\right)\\ \end{array}\]
\frac{x}{x + 1} - \frac{x + 1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -10207.34946242376827285625040531158447266 \lor \neg \left(x \le 8646.459775303861533757299184799194335938\right):\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{1}{x}}{x}, \frac{-3}{x}\right) - 3 \cdot \frac{1}{{x}^{3}}\\

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

\end{array}
double f(double x) {
        double r124890 = x;
        double r124891 = 1.0;
        double r124892 = r124890 + r124891;
        double r124893 = r124890 / r124892;
        double r124894 = r124890 - r124891;
        double r124895 = r124892 / r124894;
        double r124896 = r124893 - r124895;
        return r124896;
}

double f(double x) {
        double r124897 = x;
        double r124898 = -10207.349462423768;
        bool r124899 = r124897 <= r124898;
        double r124900 = 8646.459775303862;
        bool r124901 = r124897 <= r124900;
        double r124902 = !r124901;
        bool r124903 = r124899 || r124902;
        double r124904 = -1.0;
        double r124905 = 1.0;
        double r124906 = r124905 / r124897;
        double r124907 = r124906 / r124897;
        double r124908 = 3.0;
        double r124909 = -r124908;
        double r124910 = r124909 / r124897;
        double r124911 = fma(r124904, r124907, r124910);
        double r124912 = 1.0;
        double r124913 = 3.0;
        double r124914 = pow(r124897, r124913);
        double r124915 = r124912 / r124914;
        double r124916 = r124908 * r124915;
        double r124917 = r124911 - r124916;
        double r124918 = r124897 + r124905;
        double r124919 = r124897 / r124918;
        double r124920 = r124897 - r124905;
        double r124921 = r124918 / r124920;
        double r124922 = r124919 - r124921;
        double r124923 = exp(r124922);
        double r124924 = log(r124923);
        double r124925 = r124903 ? r124917 : r124924;
        return r124925;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -10207.349462423768 or 8646.459775303862 < 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.3

      \[\leadsto \color{blue}{\frac{-1}{{x}^{2}} - \mathsf{fma}\left(3, \frac{1}{x}, 3 \cdot \frac{1}{{x}^{3}}\right)}\]
    4. Using strategy rm
    5. Applied fma-udef0.3

      \[\leadsto \frac{-1}{{x}^{2}} - \color{blue}{\left(3 \cdot \frac{1}{x} + 3 \cdot \frac{1}{{x}^{3}}\right)}\]
    6. Applied associate--r+0.3

      \[\leadsto \color{blue}{\left(\frac{-1}{{x}^{2}} - 3 \cdot \frac{1}{x}\right) - 3 \cdot \frac{1}{{x}^{3}}}\]
    7. Simplified0.0

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

    if -10207.349462423768 < x < 8646.459775303862

    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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -10207.34946242376827285625040531158447266 \lor \neg \left(x \le 8646.459775303861533757299184799194335938\right):\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{\frac{1}{x}}{x}, \frac{-3}{x}\right) - 3 \cdot \frac{1}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{x}{x + 1} - \frac{x + 1}{x - 1}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019354 +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))