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

\mathbf{elif}\;x \le 0.007871312528259618:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \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 r6202373 = x;
        double r6202374 = r6202373 * r6202373;
        double r6202375 = 1.0;
        double r6202376 = r6202374 + r6202375;
        double r6202377 = sqrt(r6202376);
        double r6202378 = r6202373 + r6202377;
        double r6202379 = log(r6202378);
        return r6202379;
}

double f(double x) {
        double r6202380 = x;
        double r6202381 = -1.0481361170547778;
        bool r6202382 = r6202380 <= r6202381;
        double r6202383 = 0.125;
        double r6202384 = r6202383 / r6202380;
        double r6202385 = r6202380 * r6202380;
        double r6202386 = r6202384 / r6202385;
        double r6202387 = -0.5;
        double r6202388 = r6202387 / r6202380;
        double r6202389 = 0.0625;
        double r6202390 = 5.0;
        double r6202391 = pow(r6202380, r6202390);
        double r6202392 = r6202389 / r6202391;
        double r6202393 = r6202388 - r6202392;
        double r6202394 = r6202386 + r6202393;
        double r6202395 = log(r6202394);
        double r6202396 = 0.007871312528259618;
        bool r6202397 = r6202380 <= r6202396;
        double r6202398 = -0.16666666666666666;
        double r6202399 = r6202380 * r6202398;
        double r6202400 = 0.075;
        double r6202401 = fma(r6202400, r6202391, r6202380);
        double r6202402 = fma(r6202399, r6202385, r6202401);
        double r6202403 = 1.0;
        double r6202404 = hypot(r6202403, r6202380);
        double r6202405 = r6202404 + r6202380;
        double r6202406 = log(r6202405);
        double r6202407 = r6202397 ? r6202402 : r6202406;
        double r6202408 = r6202382 ? r6202395 : r6202407;
        return r6202408;
}

Error

Bits error versus x

Target

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

    1. Initial program 61.5

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

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

    if -1.0481361170547778 < x < 0.007871312528259618

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

    if 0.007871312528259618 < x

    1. Initial program 30.0

      \[\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. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.0481361170547778:\\ \;\;\;\;\log \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \left(\frac{\frac{-1}{2}}{x} - \frac{\frac{1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.007871312528259618:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \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 2019162 +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)))))