Average Error: 52.7 → 0.1
Time: 16.9s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0840635159626253:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{\frac{1}{8}}{x \cdot x}}{x} + \frac{\frac{-1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.007778482819478155:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \mathsf{fma}\left(\frac{3}{40}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.0840635159626253:\\
\;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{\frac{1}{8}}{x \cdot x}}{x} + \frac{\frac{-1}{2}}{x}\right)\right)\\

\mathbf{elif}\;x \le 0.007778482819478155:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \mathsf{fma}\left(\frac{3}{40}, {x}^{5}, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\

\end{array}
double f(double x) {
        double r6290965 = x;
        double r6290966 = r6290965 * r6290965;
        double r6290967 = 1.0;
        double r6290968 = r6290966 + r6290967;
        double r6290969 = sqrt(r6290968);
        double r6290970 = r6290965 + r6290969;
        double r6290971 = log(r6290970);
        return r6290971;
}

double f(double x) {
        double r6290972 = x;
        double r6290973 = -1.0840635159626253;
        bool r6290974 = r6290972 <= r6290973;
        double r6290975 = -0.0625;
        double r6290976 = 5.0;
        double r6290977 = pow(r6290972, r6290976);
        double r6290978 = r6290975 / r6290977;
        double r6290979 = 0.125;
        double r6290980 = r6290972 * r6290972;
        double r6290981 = r6290979 / r6290980;
        double r6290982 = r6290981 / r6290972;
        double r6290983 = -0.5;
        double r6290984 = r6290983 / r6290972;
        double r6290985 = r6290982 + r6290984;
        double r6290986 = r6290978 + r6290985;
        double r6290987 = log(r6290986);
        double r6290988 = 0.007778482819478155;
        bool r6290989 = r6290972 <= r6290988;
        double r6290990 = -0.16666666666666666;
        double r6290991 = r6290972 * r6290990;
        double r6290992 = 0.075;
        double r6290993 = fma(r6290992, r6290977, r6290972);
        double r6290994 = fma(r6290991, r6290980, r6290993);
        double r6290995 = 1.0;
        double r6290996 = hypot(r6290995, r6290972);
        double r6290997 = r6290996 + r6290972;
        double r6290998 = log(r6290997);
        double r6290999 = r6290989 ? r6290994 : r6290998;
        double r6291000 = r6290974 ? r6290987 : r6290999;
        return r6291000;
}

Error

Bits error versus x

Target

Original52.7
Target44.8
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \lt 0:\\ \;\;\;\;\log \left(\frac{-1}{x - \sqrt{x \cdot x + 1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \sqrt{x \cdot x + 1}\right)\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.0840635159626253

    1. Initial program 61.8

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified61.0

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Taylor expanded around -inf 0.2

      \[\leadsto \log \color{blue}{\left(\frac{1}{8} \cdot \frac{1}{{x}^{3}} - \left(\frac{1}{16} \cdot \frac{1}{{x}^{5}} + \frac{1}{2} \cdot \frac{1}{x}\right)\right)}\]
    4. Simplified0.2

      \[\leadsto \log \color{blue}{\left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{-1}{2}}{x} + \frac{\frac{\frac{1}{8}}{x \cdot x}}{x}\right)\right)}\]

    if -1.0840635159626253 < x < 0.007778482819478155

    1. Initial program 58.6

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified58.6

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(x + \frac{3}{40} \cdot {x}^{5}\right) - \frac{1}{6} \cdot {x}^{3}}\]
    4. Simplified0.2

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

    if 0.007778482819478155 < x

    1. Initial program 32.1

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified0.1

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.0840635159626253:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{\frac{1}{8}}{x \cdot x}}{x} + \frac{\frac{-1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.007778482819478155:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \mathsf{fma}\left(\frac{3}{40}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic arcsine"

  :herbie-target
  (if (< x 0) (log (/ -1 (- x (sqrt (+ (* x x) 1))))) (log (+ x (sqrt (+ (* x x) 1)))))

  (log (+ x (sqrt (+ (* x x) 1)))))