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

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

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

\end{array}
double f(double x) {
        double r4018086 = x;
        double r4018087 = r4018086 * r4018086;
        double r4018088 = 1.0;
        double r4018089 = r4018087 + r4018088;
        double r4018090 = sqrt(r4018089);
        double r4018091 = r4018086 + r4018090;
        double r4018092 = log(r4018091);
        return r4018092;
}

double f(double x) {
        double r4018093 = x;
        double r4018094 = -1.0432984552881022;
        bool r4018095 = r4018093 <= r4018094;
        double r4018096 = -0.0625;
        double r4018097 = 5.0;
        double r4018098 = pow(r4018093, r4018097);
        double r4018099 = r4018096 / r4018098;
        double r4018100 = -0.125;
        double r4018101 = r4018093 * r4018093;
        double r4018102 = r4018093 * r4018101;
        double r4018103 = r4018100 / r4018102;
        double r4018104 = 0.5;
        double r4018105 = r4018104 / r4018093;
        double r4018106 = r4018103 + r4018105;
        double r4018107 = r4018099 - r4018106;
        double r4018108 = log(r4018107);
        double r4018109 = 0.008530104512022981;
        bool r4018110 = r4018093 <= r4018109;
        double r4018111 = 0.075;
        double r4018112 = -0.16666666666666666;
        double r4018113 = fma(r4018112, r4018102, r4018093);
        double r4018114 = fma(r4018111, r4018098, r4018113);
        double r4018115 = cbrt(r4018093);
        double r4018116 = r4018115 * r4018115;
        double r4018117 = 1.0;
        double r4018118 = hypot(r4018117, r4018093);
        double r4018119 = fma(r4018116, r4018115, r4018118);
        double r4018120 = log(r4018119);
        double r4018121 = r4018110 ? r4018114 : r4018120;
        double r4018122 = r4018095 ? r4018108 : r4018121;
        return r4018122;
}

Error

Bits error versus x

Target

Original52.9
Target45.4
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.0432984552881022

    1. Initial program 61.9

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

    if -1.0432984552881022 < x < 0.008530104512022981

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

    if 0.008530104512022981 < x

    1. Initial program 31.3

      \[\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(\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}} + \mathsf{hypot}\left(1, x\right)\right)\]
    5. Applied fma-def0.0

      \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, \mathsf{hypot}\left(1, x\right)\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.0432984552881022:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)} + \frac{\frac{1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.008530104512022981:\\ \;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, \mathsf{hypot}\left(1, x\right)\right)\right)\\ \end{array}\]

Reproduce

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