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

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

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

\end{array}
double f(double x) {
        double r2840879 = x;
        double r2840880 = r2840879 * r2840879;
        double r2840881 = 1.0;
        double r2840882 = r2840880 + r2840881;
        double r2840883 = sqrt(r2840882);
        double r2840884 = r2840879 + r2840883;
        double r2840885 = log(r2840884);
        return r2840885;
}

double f(double x) {
        double r2840886 = x;
        double r2840887 = -1.061520745717705;
        bool r2840888 = r2840886 <= r2840887;
        double r2840889 = 0.125;
        double r2840890 = r2840886 * r2840886;
        double r2840891 = r2840889 / r2840890;
        double r2840892 = r2840891 / r2840886;
        double r2840893 = 0.5;
        double r2840894 = r2840893 / r2840886;
        double r2840895 = r2840892 - r2840894;
        double r2840896 = 0.0625;
        double r2840897 = 5.0;
        double r2840898 = pow(r2840886, r2840897);
        double r2840899 = r2840896 / r2840898;
        double r2840900 = r2840895 - r2840899;
        double r2840901 = log(r2840900);
        double r2840902 = 0.009904032332962092;
        bool r2840903 = r2840886 <= r2840902;
        double r2840904 = -0.16666666666666666;
        double r2840905 = r2840890 * r2840886;
        double r2840906 = 0.075;
        double r2840907 = fma(r2840906, r2840898, r2840886);
        double r2840908 = fma(r2840904, r2840905, r2840907);
        double r2840909 = 1.0;
        double r2840910 = hypot(r2840909, r2840886);
        double r2840911 = cbrt(r2840910);
        double r2840912 = r2840911 * r2840911;
        double r2840913 = r2840911 * r2840912;
        double r2840914 = r2840913 + r2840886;
        double r2840915 = log(r2840914);
        double r2840916 = r2840903 ? r2840908 : r2840915;
        double r2840917 = r2840888 ? r2840901 : r2840916;
        return r2840917;
}

Error

Bits error versus x

Target

Original52.6
Target45.0
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.061520745717705

    1. Initial program 61.6

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

      \[\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(\left(\frac{\frac{\frac{1}{8}}{x \cdot x}}{x} - \frac{\frac{1}{2}}{x}\right) - \frac{\frac{1}{16}}{{x}^{5}}\right)}\]

    if -1.061520745717705 < x < 0.009904032332962092

    1. Initial program 58.9

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

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

    if 0.009904032332962092 < 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 add-cube-cbrt0.0

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

Reproduce

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