Average Error: 52.6 → 0.1
Time: 14.1s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0612400279589977:\\ \;\;\;\;\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.00884177569185373:\\ \;\;\;\;\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.0612400279589977:\\
\;\;\;\;\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.00884177569185373:\\
\;\;\;\;\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 r3145823 = x;
        double r3145824 = r3145823 * r3145823;
        double r3145825 = 1.0;
        double r3145826 = r3145824 + r3145825;
        double r3145827 = sqrt(r3145826);
        double r3145828 = r3145823 + r3145827;
        double r3145829 = log(r3145828);
        return r3145829;
}

double f(double x) {
        double r3145830 = x;
        double r3145831 = -1.0612400279589977;
        bool r3145832 = r3145830 <= r3145831;
        double r3145833 = -0.5;
        double r3145834 = r3145833 / r3145830;
        double r3145835 = 0.125;
        double r3145836 = r3145835 / r3145830;
        double r3145837 = r3145830 * r3145830;
        double r3145838 = r3145836 / r3145837;
        double r3145839 = -0.0625;
        double r3145840 = 5.0;
        double r3145841 = pow(r3145830, r3145840);
        double r3145842 = r3145839 / r3145841;
        double r3145843 = r3145838 + r3145842;
        double r3145844 = r3145834 + r3145843;
        double r3145845 = log(r3145844);
        double r3145846 = 0.00884177569185373;
        bool r3145847 = r3145830 <= r3145846;
        double r3145848 = r3145837 * r3145830;
        double r3145849 = -0.16666666666666666;
        double r3145850 = 0.075;
        double r3145851 = fma(r3145850, r3145841, r3145830);
        double r3145852 = fma(r3145848, r3145849, r3145851);
        double r3145853 = 1.0;
        double r3145854 = hypot(r3145853, r3145830);
        double r3145855 = r3145854 + r3145830;
        double r3145856 = log(r3145855);
        double r3145857 = r3145847 ? r3145852 : r3145856;
        double r3145858 = r3145832 ? r3145845 : r3145857;
        return r3145858;
}

Error

Bits error versus x

Target

Original52.6
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.0612400279589977

    1. Initial program 61.7

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

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

    if -1.0612400279589977 < x < 0.00884177569185373

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

    1. Initial program 31.1

      \[\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.0612400279589977:\\ \;\;\;\;\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.00884177569185373:\\ \;\;\;\;\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 2019152 +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)))))