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

\mathbf{elif}\;x \le 0.006188922223074722:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{6}, \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 r3576684 = x;
        double r3576685 = r3576684 * r3576684;
        double r3576686 = 1.0;
        double r3576687 = r3576685 + r3576686;
        double r3576688 = sqrt(r3576687);
        double r3576689 = r3576684 + r3576688;
        double r3576690 = log(r3576689);
        return r3576690;
}

double f(double x) {
        double r3576691 = x;
        double r3576692 = -1.076228701950242;
        bool r3576693 = r3576691 <= r3576692;
        double r3576694 = -0.5;
        double r3576695 = r3576694 / r3576691;
        double r3576696 = 0.125;
        double r3576697 = r3576696 / r3576691;
        double r3576698 = r3576691 * r3576691;
        double r3576699 = r3576697 / r3576698;
        double r3576700 = -0.0625;
        double r3576701 = 5.0;
        double r3576702 = pow(r3576691, r3576701);
        double r3576703 = r3576700 / r3576702;
        double r3576704 = r3576699 + r3576703;
        double r3576705 = r3576695 + r3576704;
        double r3576706 = log(r3576705);
        double r3576707 = 0.006188922223074722;
        bool r3576708 = r3576691 <= r3576707;
        double r3576709 = r3576698 * r3576691;
        double r3576710 = -0.16666666666666666;
        double r3576711 = 0.075;
        double r3576712 = fma(r3576711, r3576702, r3576691);
        double r3576713 = fma(r3576709, r3576710, r3576712);
        double r3576714 = 1.0;
        double r3576715 = hypot(r3576714, r3576691);
        double r3576716 = r3576715 + r3576691;
        double r3576717 = log(r3576716);
        double r3576718 = r3576708 ? r3576713 : r3576717;
        double r3576719 = r3576693 ? r3576706 : r3576718;
        return r3576719;
}

Error

Bits error versus x

Target

Original52.6
Target44.6
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.076228701950242

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

    if -1.076228701950242 < x < 0.006188922223074722

    1. Initial program 58.8

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

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

    if 0.006188922223074722 < x

    1. Initial program 30.9

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

      \[\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.076228701950242:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.006188922223074722:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{6}, \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 2019153 +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)))))