Average Error: 52.4 → 0.1
Time: 15.5s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0589513033049822:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\left(\frac{1}{x}\right), \left(\frac{\frac{1}{8}}{x \cdot x} - \frac{1}{2}\right), \left(\frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\right)\\ \mathbf{elif}\;x \le 0.007287090423348713:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \left(x \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\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.0589513033049822:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\left(\frac{1}{x}\right), \left(\frac{\frac{1}{8}}{x \cdot x} - \frac{1}{2}\right), \left(\frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\right)\\

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

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

\end{array}
double f(double x) {
        double r5782820 = x;
        double r5782821 = r5782820 * r5782820;
        double r5782822 = 1.0;
        double r5782823 = r5782821 + r5782822;
        double r5782824 = sqrt(r5782823);
        double r5782825 = r5782820 + r5782824;
        double r5782826 = log(r5782825);
        return r5782826;
}

double f(double x) {
        double r5782827 = x;
        double r5782828 = -1.0589513033049822;
        bool r5782829 = r5782827 <= r5782828;
        double r5782830 = 1.0;
        double r5782831 = r5782830 / r5782827;
        double r5782832 = 0.125;
        double r5782833 = r5782827 * r5782827;
        double r5782834 = r5782832 / r5782833;
        double r5782835 = 0.5;
        double r5782836 = r5782834 - r5782835;
        double r5782837 = -0.0625;
        double r5782838 = 5.0;
        double r5782839 = pow(r5782827, r5782838);
        double r5782840 = r5782837 / r5782839;
        double r5782841 = fma(r5782831, r5782836, r5782840);
        double r5782842 = log(r5782841);
        double r5782843 = 0.007287090423348713;
        bool r5782844 = r5782827 <= r5782843;
        double r5782845 = -0.16666666666666666;
        double r5782846 = r5782827 * r5782833;
        double r5782847 = 0.075;
        double r5782848 = fma(r5782847, r5782839, r5782827);
        double r5782849 = fma(r5782845, r5782846, r5782848);
        double r5782850 = hypot(r5782830, r5782827);
        double r5782851 = r5782850 + r5782827;
        double r5782852 = log(r5782851);
        double r5782853 = r5782844 ? r5782849 : r5782852;
        double r5782854 = r5782829 ? r5782842 : r5782853;
        return r5782854;
}

Error

Bits error versus x

Target

Original52.4
Target44.7
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.0589513033049822

    1. Initial program 62.1

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

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

      \[\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.1

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

    if -1.0589513033049822 < x < 0.007287090423348713

    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(\left(x \cdot x\right) \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\right)\right)}\]

    if 0.007287090423348713 < x

    1. Initial program 31.6

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied expm1-log1p-u0.0

      \[\leadsto \log \color{blue}{\left(\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(x + \mathsf{hypot}\left(1, x\right)\right)\right)\right)\right)\right)}\]
    5. Using strategy rm
    6. Applied add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\log \left(\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(x + \mathsf{hypot}\left(1, x\right)\right)\right)\right)\right)\right)}\right)}\]
    7. Simplified0.0

      \[\leadsto \log \color{blue}{\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.0589513033049822:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\left(\frac{1}{x}\right), \left(\frac{\frac{1}{8}}{x \cdot x} - \frac{1}{2}\right), \left(\frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\right)\\ \mathbf{elif}\;x \le 0.007287090423348713:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \left(x \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\ \end{array}\]

Reproduce

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