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

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

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

\end{array}
double f(double x) {
        double r4405898 = x;
        double r4405899 = r4405898 * r4405898;
        double r4405900 = 1.0;
        double r4405901 = r4405899 + r4405900;
        double r4405902 = sqrt(r4405901);
        double r4405903 = r4405898 + r4405902;
        double r4405904 = log(r4405903);
        return r4405904;
}

double f(double x) {
        double r4405905 = x;
        double r4405906 = -1.0884602506497811;
        bool r4405907 = r4405905 <= r4405906;
        double r4405908 = -0.0625;
        double r4405909 = 5.0;
        double r4405910 = pow(r4405905, r4405909);
        double r4405911 = r4405908 / r4405910;
        double r4405912 = 0.125;
        double r4405913 = r4405912 / r4405905;
        double r4405914 = r4405905 * r4405905;
        double r4405915 = r4405913 / r4405914;
        double r4405916 = -0.5;
        double r4405917 = r4405916 / r4405905;
        double r4405918 = r4405915 + r4405917;
        double r4405919 = r4405911 + r4405918;
        double r4405920 = log(r4405919);
        double r4405921 = 0.007683264102509549;
        bool r4405922 = r4405905 <= r4405921;
        double r4405923 = -0.16666666666666666;
        double r4405924 = r4405914 * r4405905;
        double r4405925 = 0.075;
        double r4405926 = fma(r4405910, r4405925, r4405905);
        double r4405927 = fma(r4405923, r4405924, r4405926);
        double r4405928 = 1.0;
        double r4405929 = hypot(r4405928, r4405905);
        double r4405930 = sqrt(r4405929);
        double r4405931 = r4405930 * r4405930;
        double r4405932 = r4405905 + r4405931;
        double r4405933 = log(r4405932);
        double r4405934 = r4405922 ? r4405927 : r4405933;
        double r4405935 = r4405907 ? r4405920 : r4405934;
        return r4405935;
}

Error

Bits error versus x

Target

Original52.0
Target44.3
Herbie0.2
\[\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.0884602506497811

    1. Initial program 61.5

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt61.3

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

      \[\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)}\]
    6. Simplified0.3

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

    if -1.0884602506497811 < x < 0.007683264102509549

    1. Initial program 58.7

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

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

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

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

    if 0.007683264102509549 < x

    1. Initial program 29.8

      \[\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. Using strategy rm
    4. Applied add-sqr-sqrt0.1

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

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

Reproduce

herbie shell --seed 2019143 +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)))))