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

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

\end{array}
double f(double x) {
        double r101787 = x;
        double r101788 = 1.0;
        double r101789 = r101787 + r101788;
        double r101790 = r101787 / r101789;
        double r101791 = r101787 - r101788;
        double r101792 = r101789 / r101791;
        double r101793 = r101790 - r101792;
        return r101793;
}

double f(double x) {
        double r101794 = x;
        double r101795 = -254622.29660434803;
        bool r101796 = r101794 <= r101795;
        double r101797 = 116203.31990693379;
        bool r101798 = r101794 <= r101797;
        double r101799 = !r101798;
        bool r101800 = r101796 || r101799;
        double r101801 = 1.0;
        double r101802 = r101794 * r101794;
        double r101803 = r101801 / r101802;
        double r101804 = exp(r101803);
        double r101805 = log(r101804);
        double r101806 = 3.0;
        double r101807 = r101806 / r101794;
        double r101808 = r101805 + r101807;
        double r101809 = 3.0;
        double r101810 = pow(r101794, r101809);
        double r101811 = r101806 / r101810;
        double r101812 = r101808 + r101811;
        double r101813 = -r101812;
        double r101814 = r101801 * r101801;
        double r101815 = r101802 - r101814;
        double r101816 = r101794 / r101815;
        double r101817 = r101794 - r101801;
        double r101818 = -1.0;
        double r101819 = r101801 - r101794;
        double r101820 = r101801 * r101819;
        double r101821 = fma(r101794, r101794, r101820);
        double r101822 = r101818 / r101821;
        double r101823 = pow(r101801, r101809);
        double r101824 = r101810 + r101823;
        double r101825 = r101817 / r101824;
        double r101826 = r101822 / r101825;
        double r101827 = fma(r101816, r101817, r101826);
        double r101828 = 1.0;
        double r101829 = r101828 / r101825;
        double r101830 = r101828 / r101821;
        double r101831 = r101822 + r101830;
        double r101832 = r101829 * r101831;
        double r101833 = r101827 + r101832;
        double r101834 = r101800 ? r101813 : r101833;
        return r101834;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -254622.29660434803 or 116203.31990693379 < x

    1. Initial program 59.4

      \[\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}{-\left(\left(\frac{1}{x \cdot x} + \frac{3}{x}\right) + \frac{3}{{x}^{3}}\right)}\]
    4. Using strategy rm
    5. Applied add-log-exp0.5

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

    if -254622.29660434803 < x < 116203.31990693379

    1. Initial program 0.1

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

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{1}{\frac{x - 1}{x + 1}}}\]
    4. Using strategy rm
    5. Applied flip3-+0.1

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

      \[\leadsto \frac{x}{x + 1} - \frac{1}{\color{blue}{\frac{x - 1}{{x}^{3} + {1}^{3}} \cdot \left(x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)\right)}}\]
    7. Applied add-cube-cbrt0.1

      \[\leadsto \frac{x}{x + 1} - \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{x - 1}{{x}^{3} + {1}^{3}} \cdot \left(x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)\right)}\]
    8. Applied times-frac0.1

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{x - 1}{{x}^{3} + {1}^{3}}} \cdot \frac{\sqrt[3]{1}}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}}\]
    9. Applied flip-+0.2

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

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

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

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

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

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

Reproduce

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