Average Error: 52.4 → 0.1
Time: 17.7s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0468290506388152:\\ \;\;\;\;\log \left(\frac{\frac{1}{8}}{\left(x \cdot x\right) \cdot x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{-1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.009515787017106168:\\ \;\;\;\;\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(\sqrt{\mathsf{hypot}\left(1, x\right) + x} \cdot \sqrt{\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.0468290506388152:\\
\;\;\;\;\log \left(\frac{\frac{1}{8}}{\left(x \cdot x\right) \cdot x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{-1}{2}}{x}\right)\right)\\

\mathbf{elif}\;x \le 0.009515787017106168:\\
\;\;\;\;\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(\sqrt{\mathsf{hypot}\left(1, x\right) + x} \cdot \sqrt{\mathsf{hypot}\left(1, x\right) + x}\right)\\

\end{array}
double f(double x) {
        double r5075623 = x;
        double r5075624 = r5075623 * r5075623;
        double r5075625 = 1.0;
        double r5075626 = r5075624 + r5075625;
        double r5075627 = sqrt(r5075626);
        double r5075628 = r5075623 + r5075627;
        double r5075629 = log(r5075628);
        return r5075629;
}

double f(double x) {
        double r5075630 = x;
        double r5075631 = -1.0468290506388152;
        bool r5075632 = r5075630 <= r5075631;
        double r5075633 = 0.125;
        double r5075634 = r5075630 * r5075630;
        double r5075635 = r5075634 * r5075630;
        double r5075636 = r5075633 / r5075635;
        double r5075637 = 0.0625;
        double r5075638 = 5.0;
        double r5075639 = pow(r5075630, r5075638);
        double r5075640 = r5075637 / r5075639;
        double r5075641 = -0.5;
        double r5075642 = r5075641 / r5075630;
        double r5075643 = r5075640 - r5075642;
        double r5075644 = r5075636 - r5075643;
        double r5075645 = log(r5075644);
        double r5075646 = 0.009515787017106168;
        bool r5075647 = r5075630 <= r5075646;
        double r5075648 = -0.16666666666666666;
        double r5075649 = 0.075;
        double r5075650 = fma(r5075649, r5075639, r5075630);
        double r5075651 = fma(r5075635, r5075648, r5075650);
        double r5075652 = 1.0;
        double r5075653 = hypot(r5075652, r5075630);
        double r5075654 = r5075653 + r5075630;
        double r5075655 = sqrt(r5075654);
        double r5075656 = r5075655 * r5075655;
        double r5075657 = log(r5075656);
        double r5075658 = r5075647 ? r5075651 : r5075657;
        double r5075659 = r5075632 ? r5075645 : r5075658;
        return r5075659;
}

Error

Bits error versus x

Target

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

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

    if -1.0468290506388152 < x < 0.009515787017106168

    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.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.009515787017106168 < x

    1. Initial program 30.5

      \[\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-sqr-sqrt0.0

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

Reproduce

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