Average Error: 0.0 → 0.4
Time: 6.3s
Precision: 64
\[\frac{x + 1}{1 - x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x + 1}{1 - x} \le -1.000000000111358033905162301380187273026:\\ \;\;\;\;\frac{x \cdot x - 1 \cdot 1}{\left(1 - x\right) \cdot \left(x - 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x + 1}{1 - x}\right)\right)\\ \end{array}\]
\frac{x + 1}{1 - x}
\begin{array}{l}
\mathbf{if}\;\frac{x + 1}{1 - x} \le -1.000000000111358033905162301380187273026:\\
\;\;\;\;\frac{x \cdot x - 1 \cdot 1}{\left(1 - x\right) \cdot \left(x - 1\right)}\\

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

\end{array}
double f(double x) {
        double r41842 = x;
        double r41843 = 1.0;
        double r41844 = r41842 + r41843;
        double r41845 = r41843 - r41842;
        double r41846 = r41844 / r41845;
        return r41846;
}

double f(double x) {
        double r41847 = x;
        double r41848 = 1.0;
        double r41849 = r41847 + r41848;
        double r41850 = r41848 - r41847;
        double r41851 = r41849 / r41850;
        double r41852 = -1.000000000111358;
        bool r41853 = r41851 <= r41852;
        double r41854 = r41847 * r41847;
        double r41855 = r41848 * r41848;
        double r41856 = r41854 - r41855;
        double r41857 = r41847 - r41848;
        double r41858 = r41850 * r41857;
        double r41859 = r41856 / r41858;
        double r41860 = log1p(r41851);
        double r41861 = expm1(r41860);
        double r41862 = r41853 ? r41859 : r41861;
        return r41862;
}

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 1.0) (- 1.0 x)) < -1.000000000111358

    1. Initial program 0.0

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

      \[\leadsto \frac{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}}{1 - x}\]
    4. Applied associate-/l/0.2

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

    if -1.000000000111358 < (/ (+ x 1.0) (- 1.0 x))

    1. Initial program 0.0

      \[\frac{x + 1}{1 - x}\]
    2. Using strategy rm
    3. Applied expm1-log1p-u0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + 1}{1 - x} \le -1.000000000111358033905162301380187273026:\\ \;\;\;\;\frac{x \cdot x - 1 \cdot 1}{\left(1 - x\right) \cdot \left(x - 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x + 1}{1 - x}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019235 +o rules:numerics
(FPCore (x)
  :name "Prelude:atanh from fay-base-0.20.0.1"
  :precision binary64
  (/ (+ x 1) (- 1 x)))